Initial checkin of toy OS project.
[os.git] / kernel / hal / io.c
1 #include "kernel.h"
2
3 // Write a byte to an I/O port.
4 void 
5 out(WORD port, BYTE value )
6 {
7     __asm__ __volatile__ (
8         "outb %b0, %w1"
9         :
10         : "a" (value), "Nd" (port)
11     );
12 }
13
14 // Read a byte from an I/O port.
15 BYTE 
16 in(WORD port)
17 {
18     BYTE value;
19
20     __asm__ __volatile__ (
21         "inb %w1, %b0"
22         : "=a" (value)
23         : "Nd" (port)
24     );
25
26     return value;
27 }
28
29 // Short delay.  May be needed when talking to some
30 // (slow) I/O devices.
31 void 
32 iodelay(void)
33 {
34     BYTE value = 0;
35     __asm__ __volatile__ (
36         "outb %0, $0x80"
37         :
38         : "a" (value)
39     );
40 }