views:

128

answers:

3
+2  Q: 

inline gcc

Hi,

I am trying to implement context switch using gcc for m68k processors. I need to use inline assembly for saving all the registers d0, d1...d7 and a0,...a7. I was wondering if I can use a loop in my inline gcc that would allow me to save these registers instead of write a separate line of code for each register.

for eg.

move.l %d0, temp pcb.cpuregs.d0 = temp

i want to make 0 inside d0 like a loop counter.

Thanks!

+1  A: 

You can't use a C-style for loop inside the asm block. But you can use your C code to build a string and pass that along to asm.

eduffy
+2  A: 

You may want to consider macros:

#define SAVE_REG_DXX(no)  __asm__ __volatile__("move.l %%d" #no ", %0" : "=g" (pcb.cpuregs.d ## no))

SAVE_REG_DXX(0);
SAVE_REG_DXX(1);
SAVE_REG_DXX(2);

#undef SAVE_REG_DXX
Adrian Panasiuk
+2  A: 

Here you go:

MOVEM.L D0-D7/A0-A7,-(A7) ;Save registers onto stack.

You don't have to use the stack, you can use some other address.
I have a feeling that the pre-decrement mode is compulsory,
but I can't test that right now as I don't have a 68k machine.

p.s. that's probably not gcc dialect, seeing as gcc didn't exist when
I wrote that code, but I'm sure you can figure it out.

p.p.s why not use setjmp instead of inline assembly?
then your context switcher would be semi-portable.

Rhythmic Fistman
Yes, really, use setjmp. If you can avoid assembly code, do so.
Max Lybbert