Development of device driver under SCO UNIX
Juda Group Company Li Qiaoxia
I. Related concepts
----
1 Equipment number and device driver
---- Equipment number is a number, he is a sign of the device. These devices have corresponding special files on the system. The device number consists of two parts, namely the main device number and the secondary device number, the high byte, the primary device number and the bottom byte are the secondary device number. The type of the primary device number flag device tells the core which driver is to process the The request of the device, the secondary device number is explained by the corresponding device driver, which marks a specific physical device.
---- EX. Eight-sized cards, its main device number is the same, the secondary device number is different.
---- 2 Equipment Node
---- UNIX uses the device as a special file, called device file, which is the device node. The device node provides the interface of the physical device and its corresponding driver. 0 Add the command format of the device node is
---- Mknod device name [B / C] master number number
---- It will generate a directory entry and the corresponding I node for the device file.
---- 3 Equipment Drivers
---- Device Driver is a software interface between physical devices and operating systems, which consists of a set of subroutines, and he is responsible for communicating with physical equipment and providing a unified interface for the core of the operating system. The user-level program access the device through the device file, but the actual device read and write is done by the device driver.
---- Device driver divided into two categories: character device drivers and block device drivers.
two. Design and development of UNIX system equipment drivers
----
1 Driver provides the core routine:
---- Common: xxxinit (), xxxxClose (), xxxxread (), xxxxwrite (), xxxxiock (), xxxxhalt (); etc., so on. The xxxx here is the prefix of the device driver, the same as the device name, in this example for MyTT, this set of routines are the device driver entry routine, and the following respectively:
---- xxxinit: Initializing equipment, automatic call by the system during startup
---- XXXXHALT: Core call when the system is closed to turn off the device
---- xxxxopen: Get access to a device, when a user process calls the file system calling open, the core call takes this routine
---- XXXXCLOSE: Cancel the access to a device, when a user process calls the file system routineclose, the core calls this routine
---- XXXXRead: Reads data from the device, when the user process calls the file system routine READ, the core calls this routine to implement the data from the system address space to the user address space.
---- XXXXWRITE: Write data to the device, when the user process calls the file system routine WRITE, the core calls this routine, and the data is transmitted from the user address space to the system address space, and sent to the physical device.
---- xxxxintr: Processing device interrupt, when the device issues an interrupt request to the system, the core calls this routine to process the interrupt
---- xxxxstart: Start a driver's access, the routine is also automatically called by the core during startup. The difference between the XXINIT routine is that the XXINIT routine is used in the system initial, and the call of the XXStart routine is called after the system interrupt system has been initialized.
---- XXXXIOCT1: Control Character Device, User Process Call File System When IOCT1, the core calls this routine
---- These routines are optional.
---- 2 Parameters of the driver:
---- The system is allocated and maintained for each process and maintains a core data structure User, which contains all the information required for the process runtime. Variable u is the User data structure of the current active process. It contains only the core private, the driver will frequently use many elements, more commonly used: ---- u.u_base: The address of the user data area, contains Read / write data to be transmitted. When the user calls the file read / write system function, the address parameter exists in the unit.
---- u.u_offset: The start address of the passed data file
---- u.u_count: contains the number of bytes that are passed
---- u.u_ERROR: The value of the global variable errno when the file system calls returns
---- Data of the user data area passes through the core routine, passc (), cpass (), copyin (), copyout (), passc (), CPass () can automatically maintain U structure, Copyin (), COPYOUT () Must maintain the U structure manually.
---- 3 Debugging of the driver:
---- 1) Print from the variables to observe through the PrintF statement
---- 2) We write test procedures debugging, a simple read and write terminal device
---- 3) When the core is wrong, you can use Crash
# 出 内 内 映象
#LDSYSDUMP FileName
# crash -d filename
---- 4 installation of device drivers:
---- Installation of the device driver, usually follow the steps:
---- 1) Get the available master number, the command is:
/etc/conf/cf.d/configure - J NEXTMAJOR
Return - the main device number, such as 120.
---- 2) Establish a device file node, command is:
MKNOD / DEV / MYTT C 120 0
"/ dev / mytt" refers to the device file I have made, "C"
Refers to the character device, "120" refers to the main device number, "0" means a device number.
---- 3) Configure the system, command is:
CD / ETC / CONF / CF.D
./configure -m 120 -c -14 -t2 -v
4 -a myttinit myttopen myttclose /
Myttread myttwrite myttioct1
Option:
L4 interrupt priority
Interrupt mode used by T2 devices (0-3)
V4 needs to interrupt the phase
---- 4) Check if the device MyTT has been added to the system, command is:
./configure -j mytt
---- If returns 120, the MYTT has been added to the system, and the main device is 120. If the information is "No Sueh device", there is no device called MyTT, and the above command can also check if the system is exist in the system. If there is, you can delete the device first, then join the new device. To delete a specified device, you must know its primary device number. As shown above, the main device number command is as follows:
./configure -j mytt
./configure -m 120 -c -d
Remove the device MyTT from the core
---- 5) Compile the driver source code, copy the generated .o file to /etc/conf/pack.d directory
---- Compile the driver source code command line:
CC -C -D_INkernel mytt.c
Mkdir /etc/conf/pack.d/mytt
CP mytt.o /etc/conf/pack.d/mytt/driver.o ----- 6) Key core
CD / ETC / CONF / CF.D
./link_unix
---- Answer two Y, then generate a new core Unix in the root directory, the old core file is saved as a UNIX.o1D driver is installed, you need to restart the UNIX system, the device driver can be effective The system automatically executes myTTINIT (), displaying information in the main station, indicating that the device driver is installed. Development of device driver under SCO UNIX
Juda Group Company Li Qiaoxia
I. Related concepts
----
1 Equipment number and device driver
---- Equipment number is a number, he is a sign of the device. These devices have corresponding special files on the system. The device number consists of two parts, namely the main device number and the secondary device number, the high byte, the primary device number and the bottom byte are the secondary device number. The type of the primary device number flag device tells the core which driver is to process the The request of the device, the secondary device number is explained by the corresponding device driver, which marks a specific physical device.
---- EX. Eight-sized cards, its main device number is the same, the secondary device number is different.
---- 2 Equipment Node
---- UNIX uses the device as a special file, called device file, which is the device node. The device node provides the interface of the physical device and its corresponding driver. 0 Add the command format of the device node is
---- Mknod device name [B / C] master number number
---- It will generate a directory entry and the corresponding I node for the device file.
---- 3 Equipment Drivers
---- Device Driver is a software interface between physical devices and operating systems, which consists of a set of subroutines, and he is responsible for communicating with physical equipment and providing a unified interface for the core of the operating system. The user-level program access the device through the device file, but the actual device read and write is done by the device driver.
---- Device driver divided into two categories: character device drivers and block device drivers.
two. Design and development of UNIX system equipment drivers
----
1 Driver provides the core routine:
---- Common: xxxinit (), xxxxClose (), xxxxread (), xxxxwrite (), xxxxiock (), xxxxhalt (); etc., so on. The xxxx here is the prefix of the device driver, the same as the device name, in this example for MyTT, this set of routines are the device driver entry routine, and the following respectively:
---- xxxinit: Initializing equipment, automatic call by the system during startup
---- XXXXHALT: Core call when the system is closed to turn off the device
---- xxxxopen: Get access to a device, when a user process calls the file system calling open, the core call takes this routine
---- XXXXCLOSE: Cancel the access to a device, when a user process calls the file system routineclose, the core calls this routine
---- XXXXRead: Reads data from the device, when the user process calls the file system routine READ, the core calls this routine to implement the data from the system address space to the user address space.
---- XXXXWRITE: Write data to the device, when the user process calls the file system routine WRITE, the core calls this routine, and the data is transmitted from the user address space to the system address space, and sent to the physical device.
---- xxxxintr: Processing device interrupt, when the device issues an interrupt request to the system, the core calls this routine to process the interrupt
---- xxxxstart: Start a driver's access, the routine is also automatically called by the core during startup. The difference between the XXINIT routine is that the XXINIT routine is used in the system initial, and the call of the XXStart routine is called after the system interrupt system has been initialized. ---- XXXXIOCT1: Control Character Device, User Process Call File System When IOCT1, the core calls this routine
---- These routines are optional.
---- 2 Parameters of the driver:
---- The system is allocated and maintained for each process and maintains a core data structure User, which contains all the information required for the process runtime. The variable u is the USER data structure of the current active process. It contains only the core private, the driver often uses many elements, more commonly used:
---- u.u_base: The address of the user data area contains read / write data to be transmitted. When the user calls the file read / write system function, the address parameter exists in the unit.
---- u.u_offset: The start address of the passed data file
---- u.u_count: contains the number of bytes that are passed
---- u.u_ERROR: The value of the global variable errno when the file system calls returns
---- Data of the user data area passes through the core routine, passc (), cpass (), copyin (), copyout (), passc (), CPass () can automatically maintain U structure, Copyin (), COPYOUT () Must maintain the U structure manually.
---- 3 Debugging of the driver:
---- 1) Print from the variables to observe through the PrintF statement
---- 2) We write test procedures debugging, a simple read and write terminal device
---- 3) When the core is wrong, you can use Crash
# 出 内 内 映象
#LDSYSDUMP FileName
# crash -d filename
---- 4 installation of device drivers:
---- Installation of the device driver, usually follow the steps:
---- 1) Get the available master number, the command is:
/etc/conf/cf.d/configure - J NEXTMAJOR
Return - the main device number, such as 120.
---- 2) Establish a device file node, command is:
MKNOD / DEV / MYTT C 120 0
"/ dev / mytt" refers to the device file I have made, "C"
Refers to the character device, "120" refers to the main device number, "0" means a device number.
---- 3) Configure the system, command is:
CD / ETC / CONF / CF.D
./configure -m 120 -c -14 -t2 -v
4 -a myttinit myttopen myttclose /
Myttread myttwrite myttioct1
Option:
L4 interrupt priority
Interrupt mode used by T2 devices (0-3)
V4 needs to interrupt the phase
---- 4) Check if the device MyTT has been added to the system, command is:
./configure -j mytt
---- If returns 120, the MYTT has been added to the system, and the main device is 120. If the information is "No Sueh device", there is no device called MyTT, and the above command can also check if the system is exist in the system. If there is, you can delete the device first, then join the new device. To delete a specified device, you must know its primary device number. The main device number command is as follows, the steps are as follows :/ configure -j mytt
./configure -m 120 -c -d
Remove the device MyTT from the core
---- 5) Compile the driver source code, copy the generated .o file to /etc/conf/pack.d directory
---- Compile the driver source code command line:
CC -C -D_INkernel mytt.c
Mkdir /etc/conf/pack.d/mytt
Cp mytt.o /etc/conf/pack.d/mytt/driver.o
---- 6) Key core
CD / ETC / CONF / CF.D
./link_unix
---- Answer two Y, then generate a new core Unix in the root directory, the old core file is saved as a UNIX.o1D driver is installed, you need to restart the UNIX system, the device driver can be effective The system automatically executes myTTINIT (), displaying information in the main station, indicating that the device driver is installed.