;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; THE FOOL-BOOT-LOADER ; ; * 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) ; ; * 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 ; ; * A20 gate opened ; ; * 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 0x7e00] ;;define some constants ;;where we will load our kernel into memory and some ;;other memory locations ; KERNEL_DATA equ 10 ;sector on disk where the kernel starts KERNEL_SECTOR equ 0x1000 KERNEL_OFFSET equ 0x0000 MEMMAP_SIZE_OFFSET equ 0x7c00 MEMMAP_OFFSET equ 0x7c01 VESA_MODES equ 0x8300 VESA_MODE_INFO equ 0x8400 VESA_MODE_SELECT equ 0x4114 ; jmp boot_16 ;start boot process ;;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff STR_VERSION: db "Fool Loader Stage 2 v0.5",0 STR_LOAD db "Loading Kernel...",0 STR_BOOT db "Boot Drive: ",0 MEMMAP_INFO: db "Getting Memory Map from BIOS.",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" ; ; ;;get memory map routine %include "boot/memmap.asm" ; ;;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;;lets start [bits 16] boot_16: mov [BOOT_DRIVE],dl ; pr info mov bx, STR_VERSION call print_string call print_nextline 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 call print_nextline ;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 call VesaSetup call switch_to_pm ; ;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [bits 32] boot_32_pm: ;Fast A20 Gate: ;http://wiki.osdev.org/A20_Line in al, 0x92 or al, 2 out 0x92, al ; call kernel! mov eax,0 ;tell the kernel ; we are the booting processor call 0x10000 ;jump into our Kernel!