Embedded System:ARM Software Development 1 ARM Software Development.

Slides:



Advertisements
Similar presentations
CPU Structure and Function
Advertisements

More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
ECE 353 Introduction to Microprocessor Systems
Lab III Real-Time Embedded Operating System for a SoC System.
1 Exceptions, Interrupts & Traps Operating System Hebrew University Spring 2007.
Exceptions. Exception Types Exception Handling Vectoring Interrupts Interrupt Handlers Interrupt Priorities Interrupt applications 6-2.
Computer Organization and Architecture
Computertechniek Hogeschool van Utrecht / Institute for Computer, Communication and Media Technology 1.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Architectures of Digital Information Systems Part 1: Interrupts and DMA dr.ir.
Chapter 12 CPU Structure and Function. CPU Sequence Fetch instructions Interpret instructions Fetch data Process data Write data.
Computer Organization and Architecture
Computer Organization and Architecture
COMP3221: Microprocessors and Embedded Systems Lecture 15: Interrupts I Lecturer: Hui Wu Session 1, 2005.
Architectural Support for OS March 29, 2000 Instructor: Gary Kimura Slides courtesy of Hank Levy.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
CSS 372 Lecture 1 Course Overview: CSS 372 Web page Syllabus Lab Ettiquette Lab Report Format Review of CSS 371: Simple Computer Architecture Traps Interrupts.
1 Computer System Overview OS-1 Course AA
Computer System Overview
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
7/13/20151 Topic 3: Run-Time Environment Memory Model Activation Record Call Convention Storage Allocation Runtime Stack and Heap Garbage Collection.
Software Development and Software Loading in Embedded Systems.
Prardiva Mangilipally
Group 5 Alain J. Percial Paula A. Ortiz Francis X. Ruiz.
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.
Exception and Interrupt Handling
Introduction to Embedded Systems
System Calls 1.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Machine Instruction Characteristics
Introduction to Embedded Systems Rabie A. Ramadan 6.
Chap. 3 ARM CPU Architecture. 2 Outline 3.1 Registers 3.2 Memory 3.3 Exceptions.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 5 part 4 Exceptions.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
Interrupt driven I/O. MIPS RISC Exception Mechanism The processor operates in The processor operates in user mode user mode kernel mode kernel mode Access.
Operating System 1 COMPUTER SYSTEM OVERVIEW Achmad Arwan, S.Kom.
AT91 Interrupt Handling. 2 Stops the execution of main software Redirects the program flow, based on an event, to execute a different software subroutine.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Operating Systems 1 K. Salah Module 1.2: Fundamental Concepts Interrupts System Calls.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
Processor Structure and Function Chapter8:. CPU Structure  CPU must:  Fetch instructions –Read instruction from memory  Interpret instructions –Instruction.
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.
Interrupt driven I/O Computer Organization and Assembly Language: Module 12.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Hello world !!! ASCII representation of hello.c.
ARM7 TDMI INTRODUCTION.
Introduction to Exceptions 1 Introduction to Exceptions ARM Advanced RISC Machines.
Operating Systems A Biswas, Dept. of Information Technology.
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.
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.
Writing Functions in Assembly
MICROPROCESSOR BASED SYSTEM DESIGN
Timer and Interrupts.
Writing Functions in Assembly
Chapter 9 :: Subroutines and Control Abstraction
Process Description and Control
Computer Architecture
ARM Introduction.
Computer System Laboratory
Chapter 11 Processor Structure and function
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

Embedded System:ARM Software Development 1 ARM Software Development

Embedded System:ARM Software Development 2 ARM Software Development Platform ARMulator –An instruction set simulator for various ARM processors. –Support a full ANSI C library to allow complete C programs to run on the simulated system. –The main modules are A model of the ARM Processor core A model of the memory used by the processor (armmap) –Some other predefined modules Model additional hardware, such as a coprocessor or peripherals. Model pre-installed software, such as a C library, semihosting SWI handler, or an operating system. Provide debugging or benchmarking information –You can write your own modules for the above tasks. ARM Development Boards

Embedded System:ARM Software Development 3 Configuring ARMulator Related configuration files –default.ami –peripherals.ami –example.ami What you can do? –Configuring tracer –Configuring profiler –Configuring memory model –Configuring ARMulator to use the peripheral models Chapter 2 of Debug Target Guide

Embedded System:ARM Software Development 4 Writing ARMulator Models Supplied models –Basic models tracer.c, profiler.c, pagetab.c, stackuse.c, nothing.c, semihost.c, dcc.c, mapfile.c –Peripheral models intc.c, timer.c, millisec.c, watchdog.c, tube.c Writing your own models –Using the API provided in Chapter 4 of Debug Target Guide to develop the new model. –Configuring ARMulator to use new models Chapter 3.4 of Debug Target Guide

Embedded System:ARM Software Development 5 Semihosting Provides code running on an ARM target use of facilities on a host computer that is running an ARM debugger. –These include the keyboard input, screen output, and disk I/O. –To allow functions in the C library, such as printf() and scanf(), to use the screen and keyboard of the host. Is implemented by a set of defined software interrupt (SWI) operations. –In many case, the semihosting SWI will be invoked by code within library functions.

Embedded System:ARM Software Development 6 Overview of Semihosting

Embedded System:ARM Software Development 7 SWI Interface SWI instructions contain a field that encode the SWI number used by application code. The SWI number used for semihosting –0x in ARM state –0xABin Thumb state To distinguish between operations, operation type is passed in r0. –0x00 to 0x31 used by ARM –0x32 to 0xFF reserved for future use by ARM –0x100 to 0x1FF reserved for user applications –Example 0x01SYS_OPEN 0x02SYS_CLOSE

Embedded System:ARM Software Development 8 ARM-Thumb Procedure Call Standard (ATPCS) It defines register usage and stack conventions that must be followed in order to enable separately compiled or assembled subroutines to work together. It describes a contract between a calling and a called routine: –Obligations on the caller to create a memory state in which the called routine may start to execute. –Obligations on the called routine to preserve the memory-state of the caller across the call. –The rights of the called routine to alter the memory-state of its caller.

Embedded System:ARM Software Development 9 ATPCS (2) Specifies a family of Procedure Call Standard (PCS) Variants, generated by a cross product of user choices that reflect alternative priorities among: –Code size –Performance –Functionality (Ex. Ease of debugging, run-time checking, …) Contains –A machine-level base standard. –A set of machine-level variants. –Constraints on the layout of activation records and function entry sequences to support stack unwinding. –The representation of externally visible C-language and C++ extern “C”{…} entities.

Embedded System:ARM Software Development 10 Base Standard (1) Defines –a machine-level, integer-only calling standard common to ARM and Thumb, and – a machine-level floating-point standard for ARM. The base standard does not provide for –Interworking between ARM state and Thumb state. –Position independence of either data or code. –Re-entry to routines with independent data for each invocation. –Stack checking. They are specified by the PCS variants.

Embedded System:ARM Software Development 11 Base Standard (2) Machine registers

Embedded System:ARM Software Development 12 Base Standard (3) Floating point registers –FPA architecture Eight floating-point registers, f0-f7 Each may hold a value of single, double or extended precision. –VFP architecture Sixteen double-precision registers, d0-d15 each may also be used to hold two single precision numbers. No extended precision

Embedded System:ARM Software Development 13 Base Standard (4) Routine call can be implemented by any instruction sequence that has the effect: LR <--- Return address PC <--- Destination address –A subroutine call preserves the values of r4-r11 and SP Parameter Passing –Types 32-bit integers Single-precision floating-point numbers Double-precision floating-point numbers

Embedded System:ARM Software Development 14 Base Standard (4) Parameter Passing (cont.) –A source language parameter value is converted to a machine parameter value as follows: An integer value narrower than 32 bits: widen to 32 bits A 64-bit integer: treated as two 32-bit integer values A floating-point value –One or more floating-point values of the corresponding machine types if floating point hardware exists. –A sequence of integer machine words if floating-point operation is simulated. Others –Converted to a sequence of 32-bit integers

Embedded System:ARM Software Development 15 Base Standard (5) Parameter passing (cont.) –Variadic routines (passing variable number of parameters) Loading the first 4 words into integers a1-a4 (lowest addressed into a1). Pushing remaining words onto the stack in reverse order. –A floating point value can be passed in integer registers, or can be split between an integer register and memory. –Non-variadic routines The first N floating-point values are assigned to floating- point argument registers. The rest is the same as Variadic routine.

Embedded System:ARM Software Development 16 Base Standard (6) Result Return –A procedure returns no result. –A function returns a single value; a value occupies 1 or more words Integer function –Must return a 1-word value in a1 –May return a value of length 2-4 words in a1-a2, a1-a3, a1-a4. –Must return a longer value indirectly in memory. Floating-point function FPA procedure call standard VFP procedure call standard No floating-point hardware procedure call standard

Embedded System:ARM Software Development 17 Standard Variants (1) ARM and Thumb interworking Read-only position-independence (ROPI) –A read-only segment of a program can be loaded and used at any address Read-write position-independence (RWPI) –A read-write segment of a program can be loaded and executed at any address. Re-entrant code –A program which is RWPI is also re-entrant. Shared libraries –A shared library is a re-entrant program to which other programs may link at execution time.

Embedded System:ARM Software Development 18 Standard Variants (2) Stack limit checking –SL (Stack limit) must point at least 256 bytes above the lowest usable address in the stack. –SL must not be altered by code compiled or assembled with stack limit checking selected. –The value held SP (stack pointer) must always greater than or equal to the value in SL.

Embedded System:ARM Software Development 19 Interworking ARM and Thumb (1) Interworking –Mixing ARM and Thumb code as you wish. –The ARM linker alters call and return instructions, or insert small code sections called veneers, to change processor states as necessary when it detects a state change exist. –Why interworking? Thumb state provides good code density, but we need the application running in ARM state because of –Speed –Functionality (enable or disable interrupts can only be done in ARM state) Exception handling A Thumb-capable ARM processor always starts in ARM state

Embedded System:ARM Software Development 20 Interworking ARM and Thumb (2) Use –apcs/interwork options for assembler and compilers –The compiler or assembler records an interworking attribute in the object file. –The linker provides interworking veneers for subroutine entry. –In assembly language, you must write function exit code that returns to the instruction set state of the caller. –In C or C++, the compiler creates function exit code. When to use? If your object file contains: –Thumb subroutines that might need to return to ARM state. –ARM subroutines that might need to return to Thumb state. –Thumb subroutines that might make indirect or virtual calls to ARM state. –ARM subroutines that might make indirect or virtual calls to Thumb state.

Embedded System:ARM Software Development 21 Assembly Language interworking Instructions perform processor state change –BX Rn The value of bit 0 of the branch address determines the processor state –If bit 0 is set, the instructions at the branch address are executed in Thumb state. –If not, the instructions at the branch address are executed in ARM state –BLX, LDR, LDM, and POP (ARM architecture v5 only) Assembly directives –CODE16 –CODE32

Embedded System:ARM Software Development 22 Assembly Language interworking-Example

Embedded System:ARM Software Development 23 C and C++ Interworking-Example

Embedded System:ARM Software Development 24 Veneer Creation by Compiler

Embedded System:ARM Software Development 25 Assembly Language interworking Using Veneers - Example

Embedded System:ARM Software Development 26 Veneers Creation by Linker

Embedded System:ARM Software Development 27 Mixing C, C++ and Assembly Language In-line assembler Accessing C global variables Using C header files from C++ Calling between C, C++, and ARM assembly language

Embedded System:ARM Software Development 28 In-line Assembler

Embedded System:ARM Software Development 29 Accessing C global variables To access a global variable, use the IMPORT directive to import the global and then load the address into a register.

Embedded System:ARM Software Development 30 Handling Processor Exceptions Why normal processor execution interrupted? –To handle some events such as Externally generated interrupts An attempt by the processor to execute an undefined instruction Accessing privileged operating system functions Others –Basic rules of handling exceptions After handling the exception, the processor execution can be resumed with a previous processor status.

Embedded System:ARM Software Development 31 Exception Types

Embedded System:ARM Software Development 32 Exception Priorities

Embedded System:ARM Software Development 33 Entering an Exception When an exception is generated, the processor takes the following actions: –Copies the CPSR into SPSR for the mode in which the exception is to be handled. –Change the appropriate CPSR mode bits in order to Change to the appropriate mode, and map in the appropriate banked registers for that mode. Disable interrupts. –IRQs are disabled when any exception occurs. –FIQs are disabled when a FIQ occurs, and on reset. Set lr_mode to the return address Set PC to the vector address for the exception.

Embedded System:ARM Software Development 34 Returning from an Exception The actions taken by the processor –Restore the CPSR from SPSR_mode –Restore the PC using return address stored in lr_mode The way to return depends on whether a stack is used during entering the subroutine –Without a stack Performing a data processing instruction with S flag set and the PC as the destination register. –With a stack Restoring the saved registers by performing –LDMFDsp!, {r0-r12,pc}^ –^ indicates that the CPSR is restored from the SPSR

Embedded System:ARM Software Development 35 Returning from SWI and Undefined Instruction Handlers SWI and UI exceptions are generated by the instruction itself, so the PC is not updated when the exception is taken. Thus, storing (PC-4) in lr_mode makes lr_mode points to the next instruction be executed. SWI xxx  being executed  PC-8 INST-1  being decoded  PC-4 INST-2  being fetched  PC Restoring the PC from lr –Without a stack MOVSpc, lr –With a stack STMFDsp!, {reglist,lr} … LDMFDsp!, {reglist, pc}^

Embedded System:ARM Software Development 36 Returning from FIQ and IRQ Check IRQ and FIQ at the end of executing each instruction. INST-1  being executed  PC-12, IRQ or FIQ checked INST-2  being decoded  PC-8 INST-3  being fetched  PC-4 INST-4  PC Restoring PC from lr –Without a stack SUBSpc, lr, #4 –With a stack SUBlr, lr, #4 STMFDsp!, {reglist, lr} … LDMFDsp!, {reglist, pc}^

Embedded System:ARM Software Development 37 Returning from Prefetch Abort Prefetch abort is generated when it reaches the execution stage. INST-1  being executed  PC-8, Aborted INST-2  being decoded  PC-4 INST-3  being fetched  PC Restoring PC from lr –Without a stack SUBSpc, lr, #4 –With a stack SUBlr, lr, #4 STMFDsp!, {reglist, lr} … LDMFDsp!, {reglist, pc}^

Embedded System:ARM Software Development 38 Returning from Data Abort When a data abort occurs, the program counter has been updated. INST-1  being executed  PC-12, Aborted INST-2  being decoded  PC-8 INST-3  being fetched  PC-4 INST-4  PC Restoring PC from lr –Without a stack SUBSpc, lr, #8 –With a stack SUBlr, lr, #8 STMFDsp!, {reglist, lr} … LDMFDsp!, {reglist, pc}^

Embedded System:ARM Software Development 39 Install an Exception Handler Exception handlers can be reached by the instruction contained in each entry in the vector table: –A branch instruction PC relative –A load PC instruction The absolute address of a handler must be stored in a suitable memory location.

Embedded System:ARM Software Development 40 Installing the Handlers at Reset (1) If the ROM is at location 0x0 in memory (load PC can be replaced by branch)

Embedded System:ARM Software Development 41 Installing the Handlers at Reset (2) If the RAM is at location 0x0 in memory

Embedded System:ARM Software Development 42 Installing the Handler from C (1) Branch Method 1.Take the address of the exception handler. 2.Subtract the address of the corresponding vector. 3.Subtract 0x8 to allow for prefetching. 4.Shift the result to the right by two to give a word offset, rather than a byte offset. 5.Test the top eight bits of this are clear. 6.Logically OR this with 0xEA (the Opcode for the branch instruction) to produce the value to be placed in the vector.

Embedded System:ARM Software Development 43 Installing the Handler from C (2) Example for branch method

Embedded System:ARM Software Development 44 Installing the Handler from C (3) Load PC method Steps 1, 2, and 3 are the same as branch method. 4. Logically OR this with 0xE59FF000 (the Opcode for LDR pc, [pc, #offset]) to produce the value to be placed in the vector. 5. Push the address of the handler into the storage location Example

Embedded System:ARM Software Development 45 SWI Handlers ARM SWI instruction Work to be done by the handler –First load the SWI instruction into a register by LDR r0, [lr, # -4] Why? SWI  being executed  PC-8 INST-1  decoded  PC-4 INST-2  fetched  PC –Obtain the SWI number by BIC r0, r0, #0xFF000000

Embedded System:ARM Software Development 46 SWI Handlers - Example

Embedded System:ARM Software Development 47 SWI Handlers in Assembly Language According to the value in r0, jump to the corresponding handler.

Embedded System:ARM Software Development 48 SWI Handlers in C and Assembly Lang. Add the following line to the SWI_handler routine in page 46. BL C_SWI_handler

Embedded System:ARM Software Development 49 Using SWIs in Supervisor Mode Must store lr_svc and spsr_svc

Embedded System:ARM Software Development 50 Calling SWIs from an Application (1) Use __swi directive. This allows a SWI to be compiled inline, without overhead, if –Any arguments are passed in r0-r3 only, and –Any results are returned in r0-r3 only. If more than four results are returned, we have to use a struct to store the results and use the _ _value_in_regs directive.

Embedded System:ARM Software Development 51 Calling SWIs from an Application (2)

Embedded System:ARM Software Development 52 Calling SWIs from an Application (3)

Embedded System:ARM Software Development 53 Simple Interrupt Handlers in C (1) IRQ and FIQ handlers Use _ _ irq keyword that –Preserves all APCS corruptible registers –Preserves all other registers used by the function –Exits the function by setting the program counter to lr-4 and restoring the CPSR to its original value.

Embedded System:ARM Software Development 54 Simple Interrupt Handlers in C (2) After compilation

Embedded System:ARM Software Development 55 Reentrant Interrupt Handlers (1) The following steps are needed to safely re-enable interrupts in an IRQ (FIQ) handler:

Embedded System:ARM Software Development 56 Reentrant Interrupt Handlers (2)

Embedded System:ARM Software Development 57 Operations Done by Reset Handlers For example –Set up exception vectors. –Initialize stacks and registers. –Initialize the memory system, if using MMU. –Initialize any critical I/O devices. –Enable interrupts. –Change processor mode and/or state. –Initialize variables required by C and call the main application.

Embedded System:ARM Software Development 58 Undefined Instruction Handlers It is often used to emulate a coprocessor. Such an emulator must: –Attach itself to the Undefined Instruction vector. –Examine the undefined instruction to see if it should be emulated. –Otherwise the emulator must pass the exception onto the original handler using the vector stored when the emulator was installed.

Embedded System:ARM Software Development 59 Prefetch Abort Handler or Data Abort If no MMU, report error. Otherwise, the related handler is executed to deal with the virtual memory fault. Depending on whether the instruction that causes abort is re-executed or not, the return address should be properly set. –Prefetch abort INST-aborted  executed  PC-8 INST-1  decoded  PC-4 INST-2  fetched  PC

Embedded System:ARM Software Development 60 Handling Exceptions on Thumb-capable Processors