The Pedigree Project 0.1
x86_common/IoPort.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/panic.h"
21#include "pedigree/kernel/processor/IoPort.h"
22#include "pedigree/kernel/processor/Processor.h"
23
24uint8_t IoPort::read8(size_t offset) {
25#if ADDITIONAL_CHECKS
26 if (offset >= m_Size)
27 panic("8-bit IO read past allocated space.");
28#endif
29
30 uint8_t value;
31 asm volatile("inb %%dx, %%al" : "=a"(value) : "dN"(m_IoPort + offset));
32 return value;
33}
34uint16_t IoPort::read16(size_t offset) {
35#if ADDITIONAL_CHECKS
36 if ((offset + 1) >= m_Size)
37 panic("16-bit IO read past allocated space.");
38#endif
39
40 uint16_t value;
41 asm volatile("inw %%dx, %%ax" : "=a"(value) : "dN"(m_IoPort + offset));
42 return value;
43}
44uint32_t IoPort::read32(size_t offset) {
45#if ADDITIONAL_CHECKS
46 if ((offset + 3) >= m_Size)
47 panic("32-bit IO read past allocated space.");
48#endif
49
50 uint32_t value;
51 asm volatile("in %%dx, %%eax" : "=a"(value) : "dN"(m_IoPort + offset));
52 return value;
53}
54#if BITS_64
55uint64_t IoPort::read64(size_t offset) {
57 return 0;
58}
59#endif
60void IoPort::write8(uint8_t value, size_t offset) {
61#if ADDITIONAL_CHECKS
62 if (offset >= m_Size)
63 panic("8-bit IO write past allocated space.");
64#endif
65
66 asm volatile("outb %%al, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
67}
68void IoPort::write16(uint16_t value, size_t offset) {
69#if ADDITIONAL_CHECKS
70 if ((offset + 1) >= m_Size)
71 panic("16-bit IO write past allocated space.");
72#endif
73
74 asm volatile("outw %%ax, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
75}
76void IoPort::write32(uint32_t value, size_t offset) {
77#if ADDITIONAL_CHECKS
78 if (offset >= m_Size)
79 panic("32-bit IO write past allocated space.");
80#endif
81
82 asm volatile("out %%eax, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
83}
84#if BITS_64
85void IoPort::write64(uint64_t value, size_t offset) {
87}
88#endif
virtual uint64_t read64(size_t offset=0)
virtual uint16_t read16(size_t offset=0)
virtual uint32_t read32(size_t offset=0)
virtual void write8(uint8_t value, size_t offset=0)
size_t m_Size
Definition IoPort.h:82
virtual void write32(uint32_t value, size_t offset=0)
virtual uint8_t read8(size_t offset=0)
io_port_t m_IoPort
Definition IoPort.h:80
virtual void write64(uint64_t value, size_t offset=0)
virtual void write16(uint16_t value, size_t offset=0)
static void halt()
void EXPORTED_PUBLIC panic(const char *msg) NORETURN
Definition panic.cc:118