blob: eb35d02c9b1d41bd4d4dc32cdbf63a0c2fa5673c [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Basic x86 asm functions and function defs.
2//
Kevin O'Connor244caf82010-09-15 21:48:16 -04003// Copyright (C) 2008-2010 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
Kevin O'Connor9eb21002012-01-29 13:30:56 -050021static inline u32 save_flags(void)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050022{
Kevin O'Connor9eb21002012-01-29 13:30:56 -050023 u32 flags;
24 asm volatile("pushfl ; popl %0" : "=rm" (flags));
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050025 return flags;
26}
27
Kevin O'Connor9eb21002012-01-29 13:30:56 -050028static inline void restore_flags(u32 flags)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050029{
30 asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
31}
32
Kevin O'Connor06ad44e2008-04-05 19:30:02 -040033static inline void cpu_relax(void)
34{
35 asm volatile("rep ; nop": : :"memory");
36}
37
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050038static inline void nop(void)
39{
40 asm volatile("nop");
41}
42
Kevin O'Connor95b2f782008-03-05 19:52:06 -050043static inline void hlt(void)
44{
Kevin O'Connor9c447c32010-05-23 10:24:22 -040045 asm volatile("hlt": : :"memory");
Kevin O'Connor95b2f782008-03-05 19:52:06 -050046}
47
Kevin O'Connorda4a6482008-06-08 13:48:06 -040048static inline void wbinvd(void)
49{
Kevin O'Connor9c447c32010-05-23 10:24:22 -040050 asm volatile("wbinvd": : :"memory");
Kevin O'Connorda4a6482008-06-08 13:48:06 -040051}
52
Kevin O'Connor745de852012-01-29 14:15:14 -050053#define CPUID_TSC (1 << 4)
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040054#define CPUID_MSR (1 << 5)
55#define CPUID_APIC (1 << 9)
56#define CPUID_MTRR (1 << 12)
Kevin O'Connor9eb21002012-01-29 13:30:56 -050057static inline void __cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
Kevin O'Connor84ad59a2008-07-04 05:47:26 -040058{
59 asm("cpuid"
60 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
61 : "0" (index));
62}
63
Kevin O'Connor87b533b2011-07-10 22:35:07 -040064static inline u32 getcr0(void) {
65 u32 cr0;
66 asm("movl %%cr0, %0" : "=r"(cr0));
67 return cr0;
68}
69static inline void setcr0(u32 cr0) {
70 asm("movl %0, %%cr0" : : "r"(cr0));
71}
72
Kevin O'Connore97ca7b2009-06-21 09:10:28 -040073static inline u64 rdmsr(u32 index)
74{
75 u64 ret;
76 asm ("rdmsr" : "=A"(ret) : "c"(index));
77 return ret;
78}
79
80static inline void wrmsr(u32 index, u64 val)
81{
82 asm volatile ("wrmsr" : : "c"(index), "A"(val));
83}
84
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -050085static inline u64 rdtscll(void)
86{
87 u64 val;
88 asm volatile("rdtsc" : "=A" (val));
89 return val;
90}
91
Kevin O'Connor0bf92702009-08-01 11:45:37 -040092static inline u32 __ffs(u32 word)
93{
94 asm("bsf %1,%0"
95 : "=r" (word)
96 : "rm" (word));
97 return word;
98}
Kevin O'Connor86916ce2009-11-14 13:34:27 -050099static inline u32 __fls(u32 word)
100{
101 asm("bsr %1,%0"
102 : "=r" (word)
103 : "rm" (word));
104 return word;
105}
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400106
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500107static inline u32 getesp(void) {
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500108 u32 esp;
109 asm("movl %%esp, %0" : "=rm"(esp));
110 return esp;
111}
112
Kevin O'Connor91031ed2009-10-12 09:49:27 -0400113static inline void writel(void *addr, u32 val) {
114 *(volatile u32 *)addr = val;
115}
116static inline void writew(void *addr, u16 val) {
117 *(volatile u16 *)addr = val;
118}
119static inline void writeb(void *addr, u8 val) {
120 *(volatile u8 *)addr = val;
121}
122static inline u32 readl(const void *addr) {
123 return *(volatile const u32 *)addr;
124}
125static inline u16 readw(const void *addr) {
126 return *(volatile const u16 *)addr;
127}
128static inline u8 readb(const void *addr) {
129 return *(volatile const u8 *)addr;
130}
131
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400132// GDT bits
Kevin O'Connorad901592009-12-13 11:25:25 -0500133#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
134#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
135#define GDT_B (0x1ULL << 54) // Big flag
136#define GDT_G (0x1ULL << 55) // Granularity flag
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400137// GDT bits for segment base
138#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
139 | (((u64)(v) & 0x00ffffff) << 16))
140// GDT bits for segment limit (0-1Meg)
141#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
142 | (((u64)(v) & 0x0000ffff) << 0))
143// GDT bits for segment limit (0-4Gig in 4K chunks)
144#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12))
Kevin O'Connorad901592009-12-13 11:25:25 -0500145
146struct descloc_s {
147 u16 length;
148 u32 addr;
149} PACKED;
150
Kevin O'Connora83ff552009-01-01 21:00:59 -0500151// util.c
Kevin O'Connor9eb21002012-01-29 13:30:56 -0500152void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500153u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);
154u8 checksum(void *buf, u32 len);
155size_t strlen(const char *s);
156int memcmp(const void *s1, const void *s2, size_t n);
157int strcmp(const char *s1, const char *s2);
158inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
159inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
160void *memset(void *s, int c, size_t n);
Gerd Hoffmann0a806082010-11-29 09:42:11 +0100161void memset_fl(void *ptr, u8 val, size_t size);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500162inline void memcpy_far(u16 d_seg, void *d_far
163 , u16 s_seg, const void *s_far, size_t len);
Kevin O'Connor8f59aa32010-06-06 16:11:45 -0400164void memcpy_fl(void *d_fl, const void *s_fl, size_t len);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500165void *memcpy(void *d1, const void *s1, size_t len);
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500166#if MODESEGMENT == 0
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500167#define memcpy __builtin_memcpy
168#endif
169void iomemcpy(void *d, const void *s, u32 len);
170void *memmove(void *d, const void *s, size_t len);
171char *strtcpy(char *dest, const char *src, size_t len);
Kevin O'Connor2e109a62010-12-24 10:39:32 -0500172char *strchr(const char *s, int c);
Kevin O'Connor9e881a32011-01-08 12:06:54 -0500173void nullTrailingSpace(char *buf);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500174int get_keystroke(int msec);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500175
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500176// stacks.c
Kevin O'Connorbf2e8c22012-05-28 12:59:58 -0400177extern u8 ExtraStack[], *StackPos;
Kevin O'Connorecdc6552012-05-28 14:25:15 -0400178u32 stack_hop(u32 eax, u32 edx, void *func);
179u32 stack_hop_back(u32 eax, u32 edx, void *func);
Kevin O'Connore77c7052012-05-28 22:06:42 -0400180u32 call32(void *func, u32 eax, u32 errret);
181struct bregs;
182inline void farcall16(struct bregs *callregs);
183inline void farcall16big(struct bregs *callregs);
184inline void __call16_int(struct bregs *callregs, u16 offset);
185#define call16_int(nr, callregs) do { \
186 extern void irq_trampoline_ ##nr (); \
187 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
188 } while (0)
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500189extern struct thread_info MainThread;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500190struct thread_info *getCurThread(void);
191void yield(void);
Kevin O'Connor94c749c2012-05-28 11:44:02 -0400192void yield_toirq(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500193void run_thread(void (*func)(void*), void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500194void wait_threads(void);
Kevin O'Connore9086652010-02-27 13:49:47 -0500195struct mutex_s { u32 isLocked; };
196void mutex_lock(struct mutex_s *mutex);
197void mutex_unlock(struct mutex_s *mutex);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500198void start_preempt(void);
199void finish_preempt(void);
Kevin O'Connord7eb27e2010-03-20 18:17:19 -0400200int wait_preempt(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500201void check_preempt(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500202
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500203// output.c
Ian Campbell54f3b252012-06-28 11:08:32 +0100204extern u16 DebugOutputPort;
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500205void debug_serial_preinit(void);
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500206void panic(const char *fmt, ...)
Kevin O'Connordad41d92010-01-01 03:04:19 -0500207 __attribute__ ((format (printf, 1, 2))) __noreturn;
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400208void printf(const char *fmt, ...)
209 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500210int snprintf(char *str, size_t size, const char *fmt, ...)
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400211 __attribute__ ((format (printf, 3, 4)));
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500212char * znprintf(size_t size, const char *fmt, ...)
213 __attribute__ ((format (printf, 2, 3)));
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500214void __dprintf(const char *fmt, ...)
215 __attribute__ ((format (printf, 1, 2)));
216void __debug_enter(struct bregs *regs, const char *fname);
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400217void __debug_isr(const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500218void __debug_stub(struct bregs *regs, int lineno, const char *fname);
219void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
220void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500221void __warn_internalerror(int lineno, const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500222void __warn_noalloc(int lineno, const char *fname);
223void __warn_timeout(int lineno, const char *fname);
224void __set_invalid(struct bregs *regs, int lineno, const char *fname);
225void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
226void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
227void __set_code_unimplemented(struct bregs *regs, u32 linecode
228 , const char *fname);
229void hexdump(const void *d, int len);
230
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400231#define dprintf(lvl, fmt, args...) do { \
232 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
233 __dprintf((fmt) , ##args ); \
234 } while (0)
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400235#define debug_enter(regs, lvl) do { \
236 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connor05600342009-01-02 13:10:58 -0500237 __debug_enter((regs), __func__); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400238 } while (0)
Kevin O'Connor1297e5d2012-06-02 20:30:58 -0400239#define debug_isr(lvl) do { \
240 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
241 __debug_isr(__func__); \
242 } while (0)
Kevin O'Connor05600342009-01-02 13:10:58 -0500243#define debug_stub(regs) \
244 __debug_stub((regs), __LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500245#define warn_invalid(regs) \
246 __warn_invalid((regs), __LINE__, __func__)
247#define warn_unimplemented(regs) \
248 __warn_unimplemented((regs), __LINE__, __func__)
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500249#define warn_internalerror() \
250 __warn_internalerror(__LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500251#define warn_noalloc() \
252 __warn_noalloc(__LINE__, __func__)
253#define warn_timeout() \
254 __warn_timeout(__LINE__, __func__)
255#define set_invalid(regs) \
256 __set_invalid((regs), __LINE__, __func__)
257#define set_code_invalid(regs, code) \
258 __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
259#define set_unimplemented(regs) \
260 __set_unimplemented((regs), __LINE__, __func__)
261#define set_code_unimplemented(regs, code) \
262 __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500263
264// kbd.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500265void kbd_init(void);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500266void handle_15c2(struct bregs *regs);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400267void process_key(u8 key);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500268
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400269// mouse.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500270void mouse_init(void);
Kevin O'Connor57877482009-12-09 21:00:41 -0500271void process_mouse(u8 data);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400272
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400273// serial.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500274void serial_setup(void);
275void lpt_setup(void);
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400276
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500277// clock.c
Kevin O'Connor991eaff2010-02-13 21:51:47 -0500278#define PIT_TICK_RATE 1193180 // Underlying HZ of PIT
279#define PIT_TICK_INTERVAL 65536 // Default interval for 18.2Hz timer
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500280void pmtimer_setup(u16 ioport, u32 khz);
Kevin O'Connor745de852012-01-29 14:15:14 -0500281int check_tsc(u64 end);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500282void timer_setup(void);
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -0500283void ndelay(u32 count);
284void udelay(u32 count);
285void mdelay(u32 count);
Kevin O'Connor10ad7992009-10-24 11:06:08 -0400286void nsleep(u32 count);
287void usleep(u32 count);
288void msleep(u32 count);
Kevin O'Connor4e6c9702008-12-13 10:45:50 -0500289u64 calc_future_tsc(u32 msecs);
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400290u64 calc_future_tsc_usec(u32 usecs);
Kevin O'Connorb5cc2ca2010-05-23 11:38:53 -0400291u32 calc_future_timer_ticks(u32 count);
292u32 calc_future_timer(u32 msecs);
293int check_timer(u32 end);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500294void handle_1583(struct bregs *regs);
Kevin O'Connor5be04902008-05-18 17:12:06 -0400295void handle_1586(struct bregs *regs);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500296void useRTC(void);
297void releaseRTC(void);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500298
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500299// apm.c
Kevin O'Connor244caf82010-09-15 21:48:16 -0400300void apm_shutdown(void);
Kevin O'Connorc0031482010-01-01 13:03:17 -0500301void handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500302
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400303// pcibios.c
304void handle_1ab1(struct bregs *regs);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500305void bios32_init(void);
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400306
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400307// shadow.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500308void make_bios_writable(void);
309void make_bios_readonly(void);
Kevin O'Connor244caf82010-09-15 21:48:16 -0400310void qemu_prep_reset(void);
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400311
Kevin O'Connor0525d292008-07-04 06:18:30 -0400312// pciinit.c
Kevin O'Connor0d6b8d52010-07-10 13:12:37 -0400313extern const u8 pci_irqs[4];
Kevin O'Connor40f5b5a2009-09-13 10:46:57 -0400314void pci_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500315
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400316// smm.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500317void smm_setup(void);
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400318
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400319// smp.c
Kevin O'Connor603bfc32009-06-22 20:04:56 -0400320extern u32 CountCPUs;
Kevin O'Connor84705852009-10-08 22:13:15 -0400321extern u32 MaxCountCPUs;
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400322void wrmsr_smp(u32 index, u64 val);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500323void smp_setup(void);
Eduardo Habkost008c1fc2012-07-25 15:45:30 -0300324int apic_id_is_present(u8 apic_id);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400325
Kevin O'Connorc7812932008-06-08 23:08:12 -0400326// coreboot.c
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400327extern const char *CBvendor, *CBpart;
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400328struct cbfs_file;
Kevin O'Connor1f836252009-08-16 20:17:35 -0400329void cbfs_run_payload(struct cbfs_file *file);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500330void coreboot_biostable_setup(void);
Kevin O'Connor89a1efd2011-01-08 12:24:39 -0500331void cbfs_payload_setup(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500332void coreboot_preinit(void);
333void coreboot_cbfs_init(void);
Kevin O'Connorc7812932008-06-08 23:08:12 -0400334
Ian Campbell1442c312011-06-01 11:00:28 +0100335// biostable.c
Kevin O'Connor4d053eb2012-06-09 13:08:02 -0400336void copy_table(void *pos);
Ian Campbell1442c312011-06-01 11:00:28 +0100337
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400338// vgahooks.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500339void handle_155f(struct bregs *regs);
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400340struct pci_device;
341void vgahook_setup(struct pci_device *pci);
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400342
Kevin O'Connor714325c2008-11-01 20:32:27 -0400343// optionroms.c
Kevin O'Connor0a924122009-02-08 19:43:47 -0500344void call_bcv(u16 seg, u16 ip);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500345void optionrom_setup(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500346void vgarom_setup(void);
347void s3_resume_vga(void);
Kevin O'Connor422263d2011-07-05 20:56:07 -0400348extern int ScreenAndDebug;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400349
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400350// bootsplash.c
351void enable_vga_console(void);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400352void enable_bootsplash(void);
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400353void disable_bootsplash(void);
354
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500355// resume.c
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400356extern int HaveRunPost;
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500357void dma_preinit(void);
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500358
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500359// pnpbios.c
360#define PNP_SIGNATURE 0x506e5024 // $PnP
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500361u16 get_pnp_offset(void);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500362void pnp_init(void);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500363
Kevin O'Connore54ee382009-07-26 19:33:13 -0400364// pmm.c
Kevin O'Connor415d4292009-08-30 19:19:31 -0400365extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
Kevin O'Connor5e019082012-05-20 21:11:43 -0400366u32 rom_get_top(void);
367u32 rom_get_last(void);
368struct rom_header *rom_reserve(u32 size);
369int rom_confirm(u32 size);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500370void malloc_preinit(void);
371void malloc_fixupreloc_init(void);
372void malloc_prepboot(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400373void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
374int pmm_free(void *data);
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500375void pmm_init(void);
376void pmm_prepboot(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400377#define PMM_DEFAULT_HANDLE 0xFFFFFFFF
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400378// Minimum alignment of malloc'd memory
379#define MALLOC_MIN_ALIGN 16
Kevin O'Connor415d4292009-08-30 19:19:31 -0400380// Helper functions for memory allocation.
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400381static inline void *malloc_low(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400382 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400383}
Kevin O'Connor415d4292009-08-30 19:19:31 -0400384static inline void *malloc_high(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400385 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400386}
387static inline void *malloc_fseg(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400388 return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400389}
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400390static inline void *malloc_tmplow(u32 size) {
391 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
392}
Kevin O'Connor114592f2009-09-28 21:32:08 -0400393static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400394 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400395}
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500396static inline void *malloc_tmp(u32 size) {
397 void *ret = malloc_tmphigh(size);
398 if (ret)
399 return ret;
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400400 return malloc_tmplow(size);
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500401}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400402static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400403 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400404}
405static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400406 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400407}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400408static inline void *memalign_tmplow(u32 align, u32 size) {
409 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align);
410}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400411static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400412 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
413}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400414static inline void *memalign_tmp(u32 align, u32 size) {
415 void *ret = memalign_tmphigh(align, size);
416 if (ret)
417 return ret;
418 return memalign_tmplow(align, size);
419}
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400420static inline void free(void *data) {
421 pmm_free(data);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400422}
Kevin O'Connore54ee382009-07-26 19:33:13 -0400423
Kevin O'Connor7061eb62009-01-04 21:48:22 -0500424// mtrr.c
425void mtrr_setup(void);
426
Kevin O'Connor59d6ca52012-05-31 00:20:55 -0400427// romfile.c
428struct romfile_s {
429 struct romfile_s *next;
430 char name[128];
431 u32 size;
432 int (*copy)(struct romfile_s *file, void *dest, u32 maxlen);
433
434 u32 id;
435 u32 rawsize;
436 u32 flags;
437 void *data;
438};
439void romfile_add(struct romfile_s *file);
440struct romfile_s *romfile_findprefix(const char *prefix, struct romfile_s *prev);
441struct romfile_s *romfile_find(const char *name);
442void *romfile_loadfile(const char *name, int *psize);
443u64 romfile_loadint(const char *name, u64 defval);
444
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500445// romlayout.S
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500446void reset_vector(void) __noreturn;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500447
Kevin O'Connor30853762009-01-17 18:49:20 -0500448// misc.c
Kevin O'Connord83c87b2013-01-21 01:14:12 -0500449void mathcp_init(void);
450extern u32 RamSize;
451extern u64 RamSizeOver4G;
Kevin O'Connor30853762009-01-17 18:49:20 -0500452extern u8 BiosChecksum;
453
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400454// version (auto generated file out/version.c)
455extern const char VERSION[];
456
Kevin O'Connor786502d2008-02-27 10:41:41 -0500457#endif // util.h