-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.asm
66 lines (56 loc) · 1.5 KB
/
boot.asm
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
;16-bit Bootloader to Load and Execute a 32-bit Kernel
BITS 16
org 0x7C00
section .text
global _start
_start:
mov ah, 0x0E
mov al, 'L'
int 0x10
mov al, 'o'
int 0x10
mov al, 'a'
int 0x10
mov al, 'd'
int 0x10
mov al, 'i'
int 0x10
mov al, 'n'
int 0x10
mov al, 'g'
int 0x10
; Set up the stack
xor ax, ax
mov ss, ax ; Set stack segment to 0
mov sp, 0x7C00 ; Set stack pointer to top of the boot sector
; Load the second sector (loader) into memory at 0x1000
mov bx, 0x1000
mov dl, 0x80 ; Drive number (0x80 for the first hard disk)
call load_sector
mov ah, 0x0E
mov al, 'A' ; boot ending char
int 0x10
; Jump to the loaded code at 0x1000
jmp 0x1000
mov ah, 0x0E
mov al, 'Z' ; boot ending char
int 0x10
hlt ; finished
load_sector: ;load sector from disk
mov ah, 0x02 ; BIOS read sectors function
mov al, 0x01 ; Number of sectors to read
mov ch, 0x00 ; Cylinder number
mov cl, 0x02 ; Sector number (2nd sector, which is loader)
mov dh, 0x00 ; Head number
int 0x13 ; Call BIOS interrupt
jc load_error ; Jump if carry flag is set (error)
ret ; Return if successful
load_error:
mov ah, 0x0E
mov al, '-' ; ERROR flag
int 0x10
cli ; Disable interrupts
hlt ; Halt the CPU
; Boot sector signature
times 510 - ($ - $$) db 0
dw 0xAA55