From d85b6209f37b4d886f9e85fd9592c9d7cf25deb9 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 27 Aug 2014 15:56:52 +0200 Subject: further cleanup of bootloader --- boot/mbr.asm | 71 ++++++++++++++++++-------------------------------- boot/vesa_setup_16.asm | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 boot/vesa_setup_16.asm (limited to 'boot') diff --git a/boot/mbr.asm b/boot/mbr.asm index 2beac7b..83edefc 100644 --- a/boot/mbr.asm +++ b/boot/mbr.asm @@ -21,8 +21,12 @@ ; * the vesa mode specified by VESA_MODE_SELECT is set up ; (at VESA_MODES, and VESA_MODE_INFO additional info structs are available) ; +; * interrupts disabled +; ; * 32-bit protected mode was set up. ; +; * esp set to 0x90000 (Todo: take care of it!?) +; ; * A20 gate is open ; ; * PICs are configured @@ -31,6 +35,8 @@ ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;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 @@ -38,8 +44,10 @@ ;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?) [org 0x7c00] -;define where we will load our kernel into memory and some +;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 @@ -47,33 +55,36 @@ VESA_MODES equ 0x8300 VESA_MODE_INFO equ 0x8400 VESA_MODE_SELECT equ 0x4114 -;we want 16-bit instructions, before we switch to 32-bit protected mode. -[bits 16] jmp boot_16 ;start boot process -;SOME Global Data, mainly strings +;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff STR_VERSION: - db "v0.2~",0 - -VESA_CHECK: - db "vesa check.",0 + db "v0.3~",0 +VESA_CHECK1: + db "vesa1.",0 +VESA_CHECK2: + db "vesa2.",0 +VESA_CHECK3: + db "vesa3.",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) +;include 16-bit real mode routines (print_string, disk_load, vesa_setup) %include "boot/disk_load_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 mapping +;pic_setup mapping routing %include "boot/pic.asm" -;get memory map +;get memory map routine %include "boot/memmap.asm" ;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -105,42 +116,9 @@ boot_16: mov di,MEMMAP_OFFSET call BiosGetMemoryMap ; this will also put the number of entries ; of the memory map at MEMMAP_SIZE_OFFSET - + ;VESA: also setup vesa stuff before entering 32 bit protected mode - ;VESA: get all available 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: - ; - - ;VESA: get vesa 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: - - ;VESA: finally switch to the mode of choice! - mov ax,0x4f02 ;vesa function: Set Mode - mov bx,VESA_MODE_SELECT - int 0x10 + call VesaSetup ;finally lets enter Protected mode!!! call switch_to_pm @@ -154,6 +132,7 @@ boot_32_pm: ;enable A20 ;http://www.brokenthorn.com/Resources/OSDev9.html ;Method 3.1: Enables A20 through keyboard controller + ;todo: check if this has any effect at all !?!? mov al, 0xdd ; command 0xdd: enable a20 out 0x64, al ; send command to controller diff --git a/boot/vesa_setup_16.asm b/boot/vesa_setup_16.asm new file mode 100644 index 0000000..4f276b5 --- /dev/null +++ b/boot/vesa_setup_16.asm @@ -0,0 +1,47 @@ +VesaSetup: + + pusha + + ;VESA: get all available 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_CHECK1 + call print_string + cmp ax,0x004f + je vesa_ok + jmp vesa_err + vesa_ok: + ; + + ;VESA: get vesa 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_CHECK2 + call print_string + cmp ax,0x004f + je vesa_ok2 + jmp vesa_err2 + vesa_ok2: + + ;VESA: finally switch to the mode of choice! + mov ax,0x4f02 ;vesa function: Set Mode + mov bx,VESA_MODE_SELECT + int 0x10 + vesa_err3: + mov bx, VESA_CHECK3 + call print_string + cmp ax,0x004f + je vesa_ok3 + jmp vesa_err3 + vesa_ok3: + popa + ret -- cgit v1.2.3