2.5. Interrupt Handling

With programming languages such as Coral 66 there is no standard technique for handling interrupts. However in XGC Coral 66 we offer a set of low-level functions that may be called from any of the high-level langauges we offer, and which are therefore available to Coral 66 programmers too.

Note: These functions are provided by the standard library libc and are supported by code in the start file art0.S. If you use a custom start file, the library functions may not be supported.

You may of course decide not use the library procedures, and simply make calls from the interrupt vector to the appropriate handlers.

An interrupt handler has the form of a procedure. It has two parameters, one which is the number of the interrupt and one that points to the saved context on the stack. We need not declare the handler with both parameters since the external declaration is under our immediate control. The procedure is called when the interrupt is raised, and the start file ensure that registers and other vital context information is saved before the call and restore after.

You should also note that the CPU will switch stacks from the base level stack (if we interrupt base level, but not if this is a nested interrupt) to the interrupt stack. You shopuld therefore ensure that the interrupt stack is big enough for any Coral 66 procedures that may be called. You should take special care with the Coral Input-Output functions that may include quite large buffers as local data.

Example 2-4. Example of an Interrupt Handler


'procedure' timer_handler ('value''integer' sig);
'begin'
   outstring (1, "Hello world, sig = ");
   outinteger (1, sig);
   outchar (1, 10);

   count := count + 1;
'end' timer_handler;

You attach a handler to an interrupt using the library function handler, as follows: