blob: f1c4dfc635be20380d6a718d420cb83b6e4a6068 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Olaf Heringdecd3002005-08-08 13:24:38 +100012#include "ppc_asm.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14 .text
Paul Mackerras66a45dd2006-01-14 15:04:06 +110015 /* a procedure descriptor used when booting this as a COFF file */
Paul Mackerrasf40e5242007-06-07 22:21:31 +100016 .globl _zimage_start_opd
Paul Mackerras66a45dd2006-01-14 15:04:06 +110017_zimage_start_opd:
18 .long _zimage_start, 0, 0, 0
19
David Gibsoncd197ff2007-03-05 14:24:52 +110020 .weak _zimage_start
Olaf Hering67a1b682005-10-28 17:46:49 -070021 .globl _zimage_start
22_zimage_start:
Milton Miller160cc3e2007-03-21 09:02:53 -060023 .globl _zimage_start_lib
24_zimage_start_lib:
Paul Mackerras66a45dd2006-01-14 15:04:06 +110025 /* Work out the offset between the address we were linked at
26 and the address where we're running. */
Olaf Hering68643cf2005-11-17 22:09:02 +010027 bl 1f
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100281: mflr r0
Olaf Hering68643cf2005-11-17 22:09:02 +010029 lis r9,1b@ha
30 addi r9,r9,1b@l
Olaf Heringa4497232005-10-28 17:46:48 -070031 subf. r0,r9,r0
Paul Mackerras66a45dd2006-01-14 15:04:06 +110032 beq 3f /* if running at same address as linked */
Olaf Heringa4497232005-10-28 17:46:48 -070033
Paul Mackerras66a45dd2006-01-14 15:04:06 +110034 /* The .got2 section contains a list of addresses, so add
35 the address offset onto each entry. */
Olaf Heringa4497232005-10-28 17:46:48 -070036 lis r9,__got2_start@ha
37 addi r9,r9,__got2_start@l
38 lis r8,__got2_end@ha
39 addi r8,r8,__got2_end@l
40 subf. r8,r9,r8
Olaf Hering68643cf2005-11-17 22:09:02 +010041 beq 3f
Olaf Heringa4497232005-10-28 17:46:48 -070042 srwi. r8,r8,2
43 mtctr r8
44 add r9,r0,r9
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100452: lwz r8,0(r9)
Olaf Heringa4497232005-10-28 17:46:48 -070046 add r8,r8,r0
47 stw r8,0(r9)
48 addi r9,r9,4
Olaf Hering68643cf2005-11-17 22:09:02 +010049 bdnz 2b
Olaf Heringa4497232005-10-28 17:46:48 -070050
David Gibsoncd197ff2007-03-05 14:24:52 +110051 /* Do a cache flush for our text, in case the loader didn't */
Olaf Heringeacb1962006-03-04 13:15:40 +0100523: lis r9,_start@ha
53 addi r9,r9,_start@l
Olaf Heringa4497232005-10-28 17:46:48 -070054 add r9,r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 lis r8,_etext@ha
56 addi r8,r8,_etext@l
Olaf Heringa4497232005-10-28 17:46:48 -070057 add r8,r0,r8
Olaf Hering68643cf2005-11-17 22:09:02 +0100584: dcbf r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 icbi r0,r9
60 addi r9,r9,0x20
Olaf Heringeacb1962006-03-04 13:15:40 +010061 cmplw cr0,r9,r8
Olaf Hering68643cf2005-11-17 22:09:02 +010062 blt 4b
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 sync
64 isync
65
David Gibsoncd197ff2007-03-05 14:24:52 +110066 /* Clear the BSS */
67 lis r9,__bss_start@ha
68 addi r9,r9,__bss_start@l
Milton Millerf4bdbfc2007-03-28 02:21:02 -060069 add r9,r0,r9
David Gibsoncd197ff2007-03-05 14:24:52 +110070 lis r8,_end@ha
71 addi r8,r8,_end@l
Milton Millerf4bdbfc2007-03-28 02:21:02 -060072 add r8,r0,r8
73 li r10,0
745: stw r10,0(r9)
David Gibsoncd197ff2007-03-05 14:24:52 +110075 addi r9,r9,4
76 cmplw cr0,r9,r8
77 blt 5b
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
David Gibsoncd197ff2007-03-05 14:24:52 +110079 /* Possibly set up a custom stack */
80.weak _platform_stack_top
81 lis r8,_platform_stack_top@ha
82 addi r8,r8,_platform_stack_top@l
83 cmpwi r8,0
84 beq 6f
Milton Millerf4bdbfc2007-03-28 02:21:02 -060085 add r8,r0,r8
David Gibsoncd197ff2007-03-05 14:24:52 +110086 lwz r1,0(r8)
Milton Millerf4bdbfc2007-03-28 02:21:02 -060087 add r1,r0,r1
David Gibsoncd197ff2007-03-05 14:24:52 +110088 li r0,0
89 stwu r0,-16(r1) /* establish a stack frame */
906:
91
92 /* Call platform_init() */
93 bl platform_init
94
95 /* Call start */
David Gibsoncd197ff2007-03-05 14:24:52 +110096 b start