sc520_asm.S 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (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. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /* This file is largely based on code obtned from AMD. AMD's original
  24. * copyright is included below
  25. */
  26. /* TITLE SIZER - Aspen DRAM Sizing Routine.
  27. * =============================================================================
  28. *
  29. * Copyright 1999 Advanced Micro Devices, Inc.
  30. * You may redistribute this program and/or modify this program under the terms
  31. * of the GNU General Public License as published by the Free Software Foundation;
  32. * either version 2 of the License, or (at your option) any later version.
  33. *
  34. * This program is distributed WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED
  35. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  36. * General Public License for more details.
  37. *
  38. * You should have received a copy of the GNU General Public License along with
  39. * this program; if not, write to the Free Software Foundation, Inc.,
  40. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  41. *
  42. * THE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY
  43. * OF ANY KIND INCLUDING WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT OF
  44. * THIRD-PARTY INTELLECTUAL PROPERTY, OR FITNESS FOR ANY PARTICULAR PURPOSE.
  45. * IN NO EVENT SHALL AMD OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER
  46. * (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS
  47. * INTERRUPTION, LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR INABILITY
  48. * TO USE THE MATERIALS, EVEN IF AMD HAS BEEN ADVISED OF THE POSSIBILITY OF
  49. * SUCH DAMAGES. BECAUSE SOME JURSIDICTIONS PROHIBIT THE EXCLUSION OR
  50. * LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES, THE ABOVE
  51. * LIMITATION MAY NOT APPLY TO YOU.
  52. *
  53. * AMD does not assume any responsibility for any errors that may appear in
  54. * the Materials nor any responsibility to support or update the Materials.
  55. * AMD retains the right to make changes to its test specifications at any
  56. * time, without notice.
  57. * ==============================================================================
  58. */
  59. /*
  60. ******************************************************************************
  61. *
  62. * FILE : sizer.asm - SDRAM DIMM Sizing Algorithm
  63. *
  64. *
  65. *
  66. * FUNCTIONS : sizemem() - jumped to, not called. To be executed after
  67. * reset to determine the size of the SDRAM DIMMs. Initializes
  68. * the memory subsystem.
  69. *
  70. *
  71. * AUTHOR : Buddy Fey - Original.
  72. *
  73. *
  74. * DESCRIPTION : Performs sizing on SDRAM DIMMs on ASPEN processor.
  75. * NOTE: This is a small memory model version
  76. *
  77. *
  78. * INPUTS : BP contains return address offset
  79. * CACHE is assumed to be disabled.
  80. * The FS segment limit has already been set to big real mode
  81. * (full 32-bit addressing capability)
  82. *
  83. *
  84. * OUTPUTS : None
  85. *
  86. *
  87. * REG USE : ax,bx,cx,dx,di,si,bp, fs
  88. *
  89. *
  90. * REVISION : See PVCS info below
  91. *
  92. *
  93. * TEST PLAN CROSS REFERENCE:
  94. *
  95. *
  96. * $Workfile: $
  97. * $Revision: 1.2 $
  98. * $Date: 1999/09/22 12:49:33 $
  99. * $Author: chipf $
  100. * $Log: sizer.asm $
  101. * Revision 1.2 1999/09/22 12:49:33 chipf
  102. * Add legal header
  103. *
  104. *******************************************************************************
  105. */
  106. /*******************************************************************************
  107. * FUNCTIONAL DESCRIPTION:
  108. * This routine is called to autodetect the geometry of the DRAM.
  109. *
  110. * This routine is called to determine the number of column bits for the DRAM
  111. * devices in this external bank. This routine assumes that the external bank
  112. * has been configured for an 11-bit column and for 4 internal banks. This gives
  113. * us the maximum address reach in memory. By writing a test value to the max
  114. * address and locating where it aliases to, we can determine the number of valid
  115. * column bits.
  116. *
  117. * This routine is called to determine the number of internal banks each DRAM
  118. * device has. The external bank (under test) is configured for maximum reach
  119. * with 11-bit columns and 4 internal banks. This routine will write to a max
  120. * address (BA1 and BA0 = 1) and then read from an address with BA1=0 to see if
  121. * that column is a "don't care". If BA1 does not affect write/read of data,
  122. * then this device has only 2 internal banks.
  123. *
  124. * This routine is called to determine the ending address for this external
  125. * bank of SDRAM. We write to a max address with a data value and then disable
  126. * row address bits looking for "don't care" locations. Each "don't care" bit
  127. * represents a dividing of the maximum density (128M) by 2. By dividing the
  128. * maximum of 32 4M chunks in an external bank down by all the "don't care" bits
  129. * determined during sizing, we set the proper density.
  130. *
  131. * WARNINGS.
  132. * bp must be preserved because it is used for return linkage.
  133. *
  134. * EXIT
  135. * nothing returned - but the memory subsystem is enabled
  136. *******************************************************************************
  137. */
  138. #include <config.h>
  139. .section .text
  140. .equ DRCCTL, 0x0fffef010 /* DRAM control register */
  141. .equ DRCTMCTL, 0x0fffef012 /* DRAM timing control register */
  142. .equ DRCCFG, 0x0fffef014 /* DRAM bank configuration register */
  143. .equ DRCBENDADR, 0x0fffef018 /* DRAM bank ending address register */
  144. .equ ECCCTL, 0x0fffef020 /* DRAM ECC control register */
  145. .equ ECCINT, 0x0fffefd18 /* DRAM ECC nmi-INT mapping */
  146. .equ DBCTL, 0x0fffef040 /* DRAM buffer control register */
  147. .equ CACHELINESZ, 0x00000010 /* size of our cache line (read buffer) */
  148. .equ COL11_ADR, 0x0e001e00 /* 11 col addrs */
  149. .equ COL10_ADR, 0x0e000e00 /* 10 col addrs */
  150. .equ COL09_ADR, 0x0e000600 /* 9 col addrs */
  151. .equ COL08_ADR, 0x0e000200 /* 8 col addrs */
  152. .equ ROW14_ADR, 0x0f000000 /* 14 row addrs */
  153. .equ ROW13_ADR, 0x07000000 /* 13 row addrs */
  154. .equ ROW12_ADR, 0x03000000 /* 12 row addrs */
  155. .equ ROW11_ADR, 0x01000000 /* 11 row addrs/also bank switch */
  156. .equ ROW10_ADR, 0x00000000 /* 10 row addrs/also bank switch */
  157. .equ COL11_DATA, 0x0b0b0b0b /* 11 col addrs */
  158. .equ COL10_DATA, 0x0a0a0a0a /* 10 col data */
  159. .equ COL09_DATA, 0x09090909 /* 9 col data */
  160. .equ COL08_DATA, 0x08080808 /* 8 col data */
  161. .equ ROW14_DATA, 0x3f3f3f3f /* 14 row data (MASK) */
  162. .equ ROW13_DATA, 0x1f1f1f1f /* 13 row data (MASK) */
  163. .equ ROW12_DATA, 0x0f0f0f0f /* 12 row data (MASK) */
  164. .equ ROW11_DATA, 0x07070707 /* 11 row data/also bank switch (MASK) */
  165. .equ ROW10_DATA, 0xaaaaaaaa /* 10 row data/also bank switch (MASK) */
  166. .globl mem_init
  167. mem_init:
  168. /* initialize dram controller registers */
  169. xorw %ax, %ax
  170. movl $DBCTL, %edi
  171. movb %al, (%edi) /* disable write buffer */
  172. movl $ECCCTL, %edi
  173. movb %al, (%edi) /* disable ECC */
  174. movl $DRCTMCTL, %edi
  175. movb $0x1e, %al /* Set SDRAM timing for slowest */
  176. movb %al, (%edi)
  177. /* setup loop to do 4 external banks starting with bank 3 */
  178. movl $0xff000000, %eax /* enable last bank and setup */
  179. movl $DRCBENDADR, %edi /* ending address register */
  180. movl %eax, (%edi)
  181. movl $DRCCFG, %edi /* setup */
  182. movw $0xbbbb, %ax /* dram config register for */
  183. movw %ax, (%edi)
  184. /* issue a NOP to all DRAMs */
  185. movl $DRCCTL, %edi /* setup DRAM control register with */
  186. movb $0x01, %al /* Disable refresh,disable write buffer */
  187. movb %al, (%edi)
  188. movl $CACHELINESZ, %esi /* just a dummy address to write for */
  189. movw %ax, (%esi)
  190. /* delay for 100 usec? */
  191. movw $100, %cx
  192. sizdelay:
  193. loop sizdelay
  194. /* issue all banks precharge */
  195. movb $0x02, %al
  196. movb %al, (%edi)
  197. movw %ax, (%esi)
  198. /* issue 2 auto refreshes to all banks */
  199. movb $0x04, %al /* Auto refresh cmd */
  200. movb %al, (%edi)
  201. movw $0x02, %cx
  202. refresh1:
  203. movw %ax, (%esi)
  204. loop refresh1
  205. /* issue LOAD MODE REGISTER command */
  206. movb $0x03, %al /* Load mode register cmd */
  207. movb %al, (%edi)
  208. movw %ax, (%esi)
  209. /* issue 8 more auto refreshes to all banks */
  210. movb $0x04, %al /* Auto refresh cmd */
  211. movb %al, (%edi)
  212. movw $0x0008, %cx
  213. refresh2:
  214. movw %ax, (%esi)
  215. loop refresh2
  216. /* set control register to NORMAL mode */
  217. movb $0x00, %al /* Normal mode value */
  218. movb %al, (%edi)
  219. /*
  220. * size dram starting with external bank 3
  221. * moving to external bank 0
  222. */
  223. movl $0x3, %ecx /* start with external bank 3 */
  224. nextbank:
  225. /* write col 11 wrap adr */
  226. movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */
  227. movl $COL11_DATA, %eax /* pattern for max supported columns(11) */
  228. movl %eax, (%esi) /* write max col pattern at max col adr */
  229. movl (%esi), %ebx /* optional read */
  230. cmpl %ebx, %eax /* to verify write */
  231. jnz bad_ram /* this ram is bad */
  232. /* write col 10 wrap adr */
  233. movl $COL10_ADR, %esi /* set address to 10 col wrap address */
  234. movl $COL10_DATA, %eax /* pattern for 10 col wrap */
  235. movl %eax, (%esi) /* write 10 col pattern @ 10 col wrap adr */
  236. movl (%esi), %ebx /* optional read */
  237. cmpl %ebx, %eax /* to verify write */
  238. jnz bad_ram /* this ram is bad */
  239. /* write col 9 wrap adr */
  240. movl $COL09_ADR, %esi /* set address to 9 col wrap address */
  241. movl $COL09_DATA, %eax /* pattern for 9 col wrap */
  242. movl %eax, (%esi) /* write 9 col pattern @ 9 col wrap adr */
  243. movl (%esi), %ebx /* optional read */
  244. cmpl %ebx, %eax /* to verify write */
  245. jnz bad_ram /* this ram is bad */
  246. /* write col 8 wrap adr */
  247. movl $COL08_ADR, %esi /* set address to min(8) col wrap address */
  248. movl $COL08_DATA, %eax /* pattern for min (8) col wrap */
  249. movl %eax, (%esi) /* write min col pattern @ min col adr */
  250. movl (%esi), %ebx /* optional read */
  251. cmpl %ebx, %eax /* to verify write */
  252. jnz bad_ram /* this ram is bad */
  253. /* write row 14 wrap adr */
  254. movl $ROW14_ADR, %esi /* set address to max row (14) wrap addr */
  255. movl $ROW14_DATA, %eax /* pattern for max supported rows(14) */
  256. movl %eax, (%esi) /* write max row pattern at max row adr */
  257. movl (%esi), %ebx /* optional read */
  258. cmpl %ebx, %eax /* to verify write */
  259. jnz bad_ram /* this ram is bad */
  260. /* write row 13 wrap adr */
  261. movl $ROW13_ADR, %esi /* set address to 13 row wrap address */
  262. movl $ROW13_DATA, %eax /* pattern for 13 row wrap */
  263. movl %eax, (%esi) /* write 13 row pattern @ 13 row wrap adr */
  264. movl (%esi), %ebx /* optional read */
  265. cmpl %ebx, %eax /* to verify write */
  266. jnz bad_ram /* this ram is bad */
  267. /* write row 12 wrap adr */
  268. movl $ROW12_ADR, %esi /* set address to 12 row wrap address */
  269. movl $ROW12_DATA, %eax /* pattern for 12 row wrap */
  270. movl %eax, (%esi) /* write 12 row pattern @ 12 row wrap adr */
  271. movl (%esi), %ebx /* optional read */
  272. cmpl %ebx, %eax /* to verify write */
  273. jnz bad_ram /* this ram is bad */
  274. /* write row 11 wrap adr */
  275. movl $ROW11_ADR, %edi /* set address to 11 row wrap address */
  276. movl $ROW11_DATA, %eax /* pattern for 11 row wrap */
  277. movl %eax, (%edi) /* write 11 row pattern @ 11 row wrap adr */
  278. movl (%edi), %ebx /* optional read */
  279. cmpl %ebx, %eax /* to verify write */
  280. jnz bad_ram /* this ram is bad */
  281. /*
  282. * write row 10 wrap adr --- this write is really to determine
  283. * number of banks
  284. */
  285. movl $ROW10_ADR, %edi /* set address to 10 row wrap address */
  286. movl $ROW10_DATA, %eax /* pattern for 10 row wrap (AA) */
  287. movl %eax, (%edi) /* write 10 row pattern @ 10 row wrap adr */
  288. movl (%edi), %ebx /* optional read */
  289. cmpl %ebx, %eax /* to verify write */
  290. jnz bad_ram /* this ram is bad */
  291. /*
  292. * read data @ row 12 wrap adr to determine * banks,
  293. * and read data @ row 14 wrap adr to determine * rows.
  294. * if data @ row 12 wrap adr is not AA, 11 or 12 we have bad RAM.
  295. * if data @ row 12 wrap == AA, we only have 2 banks, NOT 4
  296. * if data @ row 12 wrap == 11 or 12, we have 4 banks,
  297. */
  298. xorw %di, %di /* value for 2 banks in DI */
  299. movl (%esi), %ebx /* read from 12 row wrap to check banks */
  300. /* (esi is setup from the write to row 12 wrap) */
  301. cmpl %ebx, %eax /* check for AA pattern (eax holds the aa pattern) */
  302. jz only2 /* if pattern == AA, we only have 2 banks */
  303. /* 4 banks */
  304. movw $0x008, %di /* value for 4 banks in DI (BNK_CNT bit) */
  305. cmpl $ROW11_DATA, %ebx /* only other legitimate values are 11 */
  306. jz only2
  307. cmpl $ROW12_DATA, %ebx /* and 12 */
  308. jnz bad_ram /* its bad if not 11 or 12! */
  309. /* fall through */
  310. only2:
  311. /*
  312. * validate row mask
  313. */
  314. movl $ROW14_ADR, %esi /* set address back to max row wrap addr */
  315. movl (%esi), %eax /* read actual number of rows @ row14 adr */
  316. cmpl $ROW11_DATA, %eax /* row must be greater than 11 pattern */
  317. jb bad_ram
  318. cmpl $ROW14_DATA, %eax /* and row must be less than 14 pattern */
  319. ja bad_ram
  320. cmpb %ah, %al /* verify all 4 bytes of dword same */
  321. jnz bad_ram
  322. movl %eax, %ebx
  323. shrl $16, %ebx
  324. cmpw %bx, %ax
  325. jnz bad_ram
  326. /*
  327. * read col 11 wrap adr for real column data value
  328. */
  329. movl $COL11_ADR, %esi /* set address to max col (11) wrap addr */
  330. movl (%esi), %eax /* read real col number at max col adr */
  331. /*
  332. * validate column data
  333. */
  334. cmpl $COL08_DATA, %eax /* col must be greater than 8 pattern */
  335. jb bad_ram
  336. cmpl $COL11_DATA, %eax /* and row must be less than 11 pattern */
  337. ja bad_ram
  338. subl $COL08_DATA, %eax /* normalize column data to zero */
  339. jc bad_ram
  340. cmpb %ah, %al /* verify all 4 bytes of dword equal */
  341. jnz bad_ram
  342. movl %eax, %edx
  343. shrl $16, %edx
  344. cmpw %dx, %ax
  345. jnz bad_ram
  346. /*
  347. * merge bank and col data together
  348. */
  349. addw %di, %dx /* merge of bank and col info in dl */
  350. /*
  351. * fix ending addr mask based upon col info
  352. */
  353. movb $0x03, %al
  354. subb %dh, %al /* dh contains the overflow from the bank/col merge */
  355. movb %bl, %dh /* bl contains the row mask (aa, 07, 0f, 1f or 3f) */
  356. xchgw %cx, %ax /* cx = ax = 3 or 2 depending on 2 or 4 bank device */
  357. shrb %cl, %dh
  358. incb %dh /* ending addr is 1 greater than real end */
  359. xchgw %cx, %ax /* cx is bank number again */
  360. bad_reint:
  361. /*
  362. * issue all banks precharge
  363. */
  364. movl $DRCCTL, %esi /* setup DRAM control register with */
  365. movb $0x02, %al /* All banks precharge */
  366. movb %al, (%esi)
  367. movl $CACHELINESZ, %esi /* address to init read buffer */
  368. movw %ax, (%esi)
  369. /*
  370. * update ENDING ADDRESS REGISTER
  371. */
  372. movl $DRCBENDADR, %edi /* DRAM ending address register */
  373. movl %ecx, %ebx
  374. addl %ebx, %edi
  375. movb %dh, (%edi)
  376. /*
  377. * update CONFIG REGISTER
  378. */
  379. xorb %dh, %dh
  380. movw $0x000f, %bx
  381. movw %cx, %ax
  382. shlw $2, %ax
  383. xchgw %cx, %ax
  384. shlw %cl, %dx
  385. shlw %cl, %bx
  386. notw %bx
  387. xchgw %cx, %ax
  388. movl $DRCCFG, %edi
  389. movw (%edi), %ax
  390. andw %bx, %ax
  391. orw %dx, %ax
  392. movw %ax, (%edi)
  393. jcxz cleanup
  394. decw %cx
  395. movl %ecx, %ebx
  396. movl $DRCBENDADR, %edi /* DRAM ending address register */
  397. movb $0xff, %al
  398. addl %ebx, %edi
  399. movb %al, (%edi)
  400. /*
  401. * set control register to NORMAL mode
  402. */
  403. movl $DRCCTL, %esi /* setup DRAM control register with */
  404. movb $0x00, %al /* Normal mode value */
  405. movb %al, (%esi)
  406. movl $CACHELINESZ, %esi /* address to init read buffer */
  407. movw %ax, (%esi)
  408. jmp nextbank
  409. cleanup:
  410. movl $DRCBENDADR, %edi /* DRAM ending address register */
  411. movw $0x04, %cx
  412. xorw %ax, %ax
  413. cleanuplp:
  414. movb (%edi), %al
  415. orb %al, %al
  416. jz emptybank
  417. addb %ah, %al
  418. jns nottoomuch
  419. movb $0x7f, %al
  420. nottoomuch:
  421. movb %al, %ah
  422. orb $0x80, %al
  423. movb %al, (%edi)
  424. emptybank:
  425. incl %edi
  426. loop cleanuplp
  427. #if defined CONFIG_SYS_SDRAM_DRCTMCTL
  428. /* just have your hardware desinger _GIVE_ you what you need here! */
  429. movl $DRCTMCTL, %edi
  430. movb $CONFIG_SYS_SDRAM_DRCTMCTL, %al
  431. movb %al, (%edi)
  432. #else
  433. #if defined(CONFIG_SYS_SDRAM_CAS_LATENCY_2T) || defined(CONFIG_SYS_SDRAM_CAS_LATENCY_3T)
  434. /*
  435. * Set the CAS latency now since it is hard to do
  436. * when we run from the RAM
  437. */
  438. movl $DRCTMCTL, %edi /* DRAM timing register */
  439. movb (%edi), %al
  440. #ifdef CONFIG_SYS_SDRAM_CAS_LATENCY_2T
  441. andb $0xef, %al
  442. #endif
  443. #ifdef CONFIG_SYS_SDRAM_CAS_LATENCY_3T
  444. orb $0x10, %al
  445. #endif
  446. movb %al, (%edi)
  447. #endif
  448. #endif
  449. movl $DRCCTL, %edi /* DRAM Control register */
  450. movb $0x03, %al /* Load mode register cmd */
  451. movb %al, (%edi)
  452. movw %ax, (%esi)
  453. movl $DRCCTL, %edi /* DRAM Control register */
  454. movb $0x18, %al /* Enable refresh and NORMAL mode */
  455. movb %al, (%edi)
  456. jmp dram_done
  457. bad_ram:
  458. xorl %edx, %edx
  459. xorl %edi, %edi
  460. jmp bad_reint
  461. dram_done:
  462. #if CONFIG_SYS_SDRAM_ECC_ENABLE
  463. /*
  464. * We are in the middle of an existing 'call' - Need to store the
  465. * existing return address before making another 'call'
  466. */
  467. movl %ebp, %ebx
  468. /* Get the memory size */
  469. movl $init_ecc, %ebp
  470. jmpl get_mem_size
  471. init_ecc:
  472. /* Restore the orignal return address */
  473. movl %ebx, %ebp
  474. /* A nominal memory test: just a byte at each address line */
  475. movl %eax, %ecx
  476. shrl $0x1, %ecx
  477. movl $0x1, %edi
  478. memtest0:
  479. movb $0xa5, (%edi)
  480. cmpb $0xa5, (%edi)
  481. jne out
  482. shrl $0x1, %ecx
  483. andl %ecx, %ecx
  484. jz set_ecc
  485. shll $0x1, %edi
  486. jmp memtest0
  487. set_ecc:
  488. /* clear all ram with a memset */
  489. movl %eax, %ecx
  490. xorl %esi, %esi
  491. xorl %edi, %edi
  492. xorl %eax, %eax
  493. shrl $0x2, %ecx
  494. cld
  495. rep stosl
  496. /* enable read, write buffers */
  497. movb $0x11, %al
  498. movl $DBCTL, %edi
  499. movb %al, (%edi)
  500. /* enable NMI mapping for ECC */
  501. movl $ECCINT, %edi
  502. movb $0x10, %al
  503. movb %al, (%edi)
  504. /* Turn on ECC */
  505. movl $ECCCTL, %edi
  506. movb $0x05, %al
  507. movb %al,(%edi)
  508. #endif
  509. out:
  510. jmp *%ebp
  511. /*
  512. * Read and decode the sc520 DRCBENDADR MMCR and return the number of
  513. * available ram bytes in %eax
  514. */
  515. .globl get_mem_size
  516. get_mem_size:
  517. movl $DRCBENDADR, %edi /* DRAM ending address register */
  518. bank0: movl (%edi), %eax
  519. movl %eax, %ecx
  520. andl $0x00000080, %ecx
  521. jz bank1
  522. andl $0x0000007f, %eax
  523. shll $22, %eax
  524. movl %eax, %ebx
  525. bank1: movl (%edi), %eax
  526. movl %eax, %ecx
  527. andl $0x00008000, %ecx
  528. jz bank2
  529. andl $0x00007f00, %eax
  530. shll $14, %eax
  531. movl %eax, %ebx
  532. bank2: movl (%edi), %eax
  533. movl %eax, %ecx
  534. andl $0x00800000, %ecx
  535. jz bank3
  536. andl $0x007f0000, %eax
  537. shll $6, %eax
  538. movl %eax, %ebx
  539. bank3: movl (%edi), %eax
  540. movl %eax, %ecx
  541. andl $0x80000000, %ecx
  542. jz done
  543. andl $0x7f000000, %eax
  544. shrl $2, %eax
  545. movl %eax, %ebx
  546. done:
  547. movl %ebx, %eax
  548. jmp *%ebp