blob: 25ad7453531aaea8526dd8f950bdbd64e10d75ec [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 */
16_zimage_start_opd:
17 .long _zimage_start, 0, 0, 0
18
David Gibsoncd197ff2007-03-05 14:24:52 +110019 .weak _zimage_start
Olaf Hering67a1b682005-10-28 17:46:49 -070020 .globl _zimage_start
21_zimage_start:
Milton Miller160cc3e2007-03-21 09:02:53 -060022 .globl _zimage_start_lib
23_zimage_start_lib:
Paul Mackerras66a45dd2006-01-14 15:04:06 +110024 /* Work out the offset between the address we were linked at
25 and the address where we're running. */
Olaf Hering68643cf2005-11-17 22:09:02 +010026 bl 1f
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100271: mflr r0
Olaf Hering68643cf2005-11-17 22:09:02 +010028 lis r9,1b@ha
29 addi r9,r9,1b@l
Olaf Heringa4497232005-10-28 17:46:48 -070030 subf. r0,r9,r0
Paul Mackerras66a45dd2006-01-14 15:04:06 +110031 beq 3f /* if running at same address as linked */
Olaf Heringa4497232005-10-28 17:46:48 -070032
Paul Mackerras66a45dd2006-01-14 15:04:06 +110033 /* The .got2 section contains a list of addresses, so add
34 the address offset onto each entry. */
Olaf Heringa4497232005-10-28 17:46:48 -070035 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
Olaf Hering68643cf2005-11-17 22:09:02 +010040 beq 3f
Olaf Heringa4497232005-10-28 17:46:48 -070041 srwi. r8,r8,2
42 mtctr r8
43 add r9,r0,r9
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100442: lwz r8,0(r9)
Olaf Heringa4497232005-10-28 17:46:48 -070045 add r8,r8,r0
46 stw r8,0(r9)
47 addi r9,r9,4
Olaf Hering68643cf2005-11-17 22:09:02 +010048 bdnz 2b
Olaf Heringa4497232005-10-28 17:46:48 -070049
David Gibsoncd197ff2007-03-05 14:24:52 +110050 /* Do a cache flush for our text, in case the loader didn't */
Olaf Heringeacb1962006-03-04 13:15:40 +0100513: lis r9,_start@ha
52 addi r9,r9,_start@l
Olaf Heringa4497232005-10-28 17:46:48 -070053 add r9,r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 lis r8,_etext@ha
55 addi r8,r8,_etext@l
Olaf Heringa4497232005-10-28 17:46:48 -070056 add r8,r0,r8
Olaf Hering68643cf2005-11-17 22:09:02 +0100574: dcbf r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 icbi r0,r9
59 addi r9,r9,0x20
Olaf Heringeacb1962006-03-04 13:15:40 +010060 cmplw cr0,r9,r8
Olaf Hering68643cf2005-11-17 22:09:02 +010061 blt 4b
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 sync
63 isync
64
David Gibsoncd197ff2007-03-05 14:24:52 +110065 /* Clear the BSS */
66 lis r9,__bss_start@ha
67 addi r9,r9,__bss_start@l
68 lis r8,_end@ha
69 addi r8,r8,_end@l
70 li r0,0
715: stw r0,0(r9)
72 addi r9,r9,4
73 cmplw cr0,r9,r8
74 blt 5b
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
David Gibsoncd197ff2007-03-05 14:24:52 +110076 /* Possibly set up a custom stack */
77.weak _platform_stack_top
78 lis r8,_platform_stack_top@ha
79 addi r8,r8,_platform_stack_top@l
80 cmpwi r8,0
81 beq 6f
82 lwz r1,0(r8)
83 li r0,0
84 stwu r0,-16(r1) /* establish a stack frame */
856:
86
87 /* Call platform_init() */
88 bl platform_init
89
90 /* Call start */
91 mr r3,r1
92 b start