-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_03.asm
343 lines (279 loc) · 5.48 KB
/
test_03.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
; test_03
;
; Read [sector_count = 0x1ba] blocks starting at 0 from disk 0x81 and
; compare with disk 0x80 starting at [sector_start = 0x1b6].
;
; Use various block sizes.
; Use CHS interface.
;
bits 16
%include "x86emu.inc"
section .text
org 7c00h
jmp 0:main_10
main_10:
mov ax,cs
mov ss,ax
xor sp,sp
mov ds,ax
mov es,ax
cld
sti
mov [edd.drive],dl
; x86emu_trace_on x86emu_trace_default
call disk_read
mov si,msg_hello
call print
call check
mov si,msg_check_failed
jc main_30
mov si,msg_check_ok
main_30:
jmp final_msg
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
disk_read:
; classic interface; but if block number turns out
; to be too big, try edd anyway
cmp dword [edd.sector+4],0
jnz disk_read_chs_90
mov ah,8
xor di,di
call int_13
jc disk_read_chs_90
mov ax,cx
shr cl,6
xchg cl,ch
and al,3fh
inc dh
mov bl,al
mul dh
; ax = s*h
xchg ax,di
mov ax,[edd.sector]
mov dx,[edd.sector+2]
; x86emu_print "linear dx:ax"
; x86emu_trace_on x86emu_trace_regs
; x86emu_trace_off x86emu_trace_regs
cmp dx,di
jae disk_read_chs_90
div di
; ax = c, dx = s*h
cmp ax,cx
ja disk_read_chs_90
shl ah,6
xchg al,ah
xchg ax,dx
; dx = c
div bl
; ah = s-1, al = h
add dl,ah
inc dx
mov ch,al
xchg cx,dx
mov al,[edd.count]
les bx,[edd.buf]
mov ah,2
; x86emu_print "chs"
; x86emu_trace_on x86emu_trace_regs
; x86emu_trace_off x86emu_trace_regs
call int_13
push word 0
pop es
disk_read_chs_90:
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;
; CF: 0 = edd ok, 1 = no edd
;
edd_check:
cmp byte [edd_checked],1
jbe edd_check_90
mov byte [edd_checked],0
mov ah,41h
mov bx,55aah
call int_13
jc edd_check
cmp bx,0aa55h
jnz edd_check
test cl,1
jz edd_check
inc byte [edd_checked]
edd_check_90:
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
int_13:
mov dl,[edd.drive]
push bp
int 13h
pop bp
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
final_msg:
call print
mov si,msg_done
call print
mov ah,0
int 16h
mov si,msg_nl
call print
int 19h
final_msg_10:
hlt
jmp final_msg_10
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Write string.
;
; si text
;
; return:
;
print:
lodsb
or al,al
jz print_90
cmp al,0ah
jnz print_50
mov ax,0e0dh
mov bx,7
int 10h
mov al,0ah
print_50:
mov bx,7
mov ah,0eh
int 10h
jmp print
print_90:
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
align 4
edd.packet dw 10h
edd.count dw prog_blocks
edd.buf dw 7e00h, 0
edd.sector dd 1, 0
edd.drive db 0
edd_checked db 2
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%if ($ - $$) > 1b8h
%error "test_03 too big"
%endif
mbr_fill times 1b6h - ($ - $$) db 0
sector_start dd 0
sector_count dd 0
times 40h db 0
dw 0aa55h
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
buf1_seg equ 1000h
buf2_seg equ 3000h
msg_nl db 10
msg_no_msg db 0
msg_done db 10, "test_03 done", 0
msg_hello db "starting test_03", 10, 0
msg_check_ok db 'check ok', 10, 0
msg_check_failed db 'check failed', 10, 0
msg_step db 13, 'step ', 0
align 4
cnt dd 0
block_size dd 0
block_sizes db 1, 5, 7, 26, 32, 50, 64
block_sizes_end equ $
step db 0
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Print hex number.
;
hex2:
push ax
shr al,4
call hex1
pop ax
hex1:
and al,0fh
cmp al,9
jbe hex1_20
add al,7
hex1_20:
add al,'0'
mov si,hex1_buf
mov [si],al
jmp print
hex1_buf db 0, 0
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
check:
xor ax,ax
xor di,di
mov dx,buf1_seg
mov bx,4
check_05:
mov es,dx
mov cx,8000h
rep stosw
add dx,1000h
dec bx
jnz check_05
check_07:
mov dword [cnt],0
movzx ebx,byte [step]
mov al,[block_sizes+bx]
mov [block_size],al
mov si,msg_step
call print
mov ax,[step]
call hex2
check_10:
mov dword [edd.buf],buf1_seg << 16
mov eax,[cnt]
mov [edd.sector],eax
push word [block_size]
pop word [edd.count]
call disk_read
jc check_90
; x86emu_print "read 1 ok"
mov dword [edd.buf],buf2_seg << 16
mov eax,[cnt]
add eax,[sector_start]
mov [edd.sector],eax
push word [block_size]
pop word [edd.count]
mov dl,80h
xchg dl,[edd.drive]
push dx
call disk_read
pop dx
mov [edd.drive],dl
jc check_90
; x86emu_print "read 2 ok"
mov ax,[block_size]
mov bx,buf1_seg
mov dx,buf2_seg
check_50:
xor si,si
xor di,di
mov cx,80h
mov fs,bx
mov es,dx
fs repe cmpsd
stc
jnz check_90
add bx,20h
add dx,20h
dec ax
jnz check_50
; x86emu_print "cmp ok"
mov eax,[cnt]
add eax,[block_size]
mov [cnt],eax
add eax,[block_size]
cmp eax,[sector_count]
jbe check_10
inc byte [step]
cmp byte [step],block_sizes_end - block_sizes
jb check_07
check_90:
; x86emu_trace_on x86emu_trace_default
pushf
mov si,msg_nl
call print
popf
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
prog_blocks equ ($ - $$ + 511) >> 9