git.s-ol.nu subv / b404af9
start working on DTB printer s-ol 18 days ago
3 changed file(s) with 177 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 == code 0x80400000
1 main:
2 # print device tree info.
3 # OpenSBI calls us with a1 set to the start of the DTB
4 # load 0x10000000 (UART0) into a0
5 37/lui a/rd/a0 10000/imm20
6
7 13/opi 15/rd/s5 0/subop/add b/rs/a1 0/imm12
8
9 # check magic == 0xd00dfeed
10 37/lui 6/rd/t1 edfe1dd0/imm20hi
11 13/opi 6/rd/t1 0/subop/add 6/rs/t1 edfe0dd0/imm12lo
12 03/load 5/rd/t0 2/width/w 15/rs/s5 0/imm12
13 63/branch 1/subop/!= 5/rs/t0 6/rs/t1 err_magic/off13
14
15 37/lui b/rd/a1 S_TOTALSZ/imm20hi
16 13/opi b/rd/a1 0/subop/add b/rs/a1 S_TOTALSZ/imm12lo
17 6f/jal 1/rd/ra print/off21
18
19 03/load b/rd/a1 2/width/w 15/rs/s5 4/imm12
20 6f/jal 1/rd/ra bswapw/off21
21 6f/jal 1/rd/ra print_hex_word/off21
22 6f/jal 1/rd/ra printnl/off21
23
24 exit:
25 # system reset (via SBI extension SRST)
26 # a7 = ext id, a6 = fid, a0 = 0, a1 = 0
27 37/lui 11/rd/a7 53525/imm20
28 13/opi 11/rd/a7 0/subop/add 11/rs/a7 354/imm12
29 33/opr 0/mode/norm 10/rd/a6 0/subop/add 0/rs/x0 0/rs/x0
30 33/opr 0/mode/norm a/rd/a0 0/subop/add 0/rs/x0 0/rs/x0
31 33/opr 0/mode/norm b/rd/a1 0/subop/add 0/rs/x0 0/rs/x0
32 # ECALL
33 73/system 0/subop/priv 0/funct12/ecall
34
35 err_magic:
36 37/lui b/rd/a1 E_MAGIC/imm20hi
37 13/opi b/rd/a1 0/subop/add b/rs/a1 E_MAGIC/imm12lo
38 6f/jal 1/rd/ra print/off21
39 6f/jal 0/rd/x0 exit/off21
40
41 bswapw:
42 # byte-order-swap word in a1
43 # srli a1, a0, 8
44 # lui a2, 16
45 # addi a2, a2, -256
46 # and a1, a1, a2
47 13/opi 5/rd/t0 5/subop/srl b/rs/a1 8/imm12
48 37/lui 6/rd/t1 16/imm20
49 13/opi 6/rd/t1 0/subop/add 6/rs/t1 -100/imm12
50 33/opr 5/rd/t0 7/subop/and 0/mode/norm 5/rs/t0 6/rs/t1
51 # srli a2, a0, 24
52 # or a1, a1, a2
53 13/opi 6/rd/t1 5/subop/srl b/rs/a1 18/imm12
54 33/opr 5/rd/t0 6/subop/or 0/mode/norm 5/rs/t0 6/rs/t1
55 # slli a2, a0, 8
56 # lui a3, 4080
57 # and a2, a2, a3
58 13/opi 6/rd/t1 1/subop/sll 0/mode/norm b/rs/a1 8/imm5
59 37/lui 7/rd/t2 ff0/imm20
60 33/opr 6/rd/t1 7/subop/and 0/mode/norm 6/rs/t1 7/rs/t2
61 # slli a0, a0, 24
62 # or a0, a0, a2
63 # or a0, a0, a1
64 13/opi b/rd/a1 1/subop/sll 0/mode/norm b/rs/a1 18/imm5
65 33/opr b/rd/a1 6/subop/or 0/mode/norm b/rs/a1 6/rs/t1
66 33/opr b/rd/a1 6/subop/or 0/mode/norm b/rs/a1 5/rs/t0
67 # ret
68 67/jalr 0/rd/x0 0/subop 1/rs/ra 0/off12
69
70 printnl:
71 13/opi 6/rd/t1 0/subop/add 0/rs/x0 0a/imm12
72 printnl:spin:
73 # spin if FIFO is full (thr_emtpy = UART+5 & 0x20)
74 03/load 7/rd/t2 4/width/bu a/rs/a0 5/imm12
75 13/opi 7/rd/t2 7/subop/and 7/rs/t2 20/imm12
76 63/branch 0/subop/== 7/rs/t2 0/rs/x0 printnl:spin/off13
77 # print char
78 23/store 2/width/w a/rs/a0 0/off12 6/rs/t1
79 # return
80 67/jalr 0/rd/x0 0/subop 1/rs/ra 0/off12
81
82 print:
83 print:loop:
84 # load unsigned byte at a1
85 03/load 6/rd/t1 4/width/bu b/rs/a1 0/imm12
86 # break loop if zero
87 63/branch 0/subop/== 6/rs/t1 0/rs/x0 print:break/off13
88 print:spin:
89 # spin if FIFO is full (thr_emtpy = UART+5 & 0x20)
90 03/load 7/rd/t2 4/width/bu a/rs/a0 5/imm12
91 13/opi 7/rd/t2 7/subop/and 7/rs/t2 20/imm12
92 63/branch 0/subop/== 7/rs/t2 0/rs/x0 print:spin/off13
93 # print char
94 23/store 2/width/w a/rs/a0 0/off12 6/rs/t1
95 # increment a1
96 13/opi b/rd/a1 0/subop/add b/rs/a1 1/imm12
97 # jump back up
98 6f/jal 0/rd/x0 print:loop/off21
99 print:break:
100 # return
101 67/jalr 0/rd/x0 0/subop 1/rs/ra 0/off12
102
103 print_hex_word:
104 13/opi 8/rd/s0 0/subop/add b/rs/a1 0/imm12
105 13/opi 9/rd/s1 0/subop/add 0/rs/x0 1c/imm12
106 13/opi 12/rd/s2 0/subop/add 1/rs/ra 0/imm12
107 print_hex_word:loop:
108 # shift
109 33/opr b/rd/a1 5/subop/srl 8/rs/s0 0/funct7/norm 9/rs/s1
110 6f/jal 1/rd/ra print_hex_dgt/off21
111
112 # break if last shift
113 63/branch 9/rs/s1 0/subop/== 0/rs/x0 print_hex_word:break/off13
114
115 # subtract shift count, loop
116 13/opi 9/rd/s1 0/subop/add 9/rs/s1 -4/imm12
117 6f/jal 0/rd/x0 print_hex_word:loop/off21
118 print_hex_word:break:
119 # return
120 67/jalr 0/rd/x0 0/subop 12/rs/s2 0/off12
121
122 print_hex_dgt:
123 # a1 = a1 & 0xf
124 13/opi b/rd/a1 7/subop/and b/rs/a1 f/imm12
125 # t1 = 0x40
126 13/opi 6/rd/t1 0/subop/add 0/rs/x0 40/imm12
127
128 # add 0x30 (ascii '0') / 0x61 (ascii 'a')
129 13/opi b/rd/a1 0/subop/add b/rs/a1 30/imm12
130 63/branch b/rs/a1 4/subop/< 6/rs/t1 print_hex_dgt:spin/off13
131 13/opi b/rd/a1 0/subop/add b/rs/a1 27/imm12
132
133 print_hex_dgt:spin:
134 # spin if FIFO is full (thr_emtpy = UART+5 & 0x20)
135 03/load 7/rd/t2 4/width/bu a/rs/a0 5/imm12
136 13/opi 7/rd/t2 7/subop/and 7/rs/t2 20/imm12
137 63/branch 0/subop/== 7/rs/t2 0/rs/x0 print_hex_dgt:spin/off13
138
139 # print char
140 23/store 2/width/w a/rs/a0 0/off12 b/rs/a1
141
142 # return
143 67/jalr 0/rd/x0 0/subop 1/rs/ra 0/off12
144
145 == data 0x80500000
146 E_MAGIC:
147 # "Invalid DTB magic!\n\0"
148 49/8 6e/8 76/8 61/8 6c/8 69/8 64/8 20/8 44/8 54/8 42/8 20/8 6d/8 61/8 67/8 69/8 63/8 21/8 0a/8 00/8
149 S_TOTALSZ:
150 54/8 6f/8 74/8 61/8 6c/8 20/8 53/8 69/8 7a/8 65/8 3a/8 20/8 00/8
151
127127 ValueError: label reference out of range (8 bit): 'label' (0x1234)
128128 """
129129 if not subv.is_reference(word):
130 return word
130 if len(word) != 2:
131 return word
132
133 ref = subv.parse_immediate(word[1])
134 if not ref or "split" not in ref:
135 return word
136
137 value = word[0]
138
139 sgn = -1 if value < 0 else 1
140 value *= sgn
141
142 if ref["split"] == "hi" and ref["size"] == 20:
143 value = value >> 12
144 elif ref["split"] == "lo" and ref["size"] == 12:
145 value = value & 0xFFF
146 else:
147 raise ValueError(
148 "unknown label split mode {mode}{size}{split}".format(**ref)
149 )
150
151 return (value, "imm{size}".format(**ref))
131152
132153 ref = subv.parse_reference(word)
133154
362362 if funct[2] in ["sll", "srl", "sra"]:
363363 try:
364364 shamt = pop_immediate(inputs, 5)
365 mode = pop_immediate(inputs, 7)
365 mode = validate_part(
366 inputs, ["funct7", "mode"], {"norm": 0, "alt": 32}, NAME="comp-mode"
367 )
366368 except ValueError:
367369 imm = pop_immediate(inputs, 12)
368370 shamt = ((imm[0] & 0b11111), 'imm5')