sortix-mirror/kernel/include/sortix/kernel/ioport.h
Jonas 'Sortie' Termansen 2b72262b4f Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.

All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.

All imported code from other projects is compatible with this license.

All GPL licensed code from other projects had previously been removed.

Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-05 22:21:50 +01:00

82 lines
2.2 KiB
C++

/*
* Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* sortix/kernel/ioport.h
* IO ports.
*/
#ifndef INCLUDE_SORTIX_KERNEL_IOPORT_H
#define INCLUDE_SORTIX_KERNEL_IOPORT_H
#if !(defined(__i386__) || defined(__x86_64__))
#error "This hardware platform doesn't have IO ports"
#endif
#include <stdint.h>
namespace Sortix {
__attribute__((unused))
static inline uint8_t outport8(uint16_t port, uint8_t value)
{
asm volatile ("outb %1, %0" : : "dN" (port), "a" (value));
return value;
}
__attribute__((unused))
static inline uint16_t outport16(uint16_t port, uint16_t value)
{
asm volatile ("outw %1, %0" : : "dN" (port), "a" (value));
return value;
}
__attribute__((unused))
static inline uint32_t outport32(uint16_t port, uint32_t value)
{
asm volatile ("outl %1, %0" : : "dN" (port), "a" (value));
return value;
}
__attribute__((unused))
static inline uint8_t inport8(uint16_t port)
{
uint8_t result;
asm volatile("inb %1, %0" : "=a" (result) : "dN" (port));
return result;
}
__attribute__((unused))
static inline uint16_t inport16(uint16_t port)
{
uint16_t result;
asm volatile("inw %1, %0" : "=a" (result) : "dN" (port));
return result;
}
__attribute__((unused))
static inline uint32_t inport32(uint16_t port)
{
uint32_t result;
asm volatile("inl %1, %0" : "=a" (result) : "dN" (port));
return result;
}
bool wait_inport8_clear(uint16_t ioport, uint8_t bits, bool any, unsigned int msecs);
bool wait_inport8_set(uint16_t ioport, uint8_t bits, bool any, unsigned int msecs);
} // namespace Sortix
#endif