CS 635 PROJECT 2 Due Date: Noon Friday 02/28/2003 The purpose of this project is to gain familiarity with designing a character device-driver for Linux, and simultaneously to create a useful tool for future study of the Linux memory-management system. PROJECT STATEMENT Create an installable module (named 'physmem.c') which implements a Linux device-driver for a 'read-only' character-mode device (represented by a device-file named '/dev/physmem'), that allows application programs to read the computer's physical memory as if it were just one big file. For the purposes of this project, you may disregard physical memory in excess of 896 megabytes (i.e., memory physically located at addresses equal to 0x3E000000 or higher). For 32-bit Intel Architecture machines, any physical memory at, or above, this address is known as 'high memory' and is not directly mapped into the kernel's virtual address-space. But all physical memory located BELOW this address IS directly mapped to the kernel's virtual address-space, via a straightforward linear mapping: physical addresses virtual addresses ----------------------- ----------------------- 0x00000000 - 0x37FFFFFF ---> 0xC0000000 - 0xF7FFFFFF Some symbolic constants, macros, and inline functions are defined in the kernel header-files which facilitate your writing code that makes use of this physical-to-virtual linear mapping: #define __PAGE_OFFSET 0xC0000000 #define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET) #define __va(x) ((void*)(unsigned long)(x)+PAGE_OFFSET)) #define __pa(x) ((unsigned long)(x)-PAGE_OFFSET) static inline void * phys_to_virt( unsigned long address ) { return __va(address); } static inline unsigned long virt_to_phys( volatile void *address ) { return __pa(address); } In addition, there is a kernel variable (named 'high_memory') which gets initialized during system startup with the virtual address corresponding to the end of the directly-mapped region of physical memory: void * high_memory; So you can use this value to determine the size for your device-driver's device-file, as follows: unsigned long filesize = virt_to_phys( high_memory ); _______________________________________________________________________ (c) Allan B. Cruse University of San Francisco Spring 2003