summaryrefslogtreecommitdiff
path: root/kernel/old/include/bindings.h
blob: 365abc9f95aa13f5fea8214088c980f49fcdcb57 (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
 * @file bindings.h
 * @author Freya Murphy <freya@freyacat.org>
 *
 * C-style function definitions binded to their named assembly instruction.
 */

#ifndef _BINDINGS_H
#define _BINDINGS_H
#include <types.h>

static inline uint8_t inb(uint16_t port)
{
	uint8_t ret;
	__asm__ volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
	return ret;
}

static inline void outb(uint16_t port, uint8_t val)
{
	__asm__ volatile("outb %0, %1" : : "a"(val), "Nd"(port));
}

static inline uint16_t inw(uint16_t port)
{
	uint16_t ret;
	__asm__ volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
	return ret;
}

static inline void outw(uint16_t port, uint16_t val)
{
	__asm__ volatile("outw %0, %1" : : "a"(val), "Nd"(port));
}

static inline uint32_t inl(uint16_t port)
{
	uint32_t ret;
	__asm__ volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
	return ret;
}

static inline void outl(uint16_t port, uint32_t val)
{
	__asm__ volatile("outl %0, %1" : : "a"(val), "Nd"(port));
}

static inline void io_wait(void)
{
	outb(0x80, 0);
}

static inline void sti(void)
{
	__asm__ volatile("sti");
}

static inline void cli(void)
{
	__asm__ volatile("cli");
}

static inline void int_wait(void)
{
	__asm__ volatile("sti; hlt");
}

static inline void halt(void)
{
	__asm__ volatile("cli; hlt");
}

#endif /* bindings.h */