2
* Copyright (C) Paul Mackerras 1997.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version
7
* 2 of the License, or (at your option) any later version.
9
* NOTE: this code runs in 32 bit mode, is position-independent,
10
* and is packaged as ELF32.
16
/* A procedure descriptor used when booting this as a COFF file.
17
* When making COFF, this comes first in the link and we're
20
.globl _zimage_start_opd
22
.long 0x500000, 0, 0, 0
26
p_bss_start: .long __bss_start
29
.weak _platform_stack_top
30
p_pstack: .long _platform_stack_top
35
.globl _zimage_start_lib
37
/* Work out the offset between the address we were linked at
38
and the address where we're running. */
40
p_base: mflr r10 /* r10 now points to runtime addr of p_base */
41
/* grab the link address of the dynamic section in r11 */
42
addis r11,r10,(_GLOBAL_OFFSET_TABLE_-p_base)@ha
43
lwz r11,(_GLOBAL_OFFSET_TABLE_-p_base)@l(r11)
45
beq 3f /* if not linked -pie */
46
/* get the runtime address of the dynamic section in r12 */
48
addis r12,r10,(__dynamic_start-p_base)@ha
49
addi r12,r12,(__dynamic_start-p_base)@l
50
subf r11,r11,r12 /* runtime - linktime offset */
52
/* The dynamic section contains a series of tagged entries.
53
* We need the RELA and RELACOUNT entries. */
55
RELACOUNT = 0x6ffffff9
58
9: lwz r8,0(r12) /* get tag */
60
beq 10f /* end of list */
63
lwz r9,4(r12) /* get RELA pointer in r9 */
65
11: addis r8,r8,(-RELACOUNT)@ha
68
lwz r0,4(r12) /* get RELACOUNT value in r0 */
72
/* The relocation section contains a list of relocations.
73
* We now do the R_PPC_RELATIVE ones, which point to words
74
* which need to be initialized with addend + offset.
75
* The R_PPC_RELATIVE ones come first and there are RELACOUNT
77
10: /* skip relocation if we don't have both */
83
add r9,r9,r11 /* Relocate RELA pointer */
85
2: lbz r0,4+3(r9) /* ELF32_R_INFO(reloc->r_info) */
86
cmpwi r0,22 /* R_PPC_RELATIVE */
88
lwz r12,0(r9) /* reloc->r_offset */
89
lwz r0,8(r9) /* reloc->r_addend */
95
/* Do a cache flush for our text, in case the loader didn't */
96
3: lwz r9,p_start-p_base(r10) /* note: these are relocated now */
97
lwz r8,p_etext-p_base(r10)
107
lwz r9,p_bss_start-p_base(r10)
108
lwz r8,p_end-p_base(r10)
115
/* Possibly set up a custom stack */
116
lwz r8,p_pstack-p_base(r10)
121
stwu r0,-16(r1) /* establish a stack frame */
124
/* Call platform_init() */