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

Last change on this file since 182 was 181, checked in by krille_n_@…, 13 years ago

Changes to all parts of the project:

  • Size optimizations.
  • Added a define (EXCLUDE_FROM_XTIDECFG) to exclude unused library code from XTIDECFG.
  • Tried to minimize time spent with interrupts disabled.
  • Some minor attempts to improve speed (reordering instructions etc).
  • Tried to improve readability, did some cleanup and fixed some errors in comments.
File size: 5.4 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
[161]41 xchg di, ax ; Save the contents of AX in DI
[3]42
[150]43 mov al, LARGEST_DPT_SIZE
44 sub dl, [RAMVARS.bFirstDrv]
45 mul dl
46 add ax, BYTE RAMVARS_size
[3]47
[161]48 xchg di, ax ; Restore AX and put result in DI
[150]49 pop dx
50 ret
51
52
[3]53;--------------------------------------------------------------------
54; Finds Disk Parameter Table for
55; Master or Slave drive at wanted port.
56;
[150]57; FindDPT_ToDSDIForIdeMasterAtPortDX
58; FindDPT_ToDSDIForIdeSlaveAtPortDX
[3]59; Parameters:
60; DX: IDE Base Port address
61; DS: RAMVARS segment
62; Returns:
63; DL: Drive number (if DPT found)
64; DS:DI: Ptr to DPT
65; CF: Set if wanted DPT found
66; Cleared if DPT not found
67; Corrupts registers:
[150]68; SI
[3]69;--------------------------------------------------------------------
70ALIGN JUMP_ALIGN
[150]71FindDPT_ToDSDIForIdeMasterAtPortDX:
[152]72 mov si, IterateToMasterAtPortCallback
[150]73 jmp SHORT IterateAllDPTs
[3]74
75ALIGN JUMP_ALIGN
[150]76FindDPT_ToDSDIForIdeSlaveAtPortDX:
[152]77 mov si, IterateToSlaveAtPortCallback
[150]78 jmp SHORT IterateAllDPTs
[3]79
80;--------------------------------------------------------------------
81; Iteration callback for finding DPT using
82; IDE base port for Master or Slave drive.
83;
[152]84; IterateToSlaveAtPortCallback
85; IterateToMasterAtPortCallback
[3]86; Parameters:
[150]87; CH: Drive number
[3]88; DX: IDE Base Port address
89; DS:DI: Ptr to DPT to examine
90; Returns:
91; DL: Drive number if correct DPT
92; CF: Set if wanted DPT found
93; Cleared if wrong DPT
94; Corrupts registers:
95; Nothing
96;--------------------------------------------------------------------
97ALIGN JUMP_ALIGN
[152]98IterateToSlaveAtPortCallback:
[158]99 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
[150]100 jnz SHORT CompareBasePortAddress
101 ret ; Wrong DPT
[3]102
103ALIGN JUMP_ALIGN
[152]104IterateToMasterAtPortCallback:
[158]105 test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
[150]106 jnz SHORT ReturnWrongDPT ; Return if slave drive
[3]107
[150]108CompareBasePortAddress:
[3]109 push bx
[150]110 eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
111 cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
[3]112 pop bx
[150]113 jne SHORT ReturnWrongDPT
114 mov dl, ch ; Return drive number in DL
115 stc ; Set CF since wanted DPT
[3]116 ret
[152]117
118
119;--------------------------------------------------------------------
120; IterateToDptWithInterruptInServiceFlagSet
121; Parameters:
122; DS:DI: Ptr to DPT to examine
123; Returns:
124; CF: Set if wanted DPT found
125; Cleared if wrong DPT
126; Corrupts registers:
127; Nothing
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130IterateToDptWithInterruptInServiceFlagSet:
[158]131 test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_INTERRUPT_IN_SERVICE
[152]132 jz SHORT ReturnWrongDPT
133 stc ; Set CF since wanted DPT
134 ret
[150]135ReturnWrongDPT:
[152]136 clc ; Clear CF since wrong DPT
[3]137 ret
138
139
140;--------------------------------------------------------------------
[161]141; FindDPT_ToDSDIforInterruptInService
142; Parameters:
143; DS: RAMVARS segment
144; Returns:
145; DS:DI: Ptr to DPT
146; CF: Set if wanted DPT found
147; Cleared if DPT not found
148; Corrupts registers:
149; SI
150;--------------------------------------------------------------------
151ALIGN JUMP_ALIGN
152FindDPT_ToDSDIforInterruptInService:
153 mov si, IterateToDptWithInterruptInServiceFlagSet
154 ; Fall to IterateAllDPTs
155
156
157;--------------------------------------------------------------------
[3]158; Iterates all Disk Parameter Tables.
159;
[150]160; IterateAllDPTs
[3]161; Parameters:
[152]162; AX,BX,DX: Parameters to callback function
163; CS:SI: Ptr to callback function
164; DS: RAMVARS segment
[3]165; Returns:
[152]166; DS:DI: Ptr to wanted DPT (if found)
167; CF: Set if wanted DPT found
168; Cleared if DPT not found
[181]169; Unchanged if no drives
[3]170; Corrupts registers:
[150]171; Nothing unless corrupted by callback function
[3]172;--------------------------------------------------------------------
173ALIGN JUMP_ALIGN
[150]174IterateAllDPTs:
[3]175 push cx
[150]176 mov cx, [RAMVARS.wDrvCntAndFirst]
177 jcxz .AllDptsIterated ; Return if no drives
[152]178 mov di, RAMVARS_size ; Point DS:DI to first DPT
[3]179ALIGN JUMP_ALIGN
180.LoopWhileDPTsLeft:
181 call si ; Is wanted DPT?
[150]182 jc SHORT .AllDptsIterated ; If so, return
183 inc ch ; Increment drive number
184 add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
185 dec cl ; Decrement drives left
186 jnz SHORT .LoopWhileDPTsLeft
[3]187 clc ; Clear CF since DPT not found
188ALIGN JUMP_ALIGN
[150]189.AllDptsIterated:
[3]190 pop cx
191 ret
Note: See TracBrowser for help on using the repository browser.