blob: 70d3c4c3271ff468925ae515f54c5dfb3ebbdc44 [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'Connor68caaa72010-02-15 10:46:37 -0500107static inline u16 __htons_constant(u16 val) {
108 return (val<<8) | (val>>8);
109}
110static inline u32 __htonl_constant(u32 val) {
111 return (val<<24) | ((val&0xff00)<<8) | ((val&0xff0000)>>8) | (val>>24);
112}
113static inline u32 __htonl(u32 val) {
114 asm("bswapl %0" : "+r"(val));
115 return val;
116}
117#define htonl(x) (__builtin_constant_p((u32)(x)) ? __htonl_constant(x) : __htonl(x))
118#define ntohl(x) htonl(x)
119#define htons(x) __htons_constant(x)
120#define ntohs(x) htons(x)
121
Isaku Yamahata2f54bb42010-07-20 16:37:16 +0900122static inline u16 cpu_to_le16(u16 x)
123{
124 return x;
125}
126
127static inline u32 cpu_to_le32(u32 x)
128{
129 return x;
130}
131
Isaku Yamahatabaae9402011-10-24 17:11:07 +0900132static inline u32 le32_to_cpu(u32 x)
133{
134 return x;
135}
136
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500137static inline u32 getesp(void) {
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500138 u32 esp;
139 asm("movl %%esp, %0" : "=rm"(esp));
140 return esp;
141}
142
Kevin O'Connor91031ed2009-10-12 09:49:27 -0400143static inline void writel(void *addr, u32 val) {
144 *(volatile u32 *)addr = val;
145}
146static inline void writew(void *addr, u16 val) {
147 *(volatile u16 *)addr = val;
148}
149static inline void writeb(void *addr, u8 val) {
150 *(volatile u8 *)addr = val;
151}
152static inline u32 readl(const void *addr) {
153 return *(volatile const u32 *)addr;
154}
155static inline u16 readw(const void *addr) {
156 return *(volatile const u16 *)addr;
157}
158static inline u8 readb(const void *addr) {
159 return *(volatile const u8 *)addr;
160}
161
Kevin O'Connor942d4952009-06-10 22:44:06 -0400162#define call16_simpint(nr, peax, pflags) do { \
Kevin O'Connor0b60a062009-06-15 23:03:05 -0400163 ASSERT16(); \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400164 asm volatile( \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500165 "pushl %%ebp\n" \
166 "sti\n" \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400167 "stc\n" \
168 "int %2\n" \
169 "pushfl\n" \
170 "popl %1\n" \
171 "cli\n" \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500172 "cld\n" \
173 "popl %%ebp" \
174 : "+a"(*peax), "=c"(*pflags) \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400175 : "i"(nr) \
Kevin O'Connor4ed378a2010-03-13 22:29:55 -0500176 : "ebx", "edx", "esi", "edi", "cc", "memory"); \
Kevin O'Connor942d4952009-06-10 22:44:06 -0400177 } while (0)
178
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400179// GDT bits
Kevin O'Connorad901592009-12-13 11:25:25 -0500180#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
181#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
182#define GDT_B (0x1ULL << 54) // Big flag
183#define GDT_G (0x1ULL << 55) // Granularity flag
Kevin O'Connorae6924d2010-07-25 14:46:21 -0400184// GDT bits for segment base
185#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
186 | (((u64)(v) & 0x00ffffff) << 16))
187// GDT bits for segment limit (0-1Meg)
188#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
189 | (((u64)(v) & 0x0000ffff) << 0))
190// GDT bits for segment limit (0-4Gig in 4K chunks)
191#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12))
Kevin O'Connorad901592009-12-13 11:25:25 -0500192
193struct descloc_s {
194 u16 length;
195 u32 addr;
196} PACKED;
197
Kevin O'Connora83ff552009-01-01 21:00:59 -0500198// util.c
Kevin O'Connor9eb21002012-01-29 13:30:56 -0500199void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
Kevin O'Connor9521e262008-07-04 13:04:29 -0400200struct bregs;
201inline void call16(struct bregs *callregs);
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -0500202inline void call16big(struct bregs *callregs);
Kevin O'Connor9521e262008-07-04 13:04:29 -0400203inline void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3a47a312008-03-01 14:46:37 -0500204#define call16_int(nr, callregs) do { \
205 extern void irq_trampoline_ ##nr (); \
Kevin O'Connor117fc212008-04-13 18:17:02 -0400206 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500207 } while (0)
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500208u8 checksum_far(u16 buf_seg, void *buf_far, u32 len);
209u8 checksum(void *buf, u32 len);
210size_t strlen(const char *s);
211int memcmp(const void *s1, const void *s2, size_t n);
212int strcmp(const char *s1, const char *s2);
213inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
214inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
215void *memset(void *s, int c, size_t n);
Gerd Hoffmann0a806082010-11-29 09:42:11 +0100216void memset_fl(void *ptr, u8 val, size_t size);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500217inline void memcpy_far(u16 d_seg, void *d_far
218 , u16 s_seg, const void *s_far, size_t len);
Kevin O'Connor8f59aa32010-06-06 16:11:45 -0400219void memcpy_fl(void *d_fl, const void *s_fl, size_t len);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500220void *memcpy(void *d1, const void *s1, size_t len);
Kevin O'Connor52a300f2009-12-26 23:32:57 -0500221#if MODESEGMENT == 0
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500222#define memcpy __builtin_memcpy
223#endif
224void iomemcpy(void *d, const void *s, u32 len);
225void *memmove(void *d, const void *s, size_t len);
226char *strtcpy(char *dest, const char *src, size_t len);
Kevin O'Connor2e109a62010-12-24 10:39:32 -0500227char *strchr(const char *s, int c);
Kevin O'Connor9e881a32011-01-08 12:06:54 -0500228void nullTrailingSpace(char *buf);
Kevin O'Connor9f4e1d92009-02-08 15:44:08 -0500229int get_keystroke(int msec);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -0500230
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500231// stacks.c
Kevin O'Connoraf9629b2010-11-25 09:17:31 -0500232u32 call32(void *func, u32 eax, u32 errret);
Kevin O'Connorbca07362010-03-20 20:41:38 -0400233inline u32 stack_hop(u32 eax, u32 edx, void *func);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500234extern struct thread_info MainThread;
Kevin O'Connor533b6282011-07-16 13:13:12 -0400235extern int CanPreempt;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500236struct thread_info *getCurThread(void);
237void yield(void);
Kevin O'Connor9c447c32010-05-23 10:24:22 -0400238void wait_irq(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500239void run_thread(void (*func)(void*), void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500240void wait_threads(void);
Kevin O'Connore9086652010-02-27 13:49:47 -0500241struct mutex_s { u32 isLocked; };
242void mutex_lock(struct mutex_s *mutex);
243void mutex_unlock(struct mutex_s *mutex);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500244void start_preempt(void);
245void finish_preempt(void);
Kevin O'Connord7eb27e2010-03-20 18:17:19 -0400246int wait_preempt(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500247void check_preempt(void);
Kevin O'Connor7cefbfa2009-12-10 21:35:49 -0500248
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500249// output.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500250void debug_serial_setup(void);
Kevin O'Connore07e18e2009-02-08 17:07:29 -0500251void panic(const char *fmt, ...)
Kevin O'Connordad41d92010-01-01 03:04:19 -0500252 __attribute__ ((format (printf, 1, 2))) __noreturn;
Kevin O'Connor567e4e32008-04-05 11:37:51 -0400253void printf(const char *fmt, ...)
254 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connor2be312c2009-11-24 09:37:53 -0500255int snprintf(char *str, size_t size, const char *fmt, ...)
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400256 __attribute__ ((format (printf, 3, 4)));
Kevin O'Connorca2bc1c2010-12-29 21:41:19 -0500257char * znprintf(size_t size, const char *fmt, ...)
258 __attribute__ ((format (printf, 2, 3)));
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500259void __dprintf(const char *fmt, ...)
260 __attribute__ ((format (printf, 1, 2)));
261void __debug_enter(struct bregs *regs, const char *fname);
262void __debug_isr(const char *fname);
263void __debug_stub(struct bregs *regs, int lineno, const char *fname);
264void __warn_invalid(struct bregs *regs, int lineno, const char *fname);
265void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname);
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500266void __warn_internalerror(int lineno, const char *fname);
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500267void __warn_noalloc(int lineno, const char *fname);
268void __warn_timeout(int lineno, const char *fname);
269void __set_invalid(struct bregs *regs, int lineno, const char *fname);
270void __set_unimplemented(struct bregs *regs, int lineno, const char *fname);
271void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname);
272void __set_code_unimplemented(struct bregs *regs, u32 linecode
273 , const char *fname);
274void hexdump(const void *d, int len);
275
Kevin O'Connorac8df8c2008-05-24 23:46:33 -0400276#define dprintf(lvl, fmt, args...) do { \
277 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
278 __dprintf((fmt) , ##args ); \
279 } while (0)
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400280#define debug_enter(regs, lvl) do { \
281 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connor05600342009-01-02 13:10:58 -0500282 __debug_enter((regs), __func__); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400283 } while (0)
284#define debug_isr(lvl) do { \
285 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
286 __debug_isr(__func__); \
287 } while (0)
Kevin O'Connor05600342009-01-02 13:10:58 -0500288#define debug_stub(regs) \
289 __debug_stub((regs), __LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500290#define warn_invalid(regs) \
291 __warn_invalid((regs), __LINE__, __func__)
292#define warn_unimplemented(regs) \
293 __warn_unimplemented((regs), __LINE__, __func__)
Kevin O'Connor7fb8ba82010-02-26 08:45:00 -0500294#define warn_internalerror() \
295 __warn_internalerror(__LINE__, __func__)
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500296#define warn_noalloc() \
297 __warn_noalloc(__LINE__, __func__)
298#define warn_timeout() \
299 __warn_timeout(__LINE__, __func__)
300#define set_invalid(regs) \
301 __set_invalid((regs), __LINE__, __func__)
302#define set_code_invalid(regs, code) \
303 __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__)
304#define set_unimplemented(regs) \
305 __set_unimplemented((regs), __LINE__, __func__)
306#define set_code_unimplemented(regs, code) \
307 __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500308
309// kbd.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500310void kbd_setup(void);
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500311void handle_15c2(struct bregs *regs);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400312void process_key(u8 key);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500313
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400314// mouse.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500315void mouse_setup(void);
Kevin O'Connor57877482009-12-09 21:00:41 -0500316void process_mouse(u8 data);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400317
318// system.c
Kevin O'Connore7916362008-12-28 22:03:17 -0500319extern u32 RamSize;
320extern u64 RamSizeOver4G;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500321void mathcp_setup(void);
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400322
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400323// serial.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500324void serial_setup(void);
325void lpt_setup(void);
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400326
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500327// clock.c
Kevin O'Connor991eaff2010-02-13 21:51:47 -0500328#define PIT_TICK_RATE 1193180 // Underlying HZ of PIT
329#define PIT_TICK_INTERVAL 65536 // Default interval for 18.2Hz timer
Kevin O'Connor745de852012-01-29 14:15:14 -0500330int check_tsc(u64 end);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500331void timer_setup(void);
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -0500332void ndelay(u32 count);
333void udelay(u32 count);
334void mdelay(u32 count);
Kevin O'Connor10ad7992009-10-24 11:06:08 -0400335void nsleep(u32 count);
336void usleep(u32 count);
337void msleep(u32 count);
Kevin O'Connor4e6c9702008-12-13 10:45:50 -0500338u64 calc_future_tsc(u32 msecs);
Kevin O'Connor1c46a542009-10-17 23:53:32 -0400339u64 calc_future_tsc_usec(u32 usecs);
Kevin O'Connorb5cc2ca2010-05-23 11:38:53 -0400340u32 calc_future_timer_ticks(u32 count);
341u32 calc_future_timer(u32 msecs);
342int check_timer(u32 end);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500343void handle_1583(struct bregs *regs);
Kevin O'Connor5be04902008-05-18 17:12:06 -0400344void handle_1586(struct bregs *regs);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500345void useRTC(void);
346void releaseRTC(void);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500347
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500348// apm.c
Kevin O'Connor244caf82010-09-15 21:48:16 -0400349void apm_shutdown(void);
Kevin O'Connorc0031482010-01-01 13:03:17 -0500350void handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500351
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400352// pcibios.c
353void handle_1ab1(struct bregs *regs);
Kevin O'Connor871e0a02009-12-30 12:14:53 -0500354void bios32_setup(void);
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400355
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400356// shadow.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500357void make_bios_writable(void);
358void make_bios_readonly(void);
Kevin O'Connor244caf82010-09-15 21:48:16 -0400359void qemu_prep_reset(void);
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400360
Kevin O'Connor0525d292008-07-04 06:18:30 -0400361// pciinit.c
Kevin O'Connor0d6b8d52010-07-10 13:12:37 -0400362extern const u8 pci_irqs[4];
Kevin O'Connor40f5b5a2009-09-13 10:46:57 -0400363void pci_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500364
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400365// smm.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500366void smm_init(void);
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400367
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400368// smp.c
Kevin O'Connor603bfc32009-06-22 20:04:56 -0400369extern u32 CountCPUs;
Kevin O'Connor84705852009-10-08 22:13:15 -0400370extern u32 MaxCountCPUs;
Kevin O'Connore97ca7b2009-06-21 09:10:28 -0400371void wrmsr_smp(u32 index, u64 val);
372void smp_probe(void);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400373
Kevin O'Connorc7812932008-06-08 23:08:12 -0400374// coreboot.c
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400375extern const char *CBvendor, *CBpart;
Kevin O'Connor1edc89d2009-04-30 21:50:35 -0400376struct cbfs_file;
Kevin O'Connore2304262010-06-13 16:05:17 -0400377struct cbfs_file *cbfs_finddatafile(const char *fname);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400378struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
Kevin O'Connor00882592009-08-18 22:21:10 -0400379u32 cbfs_datasize(struct cbfs_file *file);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400380const char *cbfs_filename(struct cbfs_file *file);
Kevin O'Connor00882592009-08-18 22:21:10 -0400381int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
Kevin O'Connor1f836252009-08-16 20:17:35 -0400382void cbfs_run_payload(struct cbfs_file *file);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500383void coreboot_copy_biostable(void);
Kevin O'Connor89a1efd2011-01-08 12:24:39 -0500384void cbfs_payload_setup(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500385void coreboot_setup(void);
Kevin O'Connorc7812932008-06-08 23:08:12 -0400386
Ian Campbell1442c312011-06-01 11:00:28 +0100387// biostable.c
388void copy_pir(void *pos);
389void copy_mptable(void *pos);
390void copy_acpi_rsdp(void *pos);
Ian Campbell74c78782011-06-01 11:00:29 +0100391void copy_smbios(void *pos);
Ian Campbell1442c312011-06-01 11:00:28 +0100392
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400393// vgahooks.c
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500394void handle_155f(struct bregs *regs);
Kevin O'Connorc1de91b2011-07-02 13:50:21 -0400395struct pci_device;
396void vgahook_setup(struct pci_device *pci);
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400397
Kevin O'Connor714325c2008-11-01 20:32:27 -0400398// optionroms.c
Kevin O'Connor0a924122009-02-08 19:43:47 -0500399void call_bcv(u16 seg, u16 ip);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500400void optionrom_setup(void);
401void vga_setup(void);
402void s3_resume_vga_init(void);
Kevin O'Connore7739302009-07-26 19:16:09 -0400403extern u32 RomEnd;
Kevin O'Connor422263d2011-07-05 20:56:07 -0400404extern int ScreenAndDebug;
Kevin O'Connor714325c2008-11-01 20:32:27 -0400405
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400406// bootsplash.c
407void enable_vga_console(void);
Kevin O'Connor9a01a9c2010-08-25 21:07:48 -0400408void enable_bootsplash(void);
Kevin O'Connorafbed1b2010-06-28 07:34:53 -0400409void disable_bootsplash(void);
410
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500411// resume.c
Kevin O'Connor87b533b2011-07-10 22:35:07 -0400412extern int HaveRunPost;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500413void init_dma(void);
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500414
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500415// pnpbios.c
416#define PNP_SIGNATURE 0x506e5024 // $PnP
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500417u16 get_pnp_offset(void);
418void pnp_setup(void);
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500419
Kevin O'Connore54ee382009-07-26 19:33:13 -0400420// pmm.c
Kevin O'Connor415d4292009-08-30 19:19:31 -0400421extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500422void malloc_setup(void);
Kevin O'Connor533b6282011-07-16 13:13:12 -0400423void malloc_fixupreloc(void);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500424void malloc_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400425void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
426int pmm_free(void *data);
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500427void pmm_setup(void);
428void pmm_finalize(void);
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400429#define PMM_DEFAULT_HANDLE 0xFFFFFFFF
Kevin O'Connor0bf92702009-08-01 11:45:37 -0400430// Minimum alignment of malloc'd memory
431#define MALLOC_MIN_ALIGN 16
Kevin O'Connor415d4292009-08-30 19:19:31 -0400432// Helper functions for memory allocation.
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400433static inline void *malloc_low(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400434 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connorf416fe92009-09-24 20:51:55 -0400435}
Kevin O'Connor415d4292009-08-30 19:19:31 -0400436static inline void *malloc_high(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400437 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400438}
439static inline void *malloc_fseg(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400440 return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400441}
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400442static inline void *malloc_tmplow(u32 size) {
443 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
444}
Kevin O'Connor114592f2009-09-28 21:32:08 -0400445static inline void *malloc_tmphigh(u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400446 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
Kevin O'Connor114592f2009-09-28 21:32:08 -0400447}
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500448static inline void *malloc_tmp(u32 size) {
449 void *ret = malloc_tmphigh(size);
450 if (ret)
451 return ret;
Kevin O'Connora576c9c2010-07-26 22:43:18 -0400452 return malloc_tmplow(size);
Kevin O'Connor575ffc82010-02-21 23:20:10 -0500453}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400454static inline void *memalign_low(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400455 return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400456}
457static inline void *memalign_high(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400458 return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
Kevin O'Connor415d4292009-08-30 19:19:31 -0400459}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400460static inline void *memalign_tmplow(u32 align, u32 size) {
461 return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align);
462}
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400463static inline void *memalign_tmphigh(u32 align, u32 size) {
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400464 return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
465}
Kevin O'Connor12fa24a2010-09-15 00:25:32 -0400466static inline void *memalign_tmp(u32 align, u32 size) {
467 void *ret = memalign_tmphigh(align, size);
468 if (ret)
469 return ret;
470 return memalign_tmplow(align, size);
471}
Kevin O'Connord948e2b2009-10-12 12:54:56 -0400472static inline void free(void *data) {
473 pmm_free(data);
Kevin O'Connor9ed6b622009-10-07 21:41:08 -0400474}
Kevin O'Connore54ee382009-07-26 19:33:13 -0400475
Kevin O'Connor7061eb62009-01-04 21:48:22 -0500476// mtrr.c
477void mtrr_setup(void);
478
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500479// romlayout.S
Kevin O'Connor1ca05b02010-01-03 17:43:37 -0500480void reset_vector(void) __noreturn;
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500481
Kevin O'Connor30853762009-01-17 18:49:20 -0500482// misc.c
483extern u8 BiosChecksum;
484
Kevin O'Connorc95d2ce2009-07-29 20:41:39 -0400485// version (auto generated file out/version.c)
486extern const char VERSION[];
487
Kevin O'Connor786502d2008-02-27 10:41:41 -0500488#endif // util.h