64-bit kernel not passing (char *) correctly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

Are you using your own bootloader, and if yes, how many sectors do you load into memory?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
sngskunk
Member
Member
Posts: 47
Joined: Mon Mar 31, 2008 1:00 pm
Location: Louisville, KY, USA

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

Post 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.
Currently Working On:
Bootloader (Stage 1) (Complete)
Bootloader (Stage 2) (Inprogress)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
sngskunk
Member
Member
Posts: 47
Joined: Mon Mar 31, 2008 1:00 pm
Location: Louisville, KY, USA

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

Post 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.
Currently Working On:
Bootloader (Stage 1) (Complete)
Bootloader (Stage 2) (Inprogress)
Post Reply