; *********************************************************************** ; * * ; * Software Interrupt Handler for the Flash Program, Second Version * ; * * ; *********************************************************************** ; Author: John Zaitseff ; Date: 28th May, 2003 ; Version: 1.2 ; This file contains the software interrupt handler for the second version ; of the Flash program (flash-v2.elf), as used in ELEC2041 Experiment 5. ; ----------------------------------------------------------------------- ; The following code will be placed into the ".ospage" section, NOT into ; the ".text" section. The GNU Linker will place the ".ospage" section at ; address 0x1000. ; Notice that the file boot-swi-v2.s also contains code that is placed ; into the ".ospage" section; see Figure 8 in ELEC2041 Experiment 5 to see ; how the GNU Linker handles this situation. .section .ospage, "awx" ; For "operating system" code .include "header-v2-pub.s" ; Include various public definitions .include "header-v2-int.s" ; Include various internal definitions ; Note that the internal definitions ; are only needed by the initialisation ; code and by the software interrupt ; handler. ; ----------------------------------------------------------------------- ; Software Interrupt handler .global swi_handler ; Make this label visible to other modules swi_handler: ; Software Interrupt handler ; This code runs in Supervisor mode ; R0 contains the SWI function code; each function expects its own set of ; parameters and returns its own results. ; A slight optimisation: no check is done for out-of-range errors here, as ; the code simply "falls through" to the error handler if need be, which ; then "falls through" to the exit code. cmp r0, #swi_set_LEDs ; Client wants to set the LEDs? beq swi_set_LEDs_func ; Yes, handle it cmp r0, #swi_delay ; Client wants to delay the program? beq swi_delay_func ; Yes, handle it swi_outofrange: ; Out of range error handler mov r0, #0xFFFFFFFF ; Signal an error by returning 0xFFFFFFFF swi_end: ; Return to the client program movs pc, lr ; Restore PC and CPSR ; ----------------------------------------------------------------------- ; SWI Function 0: Set the LEDs ; This function (called using the SWI instruction with R0=0) sets the LEDs ; to the value contained in R1. Nothing useful is returned. ; Notice that the caller does NOT need to know the LED port address; it ; only needs to know that the function does what it is told and what the ; inpits and outputs are. Separating the interface from the ; implementation in this way is a good thing: the user program can then be ; written as if the SWI function was a "black box". This black box's ; inner workings may be changed at a later date, such as would happen if ; this program was ported to a different ARM-based board. swi_set_LEDs_func: ; Function 0: Set the LEDs ldr r0, =portA ; Load "protected port" address into R0 strb r1, [r0] ; Set the LEDs to the value in R1 b swi_end ; Return to the caller ; ----------------------------------------------------------------------- ; SWI Function 1: Delay the program ; This function (called using the SWI instruction with R0=1) delays the ; program by "busy waiting" a number of loops; the number of loops to ; delay by is contained in R1. Nothing useful is returned. swi_delay_func: ; Function 1: Delay the program cmp r1, #0 ; R1 = number of loops to delay (unsigned) beq swi_end ; If R1 = 0, no loops, just end swi_delay_func_1: subs r1, r1, #1 ; Decrement the number of loops to go beq swi_end ; Return to caller if finished b swi_delay_func_1 ; Otherwise, repeat the loop .end