summaryrefslogtreecommitdiff
path: root/xxx/boot1/mbr.asm
diff options
context:
space:
mode:
authorMichal Idziorek <m.i@gmx.at>2015-05-14 10:44:00 +0200
committerMichal Idziorek <m.i@gmx.at>2015-05-14 10:44:00 +0200
commitdc7bf2f47d6f97407e3b50ae0b8ab59fd51079e5 (patch)
tree1ed444c804d9ff55e23a7a007275c3d5c649a455 /xxx/boot1/mbr.asm
parent7df4060ae807dd27f3ae0a11f243897f36053ba1 (diff)
moving unused files folder
Diffstat (limited to 'xxx/boot1/mbr.asm')
-rw-r--r--xxx/boot1/mbr.asm106
1 files changed, 106 insertions, 0 deletions
diff --git a/xxx/boot1/mbr.asm b/xxx/boot1/mbr.asm
new file mode 100644
index 0000000..c0a555d
--- /dev/null
+++ b/xxx/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
+