Initializing the vector table in the assembly source file requires that all the entries in the table are initialized. Interrupts, which are not used, must be associated with a standard handler.
The labels or functions that should be inserted in the vector table must be implemented in the assembly source file or an external reference must be available for them. The vector table can be defined in an assembly source file in an additional section containing constant variables. See the following listing:
XDEF ResetFunc XDEF IRQ0Int DataSec: SECTION Data: DS.W 5 ; Each interrupt increments an element of the table. CodeSec: SECTION ; Implementation of the interrupt functions. IRQ1Func: LDA #0 BRA int SWIFunc: LDA #4 BRA int ResetFunc: LDA #8 BRA entry DummyFunc: RTI int: PSHH LDHX #Data ; Load address of symbol Data in X ; X <- address of the appropriate element in the tab Ofset: TSTA BEQ Ofset3 Ofset2: AIX #$1 DECA BNE Ofset2 Ofset3: INC 0, X ; The table element is incremented PULH RTI entry: LDHX #$0E00 ; Init Stack Pointer to $E00-$1=$DFF TXS CLRX CLRH CLI ; Enables interrupts loop: BRA loop VectorTable: SECTION ; Definition of the vector table. IRQ1Int: DC.W IRQ1Func IRQ0Int: DC.W DummyFunc SWIInt: DC.W SWIFunc ResetInt: DC.W ResetFunc
The section should now be placed at the expected address. This is performed in the linker parameter file, as listed in the following listing:
LINK test.abs NAMES test.o+ END ENTRIES IRQ0Int END SECTIONS MY_ROM = READ_ONLY 0x0800 TO 0x08FF; MY_RAM = READ_WRITE 0x0B00 TO 0x0CFF; MY_STACK = READ_WRITE 0x0D00 TO 0x0DFF; /* Define the memory range for the vector table */ Vector = READ_ONLY 0xFFF8 TO 0xFFFF; END PLACEMENT DEFAULT_RAM INTO MY_RAM; DEFAULT_ROM INTO MY_ROM; SSTACK INTO MY_STACK; /* Place the section 'VectorTable' at the appropriated address. */ VectorTable INTO Vector; END INIT ResetFunc