-
Notifications
You must be signed in to change notification settings - Fork 0
/
page_table_decode.py
67 lines (58 loc) · 1.76 KB
/
page_table_decode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
def decode_entry(e: bytes, va: int, continuos: bool) -> bool:
old_continuos = continuos
continuos = False
# check 0:1 bits
e_type = e[0] & 0x3
if e_type == 0:
print("0x%08x: Fault" % (va))
elif e_type == 1:
# table_baddr 31:10
table_baddr = e[3] << 24 | ((e[2] & 0xff) << 16) | ((e[1] & 0xFC) << 8)
# P 9
p = (e[1] >> 1) & 0x1
# domain 8:5
domain = e[0] >> 5
# SBZ 4:2
sbz = (e[0] >> 2) & 0x7
print("0x%08x: Coarse page table in %08x. P: 0x%x. Domain: 0x%x. SBZ: 0x%x" % (va, table_baddr, p, domain, sbz))
elif e_type == 2:
# baddr 31:20
baddr = e[3] << 24 | ((e[2] & 0xf0) << 16)
# tex 14:12
tex = e[1] >> 4
# ap 11:10
ap = (e[1] >> 2) & 0x3
# domain 8:5
domain = e[0] >> 5
#CB 3:2
cb = (e[0] >> 2) & 0x3
#S 16
s = e[2] & 0x1
# nG 17
ng = (e[2] >> 1) & 0x1
# xN 4
xn = (e[0] >> 4) & 0x1
if ap > 0:
continuos = True
if continuos != old_continuos:
print("")
print("0x%08x: Section to 0x%08x. TEX: 0x%x AP: 0x%x Domain: 0x%x CB: 0x%x S: %d nG: %d xN: %d" % (va, baddr, tex, ap, domain, cb, s, ng, xn))
#print(e)
elif e_type == 3:
print("0x%08x: undef" % (va))
return continuos
#FILE = 'out/ram.bin'
FILE = 'roms/rom1.bin'
#POS = 0x5400000
#POS = 0x1918
POS = 0x10b000
with open(FILE, 'rb') as f:
continuos = True
f.seek(POS)
for i in range(int(16 * (1024)/4)): # 1KB
# read 4 bytes little endian
data = f.read(4)
# convert to big endian
#data = data[::-1]
continuos = decode_entry(data, i << 20, continuos)