AT91 C-startup. 2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point.

Slides:



Advertisements
Similar presentations
ECE 353 Introduction to Microprocessor Systems
Advertisements

ARM System - On - Chip Architecture2 INTRODUCTION ARM is a RISC processor. It is used for small size and high performance applications. Simple architecture.
Lab III Real-Time Embedded Operating System for a SoC System.
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
Net+OS Initialization Initialization Sequence Initialization Routine Roles ROM Image Compression/Decompression.
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
Computer System Overview
Chapter 12: Software interrupts (SWI) and exceptions
7/23 Coldfire Exceptions and Interrupts Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee
Introduction To The ARM Microprocessor
Computer System Overview
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
ARM 7 Datapath. Has “BIGEND” input bit, which defines whether the memory is big or little endian Modes: ARM7 supports six modes of operation: (1) User.
COMP3221 lec27-exception-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lectures 27: Exceptions & Interrupts - I
Exceptions, Interrupts & Traps
Software Development and Software Loading in Embedded Systems.
ARM Core Architecture. Common ARM Cortex Core In the case of ARM-based microcontrollers a company named ARM Holdings designs the core and licenses it.
- AT91SAM Training SAM9 Boot Strategies Frederic BOYER AT91 Support Group. Version 1.0 October 2006 AT91 Support Group. Version June 2007.
The ARM Programmer’s Model
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
What are Exception and Interrupts? MIPS terminology Exception: any unexpected change in the internal control flow – Invoking an operating system service.
1 © 2002, Cisco Systems, Inc. All rights reserved. Router boot procedure.
Cortex-M3 Programming. Chapter 10 in the reference book.
Exception and Interrupt Handling
Introduction to Embedded Systems
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
Introduction to Embedded Systems Rabie A. Ramadan 6.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Relocation.
Lab I Real-Time Embedded Operating System for a SoC System.
AT91 Memory Interface. 2 Features –Up to 8 programmable chip select lines –Remap Command allows dynamic exception vectors –Glue-less for both 8-bit and.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
COMP091 – Operating Systems 1 Memory Management. Memory Management Terms Physical address –Actual address as seen by memory unit Logical address –Address.
Introduction to ARM processor. Intro.. ARM founded in November 1990 Advanced RISC Machines Company headquarters in Cambridge, UK Processor design centers.
ARM7 TDMI INTRODUCTION.
Instruction Set Architectures Early trend was to add more and more instructions to new CPUs to do elaborate operations –VAX architecture had an instruction.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
DATE S. S.. Sandstone The sandstone carries out the following tasks: 1. Set up target platform environment, 2. Load a bootable image into memory, 3. Relinquish.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Chap. 4 ARM Boot Loader Internals. 2 S3C2500 ARM940T Core module ARM9TDMI CoreIC.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
Chapter 12: Software interrupts (SWI) and exceptions
Embedded System Design Center
Chapter 9 Exception & Interruption
Timer and Interrupts.
Interrupts In 8085 and 8086.
MCF5249 Software Examples Bootable example code for the MCF5249
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 27: Exceptions & Interrupts - I
Chapter 4 Addressing modes
Chapter 10 And, Finally... The Stack
Chapter 10 The Stack.
ARM System - On - Chip Architecture
CENG2400 Revision Q1a A system has an ARM processor with a 32-bit General Purpose Input Output (GPIO) module. Two on/off switches are connected to bit-3.
AT91RM9200 Boot strategies This training module describes the boot strategies on the AT91RM9200 including the internal Boot ROM and the U-Boot program.
AT91 Memory Interface This training module describes the External Bus Interface (EBI), which generatesthe signals that control the access to the external.
Real-Time Embedded Operating System for a SoC System
AT91 C-startup This training module describes the C-Startup sequence, which performs initialization of the microcontroller from the reset up to the calling.
Chapter 12: Software interrupts (SWI) and exceptions
Chapter 10 And, Finally... The Stack
CORTEX-M0 Structure Discussion 1
ARM Introduction.
Lecture 3 - Instruction Set - Al
Computer System Laboratory
Multiply Instructions
May, 2004 Modified from notes by Saeid Nooshabadi
Presentation transcript:

AT91 C-startup

2 For reasons of modularity and portability most application code for an embedded application is written in C The application entry point must perform some initialization before it can call any C code The C-startup is the first file executed at power on and Performs initialization of the microcontroller from the reset vector up to the calling of application main routine. –Exception vectors, critical peripherals, stacks and variables Why a C-startup code ?

3 Major consideration in the design of an embedded ARM application is the layout of the memory map –In particular the memory at address 0x0. The ARM processor starts to fetch instructions from address 0x0 at reset. For an embedded system, this requires NVM at address 0x0, at least initially Because of ROM limitations, the speed of execution handling is affected and the exception vectors cannot be modified –Therefore, ROM must be located at address 0x0 at power-up to assure a valid reset vector. A common strategy is to remap ROM to RAM and copy the exception vectors from ROM to RAM C-startup sequence (1/3)

4 Many applications written for ARM-based systems are embedded applications that are contained in ROM and execute on Reset –Remapping ROM to RAM, to improve execution speed –Initializing the execution environment, such as exception vectors, stacks, I/O peripherals –Initializing the application –Linking an embedded executable image to place code and data in specific locations in memory For an embedded application, the code in ROM must provide a way for the application to initialize itself and start executing C-startup sequence (2/3)

5 The initialization code, located at address zero after reset, must: –Mark the entry point for the initialization code –Set-up exception vectors –Initialize the memory system –Initialize any critical I/O devices –Initialize the stack pointer registers –Enable interrupts –Change processor mode if necessary After, the sequence continues with the application initialization and Enter the C code –For example, copying initialization values for initialized variables from ROM to RAM and resetting all other variables to zero –The main program should be a closed loop and should not return C-startup sequence (3/3)

6 AT91 C-startup goal Configuration at Reset : Configuration after C-Startup: External device selected by NCS0 Reserved on-chip device On-chip RAM Reserved On-chip peripherals Reserved on-chip device 0x x x x x xFFC  EBI after Reset : only NCS0 actived :  external memory 0x  maximum wait states on NCS0 NCS1-7 NOT available.  Interrupt vectors fixed in memory  AIC Not configured  RAM 0x  Stacks not intialized  EBI configured  NCS 0 to 7 active,  all external memories are available  RAM 0x  dynamic ARM Exception vectors  Dynamic vectoring with AIC  Stacks initialized  All variables are initialized up to 8 external devices Reserved on-chip device On-chip RAM Reserved On-chip peripherals Reserved on-chip device 0x x x x x xFFC CS0 0x

7 ; ;- Area Definition ; AREA reset, CODE, READONLY, INTERWORK ; ;- Define ENTRY point ; ENTRY ; ;- Exception vectors ( before Remap ) ; B InitReset ; reset undefvec B undefvec ; Undefined Instruction swivec B swivec ; Software Interrupt pabtvec B pabtvec ; Prefetch Abort dabtvec B dabtvec ; Data Abort rsvdvec B rsvdvec ; reserved irqvec B irqvec ; Irq fiqvec B fiqvec ; Fiq AT91 C-startup example

8 ; ;- EBI Initialization Data ; InitTableEBI DCDEBI_CSR_0 DCD EBI_CSR_1 DCD EBI_CSR_2 DCD EBI_CSR_3 DCD EBI_CSR_4 DCD EBI_CSR_5 DCD EBI_CSR_6 DCD EBI_CSR_7 DCD 0x ; REMAP command DCD 0x ; 6 memory regions, standard read PtEBIBase DCDEBI_BASE; EBI Base Address ; ;- Reset Handler before Remap ; InitReset ; ;- Speed up the Boot sequence ; ;- Load System EBI Base address and CSR0 Init Value ldr r0, PtEBIBase ldr r1, InitTableEBI; values (relative) ;- Speed up code execution by disabling wait state on Chip Select 0 str r1, [r0] AT91 C-startup example

9 ; ;- Low level init ; bl __low_level_init ; ;- Advanced Interrupt Controller configuration ; ;- Load the AIC Base Address and the default handler addresses add r0, pc,#-(8+.-AicData) where to read values (relative) ldmia r0, {r1-r4} ;- Setup the Spurious Vector str r4, [r1, #AIC_SPU] ; r4 =spurious handler ;- Set up the default interrupt handler vectors str r2, [r1, #AIC_SVR]; SVR[0] for FIQ add r1, r1, #AIC_SVR mov r0, #31 ; counter LoopAic1 str r3, [r1, r0, LSL #2]; SVRs for IRQs subs r0, r0, #1 ; do not save FIQ bhi LoopAic1 b EndInitAic AicData DCDAIC_BASE; AIC Base Address IMPORT at91_default_fiq_handler IMPORT at91_default_irq_handler IMPORT at91_spurious_handler PtDefaultHandler DCDat91_default_fiq_handler DCD at91_default_irq_handler DCD at91_spurious_handler EndInitAic AT91 C-startup example

10 ; ;-Setup Exception Vectors in Internal RAM before Remap ; b SetupRamVectors VectorTable ldr pc, [pc, #&18]; SoftReset ldr pc, [pc, #&18] ; UndefHandler ldr pc, [pc, #&18] ; SWIHandler ldr pc, [pc, #&18] ; PrefetchAbortHandler ldr pc, [pc, #&18] ; DataAbortHandler nop ; Reserved ldr pc, [pc,#-0xF20] ; IRQ : read the AIC ldr pc, [pc,#-0xF20]; FIQ : read the AIC ;- There are only 5 offsets as the vectoring is used. DCDSoftReset DCDUndefHandler DCDSWIHandler DCDPrefetchAbortHandler DCDDataAbortHandler ;- Vectoring Execution function run at absolute address SoftReset b SoftReset UndefHandler b UndefHandler SWIHandler b SWIHandler PrefetchAbortHandler b PrefetchAbortHandler DataAbortHandler b DataAbortHandler SetupRamVectors mov r8, of the hard vector in RAM 0x add r9, pc,#-(8+.-VectorTable) where to read values (relative) ldmia r9!, {r0-r7} ; read 8 vectors stmia r8!, {r0-r7} ; store them on RAM ldmia r9!, {r0-r4} ; read 5 absolute handler addresses stmia r8!, {r0-r4} ; store them on RAM AT91 C-startup example

11 ; ;- Memory Controller Initialization ; ;- Copy the Image of the Memory Controller sub r10, pc,#(8+.-InitTableEBI); get the address of the chip ; select register image ldr r12, PtInitRemap ; get the real jump address ( after remap ) ;- Copy Chip Select Register Image to Memory Controller and command remap ldmia r10!, {r0-r9,r11} ; load the complete image and the EBI base stmia r11!, {r0-r9} ; store the complete image with the remap command ;- Jump to ROM at its new address mov pc, r12 ; jump and break the pipeline PtInitRemap DCDInitRemap ; address where to jump after REMAP ; ;- From here, the code is executed from its link address, ie. 0x ; InitRemap AT91 C-startup example

12 ; ;- Stack sizes definition ; IRQ_STACK_SIZEEQU(3*8*4); 3 words FIQ_STACK_SIZE EQU(3*4) ; 3 words ABT_STACK_SIZE EQU(1*4) ; 1 word UND_STACK_SIZE EQU(1*4) ; 1 word ; ;- Top of Stack Definition ; TOP_EXCEPTION_STACK EQU RAM_LIMIT ; Defined in part TOP_APPLICATION_STACK EQU EXT_SRAM_LIMIT ; Defined in Target ; ;- Setup stack for each mode ; ldr r0, =TOP_EXCEPTION_STACK ;- Set up Fast Interrupt Mode and set FIQ Mode Stack msr CPSR_c, #ARM_MODE_FIQ:OR:I_BIT:OR:F_BIT mov r13, r0 ; Init stack FIQ sub r0, r0, #FIQ_STACK_SIZE ;- Set up Interrupt Mode and set IRQ Mode Stack msr CPSR_c, #ARM_MODE_IRQ:OR:I_BIT:OR:F_BIT mov r13, r0 ; Init stack IRQ sub r0, r0, #IRQ_STACK_SIZE ;- Set up Abort Mode and set Abort Mode Stack msr CPSR_c, #ARM_MODE_ABORT:OR:I_BIT:OR:F_BIT mov r13, r0 ; Init stack Abort sub r0, r0, #ABT_STACK_SIZE ;- Set up Undefined Instruction Mode and set Undef Mode Stack msr CPSR_c, #ARM_MODE_UNDEF:OR:I_BIT:OR:F_BIT mov r13, r0 ; Init stack Undef sub r0, r0, #UND_STACK_SIZE ;- Set up Supervisor Mode and set Supervisor Mode Stack msr CPSR_c, #ARM_MODE_SVC:OR:I_BIT:OR:F_BIT mov r13, r0 ; Init stack Sup AT91 C-startup example

13 ; ;- Setup Application Operating Mode and Enable the interrupts ; msr CPSR_c, #ARM_MODE_USER ; set User mode ldr r13, =TOP_APPLICATION_STACK ; Init stack User ; ;- Initialise C variables ; ;- Clear BSS (zero init).weak __ghsbegin_bss.weak __ghsend_bss ldr r1, =__ghsend_bss ; Get pointer to top of BSS ldr r3, =__ghsbegin_bss ; Bottom of BSS mov r2, 0 LoopZI cmp r3, r1 strcc r2, [r3], 4 bcc LoopZI ;- Clear SBSS (zero init).weak __ghsbegin_sbss.weak __ghsend_sbss ldr r1, =__ghsend_sbss ; Get pointer to top of SBSS ldr r3, =__ghsbegin_sbss ; Bottom of SBSS mov r2, 0 LoopZI2 cmp r3, r1 strcc r2, [r3], 4 bcc LoopZI2 AT91 C-startup example

14 ;- Copy Initialized data from FLASH to RAM.weak __ghsbegin_data.weak __ghsend_data.weak __ghsbegin_romdata ldr r0, =__ghsbegin_romdata ; Get pointer to top of romdata ldr r1, =__ghsbegin_data ; Get pointer to top of data ldr r3, =__ghsend_data ; Get pointer to bottom of data LoopRW cmp r1, r3 ldrcc r2, [r0], 4 strcc r2, [r1], 4 bcc LoopRW ; ;- Branch on C code Main function (with interworking) ; IMPORT __main ldr r0, =__main bx r0 END AT91 C-startup example