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

Last change on this file since 240 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: 6.3 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:
[3]33 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
[97]34 jz SHORT .InitializeRamvars ; No need to steal RAM
[3]35
[116]36 LOAD_BDA_SEGMENT_TO ds, ax, ! ; Zero AX
[3]37 mov al, [cs:ROMVARS.bStealSize]
[33]38 sub [BDA.wBaseMem], ax
39 mov ax, [BDA.wBaseMem]
[97]40 eSHL_IM ax, 6 ; Segment to first stolen kB (*=40h)
[33]41 mov ds, ax
[150]42 mov WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
43 ; Fall to .InitializeRamvars
[3]44
[33]45;--------------------------------------------------------------------
[97]46; .InitializeRamvars
[33]47; Parameters:
[97]48; Nothing
49; Returns:
[33]50; DS: RAMVARS segment
51; Corrupts registers:
52; AX, CX, DI, ES
53;--------------------------------------------------------------------
[97]54.InitializeRamvars:
55 call RamVars_GetSegmentToDS
56 mov cx, RAMVARS_size
57 xor di, di
[33]58 push ds
59 pop es
[97]60 call Memory_ZeroESDIwithSizeInCX
[150]61 mov WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
[97]62 ; Fall to .InitializeDriveTranslationAndReturn
[3]63
[97]64;--------------------------------------------------------------------
65; .InitializeDriveTranslationAndReturn
66; Parameters:
67; DS: RAMVARS segment
68; Returns:
69; Nothing
70; Corrupts registers:
71; AX
72;--------------------------------------------------------------------
73.InitializeDriveTranslationAndReturn:
74 pop es
75 jmp DriveXlate_Reset
[33]76
[97]77
[3]78;--------------------------------------------------------------------
79; Returns segment to RAMVARS.
80; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
81; or at the top of system base RAM.
82;
83; RamVars_GetSegmentToDS
84; Parameters:
85; Nothing
86; Returns:
87; DS: RAMVARS segment
88; Corrupts registers:
89; DI
90;--------------------------------------------------------------------
91ALIGN JUMP_ALIGN
92RamVars_GetSegmentToDS:
93 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
[33]94 jnz SHORT .GetStolenSegmentToDS
[181]95%ifndef USE_186
[150]96 mov di, LITE_MODE_RAMVARS_SEGMENT
[3]97 mov ds, di
[181]98%else
99 push LITE_MODE_RAMVARS_SEGMENT
100 pop ds
101%endif
[3]102 ret
103
104ALIGN JUMP_ALIGN
[33]105.GetStolenSegmentToDS:
[3]106 LOAD_BDA_SEGMENT_TO ds, di
107 mov di, [BDA.wBaseMem] ; Load available base memory size in kB
[33]108 eSHL_IM di, 6 ; Segment to first stolen kB (*=40h)
[3]109ALIGN JUMP_ALIGN
110.LoopStolenKBs:
111 mov ds, di ; EBDA segment to DS
112 add di, BYTE 64 ; DI to next stolen kB
[150]113 cmp WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
[3]114 jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
115 ret
116
117
118;--------------------------------------------------------------------
119; Checks if INT 13h function is handled by this BIOS.
120;
121; RamVars_IsFunctionHandledByThisBIOS
122; Parameters:
123; AH: INT 13h function number
124; DL: Drive number
125; DS: RAMVARS segment
126; Returns:
127; CF: Set if function is handled by this BIOS
128; Cleared if function belongs to some other BIOS
129; Corrupts registers:
[155]130; Nothing
[3]131;--------------------------------------------------------------------
132ALIGN JUMP_ALIGN
133RamVars_IsFunctionHandledByThisBIOS:
134 test ah, ah ; Reset for all floppy and hard disk drives?
[32]135 jz SHORT .FunctionIsHandledByOurBIOS
136 cmp ah, 08h ; Read Disk Drive Parameters?
137 jne SHORT RamVars_IsDriveHandledByThisBIOS
[128]138 test dl, dl ; We do not handle floppy drives
139 jns SHORT .FunctionIsNotHandledByOurBIOS
[32]140ALIGN JUMP_ALIGN
141.FunctionIsHandledByOurBIOS:
[3]142 stc
[32]143.FunctionIsNotHandledByOurBIOS:
[3]144 ret
145
146;--------------------------------------------------------------------
147; Checks if drive is handled by this BIOS.
148;
149; RamVars_IsDriveHandledByThisBIOS
150; Parameters:
151; DL: Drive number
152; DS: RAMVARS segment
153; Returns:
154; CF: Set if drive is handled by this BIOS
155; Cleared if drive belongs to some other BIOS
156; Corrupts registers:
[148]157; Nothing
[3]158;--------------------------------------------------------------------
159ALIGN JUMP_ALIGN
160RamVars_IsDriveHandledByThisBIOS:
[148]161 push ax
[3]162 mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AL, First number to AH
163 add al, ah ; One past last drive to AL
164 cmp dl, al ; Above last supported?
165 jae SHORT .DriveNotHandledByThisBIOS
[145]166 cmp ah, dl ; Below first supported?
167 ja SHORT .DriveNotHandledByThisBIOS
[3]168 stc
169.DriveNotHandledByThisBIOS:
[148]170 pop ax
[3]171 ret
172
173
174;--------------------------------------------------------------------
[32]175; RamVars_GetHardDiskCountFromBDAtoCX
[3]176; Parameters:
177; DS: RAMVARS segment
178; Returns:
[32]179; CX: Total hard disk count
[3]180; Corrupts registers:
[32]181; Nothing
[116]182;--------------------------------------------------------------------
[3]183ALIGN JUMP_ALIGN
[32]184RamVars_GetHardDiskCountFromBDAtoCX:
[3]185 push es
[32]186 push dx
187
[116]188 LOAD_BDA_SEGMENT_TO es, cx, ! ; Zero CX
[32]189 call RamVars_GetCountOfKnownDrivesToDL
[181]190 mov cl, [es:BDA.bHDCount]
191 MAX_U cl, dl
[32]192
193 pop dx
[3]194 pop es
195 ret
[32]196
197;--------------------------------------------------------------------
198; RamVars_GetCountOfKnownDrivesToDL
199; Parameters:
200; DS: RAMVARS segment
201; Returns:
202; DL: Total hard disk count
203; Corrupts registers:
204; Nothing
[116]205;--------------------------------------------------------------------
[32]206ALIGN JUMP_ALIGN
207RamVars_GetCountOfKnownDrivesToDL:
208 mov dl, [RAMVARS.bFirstDrv] ; Number for our first drive
209 add dl, [RAMVARS.bDrvCnt] ; Our drives
210 and dl, 7Fh ; Clear HD bit for drive count
211 ret
[33]212
213
214;--------------------------------------------------------------------
215; RamVars_GetIdeControllerCountToCX
216; Parameters:
217; Nothing
218; Returns:
219; CX: Number of IDE controllers to handle
220; Corrupts registers:
221; Nothing
[116]222;--------------------------------------------------------------------
[33]223RamVars_GetIdeControllerCountToCX:
[99]224 eMOVZX cx, BYTE [cs:ROMVARS.bIdeCnt]
[33]225 ret
Note: See TracBrowser for help on using the repository browser.