forked from asweeney86/tinyboot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ports.c
52 lines (44 loc) · 874 Bytes
/
ports.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "ports.h"
#include "types.h"
/**
* Write byte to specific port
*/
__inline__ void
outb(uint16_t port, uint8_t value)
{
__asm__ __volatile__("outb %1, %0" : : "dN" (port), "a" (value));
}
/**
* Read byte from port
*/
__inline__ uint8_t
inb(uint16_t port)
{
uint8_t ret;
__asm__ __volatile__("inb %1, %0"
: "=a" (ret)
: "dN" (port));
return ret;
}
/**
* Read word (16 bit value) from port
*/
__inline__ uint16_t
inw(uint16_t port)
{
uint16_t ret;
__asm__ __volatile__("inw %1, %0"
: "=a" (ret)
: "dN" (port));
return ret;
}
__inline__ void
io_wait(void)
{
/* Port 0x80 is being used for 'checkpoints' during POST,
* and Linux thinks at this point its free for us to use as a
* "wait" op
*/
__asm__ __volatile__("outb %%al, $0x80"
: : "a"(0) );
}