You are on page 1of 4

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 int 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 lr (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 the swi instruction PC is changed to R14_svc (lr), which was saved upon the execution of the swi instruction

Run the example code generating software interrupt


1. Create a directory called lab2 under the comp427 directory, and go to the lab2 directory cd comp427 mkdir lab2 cd lab2 2. Download a tar ball from http://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.gz 4. You should be able to see 5 files (Open each file with vi and inspect it) cd softirq 1

ls al at91.h, skyeye.conf, softirq_hello.lds, softirq_hello.S, and Makefile, at91.h defines memory-mapped addresses of the peripheral devices in AT91 skyeye.conf contains configuration information (cpu, memory, display etc) softirq_hello.lds 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? softirq_hello.S is an example assembly code for software interrupt Check out the context switch code at the beginning and the end of the ISR (Interrupt Service Routine). 5. Compile the code make Youll have an ARM binary softirq_hello generated Youll 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_instance ISR for the software interrupt is sending characters to the UART (Serial port) in AT91

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 378 after 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 install Install 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 up Press Ctrl C to kill the program Run softirq_hello again with redirection skyeye e softirq_hello > log.txt start run Kill the program immediately by pressing Ctrl C Open log.txt with vi vi 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_0008 Check that the program jumps to the interrupt service routine Check that the program returns to the main routine

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] <= data h%08x\n, address, data) If you dont want to see the program counter messages, comment out the statement you added in the previous section 2. Compile Skyeye again cd ~/comp427/skyeye_1.3.2_rc1 make sudo make install 3. Run softirq_hello cd ~/comp427/lab2/softirq skyeye e softirq_hello 4. Check out the messages to see if it matches with what you expect 5. 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 before return fault in the GetWord() function printf([LOG] Read data h%08x from address [h%08x] \n, *data, address) 6. Repeat the steps 2, 3, and 4

Make sure that the address and data are correctly showing the behavior of the program you are executing! Try to be familiarized with the Skyeye source code How Skyeye models the CPU and virtual platform?

You might also like