OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: changing kernel load address on rpi4
PostPosted: Sat Oct 30, 2021 3:46 am 
Offline

Joined: Sat Oct 30, 2021 3:38 am
Posts: 2
I am trying to learn systems programming. I have create a simple kernel, which prints Hello World to the UART on a Raspberry pi 4 model B. Source code can be found here. It works perfectly when kernel load address is 0x80000(which is the default load address). I would like to change the load address of the kernel and it should still be functional.

Here's the source code.
https://github.com/SikkiLadho/Leo

I tried to change the kernel_address=[any_address_other_than_defaul](for example kernel_address=0x7F78E), and I cannot see the Hello World printed on the UART. I tried reflecting this change of load_address in the linker script, but it still would not print Hello World.

Code:
SECTIONS
{
   . = 0x7F78E;
   .text.boot : { *(.text.boot) }
   .text : { *(.text) }
   .rodata : { *(.rodata) }
   .data : { *(.data) }
   . = ALIGN(0x8);
   bss_begin = .;
   .bss : { *(.bss*) }
   bss_end = .;
}


My kernel only prints Hello World, when it is loaded to 0x80000. How can I successfully load it at the different address?


Top
 Profile  
 
 Post subject: Re: changing kernel load address on rpi4
PostPosted: Sun Oct 31, 2021 1:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
You can't change the default load address, it's always 0x80000 for 64-bit kernels. If you want your kernel to run at a different address, you need to write code that will move the kernel.


Top
 Profile  
 
 Post subject: Re: changing kernel load address on rpi4
PostPosted: Sun Oct 31, 2021 1:38 pm 
Offline

Joined: Sat Oct 30, 2021 3:38 am
Posts: 2
Octocontrabass wrote:
You can't change the default load address, it's always 0x80000 for 64-bit kernels. If you want your kernel to run at a different address, you need to write code that will move the kernel.


Thank you for your reply. Actually, I wanted to load a simple hello world executable fused with the standard kernel) at [default load address - size of hello world kernel]. After simple kernel has printed Hello World to UART, it would eret to 0x80000, from where standard kernel would run.

How can I move the kernel to a different address in c so that both my hello world kernel and the standard kernel are able to run successfully?


Top
 Profile  
 
 Post subject: Re: changing kernel load address on rpi4
PostPosted: Sun Oct 31, 2021 3:33 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
SikkiLadho wrote:
How can I move the kernel to a different address in c so that both my hello world kernel and the standard kernel are able to run successfully?

Change the link script for the standard kernel so it can run at a different address.

You might be able to do it entirely in C with some linker trickery, but I don't know how to pull it off. You're trying to move the kernel into the memory that contains the currently running code, which means the code that does the copying has to first be copied elsewhere so that it doesn't overwrite itself. (This isn't too difficult if you allow yourself to use some assembly.)


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], FrankRay78, Google [Bot], SemrushBot [Bot] and 56 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