;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; FoolOS Boot Loader for 16bit entry in C ; ; 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 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: