Presentation is loading. Please wait.

Presentation is loading. Please wait.

52 Advanced Operating Systems Writing Device Drivers.

Similar presentations


Presentation on theme: "52 Advanced Operating Systems Writing Device Drivers."— Presentation transcript:

1 52 Advanced Operating Systems Writing Device Drivers

2 53 What are device drivers? Software interfaces to hardware resources in the kernel –Mirrors variety of hardware resources –Can change constantly –Will require reconfiguration –Different interfaces into the same devices –Require kernel resident programs –Uses module interface

3 54 Split level kernel User programs and applications Application level Kernel level Kernel parts features software hardware Hardware level Process mgment Memory mgment File systems Device Control Networking Achture code Memory Mang. Fs types Block Dvc Character Devices Networks If drivers Multi-tasking V Memory Files & Dirs TTYS & devs Connectivity CPURAM Disks & CDs Console S Ports Network Interfaces

4 55 Types of device driver There are some general types or characteristics of device drivers –Character devices Serial data stream –Block devices Accessed via blocked data stream –Network interfaces Although serial, has no mapping into file system

5 56 Recognising device drivers Apart from network devices most drivers appear like file in the Unix system ls –l /dev –crw-r--r-- 1 root root 10, 134 Jun7 1996 apm_bios –brw-rw---- 1 root floppy 2, 0 May 14 1996 fd0 Device type Major number Minor number File Name

6 57 Character Device Drivers Data is a serial stream No random access Even a block devices can be a character one! –Printers

7 58 Block Devices Data is read in blocks Block size depends upon the device Random access is supported Files systems can only be mounted block devices Block devices can have character interfaces –fsck works on character “raw” interface to file system

8 59 Network Interfaces Network interfaces act in some ways like a serial character orientated device, however they don’t exist in the file system For example eth0 is queried through the ifconfig command Weirdly, network devices can support block features for example network mounted file systems

9 60 Character & Block Devices Character devices –1 Memory –4 Terminal –6 Parallel interfaces –7 Vitual consoles –9 SCSI tapes –10 Bus mice –12 QIC02 Tape –13 PC speaker driver Block devices –1 RAM disk –2 Floppy disk –3 IDE disk –8 SCSI disk –11 SCSI CD-ROM –13XT 8-bit hard disk

10 61 Building kernel modules The program below is a simple kernel module compiled by –gcc –c test.c It prints hello world when installed by –insmod test.o and goodbye cruel world when removed by –rmmod test #define MODULE #include int init_module(void) {printk(" Hello world\n");return 0;} void cleanup_module(void) {printk(" Goodbye cruel world\n");}

11 62 Features of kernel programming Don’t use libraries – only kernel code –Printk not printf Set use of headers –/usr/include/asm & /usr/include/linux Beware of namespace pollution –Code shares names with the kernel –Use static


Download ppt "52 Advanced Operating Systems Writing Device Drivers."

Similar presentations


Ads by Google