1f56348afSSteve Sakoman/* 2f56348afSSteve Sakoman * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core 3f56348afSSteve Sakoman * 4f56348afSSteve Sakoman * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> 5f56348afSSteve Sakoman * 6f56348afSSteve Sakoman * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> 7f56348afSSteve Sakoman * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> 8f56348afSSteve Sakoman * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> 9f56348afSSteve Sakoman * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> 10f56348afSSteve Sakoman * Copyright (c) 2003 Kshitij <kshitij@ti.com> 11f56348afSSteve Sakoman * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> 12f56348afSSteve Sakoman * 13f56348afSSteve Sakoman * See file CREDITS for list of people who contributed to this 14f56348afSSteve Sakoman * project. 15f56348afSSteve Sakoman * 16f56348afSSteve Sakoman * This program is free software; you can redistribute it and/or 17f56348afSSteve Sakoman * modify it under the terms of the GNU General Public License as 18f56348afSSteve Sakoman * published by the Free Software Foundation; either version 2 of 19f56348afSSteve Sakoman * the License, or (at your option) any later version. 20f56348afSSteve Sakoman * 21f56348afSSteve Sakoman * This program is distributed in the hope that it will be useful, 22f56348afSSteve Sakoman * but WITHOUT ANY WARRANTY; without even the implied warranty of 23f56348afSSteve Sakoman * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24f56348afSSteve Sakoman * GNU General Public License for more details. 25f56348afSSteve Sakoman * 26f56348afSSteve Sakoman * You should have received a copy of the GNU General Public License 27f56348afSSteve Sakoman * along with this program; if not, write to the Free Software 28f56348afSSteve Sakoman * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 29f56348afSSteve Sakoman * MA 02111-1307 USA 30f56348afSSteve Sakoman */ 31f56348afSSteve Sakoman 3225ddd1fbSWolfgang Denk#include <asm-offsets.h> 33f56348afSSteve Sakoman#include <config.h> 34f56348afSSteve Sakoman#include <version.h> 35f56348afSSteve Sakoman 36f56348afSSteve Sakoman.globl _start 37f56348afSSteve Sakoman_start: b reset 38f56348afSSteve Sakoman ldr pc, _undefined_instruction 39f56348afSSteve Sakoman ldr pc, _software_interrupt 40f56348afSSteve Sakoman ldr pc, _prefetch_abort 41f56348afSSteve Sakoman ldr pc, _data_abort 42f56348afSSteve Sakoman ldr pc, _not_used 43f56348afSSteve Sakoman ldr pc, _irq 44f56348afSSteve Sakoman ldr pc, _fiq 45f56348afSSteve Sakoman 46f56348afSSteve Sakoman_undefined_instruction: .word undefined_instruction 47f56348afSSteve Sakoman_software_interrupt: .word software_interrupt 48f56348afSSteve Sakoman_prefetch_abort: .word prefetch_abort 49f56348afSSteve Sakoman_data_abort: .word data_abort 50f56348afSSteve Sakoman_not_used: .word not_used 51f56348afSSteve Sakoman_irq: .word irq 52f56348afSSteve Sakoman_fiq: .word fiq 53f56348afSSteve Sakoman_pad: .word 0x12345678 /* now 16*4=64 */ 54f56348afSSteve Sakoman.global _end_vect 55f56348afSSteve Sakoman_end_vect: 56f56348afSSteve Sakoman 57f56348afSSteve Sakoman .balignl 16,0xdeadbeef 58f56348afSSteve Sakoman/************************************************************************* 59f56348afSSteve Sakoman * 60f56348afSSteve Sakoman * Startup Code (reset vector) 61f56348afSSteve Sakoman * 62f56348afSSteve Sakoman * do important init only if we don't start from memory! 63f56348afSSteve Sakoman * setup Memory and board specific bits prior to relocation. 64f56348afSSteve Sakoman * relocate armboot to ram 65f56348afSSteve Sakoman * setup stack 66f56348afSSteve Sakoman * 67f56348afSSteve Sakoman *************************************************************************/ 68f56348afSSteve Sakoman 69561142afSHeiko Schocher.globl _TEXT_BASE 70f56348afSSteve Sakoman_TEXT_BASE: 7114d0a02aSWolfgang Denk .word CONFIG_SYS_TEXT_BASE 72f56348afSSteve Sakoman 73561142afSHeiko Schocher#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) 74f56348afSSteve Sakoman.globl _armboot_start 75f56348afSSteve Sakoman_armboot_start: 76f56348afSSteve Sakoman .word _start 77561142afSHeiko Schocher#endif 78f56348afSSteve Sakoman 79f56348afSSteve Sakoman/* 80f56348afSSteve Sakoman * These are defined in the board-specific linker script. 81f56348afSSteve Sakoman */ 82c3d3a541SHeiko Schocher.globl _bss_start_ofs 83c3d3a541SHeiko Schocher_bss_start_ofs: 84c3d3a541SHeiko Schocher .word __bss_start - _start 85f56348afSSteve Sakoman 86c3d3a541SHeiko Schocher.globl _bss_end_ofs 87c3d3a541SHeiko Schocher_bss_end_ofs: 88c3d3a541SHeiko Schocher .word _end - _start 89f56348afSSteve Sakoman 90f56348afSSteve Sakoman#ifdef CONFIG_USE_IRQ 91f56348afSSteve Sakoman/* IRQ stack memory (calculated at run-time) */ 92f56348afSSteve Sakoman.globl IRQ_STACK_START 93f56348afSSteve SakomanIRQ_STACK_START: 94f56348afSSteve Sakoman .word 0x0badc0de 95f56348afSSteve Sakoman 96f56348afSSteve Sakoman/* IRQ stack memory (calculated at run-time) */ 97f56348afSSteve Sakoman.globl FIQ_STACK_START 98f56348afSSteve SakomanFIQ_STACK_START: 99f56348afSSteve Sakoman .word 0x0badc0de 100f56348afSSteve Sakoman#endif 101f56348afSSteve Sakoman 102561142afSHeiko Schocher#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) 103561142afSHeiko Schocher/* IRQ stack memory (calculated at run-time) + 8 bytes */ 104561142afSHeiko Schocher.globl IRQ_STACK_START_IN 105561142afSHeiko SchocherIRQ_STACK_START_IN: 106561142afSHeiko Schocher .word 0x0badc0de 107561142afSHeiko Schocher 108c3d3a541SHeiko Schocher.globl _datarel_start_ofs 109c3d3a541SHeiko Schocher_datarel_start_ofs: 110c3d3a541SHeiko Schocher .word __datarel_start - _start 111561142afSHeiko Schocher 112c3d3a541SHeiko Schocher.globl _datarelrolocal_start_ofs 113c3d3a541SHeiko Schocher_datarelrolocal_start_ofs: 114c3d3a541SHeiko Schocher .word __datarelrolocal_start - _start 115561142afSHeiko Schocher 116c3d3a541SHeiko Schocher.globl _datarellocal_start_ofs 117c3d3a541SHeiko Schocher_datarellocal_start_ofs: 118c3d3a541SHeiko Schocher .word __datarellocal_start - _start 119561142afSHeiko Schocher 120c3d3a541SHeiko Schocher.globl _datarelro_start_ofs 121c3d3a541SHeiko Schocher_datarelro_start_ofs: 122c3d3a541SHeiko Schocher .word __datarelro_start - _start 123561142afSHeiko Schocher 124c3d3a541SHeiko Schocher.globl _got_start_ofs 125c3d3a541SHeiko Schocher_got_start_ofs: 126c3d3a541SHeiko Schocher .word __got_start - _start 127561142afSHeiko Schocher 128c3d3a541SHeiko Schocher.globl _got_end_Ofs 129c3d3a541SHeiko Schocher_got_end_ofs: 130c3d3a541SHeiko Schocher .word __got_end - _start 131561142afSHeiko Schocher 132561142afSHeiko Schocher/* 133561142afSHeiko Schocher * the actual reset code 134561142afSHeiko Schocher */ 135561142afSHeiko Schocher 136561142afSHeiko Schocherreset: 137561142afSHeiko Schocher /* 138561142afSHeiko Schocher * set the cpu to SVC32 mode 139561142afSHeiko Schocher */ 140561142afSHeiko Schocher mrs r0, cpsr 141561142afSHeiko Schocher bic r0, r0, #0x1f 142561142afSHeiko Schocher orr r0, r0, #0xd3 143561142afSHeiko Schocher msr cpsr,r0 144561142afSHeiko Schocher 145561142afSHeiko Schocher#if (CONFIG_OMAP34XX) 146561142afSHeiko Schocher /* Copy vectors to mask ROM indirect addr */ 147561142afSHeiko Schocher adr r0, _start @ r0 <- current position of code 148561142afSHeiko Schocher add r0, r0, #4 @ skip reset vector 149561142afSHeiko Schocher mov r2, #64 @ r2 <- size to copy 150561142afSHeiko Schocher add r2, r0, r2 @ r2 <- source end address 151561142afSHeiko Schocher mov r1, #SRAM_OFFSET0 @ build vect addr 152561142afSHeiko Schocher mov r3, #SRAM_OFFSET1 153561142afSHeiko Schocher add r1, r1, r3 154561142afSHeiko Schocher mov r3, #SRAM_OFFSET2 155561142afSHeiko Schocher add r1, r1, r3 156561142afSHeiko Schochernext: 157561142afSHeiko Schocher ldmia r0!, {r3 - r10} @ copy from source address [r0] 158561142afSHeiko Schocher stmia r1!, {r3 - r10} @ copy to target address [r1] 159561142afSHeiko Schocher cmp r0, r2 @ until source end address [r2] 160561142afSHeiko Schocher bne next @ loop until equal */ 161561142afSHeiko Schocher#if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_ONENAND_BOOT) 162561142afSHeiko Schocher /* No need to copy/exec the clock code - DPLL adjust already done 163561142afSHeiko Schocher * in NAND/oneNAND Boot. 164561142afSHeiko Schocher */ 165561142afSHeiko Schocher bl cpy_clk_code @ put dpll adjust code behind vectors 166561142afSHeiko Schocher#endif /* NAND Boot */ 167561142afSHeiko Schocher#endif 168561142afSHeiko Schocher /* the mask ROM code should have PLL and others stable */ 169561142afSHeiko Schocher#ifndef CONFIG_SKIP_LOWLEVEL_INIT 170561142afSHeiko Schocher bl cpu_init_crit 171561142afSHeiko Schocher#endif 172561142afSHeiko Schocher 173561142afSHeiko Schocher/* Set stackpointer in internal RAM to call board_init_f */ 174561142afSHeiko Schochercall_board_init_f: 175561142afSHeiko Schocher ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) 176561142afSHeiko Schocher ldr r0,=0x00000000 177561142afSHeiko Schocher bl board_init_f 178561142afSHeiko Schocher 179561142afSHeiko Schocher/*------------------------------------------------------------------------------*/ 180561142afSHeiko Schocher 181561142afSHeiko Schocher/* 182561142afSHeiko Schocher * void relocate_code (addr_sp, gd, addr_moni) 183561142afSHeiko Schocher * 184561142afSHeiko Schocher * This "function" does not return, instead it continues in RAM 185561142afSHeiko Schocher * after relocating the monitor code. 186561142afSHeiko Schocher * 187561142afSHeiko Schocher */ 188561142afSHeiko Schocher .globl relocate_code 189561142afSHeiko Schocherrelocate_code: 190561142afSHeiko Schocher mov r4, r0 /* save addr_sp */ 191561142afSHeiko Schocher mov r5, r1 /* save addr of gd */ 192561142afSHeiko Schocher mov r6, r2 /* save addr of destination */ 193561142afSHeiko Schocher mov r7, r2 /* save addr of destination */ 194561142afSHeiko Schocher 195561142afSHeiko Schocher /* Set up the stack */ 196561142afSHeiko Schocherstack_setup: 197561142afSHeiko Schocher mov sp, r4 198561142afSHeiko Schocher 199561142afSHeiko Schocher#ifndef CONFIG_SKIP_RELOCATE_UBOOT 200561142afSHeiko Schocher adr r0, _start 201561142afSHeiko Schocher ldr r2, _TEXT_BASE 202c3d3a541SHeiko Schocher ldr r3, _bss_start_ofs 203c3d3a541SHeiko Schocher add r2, r0, r3 /* r2 <- source end address */ 204561142afSHeiko Schocher cmp r0, r6 205561142afSHeiko Schocher#ifndef CONFIG_PRELOADER 206561142afSHeiko Schocher beq jump_2_ram 207561142afSHeiko Schocher#endif 208561142afSHeiko Schocher 209561142afSHeiko Schochercopy_loop: 210561142afSHeiko Schocher ldmia r0!, {r9-r10} /* copy from source address [r0] */ 211561142afSHeiko Schocher stmia r6!, {r9-r10} /* copy to target address [r1] */ 212da90d4ceSAlbert Aribaud cmp r0, r2 /* until source end address [r2] */ 213da90d4ceSAlbert Aribaud blo copy_loop 214561142afSHeiko Schocher 215561142afSHeiko Schocher#ifndef CONFIG_PRELOADER 216c3d3a541SHeiko Schocher /* 217c3d3a541SHeiko Schocher * fix .rel.dyn relocations 218c3d3a541SHeiko Schocher */ 219c3d3a541SHeiko Schocher ldr r0, _TEXT_BASE /* r0 <- Text base */ 220c3d3a541SHeiko Schocher sub r9, r7, r0 /* r9 <- relocation offset */ 221c3d3a541SHeiko Schocher ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ 222c3d3a541SHeiko Schocher add r10, r10, r0 /* r10 <- sym table in FLASH */ 223c3d3a541SHeiko Schocher ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ 224c3d3a541SHeiko Schocher add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ 225c3d3a541SHeiko Schocher ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ 226c3d3a541SHeiko Schocher add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ 227561142afSHeiko Schocherfixloop: 228c3d3a541SHeiko Schocher ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ 2298c0c2b90SGray Remlin add r0, r0, r9 /* r0 <- location to fix up in RAM */ 230c3d3a541SHeiko Schocher ldr r1, [r2, #4] 231c3d3a541SHeiko Schocher and r8, r1, #0xff 232c3d3a541SHeiko Schocher cmp r8, #23 /* relative fixup? */ 233c3d3a541SHeiko Schocher beq fixrel 234c3d3a541SHeiko Schocher cmp r8, #2 /* absolute fixup? */ 235c3d3a541SHeiko Schocher beq fixabs 236c3d3a541SHeiko Schocher /* ignore unknown type of fixup */ 237c3d3a541SHeiko Schocher b fixnext 238c3d3a541SHeiko Schocherfixabs: 239c3d3a541SHeiko Schocher /* absolute fix: set location to (offset) symbol value */ 240c3d3a541SHeiko Schocher mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ 241c3d3a541SHeiko Schocher add r1, r10, r1 /* r1 <- address of symbol in table */ 242c3d3a541SHeiko Schocher ldr r1, [r1, #4] /* r1 <- symbol value */ 243c3d3a541SHeiko Schocher add r1, r9 /* r1 <- relocated sym addr */ 244c3d3a541SHeiko Schocher b fixnext 245c3d3a541SHeiko Schocherfixrel: 246c3d3a541SHeiko Schocher /* relative fix: increase location by offset */ 247c3d3a541SHeiko Schocher ldr r1, [r0] 248c3d3a541SHeiko Schocher add r1, r1, r9 249c3d3a541SHeiko Schocherfixnext: 250c3d3a541SHeiko Schocher str r1, [r0] 251c3d3a541SHeiko Schocher add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ 252561142afSHeiko Schocher cmp r2, r3 253c3d3a541SHeiko Schocher blo fixloop 254561142afSHeiko Schocher 255561142afSHeiko Schocherclear_bss: 256c3d3a541SHeiko Schocher ldr r0, _bss_start_ofs 257c3d3a541SHeiko Schocher ldr r1, _bss_end_ofs 258561142afSHeiko Schocher ldr r3, _TEXT_BASE /* Text base */ 259561142afSHeiko Schocher mov r4, r7 /* reloc addr */ 260561142afSHeiko Schocher add r0, r0, r4 261561142afSHeiko Schocher add r1, r1, r4 262561142afSHeiko Schocher mov r2, #0x00000000 /* clear */ 263561142afSHeiko Schocher 264561142afSHeiko Schocherclbss_l:str r2, [r0] /* clear loop... */ 265561142afSHeiko Schocher add r0, r0, #4 266561142afSHeiko Schocher cmp r0, r1 267561142afSHeiko Schocher bne clbss_l 268561142afSHeiko Schocher#endif /* #ifndef CONFIG_PRELOADER */ 269561142afSHeiko Schocher#endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */ 270561142afSHeiko Schocher 271561142afSHeiko Schocher/* 272561142afSHeiko Schocher * We are done. Do not return, instead branch to second part of board 273561142afSHeiko Schocher * initialization, now running from RAM. 274561142afSHeiko Schocher */ 275561142afSHeiko Schocherjump_2_ram: 276c3d3a541SHeiko Schocher ldr r0, _board_init_r_ofs 277c3d3a541SHeiko Schocher adr r1, _start 278*123fb7deSDarius Augulis add lr, r0, r1 279*123fb7deSDarius Augulis#ifndef CONFIG_SKIP_RELOCATE_UBOOT 280*123fb7deSDarius Augulis add lr, lr, r9 281*123fb7deSDarius Augulis#endif 282561142afSHeiko Schocher /* setup parameters for board_init_r */ 283561142afSHeiko Schocher mov r0, r5 /* gd_t */ 284561142afSHeiko Schocher mov r1, r7 /* dest_addr */ 285561142afSHeiko Schocher /* jump to it ... */ 286561142afSHeiko Schocher mov pc, lr 287561142afSHeiko Schocher 288c3d3a541SHeiko Schocher_board_init_r_ofs: 289c3d3a541SHeiko Schocher .word board_init_r - _start 290c3d3a541SHeiko Schocher 291c3d3a541SHeiko Schocher_rel_dyn_start_ofs: 292c3d3a541SHeiko Schocher .word __rel_dyn_start - _start 293c3d3a541SHeiko Schocher_rel_dyn_end_ofs: 294c3d3a541SHeiko Schocher .word __rel_dyn_end - _start 295c3d3a541SHeiko Schocher_dynsym_start_ofs: 296c3d3a541SHeiko Schocher .word __dynsym_start - _start 297c3d3a541SHeiko Schocher 298561142afSHeiko Schocher#else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ 299f56348afSSteve Sakoman/* 300f56348afSSteve Sakoman * the actual reset code 301f56348afSSteve Sakoman */ 302f56348afSSteve Sakoman 303f56348afSSteve Sakomanreset: 304f56348afSSteve Sakoman /* 305f56348afSSteve Sakoman * set the cpu to SVC32 mode 306f56348afSSteve Sakoman */ 307f56348afSSteve Sakoman mrs r0, cpsr 308f56348afSSteve Sakoman bic r0, r0, #0x1f 309f56348afSSteve Sakoman orr r0, r0, #0xd3 310f56348afSSteve Sakoman msr cpsr,r0 311f56348afSSteve Sakoman 312f56348afSSteve Sakoman#if (CONFIG_OMAP34XX) 313f56348afSSteve Sakoman /* Copy vectors to mask ROM indirect addr */ 314f56348afSSteve Sakoman adr r0, _start @ r0 <- current position of code 315f56348afSSteve Sakoman add r0, r0, #4 @ skip reset vector 316f56348afSSteve Sakoman mov r2, #64 @ r2 <- size to copy 317f56348afSSteve Sakoman add r2, r0, r2 @ r2 <- source end address 318f56348afSSteve Sakoman mov r1, #SRAM_OFFSET0 @ build vect addr 319f56348afSSteve Sakoman mov r3, #SRAM_OFFSET1 320f56348afSSteve Sakoman add r1, r1, r3 321f56348afSSteve Sakoman mov r3, #SRAM_OFFSET2 322f56348afSSteve Sakoman add r1, r1, r3 323f56348afSSteve Sakomannext: 324f56348afSSteve Sakoman ldmia r0!, {r3 - r10} @ copy from source address [r0] 325f56348afSSteve Sakoman stmia r1!, {r3 - r10} @ copy to target address [r1] 326f56348afSSteve Sakoman cmp r0, r2 @ until source end address [r2] 327f56348afSSteve Sakoman bne next @ loop until equal */ 328f56348afSSteve Sakoman#if !defined(CONFIG_SYS_NAND_BOOT) && !defined(CONFIG_SYS_ONENAND_BOOT) 329f56348afSSteve Sakoman /* No need to copy/exec the clock code - DPLL adjust already done 330f56348afSSteve Sakoman * in NAND/oneNAND Boot. 331f56348afSSteve Sakoman */ 332f56348afSSteve Sakoman bl cpy_clk_code @ put dpll adjust code behind vectors 333f56348afSSteve Sakoman#endif /* NAND Boot */ 334f56348afSSteve Sakoman#endif 335f56348afSSteve Sakoman /* the mask ROM code should have PLL and others stable */ 336f56348afSSteve Sakoman#ifndef CONFIG_SKIP_LOWLEVEL_INIT 337f56348afSSteve Sakoman bl cpu_init_crit 338f56348afSSteve Sakoman#endif 339f56348afSSteve Sakoman 340f56348afSSteve Sakoman#ifndef CONFIG_SKIP_RELOCATE_UBOOT 341f56348afSSteve Sakomanrelocate: @ relocate U-Boot to RAM 342f56348afSSteve Sakoman adr r0, _start @ r0 <- current position of code 343f56348afSSteve Sakoman ldr r1, _TEXT_BASE @ test if we run from flash or RAM 344f56348afSSteve Sakoman cmp r0, r1 @ don't reloc during debug 345f56348afSSteve Sakoman beq stack_setup 346f56348afSSteve Sakoman 347f56348afSSteve Sakoman ldr r2, _armboot_start 348f56348afSSteve Sakoman ldr r3, _bss_start 349f56348afSSteve Sakoman sub r2, r3, r2 @ r2 <- size of armboot 350f56348afSSteve Sakoman add r2, r0, r2 @ r2 <- source end address 351f56348afSSteve Sakoman 352f56348afSSteve Sakomancopy_loop: @ copy 32 bytes at a time 353f56348afSSteve Sakoman ldmia r0!, {r3 - r10} @ copy from source address [r0] 354f56348afSSteve Sakoman stmia r1!, {r3 - r10} @ copy to target address [r1] 355da90d4ceSAlbert Aribaud cmp r0, r2 @ until source end address [r2] 356da90d4ceSAlbert Aribaud blo copy_loop 357f56348afSSteve Sakoman#endif /* CONFIG_SKIP_RELOCATE_UBOOT */ 358f56348afSSteve Sakoman 359f56348afSSteve Sakoman /* Set up the stack */ 360f56348afSSteve Sakomanstack_setup: 361f56348afSSteve Sakoman ldr r0, _TEXT_BASE @ upper 128 KiB: relocated uboot 362f56348afSSteve Sakoman sub r0, r0, #CONFIG_SYS_MALLOC_LEN @ malloc area 36325ddd1fbSWolfgang Denk sub r0, r0, #GENERATED_GBL_DATA_SIZE @ bdinfo 364f56348afSSteve Sakoman#ifdef CONFIG_USE_IRQ 365f56348afSSteve Sakoman sub r0, r0, #(CONFIG_STACKSIZE_IRQ + CONFIG_STACKSIZE_FIQ) 366f56348afSSteve Sakoman#endif 367f56348afSSteve Sakoman sub sp, r0, #12 @ leave 3 words for abort-stack 368f56348afSSteve Sakoman bic sp, sp, #7 @ 8-byte alignment for ABI compliance 369f56348afSSteve Sakoman 370f56348afSSteve Sakoman /* Clear BSS (if any). Is below tx (watch load addr - need space) */ 371f56348afSSteve Sakomanclear_bss: 372f56348afSSteve Sakoman ldr r0, _bss_start @ find start of bss segment 373f56348afSSteve Sakoman ldr r1, _bss_end @ stop here 374f56348afSSteve Sakoman mov r2, #0x00000000 @ clear value 375f56348afSSteve Sakomanclbss_l: 376f56348afSSteve Sakoman str r2, [r0] @ clear BSS location 377f56348afSSteve Sakoman cmp r0, r1 @ are we at the end yet 378f56348afSSteve Sakoman add r0, r0, #4 @ increment clear index pointer 379f56348afSSteve Sakoman bne clbss_l @ keep clearing till at end 380f56348afSSteve Sakoman 381f56348afSSteve Sakoman ldr pc, _start_armboot @ jump to C code 382f56348afSSteve Sakoman 383f56348afSSteve Sakoman_start_armboot: .word start_armboot 384561142afSHeiko Schocher#endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ 385f56348afSSteve Sakoman 386f56348afSSteve Sakoman/************************************************************************* 387f56348afSSteve Sakoman * 388f56348afSSteve Sakoman * CPU_init_critical registers 389f56348afSSteve Sakoman * 390f56348afSSteve Sakoman * setup important registers 391f56348afSSteve Sakoman * setup memory timing 392f56348afSSteve Sakoman * 393f56348afSSteve Sakoman *************************************************************************/ 394f56348afSSteve Sakomancpu_init_crit: 395f56348afSSteve Sakoman /* 396f56348afSSteve Sakoman * Invalidate L1 I/D 397f56348afSSteve Sakoman */ 398f56348afSSteve Sakoman mov r0, #0 @ set up for MCR 399f56348afSSteve Sakoman mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs 400f56348afSSteve Sakoman mcr p15, 0, r0, c7, c5, 0 @ invalidate icache 401f56348afSSteve Sakoman 402f56348afSSteve Sakoman /* 403f56348afSSteve Sakoman * disable MMU stuff and caches 404f56348afSSteve Sakoman */ 405f56348afSSteve Sakoman mrc p15, 0, r0, c1, c0, 0 406f56348afSSteve Sakoman bic r0, r0, #0x00002000 @ clear bits 13 (--V-) 407f56348afSSteve Sakoman bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) 408f56348afSSteve Sakoman orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align 409f56348afSSteve Sakoman orr r0, r0, #0x00000800 @ set bit 12 (Z---) BTB 410f56348afSSteve Sakoman mcr p15, 0, r0, c1, c0, 0 411f56348afSSteve Sakoman 412f56348afSSteve Sakoman /* 413f56348afSSteve Sakoman * Jump to board specific initialization... 414f56348afSSteve Sakoman * The Mask ROM will have already initialized 415f56348afSSteve Sakoman * basic memory. Go here to bump up clock rate and handle 416f56348afSSteve Sakoman * wake up conditions. 417f56348afSSteve Sakoman */ 418f56348afSSteve Sakoman mov ip, lr @ persevere link reg across call 419f56348afSSteve Sakoman bl lowlevel_init @ go setup pll,mux,memory 420f56348afSSteve Sakoman mov lr, ip @ restore link 421f56348afSSteve Sakoman mov pc, lr @ back to my caller 422f56348afSSteve Sakoman/* 423f56348afSSteve Sakoman ************************************************************************* 424f56348afSSteve Sakoman * 425f56348afSSteve Sakoman * Interrupt handling 426f56348afSSteve Sakoman * 427f56348afSSteve Sakoman ************************************************************************* 428f56348afSSteve Sakoman */ 429f56348afSSteve Sakoman@ 430f56348afSSteve Sakoman@ IRQ stack frame. 431f56348afSSteve Sakoman@ 432f56348afSSteve Sakoman#define S_FRAME_SIZE 72 433f56348afSSteve Sakoman 434f56348afSSteve Sakoman#define S_OLD_R0 68 435f56348afSSteve Sakoman#define S_PSR 64 436f56348afSSteve Sakoman#define S_PC 60 437f56348afSSteve Sakoman#define S_LR 56 438f56348afSSteve Sakoman#define S_SP 52 439f56348afSSteve Sakoman 440f56348afSSteve Sakoman#define S_IP 48 441f56348afSSteve Sakoman#define S_FP 44 442f56348afSSteve Sakoman#define S_R10 40 443f56348afSSteve Sakoman#define S_R9 36 444f56348afSSteve Sakoman#define S_R8 32 445f56348afSSteve Sakoman#define S_R7 28 446f56348afSSteve Sakoman#define S_R6 24 447f56348afSSteve Sakoman#define S_R5 20 448f56348afSSteve Sakoman#define S_R4 16 449f56348afSSteve Sakoman#define S_R3 12 450f56348afSSteve Sakoman#define S_R2 8 451f56348afSSteve Sakoman#define S_R1 4 452f56348afSSteve Sakoman#define S_R0 0 453f56348afSSteve Sakoman 454f56348afSSteve Sakoman#define MODE_SVC 0x13 455f56348afSSteve Sakoman#define I_BIT 0x80 456f56348afSSteve Sakoman 457f56348afSSteve Sakoman/* 458f56348afSSteve Sakoman * use bad_save_user_regs for abort/prefetch/undef/swi ... 459f56348afSSteve Sakoman * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling 460f56348afSSteve Sakoman */ 461f56348afSSteve Sakoman 462f56348afSSteve Sakoman .macro bad_save_user_regs 463f56348afSSteve Sakoman sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current 464f56348afSSteve Sakoman @ user stack 465f56348afSSteve Sakoman stmia sp, {r0 - r12} @ Save user registers (now in 466f56348afSSteve Sakoman @ svc mode) r0-r12 467561142afSHeiko Schocher#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) 468f56348afSSteve Sakoman ldr r2, _armboot_start 469f56348afSSteve Sakoman sub r2, r2, #(CONFIG_SYS_MALLOC_LEN) 47025ddd1fbSWolfgang Denk sub r2, r2, #(GENERATED_GBL_DATA_SIZE + 8) @ set base 2 words into abort 471561142afSHeiko Schocher#else 472561142afSHeiko Schocher ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort 473f56348afSSteve Sakoman @ stack 474561142afSHeiko Schocher#endif 475f56348afSSteve Sakoman ldmia r2, {r2 - r3} @ get values for "aborted" pc 476f56348afSSteve Sakoman @ and cpsr (into parm regs) 477f56348afSSteve Sakoman add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack 478f56348afSSteve Sakoman 479f56348afSSteve Sakoman add r5, sp, #S_SP 480f56348afSSteve Sakoman mov r1, lr 481f56348afSSteve Sakoman stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr 482f56348afSSteve Sakoman mov r0, sp @ save current stack into r0 483f56348afSSteve Sakoman @ (param register) 484f56348afSSteve Sakoman .endm 485f56348afSSteve Sakoman 486f56348afSSteve Sakoman .macro irq_save_user_regs 487f56348afSSteve Sakoman sub sp, sp, #S_FRAME_SIZE 488f56348afSSteve Sakoman stmia sp, {r0 - r12} @ Calling r0-r12 489f56348afSSteve Sakoman add r8, sp, #S_PC @ !! R8 NEEDS to be saved !! 490f56348afSSteve Sakoman @ a reserved stack spot would 491f56348afSSteve Sakoman @ be good. 492f56348afSSteve Sakoman stmdb r8, {sp, lr}^ @ Calling SP, LR 493f56348afSSteve Sakoman str lr, [r8, #0] @ Save calling PC 494f56348afSSteve Sakoman mrs r6, spsr 495f56348afSSteve Sakoman str r6, [r8, #4] @ Save CPSR 496f56348afSSteve Sakoman str r0, [r8, #8] @ Save OLD_R0 497f56348afSSteve Sakoman mov r0, sp 498f56348afSSteve Sakoman .endm 499f56348afSSteve Sakoman 500f56348afSSteve Sakoman .macro irq_restore_user_regs 501f56348afSSteve Sakoman ldmia sp, {r0 - lr}^ @ Calling r0 - lr 502f56348afSSteve Sakoman mov r0, r0 503f56348afSSteve Sakoman ldr lr, [sp, #S_PC] @ Get PC 504f56348afSSteve Sakoman add sp, sp, #S_FRAME_SIZE 505f56348afSSteve Sakoman subs pc, lr, #4 @ return & move spsr_svc into 506f56348afSSteve Sakoman @ cpsr 507f56348afSSteve Sakoman .endm 508f56348afSSteve Sakoman 509f56348afSSteve Sakoman .macro get_bad_stack 510561142afSHeiko Schocher#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) 511f56348afSSteve Sakoman ldr r13, _armboot_start @ setup our mode stack (enter 512f56348afSSteve Sakoman sub r13, r13, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool 51325ddd1fbSWolfgang Denk sub r13, r13, #(GENERATED_GBL_DATA_SIZE + 8) @ move to reserved a couple 514561142afSHeiko Schocher#else 515561142afSHeiko Schocher ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter 516561142afSHeiko Schocher @ in banked mode) 517561142afSHeiko Schocher#endif 518f56348afSSteve Sakoman 519f56348afSSteve Sakoman str lr, [r13] @ save caller lr in position 0 520f56348afSSteve Sakoman @ of saved stack 521f56348afSSteve Sakoman mrs lr, spsr @ get the spsr 522f56348afSSteve Sakoman str lr, [r13, #4] @ save spsr in position 1 of 523f56348afSSteve Sakoman @ saved stack 524f56348afSSteve Sakoman 525f56348afSSteve Sakoman mov r13, #MODE_SVC @ prepare SVC-Mode 526f56348afSSteve Sakoman @ msr spsr_c, r13 527f56348afSSteve Sakoman msr spsr, r13 @ switch modes, make sure 528f56348afSSteve Sakoman @ moves will execute 529f56348afSSteve Sakoman mov lr, pc @ capture return pc 530f56348afSSteve Sakoman movs pc, lr @ jump to next instruction & 531f56348afSSteve Sakoman @ switch modes. 532f56348afSSteve Sakoman .endm 533f56348afSSteve Sakoman 534f56348afSSteve Sakoman .macro get_bad_stack_swi 535f56348afSSteve Sakoman sub r13, r13, #4 @ space on current stack for 536f56348afSSteve Sakoman @ scratch reg. 537f56348afSSteve Sakoman str r0, [r13] @ save R0's value. 538561142afSHeiko Schocher#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) 539f56348afSSteve Sakoman ldr r0, _armboot_start @ get data regions start 540f56348afSSteve Sakoman sub r0, r0, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool 54125ddd1fbSWolfgang Denk sub r0, r0, #(GENERATED_GBL_DATA_SIZE + 8) @ move past gbl and a couple 542561142afSHeiko Schocher#else 543561142afSHeiko Schocher ldr r0, IRQ_STACK_START_IN @ get data regions start 544f56348afSSteve Sakoman @ spots for abort stack 545561142afSHeiko Schocher#endif 546f56348afSSteve Sakoman str lr, [r0] @ save caller lr in position 0 547f56348afSSteve Sakoman @ of saved stack 548f56348afSSteve Sakoman mrs r0, spsr @ get the spsr 549f56348afSSteve Sakoman str lr, [r0, #4] @ save spsr in position 1 of 550f56348afSSteve Sakoman @ saved stack 551f56348afSSteve Sakoman ldr r0, [r13] @ restore r0 552f56348afSSteve Sakoman add r13, r13, #4 @ pop stack entry 553f56348afSSteve Sakoman .endm 554f56348afSSteve Sakoman 555f56348afSSteve Sakoman .macro get_irq_stack @ setup IRQ stack 556f56348afSSteve Sakoman ldr sp, IRQ_STACK_START 557f56348afSSteve Sakoman .endm 558f56348afSSteve Sakoman 559f56348afSSteve Sakoman .macro get_fiq_stack @ setup FIQ stack 560f56348afSSteve Sakoman ldr sp, FIQ_STACK_START 561f56348afSSteve Sakoman .endm 562f56348afSSteve Sakoman 563f56348afSSteve Sakoman/* 564f56348afSSteve Sakoman * exception handlers 565f56348afSSteve Sakoman */ 566f56348afSSteve Sakoman .align 5 567f56348afSSteve Sakomanundefined_instruction: 568f56348afSSteve Sakoman get_bad_stack 569f56348afSSteve Sakoman bad_save_user_regs 570f56348afSSteve Sakoman bl do_undefined_instruction 571f56348afSSteve Sakoman 572f56348afSSteve Sakoman .align 5 573f56348afSSteve Sakomansoftware_interrupt: 574f56348afSSteve Sakoman get_bad_stack_swi 575f56348afSSteve Sakoman bad_save_user_regs 576f56348afSSteve Sakoman bl do_software_interrupt 577f56348afSSteve Sakoman 578f56348afSSteve Sakoman .align 5 579f56348afSSteve Sakomanprefetch_abort: 580f56348afSSteve Sakoman get_bad_stack 581f56348afSSteve Sakoman bad_save_user_regs 582f56348afSSteve Sakoman bl do_prefetch_abort 583f56348afSSteve Sakoman 584f56348afSSteve Sakoman .align 5 585f56348afSSteve Sakomandata_abort: 586f56348afSSteve Sakoman get_bad_stack 587f56348afSSteve Sakoman bad_save_user_regs 588f56348afSSteve Sakoman bl do_data_abort 589f56348afSSteve Sakoman 590f56348afSSteve Sakoman .align 5 591f56348afSSteve Sakomannot_used: 592f56348afSSteve Sakoman get_bad_stack 593f56348afSSteve Sakoman bad_save_user_regs 594f56348afSSteve Sakoman bl do_not_used 595f56348afSSteve Sakoman 596f56348afSSteve Sakoman#ifdef CONFIG_USE_IRQ 597f56348afSSteve Sakoman 598f56348afSSteve Sakoman .align 5 599f56348afSSteve Sakomanirq: 600f56348afSSteve Sakoman get_irq_stack 601f56348afSSteve Sakoman irq_save_user_regs 602f56348afSSteve Sakoman bl do_irq 603f56348afSSteve Sakoman irq_restore_user_regs 604f56348afSSteve Sakoman 605f56348afSSteve Sakoman .align 5 606f56348afSSteve Sakomanfiq: 607f56348afSSteve Sakoman get_fiq_stack 608f56348afSSteve Sakoman /* someone ought to write a more effective fiq_save_user_regs */ 609f56348afSSteve Sakoman irq_save_user_regs 610f56348afSSteve Sakoman bl do_fiq 611f56348afSSteve Sakoman irq_restore_user_regs 612f56348afSSteve Sakoman 613f56348afSSteve Sakoman#else 614f56348afSSteve Sakoman 615f56348afSSteve Sakoman .align 5 616f56348afSSteve Sakomanirq: 617f56348afSSteve Sakoman get_bad_stack 618f56348afSSteve Sakoman bad_save_user_regs 619f56348afSSteve Sakoman bl do_irq 620f56348afSSteve Sakoman 621f56348afSSteve Sakoman .align 5 622f56348afSSteve Sakomanfiq: 623f56348afSSteve Sakoman get_bad_stack 624f56348afSSteve Sakoman bad_save_user_regs 625f56348afSSteve Sakoman bl do_fiq 626f56348afSSteve Sakoman 627f56348afSSteve Sakoman#endif 628