Changeset 621 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/FlashSST.asm
- Timestamp:
- Nov 21, 2021, 2:15:32 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/XTIDE_Universal_BIOS_Configurator_v2/Src/FlashSST.asm
r620 r621 3 3 4 4 ; 5 ; Created by Jayeson Lee-Steere 6 ; Hereby placed into the public domain. 5 ; XTIDE Universal BIOS and Associated Tools 6 ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2021 by XTIDE Universal BIOS Team. 7 ; 8 ; This program is free software; you can redistribute it and/or modify 9 ; it under the terms of the GNU General Public License as published by 10 ; the Free Software Foundation; either version 2 of the License, or 11 ; (at your option) any later version. 12 ; 13 ; This program is distributed in the hope that it will be useful, 14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of 15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 ; GNU General Public License for more details. 17 ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 7 18 ; 8 19 … … 27 38 push si 28 39 push bp 29 mov bp, bx ; Flashvars now in SS:BP .40 mov bp, bx ; Flashvars now in SS:BP (Assumes SS=DS) 30 41 31 42 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DeviceNotDetected … … 34 45 35 46 call CalibrateSstTimeout 36 47 37 48 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.PollingTimeoutError 38 49 mov cx, [bp+FLASHVARS.wPagesToFlash] 39 lds si, [bp+FLASHVARS.fpNextSourcePage] 40 les di, [bp+FLASHVARS.fpNextDestinationPage] 50 mov dx, [bp+FLASHVARS.wEepromPageSize] 51 les di, [bp+FLASHVARS.fpNextSourcePage] 52 lds si, [bp+FLASHVARS.fpNextDestinationPage] 41 53 %ifdef CLD_NEEDED 42 54 cld … … 49 61 push di 50 62 push cx 51 mov cx, [bp+FLASHVARS.wEepromPageSize] 52 mov bx, cx 63 mov cx, dx 53 64 repe cmpsb 54 65 pop cx 55 66 pop di 56 67 pop si 57 jn zSHORT .FlashThisPage58 add si, bx59 add di, bx68 jne SHORT .FlashThisPage 69 add si, dx 70 add di, dx 60 71 jmp SHORT .ContinueLoop 61 72 … … 69 80 70 81 ; The write process has already confirmed the results one byte at a time. 71 ; Here we do an additional verify check just in case there was some 82 ; Here we do an additional verify check just in case there was some 72 83 ; kind of oddity with pages / addresses. 73 84 mov BYTE [bp+FLASHVARS.flashResult], FLASH_RESULT.DataVerifyError 85 %ifndef USE_186 74 86 mov ax, [bp+FLASHVARS.wPagesToFlash] 75 mov cl, SST_PAGE_SIZE_SHIFT 87 mov cl, SST_PAGE_SIZE_SHIFT - 1 ; -1 because we compare WORDs (verifying 64 KB won't work otherwise) 76 88 shl ax, cl 77 mov cx, ax 89 xchg cx, ax 90 %else 91 mov cx, [bp+FLASHVARS.wPagesToFlash] 92 shl cx, SST_PAGE_SIZE_SHIFT - 1 93 %endif 78 94 lds si, [bp+FLASHVARS.fpNextSourcePage] 79 95 les di, [bp+FLASHVARS.fpNextDestinationPage] 80 repe cmps b81 jn zSHORT .ExitOnError96 repe cmpsw 97 jne SHORT .ExitOnError 82 98 83 99 %ifndef CHECK_FOR_UNUSED_ENTRYPOINTS … … 106 122 ; Set if supported SST device not found 107 123 ; Corrupts registers: 108 ; AX, DI, ES124 ; AX, BX, SI, DS 109 125 ;-------------------------------------------------------------------- 110 126 ALIGN JUMP_ALIGN 111 127 DetectSstDevice: 112 les di, [bp+FLASHVARS.fpNextDestinationPage] 128 lds si, [bp+FLASHVARS.fpNextDestinationPage] 129 mov bx, 5555h 113 130 114 131 cli 115 mov BYTE [es:05555h], 0AAh ; Enter software ID sequence. 116 mov BYTE [es:02AAAh], 055h 117 mov BYTE [es:05555h], 090h 118 mov al, [es:di] ; Extra reads to be sure device 119 mov al, [es:di] ; has time to respond. 120 mov al, [es:di] 121 mov ah, [es:di] ; Vendor ID in AH. 122 mov al, [es:di + 1] ; Device ID in AL. 123 mov BYTE [es:05555h], 0F0h ; Exit software ID. 132 mov BYTE [bx], 0AAh ; Enter software ID sequence. 133 shr bx, 1 ; BX=2AAAh, CF=1 134 mov BYTE [bx], 55h 135 eRCL_IM bx, 1 ; BX=5555h 136 mov BYTE [bx], 90h 137 mov al, [si] ; Extra reads to be sure device 138 mov al, [si] ; has time to respond. 139 mov al, [si] 140 mov ah, [si] ; Vendor ID in AH. 141 mov al, [si+1] ; Device ID in AL. 142 mov BYTE [bx], 0F0h ; Exit software ID. 124 143 sti 125 144 126 cmp a l, 0B4h145 cmp ax, 0BFB4h 127 146 jb SHORT .NotValidDevice 128 cmp al, 0B7h 129 ja SHORT .NotValidDevice 130 cmp ah, 0BFh 131 jne SHORT .NotValidDevice 132 ret 133 147 cmp ax, 0BFB7h+1 148 cmc 134 149 .NotValidDevice: 135 stc 136 ret 137 150 ret 151 138 152 ;-------------------------------------------------------------------- 139 153 ; CalibrateSstTimeout … … 147 161 ALIGN JUMP_ALIGN 148 162 CalibrateSstTimeout: 149 LOAD_BDA_SEGMENT_TO ds, ax150 les di, [bp+FLASHVARS.fpNextDestinationPage]151 xor cx, cx163 LOAD_BDA_SEGMENT_TO es, cx, ! 164 mov ds, [bp+FLASHVARS.fpNextDestinationPage+2] 165 mov bx, BDA.dwTimerTicks 152 166 mov si, cx 153 167 mov di, cx 154 mov al, [ es:di]155 not al ; Forces poll to fail.156 157 mov bx, [BDA.dwTimerTicks] ; Read low word only.158 inc bx168 mov al, [di] 169 inc ax ; Forces poll to fail 170 171 mov ah, [es:bx] ; Read low byte only 172 inc ah 159 173 .WaitForFirstIncrement: 160 cmp bx, [BDA.dwTimerTicks]161 jn zSHORT .WaitForFirstIncrement162 163 inc bx174 cmp ah, [es:bx] 175 jne SHORT .WaitForFirstIncrement 176 177 inc ah 164 178 165 179 .WaitForSecondIncrement: 166 inc ch ; cx now 0x0100 167 .PollLoop: ; Identical to poll loop used 168 cmp [es:di], al ; during programming 169 jz SHORT .PollComplete ; Will never branch in this case 170 loop .PollLoop 171 .PollComplete: 172 add si, 1 ; number of poll loops completed 173 jc SHORT .countOverflow 174 cmp bx, [BDA.dwTimerTicks] 175 jnz SHORT .WaitForSecondIncrement 176 177 .CalComplete: 178 ; SI ~= number of polling loops in 215us. 179 mov [bp+FLASHVARS.wTimeoutCounter], si 180 ret 181 182 .countOverflow: 180 inc ch ; CX now 0x0100 181 .PollLoop: ; Identical to poll loop used 182 cmp [di], al ; during programming 183 loopne .PollLoop ; Will never be equal in this case 184 inc si ; Number of poll loops completed 185 jz SHORT .CountOverflow 186 cmp ah, [es:bx] 187 jne SHORT .WaitForSecondIncrement 188 SKIP1B al 189 .CountOverflow: 183 190 ; Clamp on overflow, although it should not be possible on 184 191 ; real hardware. In principle SI could overflow on a very … … 187 194 ; the device, SI can not overflow. 188 195 dec si 189 jmp SHORT .CalComplete 196 197 ; SI ~= number of polling loops in 215us. 198 mov [bp+FLASHVARS.wTimeoutCounter], si 199 ret 190 200 191 201 ;-------------------------------------------------------------------- 192 202 ; EraseSstPage 193 203 ; Parameters: 194 ; ES:DI: Destination ptr.204 ; DS:SI: Destination ptr 195 205 ; Returns: 196 206 ; CF: Set on error. 197 207 ; Corrupts registers: 198 ; AX 208 ; AX, BX 199 209 ;-------------------------------------------------------------------- 200 210 ALIGN JUMP_ALIGN … … 202 212 push cx 203 213 204 mov BYTE [es:05555h], 0AAh ; Sector erase sequence. 205 mov BYTE [es:02AAAh], 055h 206 mov BYTE [es:05555h], 080h 207 mov BYTE [es:05555h], 0AAh 208 mov BYTE [es:02AAAh], 055h 209 mov BYTE [es:di], 030h 210 214 mov bx, 5555h 215 mov ax, 2AAAh 216 217 ; Sector erase sequence. 218 mov [bx], al ; [5555h] <- AAh 219 xchg bx, ax 220 mov [bx], al ; [2AAAh] <- 55h 221 xchg bx, ax 222 mov BYTE [bx], 80h ; [5555h] <- 80h 223 mov [bx], al ; [5555h] <- AAh 224 xchg bx, ax 225 mov [bx], al ; [2AAAh] <- 55h 226 mov BYTE [si], 30h 227 228 or bl, al ; BL = 0FFh 211 229 mov ax, 1163 ; 1163 x ~215us = 250ms = 10x datasheet max 212 230 .TimeoutOuterLoop: 213 231 mov cx, [bp+FLASHVARS.wTimeoutCounter] 214 232 .TimeoutInnerLoop: 215 cmp BYTE [es:di], 0FFh ; Will return 0FFh when erase complete.216 jz SHORT .Exit217 loop .TimeoutInnerLoop233 cmp [si], bl ; Will return 0FFh when erase complete 234 loopne .TimeoutInnerLoop 235 je SHORT .Return 218 236 dec ax 219 237 jnz SHORT .TimeoutOuterLoop 220 stc ; Timed out.221 . Exit:238 ; Timed out (CF=1) 239 .Return: 222 240 pop cx 223 241 ret … … 226 244 ; WriteSstPage 227 245 ; Parameters: 228 ; DS:SI: Source ptr. 229 ; ES:DI: Destination ptr. 246 ; DX: EEPROM page size 247 ; DS:SI: Destination ptr 248 ; ES:DI: Source ptr 230 249 ; Returns: 231 250 ; SI, DI: Each advanced forward 1 page. 232 251 ; CF: Set on error. 233 252 ; Corrupts registers: 234 ; AL, BX , DX253 ; AL, BX 235 254 ;-------------------------------------------------------------------- 236 255 ALIGN JUMP_ALIGN 237 256 WriteSstPage: 238 257 push cx 258 push dx 239 259 240 260 mov bx, [bp+FLASHVARS.wTimeoutCounter] 241 mov dx, [bp+FLASHVARS.wEepromPageSize]261 xchg si, di 242 262 cli 243 263 244 264 .NextByte: 245 lodsb246 mov BYTE [ es:05555h], 0AAh; Byte program sequence.247 mov BYTE [ es:02AAAh], 055h248 mov BYTE [ es:05555h], 0A0h249 mov [ es:di], al265 es lodsb ; Read byte from ES:SI 266 mov BYTE [5555h], 0AAh ; Byte program sequence. 267 mov BYTE [2AAAh], 55h 268 mov BYTE [5555h], 0A0h 269 mov [di], al ; Write byte to DS:DI 250 270 251 271 mov cx, bx 252 272 .WaitLoop: 253 cmp [es:di], al ; Device won't return actual data until 254 jz SHORT .ByteFinished ; write complete. Timeout ~215us, or 255 loop .WaitLoop ; ~10x 20us max program time from datasheet. 256 257 stc ; Write timeout. 258 jmp SHORT .Exit 259 260 .ByteFinished: 273 cmp [di], al ; Device won't return actual data until write complete. 274 loopne .WaitLoop ; Timeout ~215us, or ~10x 20us max program time from datasheet. 275 jne SHORT .WriteTimeout 276 261 277 inc di 262 278 dec dx 263 279 jnz SHORT .NextByte 264 clc 265 .Exit: 280 SKIP1B al 281 .WriteTimeout: 282 stc 266 283 sti 267 pop cx 268 ret 284 xchg si, di 285 pop dx 286 pop cx 287 ret
Note:
See TracChangeset
for help on using the changeset viewer.