vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / graphics / et6x00 / bits.c
blobcb979ee396010e7e5a798b2bc4d8b1c88f32fd19
1 /*****************************************************************************\
2 * Tseng Labs ET6000, ET6100 and ET6300 graphics driver for BeOS 5.
3 * Copyright (c) 2003-2004, Evgeniy Vladimirovich Bobkov.
4 \*****************************************************************************/
6 #include "bits.h"
9 /*****************************************************************************/
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.
15 __inline void set8(volatile char *addr, char mask, char val)
17 if (mask == 0)
18 *addr = val;
19 else
20 *addr = (*addr & mask) | (val & ~mask);
22 /*****************************************************************************/
23 __inline void set16(volatile short *addr, short mask, short val)
25 if (mask == 0)
26 *addr = val;
27 else
28 *addr = (*addr & mask) | (val & ~mask);
30 /*****************************************************************************/
31 __inline void set32(volatile int *addr, int mask, int val)
33 if (mask == 0)
34 *addr = val;
35 else
36 *addr = (*addr & mask) | (val & ~mask);
38 /*****************************************************************************/
39 __inline void ioSet8(short port, char mask, char val)
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"
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"
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"
72 /*****************************************************************************/
73 __inline char ioGet8(short port)
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"
84 return current;
86 /*****************************************************************************/