PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/asm/boot/test/disk.s

http://github.com/dennis-gemini/tests
Assembly | 64 lines | 56 code | 8 blank | 0 comment | 0 complexity | 9cc071dd6338d16a885a1ac454aa6184 MD5 | raw file
 1.code16
 2.text
 3
 4#############################################
 5#
 6# read sectors
 7#
 8# input:
 9#    %ax     = sector number
10#    %cx     = count
11#    %es:%bx = buffer
12#
13# output:
14#    %ax     = result code
15#    %cx     = count
16#
17#############################################
18
19.global read_sectors
20read_sectors:
21	/******************************************************
22	 * LBA to CHS
23	 *     Sector = (LBA % BPB_SecPerTrk) + 1
24	 *       Head = (LBA / BPB_SecPerTrk) % BPB_NumHeads
25	 *   Cylinder = (LBA / BPB_SecPerTrk) / BPB_NumHeads
26	 ******************************************************/
27	push    %dx
28	push    %si
29	push    %cx
30
31	xor     %dx, %dx
32	divw    (BPB_SecPerTrk)
33	inc     %dl                  
34	mov     %dl, %cl             # cl = sector
35
36	xor     %dx, %dx
37	divw    (BPB_NumHeads)
38	mov     %al, %ch             # ch = cylinder(track)
39	mov     %dl, %dh             # dh = head
40
41	movb    (BS_DrvNum), %dl     # dl = drive
42
43	pop     %ax
44	mov     $0x02, %ah           #INPUT  al: number of sectors, ch: track, cl: sector, dh: head, dl: drive, es:bx: buffer
45	int     $0x13                #OUTPUT ah: return code, al: number of sectors read
46	mov     %ax, %cx
47	jc      1f
48
49	#reset drive
50	xor     %ah, %ah
51	int     $0x13
52	jmp     2f
531:
54	#let it fail immediately
55	mov     $'!', %ax
56	call    putchar
57	int     $0x18
582:
59	mov     %ch, %al
60	xor     %ch, %ch
61	pop     %si
62	pop     %dx
63	ret
64