hooking up the goodfet.xscale code. it is minimal for now. it should be able to...
[goodfet] / client / GoodFETARM9.py
1 #!/usr/bin/env python
2 # GoodFET ARM9 Client Library
3
4 # Contributions and bug reports welcome.
5 #
6 # todo:
7 #  * full cycle debugging.. halt to resume
8 #  * ensure correct PC handling
9 #  * flash manipulation (probably need to get the specific chip for this one)
10 #  * set security (chip-specific)
11
12 import sys, binascii, struct, time
13 import atlasutils.smartprint as asp
14 from GoodFET import GoodFET
15 import GoodFETARM7
16 from intelhex import IntelHex
17
18
19 #Global Commands
20 READ  = 0x00
21 WRITE = 0x01
22 PEEK  = 0x02
23 POKE  = 0x03
24 SETUP = 0x10
25 START = 0x20
26 STOP  = 0x21
27 CALL  = 0x30
28 EXEC  = 0x31
29 NOK   = 0x7E
30 OK    = 0x7F
31
32 # ARM JTAG commands
33 IR_SHIFT =                  0x80
34 DR_SHIFT =                  0x81
35 RESETTAP =                  0x82
36 RESETTARGET =               0x83
37 GET_REGISTER =              0x87
38 SET_REGISTER =              0x88
39 DEBUG_INSTR =               0x89
40 # Really ARM specific stuff
41 WAIT_DBG =                  0x91
42 CHAIN0 =                    0x93
43 SCANCHAIN1 =                0x94
44 EICE_READ =                 0x95
45 EICE_WRITE =                0x96
46
47
48 class GoodFETARM9(GoodFETARM7.GoodFETARM7):
49     def ARM9readMem(self, adr, wordcount):
50         """ Only works in ARM mode currently
51         WARNING: Addresses must be word-aligned!
52         """
53         regs = self.ARMget_registers()
54         self.ARMset_registers([0xdeadbeef for x in xrange(14)], 0xe)
55         output = []
56         count = wordcount
57         while (wordcount > 0):
58             count = (wordcount, 0xe)[wordcount>0xd]
59             bitmask = LDM_BITMASKS[count]
60             self.ARMset_register(14,adr)
61             self.ARMdebuginstr(ARM_INSTR_LDMIA_R14_r0_rx | bitmask ,0)
62             self.ARM_nop(1)
63             #FIXME: do we need the extra nop here?
64             self.ARMrestart()
65             self.ARMwaitDBG()
66             output.extend([self.ARMget_register(x) for x in xrange(count)])
67             wordcount -= count
68             adr += count*4
69             #print hex(adr)
70         # FIXME: handle the rest of the wordcount here.
71         self.ARMset_registers(regs,0xe)
72         return output