HP 3000 Manuals

Examples [ Trap Handling Programmer's Guide ] MPE/iX 5.0 Documentation


Trap Handling Programmer's Guide

Examples 

To use the XSYSTRAP intrinsic to arm/disarm the user-written system trap
handler, you must do the following:

 *  Declare the intrinsic in your source, using whatever conventions are
    appropriate to your language.

 *  Declare the trap handling procedure, using the appropriate formal
    parameters.


NOTE Since you can provide only one plabel to the XSYSTRAP intrinsic, your software system trap handling procedure must handle all types of software system traps.
Example 6-1 is an HP Pascal/XL program that illustrates the declaration and arming of a system trap handler, as well as an erroneous intrinsic call that would invoke the declared trap handler. Example 6-1. Software System Trap Handler Program foo (input,output); procedure XSYSTRAP; intrinsic; procedure activate; intrinsic; procedure quit; intrinsic; procedure sys_trap_procedure (trap_code : integer; intrin_num : integer; intrin_error : integer; intrin_parm : integer); { This trap handling routine will be invoked once a system trap occurs. } begin writeln (output, 'Now in the trap handling routine.'); writeln (output); writeln (output, 'Trap code = ', trap_code); writeln (output, 'Intrinsic number = ', intrin_num); writeln (output, 'Error = ', intrin_error); writeln (output, 'Parameter = ', intrin_parm); end; {sys_trap_procedure} procedure arm_systrap_routine; { This routine calls XSYSTRAP with the plabel of the preceding system } { trap handling routine. } var plabel : integer; oldplabel : integer; begin plabel := waddress (sys_trap_procedure); XSYSTRAP (plabel, oldplabel); { pass the offset } end; { arm_systrap_procedure } Example 6-1. Software System Trap Handler, continued begin { This is the program's outer block. First set up sys_trap_procedure to } { be the system trap handling routine. Then attempt to activate the CI } { process, which should result in a system trap. When sys_trap_procedure} { exits, control should return to the statement following the call to the} { ACTIVATE intrinsic, which is a writeln statement. } arm_systrap_routine; activate (0,0); {invalid ACTIVATE call } writeln (output, 'Now back in the program outer block.'); end. { foo }


MPE/iX 5.0 Documentation