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

Last change on this file since 364 was 364, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Advanced ATA Module variables are now kept in DPTs.
  • Forced full mode when using Advanced ATA Module.
File size: 5.1 KB
Line 
1; Project name  :   XTIDE Universal BIOS
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:
15;       DS:     RAMVARS segment
16;   Corrupts registers:
17;       AX, CX, DI
18;--------------------------------------------------------------------
19RamVars_Initialize:
20    push    es
21    ; Fall to .StealMemoryForRAMVARS
22
23;--------------------------------------------------------------------
24; .StealMemoryForRAMVARS
25;   Parameters:
26;       Nothing
27;   Returns:
28;       DS:     RAMVARS segment
29;   Corrupts registers:
30;       AX
31;--------------------------------------------------------------------
32.StealMemoryForRAMVARS:
33    ; Always steal memory when using Advanced ATA module since it
34    ; uses larger DPTs
35%ifndef MODULE_ADVANCED_ATA
36    mov     ax, LITE_MODE_RAMVARS_SEGMENT
37    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
38    jz      SHORT .InitializeRamvars    ; No need to steal RAM
39%endif
40
41    LOAD_BDA_SEGMENT_TO ds, ax, !       ; Zero AX
42    mov     al, [cs:ROMVARS.bStealSize]
43    sub     [BDA.wBaseMem], ax
44    mov     ax, [BDA.wBaseMem]
45    eSHL_IM ax, 6                       ; Segment to first stolen kB (*=40h)
46    ; Fall to .InitializeRamvars
47
48;--------------------------------------------------------------------
49; .InitializeRamvars
50;   Parameters:
51;       AX:     RAMVARS segment
52;   Returns:
53;       DS:     RAMVARS segment
54;   Corrupts registers:
55;       AX, CX, DI, ES
56;--------------------------------------------------------------------
57.InitializeRamvars:
58    mov     ds, ax
59    mov     es, ax
60    mov     cx, RAMVARS_size
61    xor     di, di
62    call    Memory_ZeroESDIwithSizeInCX
63    mov     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
64    ; Fall to .InitializeDriveTranslationAndReturn
65
66;--------------------------------------------------------------------
67; .InitializeDriveTranslationAndReturn
68;   Parameters:
69;       DS:     RAMVARS segment
70;   Returns:
71;       Nothing
72;   Corrupts registers:
73;       AX
74;--------------------------------------------------------------------
75.InitializeDriveTranslationAndReturn:
76    pop     es
77    jmp     DriveXlate_Reset
78
79
80;--------------------------------------------------------------------
81; Returns segment to RAMVARS.
82; RAMVARS might be located at the top of interrupt vectors (0030:0000h)
83; or at the top of system base RAM.
84;
85; RamVars_GetSegmentToDS
86;   Parameters:
87;       Nothing
88;   Returns:
89;       DS:     RAMVARS segment
90;   Corrupts registers:
91;       DI
92;--------------------------------------------------------------------
93ALIGN JUMP_ALIGN
94RamVars_GetSegmentToDS:
95    test    BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
96    jnz     SHORT .GetStolenSegmentToDS
97%ifndef USE_186
98    mov     di, LITE_MODE_RAMVARS_SEGMENT
99    mov     ds, di
100%else
101    push    LITE_MODE_RAMVARS_SEGMENT
102    pop     ds
103%endif
104    ret
105
106ALIGN JUMP_ALIGN
107.GetStolenSegmentToDS:
108    LOAD_BDA_SEGMENT_TO ds, di
109    mov     di, [BDA.wBaseMem]      ; Load available base memory size in kB
110    eSHL_IM di, 6                   ; Segment to first stolen kB (*=40h)
111ALIGN JUMP_ALIGN
112.LoopStolenKBs:
113    mov     ds, di                  ; EBDA segment to DS
114    add     di, BYTE 64             ; DI to next stolen kB
115    cmp     WORD [RAMVARS.wSignature], RAMVARS_SIGNATURE
116    jne     SHORT .LoopStolenKBs    ; Loop until sign found (always found eventually)
117    ret
118
119
120;--------------------------------------------------------------------
121; RamVars_GetHardDiskCountFromBDAtoAX
122;   Parameters:
123;       DS:     RAMVARS segment
124;   Returns:
125;       AX:     Total hard disk count
126;   Corrupts registers:
127;       CX
128;--------------------------------------------------------------------
129ALIGN JUMP_ALIGN
130RamVars_GetHardDiskCountFromBDAtoAX:
131    call    RamVars_GetCountOfKnownDrivesToAX
132    push    ds
133    LOAD_BDA_SEGMENT_TO ds, cx
134    mov     cl, [BDA.bHDCount]
135    MAX_U   al, cl
136    pop     ds
137    ret
138
139;--------------------------------------------------------------------
140; RamVars_GetCountOfKnownDrivesToAX
141;   Parameters:
142;       DS:     RAMVARS segment
143;   Returns:
144;       AX:     Total hard disk count
145;   Corrupts registers:
146;       None
147;--------------------------------------------------------------------
148ALIGN JUMP_ALIGN
149RamVars_GetCountOfKnownDrivesToAX:
150    mov     ax, [RAMVARS.wDrvCntAndFirst]
151    add     al, ah
152    and     al, 7fh
153    cbw
154    ret
155
156;--------------------------------------------------------------------
157; RamVars_GetIdeControllerCountToCX
158;   Parameters:
159;       Nothing
160;   Returns:
161;       CX:     Number of IDE controllers to handle
162;   Corrupts registers:
163;       Nothing
164;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
166RamVars_GetIdeControllerCountToCX:
167    eMOVZX  cx, [cs:ROMVARS.bIdeCnt]
168    ret
169
170%ifdef MODULE_SERIAL_FLOPPY
171;--------------------------------------------------------------------
172; RamVars_UnpackFlopCntAndFirstToAL
173;   Parameters:
174;       Nothing
175;   Returns:
176;       AL:     First floppy drive number supported
177;       CF:     Number of floppy drives supported (clear = 1, set = 2)
178;       SF:     Emulating drives (clear = yes, set = no)
179;   Corrupts registers:
180;       Nothing
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
183RamVars_UnpackFlopCntAndFirstToAL:
184    mov     al, [RAMVARS.xlateVars+XLATEVARS.bFlopCntAndFirst]
185    sar     al, 1
186    ret
187%endif
Note: See TracBrowser for help on using the repository browser.