blob: 42289045c0b7f1ed845c877aae8fb35e81257bca [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Basic x86 asm functions and function defs.
2//
Kevin O'Connor5b199ac2009-05-06 23:23:01 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05004//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05005// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connor786502d2008-02-27 10:41:41 -05006#ifndef __UTIL_H
7#define __UTIL_H
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05008
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "types.h" // u32
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050010
Kevin O'Connor786502d2008-02-27 10:41:41 -050011static inline void irq_disable(void)
12{
13 asm volatile("cli": : :"memory");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050014}
15
Kevin O'Connor786502d2008-02-27 10:41:41 -050016static inline void irq_enable(void)
17{
18 asm volatile("sti": : :"memory");
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050019}
20
21static 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
29static inline void irq_restore(unsigned long flags)
30{
31 asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
32}
33
Kevin O'Connor06ad44e2008-04-05 19:30:02 -040034static inline void cpu_relax(void)
35{
36 asm volatile("rep ; nop": : :"memory");
37}
38
Kevin O'Connoree2efa72009-09-20 15:33:08 -040039// Atomically enable irqs and sleep until an irq; then re-disable irqs.
40static inline void wait_irq(void)
41{
42 asm volatile("sti ; hlt ; cli ; cld": : :"memory");
43}
44
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050045static inline void nop(void)
46{
47 asm volatile("nop");
48}
49
Kevin O'Connor95b2f782008-03-05 19:52:06 -050050static inline void hlt(void)
51{
52 asm volatile("hlt");
53}
54
Kevin O'Connorda4a6482008-06-08 13:48:06 -040055static inline void wbinvd(void)
56{
57 asm volatile("wbinvd");
58}
59
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040060#define CPUID_MSR (1 << 5)
61#define CPUID_APIC (1 << 9)
62#define CPUID_MTRR (1 << 12)
Kevin O'Connor84ad59a2008-07-04 05:47:26 -040063static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
64{
65 asm("cpuid"
66 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
67 : "0" (index));
68}
69
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040070static inline u64 rdmsr(u32 index)
71{
72 u64 ret;
73 asm ("rdmsr" : "=A"(ret) : "c"(index));
74 return ret;
75}
76
77static inline void wrmsr(u32 index, u64 val)
78{
79 asm volatile ("wrmsr" : : "c"(index), "A"(val));
80}
81
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -050082static inline u64 rdtscll(void)
83{
84 u64 val;
85 asm volatile("rdtsc" : "=A" (val));
86 return val;
87}
88
Kevin O'Connor0bf92702009-08-01 11:45:37 -040089static inline u32 __ffs(u32 word)
90{
91 asm("bsf %1,%0"
92 : "=r" (word)
93 : "rm" (word));
94 return word;
95}
Kevin O'Connor86916ce2009-11-14 13:34:27 -050096static inline u32 __fls(u32 word)
97{
98 asm("bsr %1,%0"
99 : "=r" (word)
100 : "rm" (word));
101 return word;
102}
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400103
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500104static inline u32 getesp(void) {
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500105 u32 esp;
106 asm("movl %%esp, %0" : "=rm"(esp));
107 return esp;
108}
109
Kevin O'Connor91031ed2009-10-12 09:49:27 -0400110static inline void writel(void *addr, u32 val) {
111 *(volatile u32 *)addr = val;
112}
113static inline void writew(void *addr, u16 val) {
114 *(volatile u16 *)addr = val;
115}
116static inline void writeb(void *addr, u8 val) {
117 *(volatile u8 *)addr = val;
118}
119static inline u32 readl(const void *addr) {
120 return *(volatile const u32 *)addr;
121}
122static inline u16 readw(const void *addr) {
123 return *(volatile const u16 *)addr;
124}
125static inline u8 readb(const void *addr) {
126 return *(volatile const u8 *)addr;
127}
128
Kevin O'Connor942d4952009-06-10 22:44:06 -0400129#define call16_simpint(nr, peax, pflags) do { \
Kevin O'Connor0b60a062009-06-15 23:03:05 -0400130 ASSERT16(); \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400131 asm volatile( \
132 "stc\n" \
133 "int %2\n" \
134 "pushfl\n" \
135 "popl %1\n" \
136 "cli\n" \
137 "cld" \
138 : "+a"(*peax), "=r"(*pflags) \
139 : "i"(nr) \
140 : "cc", "memory"); \
141 } while (0)
142
Kevin O'Connorad901592009-12-13 11:25:25 -0500143// GDT bit manipulation
144#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
145 | (((u64)(v) & 0x00ffffff) << 16))
146#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
147 | (((u64)(v) & 0x0000ffff) << 0))
148#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
149#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
150#define GDT_B (0x1ULL << 54) // Big flag
151#define GDT_G (0x1ULL << 55) // Granularity flag
152
153struct descloc_s {
154 u16 length;
155 u32 addr;
156} PACKED;
157
Kevin O'Connora83ff552009-01-01 21:00:59 -0500158// util.c
Kevin O'Connor9521e262008-07-04 13:04:29 -0400159struct bregs;
160inline void call16(struct bregs *callregs);
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500161inline void call16big(struct bregs *callregs);
Kevin O'Connor9521e262008-07-04 13:04:29 -0400162inline void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3a47a312008-03-01 14:46:37 -0500163#define call16_int(nr, callregs) do { \
164 extern void irq_trampoline_ ##nr (); \
Kevin O'Connor117fc212008-04-13 18:17:02 -0400165 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500166 } while (0)
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500167void check_irqs(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500168u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);
169u8 checksum(void *buf, u32 len);
170size_t strlen(const char *s);
171int memcmp(const void *s1, const void *s2, size_t n);
172int strcmp(const char *s1, const char *s2);
173inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
174inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
175void *memset(void *s, int c, size_t n);
176inline void memcpy_far(u16 d_seg, void *d_far
177 , u16 s_seg, const void *s_far, size_t len);
178void *memcpy(void *d1, const void *s1, size_t len);
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500179#if MODESEGMENT == 0
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500180#define memcpy __builtin_memcpy
181#endif
182void iomemcpy(void *d, const void *s, u32 len);
183void *memmove(void *d, const void *s, size_t len);
184char *strtcpy(char *dest, const char *src, size_t len);
Kevin O'Connor10ad7992009-10-24 11:06:08 -0400185void biosusleep(u32 usec);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500186int get_keystroke(int msec);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500187
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500188// stacks.c
189inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
190extern struct thread_info MainThread;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500191void thread_setup(void);
192struct thread_info *getCurThread(void);
193void yield(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500194void run_thread(void (*func)(void*), void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500195void wait_threads(void);
196void start_preempt(void);
197void finish_preempt(void);
198void check_preempt(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500199
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500200// output.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500201void debug_serial_setup(void);
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500202void panic(const char *fmt, ...)
Kevin O'Connordad41d92010-01-01 03:04:19 -0500203 __attribute__ ((format (printf, 1, 2))) __noreturn;
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400204void printf(const char *fmt, ...)
205 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500206int snprintf(char *str, size_t size, const char *fmt, ...)
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400207 __attribute__ ((format (printf, 3, 4)));
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500208void __dprintf(const char *fmt, ...)
209 __attribute__ ((format (printf, 1, 2)));
210void __debug_enter(struct bregs *regs, const char *fname);
211void __debug_isr(const char *fname);
212void __debug_stub(struct bregs *regs, int lineno, const char *fname);
213void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
214void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
215void __warn_noalloc(int lineno, const char *fname);
216void __warn_timeout(int lineno, const char *fname);
217void __set_invalid(struct bregs *regs, int lineno, const char *fname);
218void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
219void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
220void __set_code_unimplemented(struct bregs *regs, u32 linecode
221 , const char *fname);
222void hexdump(const void *d, int len);
223
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400224#define dprintf(lvl, fmt, args...) do { \
225 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
226 __dprintf((fmt) , ##args ); \
227 } while (0)
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400228#define debug_enter(regs, lvl) do { \
229 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connor05600342009-01-02 13:10:58 -0500230 __debug_enter((regs), __func__); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400231 } while (0)
232#define debug_isr(lvl) do { \
233 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
234 __debug_isr(__func__); \
235 } while (0)
Kevin O'Connor05600342009-01-02 13:10:58 -0500236#define debug_stub(regs) \
237 __debug_stub((regs), __LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500238#define warn_invalid(regs) \
239 __warn_invalid((regs), __LINE__, __func__)
240#define warn_unimplemented(regs) \
241 __warn_unimplemented((regs), __LINE__, __func__)
242#define warn_noalloc() \
243 __warn_noalloc(__LINE__, __func__)
244#define warn_timeout() \
245 __warn_timeout(__LINE__, __func__)
246#define set_invalid(regs) \
247 __set_invalid((regs), __LINE__, __func__)
248#define set_code_invalid(regs, code) \
249 __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
250#define set_unimplemented(regs) \
251 __set_unimplemented((regs), __LINE__, __func__)
252#define set_code_unimplemented(regs, code) \
253 __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500254
255// kbd.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500256void kbd_setup(void);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500257void handle_15c2(struct bregs *regs);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400258void process_key(u8 key);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500259
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400260// mouse.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500261void mouse_setup(void);
Kevin O'Connor57877482009-12-09 21:00:41 -0500262void process_mouse(u8 data);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400263
264// system.c
Kevin O'Connore7916362008-12-28 22:03:17 -0500265extern u32 RamSize;
266extern u64 RamSizeOver4G;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500267void mathcp_setup(void);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400268
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400269// serial.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500270void serial_setup(void);
271void lpt_setup(void);
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400272
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500273// clock.c
Kevin O'Connor991eaff2010-02-13 21:51:47 -0500274#define PIT_TICK_RATE 1193180 // Underlying HZ of PIT
275#define PIT_TICK_INTERVAL 65536 // Default interval for 18.2Hz timer
Kevin O'Connor89eb6242009-10-22 22:30:37 -0400276static inline int check_time(u64 end) {
277 return (s64)(rdtscll() - end) > 0;
278}
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500279void timer_setup(void);
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -0500280void ndelay(u32 count);
281void udelay(u32 count);
282void mdelay(u32 count);
Kevin O'Connor10ad7992009-10-24 11:06:08 -0400283void nsleep(u32 count);
284void usleep(u32 count);
285void msleep(u32 count);
Kevin O'Connor4e6c9702008-12-13 10:45:50 -0500286u64 calc_future_tsc(u32 msecs);
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400287u64 calc_future_tsc_usec(u32 usecs);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500288void handle_1583(struct bregs *regs);
Kevin O'Connor5be04902008-05-18 17:12:06 -0400289void handle_1586(struct bregs *regs);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500290void useRTC(void);
291void releaseRTC(void);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500292
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500293// apm.c
Kevin O'Connorc0031482010-01-01 13:03:17 -0500294void handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500295
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400296// pcibios.c
297void handle_1ab1(struct bregs *regs);
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500298void bios32_setup(void);
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400299
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400300// shadow.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500301void make_bios_writable(void);
302void make_bios_readonly(void);
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400303
Kevin O'Connor0525d292008-07-04 06:18:30 -0400304// pciinit.c
Kevin O'Connor40f5b5a2009-09-13 10:46:57 -0400305void pci_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500306
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400307// smm.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500308void smm_init(void);
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400309
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400310// smp.c
Kevin O'Connor603bfc32009-06-22 20:04:56 -0400311extern u32 CountCPUs;
Kevin O'Connor84705852009-10-08 22:13:15 -0400312extern u32 MaxCountCPUs;
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400313void wrmsr_smp(u32 index, u64 val);
314void smp_probe(void);
Kevin O'Connoracf13742008-11-29 11:19:19 -0500315void smp_probe_setup(void);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400316
Kevin O'Connorc7812932008-06-08 23:08:12 -0400317// coreboot.c
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400318struct cbfs_file;
Kevin O'Connor1f836252009-08-16 20:17:35 -0400319struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
Kevin O'Connor00882592009-08-18 22:21:10 -0400320u32 cbfs_datasize(struct cbfs_file *file);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400321const char *cbfs_filename(struct cbfs_file *file);
Kevin O'Connor00882592009-08-18 22:21:10 -0400322int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400323int cbfs_copy_optionrom(void *dst, u32 maxlen, u32 vendev);
324void cbfs_run_payload(struct cbfs_file *file);
325
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500326void coreboot_copy_biostable(void);
327void coreboot_setup(void);
Kevin O'Connorc7812932008-06-08 23:08:12 -0400328
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400329// vgahooks.c
Kevin O'Connor22e1b912009-07-19 18:52:46 -0400330extern int VGAbdf;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500331void handle_155f(struct bregs *regs);
Kevin O'Connor22e1b912009-07-19 18:52:46 -0400332void vgahook_setup(const char *vendor, const char *part);
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400333
Kevin O'Connor714325c2008-11-01 20:32:27 -0400334// optionroms.c
Kevin O'Connor0a924122009-02-08 19:43:47 -0500335void call_bcv(u16 seg, u16 ip);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500336void optionrom_setup(void);
337void vga_setup(void);
338void s3_resume_vga_init(void);
Kevin O'Connore7739302009-07-26 19:16:09 -0400339extern u32 RomEnd;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400340
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500341// resume.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500342void init_dma(void);
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500343
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500344// pnpbios.c
345#define PNP_SIGNATURE 0x506e5024 // $PnP
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500346u16 get_pnp_offset(void);
347void pnp_setup(void);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500348
Kevin O'Connore54ee382009-07-26 19:33:13 -0400349// pmm.c
Kevin O'Connor415d4292009-08-30 19:19:31 -0400350extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500351void malloc_setup(void);
352void malloc_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400353void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
354int pmm_free(void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500355void pmm_setup(void);
356void pmm_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400357#define PMM_DEFAULT_HANDLE 0xFFFFFFFF
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400358// Minimum alignment of malloc'd memory
359#define MALLOC_MIN_ALIGN 16
Kevin O'Connor415d4292009-08-30 19:19:31 -0400360// Helper functions for memory allocation.
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400361static inline void *malloc_low(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400362 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400363}
Kevin O'Connor415d4292009-08-30 19:19:31 -0400364static inline void *malloc_high(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400365 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400366}
367static inline void *malloc_fseg(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400368 return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400369}
Kevin O'Connor114592f2009-09-28 21:32:08 -0400370static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400371 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400372}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400373static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400374 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400375}
376static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400377 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400378}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400379static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400380 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
381}
382static inline void free(void *data) {
383 pmm_free(data);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400384}
Kevin O'Connore54ee382009-07-26 19:33:13 -0400385
Kevin O'Connor7061eb62009-01-04 21:48:22 -0500386// mtrr.c
387void mtrr_setup(void);
388
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500389// romlayout.S
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500390void reset_vector(void) __noreturn;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500391
Kevin O'Connor30853762009-01-17 18:49:20 -0500392// misc.c
393extern u8 BiosChecksum;
394
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400395// version (auto generated file out/version.c)
396extern const char VERSION[];
397
Gerd Hoffmann02e60532009-12-18 12:16:03 +0100398// XXX - optimize
399#define ntohl(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | \
400 (((x)&0xff0000) >> 8) | (((x)&0xff000000) >> 24))
401#define htonl(x) ntohl(x)
402#define ntohs(x) ((((x)&0xff)<<8) | (((x)&0xff00)>>8))
403#define htons(x) ntohs(x)
404
Kevin O'Connor786502d2008-02-27 10:41:41 -0500405#endif // util.h