[PATCH] powerpc: Fixed duplicate copying in the early boot.

Jinglin Wen jinglin.wen at shingroup.cn
Tue Jun 18 19:40:11 AEST 2024


Hi Segher Boessenkool,

Segher Boessenkool <segher at kernel.crashing.org> writes:
> Hi!
> 
> On Mon, Jun 17, 2024 at 10:35:09AM +0800, Jinglin Wen wrote:
> > +	cmplwi	cr0,r4,0	/* runtime base addr is zero */
> 
> Just write
>    cmpwi r4,0
> 
> cr0 is the default, also implicit in many other instructions, please
> don't clutter the source code.  All the extra stuff makes you miss the
> things that do matter!
> 
> The "l" is unnecessary, you only care about equality here after all.
> 
> Should it not be cmpdi here, though?
> 
> 
> Segher

Thank you very much for your suggestion. I will use cmpd directly from now on. 
The specific code is as follows:

diff --git a/arch/powerpc/kernel/head_64.S b/arch/powerpc/kernel/head_64.S
index 4690c219bfa4..751181dfb897 100644
--- a/arch/powerpc/kernel/head_64.S
+++ b/arch/powerpc/kernel/head_64.S
@@ -647,8 +647,9 @@ __after_prom_start:
  * Note: This process overwrites the OF exception vectors.
  */
        LOAD_REG_IMMEDIATE(r3, PAGE_OFFSET)
-       mr.     r4,r26                  /* In some cases the loader may  */
-       beq     9f                      /* have already put us at zero */
+       mr      r4,r26                  /* Load the virtual source address into r4 */
+       cmpd    r3,r4           /* Check if source == dest */
+       beq     9f                      /* If so skip the copy  */
        li      r6,0x100                /* Start offset, the first 0x100 */
                                        /* bytes were copied earlier.    */ 

Thanks,

Jinglin Wen


More information about the Linuxppc-dev mailing list