Design and Analysis of Boot Code for ARM RISC Microprocessor

Publisher:不见南师久Latest update time:2018-02-16 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

    ARM Architecture

    At present, the ARM series of general-purpose 32-bit RISC microprocessors include ARM7, ARM9, ARM9E, ARM10 and other products. These processors can work in 7 modes. All modes except User mode are called privileged modes, and the other 5 modes except User and System are called exception modes. Most applications run in User mode. When the processor is in User mode, the executed program cannot access some protected system resources to facilitate the use of system resources by the operating system, and the mode cannot be changed, otherwise an exception will occur. For System mode, no exception will cause entry into this mode, and the registers it uses are basically the same as those in User mode. It is mainly used for operating system tasks that have access to system resources but avoid using additional registers. In privileged mode, they can fully access system resources and can change modes freely. When handling specific exceptions, the system enters the corresponding exception mode. These 5 exception modes have their own additional registers to avoid conflicts with programs in user mode when exceptions occur.

    In any processor mode, the same register is used to identify the current processor working mode. This register is called CPSR (Current Program Status Register). Its 0~4 bits are used to indicate the CPU mode. In each processor exception mode, there is a corresponding SPSR (Cache Program Status Register) to save the value of the CPSR before entering the exception mode. The function of SPSR is that when the CPU exits from the exception mode, a simple assembly instruction can restore the CPSR before entering the exception mode. The value is saved in the SPSR of the current exception mode.

    Design of startup code

The startup code is similar to the BIOS     in a computer . It takes over the CPU from the moment the system is powered on. It is responsible for initializing the CPU stack space in various modes, setting the CPU memory map, initializing various control registers of the system, initializing the CPU's external memory , setting the base address of each peripheral device, creating the correct interrupt vector table, creating the ZI (zero creation) area for C code execution, and then entering the C code. In the C code, the clock and RS232 port are initialized, and then the system interrupt enable bit is turned on. Finally, the application code is executed, responding to various interrupt signals during execution and calling pre-set interrupt service routines to handle these interrupts. The flowchart of the entire process is shown in Figure 1.

twenty three

Figure 1 Startup code flow chart

      Stack initialization

      The initialization of the stack is to allocate stack space for the seven processor modes of the processor. The following is an example of the stack setting in FIQ mode:

    ORR r1, r0, # LOC KOUT | FIQ_MODE; put the mode in r1, LOCKOUT is used to mask the interrupt bit;

    MSR cpsr, r1; Change the CPU's CPSR register and enter the specified FIQ mode;

    MSR spsr, r2 ;Save the previous mode;

    LDR sp, =FIQ_STACK ; Assign the starting value of the stack in FIQ mode to the current SP. FIQ_STACK is the starting address of the stack space allocated to FIQ mode (for example, 1K bytes). Set the stack in other modes in this way.

    DRAM initialization is determined by the system configuration information, because the system may not necessarily use DRAM, but SDRAM initialization must be done. The main processing content is the setting of ROM and RAM base addresses, the width of the data bus, the refresh time of SDRAM, etc. These can be referred to the user manual of the S3C4510B chip. The setting of special registers is mainly for I/O ports, for example, setting several I/O bits for system status indicator LEDs . The setting of registers is mainly based on the hardware configuration. It is worth noting that since this startup code is burned into ROM, and the interrupt vector must be located at address zero, the ROM base address should be set to address zero before the storage unit is remapped.

    The main purpose of copying (image) is to increase the running speed. The compiled image file code is copied from ROM to RAM, and the program is executed in RAM. Of course, the startup code does not have a very strict requirement for the running speed, so this copying action can be omitted, so that the code is stored in ROM, the code is also executed in ROM, and the data required for operation is in RAM.

    Memory initialization is to open up memory areas for the operation of C code. After the code is compiled, it will be divided into three areas: read-only area, readable and writable area,

    Zero initialization area. The initialization process of the memory is as follows: when the end address of the read-only area is equal to the base address of the readable and writable area, clear all bytes in the zero initialization area; when the end address of the read-only area is not equal to the base address of the readable and writable area, if the base address of the readable and writable area is less than the zero initialization base address, copy the data from the end address of the read-only area to the base address of the readable and writable area until it reaches the zero initialization base address, and then clear all bytes in the zero initialization area, otherwise, only clear all bytes in the zero initialization area.

    The interrupt vector table is used to handle exceptions. When an exception occurs, the return address of the current program and the value of the CPSR register must be saved first, and then the corresponding exception vector address must be entered. Generally speaking, the exception vector address is a jump instruction, which allows the program to enter the corresponding exception handling process. Since the interrupt vector table must be located at the zero address of the system, when the startup code is burned into the EEPROM and run, the address of the ROM must be defined to the zero address, so the program entry is as follows:67

    System remapping When you copy the ROM Image to RAM to increase the running speed, the interrupt vector table is not at the zero address, so you need to remap the storage unit and reset the RAM address to zero address. Mapping is to copy the startup code from ROM (EEPROM or Flash) to SDRAM for execution, and remap the memory after the copy is completed, mapping SDRAM to the original ROM address (0x0000), so that the code in SDRAM can be used to write Flash, so that the program code can be updated. However, it should be noted that if the program is mapped, it will bring difficulties to online debugging, making online debugging impossible to perform in RAM (if the code written to EEPROM is mapped, the program will inevitably be mapped when the debugger is started, so that the program cannot be located at the original location in the debugger, causing debugging to fail). A compromise method is not to map, that is, downloading cannot be used in the debugged code, so that it can be debugged like ordinary code.

  Conclusion

  After completing these initializations, switch the CPU to user mode and assign the stack pointer SP to the user stack area, then enter the C code area to run. Continue to initialize the clock and RS232 port in the C code, then turn on the system interrupt enable bit and enter the application code to execute. After this program is loaded into the processor S3C4510B and debugged, the CPU can start normally and respond to interrupt requests in a timely manner. The main code of the upper-level application can be loaded into the Flash, and the scheduling control of multi-tasks is normal after transplanting the real-time operating system RTXC.


Keywords:ARM Reference address:Design and Analysis of Boot Code for ARM RISC Microprocessor

Previous article:Introduction to the process of porting MiniGUI to S3C2440
Next article:The advantages of ARM core processors

Recommended ReadingLatest update time:2024-11-16 21:39

$40 billion deal: UK leans towards rejecting NVIDIA's acquisition of ARM
NVIDA's acquisition of ARM has not yet been approved by major countries and regions. The UK, where ARM's headquarters is located, is also not happy to see ARM being acquired by NVIDIA. The latest news says that the UK is inclined to reject NVIDIA's acquisition of ARM, but the final decision still needs to wait. This
[Semiconductor design/manufacturing]
A Design Scheme of Logistics Re-inspection System Based on ARM-LINUX
Abstract: The role of sorting in modern logistics is particularly important. In order to ensure the accuracy of sorting, a logistics re-inspection system design based on ARM-LINUX is proposed. The system adopts a master-slave architecture of the main control node and the terminal node. The terminal node and the main c
[Microcontroller]
A Design Scheme of Logistics Re-inspection System Based on ARM-LINUX
【ARM】Timer
PWM Timer   PWN: Pulse Width Modulation   Each timer has a dedicated 16-bit down counter driven by the timer clock. When the count value of the down counter reaches 0, a timer interrupt request is generated to notify the CPU that the timer operation is completed. When the timer down counter reaches 0, the correspondin
[Microcontroller]
qemu+chroot build arm aarch64 virtual machine
Building an arm virtual machine in an X86 environment can simulate the arm environment for development, install corresponding library files in the arm linux file system, compile the arm version, etc. Briefly introduce the steps to build an ARM virtual machine in an X86 environment. 1. Install qemu-user-static in x
[Microcontroller]
ARM LPC2132 Flowing Light LCD1602
1. Assembler GPADIR             EQU            0xE0028008 GPASET            EQU            0xE0028004 GPACLR            EQU            0xE002800C                         EXPORT xmain                         AREA    Init,CODE,READONLY                         ENTRY xmain                         ldr r0,=GPADIR  
[Microcontroller]
ARM LPC2132 Flowing Light LCD1602
Design of electronic control throttle based on ARM-Linux of Samsung S3C2410
  introduction   The cruise control system (CCS) was developed in the 1960s and is also known as a constant speed driving system. When the cruise control system is working, the ECU determines the operating status of the car based on the signals sent by various sensors, and automatically adjusts the throttle opening
[Microcontroller]
Design of electronic control throttle based on ARM-Linux of Samsung S3C2410
Pi Zi Heng Embedded: ARM Cortex-M Core (2) - The First Microcontroller
1. Born to Glory: The Origin of ARM Cortex-M Processor   When ARM introduced the ARMv7 core architecture in 2004, it abandoned the previous "ARM+number" processor naming method (processors before ARM11 were collectively called classic processor series), re-enabled the Cortex naming method, and subdivided the Cortex se
[Microcontroller]
Design of A/D and ARM interface of ultrasonic thickness measurement system using FIFO
In high-frequency ultrasonic data acquisition systems, many high-speed A/D converters often cannot be directly connected to the processor. In this case, FIFO is needed to build a bridge between the processor and the A/D converter. The first-in, first-out feature of FIFO can easily cache a large number of data blocks. I
[Microcontroller]
Design of A/D and ARM interface of ultrasonic thickness measurement system using FIFO
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号