--- /dev/null
+# configuration file generated by Bochs
+megs: 128
+plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, iodebug=1
+config_interface: textconfig
+display_library: x
+memory: host=128, guest=128
+romimage: file="/usr/local/share/bochs/BIOS-bochs-latest"
+vgaromimage: file="/usr/local/share/bochs/VGABIOS-lgpl-latest"
+boot: disk
+floppy_bootsig_check: disabled=1
+# no floppya
+# no floppyb
+ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14
+ata0-master: type=disk, mode=flat, translation=auto, path="./HD.IMG", cylinders=48, heads=16, spt=63, biosdetect=auto, model="Generic 1234"
+ata0-slave: type=cdrom, path="grub.iso", status=inserted, biosdetect=auto, model="Generic 1234"
+ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15
+ata2: enabled=0
+ata3: enabled=0
+parport1: enabled=1, file=""
+parport2: enabled=0
+com1: enabled=1, mode=null, dev=""
+com2: enabled=0
+com3: enabled=0
+com4: enabled=0
+cpuid: vendor_string="GenuineIntel"
+cpuid: brand_string=" Intel(R) Pentium(R) 4 CPU "
+
+usb_uhci: enabled=0
+usb_ohci: enabled=0
+print_timestamps: enabled=0
+debugger_log: -
+magic_break: enabled=1
+port_e9_hack: enabled=0
+private_colormap: enabled=0
+clock: sync=none, time0=local
+# no cmosimage
+ne2k: enabled=0
+pnic: enabled=0
+sb16: enabled=0
+# no loader
+log: -
+logprefix: %t%e%d
+panic: action=ask
+error: action=report
+info: action=report
+debug: action=ignore
+keyboard_type: mf
+keyboard_serial_delay: 250
+keyboard_paste_delay: 100000
+keyboard_mapping: enabled=1, map=/usr/local/share/bochs/keymaps/x11-pc-us.map
+user_shortcut: keys=none
+mouse: enabled=0
+#mouse: enabled=0, type=ps2, toggle=ctrl+mbutton
--- /dev/null
+# Object files
+*.o
+*.ko
+
+# Libraries
+*.lib
+*.a
+
+# Shared objects (inc. Windows DLLs)
+*.dll
+*.so
+*.so.*
+*.dylib
+
+# Executables
+*.exe
+*.out
+*.app
+
+*.IMG
+*.img
+*build*
+*.BIN
+*.map
+bin/hw
+bin/sh
#include<system.h>
-#include<boot/multiboot.h>
-#include<boot/bootparam.h>
+#include<boot/boot.h>
#include<page.h>
#include<bits.h>
#include<assert.h>
}
}
-extern void init_bootmem();
-
void CheckKernel(unsigned long addr, unsigned long magic)
{
if(magic != MULTIBOOT_BOOTLOADER_MAGIC)
init_boot_params(mbi);
- init_bootmem();
-
- while(1);
}
#if 0
/*
*--------------------------------------------------------------------------
- * File Name: reboot.S
+ * File Name: reboot.S
*
- * Description: none
+ * Description: none
*
*
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
+ * Author: Zhao Yanbai [zhaoyanbai@126.com]
*
- * Version: 1.0
+ * Version: 1.0
* Create Date: Mon Nov 10 15:58:46 2008
* Last Update: Tue Feb 10 22:39:24 2009
*
*--------------------------------------------------------------------------
*/
#define ASM
-#include"boot/multiboot.h"
+#include"boot/boot.h"
#include"system.h"
-.global _start
+.global _start
.extern CheckKernel
.extern SetupKernel
-.extern KernelEntry
+.extern KernelEntry
.extern init_pgd
.extern init_pgt
+.extern kernel_virtual_addr_start
.section .multiboot_header
.align 32
- # Multiboot Header
- # Align 32 bits boundary
- .align 4
- # Magic
- .long MULTIBOOT_HEADER_MAGIC
- # Flags
- .long MULTIBOOT_HEADER_FLAGS
- # Checksum
- .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
+ # Multiboot Header
+ # Align 32 bits boundary
+ .align 4
+ # Magic
+ .long MULTIBOOT_HEADER_MAGIC
+ # Flags
+ .long MULTIBOOT_HEADER_FLAGS
+ # Checksum
+ .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
.text
.code32
.align 32
_start:
- # Reset EFLAGS
- pushl $0
- popf
-
- # Load GDT's Information To GDTR
- lgdt GDTR-KRNLADDR
-
- mov $0x10, %dx
- mov %dx,%ds
- mov %dx,%es
- mov %dx,%ss
- mov %dx,%fs
- mov %dx,%gs
-
- movl $(stack + MULTIBOOT_STACK_SIZE - KRNLADDR), %esp
-
-
- # Save Multiboot Infomation...
- pushl %eax
- addl $KRNLADDR,%ebx
- pushl %ebx
-
- # Setup Page
- movl $init_pgd-KRNLADDR,%ebx
- movl %ebx,%edi
- movl $1024,%ecx
- xorl %eax,%eax
- cld
- rep
- stosl
-
- movl %ebx,%edi
- movl %ebx,%eax
- movl %ebx,%ecx
- addl $7,%eax
- addl $0x1000,%eax
- movl %eax, 0000(%edi)
- movl %eax, 3072(%edi)
- addl $0x1000,%eax
- movl %eax, 0004(%edi)
- movl %eax, 3076(%edi)
-
- movl $init_pgt-KRNLADDR,%ebx
- movl %ebx,%edi
- #addl $0x1000,%edi
- movl $2048,%ecx
- movl $0x07,%eax
- cld
+ # Reset EFLAGS
+ pushl $0
+ popf
+
+ # Load GDT's Information To GDTR
+ lgdt GDTR-KRNLADDR
+
+ movw $0x10, %dx
+ movw %dx,%ds
+ movw %dx,%es
+ movw %dx,%ss
+ movw %dx,%fs
+ movw %dx,%gs
+
+ movl $(stack + MULTIBOOT_STACK_SIZE - KRNLADDR), %esp
+
+ # Save Multiboot Infomation...
+ pushl %eax
+ addl $KRNLADDR,%ebx
+ pushl %ebx
+
+ # Setup Paging
+ # Clear Page Directory
+ movl $init_pgd-KRNLADDR,%ebx
+ movl %ebx,%edi
+ movl $1024,%ecx
+ xorl %eax,%eax
+ cld
+ rep
+ stosl
+
+ # Init Page Directory
+ movl %ebx,%edi
+ movl $init_pgt-KRNLADDR,%eax
+ addl $7,%eax
+ movl $BOOT_INIT_PAGETBL_CNT,%ecx
1:
- stosl
- addl $0x1000,%eax
- loop 1b
-
- movl $init_pgd-KRNLADDR,%ebx
- movl %ebx,%cr3
-
- # enable PG
- movl %cr0,%eax
- orl $0x80000000,%eax
- movl %eax,%cr0
-
-
- jmp 2f
+ stosl
+ addl $0x1000,%eax
+ loop 1b
+
+ movl $kernel_virtual_addr_start,%eax
+ shrl $20,%eax
+ addl %ebx,%eax
+ movl %eax,%edi
+
+ movl $init_pgt-KRNLADDR,%eax
+ addl $7,%eax
+ movl $BOOT_INIT_PAGETBL_CNT,%ecx
2:
-
- ljmp $0x08,$Label
+ stosl
+ addl $0x1000,%eax
+ loop 2b
+
+ # Init Page Table
+ movl $init_pgt-KRNLADDR,%ebx
+ movl %ebx,%edi
+ movl $(BOOT_INIT_PAGETBL_CNT*1024),%ecx
+ movl $0x07,%eax
+ cld
+3:
+ stosl
+ addl $0x1000,%eax
+ loop 3b
+
+ movl $init_pgd-KRNLADDR,%ebx
+ movl %ebx,%cr3
+
+ # enable PG
+ movl %cr0,%eax
+ orl $0x80000000,%eax
+ movl %eax,%cr0
+
+
+ jmp 4f
+4:
+
+ ljmp $0x08,$Label
Label:
- call CheckKernel
- addl $8,%esp
- call KernelEntry
+ call CheckKernel
+ addl $8,%esp
+ call KernelEntry
-Die: jmp Die # Should never come to here.
+Die:
+ jmp Die # Should never come to here.
.align 32
BootGDT:
-EMPT: .long 0x00000000,0x00000000
-Code: .long 0x0000FFFF,0x00CF9B00
-Data: .long 0x0000FFFF,0x00CF9300
+EMPT: .long 0x00000000, 0x00000000
+Code: .long 0x0000FFFF, 0x00CF9B00
+Data: .long 0x0000FFFF, 0x00CF9300
BootGDTEnd:
GDTR:
- GDTRLimit: .word BootGDTEnd-BootGDT
- GDTRBase: .long BootGDT-KRNLADDR
+ GDTRLimit: .word BootGDTEnd-BootGDT
+ GDTRBase: .long BootGDT-KRNLADDR
- .comm stack, MULTIBOOT_STACK_SIZE
+ .comm stack, MULTIBOOT_STACK_SIZE
/*
* ------------------------------------------------------------------------
- * File Name: bootparam.h
+ * File Name: boot.h
* Author: Zhao Yanbai
* Sat Mar 29 09:02:21 2014
* Description: none
#include "multiboot.h"
-#define E820_RAM 1
-#define E820_RESERVED 2
-#define E820_ACPI 3
-#define E820_NVS 4
-#define E820_UNUSABLE 5
+#define BOOT_INIT_PAGETBL_CNT 2
-#define E820_MAP_CNT 128
+#ifndef ASM
+
+#define E820_RAM 1
+#define E820_RESERVED 2
+#define E820_ACPI 3
+#define E820_NVS 4
+#define E820_UNUSABLE 5
+
+#define E820_MAP_CNT 128
struct e820_entry {
unsigned long addr;
};
extern struct boot_params boot_params;
+
+#endif
#pragma once
+#include <page.h>
void *alloc_bootmem(unsigned long size, unsigned long align);
+
+#define bootmem_alloc_pages(n) alloc_bootmem((n)*PAGE_SIZE, PAGE_SIZE)
+
#include<list.h>
-#define PAGE_ITEMS (PAGE_SIZE/sizeof(unsigned long))
+typedef unsigned long pde_t;
+typedef unsigned long pte_t;
+
+#define PDECNT_PER_PAGE (PAGE_SIZE/sizeof(pde_t))
+#define PTECNT_PER_PAGE (PAGE_SIZE/sizeof(pte_t))
+
+#define PAGE_ITEMS (PAGE_SIZE/sizeof(unsigned long))
#define PAGE_ALIGN(page) (page & PAGE_MASK)
#define PAGE_UP(page) (((unsigned long)page + PAGE_SIZE -1) & PAGE_MASK)
#define PAGE_DOWN PAGE_ALIGN
#define PFN_UP(addr) (((addr) + PAGE_SIZE - 1) >> PAGE_SHIFT)
#define PFN_DW(addr) ((addr) >> PAGE_SHIFT)
+
+#define LOAD_CR3(pde) asm("movl %%edx, %%cr3"::"d"(va2pa(pde)))
+
#define MAX_ORDER (11)
typedef struct page
#include<types.h>
#include<bits.h>
#include<mm.h>
-#include<boot/bootparam.h>
+#include<init.h>
+#include<boot/boot.h>
extern char kernel_begin, kernel_end;
#define pfn2inx(pfn) ((pfn) - bootmem_data.min_pfn)
#define inx2pfn(inx) ((inx) + bootmem_data.min_pfn)
+
void e820_init_bootmem_data()
{
unsigned int i=0;
void reserve_bootmem(unsigned long bgn_inx, unsigned long end_inx)
{
- printk("reserve %d %d\n", bgn_inx, end_inx);
+ //printk("reserve %d %d\n", bgn_inx, end_inx);
int i=0;
for(i=bgn_inx; i<end_inx; ++i)
e820_init_bootmem_data();
init_bootmem_allocator();
+#if 0
printk("alloc 10 bytes align 8 addr %08x\n", alloc_bootmem(10, 8));
printk("alloc 40961 bytes align 4096 addr %08x\n", alloc_bootmem(40961, 4096));
printk("alloc 5 bytes align 4 addr %08x\n", alloc_bootmem(5, 4));
printk("alloc 10 bytes align 1024 addr %08x\n", alloc_bootmem(10, 1024));
printk("alloc 123bytes align 2 addr %08x\n", alloc_bootmem(123, 2));
printk("alloc 123bytes align 2 addr %08x\n", alloc_bootmem(123, 2));
+#endif
}
unsigned long align_bootmem_index(unsigned long inx, unsigned long align)
return 0;
}
-void init_mm()
+
+
+pde_t __initdata init_pgd[PDECNT_PER_PAGE] __attribute__((__aligned__(PAGE_SIZE)));
+pte_t __initdata init_pgt[PTECNT_PER_PAGE*BOOT_INIT_PAGETBL_CNT] __attribute__((__aligned__(PAGE_SIZE)));
+
+void init_paging()
{
+ unsigned long di, ti;
+ unsigned long *pde, *pte;
+ unsigned long pde_end = (pfn2pa(bootmem_data.max_pfn) >> 22);
+
+ for(di=BOOT_INIT_PAGETBL_CNT; di<pde_end; ++di)
+ {
+ pde = init_pgd + di;
+
+ if(di >= pde_end)
+ {
+ *pde = 0;
+ continue;
+ }
+ unsigned long pt_addr = (unsigned long) va2pa(bootmem_alloc_pages(1));
+
+ *pde = pt_addr | 7;
+ *(pde + (PAGE_OFFSET>>20)) = *pde; // for kernel paging
+
+ for(ti=0; ti<PTECNT_PER_PAGE; ++ti)
+ {
+ unsigned long page = (di << 22) | (ti << 12);
+
+ pte = ((pte_t *) pa2va(pt_addr)) + ti;
+
+ *pte = page | 7;
+ //printk("pde %08x pte %08x pt_addr %08x page %08x\n", pde, pte, pt_addr, page);
+ }
+ }
+
+ LOAD_CR3(init_pgd);
+}
+
+void init_mm()
+{
+ init_bootmem();
+ init_paging();
}
#include<assert.h>
#include<printk.h>
#include<init.h>
-
-#define INIT_PAGE_TABLE_CNT 2
-
-char __initdata init_pgd[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
-char __initdata init_pgt[PAGE_SIZE*INIT_PAGE_TABLE_CNT] __attribute__((__aligned__(PAGE_SIZE)));
-
-
-void init_paging()
-{
- system.page_dir = (u32 *) init_pgd;
-
- int i;
- unsigned long kernel_pde_base = KRNLADDR>>22;
- for(i=0; i<kernel_pde_base; ++i)
- {
- system.page_dir[i] = 0;
- }
-
- for(i=kernel_pde_base + INIT_PAGE_TABLE_CNT; i<1024; ++i)
- {
-
- }
-}
+#include<mm.h>
#define get_page_from_list(pList) list_entry(pList, Page, list)
/*
*--------------------------------------------------------------------------
- * File Name: setup.c
+ * File Name: setup.c
*
- * Description: none
+ * Description: none
*
*
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
+ * Author: Zhao Yanbai [zhaoyanbai@126.com]
*
- * Version: 1.0
+ * Version: 1.0
* Create Date: Wed Mar 4 20:34:36 2009
* Last Update: Wed Mar 4 20:34:36 2009
*
#include<printk.h>
#include<system.h>
-extern void setup_gdt();
-extern void setup_idt();
-extern void setup_gate();
-extern void detect_cpu();
-extern void setup_sysc();
-extern void setup_pci();
-extern void set_tss();
-extern void show_logo();
-//extern void setup_tTasks();
-extern void setup_tasks();
-extern void setup_root_dev();
-extern void setup_hd();
-extern void setup_fs();
-extern void setup_ext2();
+extern void setup_gdt();
+extern void setup_idt();
+extern void setup_gate();
+extern void detect_cpu();
+extern void setup_sysc();
+extern void setup_pci();
+extern void set_tss();
+extern void show_logo();
+//extern void setup_tTasks();
+extern void setup_tasks();
+extern void setup_root_dev();
+extern void setup_hd();
+extern void setup_fs();
+extern void setup_ext2();
extern unsigned long mb_mm_lower, mb_mm_upper;
extern unsigned long mb_mmap_addr, mb_mmap_size;
void setup_kernel()
{
- extern char _start, _end;
+ extern char _start, _end;
- printk("kernel:\t%08x - %08x\n", &_start,
- &_end);
+ printk("kernel:\t%08x - %08x\n", &_start, &_end);
- setup_gdt();
- setup_idt();
- setup_gate();
+ init_mm();
- detect_cpu();
+ while(1);
- //setup_tTasks();
- init_mm();
+ setup_gdt();
+ setup_idt();
+ setup_gate();
- setup_irqs();
- set_tss();
- setup_sysc();
- setup_pci();
+ detect_cpu();
+
+ //setup_tTasks();
+
+ setup_irqs();
+ set_tss();
+ setup_sysc();
+ setup_pci();
while(1); // TODO MODIFY CODE BELOW
- setup_tasks();
+ setup_tasks();
- setup_root_dev();
- setup_hd();
- setup_fs();
- setup_ext2();
+ setup_root_dev();
+ setup_hd();
+ setup_fs();
+ setup_ext2();
- show_logo();
+ show_logo();
}