Task exception handling functions handle exception events that are raised for a task in the context of that task.
The task exception handler is started when all the following processing has taken place:
Register task exception handler by tk_def_tex
Enable task exception by tk_ena_tex
Raise task exception by tk_ras_tex
A task exception handler is executed as a part of the task where the task exception occurred, in the context of that task and at the protection level specified when the task was created. The task states in a task exception handler, except for those states concerning task exceptions, are the same as the states when running an ordinary task portion; and the same set of system calls are available.
A task exception handler can be started only when the target task is running in a task portion. If the task is running in any other portion when a task exception is raised, the task exception handler is started only after the control returns to the task portion. If a quasi-task portion (extended SVC) is being executed when a task exception is raised, the processing of the extended SVC handler is aborted and the control returns to the task portion. If it is needed to abort the processing of the extended SVC handler (called "break processing" for the extended SVC handler), it is performed before the control returns to the task portion where the extended SVC handler is called. "Break processing" is executed by the break function of Subsystem Management Functions.
Requested task exceptions are cleared when the task exception handler is called (when the task exception handler starts running).
Task exception is identified by a task exception code: from 1 to (bit width of UINT data type - 1). For example, if UINT is 16 bits, a number from 0 to 15 can be used as task exception code. 0 corresponds to the highest priority, and (bit width of UINT data type - 1) corresponds to the lowest priority. Task exception code 0 is handled differently from the others, as explained below.
These task exception handlers cannot be executed by nesting them. A task exception (other than task exception code 0) raised while a task exception handler is running will be made pending.
On return from a task exception handler, the task resumes from the point where processing was interrupted by the exception.
It is also possible to use longjmp()
or the like to jump to any point in the task without returning from the task exception handler.
This exception can be executed by nesting even while a task exception handler is executing for an exception of task exception code from 1 to (bit width of UINT data type - 1). Nesting does not take place when the task exception handler of task exception code 0 is executed.
A task exception handler runs after setting the user stack pointer to the initial setting when the task was started. In a system without a separate user stack and system stack, however, the stack pointer is not reset to its initial setting.
A task exception code 0 handler does not return to task processing. The task must be terminated by calling tk_ext_tsk or tk_exd_tsk.
Porting Guideline | |
---|---|
Be warned that the available number of task exception codes is now dependent on the bit width of UINT data type. For example, task exception code can take the value from 0 to 15 in 16-bit environment. |
ID |
tskid
| Task ID | Task ID |
CONST T_DTEX* |
pk_dtex
| Packet to Define Task Exception | Task exception handler definition information |
pk_dtex
Detail:
E_OK | Normal completion |
E_NOMEM | Insufficient memory (memory for control block cannot be allocated) |
E_ID | Invalid ID number (tskid is invalid or cannot be used) |
E_NOEXS | Object does not exist (the task specified in tskid does not exist) |
E_OBJ | Invalid object state (the task specified in tskid runs at protection level 0 (TA_RNG0)) |
E_RSATR | Reserved attribute (texatr is invalid or cannot be used) |
E_PAR | Parameter error (pk_dtex is invalid or cannot be used) |
Only when all the service profile items below are set to be effective, this system call can be used.
Defines a task exception handler for the task specified in tskid
. Only one task exception handler can be defined per task; if one is already defined, the last-defined handler is valid. Setting pk_dtex
= NULL cancels a definition.
Defining or canceling a task exception handler clears pending task exception requests and disables all task exceptions.
texatr
indicates system attributes in its lower bits and implementation-dependent attributes in its higher bits. The texatr
system attributes are not assigned in the present version of T-Kernel specification, and system attributes are not used.
A task exception handler takes the following form.
void texhdr( INT texcd ) { /* Task exception handling */ /* Task exception handler termination */ if ( texcd == 0 ) { tk_ext_tsk() or tk_exd_tsk(); } else { tk_end_tex(); return or longjmp(); } }
A task exception handler behaves like a TA_ASM attribute object and cannot be called via a high-level language support routine. The entry part of the task exception handler must be written in assembly language. The kernel vendor must provide the assembly language source code of the entry routine for calling the above C language task exception handler. That is, source code equivalent to a high-level language support routine must be provided.
A task set to protection level TA_RNG0 when it is created cannot use task exceptions.
At the time a task is created, no task exception handler is defined and task exceptions are disabled.
When a task reverts to DORMANT state, the task exception handler definition is canceled and task exceptions are disabled. Pending task exceptions are cleared. It is possible, however, to define a task exception handler for a task in DORMANT state.
Task exceptions are software interrupts raised by tk_ras_tex, with no direct relation to CPU exceptions.
Only when all the service profile items below are set to be effective, this system call can be used.
Enables task exceptions for the task specified in tskid
.
The parameter texptn
is a logical OR bit array representing task exception codes in the form 1 << task exception code.
tk_ena_tex enables the task exceptions specified in texptn
. If the current exception enabled status is texmask
, it changes as follows.
enable: texmask |= texptn |
If all the bits of texptn
are cleared to 0, no operation is made to texmask
. No error will result in this case.
Task exceptions cannot be enabled for a task with no task exception handler defined.
This system call can be called to tasks in DORMANT state.
Be warned that the available number of task exception codes is now dependent on the bit width of UINT data type. For example, task exception code can take the value from 0 to 15 in 16-bit environment.
Only when all the service profile items below are set to be effective, this system call can be used.
Disables task exceptions for the task specified in tskid
.
The parameter texptn
is a logical OR bit array representing task exception codes in the form 1 << task exception code.
tk_dis_tex disables the task exceptions specified in texptn
. If the current exception enabled status is texmask
, it changes as follows.
disable: texmask &= ~texptn |
If all the bits of texptn
are cleared to 0, no operation is made to texmask
. No error will result in either case.
A disabled task exception is ignored, and is not made pending. If exceptions are disabled for a task while there are pending task exceptions, the pending task exception requests are discarded (their pending status is cleared).
This system call can be called to tasks in DORMANT state.
Be warned that the available number of task exception codes is now dependent on the bit width of UINT data type. For example, task exception code can take the value from 0 to 15 in 16-bit environment.
E_OK | Normal completion |
E_ID | Invalid ID number (tskid is invalid or cannot be used) |
E_NOEXS | Object does not exist (the task specified in tskid does not exist or no task exception handler is defined) |
E_OBJ | Invalid object state (the task specified in tskid is in DORMANT state) |
E_PAR | Parameter error (texcd is invalid or cannot be used) |
E_CTX | Context error (issued from task-independent portion, or in dispatch disabled state) |
Only when all the service profile items below are set to be effective, this system call can be used.
Raises the task exception specified in texcd
for the task specified in tskid
. If the task specified in tskid
disables the task exception specified in texcd
, the raised task exception is ignored, and is not made pending. In this case, E_OK is returned to this system call.
If a task exception handler is already running in the task specified in tskid
, the newly raised task exception is made pending. If an exception is pending, the break processing (break function) for the extended SVC handler is not performed even if the target task is executing an extended SVC.
In the case of texcd
= 0, however, exceptions are not made pending even if the target task is executing an exception handler. If the target task is running a task exception handler for an exception of task exception codes from 1 to (bit width of UINT data type - 1), the task exception is accepted; and if an extended SVC is executing, the break processing (break function) for the extended SVC handler is performed. If the target task is running a task exception handler for an exception of task exception code 0, task exceptions are ignored.
The invoking task can be specified by setting tskid
= TSK_SELF = 0.
If this system call is issued from a task-independent portion, error code E_CTX is returned.
If the target task is executing an extended SVC, the break processing (break function) corresponding to the extended SVC runs as a quasi-task portion of the task that issued tk_ras_tex. That is, it is executed in the context of the quasi-task portion whose requesting task is the task that issued tk_ras_tex.
In such a case tk_ras_tex does not return control until the break processing ends. For this reason, the specification does not allow tk_ras_tex to be issued from a task-independent portion.
Task exceptions raised in the task that called tk_ras_tex while the break processing is running are held until the break processing (break function) ends.
Be warned that the available number of task exception codes is now dependent on the bit width of UINT data type. For example, task exception code can take the value from 0 to 15 in 16-bit environment.
Only when all the service profile items below are set to be effective, this system call can be used.
Ends a task exception handler and enables the new task exception handler. If there are pending task exceptions, the highest-priority task exception code among them is passed in the return code. If there are no pending task exceptions, 0 is returned.
If enatex
= FALSE and there are pending task exception, calling the new task exception handler is not allowed. In this case, the exception handler specified in return code texcd
is in running state upon return from tk_end_tex. If there are no pending task exceptions, calling the new task exception handler is allowed.
If enatex
= TRUE, calling the new task exception handler is allowed regardless of whether there are pending task exceptions. Even if there are pending task exceptions, the task exception handler is in terminated status.
There is no way of ending a task exception handler other than by calling tk_end_tex. A task exception handler continues executing from the time it is started until tk_end_tex is called. Even if return is made from a task exception handler without calling tk_end_tex, the task exception handler will still be running at the point of return. Similarly, even if longjmp
is used to get out of a task exception handler without calling tk_end_tex, the task exception handler will still be running at the jump destination.
Calling tk_end_tex while task exceptions are pending results in a new task exception being accepted. At this time even when tk_end_tex is called from an extended SVC handler, a break processing (break function) cannot be called for that extended SVC handler. If extended SVC calls are nested, then when the extended SVC nesting goes down one level, the break processing (break function) corresponding to the extended SVC return destination can be called. Calling of a task exception handler takes place upon return to the task portion.
The tk_end_tex system call cannot be issued in the case of task exception code 0 since the task exception handler cannot be ended in this case. The task must be terminated by calling tk_ext_tsk or tk_exd_tsk. If tk_end_tex is called while processing the task exception code 0, the behavior is undefined (implementation-dependent).
This system call cannot be issued from other than a task exception handler. The behavior when it is called from other than a task exception handler is undefined (implementation-dependent).
When tk_end_tex (TRUE) is called and there are pending task exceptions, another task exception handler call is made immediately following tk_end_tex. In this case, a task exception handler is called without restoring the stack, giving rise to possible stack overflow.
Ordinarily tk_end_tex (FALSE) can be used, and processing looped as illustrated below while there are task exceptions pending.
void texhdr( INT texcd ) { if ( texcd == 0 ){ /* Processing for task exception 0 */ tk_exd_tsk(); } do { /* Processing of task exception: from 1 to (bit width of UINT data type) - 1 */ } while ( (texcd = tk_end_tex(FALSE)) > 0 ); }
Strictly speaking, if a task exception were to occur during the interval after 0 is returned by tk_end_tex ending the loop and before exit from texhdr
, the possibility exists of reentering texhdr
without restoring the stack. Since task exceptions are software driven, however, ordinarily they do not occur independently of executing tasks; so in practice this is not a problem.
Be warned that the available number of task exception codes is now dependent on the bit width of UINT data type. For example, task exception code can take the value from 0 to 15 in 16-bit environment.
pk_rtex
Detail:
Only when all the service profile items below are set to be effective, this system call can be used.
Gets the status of task exceptions for the task specified in tskid
.
pendtex
indicates the currently pending task exceptions. A raised task exception is indicated in pendtex
from the time the task exception is raised until its task exception handler is called.
texmask
indicates allowed task exceptions.
Both pendtex
and texmask
are bit arrays of the form 1 << task exception code.
The invoking task can be specified by setting tskid
= TSK_SELF = 0. Note, however, that when tskid
= TSK_SELF = 0 is specified in a system call issued from a task-independent portion, error code E_ID is returned.