I recently started working on a 64-bit os, and I'm getting some strange behavior with pointers. I have this C code:
Code: Select all
#include "../lib/typeout.h"
void main(){
char testStr[15] = "Hello, World!\n\0";
char* testStr2 = "Hello, World!\n\0";
screen_clear();
screen_print_str(testStr);//Works perfectly, prints "Hello, World!" on the screen
screen_print_str(testStr2);//Prints garbage
while(1){}
return;
}
I believe this could be an issue with the Linker script I'm using, from past experience. Also, another interesting piece of the puzzle is that upon looking at the hexdump of the binary file I'm generating, this can be found
Code: Select all
00000410 83 ec 20 48 b8 48 65 6c 6c 6f 2c 20 57 48 89 45 |.. H.Hello, WH.E|
00000420 e9 c7 45 f1 6f 72 6c 64 66 c7 45 f5 21 0a c6 45 |..E.orldf.E.!..E|
Notice how it seems as though the "Hello, World!" message seems to be rather disjointed, and I believe this is around where my char pointer is pointing to. Also, later on in the hexdump, this can be seen as well:
Code: Select all
00000770 45 fc 8b 45 f8 0f b7 55 fc ef 90 5d c3 48 65 6c |E..E...U...].Hel|
00000780 6c 6f 2c 20 57 6f 72 6c 64 21 0a 00 00 66 2e 0f |lo, World!...f..|
And here, the message is in a continuous piece of memory, as one would have expected. Also, one last piece of information is that the linker script I'm using is pulled from an earlier 32-bit OS I was working on, and is now being used in this 64 bit OS project. I'm not sure if that actually makes any difference, however. Again, I suspect that this is an issue with the linker script, but I'm not sure and I'd love some help to debug. Thanks in advance!