// Basic x86 asm functions and function defs.
//
-// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2008-2010 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU LGPLv3 license.
#ifndef __UTIL_H
asm volatile("sti": : :"memory");
}
-static inline unsigned long irq_save(void)
+static inline u32 save_flags(void)
{
- unsigned long flags;
- asm volatile("pushfl ; popl %0" : "=g" (flags): :"memory");
- irq_disable();
+ u32 flags;
+ asm volatile("pushfl ; popl %0" : "=rm" (flags));
return flags;
}
-static inline void irq_restore(unsigned long flags)
+static inline void restore_flags(u32 flags)
{
asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc");
}
#define CPUID_MSR (1 << 5)
#define CPUID_APIC (1 << 9)
#define CPUID_MTRR (1 << 12)
-static inline void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
+static inline void __cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx)
{
asm("cpuid"
: "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
: "0" (index));
}
+static inline u32 getcr0(void) {
+ u32 cr0;
+ asm("movl %%cr0, %0" : "=r"(cr0));
+ return cr0;
+}
+static inline void setcr0(u32 cr0) {
+ asm("movl %0, %%cr0" : : "r"(cr0));
+}
+
static inline u64 rdmsr(u32 index)
{
u64 ret;
return x;
}
+static inline u32 le32_to_cpu(u32 x)
+{
+ return x;
+}
+
static inline u32 getesp(void) {
u32 esp;
asm("movl %%esp, %0" : "=rm"(esp));
: "ebx", "edx", "esi", "edi", "cc", "memory"); \
} while (0)
-// GDT bit manipulation
-#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
- | (((u64)(v) & 0x00ffffff) << 16))
-#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
- | (((u64)(v) & 0x0000ffff) << 0))
+// GDT bits
#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set
#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set
#define GDT_B (0x1ULL << 54) // Big flag
#define GDT_G (0x1ULL << 55) // Granularity flag
+// GDT bits for segment base
+#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \
+ | (((u64)(v) & 0x00ffffff) << 16))
+// GDT bits for segment limit (0-1Meg)
+#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \
+ | (((u64)(v) & 0x0000ffff) << 0))
+// GDT bits for segment limit (0-4Gig in 4K chunks)
+#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12))
struct descloc_s {
u16 length;
} PACKED;
// util.c
+void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx);
struct bregs;
inline void call16(struct bregs *callregs);
inline void call16big(struct bregs *callregs);
inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len);
inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len);
void *memset(void *s, int c, size_t n);
+void memset_fl(void *ptr, u8 val, size_t size);
inline void memcpy_far(u16 d_seg, void *d_far
, u16 s_seg, const void *s_far, size_t len);
void memcpy_fl(void *d_fl, const void *s_fl, size_t len);
void iomemcpy(void *d, const void *s, u32 len);
void *memmove(void *d, const void *s, size_t len);
char *strtcpy(char *dest, const char *src, size_t len);
+char *strchr(const char *s, int c);
+void nullTrailingSpace(char *buf);
int get_keystroke(int msec);
// stacks.c
+u32 call32(void *func, u32 eax, u32 errret);
inline u32 stack_hop(u32 eax, u32 edx, void *func);
extern struct thread_info MainThread;
-void thread_setup(void);
+extern int CanPreempt;
struct thread_info *getCurThread(void);
void yield(void);
void wait_irq(void);
__attribute__ ((format (printf, 1, 2)));
int snprintf(char *str, size_t size, const char *fmt, ...)
__attribute__ ((format (printf, 3, 4)));
+char * znprintf(size_t size, const char *fmt, ...)
+ __attribute__ ((format (printf, 2, 3)));
void __dprintf(const char *fmt, ...)
__attribute__ ((format (printf, 1, 2)));
void __debug_enter(struct bregs *regs, const char *fname);
void releaseRTC(void);
// apm.c
+void apm_shutdown(void);
void handle_1553(struct bregs *regs);
// pcibios.c
// shadow.c
void make_bios_writable(void);
void make_bios_readonly(void);
-void make_bios_writable_intel(u16 bdf, u32 pam0);
-void make_bios_readonly_intel(u16 bdf, u32 pam0);
+void qemu_prep_reset(void);
// pciinit.c
extern const u8 pci_irqs[4];
-void pci_bios_allocate_regions(u16 bdf, void *arg);
void pci_setup(void);
// smm.c
extern u32 MaxCountCPUs;
void wrmsr_smp(u32 index, u64 val);
void smp_probe(void);
-void smp_probe_setup(void);
// coreboot.c
+extern const char *CBvendor, *CBpart;
struct cbfs_file;
struct cbfs_file *cbfs_finddatafile(const char *fname);
struct cbfs_file *cbfs_findprefix(const char *prefix, struct cbfs_file *last);
int cbfs_copyfile(struct cbfs_file *file, void *dst, u32 maxlen);
void cbfs_run_payload(struct cbfs_file *file);
void coreboot_copy_biostable(void);
+void cbfs_payload_setup(void);
void coreboot_setup(void);
+// biostable.c
+void copy_pir(void *pos);
+void copy_mptable(void *pos);
+void copy_acpi_rsdp(void *pos);
+void copy_smbios(void *pos);
+
// vgahooks.c
-extern int VGAbdf;
void handle_155f(struct bregs *regs);
-void vgahook_setup(const char *vendor, const char *part);
+struct pci_device;
+void vgahook_setup(struct pci_device *pci);
// optionroms.c
void call_bcv(u16 seg, u16 ip);
void vga_setup(void);
void s3_resume_vga_init(void);
extern u32 RomEnd;
+extern int ScreenAndDebug;
// bootsplash.c
void enable_vga_console(void);
+void enable_bootsplash(void);
void disable_bootsplash(void);
// resume.c
+extern int HaveRunPost;
void init_dma(void);
// pnpbios.c
// pmm.c
extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh;
void malloc_setup(void);
+void malloc_fixupreloc(void);
void malloc_finalize(void);
void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align);
int pmm_free(void *data);
static inline void *malloc_fseg(u32 size) {
return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
}
+static inline void *malloc_tmplow(u32 size) {
+ return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
+}
static inline void *malloc_tmphigh(u32 size) {
return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
}
void *ret = malloc_tmphigh(size);
if (ret)
return ret;
- return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN);
+ return malloc_tmplow(size);
}
static inline void *memalign_low(u32 align, u32 size) {
return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align);
static inline void *memalign_high(u32 align, u32 size) {
return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align);
}
+static inline void *memalign_tmplow(u32 align, u32 size) {
+ return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align);
+}
static inline void *memalign_tmphigh(u32 align, u32 size) {
return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align);
}
+static inline void *memalign_tmp(u32 align, u32 size) {
+ void *ret = memalign_tmphigh(align, size);
+ if (ret)
+ return ret;
+ return memalign_tmplow(align, size);
+}
static inline void free(void *data) {
pmm_free(data);
}