David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Early initialization code for ARMv7 architecture. |
| 3 | * |
| 4 | * This file is based off of the OMAP3530/ARM Cortex start.S file from Das |
| 5 | * U-Boot, which itself got the file from armboot. |
| 6 | * |
| 7 | * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> |
| 8 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 9 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
| 10 | * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> |
| 11 | * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> |
| 12 | * Copyright (c) 2003 Kshitij <kshitij@ti.com> |
| 13 | * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> |
| 14 | * Copyright (c) 2013 The Chromium OS Authors |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
Ronald G. Minnich | 6a01563 | 2013-01-11 15:07:50 -0800 | [diff] [blame] | 18 | * published by the Free Software Foundation; version 2 of |
| 19 | * the License. |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Paul Menzel | a8ae1c6 | 2013-02-20 13:21:20 +0100 | [diff] [blame] | 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 24 | * GNU General Public License for more details. |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 25 | */ |
| 26 | |
Julius Werner | 64b9ca9 | 2013-12-12 20:24:48 -0800 | [diff] [blame] | 27 | #include <arch/asm.h> |
| 28 | |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 29 | .arm |
Vadim Bendebury | be7124e | 2015-03-02 11:33:13 -0800 | [diff] [blame] | 30 | /* |
| 31 | * Just in case the maskrom or the vendor basic firmware passes on a |
| 32 | * parameter when calling the bootblock, store it here for handling by C |
| 33 | * code. |
| 34 | */ |
| 35 | .section .bss, "aw" @nobits |
| 36 | .global maskrom_param |
| 37 | maskrom_param: |
| 38 | .word 0 |
| 39 | |
Julius Werner | 64b9ca9 | 2013-12-12 20:24:48 -0800 | [diff] [blame] | 40 | ENTRY(_start) |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 41 | /* |
Julius Werner | 985ff36 | 2013-09-18 14:39:50 -0700 | [diff] [blame] | 42 | * Set the cpu to System mode with IRQ and FIQ disabled. Prefetch/Data |
| 43 | * aborts may happen early and crash before the abort handlers are |
| 44 | * installed, but at least the problem will show up near the code that |
| 45 | * causes it. |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 46 | */ |
Julius Werner | 985ff36 | 2013-09-18 14:39:50 -0700 | [diff] [blame] | 47 | msr cpsr_cxf, #0xdf |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 48 | bl _thumb_start |
| 49 | ENDPROC(_start) |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 50 | |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 51 | .thumb |
| 52 | ENTRY(_thumb_start) |
Vadim Bendebury | be7124e | 2015-03-02 11:33:13 -0800 | [diff] [blame] | 53 | |
| 54 | /* Preserve the maskrom passed value, if any */ |
| 55 | mov r10, r0 |
| 56 | |
Julius Werner | fd9defc | 2014-01-21 20:11:22 -0800 | [diff] [blame] | 57 | bl arm_init_caches |
| 58 | |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 59 | /* |
| 60 | * From Cortex-A Series Programmer's Guide: |
| 61 | * Only CPU 0 performs initialization. Other CPUs go into WFI |
| 62 | * to do this, first work out which CPU this is |
| 63 | * this code typically is run before any other initialization step |
| 64 | */ |
| 65 | mrc p15, 0, r1, c0, c0, 5 @ Read Multiprocessor Affinity Register |
| 66 | and r1, r1, #0x3 @ Extract CPU ID bits |
| 67 | cmp r1, #0 |
| 68 | bne wait_for_interrupt @ If this is not core0, wait |
| 69 | |
David Hendricks | b313e90 | 2013-02-15 17:50:20 -0800 | [diff] [blame] | 70 | /* |
| 71 | * Initialize the stack to a known value. This is used to check for |
| 72 | * stack overflow later in the boot process. |
| 73 | */ |
Julius Werner | ec5e5e0 | 2014-08-20 15:29:56 -0700 | [diff] [blame] | 74 | ldr r0, =_stack |
| 75 | ldr r1, =_estack |
David Hendricks | b313e90 | 2013-02-15 17:50:20 -0800 | [diff] [blame] | 76 | ldr r2, =0xdeadbeef |
| 77 | init_stack_loop: |
| 78 | str r2, [r0] |
| 79 | add r0, #4 |
| 80 | cmp r0, r1 |
| 81 | bne init_stack_loop |
| 82 | |
Ronald G. Minnich | 6a01563 | 2013-01-11 15:07:50 -0800 | [diff] [blame] | 83 | call_bootblock: |
Vadim Bendebury | be7124e | 2015-03-02 11:33:13 -0800 | [diff] [blame] | 84 | |
| 85 | /* Restore parameter passed in by maskrom/vendor firmware. */ |
| 86 | ldr r0, =maskrom_param |
| 87 | str r10, [r0] |
| 88 | |
| 89 | /* Set stackpointer in internal RAM to call bootblock main() */ |
| 90 | ldr sp, =_estack |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 91 | ldr r0,=0x00000000 |
Ronald G. Minnich | d6b16f5 | 2013-08-16 15:57:56 -0700 | [diff] [blame] | 92 | /* |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 93 | * The current design of cpu_info places the struct at the top of the |
| 94 | * stack. Free enough space to accomodate for that, but make sure it's |
| 95 | * 8-byte aligned for ABI compliance. |
Ronald G. Minnich | d6b16f5 | 2013-08-16 15:57:56 -0700 | [diff] [blame] | 96 | */ |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 97 | sub sp, sp, #16 |
Ronald G. Minnich | 6a01563 | 2013-01-11 15:07:50 -0800 | [diff] [blame] | 98 | bl main |
David Hendricks | 8583ac3 | 2012-12-27 15:23:57 -0800 | [diff] [blame] | 99 | |
| 100 | wait_for_interrupt: |
| 101 | wfi |
| 102 | mov pc, lr @ back to my caller |
Julius Werner | 25a282d | 2014-01-13 13:24:30 -0800 | [diff] [blame] | 103 | ENDPROC(_thumb_start) |