aa5e45741ca924450db0a0418fbc7e46d743a651
[seabios.git] / src / util.h
1 // Basic x86 asm functions and function defs.
2 //
3 // Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
4 //
5 // This file may be distributed under the terms of the GNU GPLv3 license.
6 #ifndef __UTIL_H
7 #define __UTIL_H
8
9 #include "types.h" // u32
10
11 static inline void irq_disable(void)
12 {
13     asm volatile("cli": : :"memory");
14 }
15
16 static inline void irq_enable(void)
17 {
18     asm volatile("sti": : :"memory");
19 }
20
21 static inline unsigned long irq_save(void)
22 {
23     unsigned long flags;
24     asm volatile("pushfl ; popl %0" : "=g" (flags));
25     irq_disable();
26     return flags;
27 }
28
29 static inline void irq_restore(unsigned long flags)
30 {
31     asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
32 }
33
34 static inline void cpu_relax(void)
35 {
36     asm volatile("rep ; nop": : :"memory");
37 }
38
39 static inline void nop(void)
40 {
41     asm volatile("nop");
42 }
43
44 static inline void hlt(void)
45 {
46     asm volatile("hlt");
47 }
48
49 static inline void wbinvd(void)
50 {
51     asm volatile("wbinvd");
52 }
53
54 static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
55 {
56     asm("cpuid"
57         : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
58         : "0" (index));
59 }
60
61 void *memset(void *s, int c, size_t n);
62 void *memcpy(void *d1, const void *s1, size_t len);
63 void *memmove(void *d, const void *s, size_t len);
64
65 struct bregs;
66 inline void call16(struct bregs *callregs);
67 inline void __call16_int(struct bregs *callregs, u16 offset);
68 #ifdef MODE16
69 #define call16_int(nr, callregs) do {                           \
70         extern void irq_trampoline_ ##nr ();                    \
71         __call16_int((callregs), (u32)&irq_trampoline_ ##nr );  \
72     } while (0)
73 #else
74 #include "../out/rom16.offset.auto.h"
75 #define call16_int(nr, callregs)                                \
76     __call16_int((callregs), OFFSET_irq_trampoline_ ##nr - BUILD_BIOS_ADDR)
77 #endif
78
79 // output.c
80 void debug_serial_setup();
81 void BX_PANIC(const char *fmt, ...)
82     __attribute__ ((format (printf, 1, 2)))
83     __attribute__ ((noreturn));
84 void printf(const char *fmt, ...)
85     __attribute__ ((format (printf, 1, 2)));
86 void __dprintf(const char *fmt, ...)
87     __attribute__ ((format (printf, 1, 2)));
88 #define dprintf(lvl, fmt, args...) do {                         \
89         if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL)  \
90             __dprintf((fmt) , ##args );                         \
91     } while (0)
92 void __debug_enter(const char *fname, struct bregs *regs);
93 void __debug_fail(const char *fname, struct bregs *regs);
94 void __debug_stub(const char *fname, struct bregs *regs);
95 void __debug_isr(const char *fname);
96 #define debug_enter(regs, lvl) do {                     \
97         if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL)       \
98             __debug_enter(__func__, regs);              \
99     } while (0)
100 #define debug_isr(lvl) do {                             \
101         if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL)       \
102             __debug_isr(__func__);                      \
103     } while (0)
104 #define debug_stub(regs) \
105     __debug_stub(__func__, regs)
106
107 // kbd.c
108 void kbd_setup();
109 void handle_15c2(struct bregs *regs);
110
111 // mouse.c
112 void mouse_setup();
113
114 // system.c
115 void mathcp_setup();
116
117 // serial.c
118 void serial_setup();
119 void lpt_setup();
120
121 // clock.c
122 void timer_setup();
123 int usleep(u32 count);
124 void handle_1583(struct bregs *regs);
125 void handle_1586(struct bregs *regs);
126
127 // apm.c
128 void VISIBLE16 handle_1553(struct bregs *regs);
129
130 // pcibios.c
131 void handle_1ab1(struct bregs *regs);
132
133 // util.c
134 u8 checksum(u8 *far_data, u32 len);
135
136 // shadow.c
137 void make_bios_writable();
138 void make_bios_readonly();
139
140 // pciinit.c
141 void pci_bios_setup(void);
142
143 // smm.c
144 void smm_init();
145
146 // smpdetect.c
147 int smp_probe(void);
148
149 // mptable.c
150 void mptable_init(void);
151
152 // smbios.c
153 void smbios_init(void);
154
155 // boot.c
156 void printf_bootdev(u16 bootdev);
157
158 // post_menu.c
159 void interactive_bootmenu();
160
161 // coreboot.c
162 void coreboot_fill_map();
163
164 #endif // util.h