;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; FoolOS Boot Loader ; ; Copyright 2014 M.Idziorek ; ; we have just been loaded by the BIOS and are in 16-bits real mode! ; ; THIS IS THE CENTRAL FILE OF THE BOOTLOADER, after we finished we ; are inside the C kernel! ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;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 kernel into memory KERNEL_OFFSET equ 0x1000 [bits 16] jmp boot_16 ;start boot process ;SOME Global Data, mainly strings STR_VERSION: ; db "v0.2~",0 STR_PROT: ; db "32-bit PM",0 STR_LOADED: ; db "loaded",0 BOOT_DRIVE: db 0 ;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 "boot/common.asm" ;include 32-bit Protected Mode routines (print_string_pm,print_hex_pm) ;%include "boot/common_pm.asm" ;include our routines for switching to 32-bit protected mode %include "boot/pm.asm" ;pic mapping %include "boot/pic.asm" ;memory map %include "boot/memmap.asm" ;;;;;;;; BOOT 16-bit real ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;lets start [bits 16] boot_16: ;setup the stack mov bp,0x8000 mov sp,bp ;remember BOOT_DRIVE (as was set by BIOS) mov [BOOT_DRIVE],dl ;print FoolOS version info ; mov bx, STR_VERSION ; call print_string ;Load the KERNEL mov bx,KERNEL_OFFSET mov dh, 15 mov dl, [BOOT_DRIVE] call disk_load ;print info message that kernel was loaded ; mov bx, STR_LOADED ; call print_string ;finally lets enter Protected mode!!! call switch_to_pm ;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [bits 32] boot_32_pm: ;print info message that we are in protected mode! ; mov ecx,160 ; mov ebx,STR_PROT ; call print_string_pm ;enable A20 ;http://www.brokenthorn.com/Resources/OSDev9.html ;Method 3.1: Enables A20 through keyboard controller mov al, 0xdd ; command 0xdd: enable a20 out 0x64, al ; send command to controller ;pic setup call pic_setup call KERNEL_OFFSET ;jump into our Kernel it ;idt_descriptor: ; dw idt_end-idt_start-1 ; dd KERNEL_OFFSET ;;;; DEBUGGING STUFF ;times 8 db '@' ;dw interrupt ;times 8 db '@' ;dw interrupt2 ;times 8 db '@' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;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: