1 // Basic x86 asm functions and function defs.
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU GPLv3 license.
9 #include "types.h" // u32
11 static inline void irq_disable(void)
13 asm volatile("cli": : :"memory");
16 static inline void irq_enable(void)
18 asm volatile("sti": : :"memory");
21 static inline unsigned long irq_save(void)
24 asm volatile("pushfl ; popl %0" : "=g" (flags));
29 static inline void irq_restore(unsigned long flags)
31 asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
34 static inline void cpu_relax(void)
36 asm volatile("rep ; nop": : :"memory");
39 static inline void nop(void)
44 static inline void hlt(void)
49 static inline void wbinvd(void)
51 asm volatile("wbinvd");
54 static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
57 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
61 static inline u64 rdtscll(void)
64 asm volatile("rdtsc" : "=A" (val));
68 void *memset(void *s, int c, size_t n);
69 void *memcpy(void *d1, const void *s1, size_t len);
70 void *memcpy_far(void *far_d1, const void *far_s1, size_t len);
71 void *memmove(void *d, const void *s, size_t len);
74 inline void call16(struct bregs *callregs);
75 inline void call16big(struct bregs *callregs);
76 inline void __call16_int(struct bregs *callregs, u16 offset);
77 #define call16_int(nr, callregs) do { \
78 extern void irq_trampoline_ ##nr (); \
79 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
83 void debug_serial_setup();
84 void BX_PANIC(const char *fmt, ...)
85 __attribute__ ((format (printf, 1, 2)))
86 __attribute__ ((noreturn));
87 void printf(const char *fmt, ...)
88 __attribute__ ((format (printf, 1, 2)));
89 void __dprintf(const char *fmt, ...)
90 __attribute__ ((format (printf, 1, 2)));
91 #define dprintf(lvl, fmt, args...) do { \
92 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
93 __dprintf((fmt) , ##args ); \
95 void __debug_enter(const char *fname, struct bregs *regs);
96 void __debug_stub(const char *fname, int lineno, struct bregs *regs);
97 void __debug_isr(const char *fname);
98 #define debug_enter(regs, lvl) do { \
99 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
100 __debug_enter(__func__, (regs)); \
102 #define debug_isr(lvl) do { \
103 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
104 __debug_isr(__func__); \
106 #define debug_stub(regs) \
107 __debug_stub(__func__, __LINE__, (regs))
111 void handle_15c2(struct bregs *regs);
118 extern u64 RamSizeOver4G;
127 void ndelay(u32 count);
128 void udelay(u32 count);
129 void mdelay(u32 count);
130 u64 calc_future_tsc(u32 msecs);
131 void handle_1583(struct bregs *regs);
132 void handle_1586(struct bregs *regs);
135 void VISIBLE16 handle_1553(struct bregs *regs);
138 void handle_1ab1(struct bregs *regs);
141 inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
142 u8 checksum(u8 *far_data, u32 len);
145 void make_bios_writable();
146 void make_bios_readonly();
149 void pci_bios_setup(void);
156 void smp_probe_setup(void);
159 void mptable_init(void);
162 void smbios_init(void);
165 void coreboot_fill_map();
172 void optionrom_setup();
178 #define PNP_SIGNATURE 0x506e5024 // $PnP
179 u16 get_pnp_offset();
183 void reset_vector() __attribute__ ((noreturn));