| 1 | /* |
|---|
| 2 | * cpu-io.c - cpu io access |
|---|
| 3 | * |
|---|
| 4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
|---|
| 5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
|---|
| 6 | * |
|---|
| 7 | * This file is part of ALMOS-kernel. |
|---|
| 8 | * |
|---|
| 9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
|---|
| 10 | * under the terms of the GNU General Public License as published by |
|---|
| 11 | * the Free Software Foundation; version 2.0 of the License. |
|---|
| 12 | * |
|---|
| 13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
|---|
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 16 | * General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * You should have received a copy of the GNU General Public License |
|---|
| 19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
|---|
| 20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | #include <types.h> |
|---|
| 24 | #include <cpu-io.h> |
|---|
| 25 | |
|---|
| 26 | void cpu_io_out8(uint_t port, uint8_t value) |
|---|
| 27 | { |
|---|
| 28 | __asm__ volatile |
|---|
| 29 | ("movl %%eax, %%ecx \n" |
|---|
| 30 | "outb %%al, %%dx \n" |
|---|
| 31 | "jmp 1f \n" |
|---|
| 32 | "1: \n" |
|---|
| 33 | "movl %%ecx, %%eax \n" |
|---|
| 34 | : : "a" (value), "d" (port)); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | void cpu_io_out16(uint_t port, uint16_t value) |
|---|
| 38 | { |
|---|
| 39 | __asm__ volatile |
|---|
| 40 | ("outw %%ax, %%dx \n" |
|---|
| 41 | "jmp 1f \n" |
|---|
| 42 | "1: \n" |
|---|
| 43 | : : "a" (value), "d" (port)); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | void cpu_io_out32(uint_t port, uint32_t value) |
|---|
| 47 | { |
|---|
| 48 | __asm__ volatile |
|---|
| 49 | ("outl %0, %1 \n" |
|---|
| 50 | "jmp 1f \n" |
|---|
| 51 | "1: \n" |
|---|
| 52 | : : "a" (value), "d" ((uint16_t)port)); |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | uint8_t cpu_io_in8(uint_t port) |
|---|
| 57 | { |
|---|
| 58 | register uint8_t value; |
|---|
| 59 | |
|---|
| 60 | __asm__ volatile |
|---|
| 61 | ("inb %%dx, %%al \n" |
|---|
| 62 | : "=a" (value) : "d" (port)); |
|---|
| 63 | |
|---|
| 64 | return value; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | uint16_t cpu_io_in16(uint_t port) |
|---|
| 68 | { |
|---|
| 69 | register uint16_t value; |
|---|
| 70 | |
|---|
| 71 | __asm__ volatile |
|---|
| 72 | ("inw %%dx, %%ax \n" |
|---|
| 73 | : "=a" (value) : "d" (port)); |
|---|
| 74 | |
|---|
| 75 | return value; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | uint32_t cpu_io_in32(uint_t port) |
|---|
| 79 | { |
|---|
| 80 | register uint32_t value; |
|---|
| 81 | |
|---|
| 82 | __asm__ volatile |
|---|
| 83 | ("inl %1, %0 \n" |
|---|
| 84 | : "=a" (value) : "d" ((uint16_t)port)); |
|---|
| 85 | |
|---|
| 86 | return value; |
|---|
| 87 | } |
|---|