413 by DF0: of NFA This time,I am going to waffle on about Vectors,and how they are used within the Archimedes.Vectors are basically used to link a program that calls a routine and the routine itself together.All access to the routine is made through the vector.Confused yet? Well don't worry,it gets easier... Vectors are damn handy things for several reasons. They allow programs to access standard routines without actually needing the start address in the code.Later on,if you decide to move the routine somewhere else in memory,all you need to do is update the vector.That way,your program does not have to be re- written from scratch. Vectors can also be intercepted.This means that you can replace the normal address that they contain with your own custom routine.Next time that vector is called,it will now point to your routine and execute that one instead.Most system activities such as disc access,error handling,etc. are all vectored,so you can modify and customize the system to your needs. HARDWARE VECTORS ================ The ARM Processor has some vectors located at the bottom of the memory to deal with things it can't cope with,so instead of shitting itself at the sight of an address exception,it calls the address exception vector to deal with it.The address exception error occurs whenever a program tries to access memory that isn't actually there. The Vectors mentioned above are as follows : &00000000 ARM Reset &00000004 Undefined instruction &00000008 Software Interrupt &0000000C Abort (before fetch) &00000010 Abort (data) &00000014 Address exception &00000018 IRQ_Vec &0000001C FIRQ_Vec Each vector contains a branch instruction which tells the processor to jump to a suitable operating system routine to take care of whatever has happened. SOFTWARE VECTORS ================ The operating system has got stacks and stacks of vectors to provide access to its many routines.These are ALWAYS used whenever an OS routine is called.So,when we use an 'OS_WriteC' SWI,the operating system accesses the WRITE_C SWI via an internal vector. If you intercepted this vector,you could make it point at your own code.When you do this,the registers will normally contain some information,in the Write_C example,R0 would contain the ASCII code of the letter to be displayed. Sometimes,you may need to completley replace the OS routine,and at other times,you may just need to perform some function and then pass control back to the routine.Luckily,on the Archimedes,you can do both of these things! Operating system vectors ------------------------ &01 ErrorV * &0E ReadLineV &02 IrqV * &0F FSControl &03 WrchV * &10 EventV &04 RdchV * &14 INSV &05 CliV * &15 REMV &06 ByteV * &16 CNPV &07 WordV * &17 UKVDU23V &08 FileV * &18 UKSWIV &09 ArgsV * &19 UKPLOTV &0A BGetV * &1A MouseV &0B BPutV * &1B VDUXV &0C GBPBV * &1C TickerV &0D FindV * &1D UpcallV Claiming Vectors ================ There are two SWI calls which are very useful for intercepting vectors.The first one is SWI "OS_Claim" , and has the following register flags associated with it : R0 = Number of vector to claim R1 = Address of the new routine R2 = Value which will be passed to R12 when the routine is called. The OS will then add the routines address to the list of other routines to call when the vector is used. Releasing vectors ================= You can remove a routine from a vectors list by using SWI "OS_Release" The following registers need to be set up.... R0 = Number of the vector that has been intercepted R1 = The address of the routine to be taken off the vectors list R2 = The same value in R2 when the vector was claimed above. Important stuff =============== I.) All registers must be the same on exit as they were on entry II.) You can preserve registers by slapping them on the internal stack while they are used.To do this,type in STMFD R13!,{Register_List} To get them off,use LDMFD R13!,{Register_List} III.) An intercept routine will be used in IRQ or FIRQ mode,dpending on the sort of vector you are intercepting. IV.) When exiting from an intercept,use MOV R15,R14.