diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | asm/pic.asm (renamed from boot/pic.asm) | 4 | ||||
| -rw-r--r-- | bochsrc | 6 | ||||
| -rw-r--r-- | boot/acer/mbr.asm | 167 | ||||
| -rw-r--r-- | boot/disk_load_16.asm | 59 | ||||
| -rw-r--r-- | boot/mbr.asm | 140 | ||||
| -rw-r--r-- | kernel/kernel.c | 18 |
7 files changed, 154 insertions, 247 deletions
@@ -21,6 +21,9 @@ IMAGE_SIZE=1474560 FONT_DATA_START=25600 +USB_STICK=/dev/sdc + + ############ flags ############ CFLAGS=-ffreestanding -std=gnu99 -m32 -fno-asynchronous-unwind-tables -O0 @@ -105,8 +108,8 @@ clean: ############ test stuff ############ acer: FoolOS.img - cat FoolOS.img > /dev/sdf && sync - xxd /dev/sdf | head -n 50 + cat FoolOS.img > $(USB_STICK) && sync + xxd $(USB_STICK) | head -n 50 diff --git a/boot/pic.asm b/asm/pic.asm index 5724af6..28b484c 100644 --- a/boot/pic.asm +++ b/asm/pic.asm @@ -1,6 +1,10 @@ ;************************************************************************ ; Map the 8259A PIC to use interrupts 32-47 within our interrupt table ;************************************************************************ + +[bits 32] + +global pic_setup %define ICW_1 0x11 ; 00010001 binary. Enables initialization mode and we are sending ICW 4 @@ -330,7 +330,7 @@ floppya: 1_44=./FoolOS.img, status=inserted # ata0 and ata1 are enabled by default with the values shown below # # Examples: -# ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 + ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 # ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 # ata2: enabled=1, ioaddr1=0x1e8, ioaddr2=0x3e0, irq=11 # ata3: enabled=1, ioaddr1=0x168, ioaddr2=0x360, irq=9 @@ -381,7 +381,7 @@ 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=10M.sample, cylinders=306, heads=4, spt=17 + ata0-master: type=disk, mode=flat, path=FoolOS.img, cylinders=10, heads=4, spt=18 # 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 @@ -409,7 +409,7 @@ floppya: 1_44=./FoolOS.img, status=inserted #======================================================================= #boot: floppy #boot: disk -boot: floppy +boot: disk #======================================================================= # CLOCK: diff --git a/boot/acer/mbr.asm b/boot/acer/mbr.asm deleted file mode 100644 index b3ae034..0000000 --- a/boot/acer/mbr.asm +++ /dev/null @@ -1,167 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; -; THE FOOL-BOOT-LOADER -; -; So we have just been loaded by the BIOS and are in 16-bits real mode! -; Now the following work will bee accomplished (chronologically): -; -; * BOOT_DRIVE set -; -; * 50 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) -; -; * the VESA mode specified by VESA_MODE_SELECT will be set up -; (check at VESA_MODES, and VESA_MODE_INFO -; for additional information) -; -; * interrupts disabled -; -; * 32-bit protected mode set up. -; -; * esp set to 0x90000 (Todo: take care of it!?) -; -; * A20 gate opened (Todo: really necessary?) -; -; * PICs configured -; -; * and finally we will jump into the C world to kernel_main() ! -; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;we want 16-bit instructions, before we switch to 32-bit protected mode. -[bits 16] - -;define origin of boot record in memory: 0x7c00 -;this is where the BIOS per definition will put the first -;512 bytes of data from the boot device -;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?) -[org 0x7c00] - -;;define some constants -;;where we will load our kernel into memory and some -;;other memory locations -; -KERNEL_OFFSET equ 0x1000 -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 -;VESA_MODE_SELECT equ 0x0 -; -jmp boot_16 ;start boot process -; -;;SOME Global Data, mainly info/error strings -BOOT_DRIVE: - db 0xff -STR_VERSION: - db "v0.3.1~",0 -VESA_CHECK1: - db " V1.",0 -VESA_CHECK2: - db " V2",0 -VESA_CHECK3: - db " V3",0 -CHECK_A20: - db " A20",0 -; -;;lets put our temporary GDT (Global Descriptor Table) here -;;kernel should move this away -%include "boot/GDT.asm" -; -;;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20) -%include "boot/disk_load_16.asm" -;%include "boot/check_a20_16.asm" -%include "boot/print_string_16.asm" -%include "boot/vesa_setup_16.asm" -; -;;include our routines for switching to 32-bit protected mode -%include "boot/pm.asm" -; -;;pic_setup mapping routing -%include "boot/pic.asm" -; -;;get memory map routine -%include "boot/memmap.asm" -; -;;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; -;;lets start -[bits 16] -; -boot_16: -; -; - 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) - mov bx,KERNEL_OFFSET - mov dh, 52 - mov dl, [BOOT_DRIVE] - call disk_load - - mov bx, KERNEL_OFFSET - call print_string - -; -; ;get memory map from bios before we enter 32 bit protected mode - mov ax,0 ; set target address in es:di (0:offset) - mov es,ax - mov di,MEMMAP_OFFSET - call BiosGetMemoryMap ; this will also put the number of entries -; ; of the memory map at MEMMAP_SIZE_OFFSET -; -;a20check: -; -; mov bx, CHECK_A20 -; call print_string -; -; call check_a20 -; cmp ax,0 -; je a20check ;hang if a20 is disabled! -; -; ;VESA: also setup vesa stuff before entering 32 bit protected mode - call VesaSetup -; -; ;finally lets enter Protected mode!!! - call switch_to_pm -; -;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -[bits 32] -boot_32_pm: -; -;; we could do ALL This inside the kernel!!!!!! TODO -; -; ;enable A20 -; ;http://www.brokenthorn.com/Resources/OSDev9.html -; ;Method 3.1: Enables A20 through keyboard controller -; ;Not all keyboard controllers support this -; ;todo: check if this has any effect at all !?!? - mov al, 0xdd ; command 0xdd: enable a20 -; ;mov al, 0xdf ; command 0xdf: disable a20 - out 0x64, al ; send command to controller - -; -; ;pic setup - call pic_setup - -; - call KERNEL_OFFSET ;jump into our Kernel! -; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; -;so we get identified as MBR -times 510-($-$$) db 0x0 -dw 0xaa55 - diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm index 3d0951d..a96ad11 100644 --- a/boot/disk_load_16.asm +++ b/boot/disk_load_16.asm @@ -8,19 +8,76 @@ [bits 16] +DISK_LOAD_HANG_MSG: + db " D",0 ;disk_load routune (load dh sectors from drive dl to es:bx) disk_load: pusha + +; mov ah,0x41 +; mov bx,0x55AA +; ;mov dl,[disk] +; int 0x13 +; jne disk_load_hang + + + ;mov ah,0x42 + ; llea si,[lbaadr] + ; int 0x13 +; cmp ah,0x00 ; check for error +; jne disk_load_hang + + ; check if LBA is supported + pusha + mov ah,0x41 + mov bx,0x55aa + int 0x13 + jnc disk_load_lba + popa mov ah,0x02 ;BIOS read sector func mov al,dh ;read dh sectors (amount) mov ch,0x00 ;cyl 0 mov dh,0x00 ;head 0 mov cl,0x02 ;start at sector 2 - +; int 0x13 ;bios interrupt +; jc disk_load_hang + + popa + ret + +disk_load_lba: + popa + + xor ah,ah + mov ah,0x42 + lea si,[lbaadr] + int 0x13 + jc skip_print + + mov bx, 0x1000 + call print_string + + skip_print: popa ret +lbaadr: +dw 0x10 +dw 52 +dw 0x1000 +dw 0 +dd 1 +dd 0 + +; +;lbaadr: +; dw 0x0010 ; 2byte, reserved - size of packet. +; dw 0x0010 ; WORD 2bytes nr of blocks read. +; dd 0x00001000 ; DWORD 4bytes Transfer buffer +; ; dq 0x0000000034009605 ; QWORD 4bytes,32bit LBA address +; dq 0x0000000000000000 + diff --git a/boot/mbr.asm b/boot/mbr.asm index 96fc788..bb74d23 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -39,121 +39,115 @@ ;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?) [org 0x7c00] -;define some constants -;where we will load our kernel into memory and some -;other memory locations - +;;define some constants +;;where we will load our kernel into memory and some +;;other memory locations +; KERNEL_OFFSET equ 0x1000 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 -;VESA_MODE_SELECT equ 0x0 - +; jmp boot_16 ;start boot process - -;SOME Global Data, mainly info/error strings +; +;;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff STR_VERSION: - db "v0.3.1~",0 + db "v0.4",0 VESA_CHECK1: - db " V1.",0 + db "1",0 VESA_CHECK2: - db " V2",0 + db "2",0 VESA_CHECK3: - db " V3",0 + db "3",0 CHECK_A20: - db " A20",0 - -;lets put our temporary GDT (Global Descriptor Table) here -;kernel should move this away + db "A",0 +; +;;lets put our temporary GDT (Global Descriptor Table) here +;;kernel should move this away %include "boot/GDT.asm" - -;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20) +; +;;include 16-bit real mode routines (print_string, disk_load, vesa_setup,check_a20) %include "boot/disk_load_16.asm" -%include "boot/check_a20_16.asm" +;%include "boot/check_a20_16.asm" %include "boot/print_string_16.asm" %include "boot/vesa_setup_16.asm" - -;include our routines for switching to 32-bit protected mode +; +;;include our routines for switching to 32-bit protected mode %include "boot/pm.asm" - -;pic_setup mapping routing -%include "boot/pic.asm" - -;get memory map routine +; +; +;;get memory map routine %include "boot/memmap.asm" - -;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;lets start +; +;;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +;;lets start [bits 16] - +; boot_16: - +; +; mov bx, STR_VERSION call print_string - - ;setup the stack +; +; +; ;setup the stack mov bp,0x8000 mov sp,bp - - ;remember BOOT_DRIVE (as was set by BIOS) +; +; ;remember BOOT_DRIVE (as was set by BIOS) mov [BOOT_DRIVE],dl - - ;Load the KERNEL (52 sectors starting at sector 2) +; mov bx, BOOT_DRIVE +; call print_string +; +; ;Load the KERNEL (52 sectors starting at sector 2) mov bx,KERNEL_OFFSET mov dh, 52 mov dl, [BOOT_DRIVE] call disk_load - ;get memory map from bios before we enter 32 bit protected mode + mov bx, KERNEL_OFFSET + call print_string + +; +; ;get memory map from bios before we enter 32 bit protected mode mov ax,0 ; set target address in es:di (0:offset) mov es,ax mov di,MEMMAP_OFFSET call BiosGetMemoryMap ; this will also put the number of entries - ; of the memory map at MEMMAP_SIZE_OFFSET - -a20check: - - mov bx, CHECK_A20 - call print_string - - call check_a20 - cmp ax,0 - je a20check ;hang if a20 is disabled! - - ;VESA: also setup vesa stuff before entering 32 bit protected mode +; ; of the memory map at MEMMAP_SIZE_OFFSET +; +;a20check: +; +; mov bx, CHECK_A20 +; call print_string +; +; call check_a20 +; cmp ax,0 +; je a20check ;hang if a20 is disabled! +; +; ;VESA: also setup vesa stuff before entering 32 bit protected mode call VesaSetup - - ;finally lets enter Protected mode!!! +; +; ;finally lets enter Protected mode!!! call switch_to_pm - -;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [bits 32] boot_32_pm: +; -; we could do ALL This inside the kernel!!!!!! TODO - - ;enable A20 - ;http://www.brokenthorn.com/Resources/OSDev9.html - ;Method 3.1: Enables A20 through keyboard controller - ;Not all keyboard controllers support this - ;todo: check if this has any effect at all !?!? - ;mov al, 0xdd ; command 0xdd: enable a20 - ;mov al, 0xdf ; command 0xdf: disable a20 - ;out 0x64, al ; send command to controller - - ;pic setup - call pic_setup - +; call KERNEL_OFFSET ;jump into our Kernel! - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ;so we get identified as MBR -times 510-($-$$) db 0 +times 510-($-$$) db 0x0 +;dw 0x0 dw 0xaa55 diff --git a/kernel/kernel.c b/kernel/kernel.c index 5844f49..ebb3841 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -50,7 +50,6 @@ void show_error(uint32_t err) void int_irq13() { X86_IRQ_BEGIN - uint32_t err; asm("pop %eax"); // get Error Code @@ -68,6 +67,17 @@ void int_irq16(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Coprocessor error"); void int_irq17(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Alignment Check"); X86_IRQ_END } void int_irq18(){ X86_IRQ_BEGIN panic(FOOLOS_MODULE_NAME,"Machine Check"); X86_IRQ_END } +void enable_a20() +{ +//; ;enable A20 +//; ;http://www.brokenthorn.com/Resources/OSDev9.html +//; ;Method 3.1: Enables A20 through keyboard controller +//; ;Not all keyboard controllers support this + asm("mov $0xdd, %al");// ; command 0xdd: enable a20 +//; ;mov al, 0xdf ; command 0xdf: disable a20 + asm("outb %al, $0x64");// ; send command to controller +} + // heart of our operating system. void kernel_main(uint32_t initial_stack) { @@ -96,6 +106,12 @@ void kernel_main(uint32_t initial_stack) // initial stack log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"enable A20"); + enable_a20(); + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setup PIC"); + pic_setup(); + // PIT config (timer) timer_init(); |
