Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Olaf Hering | decd300 | 2005-08-08 13:24:38 +1000 | [diff] [blame] | 12 | #include "ppc_asm.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | .text |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 15 | /* a procedure descriptor used when booting this as a COFF file */ |
| 16 | _zimage_start_opd: |
| 17 | .long _zimage_start, 0, 0, 0 |
| 18 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 19 | .weak _zimage_start |
Olaf Hering | 67a1b68 | 2005-10-28 17:46:49 -0700 | [diff] [blame] | 20 | .globl _zimage_start |
| 21 | _zimage_start: |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 22 | /* Work out the offset between the address we were linked at |
| 23 | and the address where we're running. */ |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 24 | bl 1f |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 25 | 1: mflr r0 |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 26 | lis r9,1b@ha |
| 27 | addi r9,r9,1b@l |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 28 | subf. r0,r9,r0 |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 29 | beq 3f /* if running at same address as linked */ |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 30 | |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 31 | /* The .got2 section contains a list of addresses, so add |
| 32 | the address offset onto each entry. */ |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 33 | lis r9,__got2_start@ha |
| 34 | addi r9,r9,__got2_start@l |
| 35 | lis r8,__got2_end@ha |
| 36 | addi r8,r8,__got2_end@l |
| 37 | subf. r8,r9,r8 |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 38 | beq 3f |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 39 | srwi. r8,r8,2 |
| 40 | mtctr r8 |
| 41 | add r9,r0,r9 |
Paul Mackerras | 66a45dd | 2006-01-14 15:04:06 +1100 | [diff] [blame] | 42 | 2: lwz r8,0(r9) |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 43 | add r8,r8,r0 |
| 44 | stw r8,0(r9) |
| 45 | addi r9,r9,4 |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 46 | bdnz 2b |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 47 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 48 | /* Do a cache flush for our text, in case the loader didn't */ |
Olaf Hering | eacb196 | 2006-03-04 13:15:40 +0100 | [diff] [blame] | 49 | 3: lis r9,_start@ha |
| 50 | addi r9,r9,_start@l |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 51 | add r9,r0,r9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | lis r8,_etext@ha |
| 53 | addi r8,r8,_etext@l |
Olaf Hering | a449723 | 2005-10-28 17:46:48 -0700 | [diff] [blame] | 54 | add r8,r0,r8 |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 55 | 4: dcbf r0,r9 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | icbi r0,r9 |
| 57 | addi r9,r9,0x20 |
Olaf Hering | eacb196 | 2006-03-04 13:15:40 +0100 | [diff] [blame] | 58 | cmplw cr0,r9,r8 |
Olaf Hering | 68643cf | 2005-11-17 22:09:02 +0100 | [diff] [blame] | 59 | blt 4b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | sync |
| 61 | isync |
| 62 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 63 | /* Clear the BSS */ |
| 64 | lis r9,__bss_start@ha |
| 65 | addi r9,r9,__bss_start@l |
| 66 | lis r8,_end@ha |
| 67 | addi r8,r8,_end@l |
| 68 | li r0,0 |
| 69 | 5: stw r0,0(r9) |
| 70 | addi r9,r9,4 |
| 71 | cmplw cr0,r9,r8 |
| 72 | blt 5b |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
David Gibson | cd197ff | 2007-03-05 14:24:52 +1100 | [diff] [blame] | 74 | /* Possibly set up a custom stack */ |
| 75 | .weak _platform_stack_top |
| 76 | lis r8,_platform_stack_top@ha |
| 77 | addi r8,r8,_platform_stack_top@l |
| 78 | cmpwi r8,0 |
| 79 | beq 6f |
| 80 | lwz r1,0(r8) |
| 81 | li r0,0 |
| 82 | stwu r0,-16(r1) /* establish a stack frame */ |
| 83 | 6: |
| 84 | |
| 85 | /* Call platform_init() */ |
| 86 | bl platform_init |
| 87 | |
| 88 | /* Call start */ |
| 89 | mr r3,r1 |
| 90 | b start |