/* * Compute size of DRAM based on contents of the Madam System Control Register. * * | x8 == 0 | x8 == 0 | x8 == 1 * MSYS | MSYS DRAM | MSYS DRAM | MSYS * 2:0 VRAM | 6:5 SET0 | 4:3 SET1 | 6:3 DRAM * --- ---- | ---- ---- | ---- ---- | ---- ---- * | 00 0 MB | 00 0 MB | * 001 1 MB | 01 1 MB | 01 1 MB | 0101 2 MB * 010 2 MB | 10 4 MB | 10 4 MB | 1010 8 MB * * Combinations not shown in the above tables are not supported and * this routine is not guaranteed to return anything sensible (even * though it usually will do something vaguely rational). */ void FindMemSize(uint32 *pDramSize, uint32 *pVramSize) { uint32 bits = *MSYSBits; uint32 dram_size; uint32 vram_size; /* * This may look complex, but it only takes about eight ARM * instructions to evaluate. Basicly, take each DRAM set size * field, and double it to get the left-shift count. Then * shift "a quarter megabyte" left by the count, casting off * anything less than a megabyte; this is easiest to do if you * shift "1" left by the count, then right by two. We turn it * into megabytes later. */ dram_size = (((1<<((bits>> (DRAMSIZE_SET0SHIFT-1))&(DRAMSIZE_SETMASK<<1)))>>2) + ((1<<((bits>> (DRAMSIZE_SET1SHIFT-1))&(DRAMSIZE_SETMASK<<1)))>>2)); vram_size = ((bits & VRAMSIZE_MASK)>> VRAMSIZE_SHIFT); /* Convert to megabytes */ *pDramSize = dram_size * 1024*1024; *pVramSize = vram_size * 1024*1024; }