; *********************************************************************** ; * * ; * Initialisation Routines for the Flash Program, Second Version * ; * * ; *********************************************************************** ; Author: John Zaitseff ; Date: 28th May, 2003 ; Version: 1.2 ; This file contains the initialisation routines for the second version of ; the Flash program (flash-v2.elf), as used in ELEC2041 Experiment 5. In ; particular, it contains the ARM processor exception vector table and the ; boot code that sets the processor into User mode. .global _start ; "_start" is where the code starts running .extern main ; "main" is defined in another file .extern swi_handler ; "swi_handler" is also defined elsewhere .include "header-v2-int.s" ; Include various definitions ; ----------------------------------------------------------------------- ; The following code will be placed into the ".zeropage" section, NOT into ; the ".text" section. The GNU Linker will place the ".zeropage" section ; at address 0x0. .section .zeropage, "awx" ; For code located at address 0x00000000 _start: ; Start of the entire program ; ARM processor exception vector table ; The ARM processor exception vector table must appear at address 0x0 in ; ARM systems, as explained in the ARM Architecture Reference on page ; A2-13 (page 45 of the PDF document). This table contains exactly eight ; words (24 bytes). Each word is interpreted by the ARM processor as an ; instruction; that instruction is executed to handle a particular ; exception. ; ; This particular table only handles the Reset and Software Interrupt ; exceptions. All other entries contain the NOP ("do nothing") ; instruction. Technically, doing this is incorrect: the proper way to ; "not handle" an exception is to return to the user program, usually with ; a "subs pc, lr, #4" instruction. Doing it correctly might confuse you, ; however... If you don't understand this paragraph, ignore it. ev00: b init ; Reset exception ev04: nop ; Undefined Instruction exception ev08: b swi_handler ; Software Interrupt exception ev0C: nop ; Prefetch Abort exception ev10: nop ; Data Abort exception ev14: nop ; (Not used) ev18: nop ; Interrupt exception ev1C: nop ; Fast Interrupt exception ; ----------------------------------------------------------------------- ; 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. ; The reason this code (the initialisation routine) is placed into its own ; section is for clarity: it makes it easier for you to distinguish what ; is "operating system" code and what is User mode code. .section .ospage, "awx" ; For "operating system" code ; Initialisation routine ; This routine is run at processor reset. It changes the ARM processor ; into User mode with the Fast and normal interrupts disabled. init: ; Change to User mode using a read-modify-write cycle mrs ip, cpsr ; Get current value of CPSR into IP (R12) bic ip, ip, #ARM_PSR_mode_mask ; Mask out the bottom 5 bits orr ip, ip, #(ARM_PSR_i | ARM_PSR_f | ARM_PSR_mode_usr) ; Disable both interrupts, set User mode msr cpsr, ip ; Actually make the changes to CPSR b main ; Now in User mode; jump to the main program .end