Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/libsaio/io_inline.h

1/*
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 2.0 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Copyright (c) 1992 NeXT Computer, Inc.
26 *
27 * Inlines for io space access.
28 *
29 * HISTORY
30 *
31 * 20 May 1992 ? at NeXT
32 *Created.
33 */
34
35#ifndef __LIBSAIO_IO_INLINE_H
36#define __LIBSAIO_IO_INLINE_H
37
38
39/*
40 *############################################################################
41 *
42 * x86 IN/OUT I/O inline functions.
43 *
44 * IN : inb, inw, inl
45 * IN(port)
46 *
47 * OUT: outb, outw, outl
48 * OUT(port, data)
49 *
50 *############################################################################
51 */
52
53#define __IN(s, u) \
54static inline unsigned u \
55in##s(unsigned short port) \
56{ \
57 unsigned u data; \
58 asm volatile ( \
59 "in" #s " %1,%0" \
60: "=a" (data) \
61: "d" (port)); \
62 return (data); \
63}
64
65#define __OUT(s, u) \
66static inline void \
67out##s(unsigned short port, unsigned u data) \
68{ \
69 asm volatile ( \
70 "out" #s " %1,%0" \
71: \
72: "d" (port), "a" (data)); \
73}
74
75__IN(b, char) /* inb() */
76__IN(w, short) /* inw() */
77__IN(l, long) /* inl() */
78
79__OUT(b, char) /* outb() */
80__OUT(w, short) /* outw() */
81__OUT(l, long) /* outl() */
82
83
84static inline void cmos_write_byte (int loc, int val)
85{
86outb (0x70, loc);
87outb (0x71, val);
88}
89
90static inline unsigned cmos_read_byte (int loc)
91{
92outb (0x70, loc);
93return inb (0x71);
94}
95
96#define CMOS_WRITE_BYTE(x, y)cmos_write_byte(x, y)
97#define CMOS_READ_BYTE(x)cmos_read_byte(x)
98
99static inline void cli() {
100asm("cli");
101}
102static inline void sti() {
103asm("sti");
104}
105
106#endif /* !__LIBSAIO_IO_INLINE_H */
107

Archive Download this file

Revision: 1119