util: add memset_fl()
[seabios.git] / src / util.h
index 96f4ff76b78e6c6d012cf98f4b336b296fe06648..fa7b20f342687235e46a4974546b6a9cd52813c7 100644 (file)
@@ -1,6 +1,6 @@
 // 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
@@ -162,15 +162,19 @@ static inline u8 readb(const void *addr) {
             : "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;
@@ -194,6 +198,7 @@ int strcmp(const char *s1, const char *s2);
 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);
@@ -207,9 +212,9 @@ char *strtcpy(char *dest, const char *src, size_t len);
 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);
 struct thread_info *getCurThread(void);
 void yield(void);
 void wait_irq(void);
@@ -323,6 +328,7 @@ void useRTC(void);
 void releaseRTC(void);
 
 // apm.c
+void apm_shutdown(void);
 void handle_1553(struct bregs *regs);
 
 // pcibios.c
@@ -334,6 +340,40 @@ 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);
+
+// smm.c
+void smm_save_and_copy(void);
+void smm_relocate_and_restore(void);
+
+// pci_region.c
+// region allocator. pci region allocates the requested region
+// sequentially with overflow check.
+struct pci_region {
+    // The region is [first, last].
+    u32 first;
+    u32 last;
+
+    // The next allocation starts from here.
+    // i.e. [start, cur_first) is allocated.
+    // Right after initialization cur_first == first.
+    u32 cur_first;
+};
+// initialize the pci_region of [first, last]
+// last must not be 0xffffffff
+void pci_region_init(struct pci_region *r, u32 first, u32 last);
+// allocate the region of size
+u32 pci_region_alloc(struct pci_region *r, u32 size);
+// make the next allocation aligned to align
+u32 pci_region_align(struct pci_region *r, u32 align);
+// revert the allocation to addr.
+void pci_region_revert(struct pci_region *r, u32 addr);
+// make the allocation fail.
+u32 pci_region_disable(struct pci_region *r);
+// returns the current allocation point.
+u32 pci_region_addr(const struct pci_region *r);
+// returns the region size.
+u32 pci_region_size(const struct pci_region *r);
 
 // pciinit.c
 extern const u8 pci_irqs[4];
@@ -348,7 +388,6 @@ extern u32 CountCPUs;
 extern u32 MaxCountCPUs;
 void wrmsr_smp(u32 index, u64 val);
 void smp_probe(void);
-void smp_probe_setup(void);
 
 // coreboot.c
 struct cbfs_file;
@@ -375,6 +414,7 @@ extern u32 RomEnd;
 
 // bootsplash.c
 void enable_vga_console(void);
+void enable_bootsplash(void);
 void disable_bootsplash(void);
 
 // resume.c
@@ -406,6 +446,9 @@ static inline void *malloc_high(u32 size) {
 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);
 }
@@ -413,7 +456,7 @@ static inline void *malloc_tmp(u32 size) {
     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);
@@ -421,9 +464,18 @@ static inline void *memalign_low(u32 align, u32 size) {
 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);
 }