aboutsummaryrefslogtreecommitdiff
path: root/boot.asm
blob: e687586612ce67aa3417e194c0a7368ac9fe25fa (plain) (blame)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
[org 0x7c00]

;main code-----------------------------------------------------

mov bp, 0x8000
mov sp, bp

mov si, msg
call print

mov bx, 0x9000	;where to load (ES:BX)
mov dh, 0x02	
mov dl, [boot_drive]
call disk_load

mov dx, [0x9000]
call print_hex

mov dx, [0x9200]
call print_hex

;hang--------------------------
cli
jmp $

;functions-----------------------------------------------------

;print-------------------------------------------
print:
pusha
mov ah, 0x0e	;teletype output
a:
mov al, [si]	;char to print
cmp al, 0x0
je b
int 0x10
inc si
jmp a
b:
popa
ret

;print_hex---------------------------------------
print_hex:
pusha
;manipulate hex_out----------
mov bx, dx
shr bx, 12
and bx, 0x000f
mov bx, [hex + bx]
mov [hex_out + 2], bl

mov bx, dx
shr bx, 8
and bx, 0x000f 
mov bx, [hex + bx]
mov [hex_out + 3], bl

mov bx, dx
shr bx, 4
and bx, 0x000f
mov bx, [hex + bx]
mov [hex_out + 4], bl

mov bx, dx
shr bx, 0
and bx, 0x000f
mov bx, [hex + bx]
mov [hex_out + 5], bl
;end of manipulation---------
mov si, hex_out
call print
popa
ret

;load to memory------------------------------------------------
disk_load:
pusha
push dx		;save to cmp later
;dh-num_sec, dl-floppy/hdd/cd
mov ah, 0x02	;read sectors from drive
mov al, dh		;number of sectors to read
mov dh, 0x00	;head
mov ch, 0x00	;cylinder
mov cl, 0x02	;sector (second sector)
int 0x13

jc disk_err
pop dx
cmp dh, al
jne disk_err

popa
ret

disk_err:
mov si, lerr
call print
mov dx, ax
call print_hex
cli
jmp $

;data----------------------------------------------------------
msg: db "Data loaded from boot drive:", 0x0a, 0x0d, 0x0
hex_out: db "0x0000", 0x0a, 0x0d, 0x0
hex: db "0123456789ABCDEF"
lerr: db "Error: INT 13H -> AX: ", 0x0
boot_drive: db 0x80	;floppy-iso(0x00) or hdd-qemu(0x80)

;boot number---------------------------------------------------
times 510-($-$$) db 0
dw 0xaa55

;other sectors-------------------------------------------------
times 256 dw 0xb10c
times 256 dw 0xcafe