The "bl __restartkernel" patch: I've no clue why I've not seen the problem

Mark Millard via freebsd-ppc <[email protected]>
Newsgroups gmane.os.freebsd.devel.ppc
Message-ID <[email protected]>
> The branch main has been updated by bdragon:
> 
> URL: 
> https://cgit.FreeBSD.org/src/commit/?id=d26f2a50ff48dacd38ba358d658882d51f7bdbc4
> 
> 
> commit d26f2a50ff48dacd38ba358d658882d51f7bdbc4
> Author:     Brandon Bergren <
> bdragon at FreeBSD.org
> >
> AuthorDate: 2021-02-07 22:05:41 +0000
> Commit:     Brandon Bergren <
> bdragon at FreeBSD.org
> >
> CommitDate: 2021-02-07 22:13:55 +0000
> 
>     powerpc64: Fix boot on virtual-mode OF (PowerMac G5)
>     
>     In 78599c32efed3247d165302a1fbe8d9203e38974, CFI endproc decoration was
>     added to locore64.S. However, it missed the subtle detail that
>     __restartkernel_virtual() falls through to __restartkernel(). This was
>     causing boot failure on PowerMac G5, as it tried to execute the
>     epilogue as code.
>     
>     Fix this by branching to __restartkernel() instead of intentionally
>     running off the end of the function.
>     
>     While here, add some additional notes on how the virtual mode restart
>     works.
>     
>     MFC after:      3 days
> ---
>  sys/powerpc/aim/locore64.S | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/sys/powerpc/aim/locore64.S b/sys/powerpc/aim/locore64.S
> index 0bc0619620d9..f0a183c4b331 100644
> --- a/sys/powerpc/aim/locore64.S
> +++ b/sys/powerpc/aim/locore64.S
> @@ -255,6 +255,16 @@ ASENTRY_NOPROF(__restartkernel_virtual)
>  	addi	%r14, %r14, 1
>  	cmpdi	%r14, 16
>  	blt	1b
> +
> +	/*
> +	 * Now that we are set up with a temporary direct map, we can
> +	 * continue with __restartkernel. Translation will be switched
> +	 * back on at the rfid, at which point we will be executing from
> +	 * the temporary direct map we just installed, until the kernel
> +	 * takes over responsibility for the MMU.
> +	 */
> +	bl	__restartkernel
> +	nop
>  ASEND(__restartkernel_virtual)
>  
>  ASENTRY_NOPROF(__restartkernel)

Wow. Somehow I've not had boot powerpc64 FreeBSD boot
problems since the ASEND(__restartkernel_virtual)
addition. For example, the current boot code has
( from objdump output of /boot/kernel/kernel ):

0000000000100710 <__restartkernel_virtual> addis   r2,r12,302
0000000000100714 <__restartkernel_virtual+0x4> addi    r2,r2,10480
0000000000100718 <__restartkernel_virtual+0x8> mfmsr   r14
000000000010071c <__restartkernel_virtual+0xc> andi.   r14,r14,61389
0000000000100720 <__restartkernel_virtual+0x10> mtmsr   r14
0000000000100724 <__restartkernel_virtual+0x14> isync
0000000000100728 <__restartkernel_virtual+0x18> li      r14,0
000000000010072c <__restartkernel_virtual+0x1c> li      r18,0
0000000000100730 <__restartkernel_virtual+0x20> oris    r18,r18,49152
0000000000100734 <__restartkernel_virtual+0x24> rldicr  r18,r18,32,31
0000000000100738 <__restartkernel_virtual+0x28> slbmfev r15,r14
000000000010073c <__restartkernel_virtual+0x2c> slbmfee r16,r14
0000000000100740 <__restartkernel_virtual+0x30> or      r16,r16,r14
0000000000100744 <__restartkernel_virtual+0x34> ori     r16,r16,16
0000000000100748 <__restartkernel_virtual+0x38> or      r16,r16,r18
000000000010074c <__restartkernel_virtual+0x3c> rldicr  r17,r16,0,37
0000000000100750 <__restartkernel_virtual+0x40> isync
0000000000100754 <__restartkernel_virtual+0x44> slbie   r17
0000000000100758 <__restartkernel_virtual+0x48> slbmte  r15,r16
000000000010075c <__restartkernel_virtual+0x4c> isync
0000000000100760 <__restartkernel_virtual+0x50> addi    r14,r14,1
0000000000100764 <__restartkernel_virtual+0x54> cmpdi   r14,16
0000000000100768 <__restartkernel_virtual+0x58> blt     0000000000100738 <__restartkernel_virtual+0x28>
        ...
0000000000100778 <__restartkernel_virtual+0x68> nop
000000000010077c <__restartkernel_virtual+0x6c> nop
0000000000100780 <__restartkernel> addis   r2,r12,302
0000000000100784 <__restartkernel+0x4> addi    r2,r2,10368
0000000000100788 <__restartkernel+0x8> mtsrr1  r9
000000000010078c <__restartkernel+0xc> bl      0000000000100790 <__restartkernel+0x10>
0000000000100790 <__restartkernel+0x10> mflr    r25
0000000000100794 <__restartkernel+0x14> add     r25,r8,r25
0000000000100798 <__restartkernel+0x18> addi    r25,r25,20
000000000010079c <__restartkernel+0x1c> mtsrr0  r25
00000000001007a0 <__restartkernel+0x20> rfid
00000000001007a4 <__restartkernel+0x24> bl      0000000000100630 <__start>
00000000001007a8 <__restartkernel+0x28> nop

I wonder what implicit oddities have been happening
because of it, without obvious boot problems. Or is
the above only involved for some PowerMac G5s?

Cool find.

I've a ports rebuild in progress that may well not
finish for another 6+ hours. I'll not be updating
for this until sometime after the port build
finishes.

===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)

_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-ppc
To unsubscribe, send any mail to "[email protected]"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.