From: "Pali Rohár" <pali@kernel.org>
To: Priyanka Jain <priyanka.jain@nxp.com>, Wolfgang Denk <wd@denx.de>,
Sinan Akman <sinan@writeme.com>,
"Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: u-boot@lists.denx.de
Subject: [PATCH v2] powerpc: mpc85xx: Simplify jump to _start_cont in flash code
Date: Tue, 28 Jun 2022 17:54:00 +0200 [thread overview]
Message-ID: <20220628155400.26712-1-pali@kernel.org> (raw)
In-Reply-To: <20220511183727.1834-1-pali@kernel.org>
After more patches code for jumping to _start_cont symbol in flash memory
involved to code with useless mathematical operations. Currently it does:
r3 := CONFIG_SYS_MONITOR_BASE + ABS(_start_cont) - CONFIG_SYS_MONITOR_BASE
jump to r3
Which is equivalent of just:
r3 := ABS(_start_cont)
jump to r3
The purpose of that code is just to jump to _start_code symbol,
independently of program counter. So branch must be done to absolute
address. Trying to write:
ba _start_cont
just cause linker error:
LD u-boot
powerpc-linux-gnuspe-ld.bfd: arch/powerpc/cpu/mpc85xx/start.o: in function `switch_as':
(.bootpg+0x4b8): relocation truncated to fit: R_PPC_ADDR24 against symbol `_start_cont' defined in .text section in arch/powerpc/cpu/mpc85xx/start.o
make: *** [Makefile:1801: u-boot] Error 1
Probably by the fact that absolute address cannot be expressed by 24-bits.
So write the code via mtlr+blr pattern as it was before and load general
purpose register with absolute address of the symbol:
lis r3,_start_cont@h
ori r3,r3,_start_cont@l
mtlr r3
blr
Seems that gcc and gnu ld linker support symbol@h and symbol@l syntax like
number@h and number@l without any problem. And disassembling of compiler
u-boot binary proved that lis+ori instructions are called with numbers
which represent halves of absolute address of _start_cont symbol.
Signed-off-by: Pali Rohár <pali@kernel.org>
---
Changes in v2:
* Rebased on top of next branch, commit d61c11b8c894fad517677dc51ee82d1eade39c01
---
arch/powerpc/cpu/mpc85xx/start.S | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/powerpc/cpu/mpc85xx/start.S b/arch/powerpc/cpu/mpc85xx/start.S
index 5009cbef54a0..8a6340d800c3 100644
--- a/arch/powerpc/cpu/mpc85xx/start.S
+++ b/arch/powerpc/cpu/mpc85xx/start.S
@@ -1126,9 +1126,8 @@ switch_as:
#else
/* Calculate absolute address in FLASH and jump there */
/*--------------------------------------------------------------*/
- lis r3,CONFIG_VAL(SYS_MONITOR_BASE)@h
- ori r3,r3,CONFIG_VAL(SYS_MONITOR_BASE)@l
- addi r3,r3,_start_cont - CONFIG_VAL(SYS_MONITOR_BASE)
+ lis r3,_start_cont@h
+ ori r3,r3,_start_cont@l
mtlr r3
blr
#endif
--
2.20.1
prev parent reply other threads:[~2022-06-28 15:54 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-11 18:37 [PATCH] powerpc: mpc85xx: Simplify jump to _start_cont in flash code Pali Rohár
2022-06-28 15:54 ` Pali Rohár [this message]
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=20220628155400.26712-1-pali@kernel.org \
--to=pali@kernel.org \
--cc=peng.fan@oss.nxp.com \
--cc=priyanka.jain@nxp.com \
--cc=sinan@writeme.com \
--cc=u-boot@lists.denx.de \
--cc=wd@denx.de \
/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