1 /*
2 * Copyright (c) 2006-2018 Ali Mashtizadeh
3 * All rights reserved.
4 */
5
6 #include <stdint.h>
7
inb(unsigned short port)8 static __inline__ unsigned char inb(unsigned short port)
9 {
10 unsigned char retval;
11 __asm__ __volatile__ ("inb %w1, %0\n\t"
12 : "=a" (retval)
13 : "d" (port));
14 return retval;
15 }
16
inw(unsigned short port)17 static __inline__ unsigned short inw(unsigned short port)
18 {
19 unsigned short retval;
20 __asm__ __volatile__ ("inw %w1, %0\n\t"
21 : "=a" (retval)
22 : "d" (port));
23 return retval;
24 }
25
inl(int port)26 static __inline__ unsigned int inl(int port)
27 {
28 unsigned int retval;
29 __asm__ __volatile__ ("inl %w1, %0\n\t"
30 : "=a" (retval)
31 : "d" (port));
32 return retval;
33 }
34
outb(int port,unsigned char val)35 static __inline__ void outb(int port, unsigned char val)
36 {
37 __asm__ __volatile__ ("outb %0, %w1\n\t"
38 :
39 : "a" (val),
40 "d" (port));
41 }
42
outw(int port,unsigned short val)43 static __inline__ void outw(int port, unsigned short val)
44 {
45 __asm__ __volatile__ ("outw %0, %w1\n\t"
46 :
47 : "a" (val),
48 "d" (port));
49 }
50
outl(int port,unsigned int val)51 static __inline__ void outl(int port, unsigned int val)
52 {
53 __asm__ __volatile__ ("outl %0, %w1\n\t"
54 :
55 : "a" (val),
56 "d" (port));
57 }
58
insb(int port,void * buf,int cnt)59 static __inline__ void insb(int port,void *buf,int cnt)
60 {
61 __asm__ __volatile__ ("cld\n\trepne\n\tinsb\n\t"
62 : "=D" (buf), "=c" (cnt)
63 : "d" (port), "0" (buf), "1" (cnt) : "memory", "cc");
64 }
65
insw(int port,void * buf,int cnt)66 static __inline__ void insw(int port,void *buf,int cnt)
67 {
68 __asm__ __volatile__ ("cld\n\trepne\n\tinsw\n\t"
69 : "=D" (buf), "=c" (cnt)
70 : "d" (port), "0" (buf), "1" (cnt) : "memory", "cc");
71 }
72
insl(int port,void * buf,int cnt)73 static __inline__ void insl(int port,void *buf,int cnt)
74 {
75 __asm__ __volatile__ ("cld\n\trepne\n\tinsl\n\t"
76 : "=D" (buf), "=c" (cnt)
77 : "d" (port), "0" (buf), "1" (cnt) : "memory", "cc");
78 }
79
outsb(int port,const void * buf,int cnt)80 static __inline__ void outsb(int port,const void *buf,int cnt)
81 {
82 __asm__ __volatile__ ("cld\n\trepne\n\toutsb\n\t"
83 : "=S" (buf), "=c" (cnt)
84 : "d" (port), "0" (buf), "1" (cnt) : "cc");
85 }
86
outsw(int port,const void * buf,int cnt)87 static __inline__ void outsw(int port,const void *buf,int cnt)
88 {
89 __asm__ __volatile__ ("cld\n\trepne\n\toutsw\n\t"
90 : "=S" (buf), "=c" (cnt)
91 : "d" (port), "0" (buf), "1" (cnt) : "cc");
92 }
93
outsl(int port,const void * buf,int cnt)94 static __inline__ void outsl(int port,const void *buf,int cnt)
95 {
96 __asm__ __volatile__ ("cld\n\trepne\n\toutsl\n\t"
97 : "=S" (buf), "=c" (cnt)
98 : "d" (port), "0" (buf), "1" (cnt) : "cc");
99 }
100