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/processor/IoPort.h"
21 #include "pedigree/kernel/processor/Processor.h"
22 
23 uint8_t IoPort::read8(size_t offset)
24 {
25 #if defined(ADDITIONAL_CHECKS)
26  if (offset >= m_Size)
28 #endif
29 
30  uint8_t value;
31  asm volatile("inb %%dx, %%al" : "=a"(value) : "dN"(m_IoPort + offset));
32  return value;
33 }
34 uint16_t IoPort::read16(size_t offset)
35 {
36 #if defined(ADDITIONAL_CHECKS)
37  if ((offset + 1) >= m_Size)
39 #endif
40 
41  uint16_t value;
42  asm volatile("inw %%dx, %%ax" : "=a"(value) : "dN"(m_IoPort + offset));
43  return value;
44 }
45 uint32_t IoPort::read32(size_t offset)
46 {
47 #if defined(ADDITIONAL_CHECKS)
48  if ((offset + 3) >= m_Size)
50 #endif
51 
52  uint32_t value;
53  asm volatile("in %%dx, %%eax" : "=a"(value) : "dN"(m_IoPort + offset));
54  return value;
55 }
56 #if defined(BITS_64)
57 uint64_t IoPort::read64(size_t offset)
58 {
60  return 0;
61 }
62 #endif
63 void IoPort::write8(uint8_t value, size_t offset)
64 {
65 #if defined(ADDITIONAL_CHECKS)
66  if (offset >= m_Size)
68 #endif
69 
70  asm volatile("outb %%al, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
71 }
72 void IoPort::write16(uint16_t value, size_t offset)
73 {
74 #if defined(ADDITIONAL_CHECKS)
75  if ((offset + 1) >= m_Size)
77 #endif
78 
79  asm volatile("outw %%ax, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
80 }
81 void IoPort::write32(uint32_t value, size_t offset)
82 {
83 #if defined(ADDITIONAL_CHECKS)
84  if (offset >= m_Size)
86 #endif
87 
88  asm volatile("out %%eax, %%dx" ::"dN"(m_IoPort + offset), "a"(value));
89 }
90 #if defined(BITS_64)
91 void IoPort::write64(uint64_t value, size_t offset)
92 {
94 }
95 #endif
io_port_t m_IoPort
Definition: IoPort.h:82
virtual void write16(uint16_t value, size_t offset=0)
virtual uint64_t read64(size_t offset=0)
virtual uint8_t read8(size_t offset=0)
virtual void write32(uint32_t value, size_t offset=0)
virtual uint16_t read16(size_t offset=0)
static void halt()
virtual void write64(uint64_t value, 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:84