summaryrefslogtreecommitdiff
path: root/boot/mbr16.asm
blob: 1abc97d1ad43d0941aa1fc814ad7f89b3ba15a48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;    FoolOS Boot Loader for 16bit entry in C
;    
;    Copyright 2014 M.Idziorek  <m.i@gmx.at>
;    
;    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: