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 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, void *buf_far, u32 len);
71 u8 checksum(void *buf, u32 len);
72 int memcmp(const void *s1, const void *s2, size_t n);
73 size_t strlen(const char *s);
74 int strcmp(const char *s1, const char *s2);
75 inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
76 inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
77 void *memset(void *s, int c, size_t n);
78 void memcpy4(void *d1, const void *s1, size_t len);
79 #define memcpy(d1, s1, len) __builtin_memcpy((d1), (s1), (len))
80 inline void memcpy_far(u16 d_seg, void *d_far
81 , u16 s_seg, const void *s_far, size_t len);
82 void *memmove(void *d, const void *s, size_t len);
83 char *strtcpy(char *dest, const char *src, size_t len);
85 inline void call16(struct bregs *callregs);
86 inline void call16big(struct bregs *callregs);
87 inline void __call16_int(struct bregs *callregs, u16 offset);
88 #define call16_int(nr, callregs) do { \
89 extern void irq_trampoline_ ##nr (); \
90 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
92 inline void call16_simpint(int nr, u32 *eax, u32 *flags);
93 void usleep(u32 usec);
94 int get_keystroke(int msec);
97 void debug_serial_setup();
98 void panic(const char *fmt, ...)
99 __attribute__ ((format (printf, 1, 2)))
100 __attribute__ ((noreturn));
101 void printf(const char *fmt, ...)
102 __attribute__ ((format (printf, 1, 2)));
103 void __dprintf(const char *fmt, ...)
104 __attribute__ ((format (printf, 1, 2)));
105 #define dprintf(lvl, fmt, args...) do { \
106 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
107 __dprintf((fmt) , ##args ); \
109 void __debug_enter(struct bregs *regs, const char *fname);
110 void __debug_stub(struct bregs *regs, int lineno, const char *fname);
111 void __debug_isr(const char *fname);
112 #define debug_enter(regs, lvl) do { \
113 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
114 __debug_enter((regs), __func__); \
116 #define debug_isr(lvl) do { \
117 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
118 __debug_isr(__func__); \
120 #define debug_stub(regs) \
121 __debug_stub((regs), __LINE__, __func__)
122 void hexdump(void *d, int len);
126 void handle_15c2(struct bregs *regs);
133 extern u64 RamSizeOver4G;
142 void ndelay(u32 count);
143 void udelay(u32 count);
144 void mdelay(u32 count);
145 u64 calc_future_tsc(u32 msecs);
146 void handle_1583(struct bregs *regs);
147 void handle_1586(struct bregs *regs);
150 void VISIBLE16 handle_1553(struct bregs *regs);
153 void handle_1ab1(struct bregs *regs);
156 void make_bios_writable();
157 void make_bios_readonly();
160 void pci_bios_setup(void);
167 void smp_probe_setup(void);
170 void smbios_init(void);
173 const char *cbfs_findNprefix(const char *prefix, int n);
174 int cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev);
175 void cbfs_run_payload(const char *filename);
177 struct cbfs_file *cbfs_copy_gen_optionrom(void *dst, u32 maxlen
178 , struct cbfs_file *file);
179 void coreboot_setup();
185 void call_bcv(u16 seg, u16 ip);
187 void optionrom_setup();
193 #define PNP_SIGNATURE 0x506e5024 // $PnP
194 u16 get_pnp_offset();
198 void mtrr_setup(void);
201 void reset_vector() __attribute__ ((noreturn));
204 extern u8 BiosChecksum;