diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-09-01 13:26:52 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-09-01 13:26:52 +0200 |
| commit | 347ee926fd09d7fb45025f2c4e4a4eeab83459c9 (patch) | |
| tree | 8d082bcaebe7579fe4fa73dd6eead7c00bb051fd | |
| parent | a9682cac5f14f8d04c87d206cf1d8367e77a61e1 (diff) | |
Added kernel_entry for APs
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | boot/kernel_entry.asm | 7 | ||||
| -rw-r--r-- | boot/mbr.asm | 2 | ||||
| -rw-r--r-- | boot/mp.asm | 41 | ||||
| -rw-r--r-- | kernel/kernel.c | 26 | ||||
| -rw-r--r-- | kernel/mp.c | 2 | ||||
| -rw-r--r-- | kernel/task.c | 4 | ||||
| -rw-r--r-- | kernel/vmem.c | 4 | ||||
| -rw-r--r-- | kernel/x86.c | 5 | ||||
| -rw-r--r-- | kernel/x86.h | 1 |
11 files changed, 104 insertions, 8 deletions
@@ -16,6 +16,8 @@ #lets use the size of a 1.44 floppy for a start for our boot img IMAGE_SIZE=1474560 +#ap bin : +MP_IMG_START=25088 #font data starts at sector 50 FONT_DATA_START=25600 @@ -47,6 +49,12 @@ KERNEL_ENTRY=./boot/kernel_entry.o MBR=./boot/mbr.bin + +#multiprocessor binary entry + +MP_BIN=./boot/mp.bin + + #some fillup data (zeros) FILLUP=./data/fill.bin @@ -83,13 +91,16 @@ binfont.bin: data/binfont.src # master boot record, kernel binary and fool-font -FoolOS.img: Fool.img FoolData.img $(FILLUP) +FoolOS.img: mbr_kernel_mp.img binfont.img $(FILLUP) cat $^ | head -c $(IMAGE_SIZE) > $@ -Fool.img: $(MBR) kernel.bin $(FILLUP) +mbr_kernel_mp.img: mbr_kernel.img $(MP_BIN) $(FILLUP) cat $^ | head -c $(FONT_DATA_START) > $@ -FoolData.img: binfont.bin +mbr_kernel.img: $(MBR) kernel.bin $(FILLUP) + cat $^ | head -c $(MP_IMG_START) > $@ + +binfont.img: binfont.bin cat $^ > $@ @@ -104,7 +115,7 @@ run: FoolOS.img ############ cleanup ############ clean: - -rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) bochs.out ne2k-tx.log ne2k-txdump.txt + -rm *.bin *.img bochs.log $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) $(FILLUP) $(MBR) $(MP_BIN) bochs.out ne2k-tx.log ne2k-txdump.txt ############ test stuff ############ acer: FoolOS.img @@ -47,6 +47,7 @@ All features are only very rudiemntary and buggy. * Physical memory management * Virtual memory managment (Paging) * Multitasking (2 tasks so far) +* Multiple processors (hardcoded 2) * Floppy disk driver * VESA diff --git a/boot/kernel_entry.asm b/boot/kernel_entry.asm index adb6b51..3b1fb26 100644 --- a/boot/kernel_entry.asm +++ b/boot/kernel_entry.asm @@ -10,5 +10,12 @@ [extern kernel_main] +push 0x1 + +cmp eax,1 +je multiproc +push 0x0 +multiproc: + push esp call kernel_main ; jumps in the world of C diff --git a/boot/mbr.asm b/boot/mbr.asm index c565f33..4ece914 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -149,6 +149,8 @@ boot_32_pm: mov al, 0xdd ; command 0xdd: enable a20 ; ;mov al, 0xdf ; command 0xdf: disable a20 out 0x64, al ; send command to controller + + mov eax,0 ; call KERNEL_OFFSET ;jump into our Kernel! ; diff --git a/boot/mp.asm b/boot/mp.asm new file mode 100644 index 0000000..6c794bc --- /dev/null +++ b/boot/mp.asm @@ -0,0 +1,41 @@ +; other processors will enter here! + +[org 0x7000] + +jmp switch_to_pm + +%include "boot/GDT.asm" + +[bits 16] +switch_to_pm: + + cli ;switch off interrupts! + lgdt [gdt_descriptor] ;load descriptor table! + + ;switch on 32-bit protected mode + mov eax, cr0 + or eax,0x1 + mov cr0, eax + + jmp 0x8:init_pm + +[bits 32] +init_pm: + + mov ax, 0x10 + mov ds, ax + mov ss, ax + mov es, ax + mov fs, ax + mov gs, ax + + mov ebp, 0x95000 + mov esp, ebp + + call boot_32_pm ;continue booting in 32-bit protected mode + +boot_32_pm + + mov eax,1 +; + call 0x1000 ;jump into our Kernel! diff --git a/kernel/kernel.c b/kernel/kernel.c index 5a32c95..7bbfcce 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -21,9 +21,27 @@ uint32_t read_eip(); // this is the very heart of our operating system! // -void kernel_main(uint32_t initial_stack) +void kernel_main(uint32_t initial_stack, int mp) { + + // catch the APs (Application Processors) + if(mp==1) + { + uint16_t c3=0; + while(1) + { + + + c3++; + asm("cli"); + + PutString("cpu2: %03d", 200,560,0b1111100000000000, c3/100); + + asm("sti"); + } + } + // // We want to get output to the screen as fast as possible! // @@ -44,6 +62,7 @@ void kernel_main(uint32_t initial_stack) // our video memory // + uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7200); @@ -53,6 +72,8 @@ void kernel_main(uint32_t initial_stack) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"mp: %d",mp); + // // Initialize other processors // @@ -72,6 +93,7 @@ void kernel_main(uint32_t initial_stack) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC."); pic_setup(); + //while(1); // // Configuring the PIT timer. @@ -130,7 +152,7 @@ void kernel_main(uint32_t initial_stack) // Initialize Floppy Disk // - floppy_init(); + // floppy_init(); // diff --git a/kernel/mp.c b/kernel/mp.c index 5070b21..dd9fbd5 100644 --- a/kernel/mp.c +++ b/kernel/mp.c @@ -125,8 +125,10 @@ void show_mp_conf(mp_config *addr) //*reg=(6<<8)|(1<<14)|1; *reg=(5<<8)|(1<<14); // 101 INIT + /* uint16_t *startpos=0x7000; *startpos=0xfeeb; + */ sleep(10); diff --git a/kernel/task.c b/kernel/task.c index 1515c5b..a46ce88 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -16,7 +16,7 @@ void task_test1() c1++; asm("cli"); - PutString("task1: %03d", 0,560,0xffffff, c1/100); + PutString("cpu1 / task1: %03d", 0,560,0xffffff, c1/100); asm("sti"); } @@ -31,7 +31,7 @@ void task_test2() { c2++; asm("cli"); - PutString("task2: %03d", 0,580,0xffffff, c2/100); + PutString("cpu1 / task2: %03d", 0,580,0xffffff, c2/100); asm("sti"); } diff --git a/kernel/vmem.c b/kernel/vmem.c index b1ecfa1..8590579 100644 --- a/kernel/vmem.c +++ b/kernel/vmem.c @@ -253,11 +253,15 @@ void vmem_init(uint32_t vesa_physbase) pd_entry_set_frame (entry2, (physical_addr)table2); + + x86_set_pdbr(dir); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"enabling paging..."); x86_paging_enable(); + x86_flush_tlb(0); + x86_flush_tlb(vesa_physbase); } diff --git a/kernel/x86.c b/kernel/x86.c index cc7c303..94f4f89 100644 --- a/kernel/x86.c +++ b/kernel/x86.c @@ -50,3 +50,8 @@ void x86_paging_enable() cr0 |= 0x80000000; asm volatile("mov %0, %%cr0":: "b"(cr0)); } + +x86_flush_tlb(uint32_t addr) +{ + asm volatile("invlpg (%0)" ::"r" (addr) : "memory"); +} diff --git a/kernel/x86.h b/kernel/x86.h index 3233124..434c28c 100644 --- a/kernel/x86.h +++ b/kernel/x86.h @@ -18,5 +18,6 @@ void x86_outl(int port, uint32_t data); uint32_t x86_inl(int port); void x86_set_pdbr(uint32_t addr); void x86_paging_enable(); +void x86_flush_tlb(void* m); #endif |
