+ exec* functions
[meinos.git] / apps / include / ioport.h
blob9eff8b48ecae427e85cc1c35ec58a2e8c7235e39
1 /*
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 Lesser 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _LIBMEINOS_IOPORT_H_
20 #define _LIBMEINOS_IOPORT_H_
22 #include <stdint.h>
23 #include <syscall.h>
24 #include <errno.h>
26 static inline int ioport_reg(uint16_t port) {
27 int ret = syscall_call(SYSCALL_IO_REG,1,port);
28 errno = ret<0?-ret:0;
29 return ret<0?-1:ret;
32 static inline int ioport_unreg(uint16_t port) {
33 int ret = syscall_call(SYSCALL_IO_UNREG,1,port);
34 errno = ret<0?-ret:0;
35 return ret<0?-1:ret;
38 static inline uint8_t inb(uint16_t _port) {
39 uint8_t _result;
40 __asm__("inb %1, %0":"=a"(_result):"Nd"(_port));
41 return _result;
44 static inline uint16_t inw(uint16_t _port) {
45 uint16_t _result;
46 __asm__("inw %1, %0":"=a"(_result):"Nd"(_port));
47 return _result;
50 static inline uint32_t inl(uint16_t _port) {
51 uint32_t _result;
52 __asm__("inl %1, %0":"=a"(_result):"Nd"(_port));
53 return _result;
56 static inline void outw(uint16_t _port,uint16_t _data) {
57 __asm__("outw %0, %1"::"a"(_data),"Nd"(_port));
60 static inline void outb(uint16_t _port,uint8_t _data) {
61 __asm__("outb %0, %1"::"a"(_data),"Nd"(_port));
64 static inline void outl(uint16_t _port,uint32_t _data) {
65 __asm__("outl %0, %1"::"a"(_data),"Nd" (_port));
68 #endif