1 # SPDX-License-Identifier: LGPLv3+
2 # Copyright (C) 2020, 2021 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
3 # Copyright (C) 2021 Tobias Platen
4 # Funded by NLnet http://nlnet.nl
5 """core of the python-based POWER9 simulator
7 this is part of a cycle-accurate POWER9 simulator. its primary purpose is
8 not speed, it is for both learning and educational purposes, as well as
9 a method of verifying the HDL.
13 * https://bugs.libre-soc.org/show_bug.cgi?id=604
16 #from nmigen.back.pysim import Settle
18 from openpower
.decoder
.selectable_int
import (FieldSelectableInt
, SelectableInt
,
20 from openpower
.decoder
.helpers
import exts
, gtu
, ltu
, undefined
21 from openpower
.decoder
.isa
.mem
import Mem
, MemException
22 from openpower
.consts
import MSRb
# big-endian (PowerISA versions)
28 # very quick, TODO move to SelectableInt utils later
29 def genmask(shift
, size
):
30 res
= SelectableInt(0, size
)
33 res
[size
-1-i
] = SelectableInt(1, 1)
36 # NOTE: POWER 3.0B annotation order! see p4 1.3.2
37 # MSB is indexed **LOWEST** (sigh)
38 # from gem5 radixwalk.hh
39 # Bitfield<63> valid; 64 - (63 + 1) = 0
40 # Bitfield<62> leaf; 64 - (62 + 1) = 1
48 ## Shift address bits 61--12 right by 0--47 bits and
49 ## supply the least significant 16 bits of the result.
50 def addrshift(addr
,shift
):
54 x
= addr
.value
>> shift
.value
55 return SelectableInt(x
, 16)
64 zero
= SelectableInt(0, 1)
65 return selectconcat(zero
, RTS2(data
), RTS1(data
))
72 return x
[4:56] # python numbering end+1
76 Next Level Size (PATS and RPDS in same bits btw)
79 return x
[59:64] # python numbering end+1
83 Root Page Directory Base
84 power isa docs says 4:55 investigate
86 return x
[8:56] # python numbering end+1
91 //Accessing 2nd double word of partition table (pate1)
92 //Ref: Power ISA Manual v3.0B, Book-III, section 5.7.6.1
94 // ====================================================
95 // -----------------------------------------------
96 // | /// | PATB | /// | PATS |
97 // -----------------------------------------------
99 // PATB[4:51] holds the base address of the Partition Table,
100 // right shifted by 12 bits.
101 // This is because the address of the Partition base is
102 // 4k aligned. Hence, the lower 12bits, which are always
103 // 0 are ommitted from the PTCR.
105 // Thus, The Partition Table Base is obtained by (PATB << 12)
107 // PATS represents the partition table size right-shifted by 12 bits.
108 // The minimal size of the partition table is 4k.
109 // Thus partition table size = (1 << PATS + 12).
112 // ====================================================
113 // 0 PATE0 63 PATE1 127
114 // |----------------------|----------------------|
116 // |----------------------|----------------------|
118 // |----------------------|----------------------|
120 // |----------------------|----------------------|
124 // |----------------------|----------------------|
126 // |----------------------|----------------------|
128 // The effective LPID forms the index into the Partition Table.
130 // Each entry in the partition table contains 2 double words, PATE0, PATE1,
131 // corresponding to that partition.
133 // In case of Radix, The structure of PATE0 and PATE1 is as follows.
136 // -----------------------------------------------
137 // |1|RTS1|/| RPDB | RTS2 | RPDS |
138 // -----------------------------------------------
139 // 0 1 2 3 4 55 56 58 59 63
141 // HR[0] : For Radix Page table, first bit should be 1.
142 // RTS1[1:2] : Gives one fragment of the Radix treesize
143 // RTS2[56:58] : Gives the second fragment of the Radix Tree size.
144 // RTS = (RTS1 << 3 + RTS2) + 31.
146 // RPDB[4:55] = Root Page Directory Base.
147 // RPDS = Logarithm of Root Page Directory Size right shifted by 3.
148 // Thus, Root page directory size = 1 << (RPDS + 3).
152 // -----------------------------------------------
153 // |///| PRTB | // | PRTS |
154 // -----------------------------------------------
155 // 0 3 4 51 52 58 59 63
157 // PRTB[4:51] = Process Table Base. This is aligned to size.
158 // PRTS[59: 63] = Process Table Size right shifted by 12.
159 // Minimal size of the process table is 4k.
160 // Process Table Size = (1 << PRTS + 12).
163 // Computing the size aligned Process Table Base:
164 // table_base = (PRTB & ~((1 << PRTS) - 1)) << 12
165 // Thus, the lower 12+PRTS bits of table_base will
169 //Ref: Power ISA Manual v3.0B, Book-III, section 5.7.6.2
172 // ==========================
173 // 0 PRTE0 63 PRTE1 127
174 // |----------------------|----------------------|
176 // |----------------------|----------------------|
178 // |----------------------|----------------------|
180 // |----------------------|----------------------|
184 // |----------------------|----------------------|
186 // |----------------------|----------------------|
188 // The effective Process id (PID) forms the index into the Process Table.
190 // Each entry in the partition table contains 2 double words, PRTE0, PRTE1,
191 // corresponding to that process
193 // In case of Radix, The structure of PRTE0 and PRTE1 is as follows.
196 // -----------------------------------------------
197 // |/|RTS1|/| RPDB | RTS2 | RPDS |
198 // -----------------------------------------------
199 // 0 1 2 3 4 55 56 58 59 63
201 // RTS1[1:2] : Gives one fragment of the Radix treesize
202 // RTS2[56:58] : Gives the second fragment of the Radix Tree size.
203 // RTS = (RTS1 << 3 + RTS2) << 31,
204 // since minimal Radix Tree size is 4G.
206 // RPDB = Root Page Directory Base.
207 // RPDS = Root Page Directory Size right shifted by 3.
208 // Thus, Root page directory size = RPDS << 3.
212 // -----------------------------------------------
214 // -----------------------------------------------
216 // All bits are reserved.
223 0x10000: # PARTITION_TABLE_2 (not implemented yet)
224 # PATB_GR=1 PRTB=0x1000 PRTS=0xb
227 0x30000: # RADIX_ROOT_PTE
228 # V = 1 L = 0 NLB = 0x400 NLS = 9
230 0x40000: # RADIX_SECOND_LEVEL
231 # V = 1 L = 1 SW = 0 RPN = 0
232 # R = 1 C = 1 ATT = 0 EAA 0x7
235 0x1000000: # PROCESS_TABLE_3
236 # RTS1 = 0x2 RPDB = 0x300 RTS2 = 0x5 RPDS = 13
240 # this one has a 2nd level RADIX with a RPN of 0x5000
243 0x10000: # PARTITION_TABLE_2 (not implemented yet)
244 # PATB_GR=1 PRTB=0x1000 PRTS=0xb
247 0x30000: # RADIX_ROOT_PTE
248 # V = 1 L = 0 NLB = 0x400 NLS = 9
250 0x40000: # RADIX_SECOND_LEVEL
251 # V = 1 L = 1 SW = 0 RPN = 0x5000
252 # R = 1 C = 1 ATT = 0 EAA 0x7
255 0x1000000: # PROCESS_TABLE_3
256 # RTS1 = 0x2 RPDB = 0x300 RTS2 = 0x5 RPDS = 13
262 DCACHE GET 1000000 PROCESS_TABLE_3
263 DCACHE GET 30000 RADIX_ROOT_PTE V = 1 L = 0
264 DCACHE GET 40000 RADIX_SECOND_LEVEL V = 1 L = 1
265 DCACHE GET 10000 PARTITION_TABLE_2
266 translated done 1 err 0 badtree 0 addr 40000 pte 0
269 # see qemu/target/ppc/mmu-radix64.c for reference
271 def __init__(self
, mem
, caller
):
274 if caller
is not None:
277 self
.dsisr
= self
.caller
.spr
["DSISR"]
278 self
.dar
= self
.caller
.spr
["DAR"]
279 self
.pidr
= self
.caller
.spr
["PIDR"]
280 self
.prtbl
= self
.caller
.spr
["PRTBL"]
281 self
.msr
= self
.caller
.msr
283 # cached page table stuff
285 self
.pt0_valid
= False
287 self
.pt3_valid
= False
289 def __call__(self
, addr
, sz
):
290 val
= self
.ld(addr
.value
, sz
, swap
=False)
291 print("RADIX memread", addr
, sz
, val
)
292 return SelectableInt(val
, sz
*8)
294 def ld(self
, address
, width
=8, swap
=True, check_in_mem
=False,
296 print("RADIX: ld from addr 0x%x width %d" % (address
, width
))
298 priv
= ~
(self
.msr
[MSRb
.PR
].value
) # problem-state ==> privileged
303 addr
= SelectableInt(address
, 64)
304 pte
= self
._walk
_tree
(addr
, mode
, priv
)
307 print("error on load",pte
)
310 # use pte to load from phys address
311 data
= self
.mem
.ld(pte
.value
, width
, swap
, check_in_mem
)
312 self
.last_ld_addr
= self
.mem
.last_ld_addr
314 # XXX set SPRs on error
318 def st(self
, address
, v
, width
=8, swap
=True):
319 print("RADIX: st to addr 0x%x width %d data %x" % (address
, width
, v
))
321 priv
= ~
(self
.msr
[MSRb
.PR
].value
) # problem-state ==> privileged
323 addr
= SelectableInt(address
, 64)
324 pte
= self
._walk
_tree
(addr
, mode
, priv
)
326 # use pte to store at phys address
327 res
= self
.mem
.st(pte
.value
, v
, width
, swap
)
328 self
.last_st_addr
= self
.mem
.last_st_addr
330 # XXX set SPRs on error
333 def memassign(self
, addr
, sz
, val
):
334 print("memassign", addr
, sz
, val
)
335 self
.st(addr
.value
, val
.value
, sz
, swap
=False)
337 def _next_level(self
, addr
, check_in_mem
):
338 # implement read access to mmu mem here
340 # DO NOT perform byte-swapping: load 8 bytes (that's the entry size)
341 value
= self
.mem
.ld(addr
.value
, 8, False, check_in_mem
)
343 return "address lookup %x not found" % addr
.value
344 # assert(value is not None, "address lookup %x not found" % addr.value)
346 data
= SelectableInt(value
, 64) # convert to SelectableInt
347 print("addr", hex(addr
.value
))
348 print("value", hex(value
))
351 def _walk_tree(self
, addr
, mode
, priv
=1):
355 // vaddr |-----------------------------------------------------|
357 // |-----------|-----------------------------------------|
358 // | 0000000 | usefulBits = X bits (typically 52) |
359 // |-----------|-----------------------------------------|
360 // | |<--Cursize---->| |
364 // |-----------------------------------------------------|
367 // PDE |---------------------------| |
368 // |V|L|//| NLB |///|NLS| |
369 // |---------------------------| |
370 // PDE = Page Directory Entry |
371 // [0] = V = Valid Bit |
372 // [1] = L = Leaf bit. If 0, then |
373 // [4:55] = NLB = Next Level Base |
374 // right shifted by 8 |
375 // [59:63] = NLS = Next Level Size |
378 // | |--------------------------|
379 // | | usfulBits = X-Cursize |
380 // | |--------------------------|
381 // |---------------------><--NLS-->| |
385 // |--------------------------|
387 // If the next PDE obtained by |
388 // (NLB << 8 + 8 * index) is a |
389 // nonleaf, then repeat the above. |
391 // If the next PDE is a leaf, |
392 // then Leaf PDE structure is as |
397 // |------------------------------| |----------------|
398 // |V|L|sw|//|RPN|sw|R|C|/|ATT|EAA| | usefulBits |
399 // |------------------------------| |----------------|
400 // [0] = V = Valid Bit |
401 // [1] = L = Leaf Bit = 1 if leaf |
403 // [2] = Sw = Sw bit 0. |
404 // [7:51] = RPN = Real Page Number, V
405 // real_page = RPN << 12 -------------> Logical OR
406 // [52:54] = Sw Bits 1:3 |
407 // [55] = R = Reference |
408 // [56] = C = Change V
409 // [58:59] = Att = Physical Address
410 // 0b00 = Normal Memory
412 // 0b10 = Non Idenmpotent
413 // 0b11 = Tolerant I/O
414 // [60:63] = Encoded Access
420 pidr
= self
.caller
.spr
["PIDR"]
421 prtbl
= self
.caller
.spr
["PRTBL"]
423 print("PRTBL", prtbl
)
425 print("last 8 bits ----------")
428 # get address of root entry
429 # need to fetch process table entry
430 # v.shift := unsigned('0' & r.prtbl(4 downto 0));
431 shift
= selectconcat(SelectableInt(0, 1), NLS(prtbl
))
432 addr_next
= self
._get
_prtable
_addr
(shift
, prtbl
, addr
, pidr
)
433 print("starting with prtable, addr_next", addr_next
)
435 assert(addr_next
.bits
== 64)
436 #only for first unit tests assert(addr_next.value == 0x1000000)
438 # read an entry from prtable, decode PTRE
439 data
= self
._next
_level
(addr_next
, check_in_mem
=False)
440 print("pr_table", data
)
441 pgtbl
= data
# this is cached in microwatt (as v.pgtbl3 / v.pgtbl0)
442 (rts
, mbits
, pgbase
) = self
._decode
_prte
(pgtbl
)
443 print("pgbase", pgbase
)
447 raise MemException("invalid")
449 # mask_size := mbits(4 downto 0);
450 mask_size
= mbits
[0:5]
451 assert(mask_size
.bits
== 5)
452 print("before segment check ==========")
453 print("mask_size:", bin(mask_size
.value
))
454 print("mbits:", bin(mbits
.value
))
456 print("calling segment_check")
458 shift
= self
._segment
_check
(addr
, mask_size
, shift
)
459 print("shift", shift
)
461 if isinstance(addr
, str):
463 if isinstance(shift
, str):
472 addrsh
= addrshift(addr
, shift
)
473 print("addrsh",addrsh
)
475 print("calling _get_pgtable_addr")
476 print(mask
) #SelectableInt(value=0x9, bits=4)
477 print(pgbase
) #SelectableInt(value=0x40000, bits=56)
478 print(shift
) #SelectableInt(value=0x4, bits=16) #FIXME
479 addr_next
= self
._get
_pgtable
_addr
(mask
, pgbase
, addrsh
)
480 print("DONE addr_next", addr_next
)
482 print("nextlevel----------------------------")
484 data
= self
._next
_level
(addr_next
, check_in_mem
=False)
485 valid
= rpte_valid(data
)
486 leaf
= rpte_leaf(data
)
488 print(" valid, leaf", valid
, leaf
)
490 raise MemException("invalid")
492 print ("is leaf, checking perms")
493 ok
= self
._check
_perms
(data
, priv
, mode
)
494 if ok
== True: # data was ok, found phys address, return it?
495 paddr
= self
._get
_pte
(addrsh
, addr
, data
)
496 print (" phys addr", hex(paddr
.value
))
498 return ok
# return the error code
500 newlookup
= self
._new
_lookup
(data
, shift
, old_shift
)
501 if isinstance(newlookup
, str):
503 old_shift
= shift
# store old_shift before updating shift
504 shift
, mask
, pgbase
= newlookup
505 print (" next level", shift
, mask
, pgbase
)
507 def _get_pgbase(self
, data
):
509 v.pgbase := data(55 downto 8) & x"00"; NLB?
511 zero8
= SelectableInt(0, 8)
512 ret
= selectconcat(data
[8:56], zero8
)
516 def _new_lookup(self
, data
, shift
, old_shift
):
518 mbits := unsigned('0' & data(4 downto 0));
519 if mbits < 5 or mbits > 16 or mbits > r.shift then
520 v.state := RADIX_FINISH;
521 v.badtree := '1'; -- throw error
523 v.shift := v.shift - mbits;
524 v.mask_size := mbits(4 downto 0);
525 v.pgbase := data(55 downto 8) & x"00"; NLB?
526 v.state := RADIX_LOOKUP; --> next level
529 mbits
= selectconcat(SelectableInt(0, 1), NLS(data
))
530 print("mbits=", mbits
)
531 if mbits
< 5 or mbits
> 16 or mbits
> old_shift
:
534 # reduce shift (has to be done at same bitwidth)
535 shift
= shift
- mbits
536 assert mbits
.bits
== 6
537 mask_size
= mbits
[2:6] # get 4 LSBs from 6-bit (using MSB0 numbering)
538 pgbase
= self
._get
_pgbase
(data
)
539 return shift
, mask_size
, pgbase
541 def _decode_prte(self
, data
):
543 -----------------------------------------------
544 |/|RTS1|/| RPDB | RTS2 | RPDS |
545 -----------------------------------------------
546 0 1 2 3 4 55 56 58 59 63
548 # note that SelectableInt does big-endian! so the indices
549 # below *directly* match the spec, unlike microwatt which
550 # has to turn them around (to LE)
551 rts
, mbits
= self
._get
_rts
_nls
(data
)
552 pgbase
= self
._get
_pgbase
(data
)
554 return (rts
, mbits
, pgbase
)
556 def _get_rts_nls(self
, data
):
557 # rts = shift = unsigned('0' & data(62 downto 61) & data(7 downto 5));
560 assert(rts
.bits
== 6) # variable rts : unsigned(5 downto 0);
563 # mbits := unsigned('0' & data(4 downto 0));
564 mbits
= selectconcat(SelectableInt(0, 1), NLS(data
))
565 assert(mbits
.bits
== 6) #variable mbits : unsigned(5 downto 0);
569 def _segment_check(self
, addr
, mask_size
, shift
):
570 """checks segment valid
571 mbits := '0' & r.mask_size;
572 v.shift := r.shift + (31 - 12) - mbits;
573 nonzero := or(r.addr(61 downto 31) and not finalmask(30 downto 0));
574 if r.addr(63) /= r.addr(62) or nonzero = '1' then
575 v.state := RADIX_FINISH;
577 elsif mbits < 5 or mbits > 16 or mbits > (r.shift + (31 - 12)) then
578 v.state := RADIX_FINISH;
581 v.state := RADIX_LOOKUP;
583 # note that SelectableInt does big-endian! so the indices
584 # below *directly* match the spec, unlike microwatt which
585 # has to turn them around (to LE)
586 mbits
= selectconcat(SelectableInt(0,1), mask_size
)
587 mask
= genmask(shift
, 44)
588 nonzero
= addr
[2:33] & mask
[13:44] # mask 31 LSBs (BE numbered 13:44)
589 print ("RADIX _segment_check nonzero", bin(nonzero
.value
))
590 print ("RADIX _segment_check addr[0-1]", addr
[0].value
, addr
[1].value
)
591 if addr
[0] != addr
[1] or nonzero
!= 0:
593 limit
= shift
+ (31 - 12)
594 if mbits
.value
< 5 or mbits
.value
> 16 or mbits
.value
> limit
.value
:
596 new_shift
= SelectableInt(limit
.value
- mbits
.value
, shift
.bits
)
597 # TODO verify that returned result is correct
600 def _check_perms(self
, data
, priv
, mode
):
601 """check page permissions
603 // |------------------------------| |----------------|
604 // |V|L|sw|//|RPN|sw|R|C|/|ATT|EAA| | usefulBits |
605 // |------------------------------| |----------------|
606 // [0] = V = Valid Bit |
607 // [1] = L = Leaf Bit = 1 if leaf |
609 // [2] = Sw = Sw bit 0. |
610 // [7:51] = RPN = Real Page Number, V
611 // real_page = RPN << 12 -------------> Logical OR
612 // [52:54] = Sw Bits 1:3 |
613 // [55] = R = Reference |
614 // [56] = C = Change V
615 // [58:59] = Att = Physical Address
616 // 0b00 = Normal Memory
618 // 0b10 = Non Idenmpotent
619 // 0b11 = Tolerant I/O
620 // [60:63] = Encoded Access
624 -- check permissions and RC bits
626 if r.priv = '1' or data(3) = '0' then
627 if r.iside = '0' then
628 perm_ok := data(1) or (data(2) and not r.store);
630 -- no IAMR, so no KUEP support for now
631 -- deny execute permission if cache inhibited
632 perm_ok := data(0) and not data(5);
635 rc_ok := data(8) and (data(7) or not r.store);
636 if perm_ok = '1' and rc_ok = '1' then
637 v.state := RADIX_LOAD_TLB;
639 v.state := RADIX_FINISH;
640 v.perm_err := not perm_ok;
641 -- permission error takes precedence over RC error
642 v.rc_error := perm_ok;
645 # decode mode into something that matches microwatt equivalent code
646 instr_fetch
, store
= 0, 0
649 if mode
== 'EXECUTE':
652 # check permissions and RC bits
654 if priv
== 1 or data
[60] == 0:
656 perm_ok
= data
[62] |
(data
[61] & (store
== 0))
657 # no IAMR, so no KUEP support for now
658 # deny execute permission if cache inhibited
659 perm_ok
= data
[63] & ~data
[58]
660 rc_ok
= data
[55] & (data
[56] |
(store
== 0))
661 if perm_ok
== 1 and rc_ok
== 1:
664 return "perm_err" if perm_ok
== 0 else "rc_err"
666 def _get_prtable_addr(self
, shift
, prtbl
, addr
, pid
):
668 if r.addr(63) = '1' then
669 effpid := x"00000000";
673 x"00" & r.prtbl(55 downto 36) &
674 ((r.prtbl(35 downto 12) and not finalmask(23 downto 0)) or
675 (effpid(31 downto 8) and finalmask(23 downto 0))) &
676 effpid(7 downto 0) & "0000";
678 finalmask
= genmask(shift
, 44)
679 finalmask24
= finalmask
[20:44]
680 print ("_get_prtable_addr", shift
, prtbl
, addr
, pid
,
681 bin(finalmask24
.value
))
682 if addr
[0].value
== 1:
683 effpid
= SelectableInt(0, 32)
685 effpid
= pid
#self.pid # TODO, check on this
686 zero8
= SelectableInt(0, 8)
687 zero4
= SelectableInt(0, 4)
688 res
= selectconcat(zero8
,
690 (prtbl
[28:52] & ~finalmask24
) |
#
691 (effpid
[0:24] & finalmask24
), #
697 def _get_pgtable_addr(self
, mask_size
, pgbase
, addrsh
):
699 x"00" & r.pgbase(55 downto 19) &
700 ((r.pgbase(18 downto 3) and not mask) or (addrsh and mask)) &
703 print("pgbase",pgbase
)
704 assert(pgbase
.bits
==56)
705 mask16
= genmask(mask_size
+5, 16)
706 zero8
= SelectableInt(0, 8)
707 zero3
= SelectableInt(0, 3)
708 res
= selectconcat(zero8
,
710 (pgbase
[37:53] & ~mask16
) |
716 def _get_pte(self
, shift
, addr
, pde
):
719 ((r.pde(55 downto 12) and not finalmask) or
720 (r.addr(55 downto 12) and finalmask))
721 & r.pde(11 downto 0);
724 finalmask
= genmask(shift
, 44)
725 zero8
= SelectableInt(0, 8)
726 rpn
= pde
[8:52] # RPN = Real Page Number
727 abits
= addr
[8:52] # non-masked address bits
728 print(" get_pte RPN", hex(rpn
.value
))
729 print(" abits", hex(abits
.value
))
730 print(" shift", shift
.value
)
731 print(" finalmask", bin(finalmask
.value
))
732 res
= selectconcat(zero8
,
733 (rpn
& ~finalmask
) |
#
734 (abits
& finalmask
), #
740 class TestRadixMMU(unittest
.TestCase
):
742 def test_genmask(self
):
743 shift
= SelectableInt(5, 6)
744 mask
= genmask(shift
, 43)
745 print (" mask", bin(mask
.value
))
747 self
.assertEqual(mask
.value
, 0b11111, "mask should be 5 1s")
750 inp
= SelectableInt(0x40000000000300ad, 64)
753 print("rtdb",rtdb
,bin(rtdb
.value
))
754 self
.assertEqual(rtdb
.value
,0x300,"rtdb should be 0x300")
756 result
= selectconcat(rtdb
,SelectableInt(0,8))
757 print("result",result
)
759 def test_get_pgtable_addr(self
):
763 dut
= RADIX(mem
, caller
)
766 pgbase
= SelectableInt(0,56)
767 addrsh
= SelectableInt(0,16)
768 ret
= dut
._get
_pgtable
_addr
(mask_size
, pgbase
, addrsh
)
770 self
.assertEqual(ret
, 0, "pgtbl_addr should be 0")
772 def test_walk_tree_1(self
):
775 # https://github.com/power-gem5/gem5/blob/gem5-experimental/src/arch/power/radix_walk_example.txt#L65
782 # set up dummy minimal ISACaller
783 spr
= {'DSISR': SelectableInt(0, 64),
784 'DAR': SelectableInt(0, 64),
785 'PIDR': SelectableInt(0, 64),
786 'PRTBL': SelectableInt(prtbl
, 64)
788 # set problem state == 0 (other unit tests, set to 1)
789 msr
= SelectableInt(0, 64)
791 class ISACaller
: pass
796 shift
= SelectableInt(5, 6)
797 mask
= genmask(shift
, 43)
798 print (" mask", bin(mask
.value
))
800 mem
= Mem(row_bytes
=8, initial_mem
=testmem
)
801 mem
= RADIX(mem
, caller
)
802 # -----------------------------------------------
803 # |/|RTS1|/| RPDB | RTS2 | RPDS |
804 # -----------------------------------------------
805 # |0|1 2|3|4 55|56 58|59 63|
806 data
= SelectableInt(0, 64)
809 data
[59:64] = 0b01101 # mask
811 (rts
, mbits
, pgbase
) = mem
._decode
_prte
(data
)
812 print (" rts", bin(rts
.value
), rts
.bits
)
813 print (" mbits", bin(mbits
.value
), mbits
.bits
)
814 print (" pgbase", hex(pgbase
.value
), pgbase
.bits
)
815 addr
= SelectableInt(0x1000, 64)
816 check
= mem
._segment
_check
(addr
, mbits
, shift
)
817 print (" segment check", check
)
819 print("walking tree")
820 addr
= SelectableInt(testaddr
,64)
825 result
= mem
._walk
_tree
(addr
, mode
)
826 print(" walking tree result", result
)
827 print("should be", testresult
)
828 self
.assertEqual(result
.value
, expected
,
829 "expected 0x%x got 0x%x" % (expected
,
832 def test_walk_tree_2(self
):
834 # test address slightly different
841 # set up dummy minimal ISACaller
842 spr
= {'DSISR': SelectableInt(0, 64),
843 'DAR': SelectableInt(0, 64),
844 'PIDR': SelectableInt(0, 64),
845 'PRTBL': SelectableInt(prtbl
, 64)
847 # set problem state == 0 (other unit tests, set to 1)
848 msr
= SelectableInt(0, 64)
850 class ISACaller
: pass
855 shift
= SelectableInt(5, 6)
856 mask
= genmask(shift
, 43)
857 print (" mask", bin(mask
.value
))
859 mem
= Mem(row_bytes
=8, initial_mem
=testmem2
)
860 mem
= RADIX(mem
, caller
)
861 # -----------------------------------------------
862 # |/|RTS1|/| RPDB | RTS2 | RPDS |
863 # -----------------------------------------------
864 # |0|1 2|3|4 55|56 58|59 63|
865 data
= SelectableInt(0, 64)
868 data
[59:64] = 0b01101 # mask
870 (rts
, mbits
, pgbase
) = mem
._decode
_prte
(data
)
871 print (" rts", bin(rts
.value
), rts
.bits
)
872 print (" mbits", bin(mbits
.value
), mbits
.bits
)
873 print (" pgbase", hex(pgbase
.value
), pgbase
.bits
)
874 addr
= SelectableInt(0x1000, 64)
875 check
= mem
._segment
_check
(addr
, mbits
, shift
)
876 print (" segment check", check
)
878 print("walking tree")
879 addr
= SelectableInt(testaddr
,64)
884 result
= mem
._walk
_tree
(addr
, mode
)
885 print(" walking tree result", result
)
886 print("should be", testresult
)
887 self
.assertEqual(result
.value
, expected
,
888 "expected 0x%x got 0x%x" % (expected
,
892 if __name__
== '__main__':