2019-05-27 08:55:01 +02:00
/* SPDX-License-Identifier: GPL-2.0-or-later */
2005-04-16 15:20:36 -07:00
/ *
* Copyright ( C ) P a u l M a c k e r r a s 1 9 9 7 .
*
2014-04-24 09:23:37 +02:00
* Adapted f o r 6 4 b i t L E P o w e r P C b y A n d r e w T a u f e r n e r
2005-04-16 15:20:36 -07:00
* /
2005-08-08 13:24:38 +10:00
# include " p p c _ a s m . h "
2005-04-16 15:20:36 -07:00
2014-04-24 09:23:37 +02:00
RELA = 7
2022-04-06 17:00:38 +10:00
RELASZ = 8
RELAENT = 9
2014-04-24 09:23:37 +02:00
2018-11-27 09:01:54 +11:00
.data
2011-04-12 20:38:55 +00:00
/ * A p r o c e d u r e d e s c r i p t o r u s e d w h e n b o o t i n g t h i s a s a C O F F f i l e .
* When m a k i n g C O F F , t h i s c o m e s f i r s t i n t h e l i n k a n d w e ' r e
* linked a t 0 x50 0 0 0 0 .
* /
2007-06-07 22:21:31 +10:00
.globl _zimage_start_opd
2006-01-14 15:04:06 +11:00
_zimage_start_opd :
2011-04-12 20:38:55 +00:00
.long 0 x5 0 0 0 0 0 , 0 , 0 , 0
2018-11-27 09:01:54 +11:00
.text
b _ z i m a g e _ s t a r t
2011-04-12 20:38:55 +00:00
2014-04-24 09:23:37 +02:00
# ifdef _ _ p o w e r p c64 _ _
.balign 8
2017-03-09 16:42:12 +11:00
p_start : .8byte _ s t a r t
p_etext : .8byte _ e t e x t
p_bss_start : .8byte _ _ b s s _ s t a r t
p_end : .8byte _ e n d
2014-04-24 09:23:37 +02:00
powerpc/toc: Future proof kernel toc
This patch future-proofs the kernel against linker changes that might
put the toc pointer at some location other than .got+0x8000, by
replacing __toc_start+0x8000 with .TOC. throughout. If the kernel's
idea of the toc pointer doesn't agree with the linker, bad things
happen.
prom_init.c code relocating its toc is also changed so that a symbolic
__prom_init_toc_start toc-pointer relative address is calculated
rather than assuming that it is always at toc-pointer - 0x8000. The
length calculations loading values from the toc are also avoided.
It's a little incestuous to do that with unreloc_toc picking up
adjusted values (which is fine in practice, they both adjust by the
same amount if all goes well).
I've also changed the way .got is aligned in vmlinux.lds and
zImage.lds, mostly so that dumping out section info by objdump or
readelf plainly shows the alignment is 256. This linker script
feature was added 2005-09-27, available in FSF binutils releases from
2.17 onwards. Should be safe to use in the kernel, I think.
Finally, put *(.got) before the prom_init.o entry which only needs
*(.toc), so that the GOT header goes in the correct place. I don't
believe this makes any difference for the kernel as it would for
dynamic objects being loaded by ld.so. That change is just to stop
lusers who blindly copy kernel scripts being led astray. Of course,
this change needs the prom_init.c changes.
Some notes on .toc and .got.
.toc is a compiler generated section of addresses. .got is a linker
generated section of addresses, generally built when the linker sees
R_*_*GOT* relocations. In the case of powerpc64 ld.bfd, there are
multiple generated .got sections, one per input object file. So you
can somewhat reasonably write in a linker script an input section
statement like *prom_init.o(.got .toc) to mean "the .got and .toc
section for files matching *prom_init.o". On other architectures that
doesn't make sense, because the linker generally has just one .got
section. Even on powerpc64, note well that the GOT entries for
prom_init.o may be merged with GOT entries from other objects. That
means that if prom_init.o references, say, _end via some GOT
relocation, and some other object also references _end via a GOT
relocation, the GOT entry for _end may be in the range
__prom_init_toc_start to __prom_init_toc_end and if the kernel does
something special to GOT/TOC entries in that range then the value of
_end as seen by objects other than prom_init.o will be affected. On
the other hand the GOT entry for _end may not be in the range
__prom_init_toc_start to __prom_init_toc_end. Which way it turns out
is deterministic but a detail of linker operation that should not be
relied on.
A feature of ld.bfd is that input .toc (and .got) sections matching
one linker input section statement may be sorted, to put entries used
by small-model code first, near the toc base. This is why scripts for
powerpc64 normally use *(.got .toc) rather than *(.got) *(.toc), since
the first form allows more freedom to sort.
Another feature of ld.bfd is that indirect addressing sequences using
the GOT/TOC may be edited by the linker to relative addressing. In
many cases relative addressing would be emitted by gcc for
-mcmodel=medium if you appropriately decorate variable declarations
with non-default visibility.
The original patch is here:
https://lore.kernel.org/linuxppc-dev/20210310034813.GM6042@bubble.grove.modra.org/
Signed-off-by: Alan Modra <amodra@au1.ibm.com>
[aik: removed non-relocatable which is gone in 24d33ac5b8ffb]
[aik: added <=2.24 check]
[aik: because of llvm-as, kernel_toc_addr() uses "mr" instead of global register variable]
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211221055904.555763-2-aik@ozlabs.ru
2021-12-21 16:58:59 +11:00
p_toc : .8byte . T O C . - p _ b a s e
2017-03-09 16:42:12 +11:00
p_dyn : .8byte _ _ d y n a m i c _ s t a r t - p _ b a s e
p_rela : .8byte _ _ r e l a _ d y n _ s t a r t - p _ b a s e
p_prom : .8byte 0
2014-04-24 09:23:37 +02:00
.weak _platform_stack_top
2017-03-09 16:42:12 +11:00
p_pstack : .8byte _ p l a t f o r m _ s t a c k _ t o p
2014-04-24 09:23:37 +02:00
# else
2011-04-12 20:38:55 +00:00
p_start : .long _ s t a r t
p_etext : .long _ e t e x t
p_bss_start : .long _ _ b s s _ s t a r t
p_end : .long _ e n d
.weak _platform_stack_top
p_pstack : .long _ p l a t f o r m _ s t a c k _ t o p
2014-04-24 09:23:37 +02:00
# endif
2006-01-14 15:04:06 +11:00
2018-09-14 13:36:47 +09:30
.weak _zimage_start
2005-10-28 17:46:49 -07:00
_zimage_start :
2007-03-21 09:02:53 -06:00
.globl _zimage_start_lib
_zimage_start_lib :
2006-01-14 15:04:06 +11:00
/ * Work o u t t h e o f f s e t b e t w e e n t h e a d d r e s s w e w e r e l i n k e d a t
and t h e a d d r e s s w h e r e w e ' r e r u n n i n g . * /
2023-04-07 14:09:24 +10:00
bcl 2 0 ,3 1 ,. + 4
2011-04-12 20:38:55 +00:00
p_base : mflr r10 / * r10 n o w p o i n t s t o r u n t i m e a d d r o f p _ b a s e * /
2014-04-24 09:23:37 +02:00
# ifndef _ _ p o w e r p c64 _ _
2011-04-12 20:38:55 +00:00
/* grab the link address of the dynamic section in r11 */
addis r11 ,r10 ,( _ G L O B A L _ O F F S E T _ T A B L E _ - p _ b a s e ) @ha
lwz r11 ,( _ G L O B A L _ O F F S E T _ T A B L E _ - p _ b a s e ) @l(r11)
cmpwi r11 ,0
beq 3 f / * i f n o t l i n k e d - p i e * /
/* get the runtime address of the dynamic section in r12 */
.weak __dynamic_start
addis r12 ,r10 ,( _ _ d y n a m i c _ s t a r t - p _ b a s e ) @ha
addi r12 ,r12 ,( _ _ d y n a m i c _ s t a r t - p _ b a s e ) @l
subf r11 ,r11 ,r12 / * r u n t i m e - l i n k t i m e o f f s e t * /
/ * The d y n a m i c s e c t i o n c o n t a i n s a s e r i e s o f t a g g e d e n t r i e s .
* We n e e d t h e R E L A a n d R E L A C O U N T e n t r i e s . * /
li r9 ,0
li r0 ,0
9 : lwz r8 ,0 ( r12 ) / * g e t t a g * /
cmpwi r8 ,0
beq 1 0 f / * e n d o f l i s t * /
cmpwi r8 ,R E L A
bne 1 1 f
lwz r9 ,4 ( r12 ) / * g e t R E L A p o i n t e r i n r9 * /
b 1 2 f
2022-04-06 17:00:38 +10:00
11 : cmpwi r8 ,R E L A S Z
bne . L c h e c k _ f o r _ r e l a e n t
lwz r0 ,4 ( r12 ) / * g e t R E L A S Z v a l u e i n r0 * /
b 1 2 f
.Lcheck_for_relaent :
cmpwi r8 ,R E L A E N T
2011-04-12 20:38:55 +00:00
bne 1 2 f
2022-04-06 17:00:38 +10:00
lwz r14 ,4 ( r12 ) / * g e t R E L A E N T v a l u e i n r14 * /
2011-04-12 20:38:55 +00:00
12 : addi r12 ,r12 ,8
b 9 b
2005-10-28 17:46:48 -07:00
2011-04-12 20:38:55 +00:00
/ * The r e l o c a t i o n s e c t i o n c o n t a i n s a l i s t o f r e l o c a t i o n s .
* We n o w d o t h e R _ P P C _ R E L A T I V E o n e s , w h i c h p o i n t t o w o r d s
2022-04-06 17:00:38 +10:00
* which n e e d t o b e i n i t i a l i z e d w i t h a d d e n d + o f f s e t * /
2011-04-12 20:38:55 +00:00
10 : /* skip relocation if we don't have both */
cmpwi r0 ,0
2005-11-17 22:09:02 +01:00
beq 3 f
2011-04-12 20:38:55 +00:00
cmpwi r9 ,0
beq 3 f
2022-04-06 17:00:38 +10:00
cmpwi r14 ,0
beq 3 f
2011-04-12 20:38:55 +00:00
add r9 ,r9 ,r11 / * R e l o c a t e R E L A p o i n t e r * /
2022-04-06 17:00:38 +10:00
divwu r0 ,r0 ,r14 / * R E L A S Z / R E L A E N T * /
2011-04-12 20:38:55 +00:00
mtctr r0
2 : lbz r0 ,4 + 3 ( r9 ) / * E L F 3 2 _ R _ I N F O ( r e l o c - > r _ i n f o ) * /
cmpwi r0 ,2 2 / * R _ P P C _ R E L A T I V E * /
2022-04-06 17:00:38 +10:00
bne . L n e x t
2011-04-12 20:38:55 +00:00
lwz r12 ,0 ( r9 ) / * r e l o c - > r _ o f f s e t * /
lwz r0 ,8 ( r9 ) / * r e l o c - > r _ a d d e n d * /
add r0 ,r0 ,r11
stwx r0 ,r11 ,r12
2022-04-06 17:00:38 +10:00
.Lnext : add r9 ,r9 ,r14
2005-11-17 22:09:02 +01:00
bdnz 2 b
2005-10-28 17:46:48 -07:00
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
/* Do a cache flush for our text, in case the loader didn't */
2011-04-12 20:38:55 +00:00
3 : lwz r9 ,p _ s t a r t - p _ b a s e ( r10 ) / * n o t e : t h e s e a r e r e l o c a t e d n o w * /
lwz r8 ,p _ e t e x t - p _ b a s e ( r10 )
2005-11-17 22:09:02 +01:00
4 : dcbf r0 ,r9
2005-04-16 15:20:36 -07:00
icbi r0 ,r9
addi r9 ,r9 ,0 x20
2006-03-04 13:15:40 +01:00
cmplw c r0 ,r9 ,r8
2005-11-17 22:09:02 +01:00
blt 4 b
2005-04-16 15:20:36 -07:00
sync
isync
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
/* Clear the BSS */
2011-04-12 20:38:55 +00:00
lwz r9 ,p _ b s s _ s t a r t - p _ b a s e ( r10 )
lwz r8 ,p _ e n d - p _ b a s e ( r10 )
li r0 ,0
5 : stw r0 ,0 ( r9 )
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
addi r9 ,r9 ,4
cmplw c r0 ,r9 ,r8
blt 5 b
2005-04-16 15:20:36 -07:00
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
/* Possibly set up a custom stack */
2011-04-12 20:38:55 +00:00
lwz r8 ,p _ p s t a c k - p _ b a s e ( r10 )
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
cmpwi r8 ,0
beq 6 f
lwz r1 ,0 ( r8 )
li r0 ,0
stwu r0 ,- 1 6 ( r1 ) / * e s t a b l i s h a s t a c k f r a m e * /
6 :
2014-04-24 09:23:37 +02:00
# else / * _ _ p o w e r p c64 _ _ * /
/* Save the prom pointer at p_prom. */
std r5 ,( p _ p r o m - p _ b a s e ) ( r10 )
/* Set r2 to the TOC. */
ld r2 ,( p _ t o c - p _ b a s e ) ( r10 )
add r2 ,r2 ,r10
/* Grab the link address of the dynamic section in r11. */
ld r11 ,- 3 2 7 6 8 ( r2 )
cmpwi r11 ,0
beq 3 f / * i f n o t l i n k e d - p i e t h e n n o d y n a m i c s e c t i o n * /
ld r11 ,( p _ d y n - p _ b a s e ) ( r10 )
add r11 ,r11 ,r10
ld r9 ,( p _ r e l a - p _ b a s e ) ( r10 )
add r9 ,r9 ,r10
2015-02-11 12:55:44 +08:00
li r13 ,0
2014-04-24 09:23:37 +02:00
li r8 ,0
2015-02-11 12:55:44 +08:00
9 : ld r12 ,0 ( r11 ) / * g e t t a g * /
cmpdi r12 ,0
2014-04-24 09:23:37 +02:00
beq 1 2 f / * e n d o f l i s t * /
2015-02-11 12:55:44 +08:00
cmpdi r12 ,R E L A
2014-04-24 09:23:37 +02:00
bne 1 0 f
2015-02-11 12:55:44 +08:00
ld r13 ,8 ( r11 ) / * g e t R E L A p o i n t e r i n r13 * /
2014-04-24 09:23:37 +02:00
b 1 1 f
2022-04-06 17:00:38 +10:00
10 : cmpwi r12 ,R E L A S Z
bne . L c h e c k _ f o r _ r e l a e n t
lwz r8 ,8 ( r11 ) / * g e t R E L A S Z p o i n t e r i n r8 * /
b 1 1 f
.Lcheck_for_relaent :
cmpwi r12 ,R E L A E N T
bne 1 1 f
lwz r14 ,8 ( r11 ) / * g e t R E L A E N T p o i n t e r i n r14 * /
2014-04-24 09:23:37 +02:00
11 : addi r11 ,r11 ,1 6
b 9 b
12 :
2022-04-06 17:00:38 +10:00
cmpdi r13 ,0 / * c h e c k w e h a v e b o t h R E L A , R E L A S Z , R E L A E N T * /
2014-04-24 09:23:37 +02:00
cmpdi c r1 ,r8 ,0
beq 3 f
beq c r1 ,3 f
2022-04-06 17:00:38 +10:00
cmpdi r14 ,0
beq 3 f
2014-04-24 09:23:37 +02:00
/* Calcuate the runtime offset. */
2015-02-11 12:55:44 +08:00
subf r13 ,r13 ,r9
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
2014-04-24 09:23:37 +02:00
/ * Run t h r o u g h t h e l i s t o f r e l o c a t i o n s a n d p r o c e s s t h e
* R_ P P C 6 4 _ R E L A T I V E o n e s . * /
2022-04-06 17:00:38 +10:00
divdu r8 ,r8 ,r14 / * R E L A S Z / R E L A E N T * /
2014-04-24 09:23:37 +02:00
mtctr r8
13 : ld r0 ,8 ( r9 ) / * E L F 6 4 _ R _ T Y P E ( r e l o c - > r _ i n f o ) * /
cmpdi r0 ,2 2 / * R _ P P C 6 4 _ R E L A T I V E * /
2022-04-06 17:00:38 +10:00
bne . L n e x t
2015-02-11 12:55:44 +08:00
ld r12 ,0 ( r9 ) / * r e l o c - > r _ o f f s e t * /
2014-04-24 09:23:37 +02:00
ld r0 ,1 6 ( r9 ) / * r e l o c - > r _ a d d e n d * /
2015-02-11 12:55:44 +08:00
add r0 ,r0 ,r13
stdx r0 ,r13 ,r12
2022-04-06 17:00:38 +10:00
.Lnext : add r9 ,r9 ,r14
2014-04-24 09:23:37 +02:00
bdnz 1 3 b
/* Do a cache flush for our text, in case the loader didn't */
3 : ld r9 ,p _ s t a r t - p _ b a s e ( r10 ) / * n o t e : t h e s e a r e r e l o c a t e d n o w * /
ld r8 ,p _ e t e x t - p _ b a s e ( r10 )
4 : dcbf r0 ,r9
icbi r0 ,r9
addi r9 ,r9 ,0 x20
cmpld c r0 ,r9 ,r8
blt 4 b
sync
isync
/* Clear the BSS */
ld r9 ,p _ b s s _ s t a r t - p _ b a s e ( r10 )
ld r8 ,p _ e n d - p _ b a s e ( r10 )
li r0 ,0
5 : std r0 ,0 ( r9 )
addi r9 ,r9 ,8
cmpld c r0 ,r9 ,r8
blt 5 b
/* Possibly set up a custom stack */
ld r8 ,p _ p s t a c k - p _ b a s e ( r10 )
cmpdi r8 ,0
beq 6 f
ld r1 ,0 ( r8 )
li r0 ,0
2015-02-11 12:55:44 +08:00
stdu r0 ,- 1 1 2 ( r1 ) / * e s t a b l i s h a s t a c k f r a m e * /
2014-04-24 09:23:37 +02:00
6 :
# endif / * _ _ p o w e r p c64 _ _ * /
[POWERPC] zImage: Cleanup and improve zImage entry point
This patch re-organises the way the zImage wrapper code is entered, to
allow more flexibility on platforms with unusual entry conditions.
After this patch, a platform .o file has two options:
1) It can define a _zimage_start, in which case the platform code gets
control from the very beginning of execution. In this case the
platform code is responsible for relocating the zImage if necessary,
clearing the BSS, performing any platform specific initialization, and
finally calling start() to load and enter the kernel.
2) It can define platform_init(). In this case the generic crt0.S
handles initial entry, and calls platform_init() before calling
start(). The signature of platform_init() is changed, however, to
take up to 5 parameters (in r3..r7) as they come from the platform's
initial loader, instead of a fixed set of parameters based on OF's
usage.
When using the generic crt0.S, the platform .o can optionally
supply a custom stack to use, using the BSS_STACK() macro. If this
is not supplied, the crt0.S will assume that the loader has
supplied a usable stack.
In either case, the platform code communicates information to the
generic code (specifically, a PROM pointer for OF systems, and/or an
initrd image address supplied by the bootloader) via a global
structure "loader_info".
In addition the wrapper script is rearranged to ensure that the
platform .o is always linked first. This means that platforms where
the zImage entry point is at a fixed address or offset, rather than
being encoded in the binary header can be supported using option (1).
Signed-off-by: David Gibson <dwg@au1.ibm.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
2007-03-05 14:24:52 +11:00
/* Call platform_init() */
bl p l a t f o r m _ i n i t
/* Call start */
b s t a r t
2014-04-24 09:23:36 +02:00
# ifdef _ _ p o w e r p c64 _ _
# define P R O M _ F R A M E _ S I Z E 5 1 2
2021-10-22 16:13:22 +10:00
.macro OP_REGS op, w i d t h , s t a r t , e n d , b a s e , o f f s e t
.Lreg = \ start
.rept ( \ end - \ s t a r t + 1 )
\ op . L r e g ,\ o f f s e t + \ w i d t h * . L r e g ( \ b a s e )
.Lreg = .Lreg + 1
.endr
.endm
# define S A V E _ G P R S ( s t a r t , e n d , b a s e ) O P _ R E G S s t d , 8 , s t a r t , e n d , b a s e , 0
# define R E S T _ G P R S ( s t a r t , e n d , b a s e ) O P _ R E G S l d , 8 , s t a r t , e n d , b a s e , 0
# define S A V E _ G P R ( n , b a s e ) S A V E _ G P R S ( n , n , b a s e )
# define R E S T _ G P R ( n , b a s e ) R E S T _ G P R S ( n , n , b a s e )
2014-04-24 09:23:36 +02:00
/ * prom h a n d l e s t h e j u m p i n t o a n d r e t u r n f r o m f i r m w a r e . T h e p r o m a r g s p o i n t e r
is l o a d e d i n r3 . * /
.globl prom
prom :
mflr r0
std r0 ,1 6 ( r1 )
stdu r1 ,- P R O M _ F R A M E _ S I Z E ( r1 ) / * S a v e S P a n d c r e a t e s t a c k s p a c e * /
SAVE_ G P R ( 2 , r1 )
2021-10-22 16:13:22 +10:00
SAVE_ G P R S ( 1 3 , 3 1 , r1 )
2014-04-24 09:23:36 +02:00
mfcr r10
std r10 ,8 * 3 2 ( r1 )
mfmsr r10
std r10 ,8 * 3 3 ( r1 )
/* remove MSR_LE from msr but keep MSR_SF */
mfmsr r10
rldicr r10 ,r10 ,0 ,6 2
mtsrr1 r10
/* Load FW address, set LR to label 1, and jump to FW */
2023-04-07 14:09:24 +10:00
bcl 2 0 ,3 1 ,0 f
2014-04-24 09:23:36 +02:00
0 : mflr r10
addi r11 ,r10 ,( 1 f - 0 b )
mtlr r11
ld r10 ,( p _ p r o m - 0 b ) ( r10 )
mtsrr0 r10
rfid
1 : /* Return from OF */
2014-04-24 09:23:39 +02:00
FIXUP_ E N D I A N
2014-04-24 09:23:36 +02:00
/* Restore registers and return. */
rldicl r1 ,r1 ,0 ,3 2
/* Restore the MSR (back to 64 bits) */
ld r10 ,8 * ( 3 3 ) ( r1 )
mtmsr r10
isync
/* Restore other registers */
REST_ G P R ( 2 , r1 )
2021-10-22 16:13:22 +10:00
REST_ G P R S ( 1 3 , 3 1 , r1 )
2014-04-24 09:23:36 +02:00
ld r10 ,8 * 3 2 ( r1 )
mtcr r10
addi r1 ,r1 ,P R O M _ F R A M E _ S I Z E
ld r0 ,1 6 ( r1 )
mtlr r0
blr
# endif