Crash when casting a void* to a multiboot_info_t*

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.
Post Reply
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

Crash when casting a void* to a multiboot_info_t*

Post 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
Working on managarm.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

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

Post 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.)
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

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

Post 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 ī).
Working on managarm.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

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

Post by Geri »

how do you know if you even have a proper stack pointer? are you sure you even have the right code origin?
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

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

Post by qookie »

I fixed the issue. I just realized I pushed EBP instead of EBX. My bad. Sorry if I wasted anyone's time.
Working on managarm.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

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

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
qookie
Member
Member
Posts: 72
Joined: Sun Apr 30, 2017 12:16 pm
Libera.chat IRC: qookie
Location: Poland

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

Post by qookie »

Thank you for helping Brendan but I solved my issue right before you posted. Still thanks for advice and help.
Working on managarm.
Post Reply