blob: e0192c26037b918f1e195d41d2f5ec9176606535 [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
Olaf Hering67a1b682005-10-28 17:46:49 -070019 .globl _zimage_start
20_zimage_start:
Paul Mackerras66a45dd2006-01-14 15:04:06 +110021 /* Work out the offset between the address we were linked at
22 and the address where we're running. */
Olaf Hering68643cf2005-11-17 22:09:02 +010023 bl 1f
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100241: mflr r0
Olaf Hering68643cf2005-11-17 22:09:02 +010025 lis r9,1b@ha
26 addi r9,r9,1b@l
Olaf Heringa4497232005-10-28 17:46:48 -070027 subf. r0,r9,r0
Paul Mackerras66a45dd2006-01-14 15:04:06 +110028 beq 3f /* if running at same address as linked */
Olaf Heringa4497232005-10-28 17:46:48 -070029
Paul Mackerras66a45dd2006-01-14 15:04:06 +110030 /* The .got2 section contains a list of addresses, so add
31 the address offset onto each entry. */
Olaf Heringa4497232005-10-28 17:46:48 -070032 lis r9,__got2_start@ha
33 addi r9,r9,__got2_start@l
34 lis r8,__got2_end@ha
35 addi r8,r8,__got2_end@l
36 subf. r8,r9,r8
Olaf Hering68643cf2005-11-17 22:09:02 +010037 beq 3f
Olaf Heringa4497232005-10-28 17:46:48 -070038 srwi. r8,r8,2
39 mtctr r8
40 add r9,r0,r9
Paul Mackerras66a45dd2006-01-14 15:04:06 +1100412: lwz r8,0(r9)
Olaf Heringa4497232005-10-28 17:46:48 -070042 add r8,r8,r0
43 stw r8,0(r9)
44 addi r9,r9,4
Olaf Hering68643cf2005-11-17 22:09:02 +010045 bdnz 2b
Olaf Heringa4497232005-10-28 17:46:48 -070046
Paul Mackerras66a45dd2006-01-14 15:04:06 +110047 /* Do a cache flush for our text, in case OF didn't */
483: lis r9,_start@h
Olaf Heringa4497232005-10-28 17:46:48 -070049 add r9,r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 lis r8,_etext@ha
51 addi r8,r8,_etext@l
Olaf Heringa4497232005-10-28 17:46:48 -070052 add r8,r0,r8
Olaf Hering68643cf2005-11-17 22:09:02 +0100534: dcbf r0,r9
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 icbi r0,r9
55 addi r9,r9,0x20
56 cmplwi 0,r9,8
Olaf Hering68643cf2005-11-17 22:09:02 +010057 blt 4b
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 sync
59 isync
60
Olaf Hering7e658112005-10-28 17:46:50 -070061 mr r6,r1
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 b start
63