Page 1 of 1

Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 10:54 am
by qookie
Hello. I'm developing an OS. I get a very weird issue. When I cast void* passed as argument to kernel_main I get a very weird crash. EBX, ESI and EIP are set to a very similar value. Every time EIP is set to the same value(0x31303131) which results in a crash because of code executing outside of ROM or RAM. Source code.
PS. I'm using GRUB 2

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:01 am
by Geri
you cant get crash from casting a void pointer to something. thats just giving a value to something. either the target variable, or the source is not a valid memory location.

(your project, kuki means small penis (boys penis) in hungarian language.)

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:10 am
by qookie
Geri wrote:you cant get crash from casting a void pointer to something. thats just giving a value to something. either the target variable, or the source is not a valid memory location.

(your project, kuki means small penis (boys penis) in hungarian language.)
I isolated the problem to be that one line(I tried it without anything before and after) and the EIP still was corrupted. How can I check the value if it doesn't get past that line.
KukkiOS is because Git doesn't really like non-ASCII characters(same with text mode). The correct OS name is クッキーOS or Kukkī OS(notice the i is not really an i, it's ī).

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:14 am
by Geri
how do you know if you even have a proper stack pointer? are you sure you even have the right code origin?

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:16 am
by qookie
I fixed the issue. I just realized I pushed EBP instead of EBX. My bad. Sorry if I wasted anyone's time.

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:18 am
by Brendan
Hi,
qookie wrote:Hello. I'm developing an OS. I get a very weird issue. When I cast void* passed as argument to kernel_main I get a very weird crash. EBX, ESI and EIP are set to a very similar value. Every time EIP is set to the same value(0x31303131) which results in a crash because of code executing outside of ROM or RAM. Source code.
PS. I'm using GRUB 2
The problem is here (in "boot.s"):

Code: Select all

_start:
	mov $stack_top, %esp
	push %ebp
	push %eax
	
	call kernel_main
The address of the multiboot info is passed (by the boot loader) in EBX, not in EBP.

Note that you can avoid casting by defining main like this:

Code: Select all

void kernel_main(uint32_t magic, multiboot_info_t* header) {
..but that would just make the code a little cleaner.


Cheers,

Brendan

Re: Crash when casting a void* to a multiboot_info_t*

Posted: Sun May 14, 2017 11:21 am
by qookie
Thank you for helping Brendan but I solved my issue right before you posted. Still thanks for advice and help.