generalized pixel format handling in 3d pipeline
[bootcensus] / src / asmops.h
1 /*
2 pcboot - bootable PC demo/game kernel
3 Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY, without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #ifndef ASMOPS_H_
19 #define ASMOPS_H_
20
21 #include <inttypes.h>
22
23 #define enable_intr() asm volatile("sti")
24 #define disable_intr() asm volatile("cli")
25 #define halt_cpu() asm volatile("hlt")
26
27 #define CALLER_EIP(eip) \
28         asm volatile( \
29                 "mov (%%esp), %0\n\t" \
30                 : "=a" ((uint32_t)eip))
31
32 static inline uint8_t inb(uint16_t port)
33 {
34         uint8_t res;
35         asm volatile (
36                 "inb %1, %0\n\t"
37                 : "=a" (res)
38                 : "dN" (port));
39         return res;
40 }
41
42 static inline uint16_t inw(uint16_t port)
43 {
44         uint16_t res;
45         asm volatile (
46                 "inw %1, %0\n\t"
47                 : "=a" (res)
48                 : "dN" (port));
49         return res;
50 }
51
52 static inline uint32_t inl(uint16_t port)
53 {
54         uint32_t res;
55         asm volatile (
56                 "inl %1, %0\n\t"
57                 : "=a" (res)
58                 : "dN" (port));
59         return res;
60 }
61
62 #define outb(src, port) \
63         asm volatile( \
64                 "outb %0, %1\n\t" \
65                 :: "a" ((uint8_t)(src)), "dN" ((uint16_t)(port)))
66
67 #define outw(src, port) \
68         asm volatile( \
69                 "outw %0, %1\n\t" \
70                 :: "a" ((uint16_t)(src)), "dN" ((uint16_t)(port)))
71
72 #define outl(src, port) \
73         asm volatile( \
74                 "outl %0, %1\n\t" \
75                 :: "a" ((uint32_t)(src)), "dN" ((uint16_t)(port)))
76
77 /* delay for about 1us */
78 #define iodelay() outb(0, 0x80)
79
80
81 #endif  /* ASMOPS_H_ */