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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
; number of sectors to be read
; 3 * 512 for bootloader stage2 and the kernel code
; (note: the first sector gets loaded by the BIOS, so
; subtract 1 here!)
NOF_LOAD_SECTORS equ 20
; IN bx: begin of memory area to dump
; IN ax: number of words to dump
dump_range:
mov dx, bx
call print_hex
mov dx, [bx]
call print_hex
call print_newline
add bx, 2
dec ax
cmp ax, 0
jnz dump_range
ret
; IN dx: hex value to print
print_hex:
push bx
push si
mov si, HEX_TEMPLATE
mov bx, dx
shr bx, 12
mov bx, [HEXABET+bx]
mov [HEX_TEMPLATE+2], bl
mov bx, dx
and bx, 0x0FFF
shr bx, 8
mov bx, [HEXABET+bx]
mov [HEX_TEMPLATE+3], bl
mov bx, dx
and bx, 0x00FF
shr bx, 4
mov bx, [HEXABET+bx]
mov [HEX_TEMPLATE+4], bl
mov bx, dx
and bx, 0x000F
mov bx, [HEXABET+bx]
mov [HEX_TEMPLATE+5], bl
call print_string
pop si
pop bx
ret
HEX_TEMPLATE:
db '0x???? ', 0
HEXABET:
db '0123456789ABCDEF'
print_newline:
push ax
mov al, 10
call print_char
mov al, 13
call print_char
pop ax
ret
; IN si
print_string:
push ax
.loop:
lodsb
cmp al, 0
je .fini
call print_char
jmp .loop
.fini:
pop ax
ret
; IN al: character to print
; MOD ah
print_char:
mov ah, 0x0e
int 0x10
ret
fat_cursor:
push ax
push cx
mov ah, 0x01
mov cx, 0x0007
int 0x10
pop cx
pop ax
ret
; OUT: current row
current_row:
push ax
push bx
push cx
mov ah, 0x03
mov bh, 0
int 0x10
pop cx
pop bx
pop ax
ret
; IN dl: drive to read from
read_from_disk:
mov ah, 0x02 ; read sectors from drive
mov al, NOF_LOAD_SECTORS ; read 1 sector
mov ch, 0 ; select first cylinder
mov dh, 0 ; first head
mov cl, 2 ; second sector after boot sector
mov bx, 0 ; where to store the data
mov es, bx
mov bx, 0x7e00 ; 512 bytes after first sector
int 0x13
jc .read_error
cmp al, NOF_LOAD_SECTORS ; 1 sector read?
jne .short_read ; if not, short read
ret
.read_error:
mov si, DISK_ERROR
call print_string
mov dh, 0
mov dl, ah
call print_hex
jmp $
.short_read:
mov si, SHORT_READ
call print_string
jmp $
|