OSSetErrorHandler

C Specification

#include <revolution/os.h>
#include <revolution/base/PPCArch.h>

extern u32 __OSFpscrEnableBits;  // for OS_ERROR_FPE. OR-ed FPSCR_*E bits

typedef void (*OSErrorHandler)(OSError error, OSContext* context, ...);
OSErrorHandler OSSetErrorHandler(OSError error, OSErrorHandler handler);

Arguments

error Error numbers given in the table below.
handler Pointer to the handler to set.

Return Values

The handler before the error.

Description

Implements an error handler of the specified error type. The following error types are defined in <os.h>.

No. OSError Description Comments
0 OS_ERROR_SYSTEM_RESET System reset exception
1 OS_ERROR_MACHINE_CHECK Machine check exception
2 OS_ERROR_DSI DSI exception
3 OS_ERROR_ISI ISI exception
4 OS_ERROR_EXTERNAL_INTERRUPT External interrupt exception (a)
5 OS_ERROR_ALIGNMENT Alignment exception
6 OS_ERROR_PROGRAM Program exception (b)
7 OS_ERROR_FLOATING_POINT Floating-point unavailable exception (a)
8 OS_ERROR_DECREMENTER Decrementer exception (a)
9 OS_ERROR_SYSTEM_CALL System call exception (a)
10 OS_ERROR_TRACE Trace exception (b)
11 OS_ERROR_PERFORMACE_MONITOR Performance monitor exception
12 OS_ERROR_BREAKPOINT Instruction address break point exception (b)
13 OS_ERROR_SYSTEM_INTERRUPT System management interrupt exception
14 OS_ERROR_THERMAL_INTERRUPT Thermal interrupt exception
15 OS_ERROR_PROTECTION Memory protection error
16 OS_ERROR_FPE Floating-point exception

OS_ERROR_SYSTEM_RESET --OS_ERROR_SYSTEM_INTERRUPT

Errors from OS_ERROR_SYSTEM_RESET to OS_ERROR_SYSTEM_INTERRUPT are generated by exceptions that the Broadway processor generates. OSInit sets default error handlers for every error type that writes error messages to the serial output. A game program can overwrite and register the default error handlers if necessary (except those marked with (a) or (b) in the above table; see below).

The OSErrorHandler for these errors takes the third and fourth arguments dsisr and dar as shown below:

void (*OSErrorHandler)( OSError error, OSContext* context,
u32 dsisr, u32 dar );

error displays the generated error number. context will have the Broadway register value from the time the error occurred excluding the FPU register context. Because the operating system manages the FPU registers to save context switch overhead, the error handler must not manipulate those registers. dsisr and dar will have the corresponding Broadway register values from the time the error occurred.

(a) Do not set error handlers for OS_ERROR_EXTERNAL_INTERRUPT, OS_ERROR_FLOATING_POINT, OS_ERROR_SYSTEM_CALL, and OS_ERROR_DECREMENTER. These error codes are used by the operating system.

(b) Do not set error handlers for OS_ERROR_PROGRAM, OS_ERROR_TRACE, OS_ERROR_BREAKPOINT when using debug. These error codes are used by the debug kernel.

OS_ERROR_PROTECTION

OS_ERROR_PROTECTION is generated when Broadway manipulated the memory range from the end of the main memory addresses to 64 megabytes, or when Hollywood detected a memory access violation with the setting specified by OSProtectRange.

The OSErrorHandler for these errors takes the third and fourth arguments dsisr and dar as shown below:

// dsisr bits for memory protection error handler, which tells
// from which region the error was reported
#define OS_PROTECT0_BIT             0x00000001  // by OS_PROTECT_CHAN0 range
#define OS_PROTECT1_BIT             0x00000002  // by OS_PROTECT_CHAN1 range
#define OS_PROTECT2_BIT             0x00000004  // by OS_PROTECT_CHAN2 range
#define OS_PROTECT3_BIT             0x00000008  // by OS_PROTECT_CHAN3 range
#define OS_PROTECT_ADDRERR_BIT      0x00000010  // by [24M or 48M, 64M)

void (*OSErrorHandler)( OSError error, OSContext* context,
u32 dsisr, u32 dar );

error displays the generated error number (OS_ERROR_PROTECTION). context will have the Broadway register value from the time the protection error was notified from Hollywood excluding the FPU register context. Because OS_ERROR_PROTECTION is notified asynchronously from Hollywood to Broadway, context does not contain the register context from the time that the memory protection violation occurred. Because the operating system manages the FPU registers to save context switch overhead, the error handler must not manipulate those registers. dar contains the physical memory address that violates the memory protection. dsisr will be OS_PROTECT_ADDRERR_BIT or OS_PROTECT_n.

OS_ERROR_FPE

OS_ERROR_FPE occurs only when error handler is set to OSSetErrorHandler. By setting an OS_ERROR_FPE error handler, floating-point exceptions such as the floating-point zero division can be caught during execution.

The OSErrorHandler for the OS_ERROR_FPE error takes the third and fourth arguments dsisr and dar as shown below:

void (*OSErrorHandler)( OSError error, OSContext* context,
u32 dsisr, u32 dar );

error displays the generated error number (OS_ERROR_FPE). context will have the Broadway register value from the time the floating-point exception occurred including the FPU register context. The error handler can manipulate the FPU register. When the error handler completes processing, this register is reflected to the thread in which the exception occurred. dsisr and dar will have the corresponding Broadway register values from the time the error occurred. The context->fpscr bit indicates the floating-point exception types as summarized below:

fpscr bit     Description
FPSCR_VX Invalid operation exception
FPSCR_OX Overflow exception
FPSCR_UX Underflow exception
FPSCR_ZX Zero divide exception
FPSCR_XX Inexact exception

When the error handler is set, the OSSetErrorHandler function sets the MSR[FE0] and MSR[FE1] bits of all threads including threads that will be created afterwards to enable the Broadway precise floating-point exception. The FPSCR bits of each thread are also initialized and bitwise ORed with the __OSFpscrEnableBits global variable. By default, __OSFpscrEnableBits has VE, OE, UE, ZE, and XE bits set (i.e., all bits are enabled). The types of floating-point exceptions that cause OS_ERROR_FPE errors can be controlled by setting a bitwise ORed set of the following enable bits in __OSFpscrEnableBits.

__OSFpscrEnableBits bit  Description
FPSCR_VE Invalid operation exception enable
FPSCR_OE Overflow exception enable
FPSCR_UE Underflow exception enable
FPSCR_ZE Zero divide exception enable
FPSCR_XE Inexact exception enable

Once the OS_ERROR_FPE error handler is set, the value of __OSFpscrEnableBits should not be changed until the OS_ERROR_FPE handler is deleted.

The example program that shows the use of the OS_ERROR_FPE error handler is under the following path:

    $REVOLUTION_SDK_ROOT/build/demos/osdemo/src/fpe.c

See Also

Error Functions, OSProtectRange,
IBM Broadway RISC Microprocessor User's Manual

Revision History

03/01/2006 Initial version.