ES Lab2 SW Interrupt Programming
-
Upload
wongngeeseng -
Category
Documents
-
view
215 -
download
0
Transcript of ES Lab2 SW Interrupt Programming
-
7/27/2019 ES Lab2 SW Interrupt Programming
1/4
1
COMP427 Embedded Systems
Lab 2. Software Interrupt Programming with ARM
In this lab, we are going to run a simple program that generates a software interrupt in ARM.
Software interrupt is implemented in the instruction set. ARM provides the swi instruction
for software interrupt. x86 provides the i nt instruction for software interrupt. Software
interrupt is used to implement OS system calls. The following is done by ARM upon the
execution of the swi instruction.
ARM switches to the supervisor mode CPSR is saved in SPSR_svc The subsequent instructions PC following swi is saved in l r (link register,
R14_svc) of the supervisor mode PC is changed to 0x0000_0008
Thus, at the memory location of 0x0000_0008, there should be an appropriate code to
handle the software interrupt. To return from the software interrupt, you have to use the
following instruction.
MOVS PC, R14
This instruction does the following operations
CPSR is updated with SPSR_svc, which was saved upon the execution of theswi instruction
PC is changed to R14_svc ( l r ) , which was saved upon the execution of theswi instruction
Run the example code generating software interrupt
1. Create a directory called lab2 under the comp427 directory, and go to the lab2directory
cd comp427 mkdir lab2 cd lab2
2. Download a tar ball fromhttp://esca.korea.ac.kr/teaching/comp427_ES/lab2/softirq.tar.gz and copy it
to .~/comp427/lab2
cp ~/Download/softirq.tar.gz .3. Uncompress the tarball
tar zxvf softirq.tar.gz4. You should be able to see 5 files (Open each file with vi and inspect it)
cd softirq
-
7/27/2019 ES Lab2 SW Interrupt Programming
2/4
2
ls al at 91. h, skyeye. conf , sof t i r q_hel l o. l ds, sof t i r q_hel l o. S,
and Makef i l e,
at 91. h defines memory-mapped addresses of the peripheral devicesin AT91
skyeye. conf contains configuration information (cpu, memory,display etc)
sof t i rq_hel l o. l ds is a link script Note that the text (code) starts from the address 0x0000_0000 What code is going to be located at the address 0x0000_0008
then?
sof t i rq_hel l o. S is an example assembly code for softwareinterrupt
Check out the context switch code at the beginning and theend of the ISR (Interrupt Service Routine).
5. Compile the code make
Youll have an ARM binary softirq_hello generatedYoull also have a disassembled file softirq_hello.dump generated
6. Run the binary with skyeye skyeye e softirq_hello
You should be able to see Hello printed on the uart_instanceISR for the software interrupt is sending characters to the UART
(Serial port) in AT91
-
7/27/2019 ES Lab2 SW Interrupt Programming
3/4
3
Instrument the Skyeye source code to print out the program
counter (PC) while executing the program (softirq_hello.S)
1. Instrument armemu.c located in ./skyeye-1.3.2_rc1/arch/arm/common/ vi ~/comp427/skyeye-1.3.2_rc1/arch/arm/common/armemu.c
go to line 378after do {, add the following line
printf([LOG] PC (R15) is 0h%08x\n, pc)2. Compile Skyeye again
cd ~/comp427/skyeye-1.3.2_rc1 make
You have a new Skyeye with the printf statement added
sudo make installInstall the executable at /opt/skyeye
3. Run softireq_hello again cd ~/comp427/lab2/softirq skyeye e softirq_hello
Youll have a lot of messages scrolled upPress Ctrl C to kill the program
Run softirq_hello again with redirectionskyeye e softirq_hello > log.txtstartrunKill the program immediately by pressing Ctrl C
Open log.txt with vivi log.txt
4. Compare the execution flow with referencing the disassembled file Open the disassembled file in another shell
vi softirq_hello.dump Compare the execution flow (log.txt) with softirq_hello.s
Check that the PC is changed to 0x0000_0008Check that the program jumps to the interrupt service routineCheck that the program returns to the main routine
-
7/27/2019 ES Lab2 SW Interrupt Programming
4/4
4
Instrument the Skyeye source code to print out the load and
store operations and instruction fetch of the program
(softirq_hello.S)
1. Instrument armvirt.c located in ./skyeye-1.3.2_rc1/arch/arm/common/ vi ~/comp427/skyeye-1.3.2_rc1/arch/arm/common/armvirt.c
Add the following line right after fault_t fault; in the PutWord()function
printf([LOG] Write: Address [h%08x]