From e3cc5f6c89ba9f37bf2c1edf588d0f75c1d63c57 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Fri, 14 Nov 2014 11:08:04 +0100 Subject: rename dirs --- boot1/mbr.asm | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 boot1/mbr.asm (limited to 'boot1/mbr.asm') diff --git a/boot1/mbr.asm b/boot1/mbr.asm new file mode 100644 index 0000000..c0a555d --- /dev/null +++ b/boot1/mbr.asm @@ -0,0 +1,106 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; FOOL-OS Master Boot Record +; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; +; This is the Master Boot Record for x86 +; +; We are limited to 512 bytes (one sector) +; minus 64 bytes for the partition table +; minus 2 bytes formagic number (0xaa55) +; +; all we do here is : +; +; 1. Put the Stack at 0x07bff (it is counting down) +; 2. Remeber Boot Drive at [BOOT_DRIVE] +; 3. Print PR message and Boot Drive number +; 4. Load Second Stage Bootloader from Boot Drive at next sector +; 5. Show Info Message after successfull loading +; 6. Jump to 2nd Stage Boot Loader +; +; Refer to a memory map as needed: +; http://wiki.osdev.org/Memory_Map_(x86) + +; Everything here is 16bit +[bits 16] + +; Per definition this will be loaded by the BIOS at 0x7c00 +[org 0x7c00] + +; skip constants and includes +jmp stage1 + +; string constants (null terminated) +STR_1: db "Fool Loader Stage 1. v0.1",0 +STR_2: db "Starting Stage 2",0 +STR_BOOT: db "Boot drive: ",0 + +; some space (one byte) to remember the Boot Drive +BOOT_DRIVE: db 0xff + +; include print and disk load routines +%include "print_string_16.asm" +%include "disk_load_16.asm" + +; Here we start! +stage1: + + ; first of all, setup the stack (right under our MBR) + ; ~30KB space guaranteed + mov bp,0x07bff + mov sp,bp + + ; remember BOOT_DRIVE (as was set by BIOS in dl) + mov [BOOT_DRIVE],dl + + ; clear screen and print PR message + call print_clear + call print_nextline + + mov bx, STR_1 + call print_string + call print_nextline + + + ; print bootdrive number + mov bx, STR_BOOT + call print_string + + mov al,[BOOT_DRIVE] + call print_hex_byte + call print_nextline + + + ; Actually Load the Second Stage Bootloader! + call disk_load_16 + + + ; show info message that 2nd Stage was loaded + mov bx, STR_2 + call print_string + call print_nextline + call print_nextline + + + ; save Boot Drive in dl for second stage + mov dl,[BOOT_DRIVE] + + + ; jump to the next sector where we loaded the 2nd stage + jmp 0x7e00 + + + ; nothing essential under this line + ; we need this to follow some mbr standards + + ; fill at least 4x16byte with zeroes. (partition table) + ; (otherwise my Acer Aspire will not boot) + times 64 db 0x0 + + ; fill rest with zeroes + times 510-($-$$) db 0x0 + + ; magic number so we get identified as MBR + dw 0xaa55 + -- cgit v1.2.3