source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/FindDPT.asm@ 151

Last change on this file since 151 was 150, checked in by Tomi Tilli, 13 years ago

Changes to XTIDE Universal BIOS:

  • Redesigned Disk Parameter Tables.
  • Code generalizations for supporting non-IDE devices in the future.
File size: 4.7 KB
RevLine 
[150]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for finding Disk Parameter Table.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Finds pointer to first unused Disk Parameter Table.
9;
[150]10; FindDPT_ForNewDriveToDSDI
[3]11; Parameters:
12; DS: RAMVARS segment
13; Returns:
14; DS:DI: Ptr to first unused DPT
15; Corrupts registers:
[150]16; DL
17;--------------------------------------------------------------------
18ALIGN JUMP_ALIGN
19FindDPT_ForNewDriveToDSDI:
20 mov dl, [RAMVARS.bFirstDrv]
21 add dl, [RAMVARS.bDrvCnt]
22 ; Fall to FindDPT_ForDriveNumber
23
24
25;--------------------------------------------------------------------
26; Finds Disk Parameter Table for drive number.
27; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
28;
29; FindDPT_ForDriveNumber
30; Parameters:
31; DL: Drive number
32; DS: RAMVARS segment
33; Returns:
34; DS:DI: Ptr to DPT
35; Corrupts registers:
[3]36; Nothing
37;--------------------------------------------------------------------
38ALIGN JUMP_ALIGN
[150]39FindDPT_ForDriveNumber:
40 push dx
41 push ax
[3]42
[150]43 mov al, LARGEST_DPT_SIZE
44 sub dl, [RAMVARS.bFirstDrv]
45 mul dl
46 add ax, BYTE RAMVARS_size
47 xchg di, ax
[3]48
[150]49 pop ax
50 pop dx
51 ret
52
53
[3]54;--------------------------------------------------------------------
55; Finds Disk Parameter Table for
56; Master or Slave drive at wanted port.
57;
[150]58; FindDPT_ToDSDIForIdeMasterAtPortDX
59; FindDPT_ToDSDIForIdeSlaveAtPortDX
[3]60; Parameters:
61; DX: IDE Base Port address
62; DS: RAMVARS segment
63; Returns:
64; DL: Drive number (if DPT found)
65; DS:DI: Ptr to DPT
66; CF: Set if wanted DPT found
67; Cleared if DPT not found
68; Corrupts registers:
[150]69; SI
[3]70;--------------------------------------------------------------------
71ALIGN JUMP_ALIGN
[150]72FindDPT_ToDSDIForIdeMasterAtPortDX:
73 mov si, FindDPT_IterateToMasterAtPortCallback
74 jmp SHORT IterateAllDPTs
[3]75
76ALIGN JUMP_ALIGN
[150]77FindDPT_ToDSDIForIdeSlaveAtPortDX:
78 mov si, FindDPT_IterateToSlaveAtPortCallback
79 jmp SHORT IterateAllDPTs
[3]80
81;--------------------------------------------------------------------
82; Iteration callback for finding DPT using
83; IDE base port for Master or Slave drive.
84;
85; FindDPT_IterateToSlaveAtPortCallback
86; FindDPT_IterateToMasterAtPortCallback
87; Parameters:
[150]88; CH: Drive number
[3]89; DX: IDE Base Port address
90; DS:DI: Ptr to DPT to examine
91; Returns:
92; DL: Drive number if correct DPT
93; CF: Set if wanted DPT found
94; Cleared if wrong DPT
95; Corrupts registers:
96; Nothing
97;--------------------------------------------------------------------
98ALIGN JUMP_ALIGN
99FindDPT_IterateToSlaveAtPortCallback:
[150]100 test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE ; Clears CF
101 jnz SHORT CompareBasePortAddress
102 ret ; Wrong DPT
[3]103
104ALIGN JUMP_ALIGN
105FindDPT_IterateToMasterAtPortCallback:
[150]106 test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE
107 jnz SHORT ReturnWrongDPT ; Return if slave drive
[3]108
[150]109CompareBasePortAddress:
[3]110 push bx
[150]111 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
112 cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
[3]113 pop bx
[150]114 jne SHORT ReturnWrongDPT
115 mov dl, ch ; Return drive number in DL
116 stc ; Set CF since wanted DPT
[3]117 ret
[150]118ReturnWrongDPT:
119 clc ; Clear CF since wrong DPT
[3]120 ret
121
122
123;--------------------------------------------------------------------
124; Iterates all Disk Parameter Tables.
125;
[150]126; IterateAllDPTs
[3]127; Parameters:
128; BX,DX: Parameters to callback function
129; CS:SI: Ptr to callback function
130; DS: RAMVARS segment
131; Returns:
132; DS:DI: Ptr to wanted DPT (if found)
133; CF: Set if wanted DPT found
134; Cleared if DPT not found
135; Corrupts registers:
[150]136; Nothing unless corrupted by callback function
[3]137;--------------------------------------------------------------------
138ALIGN JUMP_ALIGN
[150]139IterateAllDPTs:
[3]140 push cx
[150]141 mov cx, [RAMVARS.wDrvCntAndFirst]
142 jcxz .AllDptsIterated ; Return if no drives
[3]143 call FindDPT_PointToFirstDPT ; Point DS:DI to first DPT
144ALIGN JUMP_ALIGN
145.LoopWhileDPTsLeft:
146 call si ; Is wanted DPT?
[150]147 jc SHORT .AllDptsIterated ; If so, return
148 inc ch ; Increment drive number
149 add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
150 dec cl ; Decrement drives left
151 jnz SHORT .LoopWhileDPTsLeft
[3]152 clc ; Clear CF since DPT not found
153ALIGN JUMP_ALIGN
[150]154.AllDptsIterated:
[3]155 pop cx
156 ret
157
158
159;--------------------------------------------------------------------
160; Sets DI to point to first Disk Parameter Table.
161;
162; FindDPT_PointToFirstDPT
163; Parameters:
164; Nothing
165; Returns:
166; DI: Offset to first DPT (even if unused)
167; Corrupts registers:
168; Nothing
169;--------------------------------------------------------------------
170ALIGN JUMP_ALIGN
171FindDPT_PointToFirstDPT:
172 mov di, RAMVARS_size
173 ret
Note: See TracBrowser for help on using the repository browser.