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 LGPLv3 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));
69 inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
70 u8 checksum_far(u16 buf_seg, u8 *buf_far, u32 len);
71 u8 checksum(u8 *buf, u32 len);
72 void *memset(void *s, int c, size_t n);
73 void *memcpy(void *d1, const void *s1, size_t len);
74 inline void memcpy_far(u16 d_seg, void *d_far
75 , u16 s_seg, const void *s_far, size_t len);
76 void *memmove(void *d, const void *s, size_t len);
77 char *strtcpy(char *dest, const char *src, size_t len);
79 inline void call16(struct bregs *callregs);
80 inline void call16big(struct bregs *callregs);
81 inline void __call16_int(struct bregs *callregs, u16 offset);
82 #define call16_int(nr, callregs) do { \
83 extern void irq_trampoline_ ##nr (); \
84 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
86 inline void call16_simpint(int nr, u32 *eax, u32 *flags);
87 int get_keystroke(int msec);
90 void debug_serial_setup();
91 void panic(const char *fmt, ...)
92 __attribute__ ((format (printf, 1, 2)))
93 __attribute__ ((noreturn));
94 void printf(const char *fmt, ...)
95 __attribute__ ((format (printf, 1, 2)));
96 void __dprintf(const char *fmt, ...)
97 __attribute__ ((format (printf, 1, 2)));
98 #define dprintf(lvl, fmt, args...) do { \
99 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
100 __dprintf((fmt) , ##args ); \
102 void __debug_enter(struct bregs *regs, const char *fname);
103 void __debug_stub(struct bregs *regs, int lineno, const char *fname);
104 void __debug_isr(const char *fname);
105 #define debug_enter(regs, lvl) do { \
106 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
107 __debug_enter((regs), __func__); \
109 #define debug_isr(lvl) do { \
110 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
111 __debug_isr(__func__); \
113 #define debug_stub(regs) \
114 __debug_stub((regs), __LINE__, __func__)
118 void handle_15c2(struct bregs *regs);
125 extern u64 RamSizeOver4G;
134 void ndelay(u32 count);
135 void udelay(u32 count);
136 void mdelay(u32 count);
137 u64 calc_future_tsc(u32 msecs);
138 void handle_1583(struct bregs *regs);
139 void handle_1586(struct bregs *regs);
142 void VISIBLE16 handle_1553(struct bregs *regs);
145 void handle_1ab1(struct bregs *regs);
148 void make_bios_writable();
149 void make_bios_readonly();
152 void pci_bios_setup(void);
159 void smp_probe_setup(void);
162 void mptable_init(void);
165 void smbios_init(void);
168 void coreboot_fill_map();
174 void call_bcv(u16 seg, u16 ip);
176 void optionrom_setup();
182 #define PNP_SIGNATURE 0x506e5024 // $PnP
183 u16 get_pnp_offset();
187 void mtrr_setup(void);
190 void reset_vector() __attribute__ ((noreturn));
193 extern u8 BiosChecksum;