1include("/sys/lib/acid/arm"); 2 3// feroceon memory definitions 4TmrWDenable=1<<4; 5PHYSIO=0xf1000000; 6TIMERREG=0xf1020300; 7PsrMsvc=0x00000013; 8timerctl=0; 9KZERO=0x60000000; 10 11ureg = 0; 12complex Ureg ureg; 13uregtypeaddr=60; //kludge 14 15//generated from 8c -a 16sizeofMMURegs = 32; 17aggr MMURegs 18{ 19 'U' 0 cpid; 20 'U' 4 control; 21 'U' 8 ttb; 22 'U' 12 dac; 23 'U' 16 fsr; 24 'U' 20 far; 25 'U' 24 ct; 26 'U' 28 pid; 27}; 28 29defn 30remapdata() 31{ 32 mps = map(); 33 34 while mps do { 35 m = head mps; 36 name = head m; 37 if name == "*data" then { 38 dend = head tail tail m; 39 map({"*data", KZERO, dend, KZERO}); 40 } 41 mps = tail mps; 42 } 43} 44//I want to be able to access MACH and other stuff 45remapdata(); 46memmap=map(); 47//TO DO is there any arm with fpregs? 48map({"regs", 0, sizeofUreg+sizeofMMURegs, 0}); 49 50defn 51MMURegs(addr) { 52 complex MMURegs addr; 53 print(" cpid ", addr.cpid\X, "\n"); 54 print(" control ", addr.control\X, "\n"); 55 print(" ttb ", addr.ttb\X, "\n"); 56 print(" dac ", addr.dac\X, "\n"); 57 print(" fsr ", addr.fsr\X, "\n"); 58 print(" far ", addr.far\X, "\n"); 59 print(" ct ", addr.ct\X, "\n"); 60 print(" pid ", addr.pid\X, "\n"); 61}; 62 63complex MMURegs mmuregs; 64mmuregs=sizeofUreg; // plus size of floating point registers 65 66defn 67mmuregs() 68{ 69 MMURegs(mmuregs); 70} 71 72defn 73stopwdog() 74{ 75 // change to svc mode to be able to access the address 76 stype = ureg.type; 77 *uregtypeaddr=PsrMsvc; 78 timerctl=*TIMERREG; 79 *TIMERREG = ~TmrWDenable&*TIMERREG; 80 *uregtypeaddr=stype; 81} 82 83defn 84startwdog() 85{ 86 stype = ureg.type; 87 *uregtypeaddr=PsrMsvc; 88 *TIMERREG = TmrWDenable|timerctl; 89 *uregtypeaddr=stype; 90} 91 92defn 93hwbpset(addr, mask) 94{ 95 printto("/proc/"+itoa(pid)+"/ctl", "breakpoint ", itoa(addr), " ", itoa(mask)); 96} 97 98defn 99veccatch(vecstr) 100{ 101 printto("/proc/"+itoa(pid)+"/ctl", "veccatch ", vecstr); 102} 103 104defn 105reset() 106{ 107 printto("/proc/"+itoa(pid)+"/ctl", "reset "); 108} 109 110defn 111debug(dbstr) 112{ 113 printto("/proc/"+itoa(pid)+"/ctl", "debug ", dbstr); 114} 115 116defn 117cpuid() 118{ 119 printto("/proc/"+itoa(pid)+"/ctl", "cpuid"); 120} 121 122defn 123jtaginfo() 124{ 125 rc("cat /proc/"+itoa(pid)+"/ctl"); 126} 127 128defn 129sheevastop() 130{ 131 stop(pid); 132 stopwdog(); 133} 134 135defn 136sheevastart() 137{ 138 startwdog(); 139 start(pid); 140} 141 142defn 143sheevawaitstop() 144{ 145 waitstop(pid); 146 stopwdog(); 147} 148 149// FROM here down on, UNTRIED BUG BUG BUG!!!!! 150 151//CpCONTROL, h2acid 152CpCmmu = 0x00000001; 153CpCalign = 0x00000002; 154CpCdcache = 0x00000004; 155CpCwb = 0x00000008; 156CpCi32 = 0x00000010; 157CpCd32 = 0x00000020; 158CpCbe = 0x00000080; 159CpCsystem = 0x00000100; 160CpCrom = 0x00000200; 161CpCicache = 0x00001000; 162CpChv = 0x00002000; 163 164//MMU definitions, h2acid 165KB=1024; 166MB=1024*1024; 167Mbo = 0x10; 168Coarse = (Mbo|1); 169Section = (Mbo|2); 170Fine = (Mbo|3); 171 172defn 173ismmuon() 174{ 175 mmu = mmuregs; 176 complex MMURegs mmu; 177 return mmu.control&CpCmmu; 178} 179 180defn 181l1x(vaddr) 182{ 183 return ((vaddr>>20) & 0x0fff)<<2; 184} 185 186defn 187l2x(vaddr) 188{ 189 return ((vaddr>>12) & 0xff)<<2; 190} 191 192defn 193pgsz(type) 194{ 195 if type == Fine then { 196 return KB; 197 } else if type == Section then { 198 return MB; 199 } else if type == Coarse then { 200 return 4*KB; 201 } 202 return 4*KB; 203} 204 205defn 206kaddr(vaddr) 207{ 208 return KZERO|vaddr; //very non portable 209} 210 211defn 212ttbpaddr(ttb, vaddr) 213{ 214 if ! ismmuon() then { 215 print("paddr: mmu is off\n"); 216 return 0; 217 } 218 l1idx = l1x(vaddr); 219 l2idx = l2x(vaddr); 220 pte1 = *((kaddr(ttb)&~0x1fff) + l1idx); 221 if pte1 == 0 then { 222 return 0; 223 } 224 type = pte1 & (Fine|Section|Coarse); 225 sz = pgsz(type); 226 if type == Section then { 227 return (pte1 & ~(sz - 1)) + (vaddr & (sz - 1)); 228 } 229 230 l2addr = pte1 & ~(sz - 1); 231 if l2addr == 0 then { 232 return 0; 233 } 234 pte2 = *(kaddr(l2addr) + l2idx); 235 return (pte2 & ~(sz - 1)) + (vaddr & (sz - 1)); 236} 237 238defn 239paddr(vaddr) 240{ 241 mmu = mmuregs; 242 complex MMURegs mmu; 243 return ttbpaddr(mmu.ttb, vaddr); 244} 245 246