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

Last change on this file since 21 was 3, checked in by Tomi Tilli, 14 years ago
File size: 6.0 KB
RevLine 
[3]1; File name : RamVars.asm
2; Project name : IDE BIOS
3; Created date : 14.3.2010
4; Last update : 2.5.2010
5; Author : Tomi Tilli
6; Description : Functions for accessings RAMVARS.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Initializes RAMVARS.
13; Drive detection can be started after this function returns.
14;
15; RamVars_Initialize
16; Parameters:
17; Nothing
18; Returns:
19; Nothing
20; Corrupts registers:
21; AX, CX, DI, DS, ES
22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24RamVars_Initialize:
25 call RamVars_StealBaseMemory ; Get RAMVARS segment to DS even if no stealing
26 call RamVars_ClearToZero
27 jmp DriveXlate_Reset
28
29
30;--------------------------------------------------------------------
31; Steals base memory to be used for RAMVARS.
32;
33; RamVars_StealBaseMemory
34; Parameters:
35; Nothing
36; Returns:
37; DS: RAMVARS segment
38; Corrupts registers:
39; AX
40;--------------------------------------------------------------------
41ALIGN JUMP_ALIGN
42RamVars_StealBaseMemory:
43 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
44 jz SHORT RamVars_GetSegmentToDS ; No need to steal
45
46 LOAD_BDA_SEGMENT_TO ds, ax ; Zero AX
47 mov al, [cs:ROMVARS.bStealSize]
48 sub [BDA.wBaseMem], ax ; Steal one or more kilobytes
49 mov ax, [BDA.wBaseMem] ; Load base memory left
50 eSHL_IM ax, 6 ; Shift for segment address
51 mov ds, ax ; Copy RAMVARS segment to DS
52 ret
53
54
55;--------------------------------------------------------------------
56; Returns segment to RAMVARS.
57; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
58; or at the top of system base RAM.
59;
60; RamVars_GetSegmentToDS
61; Parameters:
62; Nothing
63; Returns:
64; DS: RAMVARS segment
65; Corrupts registers:
66; DI
67;--------------------------------------------------------------------
68ALIGN JUMP_ALIGN
69RamVars_GetSegmentToDS:
70 test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
71 jnz SHORT RamVars_GetStolenSegmentToDS
72 mov di, SEGMENT_RAMVARS_TOP_OF_INTERRUPT_VECTORS
73 mov ds, di
74 ret
75
76ALIGN JUMP_ALIGN
77RamVars_GetStolenSegmentToDS:
78 LOAD_BDA_SEGMENT_TO ds, di
79 mov di, [BDA.wBaseMem] ; Load available base memory size in kB
80 eSHL_IM di, 6 ; Segment to first stolen kB
81ALIGN JUMP_ALIGN
82.LoopStolenKBs:
83 mov ds, di ; EBDA segment to DS
84 add di, BYTE 64 ; DI to next stolen kB
85 cmp WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
86 jne SHORT .LoopStolenKBs ; Loop until sign found (always found eventually)
87 ret
88
89
90;--------------------------------------------------------------------
91; Clears RAMVARS variables to zero.
92; FULLRAMVARS sign will be saved if available.
93;
94; RamVars_ClearToZero
95; Parameters:
96; DS: RAMVARS segment
97; Returns:
98; Nothing
99; Corrupts registers:
100; AX, CX, DI, ES
101;--------------------------------------------------------------------
102ALIGN JUMP_ALIGN
103RamVars_ClearToZero:
104 call FindDPT_PointToFirstDPT ; Get RAMVARS/FULLRAMVARS size to DI
105 mov cx, di ; Copy byte count to CX
106 push ds
107 pop es
108 xor di, di ; ES:DI now points to RAMVARS/FULLRAMVARS
109 xor ax, ax ; Store zeroes
110 rep stosb
111 mov WORD [FULLRAMVARS.wSign], W_SIGN_FULLRAMVARS
112 ret
113
114
115;--------------------------------------------------------------------
116; Checks if INT 13h function is handled by this BIOS.
117;
118; RamVars_IsFunctionHandledByThisBIOS
119; Parameters:
120; AH: INT 13h function number
121; DL: Drive number
122; DS: RAMVARS segment
123; Returns:
124; CF: Set if function is handled by this BIOS
125; Cleared if function belongs to some other BIOS
126; Corrupts registers:
127; DI
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130RamVars_IsFunctionHandledByThisBIOS:
131 test ah, ah ; Reset for all floppy and hard disk drives?
132 jnz SHORT RamVars_IsDriveHandledByThisBIOS
133 stc
134 ret
135
136;--------------------------------------------------------------------
137; Checks if drive is handled by this BIOS.
138;
139; RamVars_IsDriveHandledByThisBIOS
140; Parameters:
141; DL: Drive number
142; DS: RAMVARS segment
143; Returns:
144; CF: Set if drive is handled by this BIOS
145; Cleared if drive belongs to some other BIOS
146; Corrupts registers:
147; DI
148;--------------------------------------------------------------------
149ALIGN JUMP_ALIGN
150RamVars_IsDriveHandledByThisBIOS:
151 xchg di, ax ; Backup AX
152 mov ax, [RAMVARS.wDrvCntAndFirst] ; Drive count to AL, First number to AH
153 add al, ah ; One past last drive to AL
154 cmp dl, al ; Above last supported?
155 jae SHORT .DriveNotHandledByThisBIOS
156 cmp dl, ah ; Below first supported?
157 jb SHORT .DriveNotHandledByThisBIOS
158 xchg ax, di
159 stc
160 ret
161ALIGN JUMP_ALIGN
162.DriveNotHandledByThisBIOS:
163 xchg ax, di
164 clc
165 ret
166
167
168;--------------------------------------------------------------------
169; Increments hard disk count to RAMVARS.
170;
171; RamVars_IncrementHardDiskCount
172; Parameters:
173; DL: Drive number for new drive
174; DS: RAMVARS segment
175; Returns:
176; Nothing
177; Corrupts registers:
178; Nothing
179;--------------------------------------------------------------------
180ALIGN JUMP_ALIGN
181RamVars_IncrementHardDiskCount:
182 inc BYTE [RAMVARS.bDrvCnt] ; Increment drive count to RAMVARS
183 cmp BYTE [RAMVARS.bFirstDrv], 0 ; First drive set?
184 ja SHORT .Return ; If so, return
185 mov [RAMVARS.bFirstDrv], dl ; Store first drive number
186ALIGN JUMP_ALIGN
187.Return:
188 ret
189
190
191;--------------------------------------------------------------------
192; Return number of Hard Disks in system.
193;
194; RamVars_GetDriveCounts
195; Parameters:
196; DS: RAMVARS segment
197; Returns:
198; AL: Number of hard disks handled by our BIOS
199; CX: Total number of hard disks in system
200; Corrupts registers:
201; AH
202;--------------------------------------------------------------------
203ALIGN JUMP_ALIGN
204RamVars_GetDriveCounts:
205 push es
206 LOAD_BDA_SEGMENT_TO es, cx ; Zero CX
207 mov cl, [es:BDA.bHDCount] ; Total hard drive count
208 mov al, [RAMVARS.bDrvCnt] ; Our drive count
209 pop es
210 ret
Note: See TracBrowser for help on using the repository browser.