9front - general discussion about 9front
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9front@9front.org
Subject: Re: [9front] PXE booting Rpi
Date: Mon, 12 Apr 2021 12:14:20 +0200	[thread overview]
Message-ID: <633FF4EC79DF3B38CDE5E179107968A5@felloff.net> (raw)
In-Reply-To: <DF764266-F8B4-4A55-8E21-431F58741BC4@me.com>


> > ok, i just tried the 32 bit pi2 kernel with a raspberry pi 3B+ 
> > pxeboot and the R2 register appears to be zero on entry.

> I stumbled upon the R2 thing just by reading the docs and as I was
> debugging my issue I thought the docs/comments mismatch might have
> been an hint.

> I did not double-check it as:
> - I don't know yet how to access a register (:D) (is KADDR giving a 
> pointer to it? What if I give it 2 instead of 0?), and 

nonono. you have to save the R2 register on entry and get it to
main. see the diff later.

> - I assumed `if(pa != 0 && /* smth */` is never asserted as pa is
> apparently always 0.

of course, we always call bootargsinit(0) in the 32 bit bcm kernel.
that is a constant.

> If I call bootargsinit(2) which calls KADDR(2) is yielding R2, I just
> checked it and (without device_tree= in config.txt, otherwise the
> fallback works and the Pi loads the args) the Pi is *NOT* loading
> neither devtree nor atags: I assume you’re right then? No R2 for
> Pis?

nononono. KADDR() translates a physical address to the KZERO window
of the kernel. like physical address 0 becomes (KZERO+0)... this
for accessing memory (reading the DTB/ATAGS).

> I’ll be on it later this afternoon.

> Why the ‘pa != 0’ check?

i already said that bootargs.c in bcm/ is shared also by the bcm64
kernel, where we pass the dtb pointer to it. but it is not used in
the 32 bit bcm kernel. that is why there is a conditional. a pa
of 0 means the address is not valid. its like a NULL check.

theres also a special case that ATAGS are trashed on kernel-to-kernel
reboot. so even on bcm64, pa can be 0 when the information has been
converted to CONFADDR text block.

> Just to learn something from a master, how are you debugging this?
> I’m collecting data and dumping it as soon as print is ready!

thats pretty much how you do it.

anyway, heres how i checked what R2 is on entry. basically,
move R2 to R10 (which is reserved by c code for the mach
pointer so c code wont trash it). and then before calling
main() put it in R0 (first arument).

diff -r b4182c0fe4a9 sys/src/9/bcm/armv6.s
--- a/sys/src/9/bcm/armv6.s	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/armv6.s	Mon Apr 12 11:58:27 2021 +0200
@@ -76,6 +76,9 @@
 	MOVW	$1, R1
 	MCR	CpSC, 0, R1, C(CpSPM), C(CpSPMperf), CpSPMctl
 
+	/* first arg to main is saved R2 */
+	MOVW	R10, R0
+
 	/*
 	 * call main and loop forever if it returns
 	 */
diff -r b4182c0fe4a9 sys/src/9/bcm/armv7.s
--- a/sys/src/9/bcm/armv7.s	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/armv7.s	Mon Apr 12 11:58:27 2021 +0200
@@ -126,6 +126,9 @@
 	MOVW	$1, R1
 	MCR	CpSC, 0, R1, C(CpCLD), C(CpCLDena), CpCLDenapmnc
 
+	/* first arg to main is saved R2 */
+	MOVW	R10, R0
+
 	/*
 	 * call main and loop forever if it returns
 	 */
diff -r b4182c0fe4a9 sys/src/9/bcm/bootargs.c
--- a/sys/src/9/bcm/bootargs.c	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/bootargs.c	Mon Apr 12 11:58:27 2021 +0200
@@ -265,7 +265,7 @@
 	uintptr len;
 
 	/*
-	 * kernel gets DTB/ATAGS pointer in R0 on entry
+	 * kernel gets DTB/ATAGS pointer on entry
 	 */
 	if(pa != 0 && (len = cankaddr(pa)) != 0){
 		void *va = KADDR(pa);
diff -r b4182c0fe4a9 sys/src/9/bcm/l.s
--- a/sys/src/9/bcm/l.s	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/l.s	Mon Apr 12 11:58:27 2021 +0200
@@ -10,6 +10,9 @@
  * other cpus enter at cpureset in armv7.s
  */
 TEXT _start(SB), 1, $-4
+	/* save R2 in extern register R10 (Mach *m) */
+	MOVW	R2, R10
+
 	/*
 	 * load physical base for SB addressing while mmu is off
 	 * keep a handy zero in R0 until first function call
diff -r b4182c0fe4a9 sys/src/9/bcm/main.c
--- a/sys/src/9/bcm/main.c	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/main.c	Mon Apr 12 11:58:27 2021 +0200
@@ -75,7 +75,7 @@
 }
 
 void
-main(void)
+main(uintptr arg0)
 {
 	extern char edata[], end[];
 	uint fw, board;
@@ -90,6 +90,8 @@
 	uartconsinit();
 	screeninit();
 
+	print("arg0 = %#p\n", arg0);
+
 	print("\nPlan 9 from Bell Labs\n");
 	board = getboardrev();
 	fw = getfirmware();
diff -r b4182c0fe4a9 sys/src/9/bcm/rebootcode.s
--- a/sys/src/9/bcm/rebootcode.s	Sun Apr 11 23:58:30 2021 +0200
+++ b/sys/src/9/bcm/rebootcode.s	Mon Apr 12 11:58:27 2021 +0200
@@ -84,6 +84,7 @@
 	BEQ	dowfi		/* if zero, wait again */
 
 bootcpu:
+	MOVW	$0, R2		/* no ATAGS/DTB pointer */
 	BIC	$KSEGM, R8	/* entry to physical */
 	ORR	$PHYSDRAM, R8
 	BL	(R8)

--
cinap

  reply	other threads:[~2021-04-12 10:21 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-10 14:05 Daniel Morandini
2021-03-10 17:20 ` cinap_lenrek
2021-03-12 10:36   ` Daniel Morandini
2021-03-25 10:55     ` Daniel Morandini
2021-03-25 18:49       ` Noam Preil
2021-03-25 21:49         ` Noam Preil
2021-04-07  8:39         ` Daniel Morandini
2021-04-08 14:21           ` cinap_lenrek
2021-04-08 15:45             ` Daniel Morandini
2021-04-08 16:12               ` cinap_lenrek
2021-04-11 12:11                 ` cinap_lenrek
2021-04-12  9:04                   ` Daniel Morandini
2021-04-12 10:14                     ` cinap_lenrek [this message]
2021-04-12 16:48                       ` Daniel Morandini
2021-04-15 21:15                         ` cinap_lenrek
2021-04-19  7:53                           ` Daniel Morandini
2021-04-19 16:20                             ` Daniel Morandini

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=633FF4EC79DF3B38CDE5E179107968A5@felloff.net \
    --to=cinap_lenrek@felloff.net \
    --cc=9front@9front.org \
    /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;
as well as URLs for NNTP newsgroup(s).