-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump.S
199 lines (160 loc) · 2.2 KB
/
dump.S
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
.global dump_state
dump_state:
cli
push r31
push r30
push r29
push r28
push r27
push r26
push r25
push r24
push r23
push r22
push r21
push r20
push r19
push r18
push r17
push r16
push r15
push r14
push r13
push r12
push r11
push r10
push r9
push r8
push r7
push r6
push r5
push r4
push r3
push r2
push r1
push r0
ldi r23, 32
ldi r22, 0
ldi r21, 0
ldi r20, 0x30
.print_reg_loop:
/* Loop through register values */
ldi r24, 'R'
call serial_tx_byte
mov r24, r22
add r24, r20
call serial_tx_byte
mov r24, r21
add r24, r20
call serial_tx_byte
ldi r24, ':'
call serial_tx_byte
ldi r24, '\t'
call serial_tx_byte
pop r24
call _print_byte_hex
call _print_nl
inc r21
cpi r21, 10
brlt .prl0
ldi r21, 0
inc r22
.prl0:
dec r23
brne .print_reg_loop
/* PC from stack */
call avr_mcu_pc_size_bytes
mov r19, r24
cpi r19, 3
brlt .pc0
pop r25
.pc0:
pop r23
pop r22
/* SP at call site */
in r21, 0x3e
in r20, 0x3d
ldi r24, 'P'
call serial_tx_byte
ldi r24, 'C'
call serial_tx_byte
ldi r24, ':'
call serial_tx_byte
ldi r24, '\t'
call serial_tx_byte
cpi r19, 3
brlt .pc1
mov r24, r25
call _print_byte_hex
.pc1:
mov r24, r23
call _print_byte_hex
mov r24, r22
call _print_byte_hex
call _print_nl
ldi r24, 'S'
call serial_tx_byte
ldi r24, 'P'
call serial_tx_byte
ldi r24, ':'
call serial_tx_byte
ldi r24, '\t'
call serial_tx_byte
mov r24, r21
call _print_byte_hex
mov r24, r20
call _print_byte_hex
call _print_nl
/* Print some stack bytes */
ldi r23, 32
.print_stack_bytes_loop:
ldi r24, ' '
call serial_tx_byte
pop r24
call _print_byte_hex
dec r23
mov r22, r23
andi r22, 0x03
brne .psbl0
call _print_nl
.psbl0:
cpi r23, 0
brne .print_stack_bytes_loop
.ds_sleep:
sleep
rjmp .ds_sleep
_print_nl:
push r24
ldi r24, 0x0d
call serial_tx_byte
ldi r24, 0x0a
call serial_tx_byte
pop r24
ret
_print_byte_hex:
push r21
push r20
ldi r21, 0x30
ldi r20, 0x27
push r24
swap r24
andi r24, 0x0f
cpi r24, 0x0a
brlt .pbh0
add r24, r20
.pbh0:
add r24, r21
call serial_tx_byte
pop r24
push r24
andi r24, 0x0f
cpi r24, 0x0a
brlt .pbh1
add r24, r20
.pbh1:
add r24, r21
call serial_tx_byte
pop r24
pop r20
pop r21
ret