rockbox/utils/hwstub/tools/lua/jz/misc.lua
Amaury Pouly 8e07d68452 hwstub: add various jz stuff and xburst tests
The JZ misc allows to enable and test SRAM.
The XBurst code uses the coprocessor interface to analyse the cpu. It also
provides a test platform for various features like EBASE and exceptions.
I was able to test and confirm that on jz4760b (thus xburst), EBASE works
(but top 2 bits are not controllable and always 01). The processor claims
to support vector interrupts but this is untested. The values in ConfigX
are not to be trusted blindly, clearly some are wrong. I tried to use the
JZ4780 Config7 "ebase gate" to change bit 30 of EBASE but it does not work,
which suggests that JZ480 uses a newer version of XBurst. Detailled log below:

> ./hwstub_shell -q -f lua/xburst.lua -e "XBURST.init()"
[...]
XBurst:
  PRId: 0x2ed0024f
    CPU: JZ4760(B)
  Config: 0x80000483
    Architecture Type: MIPS32
    Architecture Level: Release 2 (or more)
    MMU Type: Standard TLB
  Config1: 0x3e63318a
    MMU Size: 32
    ICache
      Sets per way: 128
      Ways: 4
      Line size: 32
    DCache
      Sets per way: 128
      Ways: 4
      Line size: 32
    FPU: no
  Config2: 0x80000000
  Config3: 0x20
    Vectored interrupt: yes
  Config7: 0x0

> ./hwstub_shell -q -e 'require("jz/misc"); JZ.misc.enable_sram()' \
  -f lua/xburst.lua -e "XBURST.test_ebase(0x80000000);XBURST.test_ebase(0xb32d0000)
[...]
Testing EBASE...
  Disable BEV
  SR value: 0x2000fc00
  EBASE value: 0x80000000
    Value after writing 0x80000000: 0x80000000
    Value after writing 0x80040000: 0x80040000
  Test result: EBase seems to work
    Disable config7 gate: write 0x0 to Config7
    Value after writing 0xfffff000: 0xbffff000
    Enable config7 gate: write 0x80 to Config7
    Value after writing 0xc0000000: 0x80000000
  Config7 result: Config7 gate does not work
Exception test with EBASE at 0x80000000...
  Writing instructions to memory
  Old SR: 0x2000fc00
  New SR: 0xfc00
  EBASE: 80000000
  Before: cafebabe
  After: deadbeef
  Exception result: Exception and EBASE are working
Testing EBASE...
  Disable BEV
  SR value: 0x2000fc00
  EBASE value: 0x80000000
    Value after writing 0x80000000: 0x80000000
    Value after writing 0x80040000: 0x80040000
  Test result: EBase seems to work
    Disable config7 gate: write 0x0 to Config7
    Value after writing 0xfffff000: 0xbffff000
    Enable config7 gate: write 0x80 to Config7
    Value after writing 0xc0000000: 0x80000000
  Config7 result: Config7 gate does not work
Exception test with EBASE at 0xb32d0000...
  Writing instructions to memory
  Old SR: 0x2000fc00
  New SR: 0xfc00
  EBASE: b32d0000
  Before: cafebabe
  After: deadbeef
  Exception result: Exception and EBASE are working

Change-Id: I894227981a141a8c14419b36ed9f519baf145ad1
2017-01-24 15:25:14 +01:00

43 lines
1.2 KiB
Lua

----------
-- MISC --
----------
JZ.misc = {}
function JZ.misc.enable_sram()
HW.CPM.CLKGATE1.SRAM.clr()
HW.CPM.CLKGATE1.AHB1.clr()
end
function JZ.misc.test_sram()
DEV.write32(0xb32d0000, 0xaaaa5555)
if DEV.read32(0xb32d0000) ~= 0xaaaa5555 then
error("SRAM is not working")
end
DEV.write32(0xb32d0000, 0xdeadbeef)
if DEV.read32(0xb32d0000) ~= 0xdeadbeef then
error("SRAM is not working")
end
print("SRAM seems to be working")
size = 0
for i=4,64*1024,4 do
DEV.write32(0xb32d0000, 0xdeadbeef)
DEV.write32(0xb32d0000 + i, 0xcafebabe)
if DEV.read32(0xb32d0000 + i) ~= 0xcafebabe or DEV.read32(0xb32d0000) == 0xcafebabe then
size = i
break
end
end
print(string.format("SRAM size: 0x%x (%d KiB)", size, size / 1024))
-- double check
for i=0,size-1,2 do
DEV.write16(0xb32d0000 + i, i)
end
for i=0,size-1,2 do
if DEV.read16(0xb32d0000 + i) ~= i then
error(string.format("SRAM size is not confirmed: read @%x gives %d instead of %d",
0xb32d0000 + i, DEV.read16(0xb32d0000 + i), i))
end
end
print("SRAM size confirmed and working")
end