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.
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.
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.
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.
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?
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.)