1 | ; File name : EEPROM.asm |
---|
2 | ; Project name : XTIDE Univeral BIOS Configurator |
---|
3 | ; Created date : 19.4.2010 |
---|
4 | ; Last update : 2.5.2010 |
---|
5 | ; Author : Tomi Tilli |
---|
6 | ; Description : Functions for managing EEPROM contents. |
---|
7 | |
---|
8 | ; Section containing code |
---|
9 | SECTION .text |
---|
10 | |
---|
11 | ;-------------------------------------------------------------------- |
---|
12 | ; Loads XTIDE Universal BIOS from ROM to RAM to be configured. |
---|
13 | ; |
---|
14 | ; EEPROM_LoadBiosFromROM |
---|
15 | ; Parameters: |
---|
16 | ; Nothing |
---|
17 | ; Returns: |
---|
18 | ; CX: BIOS size in bytes |
---|
19 | ; Corrupts registers: |
---|
20 | ; AX, BX, ES |
---|
21 | ;-------------------------------------------------------------------- |
---|
22 | ALIGN JUMP_ALIGN |
---|
23 | EEPROM_LoadBiosFromROM: |
---|
24 | push si |
---|
25 | call EEPROM_FindXtideUniversalBiosROM |
---|
26 | xor si, si ; Load from beginning of ROM |
---|
27 | eMOVZX cx, BYTE [es:ROMVARS.bRomSize] |
---|
28 | eSHL_IM cx, 9 ; *= 512 for byte count |
---|
29 | call EEPROM_LoadBytesFromROM |
---|
30 | pop si |
---|
31 | ret |
---|
32 | |
---|
33 | |
---|
34 | ;-------------------------------------------------------------------- |
---|
35 | ; Loads old XTIDE Universal BIOS settings from ROM to RAM. |
---|
36 | ; |
---|
37 | ; EEPROM_LoadSettingsFromRomToRam |
---|
38 | ; Parameters: |
---|
39 | ; Nothing |
---|
40 | ; Returns: |
---|
41 | ; Nothing |
---|
42 | ; Corrupts registers: |
---|
43 | ; AX, BX, CX, SI, ES |
---|
44 | ;-------------------------------------------------------------------- |
---|
45 | ALIGN JUMP_ALIGN |
---|
46 | EEPROM_LoadSettingsFromRomToRam: |
---|
47 | mov cx, ROMVARS_size - ROMVARS.wFlags ; Number of bytes to load |
---|
48 | mov si, ROMVARS.wFlags ; Offset where to start loading |
---|
49 | ; Fall to EEPROM_LoadBytesFromROM |
---|
50 | |
---|
51 | ;-------------------------------------------------------------------- |
---|
52 | ; Loads wanted number of bytes from XTIDE Universal BIOS ROM. |
---|
53 | ; |
---|
54 | ; EEPROM_LoadBytesFromROM |
---|
55 | ; Parameters: |
---|
56 | ; CX: Number of bytes to load from beginning of ROM |
---|
57 | ; SI: Offset to first byte |
---|
58 | ; Returns: |
---|
59 | ; Nothing |
---|
60 | ; Corrupts registers: |
---|
61 | ; AX, BX, SI, ES |
---|
62 | ;-------------------------------------------------------------------- |
---|
63 | ALIGN JUMP_ALIGN |
---|
64 | EEPROM_LoadBytesFromROM: |
---|
65 | push ds |
---|
66 | push di |
---|
67 | push cx |
---|
68 | |
---|
69 | call EEPROM_FindXtideUniversalBiosROM |
---|
70 | push es |
---|
71 | pop ds ; DS:SI points to ROM |
---|
72 | push cs |
---|
73 | pop es |
---|
74 | lea di, [si+g_cfgVars+CFGVARS.rgbEepromBuffers] ; ES:DI points to RAM buffer |
---|
75 | shr cx, 1 ; Byte count to word count |
---|
76 | cld ; MOVSW to increment SI and DI |
---|
77 | rep movsw ; Read from ROM to RAM |
---|
78 | |
---|
79 | pop cx |
---|
80 | pop di |
---|
81 | pop ds |
---|
82 | ret |
---|
83 | |
---|
84 | |
---|
85 | ;-------------------------------------------------------------------- |
---|
86 | ; Finds EEPROM using known signature. |
---|
87 | ; |
---|
88 | ; EEPROM_FindXtideUniversalBiosROM |
---|
89 | ; Parameters: |
---|
90 | ; Nothing |
---|
91 | ; Returns: |
---|
92 | ; ES: EEPROM segment |
---|
93 | ; CF: Set if EEPROM was found |
---|
94 | ; Cleared if EEPROM not found |
---|
95 | ; Corrupts registers: |
---|
96 | ; AX, BX |
---|
97 | ;-------------------------------------------------------------------- |
---|
98 | ALIGN JUMP_ALIGN |
---|
99 | EEPROM_FindXtideUniversalBiosROM: |
---|
100 | push di |
---|
101 | xor di, di ; Zero DI |
---|
102 | mov bx, 0C000h ; First possible ROM segment |
---|
103 | ALIGN JUMP_ALIGN |
---|
104 | .SegmentLoop: |
---|
105 | mov es, bx ; Possible ROM segment to ES |
---|
106 | call EEPROM_IsXtideUniversalBiosSignaturePresent |
---|
107 | je SHORT .RomFound |
---|
108 | add bx, 200h ; Increment by 8kB |
---|
109 | jnc SHORT .SegmentLoop ; Loop until segment overflows |
---|
110 | pop di |
---|
111 | clc |
---|
112 | ret |
---|
113 | ALIGN JUMP_ALIGN |
---|
114 | .RomFound: |
---|
115 | pop di |
---|
116 | stc |
---|
117 | ret |
---|
118 | |
---|
119 | |
---|
120 | ;-------------------------------------------------------------------- |
---|
121 | ; Checks if XTIDE Universal BIOS is loaded to be configured. |
---|
122 | ; |
---|
123 | ; EEPROM_IsXtideUniversalBiosLoaded |
---|
124 | ; Parameters: |
---|
125 | ; Nothing |
---|
126 | ; Returns: |
---|
127 | ; ZF: Set if signature found |
---|
128 | ; Cleared if signature not present |
---|
129 | ; Corrupts registers: |
---|
130 | ; AX |
---|
131 | ;-------------------------------------------------------------------- |
---|
132 | ALIGN JUMP_ALIGN |
---|
133 | EEPROM_IsXtideUniversalBiosLoaded: |
---|
134 | push es |
---|
135 | push di |
---|
136 | |
---|
137 | push cs |
---|
138 | pop es |
---|
139 | mov di, g_cfgVars+CFGVARS.rgbEepromBuffers |
---|
140 | call EEPROM_IsXtideUniversalBiosSignaturePresent |
---|
141 | |
---|
142 | pop di |
---|
143 | pop es |
---|
144 | ret |
---|
145 | |
---|
146 | |
---|
147 | ;-------------------------------------------------------------------- |
---|
148 | ; Checks if ROM contains Xtide Universal BIOS signature. |
---|
149 | ; |
---|
150 | ; EEPROM_IsXtideUniversalBiosSignaturePresent |
---|
151 | ; Parameters: |
---|
152 | ; ES:DI: Ptr to ROM contents |
---|
153 | ; Returns: |
---|
154 | ; ZF: Set if signature found |
---|
155 | ; Cleared if signature not present |
---|
156 | ; Corrupts registers: |
---|
157 | ; AX |
---|
158 | ;-------------------------------------------------------------------- |
---|
159 | ALIGN JUMP_ALIGN |
---|
160 | EEPROM_IsXtideUniversalBiosSignaturePresent: |
---|
161 | push ds |
---|
162 | push di |
---|
163 | push si |
---|
164 | push cx |
---|
165 | |
---|
166 | push cs |
---|
167 | pop ds |
---|
168 | mov si, g_szSignature ; DS:SI points to known signature string |
---|
169 | add di, BYTE ROMVARS.rgbSign ; ES:DI points to possible ROM signature |
---|
170 | mov cx, LEN_SIGNATURE/2 ; Signature string length in words |
---|
171 | cld ; CMPSW to increment DI and SI |
---|
172 | repe cmpsw |
---|
173 | |
---|
174 | pop cx |
---|
175 | pop si |
---|
176 | pop di |
---|
177 | pop ds |
---|
178 | ret |
---|
179 | |
---|
180 | |
---|
181 | ;-------------------------------------------------------------------- |
---|
182 | ; Called when new BIOS has been loaded to be flashed. |
---|
183 | ; |
---|
184 | ; EEPROM_NewBiosLoadedFromFileOrROM |
---|
185 | ; Parameters: |
---|
186 | ; AX: EEPROM source (FLG_CFGVARS_FILELOADED or FLG_CFGVARS_ROMLOADED) |
---|
187 | ; CX: EEPROM size in bytes |
---|
188 | ; Returns: |
---|
189 | ; Nothing |
---|
190 | ; Corrupts registers: |
---|
191 | ; Nothing |
---|
192 | ;-------------------------------------------------------------------- |
---|
193 | ALIGN JUMP_ALIGN |
---|
194 | EEPROM_NewBiosLoadedFromFileOrROM: |
---|
195 | and WORD [cs:g_cfgVars+CFGVARS.wFlags], ~(FLG_CFGVARS_FILELOADED | FLG_CFGVARS_ROMLOADED | FLG_CFGVARS_UNSAVED) |
---|
196 | or WORD [cs:g_cfgVars+CFGVARS.wFlags], ax |
---|
197 | mov WORD [cs:g_cfgVars+CFGVARS.wEepromSize], cx |
---|
198 | ret |
---|
199 | |
---|
200 | |
---|
201 | ;-------------------------------------------------------------------- |
---|
202 | ; Generated checksum byte to the end of BIOS image buffer. |
---|
203 | ; |
---|
204 | ; EEPROM_GenerateChecksum |
---|
205 | ; Parameters: |
---|
206 | ; Nothing |
---|
207 | ; Returns: |
---|
208 | ; Nothing |
---|
209 | ; Corrupts registers: |
---|
210 | ; AX, BX, CX |
---|
211 | ;-------------------------------------------------------------------- |
---|
212 | ALIGN JUMP_ALIGN |
---|
213 | EEPROM_GenerateChecksum: |
---|
214 | xor ax, ax |
---|
215 | mov bx, g_cfgVars+CFGVARS.rgbEepromBuffers |
---|
216 | mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize] |
---|
217 | dec cx |
---|
218 | ALIGN JUMP_ALIGN |
---|
219 | .ByteLoop: |
---|
220 | add al, [cs:bx] |
---|
221 | inc bx |
---|
222 | loop .ByteLoop |
---|
223 | neg al |
---|
224 | mov [cs:bx], al |
---|
225 | ret |
---|
226 | |
---|
227 | |
---|
228 | ;-------------------------------------------------------------------- |
---|
229 | ; Returns pointer source data to be flashed to EEPROM. |
---|
230 | ; |
---|
231 | ; EEPROM_GetSourceBufferPointerToDSSI |
---|
232 | ; Parameters: |
---|
233 | ; Nothing |
---|
234 | ; Returns: |
---|
235 | ; DS:SI: Ptr to source buffer |
---|
236 | ; Corrupts registers: |
---|
237 | ; Nothing |
---|
238 | ;-------------------------------------------------------------------- |
---|
239 | ALIGN JUMP_ALIGN |
---|
240 | EEPROM_GetSourceBufferPointerToDSSI: |
---|
241 | push cs |
---|
242 | pop ds |
---|
243 | mov si, g_cfgVars+CFGVARS.rgbEepromBuffers |
---|
244 | ret |
---|
245 | |
---|
246 | |
---|
247 | ;-------------------------------------------------------------------- |
---|
248 | ; Returns pointer to comparison buffer for old EEPROM data. |
---|
249 | ; |
---|
250 | ; EEPROM_GetComparisonBufferPointerToDSBX |
---|
251 | ; Parameters: |
---|
252 | ; Nothing |
---|
253 | ; Returns: |
---|
254 | ; DS:BX: Ptr to verify buffer |
---|
255 | ; Corrupts registers: |
---|
256 | ; Nothing |
---|
257 | ;-------------------------------------------------------------------- |
---|
258 | ALIGN JUMP_ALIGN |
---|
259 | EEPROM_GetComparisonBufferPointerToDSBX: |
---|
260 | push cs |
---|
261 | pop ds |
---|
262 | mov bx, [cs:g_cfgVars+CFGVARS.wEepromSize] |
---|
263 | add bx, g_cfgVars+CFGVARS.rgbEepromBuffers |
---|
264 | ret |
---|
265 | |
---|
266 | |
---|
267 | ;-------------------------------------------------------------------- |
---|
268 | ; Returns pointer to EEPROM where to flash. |
---|
269 | ; |
---|
270 | ; EEPROM_GetEepromPointerToESDI |
---|
271 | ; Parameters: |
---|
272 | ; Nothing |
---|
273 | ; Returns: |
---|
274 | ; ES:DI: Ptr to EEPROM |
---|
275 | ; Corrupts registers: |
---|
276 | ; Nothing |
---|
277 | ;-------------------------------------------------------------------- |
---|
278 | ALIGN JUMP_ALIGN |
---|
279 | EEPROM_GetEepromPointerToESDI: |
---|
280 | mov es, [cs:g_cfgVars+CFGVARS.wEepromSegment] |
---|
281 | xor di, di |
---|
282 | ret |
---|