2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <sys/types.h>
31 if (devices
[i
]!=NULL
) {
32 devfs_removedev(devices
[i
]->dev
);
38 static struct com_device
*com_dev_find(devfs_dev_t
*dev
) {
42 if (dev
==devices
[i
]->dev
) return devices
[i
];
47 static ssize_t
com_onread(devfs_dev_t
*dev
,void *buf
,size_t count
,off_t offset
) {
48 struct com_device
*com_dev
= com_dev_find(dev
);
49 if (dev
!=NULL
) return com_dev_recv(com_dev
,buf
,count
);
53 static ssize_t
com_onwrite(devfs_dev_t
*dev
,void *buf
,size_t count
,off_t offset
) {
54 struct com_device
*com_dev
= com_dev_find(dev
);
55 if (dev
!=NULL
) return com_dev_send(com_dev
,buf
,count
);
60 uint16_t io_ports
[] = {0x3F8,0x2F8,0x3E8,0x2E8};
69 snprintf(devname
,5,"com%d",i
);
70 devfs_dev_t
*dev
= devfs_createdev(devname
);
72 devfs_onread(dev
,com_onread
);
73 devfs_onwrite(dev
,com_onwrite
);
74 devices
[i
] = malloc(sizeof(struct com_device
));
75 devices
[i
]->base
= io_ports
[i
];
76 devices
[i
]->dev
= dev
;
78 else devices
[i
] = NULL
;
80 else devices
[i
] = NULL
;