blob: acd5d0c31a49f71ce6b56bcd11aa7a802ac81151 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Basic x86 asm functions and function defs.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
5// This file may be distributed under the terms of the GNU GPLv3 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'Connor38fcbfe2008-02-25 22:30:47 -050039static inline void nop(void)
40{
41 asm volatile("nop");
42}
43
Kevin O'Connor95b2f782008-03-05 19:52:06 -050044static inline void hlt(void)
45{
46 asm volatile("hlt");
47}
48
Kevin O'Connorda4a6482008-06-08 13:48:06 -040049static inline void wbinvd(void)
50{
51 asm volatile("wbinvd");
52}
53
Kevin O'Connor84ad59a2008-07-04 05:47:26 -040054static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
55{
56 asm("cpuid"
57 : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
58 : "0" (index));
59}
60
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -050061static inline u64 rdtscll(void)
62{
63 u64 val;
64 asm volatile("rdtsc" : "=A" (val));
65 return val;
66}
67
Kevin O'Connora83ff552009-01-01 21:00:59 -050068// util.c
69inline u32 stack_hop(u32 eax, u32 edx, u32 ecx, void *func);
70u8 checksum(u8 *far_data, u32 len);
Kevin O'Connor5e4235f2008-04-12 09:00:04 -040071void *memset(void *s, int c, size_t n);
Kevin O'Connor567e4e32008-04-05 11:37:51 -040072void *memcpy(void *d1, const void *s1, size_t len);
Kevin O'Connor18b927e2008-08-29 21:14:36 -040073void *memcpy_far(void *far_d1, const void *far_s1, size_t len);
Kevin O'Connorc7812932008-06-08 23:08:12 -040074void *memmove(void *d, const void *s, size_t len);
Kevin O'Connor9521e262008-07-04 13:04:29 -040075struct bregs;
76inline void call16(struct bregs *callregs);
Kevin O'Connor6e5b4a42008-12-06 13:03:52 -050077inline void call16big(struct bregs *callregs);
Kevin O'Connor9521e262008-07-04 13:04:29 -040078inline void __call16_int(struct bregs *callregs, u16 offset);
Kevin O'Connor3a47a312008-03-01 14:46:37 -050079#define call16_int(nr, callregs) do { \
80 extern void irq_trampoline_ ##nr (); \
Kevin O'Connor117fc212008-04-13 18:17:02 -040081 __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050082 } while (0)
Kevin O'Connora83ff552009-01-01 21:00:59 -050083inline void call16_simpint(int nr, u32 *eax, u32 *flags);
Kevin O'Connor38fcbfe2008-02-25 22:30:47 -050084
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050085// output.c
Kevin O'Connor61d6b062008-06-21 12:15:10 -040086void debug_serial_setup();
Kevin O'Connor567e4e32008-04-05 11:37:51 -040087void BX_PANIC(const char *fmt, ...)
88 __attribute__ ((format (printf, 1, 2)))
89 __attribute__ ((noreturn));
Kevin O'Connor567e4e32008-04-05 11:37:51 -040090void printf(const char *fmt, ...)
91 __attribute__ ((format (printf, 1, 2)));
Kevin O'Connorac8df8c2008-05-24 23:46:33 -040092void __dprintf(const char *fmt, ...)
93 __attribute__ ((format (printf, 1, 2)));
94#define dprintf(lvl, fmt, args...) do { \
95 if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \
96 __dprintf((fmt) , ##args ); \
97 } while (0)
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050098void __debug_enter(const char *fname, struct bregs *regs);
Kevin O'Connora68aeaf2008-07-07 21:37:10 -040099void __debug_stub(const char *fname, int lineno, struct bregs *regs);
Kevin O'Connored128492008-03-11 11:14:59 -0400100void __debug_isr(const char *fname);
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400101#define debug_enter(regs, lvl) do { \
102 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400103 __debug_enter(__func__, (regs)); \
Kevin O'Connor15c1f222008-06-12 22:59:43 -0400104 } while (0)
105#define debug_isr(lvl) do { \
106 if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \
107 __debug_isr(__func__); \
108 } while (0)
Kevin O'Connor4ce6a492008-02-29 00:21:27 -0500109#define debug_stub(regs) \
Kevin O'Connora68aeaf2008-07-07 21:37:10 -0400110 __debug_stub(__func__, __LINE__, (regs))
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500111
112// kbd.c
Kevin O'Connorefda97d2008-07-04 13:10:12 -0400113void kbd_setup();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500114void handle_15c2(struct bregs *regs);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500115
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400116// mouse.c
117void mouse_setup();
118
119// system.c
Kevin O'Connore7916362008-12-28 22:03:17 -0500120extern u32 RamSize;
121extern u64 RamSizeOver4G;
Kevin O'Connorf54c1502008-06-14 15:56:16 -0400122void mathcp_setup();
123
Kevin O'Connor913cc2e2008-04-13 17:31:45 -0400124// serial.c
125void serial_setup();
126void lpt_setup();
127
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500128// clock.c
Kevin O'Connore6eb3f52008-04-13 17:37:41 -0400129void timer_setup();
Kevin O'Connorbc2aecd2008-11-28 16:40:06 -0500130void ndelay(u32 count);
131void udelay(u32 count);
132void mdelay(u32 count);
Kevin O'Connor4e6c9702008-12-13 10:45:50 -0500133u64 calc_future_tsc(u32 msecs);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500134void handle_1583(struct bregs *regs);
Kevin O'Connor5be04902008-05-18 17:12:06 -0400135void handle_1586(struct bregs *regs);
Kevin O'Connorbdce35f2008-02-26 21:33:14 -0500136
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500137// apm.c
Kevin O'Connor44d65302008-03-08 11:34:46 -0500138void VISIBLE16 handle_1553(struct bregs *regs);
Kevin O'Connor95b2f782008-03-05 19:52:06 -0500139
Kevin O'Connora0dc2962008-03-16 14:29:32 -0400140// pcibios.c
141void handle_1ab1(struct bregs *regs);
142
Kevin O'Connorda4a6482008-06-08 13:48:06 -0400143// shadow.c
144void make_bios_writable();
145void make_bios_readonly();
146
Kevin O'Connor0525d292008-07-04 06:18:30 -0400147// pciinit.c
148void pci_bios_setup(void);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500149
Kevin O'Connorf7ba6d72008-07-04 05:05:54 -0400150// smm.c
151void smm_init();
152
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400153// smpdetect.c
154int smp_probe(void);
Kevin O'Connoracf13742008-11-29 11:19:19 -0500155void smp_probe_setup(void);
Kevin O'Connor84ad59a2008-07-04 05:47:26 -0400156
157// mptable.c
158void mptable_init(void);
159
Kevin O'Connor0525d292008-07-04 06:18:30 -0400160// smbios.c
161void smbios_init(void);
162
Kevin O'Connorc7812932008-06-08 23:08:12 -0400163// coreboot.c
164void coreboot_fill_map();
165
Kevin O'Connorcbffa8e2008-08-17 11:11:07 -0400166// vgahooks.c
167void handle_155f();
168
Kevin O'Connor714325c2008-11-01 20:32:27 -0400169// optionroms.c
170void vga_setup();
171void optionrom_setup();
172
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500173// resume.c
174void init_dma();
175
Kevin O'Connor0c3068d2008-12-21 17:51:36 -0500176// pnpbios.c
177#define PNP_SIGNATURE 0x506e5024 // $PnP
178u16 get_pnp_offset();
179void pnp_setup();
180
Kevin O'Connor18e38b22008-12-10 20:40:13 -0500181// romlayout.S
182void reset_vector() __attribute__ ((noreturn));
183
Kevin O'Connor786502d2008-02-27 10:41:41 -0500184#endif // util.h