diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-10-24 01:42:05 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-10-24 01:42:05 +0200 |
| commit | 831df8bcb2717442a41464533bacf0a58a4af0ce (patch) | |
| tree | 5422b40b6d303a709dac5c6cf6a386df9e071227 | |
| parent | 01c79415ed46f645f46287ce3b033943fb9dcb1e (diff) | |
working on bootloader (extended mem) (broken!)
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | boot/GDT.asm | 26 | ||||
| -rw-r--r-- | boot/disk_load_16.asm | 9 | ||||
| -rw-r--r-- | boot/stage2.asm | 108 | ||||
| -rw-r--r-- | data/fill.asm | 3 |
5 files changed, 130 insertions, 18 deletions
@@ -102,7 +102,7 @@ FoolOS.img: $(MBR) $(STAGE2) kernel.bin $(FILLUP) FoolData.img cp $(FILLUP) $@ dd if=$(MBR) of=$@ bs=512 seek=0 conv=notrunc dd if=$(STAGE2) of=$@ bs=512 seek=1 conv=notrunc - dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc #will end up at 0x18000 in ram + dd if=kernel.bin of=$@ bs=512 seek=10 conv=notrunc #will end up at 0x18000 in ram (this is what the booloader starts loading secotr: 10) dd if=FoolData.img of=$@ bs=512 seek=842 conv=notrunc binfont.img: binfont.bin diff --git a/boot/GDT.asm b/boot/GDT.asm index df76210..cc33c45 100644 --- a/boot/GDT.asm +++ b/boot/GDT.asm @@ -24,7 +24,7 @@ gdt_code: ; flags: ; present: 1 / privilege: 00 / type: 1 ; code: 1 / conforming: 0 / readable: 1 / accessed: 0 - ; granularity: 1 / 32-bit default: 1 / 64-bit seg: 0 / AVL: 0 + ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0 dw 0xffff ;limit dw 0x0 ;base db 0x0 ;base @@ -39,6 +39,28 @@ gdt_data: dw 0x0 db 0x0 db 10010010b + db 10001111b + db 0x0 + +gdt16_code: + ; flags: + ; present: 1 / privilege: 00 / type: 1 + ; code: 1 / conforming: 0 / readable: 1 / accessed: 0 + ; granularity: 1 / 16-bit default: 1 / 64-bit seg: 0 / AVL: 0 + dw 0xffff ;limit + dw 0x0 ;base + db 0x0 ;base + db 10011010b ;flags + db 10001111b ;flags & seg.limit + db 0x0 ;base + +gdt16_data: + ; flags: + ; code: 0 / expand down: 0 / writable: 1 / accessed: 0 + dw 0xffff + dw 0x0 + db 0x0 + db 10010010b db 11001111b db 0x0 @@ -50,3 +72,5 @@ gdt_descriptor: CODE_SEG equ gdt_code - gdt_start DATA_SEG equ gdt_data - gdt_start +CODE16_SEG equ gdt16_code - gdt_start +DATA16_SEG equ gdt16_data - gdt_start diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm index fe573ea..78aa22b 100644 --- a/boot/disk_load_16.asm +++ b/boot/disk_load_16.asm @@ -76,15 +76,15 @@ disk_load_lba: jc disk_read_error mov bx,es - add bx,0x0200 - cmp bx,0x9e00 + add bx,0x0800 + cmp bx,0x9000 je disk_load_finish mov es,bx mov bx,0 mov ax,[LBA] - add ax,16 + add ax,64 ; 64 sectors = 0x2000*4 bytes ;16 sectors this is 0x200*0x10 butes mov [LBA],ax jmp next_sectors_lba @@ -157,6 +157,7 @@ disk_load_chs: ;calculate chs call lba_to_chs + ; and now READ it! mov al,16 ;number of sectors to read mov dl,[BOOT_DRIVE] @@ -221,7 +222,7 @@ lba_to_chs: lba_adr: dw 0x10 ; size of packet ( 16 byte) - dw 16 ; number of sectors to read + dw 64 ; number of sectors to read ; target is 0x10000 diff --git a/boot/stage2.asm b/boot/stage2.asm index ebc346e..3fde5c1 100644 --- a/boot/stage2.asm +++ b/boot/stage2.asm @@ -27,10 +27,10 @@ ;we want 16-bit instructions, before we switch to 32-bit protected mode. [bits 16] -;define origin of boot record in memory: 0x7c00 +;define origin of boot record in memory: 0x7c00 was bootloader0 ;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 (?) +;wer are one sector after that. [org 0x7e00] ;;define some constants @@ -49,6 +49,8 @@ jmp boot_16 ;start boot process ;;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff +KERNEL_CHUNK: + dw 0x1 STR_VERSION: db "Fool Loader Stage 2 v0.5",0 @@ -58,6 +60,8 @@ STR_BOOT: db "Boot Drive: ",0 MEMMAP_INFO: db "Getting Memory Map from BIOS.",0 +STR_PM: + db "PROTECTED MODE",0 ; ;;lets put our temporary GDT (Global Descriptor Table) here @@ -72,6 +76,11 @@ MEMMAP_INFO: ; ;;include our routines for switching to 32-bit protected mode %include "boot/pm.asm" + +;include some pm mode helpers +%include "boot/common_pm.asm" + +; ; ; ;;get memory map routine @@ -82,29 +91,27 @@ MEMMAP_INFO: ;;lets start [bits 16] +idt_real: + dw 0x3ff ; 256 entries, 4b each = 1K + dd 0 ; Real Mode IVT @ 0x0000 + boot_16: mov [BOOT_DRIVE],dl -; pr info + ;pr info mov bx, STR_VERSION call print_string call print_nextline + ;show bootdrive mov bx, STR_BOOT call print_string mov al,dl call print_hex_byte call print_nextline - ;show bootdrive - ; Load the KERNEL Image - mov bx, STR_LOAD - call print_string - call print_nextline - call disk_load_16 - ; memmap message mov bx,MEMMAP_INFO call print_string @@ -117,7 +124,13 @@ boot_16: call BiosGetMemoryMap ; this will also put the number of entries ; of the memory map at MEMMAP_SIZE_OFFSET - call VesaSetup +kernel_load: + ; Load the KERNEL Image + mov bx, STR_LOAD + call print_string + call print_nextline + call disk_load_16 + call switch_to_pm ; @@ -132,8 +145,81 @@ boot_32_pm: or al, 2 out 0x92, al + + ; tell the world we are protected + mov ebx,STR_PM + mov ecx,2*23*80 + call print_string_pm + + push edx ; persist edx for some reason!? + + mov edx,0 + mov dx,[KERNEL_CHUNK] + mov ecx,2*24*80 + call print_hex_pm + + + + ; here we should move the chunk away or stop the loop if everything loaded. + mov ax,[KERNEL_CHUNK] + add ax,1 + mov [KERNEL_CHUNK],ax + + ; here we should copy the chunk into ext mem! + + + + + ; and now go back to real! (first 16bit protected!) + cmp edx,0x20 + je finish_load + pop edx + + + + jmp CODE16_SEG:reinit_16 + finish_load: + ; + + call VesaSetup + ; call kernel! mov eax,0 ;tell the kernel ; we are the booting processor call 0x18000 ;jump into our Kernel! + +[bits 16] +reinit_16: ;16 bit protected mode + + mov eax,DATA16_SEG + mov ds,eax + mov es,eax + mov fs,eax + mov gs,eax + mov ss,eax + + + mov eax,cr0 + and eax,!0x1 ; Disable protected mode + mov cr0, eax + + jmp 0:realmode + + +realmode: + + mov sp,0x07bff + mov bp,sp + + mov ax,0 + mov ds,ax + mov es,ax + mov fs,ax + mov gs,ax + mov ss,ax + + lidt [idt_real] + + sti + jmp kernel_load diff --git a/data/fill.asm b/data/fill.asm index 216a328..ce9cb5f 100644 --- a/data/fill.asm +++ b/data/fill.asm @@ -7,4 +7,5 @@ ; ; -times 1474560 db 0x69 +;times 1474560 db 0x69 +times 14745600 db 0x69 |
