public inbox for kernelnewbies@kernelnewbies.org
 help / color / mirror / Atom feed
From: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
To: Mushahid Hussain <mushi.shar@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Loading a simple "kernel" at the address other than default on Raspberry Pi 4
Date: Wed, 3 Nov 2021 09:24:38 +1300	[thread overview]
Message-ID: <20211102202438.GA3466@localhost.localdomain> (raw)
In-Reply-To: <CADaYRJve0AxzvoOQ0pbO_VSwnhsq_zxN+U+JrUd0vG500M1XNQ@mail.gmail.com>


Disclaimer: I'm not an expert in ARM, I'm just trying to help because
I've been (still am really) in the journey of writing a hobbist OS and
know how small suggestions can help sometimes.

On Tue, Nov 02, 2021 at 05:13:16PM +0500, Mushahid Hussain wrote:
> There's a configuration(config.txt)[1] kernel_address on Raspberry Pi 4 but
> whenever I change the load address by even 1 byte, the simple kernel would
> not run. It is only able to run at 0x80000.

Most likely the stages (and code) that run in previous stages expect
your code to be present precisely at this address. Hence, when you
change the target address even by 1 byte it doesn't work.

Remember that if the CPU reads something that causes it to throw an
error/exception, it doesn't go to the next instruction.

QEMU + GDB can be great allies when answering these types of questions.

Something like this (I haven't tested it but this is a starting point):

QEMU cmd: qemu-system-aarch64 -gdb tcp::8864 -drive format=raw,file=$(OUTPUT_RAW_DISK) \
		-S -d guest_errors -d int -no-reboot -no-shutdown

GDB cmd: gdb -ex 'target remote localhost:8864' \
	        -ex 'layout asm' \
	        -ex 'layout regs' \
		-ex 'b *0x80000' \


> How is the standard kernel being loaded at 0x200000, but my simple kernel
> cannot be loaded at any address except for the default address(0x80000)?
> 

I'm not familiar with that firmware but again if I were you I would be debugging the standard 
kernel as well. 

From my personal experience (I'm developing for x86-64), there were a
couple of things that GRUB bootloader did out-of-the-box for the linux kernel to make
its life easier that I had to write myself because I wanted to write the
bootloader too.

My point is, for quite sometime I was looking for the answers in the linux
kernel when in reality those were in a different component (grub in this
case). Make sure that this isn't the case for you as well.

Happy coding :)

> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2021-11-02 20:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-02 12:13 Loading a simple "kernel" at the address other than default on Raspberry Pi 4 Mushahid Hussain
2021-11-02 20:24 ` Paulo Miguel Almeida [this message]
2021-11-02 21:59 ` Valdis Klētnieks
2021-11-04 15:28   ` Mushahid Hussain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211102202438.GA3466@localhost.localdomain \
    --to=paulo.miguel.almeida.rodenas@gmail.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=mushi.shar@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox