-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_01.asm
256 lines (207 loc) · 4.03 KB
/
test_01.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
; test_01
;
; Read [sector_count = 0x1ba] blocks starting at 0 from disk 0x81 and
; compare with disk 0x80 starting at [sector_start = 0x1b6].
;
; Read one sector at a time.
;
bits 16
%include "x86emu.inc"
disk_buf equ 8000h
disk_buf2 equ 8200h
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
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
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
check:
check_10:
mov eax,[cnt]
mov [edd.sector],eax
mov word [edd.count],1
call disk_read
jc check_90
; x86emu_reset_stats
mov si,disk_buf
mov di,disk_buf2
mov cx,100h
rep movsw
mov eax,[cnt]
add eax,[sector_start]
mov [edd.sector],eax
mov word [edd.count],1
mov dl,80h
xchg dl,[edd.drive]
push dx
call disk_read
pop dx
mov [edd.drive],dl
; x86emu_print "sector2 ok"
; x86emu_dump x86emu_dump_mem_default
jc check_90
mov si,disk_buf
mov di,disk_buf2
mov cx,100h
repe cmpsw
stc
jnz check_90
; x86emu_trace_on x86emu_trace_default
mov eax,[cnt]
inc eax
mov [cnt],eax
cmp eax,[sector_count]
jb check_10
check_90:
; x86emu_trace_on x86emu_trace_default
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
disk_read:
mov dword [edd.buf],disk_buf << 12
call edd_check
jc disk_read_chs
disk_read_edd:
mov si,edd.packet
mov word [si],10h
mov ah,42h
jmp int_13
disk_read_chs:
; classic interface; but if block number turns out
; to be too big, try edd anyway
cmp dword [edd.sector+4],0
jnz disk_read_edd
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]
cmp dx,di
jae disk_read_edd
div di
; ax = c, dx = s*h
cmp ax,cx
ja disk_read_edd
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
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
mov bx,7
mov ah,14
int 10h
jmp print
print_90:
ret
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
align 4
edd.packet dw 10h
edd.count dw 1
edd.buf dw 0, 0
edd.sector dd 0, 0
edd.drive db 0
cnt dd 0
edd_checked db 2
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
msg_nl db 13, 10
msg_no_msg db 0
msg_hello db "starting test_01", 13, 10, 0
msg_done db 10, "test_01 done", 0
msg_check_ok db 'check ok', 13, 10, 0
msg_check_failed db 'check failed', 13, 10, 0
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
%if ($ - $$) > 1b8h
%error "test_01 too big"
%endif
mbr_fill times 1b6h - ($ - $$) db 0
sector_start dd 0
sector_count dd 0
times 40h db 0
dw 0aa55h