Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* Copyright (c) 1997 Paul Mackerras <paulus@cs.anu.edu.au> |
| 2 | * Initial Power Macintosh COFF version. |
| 3 | * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> |
| 4 | * Modifications for IBM PowerPC 400-class processor evaluation |
| 5 | * boards. |
| 6 | * |
| 7 | * Module name: crt0.S |
| 8 | * |
| 9 | * Description: |
| 10 | * Boot loader execution entry point. Clears out .bss section as per |
| 11 | * ANSI C requirements. Invalidates and flushes the caches over the |
| 12 | * range covered by the boot loader's .text section. Sets up a stack |
| 13 | * below the .text section entry point. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/ppc_asm.h> |
| 22 | |
| 23 | .text |
| 24 | |
| 25 | .globl _start |
| 26 | _start: |
| 27 | #ifdef XCOFF |
| 28 | .long __start,0,0 |
| 29 | |
| 30 | .globl __start |
| 31 | __start: |
| 32 | #endif |
| 33 | |
| 34 | ## Flush and invalidate the caches for the range in memory covering |
| 35 | ## the .text section of the boot loader |
| 36 | |
| 37 | lis r9,_start@h # r9 = &_start |
| 38 | lis r8,_etext@ha # |
| 39 | addi r8,r8,_etext@l # r8 = &_etext |
| 40 | 3: dcbf r0,r9 # Flush the data cache |
| 41 | icbi r0,r9 # Invalidate the instruction cache |
| 42 | addi r9,r9,0x10 # Increment by one cache line |
| 43 | cmplw cr0,r9,r8 # Are we at the end yet? |
| 44 | blt 3b # No, keep flushing and invalidating |
| 45 | sync # sync ; isync after flushing the icache |
| 46 | isync |
| 47 | |
| 48 | ## Clear out the BSS as per ANSI C requirements |
| 49 | |
| 50 | lis r7,_end@ha |
| 51 | addi r7,r7,_end@l # r7 = &_end |
| 52 | lis r8,__bss_start@ha # |
| 53 | addi r8,r8,__bss_start@l # r8 = &_bss_start |
| 54 | |
| 55 | ## Determine how large an area, in number of words, to clear |
| 56 | |
| 57 | subf r7,r8,r7 # r7 = &_end - &_bss_start + 1 |
| 58 | addi r7,r7,3 # r7 += 3 |
| 59 | srwi. r7,r7,2 # r7 = size in words. |
| 60 | beq 2f # If the size is zero, do not bother |
| 61 | addi r8,r8,-4 # r8 -= 4 |
| 62 | mtctr r7 # SPRN_CTR = number of words to clear |
| 63 | li r0,0 # r0 = 0 |
| 64 | 1: stwu r0,4(r8) # Clear out a word |
| 65 | bdnz 1b # If we are not done yet, keep clearing |
| 66 | 2: |
| 67 | |
| 68 | #ifdef CONFIG_40x |
| 69 | ## Set up the stack |
| 70 | |
| 71 | lis r9,_start@h # r9 = &_start (text section entry) |
| 72 | ori r9,r9,_start@l |
| 73 | subi r1,r9,64 # Start the stack 64 bytes below _start |
| 74 | clrrwi r1,r1,4 # Make sure it is aligned on 16 bytes. |
| 75 | li r0,0 |
| 76 | stwu r0,-16(r1) |
| 77 | mtlr r9 |
| 78 | #endif |
| 79 | |
| 80 | b start # All done, start the real work. |