1 /*****************************************************************************\
2 * Tseng Labs ET6000, ET6100 and ET6300 graphics driver for BeOS 5.
3 * Copyright (c) 2003-2004, Evgeniy Vladimirovich Bobkov.
4 \*****************************************************************************/
5
6 #include "bits.h"
7
8
9 /*****************************************************************************/
10 /*
11 * Set bits in a byte pointed by addr; mask must contain 0s at the bits
12 * positions to be set and must contain 1s at all other bits; val must
13 * contain the values of bits to be set.
14 */
set8(volatile char * addr,char mask,char val)15 __inline void set8(volatile char *addr, char mask, char val)
16 {
17 if (mask == 0)
18 *addr = val;
19 else
20 *addr = (*addr & mask) | (val & ~mask);
21 }
22 /*****************************************************************************/
set16(volatile short * addr,short mask,short val)23 __inline void set16(volatile short *addr, short mask, short val)
24 {
25 if (mask == 0)
26 *addr = val;
27 else
28 *addr = (*addr & mask) | (val & ~mask);
29 }
30 /*****************************************************************************/
set32(volatile int * addr,int mask,int val)31 __inline void set32(volatile int *addr, int mask, int val)
32 {
33 if (mask == 0)
34 *addr = val;
35 else
36 *addr = (*addr & mask) | (val & ~mask);
37 }
38 /*****************************************************************************/
ioSet8(short port,char mask,char val)39 __inline void ioSet8(short port, char mask, char val)
40 {
41 char current;
42 if (mask == 0) {
43 __asm__ __volatile__ (
44 "movb %0, %%al\n\t"
45 "movw %1, %%dx\n\t"
46 "outb %%al, %%dx"
47 : /* no output */
48 : "r"(val), "r"(port)
49 : "%eax", "%edx"
50 );
51 }
52 else {
53 __asm__ __volatile__ (
54 "movw %1, %%dx;"
55 "inb %%dx, %%al;"
56 "movb %%al, %0"
57 : "=r"(current)
58 : "r"(port)
59 : "%eax", "%edx"
60 );
61 current = (current & mask) | (val & ~mask);
62 __asm__ __volatile__ (
63 "movb %0, %%al;"
64 "movw %1, %%dx;"
65 "outb %%al, %%dx"
66 : /* no output */
67 : "r"(current), "r"(port)
68 : "%eax", "%edx"
69 );
70 }
71 }
72 /*****************************************************************************/
ioGet8(short port)73 __inline char ioGet8(short port)
74 {
75 char current;
76 __asm__ __volatile__ (
77 "movw %1, %%dx;"
78 "inb %%dx, %%al;"
79 "movb %%al, %0"
80 : "=r"(current)
81 : "r"(port)
82 : "%eax", "%edx"
83 );
84 return current;
85 }
86 /*****************************************************************************/
87