OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [bios/] [io.h] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see <http://www.gnu.org/licenses/>.
17
 
18
#pragma once
19
 
20
static inline void outw(unsigned short port, unsigned short v)
21
{
22
    asm volatile("outw %1, %0" : : "d"(port), "a"(v));
23
}
24
 
25
static inline void outb(unsigned short port, unsigned char v)
26
{
27
    asm volatile(
28
        "mov %0, %%al\n"
29
        "outb %%al, %w1"
30
        :
31
        : "a"(v), "Nd"(port)
32
        : "%al");
33
}
34
 
35
static inline unsigned short inw(unsigned short port)
36
{
37
    unsigned short v;
38
 
39
    asm volatile("inw %1, %0" : "=a"(v) : "d"(port));
40
 
41
    return v;
42
}
43
 
44
static inline unsigned char inb(unsigned short port)
45
{
46
    unsigned char v;
47
 
48
    asm volatile(
49
        "inb %w1, %%al\n"
50
        "mov %%al, %0"
51
        : "=a"(v)
52
        : "Nd"(port)
53
        : "%al");
54
 
55
    return v;
56
}
57
 
58
static inline void writeb(unsigned short segment,
59
                          unsigned short address,
60
                          unsigned char val)
61
{
62
    asm volatile(
63
        "push %%ds\n"
64
        "mov %P[segment], %%ds\n"
65
        "mov %P[address], %%bx\n"
66
        "movb %P[val], (%%bx)\n"
67
        "pop %%ds"
68
        :
69
        : [segment] "r"(segment), [address] "m"(address), [val] "r"(val)
70
        : "%bx", "memory");
71
}
72
 
73
static inline void writew(unsigned short segment,
74
                          unsigned short address,
75
                          unsigned short val)
76
{
77
    asm volatile(
78
        "push %%ds\n"
79
        "mov %P[segment], %%ds\n"
80
        "mov %P[address], %%bx\n"
81
        "movw %P[val], (%%bx)\n"
82
        "pop %%ds"
83
        :
84
        : [segment] "r"(segment), [address] "m"(address), [val] "r"(val)
85
        : "%bx", "memory");
86
}
87
 
88
static inline void memcpy_seg(unsigned short dseg,
89
                              void *dst,
90
                              unsigned short sseg,
91
                              const void *src,
92
                              unsigned short len)
93
{
94
    asm volatile(
95
        "push %%ds\n"
96
        "push %%es\n"
97
        "push %%cx\n"
98
        "push %%si\n"
99
        "push %%di\n"
100
        "cld\n"
101
        "mov %P[dseg], %%es\n"
102
        "mov %P[sseg], %%ds\n"
103
        "mov %P[len], %%cx\n"
104
        "rep movsb\n"
105
        "pop %%di\n"
106
        "pop %%si\n"
107
        "pop %%cx\n"
108
        "pop %%es\n"
109
        "pop %%ds\n"
110
        :
111
        : [dseg] "r"(dseg), [sseg] "r"(sseg), "S"(src), "D"(dst), [len] "r"(len)
112
        : "memory", "cc");
113
}
114
 
115
static inline unsigned char readb(unsigned short segment,
116
                                  unsigned short address)
117
{
118
    unsigned char v;
119
 
120
    asm volatile(
121
        "push %%ds\n"
122
        "mov %P[segment], %%ds\n"
123
        "mov %P[address], %%bx\n"
124
        "movb (%%bx), %P[val]\n"
125
        "pop %%ds"
126
        : [val] "=r"(v)
127
        : [segment] "r"(segment), [address] "m"(address)
128
        : "%bx", "memory");
129
 
130
    return v;
131
}
132
 
133
static inline unsigned short readw(unsigned short segment,
134
                                   unsigned short address)
135
{
136
    unsigned short v;
137
 
138
    asm volatile(
139
        "push %%ds\n"
140
        "mov %P[segment], %%ds\n"
141
        "mov %P[address], %%bx\n"
142
        "movw (%%bx), %P[val]\n"
143
        "pop %%ds"
144
        : [val] "=r"(v)
145
        : [segment] "r"(segment), [address] "m"(address)
146
        : "%bx", "memory");
147
 
148
    return v;
149
}
150
 
151
static inline unsigned short get_cs(void)
152
{
153
    unsigned short cs;
154
 
155
    asm volatile("mov %%cs, %0" : "=r"(cs));
156
 
157
    return cs;
158
}
159
 
160
static inline unsigned short get_es(void)
161
{
162
    unsigned short es;
163
 
164
    asm volatile("mov %%es, %0" : "=r"(es));
165
 
166
    return es;
167
}
168
 
169
static inline void set_es(unsigned short es)
170
{
171
    asm volatile("mov %0, %%es" ::"r"(es));
172
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.