Subsystem and Device Driver Starting

In µT-Kernel, there is no particular definition concerning the start-up of the subsystem and device driver. In terms of portability, it is desirable to prepare the entry routine in the same format as T-Kernel if possible.

[Difference with T-Kernel]

In T-Kernel, subsystems and device drivers have the following entries:

Entry routines like the following are defined for subsystems and device drivers.


ER main( INT ac, UB *av[] )
{
	if ( ac >= 0 ) {
	/* Subsystem/device driver start processing */
	} else {
	/* Subsystem/device driver termination processing */
	}
	return ercd;
}

This entry routine simply performs startup processing or termination processing for a subsystem or device driver and does not provide any actual service. It must return to its caller as soon as the startup processing or termination processing is performed. An entry routine must perform its processing as quickly as possible and return to its caller.

An entry routine is called by the task which belongs to the system resource group at the time of normal system startup or shutdown, and runs in the context of the OS start processing task or termination processing task (protection level 0). In a system that supports dynamic loading of subsystems and device drivers, it may be called at other times besides system startup and shutdown.

When there are multiple subsystems and device drivers, each of the entry routines is called one at a time at system startup and shutdown. In no case are multiple entry routines called by different tasks at the same time. Accordingly, if subsystem or device driver initialization needs to be performed in a certain order, this order can be maintained by completing all necessary processing before returning from an entry routine.

The entry routine function name is normally main, but any other name may be used if, for example, main cannot be used because of linking with the OS.

  • Startup processing

ac Number of parameters (>= 0)

av Parameters (string)

return code Error

A value of ac >= 0 indicates startup processing. After performing the subsystem or device driver initialization, it registers the subsystem or device driver.

If a negative value (error) is returned as a return value, the boot process is assumed to have failed. In this case, subsystems and device drivers are deleted from the memory. So an error should not be returned while registering subsystems and device drivers. The registration must first be removed before returning the error. Allocated resources must also be released. They are not released automatically.

The parameters ac and av are the same as the parameters passed to the standard C language main() function, with ac indicating the number of parameters and av indicating a parameter string as an array of ac + 1 pointers. The array termination (avac) is NULL.

av0 is the name of the subsystem or device driver. Generally this is the file name of the subsystem or device driver, but the kind of name in which it is stored is implementation-dependent. It is also possible to have no name (blank string "").

Parameters from av1 onwards are defined separately for each subsystem and device driver.

After exiting from the entry routine, the character string space specified by av is deleted, so parameters must be saved to a different location if needed.

  • Termination processing

ac -1

av NULL

return code Error

A value of ac < 0 indicates termination processing. After deleting the subsystem or device driver registration, the entry routine releases allocated resources. If an error occurs during termination processing, the processing must not be aborted but must be completed to the extent possible. If some of the processing could not be completed normally, an error is passed in the return code.

The behavior if termination processing is called while requests to the subsystem or device driver are being processed is dependent on the subsystem or device driver implementation. Generally, termination processing is called at system shutdown and requests are not issued during processing. For this reason, ordinary behavior is not guaranteed in the case of requests issued during termination processing.

Comments

Click here to Post a Comment