I'm taking an operating systems design class in which they have given us a microkernel written in C that we're building on top of. The kernel seems to have been designed with 32-bit machines in mind and I'm running snow leopard. So a friend in the class and I have been trying to hack it into 64-bit addressing.
The biggest issue seems to be one line of code, where inline assembly is utilized to copy the current stack pointer into a temporary variable used by the dispatcher:
#define SET_STACK(s) asm("movl temp,%esp");
Naturally, the compiler spits back errors at me because %esp is a 32-bit register.
/var/folders/0A/0AVWZC-5HhOg6twWZBlDgU+++TI/-Tmp-//cckS2oq7.s:523:32-bit absolute addressing is not supported for x86-64
/var/folders/0A/0AVWZC-5HhOg6twWZBlDgU+++TI/-Tmp-//cckS2oq7.s:523:cannot do signed 4 byte relocation
So I replaced it with %rsp because it's the 64-bit stack pointer register (and I think just %sp works as well, I read somewhere else on here that GAS is smart enough to put the right prefix). After replacing %esp with %rsp, I get this error:
/var/folders/0A/0AVWZC-5HhOg6twWZBlDgU+++TI/-Tmp-//cc8TLdjH.s:523:Incorrect register `%sp' used with `l' suffix
Now, I'm a bit at a loss because I'm not really experienced with assembler. I've tried replacing movl with mov, and movq, but nothing seems to work. Which leads me to believe that maybe tempis the wrong size?
Temp is a global variable, declared like so:
void* temp; // temp pointer used in dispatcher
I wrote a quick program to print out the sizes of different datatypes, and it seems like void* in x86-64 are 8 bytes in size, which should be the right size, right?
Anyway, obviously I don't expect anyone to solve this problem for me, but any tips that might point me in the right direction would be much appreciated!
UPDATE If anyone is willing to take a quick look at the code I have it posted on github. http://github.com/jarsen/os345
The macro in question is on line 166 of http://github.com/jarsen/os345/blob/master/os345.h
The variable tempis defined on line 65, assigned a value on 350, and the macro is called on 351 of http://github.com/jarsen/os345/blob/master/os345.c
It looks like temp is being cast as an int*, which I suspect is causing the issues... although as a pointer it should be 8 bytes, so should be the right size... right?