OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:22 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem with my custom boot loader, tried everything
PostPosted: Thu May 04, 2023 7:10 am 
Offline

Joined: Thu May 04, 2023 6:50 am
Posts: 1
When I use my boot loader inline strings(char pointers) don't work, same with global variables
I've seen this issue with grub here https://stackoverflow.com/questions/18687350/homemade-kernel-linker-global-variables-and-inline-strings-cannot-be-accessed at stack overflow
but it does not work for me
I tried everything

What i know:
- pointers are pointing to a wrong memory address
- this only occurs when I use my own boot loader, it does not when I use qemu with -kernel flag
- probably something wrong with the linker

What I don't know is how to fix it

To reproduce run make

os does print "OS booted successfully", but only because it is stored in a char array, and not an inline string
those hex values are:
first one is a test if the function does it's thing - it should be 0x79F
second is the memory address of a char pointer, which is not pointing where it should

and the last one is where the rodata section starts, according to linker

I'm new to os development and c++ development (previously wrote mainly in c#), so please question every line of code I wrote

code available here: https://github.com/imicz-a/MyOs

Thanks for your help


Top
 Profile  
 
 Post subject: Re: Problem with my custom boot loader, tried everything
PostPosted: Sun May 07, 2023 2:53 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
You're telling the linker to produce an ELF executable, but your bootloader is expecting a flat binary. Try telling the linker to produce a flat binary.

Also, you have a Multiboot header at the beginning of your binary, and once you tell the linker to produce a flat binary you'll jump to that header and execute it, which certainly won't do anything useful.

Also, your bootloader has some bugs related to segmentation. For example, you have no idea where your stack is.

Are you sure you want to write your own bootloader?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 70 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group