1 // Basic x86 asm functions and function defs.
3 // Copyright (C) 2008,2009 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 #define CPUID_MSR (1 << 5)
55 #define CPUID_APIC (1 << 9)
56 #define CPUID_MTRR (1 << 12)
57 static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
60 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
64 static inline u64 rdmsr(u32 index)
67 asm ("rdmsr" : "=A"(ret) : "c"(index));
71 static inline void wrmsr(u32 index, u64 val)
73 asm volatile ("wrmsr" : : "c"(index), "A"(val));
76 static inline u64 rdtscll(void)
79 asm volatile("rdtsc" : "=A" (val));
83 #define call16_simpint(nr, peax, pflags) do { \
92 : "+a"(*peax), "=r"(*pflags) \
98 inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
99 u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);
100 u8 checksum(void *buf, u32 len);
101 int memcmp(const void *s1, const void *s2, size_t n);
102 size_t strlen(const char *s);
103 int strcmp(const char *s1, const char *s2);
104 inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
105 inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
106 void *memset(void *s, int c, size_t n);
107 void *memcpy(void *d1, const void *s1, size_t len);
109 #define memcpy __builtin_memcpy
111 inline void memcpy_far(u16 d_seg, void *d_far
112 , u16 s_seg, const void *s_far, size_t len);
113 void *memmove(void *d, const void *s, size_t len);
114 char *strtcpy(char *dest, const char *src, size_t len);
116 inline void call16(struct bregs *callregs);
117 inline void call16big(struct bregs *callregs);
118 inline void __call16_int(struct bregs *callregs, u16 offset);
119 #define call16_int(nr, callregs) do { \
120 extern void irq_trampoline_ ##nr (); \
121 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
123 void usleep(u32 usec);
124 int get_keystroke(int msec);
127 void debug_serial_setup();
128 void panic(const char *fmt, ...)
129 __attribute__ ((format (printf, 1, 2)))
130 __attribute__ ((noreturn));
131 void printf(const char *fmt, ...)
132 __attribute__ ((format (printf, 1, 2)));
133 void __dprintf(const char *fmt, ...)
134 __attribute__ ((format (printf, 1, 2)));
135 #define dprintf(lvl, fmt, args...) do { \
136 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
137 __dprintf((fmt) , ##args ); \
139 void __debug_enter(struct bregs *regs, const char *fname);
140 void __debug_stub(struct bregs *regs, int lineno, const char *fname);
141 void __debug_isr(const char *fname);
142 #define debug_enter(regs, lvl) do { \
143 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
144 __debug_enter((regs), __func__); \
146 #define debug_isr(lvl) do { \
147 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
148 __debug_isr(__func__); \
150 #define debug_stub(regs) \
151 __debug_stub((regs), __LINE__, __func__)
152 void hexdump(void *d, int len);
156 void handle_15c2(struct bregs *regs);
163 extern u64 RamSizeOver4G;
172 void ndelay(u32 count);
173 void udelay(u32 count);
174 void mdelay(u32 count);
175 u64 calc_future_tsc(u32 msecs);
176 void handle_1583(struct bregs *regs);
177 void handle_1586(struct bregs *regs);
180 void VISIBLE16 handle_1553(struct bregs *regs);
183 void handle_1ab1(struct bregs *regs);
186 void make_bios_writable();
187 void make_bios_readonly();
190 void pci_bios_setup(void);
196 extern u32 CountCPUs;
197 void wrmsr_smp(u32 index, u64 val);
198 void smp_probe(void);
199 void smp_probe_setup(void);
202 void smbios_init(void);
205 const char *cbfs_findNprefix(const char *prefix, int n);
206 int cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev);
207 void cbfs_run_payload(const char *filename);
209 struct cbfs_file *cbfs_copyfile_prefix(void *dst, u32 maxlen, const char *prefix
210 , struct cbfs_file *last);
211 void coreboot_setup();
216 void vgahook_setup(const char *vendor, const char *part);
219 void call_bcv(u16 seg, u16 ip);
220 void optionrom_setup();
222 void s3_resume_vga_init();
228 #define PNP_SIGNATURE 0x506e5024 // $PnP
229 u16 get_pnp_offset();
233 void mtrr_setup(void);
236 void reset_vector() __attribute__ ((noreturn));
239 extern u8 BiosChecksum;