Файл: Embedded system development and labs for ARM (R. Muresan, 2005).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 13.06.2025
Просмотров: 2358
Скачиваний: 5
Embedded Systems Development and Labs; The English Edition
The program status register CPSR and SPAR in 3.2.4 includes condition code flags, interrupt disable bit, current processor mode bits, etc. Each exception mode has a Saved Program Status Registers (SPSR). When exceptions happen, SPSR is used to save the status of CPSR.
The format of CPSR and SPSR is as following:
1) Condition Code Flags
The N, Z, C and V bits are the condition code flags that most of ARM instruction can be detected. These flags can be used to decide how to execute the programs.
2) Control Bits
The bottom 8 bits I, F, T, M, M, M, M, M are used as control bits. When exception happens, the control bits can be changed; when the processor working at the supervisor mode, these bits can be changed by software.
●Interruption disable bit: The I and F bits are the interrupt disable bits. When set, these disable the IRQ and FIQ interrupts respectively.
●The T bit: This reflects the operating state. When this bit is set, the processor is executing in THUMB state, otherwise it is executing in ARM state. The instructions that can switch the states between ARM and Thumb can be used freely.
●Mode Bits: The M4, M3, M2, M1 and M0 bits (M [4:0]) are the mode bits. These determine the processor’s operating mode, as shown in Table 3-3.
99
Embedded Systems Development and Labs; The English Edition
Table 3-3 ARM Work Modes M [4:0]
3) Other Bits
The other bits of status register are reserved for extension in the future.
3. The Command Line Parameters of ld Used in This Lab
-Ttext org
The “org” is used as the start address of the text segment. Org must be a hex number.
3.4.5 Operation Steps of the Lab
1)Refer to Step 1 of 3.1.5 Lab A, create a new project and name it as ARMMode.
2)Refer to Step 2 of 3.1.5 Lab A, and the sample source file, input the source code of the Lab. After the edition finished, save the file as ARMMode.s
3)Select Project->Add To Project Files item, or right click the project management window and select the same item. A dialog will open. Select the source file that has just been created.
4)Refer to Step 2 of 3.1.5 Lab A, finish the related settings.
Note: At the Link Option in the Linker page, manually add “-Ttext 0x0” that specifies the start address of the data segment. This is shown in Figure 3-8.
5)Refer to Step 5 of 3.1.5 Lab A, generate the object code.
6)In the Download Address, the download address should be the same as the start address at the Linker page.
7)Select Debug->Remote Connection to connect the software emulator. Execute the download command; open the register window.
8)Single step execute the program. Watch and record how the value changes in R0 and CPSR and in the 36 registers after the value is written. Specially notice the value changes in of R13 and R14 in every mode.
100
Embedded Systems Development and Labs; The English Edition
Figure 3-8 Embest IDE Linker Settings
Figure 3-9 Embest IDE Debug Settings
9) Combined with the contents of the Lab and related technology materials, watch the program run. Get a deeper
101
Embedded Systems Development and Labs; The English Edition
understanding of the usage of the registers in different modes.
10) After understanding and mastering the lab, finish the Lab exercises.
3.4.6 Sample Programs of the Lab
.global _start
.text _start:
# --- Setup interrupt / exception vectors
B |
Reset_Handler |
Undefined_Handler: |
|
B |
Undefined_Handler |
B |
SWI_Handler |
Prefetch_Handler: |
|
B |
Prefetch_Handler |
Abort_Handler: |
|
B |
Abort_Handler |
NOP |
/* Reserved vector */ |
IRQ_Handler: |
|
B |
IRQ_Handler |
FIQ_Handler: |
|
B |
FIQ_Handler |
SWI_Handler:
mov pc, lr
Reset_Handler:
#into System mode MRS R0,CPSR
BIC R0,R0,#0x1F
ORR R0,R0,#0x1F MSR CPSR,R0 MOV R0, #1 MOV R1, #2 MOV R2, #3 MOV R3, #4 MOV R4, #5 MOV R5, #6 MOV R6, #7 MOV R7, #8
102
Embedded Systems Development and Labs; The English Edition
MOV R8, #9
MOV R9, #10
MOV R10, #11
MOV R11, #12
MOV R12, #13
MOV R13, #14
MOV R14, #15
#into FIQ mode
MRS R0,CPSR BIC R0,R0,#0x1F ORR R0,R0,#0x11 MSR CPSR,R0 MOV R8, #16 MOV R9, #17 MOV R10, #18 MOV R11, #19 MOV R12, #20 MOV R13, #21 MOV R14, #22
#into SVC mode
MRS R0,CPSR BIC R0,R0,#0x1F ORR R0,R0,#0x13 MSR CPSR,R0 MOV R13, #23 MOV R14, #24
#into Abort mode
MRS R0,CPSR BIC R0,R0,#0x1F ORR R0,R0,#0x17 MSR CPSR,R0 MOV R13, #25 MOV R14, #26
#into IRQ mode
MRS R0,CPSR BIC R0,R0,#0x1F ORR R0,R0,#0x12 MSR CPSR,R0 MOV R13, #27 MOV R14, #28
103
Embedded Systems Development and Labs; The English Edition
#into UNDEF mode MRS R0,CPSR
BIC R0,R0,#0x1F
ORR R0,R0,#0x1b MSR CPSR,R0 MOV R13, #29 MOV R14, #30
B Reset_Handler
.end
3.4.7 Exercises
Refer to the example of this Lab, change the system mode to user mode; compile and debug the program; watch the result of the program execution.
Prompt: You can’t switch the mode directly from user mode to system mode. Use SWI instruction to switch to supervisor mode first.
3.5 C Language Program Lab 1
3.5.1 Purpose
●Learn how to write and debug simple C language program using Embest IDE.
●Learn how to write and use command script files.
●Analyze the result through the Memory, Register, Watch and Variable windows.
3.5.2Lab Equipment
● Hardware: PC
● Software: Embest IDE 2003, Windows 98/2000/NT/XP.
3.5.3Content of the Lab
Use the command script to initialize the stack pointer. Use C language to create a delay function.
3.5.4 Principles of the Lab 1. Command Script
When the user connects the IDE to the target board for debugging or execution of programs sometimes the user needs to perform automatically some specific functions such as reset the target board, clear the watch dog, mask the interrupt register and memory, etc. By executing a series of commands we can perform various specific functions. The file that contains a group of sequential commands is called command script file (Embest uses .cs as the file extension for a command script file).
Each command has a name and appropriate parameters. In each command line the “;” indicates the beginning of
104
Embedded Systems Development and Labs; The English Edition
the comment. Every command that can be used in the debug window can also be used in the command script file including the executing command SCRIPT. For the debug commands and detailed contents, please refer to “Debug Command List” in the user guide document UserGuide.chm found on the CD that accompanies the EmbestIDE ARM development system.
The commands in the script will be executed automatically in a sequential order.
2.The Executing Methods of the Command Scripts
There are two methods of executing a command script:
● Input the SCRIPT command in the command window: script <command script file name>
● On the Debug page of Project Settings Dialog, specify the command script file at the “Action After Connected”. The IDE will first execute the command script file after the connection established.
3.The Often Used Commands
1) GO – Execute target program
syntax: |
go |
||
description: |
Execute target program from current program counter |
||
Parameter: |
none |
||
option: |
none |
||
example: |
Go |
||
2) MEMWRITE –Write to memory |
|||
syntax: |
memwrite [option] address value |
||
description: |
Write value to the specified memory location. It accesses the |
||
memory by default in word format using Little Endian mode. |
|||
parameter: |
address |
memory location |
|
value |
Specifies value to write. |
||
option: |
-h |
Specifies access the memory in half word format. |
|
-b |
Specifies access the memory in byte format. |
||
-e |
Write memory using Big Endian mode |
||
example: |
Memwrite 0x1000 0x5A |
Write 0x5a to 0x1000 |
|
memwrite -e |
Equal to memwrite 0x2000000 |
||
0x2000000 |
0x55443322 |
||
0x22334455 |
|||
105
Embedded Systems Development and Labs; The English Edition
3) REFRESH – refresh all windows
syntax: |
refresh |
|
description: |
refresh all windows include register, memory, stack, watch, |
|
global/local |
||
parameter: |
none |
|
option: |
none |
|
example: |
refresh |
|
4) REGWRITE – set register |
||
syntax: |
Regwrite register name value |
|
description: |
Set register |
|
parameter: |
register |
Specifies register name |
name |
||
value |
The value to write |
|
option: |
none |
|
example: |
regwrite pc 0x3840 Set PC with the value 0x3840 |
|
5) RESET –Reset the target
syntax: |
reset |
description: |
Reset the target device |
parameter: |
none |
option: |
none |
example: |
reset |
6) STOP –Stop the target |
|
syntax: |
stop |
description: |
Stop the target |
parameter: |
none |
option: |
none |
106
Embedded Systems Development and Labs; The English Edition
example: stop
3.5.5 Operation Steps
1)Refer to the former Labs and create a new project (project name is c1).
2)Refer to the sample program, edit the source file c1.c and c1.cs and add them to the project. Add the c1.cs to the root directory of the project.
3)Refer to the former Labs, finish the standard settings. One thing to be noted is that the command script file needs to be added as well in the settings. This is shown in Figure 3-10.
Figure 3-10 Embest IDE Debug Settings
4)Refer to the former Labs and compile the program.
5)Download the program and open the Memory/Register/Watch/Variable windows. Single step through the program and analyze the results through the Memory/Register/Watch/Variable windows. In the Watch window, input the variable I and J that need to be watched.
6)Refer to the contents of the Lab and related technology materials, watch the program run.
7)After understanding and mastering the Lab, do the exercises.
3.5.6 Sample Programs
1. c1.c sample program source code
107
Embedded Systems Development and Labs; The English Edition
2. c1.cs sample source code
stop |
; stop target CPU |
regwrite sp 0x1000 |
; initialize stack, set stack pointer at 0x1000 |
3.5.7 Exercises
Write an assembly program. Use B or BL instruction to jump to the main () function of the C language program. Use the ev40boot.cs as command script file. Watch the memory settings by executing this command script file.
3.6 C Language Program Lab 2
3.6.1 Purpose
●Create a complete ARM project including boot code, linker script, etc.
108
Embedded Systems Development and Labs; The English Edition
●Understand the boot process of ARM7. Learn how to write simple C language programs and assembly language boot program.
●Master the linker commands.
●Learn how to specify a code entry address and entry point.
●Learn the usage of Memory/Register/Watch/Variable windows.
3.6.2Lab Equipment
● Hardware: PC
● Software: Embest IDE 2003, Windows 98/2000/NT/XP.
3.6.3Content of the Lab
Write a delay function using C language. Use embedded assembly code.
3.6.4 Principles of the Lab
1. ARM Exception Vector Table
An exception takes place when the normal program execution flow is interrupted. For example, the process of an external interrupt causes an exception. Before the processor core processes the exceptions, the current status must be preserved. When the exception process is finished, the processor will return to the interrupted program. The ARM exception Vector Table is shown in Table 3-4.
Table 3-4 ARM Exception Vector table
Vector Address |
Exception |
Mode |
0x00000000 |
Reset |
SVC |
0x00000004 |
Undefined Instruction |
UND |
0x00000008 |
Software interrupt |
SVC |
0x0000000C |
Prefetch abort |
Abort |
0x00000010 |
Data abort |
Abort |
0x00000014 |
Reserved |
Reserved |
0x00000018 |
IRQ |
IRQ |
0x0000001C |
FIQ |
FIQ |
Multiple exceptions can arise at the same time. As a result, a priority order in which the exceptions are handled is defined:
High Priorities
1—Reset (highest priority) 2— Data abort
3—FIQ
4—IRQ 5—Prefetch Abort
6— SWI, undefined instruction (including absent coprocessor); this is the lowest priority
These are mutually exclusive instruction encodings and therefore cannot occur simultaneously. Reset starts the
109