diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-08-27 03:20:16 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-08-27 03:20:16 +0200 |
| commit | 50c7bdbe826b5b425748a11273d14e3aed2ce851 (patch) | |
| tree | 8fc2bec5576aad366b6f9f3f1fcc406f6a3eeb33 /boot | |
| parent | fc7022286a14e7325907fb4e77aa44330037229b (diff) | |
many changes and adaptions and VESA mode !!
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/boot16_entry.asm | 11 | ||||
| -rw-r--r-- | boot/mbr.asm | 99 | ||||
| -rw-r--r-- | boot/mbr16.asm | 79 | ||||
| -rw-r--r-- | boot/memmap.asm | 2 | ||||
| -rw-r--r-- | boot/print16.asm | 28 |
5 files changed, 175 insertions, 44 deletions
diff --git a/boot/boot16_entry.asm b/boot/boot16_entry.asm new file mode 100644 index 0000000..e8d63be --- /dev/null +++ b/boot/boot16_entry.asm @@ -0,0 +1,11 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; this will be compiled to an object file and linked with the boot loader +; to simplify the entrance! +; +; +[bits 16] +[extern boot_main] +call boot_main ; jumps in the world of C diff --git a/boot/mbr.asm b/boot/mbr.asm index 3406b55..32f1a6f 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -21,6 +21,12 @@ ;define where we will load our kernel into memory 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 0x411A [bits 16] jmp boot_16 ;start boot process @@ -32,6 +38,9 @@ BOOT_DRIVE: STR_VERSION: db "v0.2~",0 +VESA_CHECK: + db "vesa check.",0 + ;STR_PROT: ; db "32-bit PM",0 ;STR_LOADED: @@ -40,8 +49,9 @@ STR_VERSION: ;lets put our temporary GDT (Global Descriptor Table) here %include "boot/GDT.asm" -;include 16-bit real mode routines (print_string, print_hex, disk_load) +;include 16-bit real mode routines (print_string, disk_load) %include "boot/common.asm" +%include "boot/print16.asm" ;include 32-bit Protected Mode routines (print_string_pm,print_hex_pm) ;%include "boot/common_pm.asm" @@ -60,35 +70,6 @@ STR_VERSION: ;lets start [bits 16] -;print_string routine ([bx]) -;this routine will print a null terminated string at [bx] to the screen. -print_string: - - pusha ;push all registers - mov ah,0x0e - - print_string_loop: - - ;check if value at [bx] is "\0" (end of string) - mov cl,[bx] - cmp cl,0 - je print_string_finish - - ;otherwise instruct BIOS to print the current char - mov al,cl - int 0x10 - - ;proceed with next char - inc bx - jmp print_string_loop - - print_string_finish: - - popa ;pop all registers - ret ;return to caller - - - boot_16: mov bx, STR_VERSION @@ -107,7 +88,7 @@ boot_16: ;Load the KERNEL mov bx,KERNEL_OFFSET - mov dh, 50 + mov dh, 50 ;50 sectors! mov dl, [BOOT_DRIVE] call disk_load @@ -116,11 +97,47 @@ boot_16: ; call print_string - ;get memory map from biso before we enter 32 bit protected mode - ; todo: how to set es!?!? - ;mov es,0 - mov di,MEMMAP - call BiosGetMemoryMap + ;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 + + ;get vesa modes! + mov ax,0 ; set target address in es:di (0:offset) + mov es,ax + mov di,VESA_MODES + mov ax,0x4f00 ;vesa function: Get Controller Info + int 0x10 ; call the interrupt to get the data from the bios! + vesa_err: + mov bx, VESA_CHECK + call print_string + cmp ax,0x004f + je vesa_ok + jmp vesa_err + vesa_ok: + ; + + ;get info on mode of interest + mov ax,0 ; set target address in es:di (0:offset) + mov es,ax + mov di,VESA_MODE_INFO + mov ax,0x4f01 ;vesa function: Get Mode Info + mov cx,VESA_MODE_SELECT + int 0x10 ; call the interrupt to get the data from the bios! + vesa_err2: + mov bx, VESA_CHECK + call print_string + cmp ax,0x004f + je vesa_ok2 + jmp vesa_err2 + vesa_ok2: + + ;finally switch to the mode of choice! + mov ax,0x4f02 ;vesa function: Set Mode + mov bx,VESA_MODE_SELECT + int 0x10 ;finally lets enter Protected mode!!! call switch_to_pm @@ -129,7 +146,7 @@ boot_16: [bits 32] boot_32_pm: -; we could do ALL This inside the kernel!!! +; we could do ALL This inside the kernel!!!!!! TODO ;print info message that we are in protected mode! ; mov ecx,160 @@ -145,15 +162,8 @@ boot_32_pm: ;pic setup call pic_setup - call KERNEL_OFFSET ;jump into our Kernel it -db 'X' -db 'X' -MEMMAP: - - - ;idt_descriptor: ; dw idt_end-idt_start-1 ; dd KERNEL_OFFSET @@ -166,6 +176,7 @@ MEMMAP: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;so we get identified as MBR times 510-($-$$) db 0 dw 0xaa55 diff --git a/boot/mbr16.asm b/boot/mbr16.asm new file mode 100644 index 0000000..1abc97d --- /dev/null +++ b/boot/mbr16.asm @@ -0,0 +1,79 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; FoolOS Boot Loader for 16bit entry in C +; +; Copyright 2014 M.Idziorek <m.i@gmx.at> +; +; we have just been loaded by the BIOS and are in 16-bits real mode! +; +; THIS IS THE CENTRAL FILE OF THE 16bit BOOTLOADER, after we finished we +; are inside 16bit C code! +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;we want 16-bit instructions, before we switch to 32-bit protected mode. + +;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 where we will load our "C binary" +BOOT_OFFSET equ 0x1000 + +[bits 16] +jmp boot_16 ;start boot process + +BOOT_DRIVE: + db 0xff + +;SOME Global Data, mainly strings +STR_VERSION: + db "~ Fool Loader 16-bit, v0.1 ~",0 + +;include 16-bit real mode routines (print_string, print_hex, disk_load) +%include "boot/common.asm" +%include "boot/print16.asm" + +;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;lets start + +boot_16: + + ;print version info + 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 BOOT LOADER from second sector (max 50 sectors) + mov bx,BOOT_OFFSET ;destination in ram + mov dh, 50 ;50 sectors + mov dl, [BOOT_DRIVE] ;source drive + call disk_load + + call BOOT_OFFSET ;jump into our C code + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;so we get identified as MBR +times 510-($-$$) db 0 +dw 0xaa55 + +;interrupt descriptor table (hardcoded address of interrupts:) +;idt_start: +;times 33 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0 +;db 0x59,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0 +;times 253 db 0x50,0x7c,0x08,0x00,0x00,10001110b,0x0,0x0 +;idt_end: + + + + diff --git a/boot/memmap.asm b/boot/memmap.asm index 29d48f3..d101557 100644 --- a/boot/memmap.asm +++ b/boot/memmap.asm @@ -51,5 +51,7 @@ BiosGetMemoryMap: .error: stc .done: + + mov [MEMMAP_SIZE_OFFSET],bp popad ret diff --git a/boot/print16.asm b/boot/print16.asm new file mode 100644 index 0000000..5d8ad5c --- /dev/null +++ b/boot/print16.asm @@ -0,0 +1,28 @@ +[bits 16] + +;print_string routine ([bx]) +;this routine will print a null terminated string at [bx] to the screen. +print_string: + + pusha ;push all registers + mov ah,0x0e + + print_string_loop: + + ;check if value at [bx] is "\0" (end of string) + mov cl,[bx] + cmp cl,0 + je print_string_finish + + ;otherwise instruct BIOS to print the current char + mov al,cl + int 0x10 + + ;proceed with next char + inc bx + jmp print_string_loop + + print_string_finish: + + popa ;pop all registers + ret ;return to caller |
