Skip to content

Commit f3285fe

Browse files
Valmareloxdpgeorge
authored andcommitted
py/nlrpowerpc: Fix generation of ppc64 code on ppc32 build.
Due to inline assembly, wrong instructions were generated. Use corresponding 32 bit instructions and fix the offsets used. Signed-off-by: Efi Weiss <[email protected]>
1 parent 2e8816d commit f3285fe

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

py/nlrpowerpc.c

+93
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
// Saving all ABI non-vol registers here
3434

35+
#ifdef __LP64__
36+
3537
unsigned int nlr_push(nlr_buf_t *nlr) {
3638

3739
__asm__ volatile (
@@ -118,4 +120,95 @@ NORETURN void nlr_jump(void *val) {
118120
MP_UNREACHABLE;
119121
}
120122

123+
#else
124+
// Saving all ABI non-vol registers here
125+
126+
unsigned int nlr_push(nlr_buf_t *nlr) {
127+
128+
__asm__ volatile (
129+
"li 4, 0x4eed ; " // Store canary
130+
"stw 4, 0x00(%0) ;"
131+
"stw 0, 0x04(%0) ;"
132+
"stw 1, 0x08(%0) ;"
133+
"stw 2, 0x0c(%0) ;"
134+
"stw 14, 0x10(%0) ;"
135+
"stw 15, 0x14(%0) ;"
136+
"stw 16, 0x18(%0) ;"
137+
"stw 17, 0x1c(%0) ;"
138+
"stw 18, 0x20(%0) ;"
139+
"stw 19, 0x24(%0) ;"
140+
"stw 20, 0x28(%0) ;"
141+
"stw 21, 0x2c(%0) ;"
142+
"stw 22, 0x30(%0) ;"
143+
"stw 23, 0x34(%0) ;"
144+
"stw 24, 0x38(%0) ;"
145+
"stw 25, 0x3c(%0) ;"
146+
"stw 26, 0x40(%0) ;"
147+
"stw 27, 0x44(%0) ;"
148+
"stw 28, 0x48(%0) ;"
149+
"stw 29, 0x4c(%0) ;"
150+
"stw 30, 0x50(%0) ;"
151+
"stw 31, 0x54(%0) ;"
152+
153+
"mfcr 4 ; "
154+
"stw 4, 0x58(%0) ;"
155+
"mflr 4 ;"
156+
"stw 4, 0x5c(%0) ;"
157+
"li 4, nlr_push_tail@l ;"
158+
"oris 4, 4, nlr_push_tail@h ;"
159+
"mtctr 4 ;"
160+
"mr 3, %1 ; "
161+
"bctr ;"
162+
:
163+
: "r" (&nlr->regs), "r" (nlr)
164+
:
165+
);
166+
167+
return 0;
168+
}
169+
170+
NORETURN void nlr_jump(void *val) {
171+
MP_NLR_JUMP_HEAD(val, top)
172+
173+
__asm__ volatile (
174+
"l 3, 0x0(%0) ;"
175+
"cmpdi 3, 0x4eed ; " // Check canary
176+
"bne . ; "
177+
"l 0, 0x04(%0) ;"
178+
"l 1, 0x08(%0) ;"
179+
"l 2, 0x0c(%0) ;"
180+
"l 14, 0x10(%0) ;"
181+
"l 15, 0x14(%0) ;"
182+
"l 16, 0x18(%0) ;"
183+
"l 17, 0x1c(%0) ;"
184+
"l 18, 0x20(%0) ;"
185+
"l 19, 0x24(%0) ;"
186+
"l 20, 0x28(%0) ;"
187+
"l 21, 0x2c(%0) ;"
188+
"l 22, 0x30(%0) ;"
189+
"l 23, 0x34(%0) ;"
190+
"l 24, 0x38(%0) ;"
191+
"l 25, 0x3c(%0) ;"
192+
"l 26, 0x40(%0) ;"
193+
"l 27, 0x44(%0) ;"
194+
"l 28, 0x48(%0) ;"
195+
"l 29, 0x4c(%0) ;"
196+
"l 30, 0x50(%0) ;"
197+
"l 31, 0x54(%0) ;"
198+
"l 3, 0x58(%0) ;"
199+
"mtcr 3 ;"
200+
"l 3, 0x5c(%0) ;"
201+
"mtlr 3 ; "
202+
"li 3, 1;"
203+
"blr ;"
204+
:
205+
: "r" (&top->regs)
206+
:
207+
);
208+
209+
MP_UNREACHABLE;
210+
}
211+
212+
#endif // __LP64__
213+
121214
#endif // MICROPY_NLR_POWERPC

0 commit comments

Comments
 (0)