-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.asm
86 lines (61 loc) · 1.4 KB
/
bootstrap.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
start:
mov ax, 07C0h
mov ds, ax
mov si, title_string
call print_string
mov si, message_string
call print_string
call load_kernel_from_disk
jmp 0900h:0000
load_kernel_from_disk:
mov ax, [curr_sector_to_load]
sub ax, 2
mov bx, 512d
mul bx
mov bx, ax
mov ax, 0900h
mov es, ax
mov ah, 02h
mov al, 01h
mov ch, 0h
mov cl, [curr_sector_to_load]
mov dh, 0h
mov dl, 80h
int 13h
jc kernel_load_error
sub byte [number_of_sectors_to_load], 1
add byte [curr_sector_to_load], 1
cmp byte [number_of_sectors_to_load], 0
jne load_kernel_from_disk
ret
kernel_load_error:
mov si, load_error_string
call print_string
jmp $
print_string:
mov ah, 0Eh
print_char:
lodsb
cmp al, 0
je printing_finished
int 10h
jmp print_char
printing_finished:
mov al, 10d ; print new line
int 10h
; reading current cursor position
mov ah, 03h
mov bh, 0
int 10h
; move the cursor to the beginning
mov ah, 02h
mov dl, 0
int 10h
ret
title_string db 'The Bootloader of 539kernel.', 0
message_string db 'The kernel is loading...', 0
load_error_string db 'The kernel cannot be loaded.', 0
number_of_sectors_to_load db 15d ; 255 sectors = 127.5KB
curr_sector_to_load db 2d
times 510-($-$$) db 0
dw 0xAA55