Initializing the Vector table in the linker PRM file

Initializing the vector table from the PRM file allows you to initialize single entries in the table. The user can decide to initialize all the entries in the vector table or not.

The labels or functions, which should be inserted in the vector table, must be implemented in the assembly source file ( Listing: Initializing the Vector table from a PRM File). All these labels must be published, otherwise they cannot be addressed in the linker PRM file.

Listing: Initializing the Vector table from a PRM File

          XDEF  IRQ1Func, SWIFunc, ResetFunc
DataSec:  SECTION

Data:     DS.W 5       ; Each interrupt increments an element

                       ; of the table.

CodeSec:  SECTION

; Implementation of the interrupt functions.

IRQ1Func:

          LD D0,   #0

          BRA   int

SWIFunc:

          LD D0,   #4

          BRA   int

ResetFunc:

          LD D0,   #8

          BRA    entry

int:

          PSHH

          LD X,  #Data  ; Load address of symbol Data in X

; X <- address of the appropriate element in the tab

Ofset:    TST D0,

          TBEQ D0,   Ofset3

Ofset2:

          INC X   #$1

          DEC A

          BNE Ofset2

Ofset3:

          INC.W (0,X)   ; The table element is incremented

          PULH

          RTI

entry:

          LD S,  #0x10FF; Init Stack Pointer to $1100-$1=$10FF

          TXS

          CLRX

          CLRH

          CLI          ; Enables interrupts

loop:     BRA   loop
Note: The IRQ1Func, SWIFunc, and ResetFunc functions are published. This is required, because they are referenced in the linker PRM file.
Note: The S12Z processor automatically pushes the PC, X, A, and CCR registers on the stack when an interrupt occurs. The interrupt functions do not need to save and restore those registers. It is the user's responsibility to save and restore it prior to returning.
Note: All Interrupt functions must be terminated with an RTI instruction

The vector table is initialized using the linker VECTOR ADDRESS command, as listed in the following listing:

Listing: Using the VECTOR ADDRESS Linker Command

LINK test.abs
NAMES

  test.o

END

SECTIONS

  MY_ROM   = READ_ONLY  0x0800 TO 0x08FF;

  MY_RAM   = READ_WRITE 0x0B00 TO 0x0CFF;

  MY_STACK = READ_WRITE 0x0D00 TO 0x0DFF;

END

PLACEMENT

  DEFAULT_RAM        INTO MY_RAM;

  DEFAULT_ROM        INTO MY_ROM;

  SSTACK             INTO MY_STACK;

END

INIT ResetFunc

VECTOR ADDRESS 0xFFF8 IRQ1Func

VECTOR ADDRESS 0xFFFC SWIFunc

VECTOR ADDRESS 0xFFFE ResetFunc
Note: The statement INIT ResetFunc defines the application entry point. Usually, this entry point is initialized with the same address as the reset vector.
Note: The statement VECTOR ADDRESS 0xFFF8 IRQ1Func specifies that the address of the IRQ1Func function should be written at address 0xFFF8.