INF: Limitations on Writing Device Drivers in C

ID Number: Q10826

4.00 5.00 5.10 6.00 6.00a 6.00ax

MS-DOS

Summary:

This article discusses the limitations of writing MS-DOS device

drivers with Microsoft C versions 4.0, 5.0, 5.1, 6.0, 6.0a, and 6.0ax.

More Information:

You cannot write complete device drivers in C. You must write some

parts in assembly, and you cannot use the majority of the C run-time

library support.

The major problems with using C to write device drivers are:

1. The .EXE loader is in COMMAND.COM, and therefore not available to

load device drivers. In this case, the device driver must be a

binary image of a single-segment program. The C compiler does not

generate such code. At best, in small model, you have two disjoint

physical segments [one for code (CS) and one for data (SS AND DS)].

2. The C run-time initialization code depends on the PSP (program

segment prefix) being set up properly and it relies on MS-DOS being

available. Although, the startup source is provided, it is mainly

assembly code and requires major modifications.

3. The entry-exit sequences for C functions are not appropriate for

being called as an MS-DOS driver.

You can work around some of these limitations by using assembly code

generated by the C compiler. The -Fa switch directs the compiler to

output assembler source code, which then can be edited and used as

part of the driver source code. Depending on the complexity of the

MS-DOS driver, it is possible that most of the driver could be written

in C and still provide for reasonably easy modification and

maintenance.

Additional reference words: 5.00 5.10 6.00 6.00a 6.00ax