Page 2 of 2

Re: 64-bit kernel not passing (char *) correctly

Posted: Fri Jun 20, 2008 7:21 am
by Combuster
Are you using your own bootloader, and if yes, how many sectors do you load into memory?

Re: 64-bit kernel not passing (char *) correctly

Posted: Fri Jun 20, 2008 7:44 am
by sngskunk
I am using my own boot loader but it reads the fat12 partition, so it loads the file in to memory until it reaches the end of file marker (0x0FF0).

I loads everything in to memory because I can put the string before any of the data section and everything in the data section works, but the string still doesn't work.

If i even try this is doesn't work, it doesn't ever matter about it getting passed a (char *):

Code: Select all

/** Doesnt Work **/
void write(void) {
	char *c = "hello";
	int i = 0;
	while(c[i]) {
		put(c[i++]);
	}
}

/** Does Work **/
void write(void) {
	char c[6] = "hello";
	int i = 0;
	while(c[i]) {
		contVideoPut(c[i++]);
	}
}
I mean it is basically the same thing, but shows that its not becuase the function is getting push the wrong address.

I am in long so it has to do with me linking it wrong, or how pointers are 64bit, but I do not know why it would matter if it derefrenced the pointer.

Re: 64-bit kernel not passing (char *) correctly

Posted: Fri Jun 20, 2008 7:58 am
by Combuster
Given that you use your own bootloader, I still suspect there's something wrong in there. The possibilities are however too many to list here, so you'll have to give us some indication of what does and what does not happen.

Given that the output binary contains the string, I suggest you get a copy of bochs with x86_64 and debugging enabled. Then when it has loaded your kernel, and when it enters your kernel you can see what is in virtual memory, physical memory, the processor state, and everything else that might be involved.

Look at memory, page tables, step through the "broken" code, so you can see what the processor actually thinks of your work, as the "printf debugging" you did can not show you all the variables.

Besides, knowing how to use Bochs' debugger is a very useful ability of itself already too :wink:

Re: 64-bit kernel not passing (char *) correctly

Posted: Fri Jun 20, 2008 10:16 am
by sngskunk
thank you Combuster, I have been trying to do this awhile and i never had bochs debugger installed like an idiot, but I installed it, and started looking at the memory and where my function was looking, and then found that I have my linker script to the wrong address. :oops:

I feel like an idiot.

Thank you to all that work with me on my stupidity.