1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 2;; 3;; Part one of the system initialization code, 4;; contains low-level 5;; initialization. 6;; 7;; Copyright 2007 IAR Systems. All rights reserved. 8;; 9;; $Revision: 49919 $ 10;; 11 12 MODULE ?cstartup 13 14 ;; Forward declaration of sections. 15 SECTION IRQ_STACK:DATA:NOROOT(3) 16 SECTION FIQ_STACK:DATA:NOROOT(3) 17 SECTION CSTACK:DATA:NOROOT(3) 18 19; 20; The module in this file are included in the libraries, and may be 21; replaced by any user-defined modules that define the PUBLIC symbol 22; __iar_program_start or a user defined start symbol. 23; 24; To override the cstartup defined in the library, simply add your 25; modified version to the workbench project. 26 27 SECTION .intvec:CODE:NOROOT(2) 28 29 PUBLIC __vector 30 PUBLIC __iar_program_start 31 EXTERN Undefined_Handler 32 EXTERN SWI_Handler 33 EXTERN Prefetch_Handler 34 EXTERN Abort_Handler 35 EXTERN IRQ_Handler 36 EXTERN FIQ_Handler 37 38 DATA 39 40__iar_init$$done: ; The vector table is not needed 41 ; until after copy initialization is done 42 43__vector: ; Make this a DATA label, so that stack usage 44 ; analysis doesn't consider it an uncalled fun 45 46 ARM 47 48 ; All default exception handlers (except reset) are 49 ; defined as weak symbol definitions. 50 ; If a handler is defined by the application it will take precedence. 51 LDR PC,Reset_Addr ; Reset 52 LDR PC,Undefined_Addr ; Undefined instructions 53 LDR PC,SWI_Addr ; Software interrupt (SWI/SVC) 54 LDR PC,Prefetch_Addr ; Prefetch abort 55 LDR PC,Abort_Addr ; Data abort 56 DCD 0 ; RESERVED 57 LDR PC,IRQ_Addr ; IRQ 58 LDR PC,FIQ_Addr ; FIQ 59 60 DATA 61 62Reset_Addr: DCD __iar_program_start 63Undefined_Addr: DCD Undefined_Handler 64SWI_Addr: DCD SWI_Handler 65Prefetch_Addr: DCD Prefetch_Handler 66Abort_Addr: DCD Abort_Handler 67IRQ_Addr: DCD IRQ_Handler 68FIQ_Addr: DCD FIQ_Handler 69 70 71; -------------------------------------------------- 72; ?cstartup -- low-level system initialization code. 73; 74; After a reset execution starts here, the mode is ARM, supervisor 75; with interrupts disabled. 76; 77 78 79 80 SECTION .text:CODE:NOROOT(2) 81 82 EXTERN __cmain 83 REQUIRE __vector 84 EXTWEAK __iar_init_core 85 EXTWEAK __iar_init_vfp 86 87 88 ARM 89 90__iar_program_start: 91?cstartup: 92 93; 94; Add initialization needed before setup of stackpointers here. 95; 96 97; 98; Initialize the stack pointers. 99; The pattern below can be used for any of the exception stacks: 100; FIQ, IRQ, SVC, ABT, UND, SYS. 101; The USR mode uses the same stack as SYS. 102; The stack segments must be defined in the linker command file, 103; and be declared above. 104; 105 106 107; -------------------- 108; Mode, correspords to bits 0-5 in CPSR 109 110#define MODE_MSK 0x1F ; Bit mask for mode bits in CPSR 111 112#define USR_MODE 0x10 ; User mode 113#define FIQ_MODE 0x11 ; Fast Interrupt Request mode 114#define IRQ_MODE 0x12 ; Interrupt Request mode 115#define SVC_MODE 0x13 ; Supervisor mode 116#define ABT_MODE 0x17 ; Abort mode 117#define UND_MODE 0x1B ; Undefined Instruction mode 118#define SYS_MODE 0x1F ; System mode 119 120 MRS r0, cpsr ; Original PSR value 121 122 ;; Set up the interrupt stack pointer. 123 124 BIC r0, r0, #MODE_MSK ; Clear the mode bits 125 ORR r0, r0, #IRQ_MODE ; Set IRQ mode bits 126 MSR cpsr_c, r0 ; Change the mode 127 LDR sp, =SFE(IRQ_STACK) ; End of IRQ_STACK 128 BIC sp,sp,#0x7 ; Make sure SP is 8 aligned 129 130 ;; Set up the fast interrupt stack pointer. 131 132 BIC r0, r0, #MODE_MSK ; Clear the mode bits 133 ORR r0, r0, #FIQ_MODE ; Set FIR mode bits 134 MSR cpsr_c, r0 ; Change the mode 135 LDR sp, =SFE(FIQ_STACK) ; End of FIQ_STACK 136 BIC sp,sp,#0x7 ; Make sure SP is 8 aligned 137 138 ;; Set up the normal stack pointer. 139 140 BIC r0 ,r0, #MODE_MSK ; Clear the mode bits 141 ORR r0 ,r0, #SYS_MODE ; Set System mode bits 142 MSR cpsr_c, r0 ; Change the mode 143 LDR sp, =SFE(CSTACK) ; End of CSTACK 144 BIC sp,sp,#0x7 ; Make sure SP is 8 aligned 145 146 ;; Turn on core features assumed to be enabled. 147 FUNCALL __iar_program_start, __iar_init_core 148 BL __iar_init_core 149 150 ;; Initialize VFP (if needed). 151 FUNCALL __iar_program_start, __iar_init_vfp 152 BL __iar_init_vfp 153 154;;; 155;;; Add more initialization here 156;;; 157 158;;; Continue to __cmain for C-level initialization. 159 160 FUNCALL __iar_program_start, __cmain 161 B __cmain 162 163 END 164