(I) Understanding of ARM processor Remap My understanding of relocation: Regarding relocation, based on NOR BOOT, it is necessary to calculate the offset after the code is moved, and the global variable address needs to be added to this offset. Global variables are divided into initialized and uninitialized global variables, RO, RW, BSS (II) How to use ads (axd) correctly (III) Startup process and REMAP based on S3C4510B system 1 Introduction to S3C4510B S3C4510B, based on Ethernet, 16/32-bit RISC microprocessor. The chip integrates 8KB Cache/SRAM and Ethernet controller, and can be expanded with ROM, Flash, SDRAM and other storage chips. There is no program memory inside the S3C4510B chip, and all programs are stored in the ROM and Flash that are extended outside the chip. At the beginning of the startup, the ROM or Flash containing the startup code will be mapped to the address 0x00, and the system will start running from then on. However, in actual applications, in order to improve the real-time performance of the system and speed up the execution of the code, the program is often moved to the RAM after the system starts, because the access speed of the RAM is much faster than that of the ROM, which greatly improves the performance of the system. Since the abnormal interrupt entry address in the S3C4510B chip is fixed in the 8 words starting from 0x00, the system can only reallocate the address space and map the RAM to the address 0x00, which is the reason for Remap. There are several special registers inside the S3C4510B, which are used to implement the mapping of address space and storage media inside and outside the chip. The brief introduction of these registers is as follows: SYSCFG: Set the starting address of special registers and the starting address of on-chip SRAM. EXTDBWTH: Set the data line width of the chip mapped by each Bank register. ROMCON0~ROMCON5: Set the start and end addresses of the system's on-chip expansion ROM and Flash. DRAMCON0~DRAMCON3: Set the start and end addresses of the off-chip expansion RAM in the system. The physical address of the special register segment in the S3C4510B chip is 0x3ff0000. For the offset address of each special register, please refer to the technical manual of the S3C4510B. Implementation of Remap in 2S3C4510B System The reallocation of address space is closely related to the hardware structure of the processor. Generally speaking, the address remapping mechanism in a 32-bit system can be divided into two cases: one is that the dedicated register inside the processor can complete the remap, so you only need to set the corresponding position of the remap register to 1, and the address remapping is completed by hardware logic, such as the AtmelAT91xx series; the other is that there is no dedicated remap control register, and the bank register inside the processor used to control the start and end addresses of the memory needs to be rewritten to implement the remap process. S3C4510B belongs to the second case. 2.1 Hardware system structure and address allocation Assume that the system is built with reference to the test board provided by Samsung, where the ROM capacity is 512KB, 8-bit data bus, the address range before Remap is 0x0000000~0x0100000, and the address range after Remap is 0x1000000~0x1100000; the RAM capacity is 16MB, 32-bit data bus, the address range before Remap is 0x0100000~0x100000, and the address range after Remap is 0x0000000~0x1000000; the Flash capacity is 2MB, 16-bit data bus, and the address before and after Remap is unchanged, both 0x1100000~0x1300000. The address mapping relationship before and after Remap is shown in Figure 2. 2.2 System startup process and Remap implementation The system address remapping should be completed during system startup. The following is the Remap startup process of S3C4510B. ① Setting of system special registers. It mainly configures the registers used to implement address space and chip internal and external storage media mapping as described above. In this system, the configuration is as follows: SYSCFG=0x87ffff90 EXTDBWTH=0x3001 ROMCON0 = 0x01000060 ROMCON1 = 0x13044060 DRAMCON0 = 0x11004060 ② Initialize the system stack. There are seven working modes in the ARM7 architecture. Different modes have different stack pointers and do not interfere with each other. Each mode corresponds to different exception interrupts. As for which mode's stack needs to be initialized, it depends on which interrupts the user uses and what types of exceptions the system needs to handle. Generally speaking, the manager (SVC) stack must be set, and if the IRQ interrupt is used, the IRQ stack must also be set. One thing to note is that in order to ensure that the program runs normally after remap, all stacks should be set in the high-end address of RAM. ③ Initialize the I/O ports, UART, timer, interrupt controller and other resources used in the system. Before initializing the exception vector table or modifying the entry address in the exception vector table, turn off all interrupts. ④ Initialization of the exception vector table. Write the entry address of the exception handler into the corresponding exception vector in RAM. It must be ensured that the exception vector table will never be overwritten by the code and data moved from ROM to RAM. For this reason, the exception vector table is generally defined in the high-end address in RAM. ⑤ Migration of program code and data. After Remap, RAM is mapped to the address space of 0x0000, and ROM is moved to the high-end address. To ensure that the program can run after Remap, the code and data in ROM must be moved to RAM without changing the address. This is the key to the success of Remap. There are two ways to achieve migration. One is to directly move the entire ROM address space to RAM regardless of the actual code space size. Of course, this method is not suitable for use in real startup code, but it can be used to check whether the stack and exception interrupt settings are reasonable when doing preliminary remap tests. Another method is more complicated. It uses the positioning information generated by the SDT linker ARMLink to move only the valid code and data segments of the RO to RAM. ARMLink links the compiled program into an ELF file. There are three output segments in the image file: RO segment, RW segment and ZI segment. These three output segments contain read-only code and a small amount of data contained in the code segment, readable and writable data, and data initialized to 0. ARMLink also generates the start and end positioning information of these three output segments: Image RORO Base、Image RORO Limit、Image R Base、Image Limit、ImageLimit、Image Linit and Image ZIZI Limit. You can use this positioning information in the program. Move the code and data in ROM to RAM. The implementation code is as follows: Data definition: BaseOfROMDCD|Image RORO Base| TopOfROMDCD|Image RORO Limit| BaseOfBSSDCD|Image R Base| BaseOfZeroDCD|Image ZIZI Base| EndOfBSSDCD|Image ZIZI Limit| Source program: ; Move the program in ROM to RAM, and the remapped address remains unchanged adrr0,ResetEntry; the starting address of the program in ROM movr3,#(RamBaseAddr<<16);RamBaseAddr=0x100 Idrr1,BaseOfROM Idrr2,TopOfROM Addr1,r1,r3 Addr2,r2,r3 0 Idmiar0!,{r4-r11} Stmiar1!,{r4-r11} Cmpr1,r2 Bcc%B0 ; Move the pre-initialized variables in the RW segment to RAM subr1,r1,r2 subr0,r0,r1; point r0 to the end of the RO segment, that is, the beginning of the RW segment ldrr1,BaseOfBSS Idrr2,BaseOfZero Addr1,r1,3 Addr2,r2,r3 1; Relative jump based on local label, PC + offset address, generates position-independent code cmpr1,r2 ldrccr4,[r0],#4 strccr4,[r1],#4 bcc%B1 ; Then move the ZI segment to RAM and initialize it to 0 movr0,#0 Idrr2,EndOfBSS Addr2,r2,r3 2 cmpr1,2 strccr0,[r1],#4 bcc%B2 ⑥ Address remapping. The remap process in S3C4510B is actually very simple. You only need to re-set ROMCON0~ROMCON5 and DRAMCON0~DRAMCON3. In this system, you only need to re-set ROMCON0 and DRAMCON0. source code: ;/*Memory control register reset - storage space remap address space*/ EXPORTRemapMemory RemapMemory movr12,r14 adrr0,RemapMem ldmiar0,{r1-r11} ldrr0,=ROMCON0;ROMCON0 is the starting address of the Bank register stmiar0,{r1-r11} blExceptionTalbeInit; interrupt vector table reinitialization movpc,r12 RemapMem DCD&11040060;/*ROMCON00x1000000~0x1100000*/ … DCD&10000398;/*DRACON00x0~0x1000000*/ … ⑦ Enter the C code space and start running the main program. At this time, the code should be running in RAM. The above steps can be appropriately added or deleted according to actual needs. It is worth noting that the code generated by the assembly should be position-independent code, that is, the code can be mapped to different address spaces during operation, and the jump instructions are all relative jump instructions based on the PC register. The PC-based label is a label located before the target instruction or before the data definition pseudo-operation in the program. This symbol will be processed as the PC value plus or minus a numeric constant during assembly. 3. Handling of abnormal interruption In the Remap startup code, special attention should be paid to the handling of abnormal interrupts. In S3C4510B, the entry addresses of abnormal interrupts are fixed and arranged in the order of Table 1. Table 1 Exception type Working mode Normal address Reset Management 0x00000000 Undefined instruction Undefined 0x00000004 Software interrupt (SWI) Management 0x00000008 Prefetch abort Abort 0x0000000 Data abort Abort 0x00000010 Reserved - 0x00000014 IRQ (interrupt) IRQ 0x00000018 FIQ (fast interrupt) FIQ 0x0000001 After the address is remapped, the entry address is mapped to RAM, and the interrupt processing code is also moved to the RAM address space. At this time, the speed of interrupt response and interrupt processing will be greatly accelerated, which will help improve the real-time performance of the entire system. The design structure of the exception interrupt vector table is shown in Figure 3. Below is the source code of each part (taking IRQ exception interrupt as an example). Definition of exception vector table: (When the system is initialized, the exception handling code entry address is written into the vector table in the exception) _RAM_END_ADDREQU0x01000000; The end address of RAM after remapping MAP(_RAM_END_ADDR - 0x100) SYS_RST_VECTOR#4 UDF_INS_VECTOR#4 SWI_SVC_VECTOR#4 INS_ABT_VECTOR#4 DAT_ABT_VECTOR#4 RESERVED_VECTOR#4 IRQ_SVC_VECTOR#4 FIQ_SVC_VECTOR#4 Exception initialization code: … bIRQ_SVC_HANDLER;0x18 … IRQ_SVC_HANDLER SUBsp,sp,#4; Full decrement stack STMFDsp!,{r0} LDRr0,=IRQ_SVC_VECTOR; read the interrupt vector, ;IRQ_SVC_VECTOR=SystemrqHandle LDRr0,[r0] STRr0,[sp,#4] LDMFDsp!,{r0,pc}; Jump to the exception interrupt processing code entry Exception handling entry code: … SystemIrqHandler IMPORTISR_IrqHandler STMFDsp!,{r0-r12,lr} BLISR_IrqHandler; Jump to the exception interrupt handler ISR_IrqHandler in C code LDMFDsp!,{r0-r12,lr} SUBSpc,lr,#4 … In the above structure, regardless of whether the system performs address remapping, the exception interrupt vector can be changed dynamically at runtime, which greatly improves the flexibility of interrupt processing. The interrupt vector can point to different exception handling code entries at runtime. |
Previous article:Method of relocating ARM interrupt vector table to off-chip RAM
Next article:Use of STM32 external memory
Recommended ReadingLatest update time:2024-11-16 14:48
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Analog Electronics Course Test] + Measurement and Optimization of ADC Frequency Domain Indicators
- Please recommend a low-power DC motor driver chip!
- Selection method and principle of infrared temperature sensor
- Several gadgets that RF engineers cannot miss
- Application of TPS61046 dual output in optical communication
- MicroPython v2.0 roadmap
- Computer power supply plus current regulation
- PCB design software Protel 99 SE and AD copper-free hole and copper-free slot design
- Why is a bootstrap circuit used in BUCK power chip?
- The states of the terminal device in the TI ZigBee protocol stack involved in the protocol stack