Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) Paul Mackerras 1997. | |
3 | * | |
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. | |
8 | * | |
9 | * NOTE: this code runs in 32 bit mode and is packaged as ELF32. | |
10 | */ | |
11 | ||
decd300b | 12 | #include "ppc_asm.h" |
1da177e4 LT |
13 | |
14 | .text | |
66a45dd3 PM |
15 | /* a procedure descriptor used when booting this as a COFF file */ |
16 | _zimage_start_opd: | |
17 | .long _zimage_start, 0, 0, 0 | |
18 | ||
cd197ffc | 19 | .weak _zimage_start |
67a1b682 OH |
20 | .globl _zimage_start |
21 | _zimage_start: | |
160cc3ec MM |
22 | .globl _zimage_start_lib |
23 | _zimage_start_lib: | |
66a45dd3 PM |
24 | /* Work out the offset between the address we were linked at |
25 | and the address where we're running. */ | |
68643cfb | 26 | bl 1f |
66a45dd3 | 27 | 1: mflr r0 |
68643cfb OH |
28 | lis r9,1b@ha |
29 | addi r9,r9,1b@l | |
a4497235 | 30 | subf. r0,r9,r0 |
66a45dd3 | 31 | beq 3f /* if running at same address as linked */ |
a4497235 | 32 | |
66a45dd3 PM |
33 | /* The .got2 section contains a list of addresses, so add |
34 | the address offset onto each entry. */ | |
a4497235 OH |
35 | lis r9,__got2_start@ha |
36 | addi r9,r9,__got2_start@l | |
37 | lis r8,__got2_end@ha | |
38 | addi r8,r8,__got2_end@l | |
39 | subf. r8,r9,r8 | |
68643cfb | 40 | beq 3f |
a4497235 OH |
41 | srwi. r8,r8,2 |
42 | mtctr r8 | |
43 | add r9,r0,r9 | |
66a45dd3 | 44 | 2: lwz r8,0(r9) |
a4497235 OH |
45 | add r8,r8,r0 |
46 | stw r8,0(r9) | |
47 | addi r9,r9,4 | |
68643cfb | 48 | bdnz 2b |
a4497235 | 49 | |
cd197ffc | 50 | /* Do a cache flush for our text, in case the loader didn't */ |
eacb1962 OH |
51 | 3: lis r9,_start@ha |
52 | addi r9,r9,_start@l | |
a4497235 | 53 | add r9,r0,r9 |
1da177e4 LT |
54 | lis r8,_etext@ha |
55 | addi r8,r8,_etext@l | |
a4497235 | 56 | add r8,r0,r8 |
68643cfb | 57 | 4: dcbf r0,r9 |
1da177e4 LT |
58 | icbi r0,r9 |
59 | addi r9,r9,0x20 | |
eacb1962 | 60 | cmplw cr0,r9,r8 |
68643cfb | 61 | blt 4b |
1da177e4 LT |
62 | sync |
63 | isync | |
64 | ||
cd197ffc DG |
65 | /* Clear the BSS */ |
66 | lis r9,__bss_start@ha | |
67 | addi r9,r9,__bss_start@l | |
f4bdbfc4 | 68 | add r9,r0,r9 |
cd197ffc DG |
69 | lis r8,_end@ha |
70 | addi r8,r8,_end@l | |
f4bdbfc4 MM |
71 | add r8,r0,r8 |
72 | li r10,0 | |
73 | 5: stw r10,0(r9) | |
cd197ffc DG |
74 | addi r9,r9,4 |
75 | cmplw cr0,r9,r8 | |
76 | blt 5b | |
1da177e4 | 77 | |
cd197ffc DG |
78 | /* Possibly set up a custom stack */ |
79 | .weak _platform_stack_top | |
80 | lis r8,_platform_stack_top@ha | |
81 | addi r8,r8,_platform_stack_top@l | |
82 | cmpwi r8,0 | |
83 | beq 6f | |
f4bdbfc4 | 84 | add r8,r0,r8 |
cd197ffc | 85 | lwz r1,0(r8) |
f4bdbfc4 | 86 | add r1,r0,r1 |
cd197ffc DG |
87 | li r0,0 |
88 | stwu r0,-16(r1) /* establish a stack frame */ | |
89 | 6: | |
90 | ||
91 | /* Call platform_init() */ | |
92 | bl platform_init | |
93 | ||
94 | /* Call start */ | |
cd197ffc | 95 | b start |