6 /* Register contents after executing an TROO insn */
16 uint8_t tran_table
[20] __attribute__((aligned(8))) = {
17 0xaa,0xbb,0xcc,0xdd,0xff,0xda,0xbc,0xab,0xca,0xea,0xcc,0xee
21 0x04,0x01,0x03,0x07,0x08,0x06,0x02,0x05,0x09
26 troo_regs
tr(uint8_t *addr
, uint8_t *codepage
, uint8_t *dest
, uint64_t len
,
30 register uint64_t test_byte
asm("0") = test
;
31 register uint64_t length
asm("3") = len
;
32 register uint64_t srcaddr
asm("4") = (uint64_t)addr
;
33 register uint64_t codepage2
asm("1") = (uint64_t)codepage
;
34 register uint64_t desaddr
asm("2") = (uint64_t)dest
;
35 register uint64_t cc
asm("5");
37 cc
= 2; /* cc result will never be 2 */
42 : "=d"(cc
), "+a"(desaddr
),
43 "+a"(srcaddr
), "+d"(test_byte
), "+a"(codepage2
), "+a"(length
)
46 regs
.srcaddr
= srcaddr
;
48 regs
.desaddr
= desaddr
;
49 regs
.tabaddr
= codepage2
;
50 regs
.testbyte
= test_byte
;
55 int run_test(void *srcaddr
, void *tableaddr
, void *desaddr
, uint64_t len
,
61 assert(len
<= sizeof src
);
63 if ((testbyte
& 0xff) != testbyte
)
64 printf("testbyte should be 1 byte only\n");
66 regs
= tr(srcaddr
, tableaddr
, desaddr
, len
, testbyte
);
68 if ((uint64_t)tableaddr
!= regs
.tabaddr
)
69 printf("translation table address changed\n");
70 if ((uint64_t)srcaddr
+ (len
- regs
.len
) != regs
.srcaddr
)
71 printf("source address/length not updated properly\n");
72 if ((uint64_t)desaddr
+ (len
- regs
.len
) != regs
.desaddr
)
73 printf("destination address/length not updated properly\n");
74 if (regs
.cc
== 0 && regs
.len
!= 0)
75 printf("length is not zero but cc is zero\n");
76 printf("%u bytes translated\n", (unsigned)(len
- regs
.len
));
77 printf("the translated values are");
78 for (i
= 0; i
< len
- regs
.len
; i
++) {
79 printf(" %x", des
[i
]);
90 assert(sizeof des
>= sizeof src
);
92 /* Test 1 : len == 0 */
93 cc
= run_test(NULL
, NULL
, NULL
, 0, 0x0);
95 printf("cc not updated properly:%d", cc
);
97 cc
= run_test(&src
, &tran_table
, &des
, 0, 0xca);
99 printf("cc not updated properly:%d",cc
);
101 /* Test 2 : len > 0, testbyte not matching */
102 cc
= run_test(&src
, &tran_table
, &des
, 5, 0xee);
104 printf("cc not updated properly:%d",cc
);
106 cc
= run_test(&src
, &tran_table
, &des
, 10, 0x00);
108 printf("cc not updated properly:%d",cc
);
110 memset((char *)&des
, 0, 10);
112 /* Test 3 : len > 0, testbyte matching */
113 cc
= run_test(&src
, &tran_table
, &des
, 5, 0xff); /* 1st byte matches */
115 printf("cc not updated properly:%d",cc
);
117 cc
= run_test(&src
, &tran_table
, &des
, 5, 0xbb); /* 2nd byte matches */
119 printf("cc not updated properly:%d",cc
);
121 cc
= run_test(&src
, &tran_table
, &des
, 10, 0xea);
123 printf("cc not updated properly:%d",cc
);