source: xtideuniversalbios/trunk/Configurator/Src/Flash.asm@ 200

Last change on this file since 200 was 2, checked in by Tomi Tilli, 14 years ago
File size: 7.5 KB
Line 
1; File name : Flash.asm
2; Project name : XTIDE Univeral BIOS Configurator
3; Created date : 30.4.2010
4; Last update : 2.5.2010
5; Author : Tomi Tilli
6; Description : Function for flashing the EEPROM.
7
8; Section containing code
9SECTION .text
10
11;--------------------------------------------------------------------
12; Loads old XTIDE Universal BIOS settings from ROM to RAM.
13;
14; EEPROM_LoadSettingsFromRomToRam
15; Parameters:
16; Nothing
17; Returns:
18; Nothing
19; Corrupts registers:
20; BX, CX, ES
21;--------------------------------------------------------------------
22ALIGN JUMP_ALIGN
23Flash_CopyCurrentContentsForComparison:
24 push ds
25 push di
26 push si
27
28 call EEPROM_GetComparisonBufferPointerToDSBX
29 push ds
30 pop es
31 mov di, bx ; Comparison buffer now in ES:DI
32 xor si, si
33 mov ds, [cs:g_cfgVars+CFGVARS.wEepromSegment] ; EEPROM now in DS:SI
34 mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize]
35 shr cx, 1 ; Byte count to word count
36 cld ; MOVSW to increment DI and SI
37 rep movsw
38
39 pop si
40 pop di
41 pop ds
42 ret
43
44
45;--------------------------------------------------------------------
46; Verifies that all data has been written successfully.
47;
48; Flash_WasDataWriteSuccessfull
49; Parameters:
50; Nothing
51; Returns:
52; ZF: Set if data was written successfully
53; Cleared if write failed
54; Corrupts registers:
55; CX, ES
56;--------------------------------------------------------------------
57ALIGN JUMP_ALIGN
58Flash_WasDataWriteSuccessfull:
59 push ds
60 push di
61 push si
62
63 call EEPROM_GetSourceBufferPointerToDSSI
64 call EEPROM_GetEepromPointerToESDI
65 mov cx, [cs:g_cfgVars+CFGVARS.wEepromSize]
66 shr cx, 1 ; Byte count to word count
67 cld ; CMPSW to increment SI and DI
68 repe cmpsw
69
70 pop si
71 pop di
72 pop ds
73 ret
74
75
76;--------------------------------------------------------------------
77; Writes page of data to EEPROM.
78;
79; Flash_WritePage
80; Parameters:
81; AX: SDP command
82; CX: Page size (1, 2, 4, 8, 16, 32 or 64 bytes)
83; DS:BX: Ptr to comparison buffer with old EEPROM data
84; DS:SI: Ptr to source data to write
85; ES:DI: Ptr to destination EEPROM
86; Returns:
87; BX, SI, DI: Updated to next page
88; CF: Cleared if page written successfully
89; Set if polling timeout
90; Corrupts registers:
91; Nothing
92;--------------------------------------------------------------------
93ALIGN JUMP_ALIGN
94Flash_WritePage:
95 call Flash_DoesPageNeedToBeWritten
96 jz SHORT .ReturnWithoutWriting
97 push bp
98 push cx
99 push ax
100
101 mov bp, .LoopWritePageBytes ; Return address from SDP command
102 cli ; Disable interrupts
103 jmp SHORT Flash_WriteSdpCommand
104
105ALIGN JUMP_ALIGN
106.LoopWritePageBytes:
107 lodsb ; Load source byte to AL, increment SI
108 cmp al, [bx] ; Trying to write existing data?
109 je SHORT .SkipByte
110 inc bx ; Increment comparison buffer pointer
111 mov ah, al ; Last byte written to AH
112 mov bp, di ; ES:BP points to last byte written
113 stosb ; Write source byte to EEPROM, increment DI
114 loop .LoopWritePageBytes
115 jmp SHORT .PageCompleted
116ALIGN JUMP_ALIGN
117.SkipByte:
118 inc bx
119 inc di
120 loop .LoopWritePageBytes
121
122ALIGN JUMP_ALIGN
123.PageCompleted:
124 sti ; Enable interrupts
125 call Flash_PollEepromUntilWriteCycleHasCompleted
126 pop ax
127 pop cx
128 pop bp
129 ret
130
131ALIGN JUMP_ALIGN
132.ReturnWithoutWriting:
133 add bx, cx
134 add si, cx
135 add di, cx
136 clc
137 ret
138
139;--------------------------------------------------------------------
140; Compares source data and comparison buffer.
141;
142; Flash_DoesPageNeedToBeWritten
143; Parameters:
144; CX: Page size (1, 2, 4, 8, 16, 32 or 64 bytes)
145; DS:BX: Ptr to comparison buffer with old EEPROM data
146; DS:SI: Ptr to source data to write
147; Returns:
148; ZF: Set if no need to write page
149; Cleared if writing is needed
150; Corrupts registers:
151; Nothing
152;--------------------------------------------------------------------
153ALIGN JUMP_ALIGN
154Flash_DoesPageNeedToBeWritten:
155 push es
156 push di
157 push si
158 push cx
159
160 push ds
161 pop es
162 mov di, bx ; ES:DI now points to comparison buffer
163 cld ; CMPSB to increment SI and DI
164 repe cmpsb
165
166 pop cx
167 pop si
168 pop di
169 pop es
170 ret
171
172
173;--------------------------------------------------------------------
174; Writes Software Data Protection command to EEPROM.
175;
176; Flash_WriteSdpCommand
177; Parameters:
178; AX: SDP command
179; BP: Return address
180; ES: Segment to EEPROM
181; Returns:
182; Nothing
183; Corrupts registers:
184; Nothing
185;--------------------------------------------------------------------
186ALIGN JUMP_ALIGN
187Flash_WriteSdpCommand:
188 cmp ax, CMD_SDP_ENABLE
189 je SHORT Flash_WriteSdpEnableCommand
190 cmp ax, CMD_SDP_DISABLE
191 je SHORT Flash_WriteSdpDisableCommand
192 jmp bp
193
194ALIGN JUMP_ALIGN
195Flash_WriteSdpEnableCommand:
196 mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h
197 mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh
198 mov BYTE [es:1555h], 0A0h ; Write A0h to address 1555h
199 jmp bp
200
201ALIGN JUMP_ALIGN
202Flash_WriteSdpDisableCommand:
203 mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h
204 mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh
205 mov BYTE [es:1555h], 80h ; Write 80h to address 1555h
206 mov BYTE [es:1555h], 0AAh ; Write AAh to address 1555h
207 mov BYTE [es:0AAAh], 55h ; Write 55h to address 0AAAh
208 mov BYTE [es:1555h], 20h ; Write 20h to address 1555h
209 jmp bp
210
211
212;--------------------------------------------------------------------
213; Polls EEPROM until write cycle ends.
214;
215; Flash_PollEepromUntilWriteCycleHasCompleted
216; Parameters:
217; AH: Last byte written
218; ES:BP: Ptr to EEPROM last write location
219; Returns:
220; CF: Cleared if polling successfull
221; Set if polling timeout
222; Corrupts registers:
223; AX, CX
224;--------------------------------------------------------------------
225ALIGN JUMP_ALIGN
226Flash_PollEepromUntilWriteCycleHasCompleted:
227 call Flash_InitializePollingTimeout
228ALIGN JUMP_ALIGN
229.PollLoop:
230 mov al, [es:bp] ; Load byte from EEPROM
231 and ax, 8080h ; Clear all but bit 7 from both bytes
232 cmp al, ah ; Same bytes?
233 je SHORT .Return
234 call Flash_UpdatePollingTimeout
235 jnc SHORT .PollLoop ; Not timeout
236ALIGN JUMP_ALIGN
237.Return:
238 ret
239
240;--------------------------------------------------------------------
241; Initializes timeout counter. Timeouts are implemented using system
242; timer ticks. First tick might take 0...54.9ms and remaining ticks
243; will occur at 54.9ms intervals. Use delay of two (or more) ticks to
244; ensure at least 54.9ms wait.
245;
246; Flash_InitializePollingTimeout
247; Parameters:
248; Nothing
249; Returns:
250; CX: Timeout end time for Flash_UpdatePollingTimeout
251; Corrupts registers:
252; Nothing
253;--------------------------------------------------------------------
254ALIGN JUMP_ALIGN
255Flash_InitializePollingTimeout:
256 push ds
257 LOAD_BDA_SEGMENT_TO ds, cx
258 mov cx, CNT_TMEOUT_POLL
259 add cx, [BDA.dwTimerTicks] ; CX = End time
260 pop ds
261 sti ; Enable interrupts
262 ret
263
264;--------------------------------------------------------------------
265; Updates timeout counter. Timeout counter can be
266; initialized with Flash_InitializePollingTimeout.
267;
268; Flash_UpdatePollingTimeout
269; Parameters:
270; CX: Timeout end time
271; Returns:
272; CF: Set if timeout
273; Cleared if time left
274; Corrupts registers:
275; Nothing
276;--------------------------------------------------------------------
277ALIGN JUMP_ALIGN
278Flash_UpdatePollingTimeout:
279 push ds
280 push ax
281 LOAD_BDA_SEGMENT_TO ds, ax
282 cmp cx, [BDA.dwTimerTicks] ; Timeout?
283 pop ax
284 pop ds
285 je SHORT .ReturnTimeout
286 clc
287 ret
288.ReturnTimeout:
289 stc
290 ret
Note: See TracBrowser for help on using the repository browser.