diff options
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | bochsrc | 7 | ||||
| -rw-r--r-- | boot/disk_load_16.asm | 7 | ||||
| -rw-r--r-- | boot/mbr.asm | 28 | ||||
| -rw-r--r-- | boot/mp.asm | 4 | ||||
| -rw-r--r-- | boot/pm.asm | 2 | ||||
| -rw-r--r-- | data/fill.asm | 2 | ||||
| -rw-r--r-- | data/floppy.img | bin | 1474560 -> 1474560 bytes | |||
| -rw-r--r-- | kernel/config.h | 2 | ||||
| -rw-r--r-- | kernel/floppy.c | 1 | ||||
| -rw-r--r-- | kernel/interrupts.c | 24 | ||||
| -rw-r--r-- | kernel/kernel.c | 26 | ||||
| -rw-r--r-- | kernel/mem.c | 5 | ||||
| -rw-r--r-- | kernel/smp.c | 2 | ||||
| -rw-r--r-- | kernel/task.c | 46 | ||||
| -rw-r--r-- | kernel/x86.c | 12 |
16 files changed, 113 insertions, 74 deletions
@@ -14,17 +14,19 @@ ############ some constants ############ #lets use the size of a 1.44 floppy for a start for our boot img -IMAGE_SIZE=1474560 +IMAGE_SIZE=1474560 #floppy #ap bin : -MP_IMG_START=25088 +MP_IMG_START=26112 #multiboot is initially at 0x6600 #font data starts here: -FONT_DATA_START=26624 +FONT_DATA_START=26624 #fool font initially at 0x6800 USB_STICK=/dev/sdd +KERNEL_START=0x10000 + ############ flags ############ @@ -81,7 +83,7 @@ all: FoolOS.img # the kernel_entry.o needs to be FIRST!! kernel.bin: $(KERNEL_ENTRY) $(ASMOBJECTS) $(OBJECTS) - ld -o $@ -Ttext 0x1000 --oformat binary -melf_i386 $^ -O0 # --gc-sections --entry=kernel_main -v + ld -o $@ -Ttext $(KERNEL_START) --oformat binary -melf_i386 $^ -O0 # --gc-sections --entry=kernel_main -v ############ fool-font ############ @@ -127,5 +129,10 @@ stick: FoolOS.img - - +##### floppy operations ####### +floppy_losetup_on: + sudo losetup /dev/loop0 data/floppy.img +floppy_losetup_off: + sudo losetup -d /dev/loop0 +floppy_init: + sudo dd if=/dev/zero of=data/floppy.img count=2880 bs=512 @@ -299,7 +299,7 @@ vga: extension=cirrus # The optional parameter 'write_protected' can be used to control the media # write protect switch. By default it is turned off. #======================================================================= -floppya: 1_44=./FoolOS.img, status=inserted +floppya: 1_44=FoolOS.img, status=inserted #floppya: image=../1.44, status=inserted #floppya: 1_44=/dev/fd0H1440, status=inserted #floppya: 1_2=../1_2, status=inserted @@ -377,7 +377,8 @@ floppya: 1_44=./FoolOS.img, status=inserted # The biosdetect option has currently no effect on the bios # # Examples: - ata0-master: type=disk, mode=flat, path=FoolOS.img, cylinders=10, heads=4, spt=18 +# ata0-master: type=disk, mode=flat, path=FoolOS.img, cylinders=10, heads=4, spt=18 +# ata0-master: type=disk, mode=flat, path=disk.img # ata0-slave: type=disk, mode=flat, path=20M.sample, cylinders=615, heads=4, spt=17 # ata1-master: type=disk, mode=flat, path=30M.sample, cylinders=615, heads=6, spt=17 # ata1-slave: type=disk, mode=flat, path=46M.sample, cylinders=940, heads=6, spt=17 @@ -405,7 +406,7 @@ floppya: 1_44=./FoolOS.img, status=inserted #======================================================================= #boot: floppy #boot: disk -boot: disk +boot: floppy #======================================================================= # CLOCK: diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm index fd05889..2fa88ee 100644 --- a/boot/disk_load_16.asm +++ b/boot/disk_load_16.asm @@ -34,6 +34,9 @@ disk_load_16: ; int 0x13 ;bios interrupt + mov bx, DISK_LOAD + call print_string + popa ret @@ -61,8 +64,8 @@ lba_adr: dw 53 ; number of sectors to read - dw 0x1000 ; target addr. - dw 0 ; + dw 0x0000 ; target addr. offset + dw 0x1000 ; target addr. sector dd 1 ; first sector to read dd 0 ; diff --git a/boot/mbr.asm b/boot/mbr.asm index 8483705..4513100 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -10,7 +10,7 @@ ; ; * BOOT_DRIVE set ; -; * 52 sectors of our kernel loaded at KERNEL_OFFSET from floppy +; * X sectors of our kernel loaded at KERNEL_OFFSET from floppy ; ; * memory map made available at MEMMAP_OFFSET ; (check at MEMMEP_SIZE_OFFSET for number of entries) @@ -45,12 +45,15 @@ ;;where we will load our kernel into memory and some ;;other memory locations ; -KERNEL_OFFSET equ 0x1000 +KERNEL_SECTOR equ 0x1000 +KERNEL_OFFSET equ 0x0000 + MEMMAP_SIZE_OFFSET equ 0x7c00+0x600 MEMMAP_OFFSET equ 0x7c00+0x400 VESA_MODES equ 0x8300 VESA_MODE_INFO equ 0x8400 VESA_MODE_SELECT equ 0x4114 + ; jmp boot_16 ;start boot process db 'X' @@ -94,22 +97,27 @@ CHECK_A20: [bits 16] ; boot_16: + + + + ;first of allsetup the stack (Right under mbr) + ;guaranteed ~30KB space + mov bp,0x07bff + mov sp,bp ; ; mov bx, STR_VERSION call print_string ; -; -; ;setup the stack - mov bp,0x8000 - mov sp,bp -; ; ;remember BOOT_DRIVE (as was set by BIOS) mov [BOOT_DRIVE],dl ; -; ;Load the KERNEL (52 sectors starting at sector 2) +; ;Load the KERNEL (sectors starting at sector 2) + mov ax,KERNEL_SECTOR + mov es,ax mov bx,KERNEL_OFFSET - mov dh, 53 ; for lba mode this is hardcoded anyway + + mov dh, 53 ; for lba mode this is hardcoded anyway mov dl, [BOOT_DRIVE] call disk_load_16 @@ -160,7 +168,7 @@ boot_32_pm: ; call kernel! mov eax,0 ;booting processor - call KERNEL_OFFSET ;jump into our Kernel! + call 0x10000 ;KERNEL_SECTOR:KERNEL_OFFSET ;jump into our Kernel! ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; diff --git a/boot/mp.asm b/boot/mp.asm index 497a0a8..0e1ec7f 100644 --- a/boot/mp.asm +++ b/boot/mp.asm @@ -1,6 +1,6 @@ ; other processors will enter here! -[org 0x7000] +[org 0x9000] jmp switch_to_pm @@ -38,4 +38,4 @@ boot_32_pm: mov eax,1 ; - call 0x1000 ;jump into our Kernel! + call 0x10000 ;jump into our Kernel! diff --git a/boot/pm.asm b/boot/pm.asm index 2d3d343..e6f3474 100644 --- a/boot/pm.asm +++ b/boot/pm.asm @@ -30,7 +30,7 @@ init_pm: mov fs, ax mov gs, ax - mov ebp, 0x90000 + mov ebp, 0x07bff mov esp, ebp call boot_32_pm ;continue booting in 32-bit protected mode diff --git a/data/fill.asm b/data/fill.asm index 0d40c24..d731efc 100644 --- a/data/fill.asm +++ b/data/fill.asm @@ -7,4 +7,4 @@ ; ; -times 2000000 db 0xff +times 2000000 db 0x69 diff --git a/data/floppy.img b/data/floppy.img Binary files differindex d798737..6b4dc22 100644 --- a/data/floppy.img +++ b/data/floppy.img diff --git a/kernel/config.h b/kernel/config.h new file mode 100644 index 0000000..15d2121 --- /dev/null +++ b/kernel/config.h @@ -0,0 +1,2 @@ +#define FOOLOS_COMPILE_FLOPPY + diff --git a/kernel/floppy.c b/kernel/floppy.c index e00e96b..355801c 100644 --- a/kernel/floppy.c +++ b/kernel/floppy.c @@ -17,6 +17,7 @@ */ #define FOOLOS_MODULE_NAME "floppy" +#include "config.h" #ifdef FOOLOS_COMPILE_FLOPPY diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 0852812..198fe11 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -27,19 +27,6 @@ static struct idt_desc } idtd; -// disable interrupts -void int_disable() -{ - __asm__("cli"); -} - -// enable interrupts -void int_enable() -{ - __asm__("sti"); - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"up and running"); -} - void int_generate88() { @@ -102,11 +89,10 @@ void int_irq18(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Machine Check"); X8 void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr) { - uint64_t base=(uint64_t)&(*addr); // TODO! + uint64_t base=(uint64_t)&(*addr); idt[irq].addrLo = base & 0xffff; idt[irq].addrHi = (base >> 16) & 0xffff; - idt[irq].addrHi = 0x0; idt[irq].zeros=0; idt[irq].flags=flags; idt[irq].sel=sel; @@ -150,13 +136,13 @@ void int_init(uint16_t sel) void int_install() { + idtd.size=sizeof(struct int_desc)*INT_MAX; - idtd.size=sizeof(struct int_desc)*INT_MAX; //TODO - idtd.baseHi=0x0000; - idtd.baseLo=&idt[0]; + uint32_t addr=&idt[0]; + idtd.baseHi=addr>>16; + idtd.baseLo=0xffff&addr; __asm__("lidt %0"::"m" (idtd)); - } /* //print interrupt table; //TODO! diff --git a/kernel/kernel.c b/kernel/kernel.c index e85b298..b2af08d 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -47,7 +47,20 @@ void kernel_main(uint32_t initial_stack, int mp) proc=0; + // move the foolfont and aps code before it gets overwritten! + uint8_t *source=0x16600; + uint8_t *dest=0x80000; + for(int i=0;i<2*512;i++) + { + dest[i]=source[i]; + } + source=0x16400; + dest=0x9000; + for(int i=0;i<1*512;i++) + { + dest[i]=source[i]; + } // // We want to get output to the screen as fast as possible! @@ -69,7 +82,8 @@ void kernel_main(uint32_t initial_stack, int mp) // our video memory // - uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7600); + //uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x7600); + uint32_t vesa_physbase=vesa_init(0x8300,0x8400,0x80000); // @@ -103,8 +117,6 @@ void kernel_main(uint32_t initial_stack, int mp) // we know that here, the bootloader placed the mamory map! mem_init(0x7c00+0x400,*((uint16_t *)(0x7c00+0x600))); - - // // Initialize other processors (run this before entering paged mode) // @@ -165,8 +177,9 @@ void kernel_main(uint32_t initial_stack, int mp) //int_install_ir(38, 0b10001110, 0x08,&int_floppy_handler); // now we can enable interrupts back again - int_enable(); + x86_int_enable(); + ////////////////////// // // Scan the PCI Bus @@ -200,14 +213,13 @@ void kernel_main(uint32_t initial_stack, int mp) // round robin style. // -// smp_log_procdata(&procdata1); - task_init(); + task_init(); - while(1) asm("hlt"); // // Just hang here. // + while(1)asm("hlt"); diff --git a/kernel/mem.c b/kernel/mem.c index 0f52873..9899822 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -19,7 +19,7 @@ // memory map bit array. Each bit represents a memory block //uint32_t _mmngr_memory_map[MEM_BITMAP_SIZE]; -uint32_t *_mmngr_memory_map; +uint32_t _mmngr_memory_map[MEM_BITMAP_SIZE]; static uint32_t mem_free_blocks; @@ -246,11 +246,12 @@ void mem_test(int start, int end, int steps) void mem_init(uint16_t *memmap,uint16_t entries) { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing bitmap at: %08X",_mmngr_memory_map); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries); // hardcoded memory bitmap!!??! // todo: fix! - _mmngr_memory_map=0x9000; + //_mmngr_memory_map=0x80000; mem_free_blocks=0; pmmngr_init (); diff --git a/kernel/smp.c b/kernel/smp.c index 58e37a5..2002385 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -45,7 +45,7 @@ void smp_start_aps(smp_processors *pros) sleep(10); // start proc at 0x7000; - *reg=(6<<8)|(1<<14)|0x7; // 110 SIPI + *reg=(6<<8)|(1<<14)|0x9; // 110 SIPI } } diff --git a/kernel/task.c b/kernel/task.c index b94d5e4..ebfd4a7 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -15,7 +15,7 @@ void task_test1() while(1) { c++; - while(1)PutString("task0: %d", 00,500,0b1111100000000000, (c++)); + while(1)PutString("t1: %d", 00,500,0b1111100000000000, (c++)); } } @@ -27,7 +27,20 @@ void task_test2() while(1) { c++; - while(1)PutString("task1: %d", 200,500,0b1111100000000000, (c++)); + while(1)PutString("t2: %d", 100,500,0b1111100000000000, (c++)); + + } + +} + +void task_test3() +{ + uint32_t c; + + while(1) + { + c++; + while(1)PutString("t3: %d",200,500,0b1111100000000000, (c++)); } @@ -41,8 +54,8 @@ typedef struct{ //Simple structure for a thread } Thread; -Thread Threads[2]; //Space for our simple threads. Just 2! -int CurrentTask = -1; //The thread currenlty running (-1 == none) +Thread Threads[3]; //Space for our simple threads. Just 2! +volatile int CurrentTask; //The thread currenlty running (-1 == none) void task_create(int pid,void(*thread)()) @@ -50,7 +63,7 @@ void task_create(int pid,void(*thread)()) unsigned int *stack; Threads[pid].esp0 = pmmngr_alloc_block(); - stack = (unsigned int*)Threads[pid].esp0+4000; //This makes a pointer to the stack for us + stack = (unsigned int*)Threads[pid].esp0+4095; //This makes a pointer to the stack for us log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"new task : stack: 0x%08X ", stack); //First, this stuff is pushed by the processor @@ -86,24 +99,15 @@ void task_create(int pid,void(*thread)()) uint32_t task_switch_next(uint32_t oldesp) { - if(started!=0xabcde) return oldesp; + if(CurrentTask!=-1)Threads[CurrentTask].esp0=oldesp; + CurrentTask++; + if(CurrentTask>2)CurrentTask=0; - if(CurrentTask != -1){ //Were we even running a task? - Threads[CurrentTask].esp0 =oldesp; //Save the new esp for the thread - - //Now switch what task we're on - if(CurrentTask == 0)CurrentTask = 1; - else CurrentTask = 0; - } else{ - CurrentTask = 0; //We just started multi-tasking, start with task 0 - } - - uint32_t esp=0; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"oldesp: 0x%08X saved / next task: %d (esp: 0x%08X) ",oldesp, CurrentTask,Threads[CurrentTask].esp0); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"oldesp: 0x%08X saved / next task: %d (esp: 0x%08X) ",oldesp, CurrentTask,Threads[CurrentTask].esp0); - return Threads[CurrentTask].esp0; //Return new stack pointer to ASM + return Threads[CurrentTask].esp0; //Return new stack pointer to ASM } void stack_trace(uint32_t *stack,int size) @@ -122,7 +126,9 @@ void task_init() log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init multitasking."); task_create(0,task_test1); task_create(1,task_test2); - started=0xabcde; + task_create(2,task_test3); + started=0xabcde; + CurrentTask=-1; } diff --git a/kernel/x86.c b/kernel/x86.c index 8473bcc..0b6a448 100644 --- a/kernel/x86.c +++ b/kernel/x86.c @@ -9,6 +9,18 @@ void sleep(int i) } } +// disable interrupts +void x86_int_disable() +{ + __asm__("cli"); +} + +// enable interrupts +void x86_int_enable() +{ + __asm__("sti"); +} + // get control registers (cr0-cr4) uint32_t x86_get_cr0() |
