root / Whitix / branches / hybrid / devices / misc.c

Revision 330, 1.9 kB (checked in by mwhitworth, 6 months ago)

Add mmap function for Zero.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#include <fs/vfs.h>
20#include <fs/devfs.h>
21#include <typedefs.h>
22#include <init.h>
23#include <i386/i386.h>
24#include <i386/virtual.h>
25
26#define MISC_MAJOR 2
27
28static int ZeroRead(struct File* file,BYTE* data,DWORD size)
29{
30        ZeroMemory(data,size);
31        return size;
32}
33
34static int ZeroMemoryMap(struct VNode* vNode, DWORD address, DWORD offset)
35{
36        ZeroMemory(address, PAGE_SIZE);
37        return 0;
38}
39
40static int NullWrite(struct File* file,BYTE* data,DWORD size)
41{
42        return size;
43}
44
45static int MemMemoryMap(struct VNode* vNode, DWORD address, DWORD offset)
46{
47//      printf("Mapping %#X to %#X\n", address, offset);
48        VirtMemMapPage(address, offset, PAGE_USER | PAGE_RW | PAGE_PRESENT);
49        return 0;
50}
51
52struct FileOps nullOps={
53        .write = NullWrite,
54};
55
56struct FileOps zeroOps={
57        .read = ZeroRead,
58        .mMap = ZeroMemoryMap,
59};
60
61struct FileOps memOps={
62        .mMap = MemMemoryMap,
63};
64
65int MiscInit()
66{
67        DevAddDevice("Special/Null",MISC_MAJOR,0,DEVICE_CHAR,&nullOps);
68        DevAddDevice("Special/Zero",MISC_MAJOR,1,DEVICE_CHAR,&zeroOps);
69        DevAddDevice("Special/Memory",MISC_MAJOR,2,DEVICE_CHAR,&memOps);
70
71        return 0;
72}
73
74DeviceInit(MiscInit);
Note: See TracBrowser for help on using the browser.