source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/VariablesAndDPTs/RamVars.asm@ 261

Last change on this file since 261 was 258, checked in by gregli@…, 12 years ago

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File size: 7.9 KB
RevLine 
[90]1; Project name : XTIDE Universal BIOS
[3]2; Description : Functions for accessings RAMVARS.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Initializes RAMVARS.
9; Drive detection can be started after this function returns.
10;
11; RamVars_Initialize
12; Parameters:
13; Nothing
14; Returns:
[97]15; DS: RAMVARS segment
[3]16; Corrupts registers:
[97]17; AX, CX, DI
[3]18;--------------------------------------------------------------------
19RamVars_Initialize:
[90]20 push es
[97]21 ; Fall to .StealMemoryForRAMVARS
[3]22
23;--------------------------------------------------------------------
[33]24; .StealMemoryForRAMVARS
[3]25; Parameters:
26; Nothing
27; Returns:
28; DS: RAMVARS segment
29; Corrupts registers:
30; AX
31;--------------------------------------------------------------------
[33]32.StealMemoryForRAMVARS:
[241]33 mov ax, LITE_MODE_RAMVARS_SEGMENT
[3]34 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
[97]35 jz SHORT .InitializeRamvars ; No need to steal RAM
[3]36
[116]37 LOAD_BDA_SEGMENT_TO ds, ax, ! ; Zero AX
[3]38 mov al, [cs:ROMVARS.bStealSize]
[33]39 sub [BDA.wBaseMem], ax
40 mov ax, [BDA.wBaseMem]
[97]41 eSHL_IM ax, 6 ; Segment to first stolen kB (*=40h)
[150]42 ; Fall to .InitializeRamvars
[3]43
[33]44;--------------------------------------------------------------------
[97]45; .InitializeRamvars
[33]46; Parameters:
[241]47; AX: RAMVARS segment
[97]48; Returns:
[33]49; DS: RAMVARS segment
50; Corrupts registers:
51; AX, CX, DI, ES
52;--------------------------------------------------------------------
[97]53.InitializeRamvars:
[241]54 mov ds, ax
55 mov es, ax
[97]56 mov cx, RAMVARS_size
57 xor di, di
58 call Memory_ZeroESDIwithSizeInCX
[150]59 mov WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
[97]60 ; Fall to .InitializeDriveTranslationAndReturn
[3]61
[97]62;--------------------------------------------------------------------
63; .InitializeDriveTranslationAndReturn
64; Parameters:
65; DS: RAMVARS segment
66; Returns:
67; Nothing
68; Corrupts registers:
69; AX
70;--------------------------------------------------------------------
71.InitializeDriveTranslationAndReturn:
72 pop es
73 jmp DriveXlate_Reset
[33]74
[97]75
[3]76;--------------------------------------------------------------------
77; Returns segment to RAMVARS.
78; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
79; or at the top of system base RAM.
80;
81; RamVars_GetSegmentToDS
82; Parameters:
83; Nothing
84; Returns:
85; DS: RAMVARS segment
86; Corrupts registers:
87; DI
88;--------------------------------------------------------------------
89ALIGN JUMP_ALIGN
90RamVars_GetSegmentToDS:
91 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
[33]92 jnz SHORT .GetStolenSegmentToDS
[181]93%ifndef USE_186
[150]94 mov di, LITE_MODE_RAMVARS_SEGMENT
[3]95 mov ds, di
[181]96%else
97 push LITE_MODE_RAMVARS_SEGMENT
98 pop ds
99%endif
[3]100 ret
101
102ALIGN JUMP_ALIGN
[33]103.GetStolenSegmentToDS:
[3]104 LOAD_BDA_SEGMENT_TO ds, di
105 mov di, [BDA.wBaseMem] ; Load available base memory size in kB
[33]106 eSHL_IM di, 6 ; Segment to first stolen kB (*=40h)
[3]107ALIGN JUMP_ALIGN
108.LoopStolenKBs:
109 mov ds, di ; EBDA segment to DS
110 add di, BYTE 64 ; DI to next stolen kB
[150]111 cmp WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
[3]112 jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
113 ret
114
115
116;--------------------------------------------------------------------
117; Checks if INT 13h function is handled by this BIOS.
118;
119; RamVars_IsFunctionHandledByThisBIOS
120; Parameters:
121; AH: INT 13h function number
122; DL: Drive number
123; DS: RAMVARS segment
124; Returns:
[258]125; CF: Cleared if function is handled by this BIOS
126; Set if function belongs to some other BIOS
[3]127; Corrupts registers:
[155]128; Nothing
[3]129;--------------------------------------------------------------------
130ALIGN JUMP_ALIGN
131RamVars_IsFunctionHandledByThisBIOS:
132 test ah, ah ; Reset for all floppy and hard disk drives?
[258]133 jz SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
134 cmp ah, 08h
135%ifdef MODULE_SERIAL_FLOPPY
136; we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts
137 je SHORT RamVars_IsDriveHandledByThisBIOS.CFAlreadyClear_IsHandledByOurBIOS
138%else
139; we handle all *hard disk* traffic for function 08h, as we need to wrap the hard disk drive count
140 je SHORT RamVars_IsDriveHandledByThisBIOS.IsDriveAHardDisk
141%endif
142;;; fall-through
143
[3]144;--------------------------------------------------------------------
145; Checks if drive is handled by this BIOS.
146;
147; RamVars_IsDriveHandledByThisBIOS
148; Parameters:
149; DL: Drive number
150; DS: RAMVARS segment
151; Returns:
[258]152; CF: Cleared if drive is handled by this BIOS
153; Set if drive belongs to some other BIOS
[3]154; Corrupts registers:
[148]155; Nothing
[3]156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158RamVars_IsDriveHandledByThisBIOS:
[148]159 push ax
[258]160
161 mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AH, First number to AL
162 add ah, al ; One past last drive to AH
163 cmp dl, ah ; Above last supported?
164 jae SHORT .HardDiskIsNotHandledByThisBIOS
165.TestLowLimit:
166 cmp dl, al ; Below first supported?
167 jae SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX ; note that CF is clear if the branch is taken
168
169.HardDiskIsNotHandledByThisBIOS:
170%ifdef MODULE_SERIAL_FLOPPY
171 call RamVars_UnpackFlopCntAndFirstToAL
172 cbw ; normally 0h, could be ffh if no drives present
173 adc ah, al ; if no drives present, still ffh (ffh + ffh + 1 = ffh)
174 js SHORT .DiskIsNotHandledByThisBIOS
175 cmp ah, dl
176 jz SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
177 cmp al, dl
178 jz SHORT .CFAlreadyClear_IsHandledByOurBIOS_PopAX
179.DiskIsNotHandledByThisBIOS:
180%endif
181
182 stc ; Is not supported by our BIOS
183
184.CFAlreadyClear_IsHandledByOurBIOS_PopAX:
[148]185 pop ax
[258]186.CFAlreadyClear_IsHandledByOurBIOS:
[3]187 ret
188
[258]189%ifndef MODULE_SERIAL_FLOPPY
190;
191; Note that we could have just checked for the high order bit in dl, but with the needed STC and jumps,
192; leveraging the code above resulted in space savings.
193;
194.IsDriveAHardDisk:
195 push ax ; match stack at the top of routine
196 mov al, 80h ; to catch all hard disks, lower limit is 80h vs. bFirstDrv
197 jmp .TestLowLimit ; and there is no need to test a high limit
198%endif
[3]199
200;--------------------------------------------------------------------
[258]201; RamVars_GetHardDiskCountFromBDAtoAX
[3]202; Parameters:
203; DS: RAMVARS segment
204; Returns:
[258]205; AX: Total hard disk count
[3]206; Corrupts registers:
[258]207; CX
[116]208;--------------------------------------------------------------------
[3]209ALIGN JUMP_ALIGN
[258]210RamVars_GetHardDiskCountFromBDAtoAX:
[3]211 push es
[32]212
[258]213 LOAD_BDA_SEGMENT_TO es, ax
214 call RamVars_GetCountOfKnownDrivesToAX
[181]215 mov cl, [es:BDA.bHDCount]
[258]216 MAX_U al, cl
217
[3]218 pop es
219 ret
[32]220
221;--------------------------------------------------------------------
[258]222; RamVars_GetCountOfKnownDrivesToAX
[32]223; Parameters:
224; DS: RAMVARS segment
225; Returns:
[258]226; AX: Total hard disk count
[32]227; Corrupts registers:
[258]228; None
[116]229;--------------------------------------------------------------------
[32]230ALIGN JUMP_ALIGN
[258]231RamVars_GetCountOfKnownDrivesToAX:
232 mov ax, [RAMVARS.wDrvCntAndFirst]
233 add al, ah
234 and al, 7fh
235 cbw
[32]236 ret
[258]237
[33]238;--------------------------------------------------------------------
239; RamVars_GetIdeControllerCountToCX
240; Parameters:
241; Nothing
242; Returns:
243; CX: Number of IDE controllers to handle
244; Corrupts registers:
245; Nothing
[116]246;--------------------------------------------------------------------
[258]247ALIGN JUMP_ALIGN
[33]248RamVars_GetIdeControllerCountToCX:
[99]249 eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
[33]250 ret
[258]251
252%ifdef MODULE_SERIAL_FLOPPY
253;--------------------------------------------------------------------
254; RamVars_UnpackFlopCntAndFirstToAL
255; Parameters:
256; Nothing
257; Returns:
258; AL: First floppy drive number supported
259; CF: Number of floppy drives supported (clear = 1, set = 2)
260; Corrupts registers:
261; Nothing
262;--------------------------------------------------------------------
263ALIGN JUMP_ALIGN
264RamVars_UnpackFlopCntAndFirstToAL:
265 mov al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst]
266 sar al, 1
267 ret
268%endif
Note: See TracBrowser for help on using the repository browser.