1 / 39

Presented by Shih-hsun Chang January 02, 2003

Presented by Shih-hsun Chang January 02, 2003. Outline. An Overview of the Operating Systems Driver Layers and Device Objects Layered, IRPs, and I/O Objects A GenPort Example Installing Device Drivers Conclusion. Windows 98 Architecture. Windows 2000 Architecture. (Rtl, Zw). (CM).

teagan
Download Presentation

Presented by Shih-hsun Chang January 02, 2003

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Presented by Shih-hsun Chang January 02, 2003

  2. Outline • An Overview of the Operating Systems • Driver Layers and Device Objects • Layered, IRPs, and I/O Objects • A GenPort Example • Installing Device Drivers • Conclusion Real Time Systems Lab

  3. Windows 98 Architecture Real Time Systems Lab

  4. Windows 2000 Architecture Real Time Systems Lab

  5. (Rtl, Zw) (CM) (Ob) (Se) (Mm) (PNP) (Ps) (Io) Run-Time library ZwXxx routines (Ke) (Ex) (Hal) (Po) Windows 2000 Component Overview (I) Real Time Systems Lab

  6. Windows 2000 Component Overview (II) • I/O Manager (Io) - contains many service functions that drivers use. • Process Structure (Ps) - creates and manages kernel-mode threads. • Ex: an independent thread to repeatedly poll a device incapable of generating interrupts. • Memory Manager (Mn) - controls the page tables that define the mapping of virtual address onto physical memory. • Executive Support (Ex) – supplies heap management and synchronization services. • Object Manager (Ob) – provides centralized control over the many data objects with which Windows NT works. • Ex: keeping a reference count that prevents an object from disappearing while someone is still using it. Real Time Systems Lab

  7. Windows 2000 Component Overview (III) • Security Reference Monitor (Se) – allows file system drivers to perform security checks. • Run-time library (Rtl) – contains utility routines, such as list and string management routines. • Ex: unicode • Windows NT implements user-modecalls to the Win32 subsystem in kernel mode with routines whose names begin with the Ze. • Windows NT kernel (Ke) – is where all the low-level synchronization of activities between threads and processors occurs. • Hardware abstraction layer (Hal) – understands how interrupts work on a particular platform, how to implement spin lock, how to address I/O and memory-mapped devices, and so on. • Configuration Manager (CM) - these functions provide high-level device installation support used by system installation and maintenance utilities. Real Time Systems Lab

  8. Windows 2000 and WDM Driver Design Goals • Portability from one platform to another • Configurability of hardware and software • Always Preemptible and Always Interruptible • The kernel-defined run-time priority scheme for threads • The kernel-defined interrupt request level (IRQL) • Deferred procedure call (DPC) – Bottom half of Linux • Multiprocessor-safe on multiprocessor platforms • Spin lock • Object-based • Packet-driven I/O with reusable I/O request packets (IRPs) • Has a fixed part and one or more driver-specific I/O stack locations. • Supporting for asynchronous I/O Real Time Systems Lab

  9. Outline • An Overview of the Operating Systems • Driver Layers and Device Objects • Layered, IRPs, and I/O Objects • A GenPort Example • Installing Device Drivers • Conclusion Real Time Systems Lab

  10. Device Tree Real Time Systems Lab

  11. Device Tree (contd.) Real Time Systems Lab

  12. Kinds of Drivers • Bus driver • drives an I/O bus and provides per-slot functionality that is device-independent. • Microsoft provides bus drivers for most common buses such as PCI, SCSI, and USB. • Function driver • drives an individual device. • provided by the device vendor. • Filter driver • filters I/O requests for a device, a class of devices, or a bus . • add value to or modify the behavior of a device and/or a bus. • provide by the Microsoft or a system OEM. Real Time Systems Lab

  13. Driver Layers Real Time Systems Lab

  14. Driver Layers — An Example Real Time Systems Lab

  15. Kinds of Device Objects • Physical Device Object (PDO) • represents a device on a bus to a bus driver • Functional Device Object (FDO) • represents a device to a function driver • Filter Device Object (filter DO) • represents a device to a filter driver Real Time Systems Lab

  16. Device Objects — An Example Real Time Systems Lab

  17. Outline • An Overview of the Operating Systems • Driver Layers and Device Objects • Layered, IRPs, and I/O Objects • A GenPort Example • Installing Device Drivers • Conclusion Real Time Systems Lab

  18. File Objects Represent Files and Devices Real Time Systems Lab

  19. Opening a File Object Real Time Systems Lab

  20. Processing IRPs in Layered Drivers Real Time Systems Lab

  21. Processing IRPs in Layered Drivers (contd.) Real Time Systems Lab

  22. Outline • An Overview of the Operating Systems • Driver Layers and Device Objects • Layered, IRPs, and I/O Objects • A GenPort Example • Installing Device Drivers • Conclusion Real Time Systems Lab

  23. DriverEntry Routine • Each driver must have a DriverEntry routine, which initializes driver-wide data structures and resources. • The I/O Manager calls the DriverEntry routine when it loads the driver. • It is responsible for driver initialization. Real Time Systems Lab

  24. DriverEntry Routine (contd.) NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { // Create dispatch points for the IRPs. DriverObject->MajorFunction[IRP_MJ_CREATE] = GpdDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = GpdDispatch; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = GpdDispatch; DriverObject->DriverUnload = GpdUnload; DriverObject->MajorFunction[IRP_MJ_PNP] = GpdDispatchPnp; DriverObject->MajorFunction[IRP_MJ_POWER] = GpdDispatchPower; DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = GpdDispatchSystemControl; DriverObject->DriverExtension->AddDevice = GpdAddDevice; return STATUS_SUCCESS; } DRIVER_EXTENSION DRIVER_OBJECT Real Time Systems Lab

  25. AddDevice Routine • A driver has a special AddDevice function that the PnP Manager can call for each such device. • It is responsible for device initialization. • In the routine you create a device object by calling IoCreateDevice. Real Time Systems Lab

  26. AddDevice Routine (contd.) NTSTATUS GpdAddDevice( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT PhysicalDeviceObject ) { …… PAGED_CODE(); RtlInitUnicodeString(&ntDeviceName, GPD_DEVICE_NAME); \* \\Device\\Gpd0 */ // Create a device object. status = IoCreateDevice (DriverObject, sizeof (LOCAL_DEVICE_INFO), &ntDeviceName, GPD_TYPE, 0, FALSE, &deviceObject); if (!NT_SUCCESS (status)) return status; deviceInfo = (PLOCAL_DEVICE_INFO) deviceObject->DeviceExtension; deviceInfo->NextLowerDriver = IoAttachDeviceToDeviceStack ( deviceObject, PhysicalDeviceObject); if(NULL == deviceInfo->NextLowerDriver) { IoDeleteDevice(deviceObject); return STATUS_NO_SUCH_DEVICE; } …… return STATUS_SUCCESS; } DEVICE_OBJECT Real Time Systems Lab

  27. Read Operation void main(int argc, char ** argv) { …… hndFile = CreateFile( "\\\\.\\GpdDev", // Open the Device "file" GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); IoctlResult = DeviceIoControl( hndFile, // Handle to device IOCTL_GPD_READ_PORT_UCHAR, // IO Control code for Read &PortNumber, // Buffer to driver. sizeof(PortNumber), // Length of buffer in bytes. &DataBuffer, // Buffer from driver. DataLength, // Length of buffer in bytes. &ReturnedLength, // Bytes placed in DataBuffer. NULL // NULL means wait till op. completes. ); …. CloseHandle(hndFile); } Real Time Systems Lab

  28. Dispatch Routine NTSTATUS GpdDispatch( IN PDEVICE_OBJECT pDO, IN PIRP pIrp) { …… pIrpStack = IoGetCurrentIrpStackLocation(pIrp); switch (pIrpStack->MajorFunction) { case IRP_MJ_CREATE, IRP_MJ_CLOSE : …… break; case IRP_MJ_DEVICE_CONTROL: // Dispatch on IOCTL switch (pIrpStack->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_GPD_READ_PORT_UCHAR: Status = GpdIoctlReadPort( pLDI, pIrp, pIrpStack, pIrpStack->Parameters.DeviceIoControl.IoControlCode); break; } break; } pIrp->IoStatus.Status = Status; IoCompleteRequest(pIrp, IO_NO_INCREMENT ); return Status; } I/O Stack Location Real Time Systems Lab

  29. Outline • An Overview of the Operating Systems • Driver Layers and Device Objects • Layered, IRPs, and I/O Objects • Installing Device Drivers • Conclusion Real Time Systems Lab

  30. Version Section [Version] Signature="$WINDOWS NT$" Class=Sample ClassGuid={78A1C341-4539-11d3-B88D-00C04FAD5171} Provider=%MSFT% DriverVer=06/16/1999,5.00.2072 [Strings] MSFT = "Microsoft" ClassName = "Sample Drivers" PortIO.SVCDESC = "Sample PortIO Service" PortIO.DRVDESC = "Sample PortIO Driver" DISK_NAME = "Portio Sample Install Disk" Real Time Systems Lab

  31. Tree Structure of an INF file Real Time Systems Lab

  32. Manufacturers [Manufacturer] %MSFT%=MSFT [MSFT] ; DisplayName Section DeviceId ; ----------- ------- -------- %PortIO.DRVDESC%=PortIO_Inst,root\portio [PortIO_Inst.NT] CopyFiles=PortIO.CopyFiles LogConfig=PortIO.LC0, PortIO.LC1 [PortIO.LC0] ConfigPriority=DESIRED IOConfig=300-303(3ff::) ; 10 bit decode ranging from 300 - 303 [PortIO.LC1] ConfigPriority=NORMAL IOConfig=4@300-3ff(3ff::) ; 4 ports starting anywhere between 300 and 3fc Real Time Systems Lab

  33. Manufacturers (contd.) Real Time Systems Lab

  34. Source and Destination Information for File Copies Real Time Systems Lab

  35. Source and Destination Information for File Copies (contd.) [DestinationDirs] DefaultDestDir = 10,System32\Drivers [SourceDisksFiles] genport.sys=1 [SourceDisksNames] 1=%DISK_NAME%, [PortIO.CopyFiles] genport.sys Real Time Systems Lab

  36. AddReg Section [PortIO_Inst.NT.Services] AddService=portio,0x00000002,PortIO_Service [PortIO_Service] DisplayName = %PortIO.SVCDESC% ServiceType = 1; SERVICE_KERNEL_DRIVER StartType = 3; SERVICE_DEMAND_START ErrorControl = 1; SERVICE_ERROR_NORMAL ServiceBinary = %12%\genport.sys Real Time Systems Lab

  37. AddReg Section (contd.) Real Time Systems Lab

  38. A Final Snapshot Real Time Systems Lab

  39. Conclusion • It is not easy to understand Windows Driver Model and its design idea. • I think I must spend a half of year to lean and practice the WDM. • WDM is a good model for designing device driver model of OS. Real Time Systems Lab

More Related