ia64/xen-unstable

view tools/firmware/hvmloader/util.h @ 19079:f3240cd3cd2b

rombios: Indirect through 32-bit jump table from within the 32-bit bios.

This gets rid of shenanigans with relocating the jump table around the
place.

Also clean up bios_info table while we are updating it.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri Jan 23 14:32:41 2009 +0000 (2009-01-23)
parents 67ffce500feb
children
line source
1 #ifndef __HVMLOADER_UTIL_H__
2 #define __HVMLOADER_UTIL_H__
4 #include <stdarg.h>
5 #include <stdint.h>
6 #include <xen/hvm/hvm_info_table.h>
8 #undef offsetof
9 #define offsetof(t, m) ((unsigned long)&((t *)0)->m)
11 #undef NULL
12 #define NULL ((void*)0)
14 void __assert_failed(char *assertion, char *file, int line)
15 __attribute__((noreturn));
16 #define ASSERT(p) \
17 do { if (!(p)) __assert_failed(#p, __FILE__, __LINE__); } while (0)
18 void __bug(char *file, int line) __attribute__((noreturn));
19 #define BUG() __bug(__FILE__, __LINE__)
20 #define BUG_ON(p) do { if (p) BUG(); } while (0)
21 #define BUILD_BUG_ON(p) ((void)sizeof(char[1 - 2 * !!(p)]))
23 /* MSR access */
24 void wrmsr(uint32_t idx, uint64_t v);
25 uint64_t rdmsr(uint32_t idx);
27 /* I/O output */
28 void outb(uint16_t addr, uint8_t val);
29 void outw(uint16_t addr, uint16_t val);
30 void outl(uint16_t addr, uint32_t val);
32 /* I/O input */
33 uint8_t inb(uint16_t addr);
34 uint16_t inw(uint16_t addr);
35 uint32_t inl(uint16_t addr);
37 /* CMOS access */
38 uint8_t cmos_inb(uint8_t idx);
39 void cmos_outb(uint8_t idx, uint8_t val);
41 /* APIC access */
42 uint32_t ioapic_read(uint32_t reg);
43 void ioapic_write(uint32_t reg, uint32_t val);
44 uint32_t lapic_read(uint32_t reg);
45 void lapic_write(uint32_t reg, uint32_t val);
47 /* PCI access */
48 uint32_t pci_read(uint32_t devfn, uint32_t reg, uint32_t len);
49 #define pci_readb(devfn, reg) ((uint8_t) pci_read(devfn, reg, 1))
50 #define pci_readw(devfn, reg) ((uint16_t)pci_read(devfn, reg, 2))
51 #define pci_readl(devfn, reg) ((uint32_t)pci_read(devfn, reg, 4))
52 void pci_write(uint32_t devfn, uint32_t reg, uint32_t len, uint32_t val);
53 #define pci_writeb(devfn, reg, val) (pci_write(devfn, reg, 1, (uint8_t) val))
54 #define pci_writew(devfn, reg, val) (pci_write(devfn, reg, 2, (uint16_t)val))
55 #define pci_writel(devfn, reg, val) (pci_write(devfn, reg, 4, (uint32_t)val))
57 /* Get CPU speed in MHz. */
58 uint16_t get_cpu_mhz(void);
60 /* Hardware detection. */
61 int uart_exists(uint16_t uart_base);
62 int hpet_exists(unsigned long hpet_base);
64 /* Do cpuid instruction, with operation 'idx' */
65 void cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx,
66 uint32_t *ecx, uint32_t *edx);
68 /* Read the TSC register. */
69 static inline uint64_t rdtsc(void)
70 {
71 uint64_t tsc;
72 asm volatile ( "rdtsc" : "=A" (tsc) );
73 return tsc;
74 }
76 /* Relax the CPU and let the compiler know that time passes. */
77 static inline void cpu_relax(void)
78 {
79 asm volatile ( "rep ; nop" : : : "memory" );
80 }
82 /* Memory barriers. */
83 #define barrier() asm volatile ( "" : : : "memory" )
84 #define rmb() barrier()
85 #define wmb() barrier()
86 #define mb() asm volatile ( "lock; addl $0,0(%%esp)" : : : "memory" )
88 /*
89 * Divide a 64-bit dividend by a 32-bit divisor.
90 * (1) Overwrites the 64-bit dividend _in_place_ with the quotient
91 * (2) Returns the 32-bit remainder
92 */
93 #define do_div(n, base) ({ \
94 unsigned long __upper, __low, __high, __mod, __base; \
95 __base = (base); \
96 asm ( "" : "=a" (__low), "=d" (__high) : "A" (n) ); \
97 __upper = __high; \
98 if ( __high ) \
99 { \
100 __upper = __high % (__base); \
101 __high = __high / (__base); \
102 } \
103 asm ( "divl %2" \
104 : "=a" (__low), "=d" (__mod) \
105 : "rm" (__base), "0" (__low), "1" (__upper) ); \
106 asm ( "" : "=A" (n) : "a" (__low), "d" (__high) ); \
107 __mod; \
108 })
110 /* HVM-builder info. */
111 struct hvm_info_table *get_hvm_info_table(void);
112 #define hvm_info (get_hvm_info_table())
114 /* String and memory functions */
115 int strcmp(const char *cs, const char *ct);
116 int strncmp(const char *s1, const char *s2, uint32_t n);
117 char *strcpy(char *dest, const char *src);
118 char *strncpy(char *dest, const char *src, unsigned n);
119 unsigned strlen(const char *s);
120 int memcmp(const void *s1, const void *s2, unsigned n);
121 void *memcpy(void *dest, const void *src, unsigned n);
122 void *memmove(void *dest, const void *src, unsigned n);
123 void *memset(void *s, int c, unsigned n);
124 char *itoa(char *a, unsigned int i);
126 /* convert a byte to two lowercase hex digits, with no terminating NUL
127 character. digits[] must have at least two elements. */
128 void byte_to_hex(char *digits, uint8_t byte);
130 /* Convert an array of 16 unsigned bytes to a DCE/OSF formatted UUID
131 string. Pre-condition: sizeof(dest) >= 37 */
132 void uuid_to_string(char *dest, uint8_t *uuid);
134 /* Debug output */
135 int printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
136 int vprintf(const char *fmt, va_list ap);
138 /* Allocate memory in a reserved region below 4GB. */
139 void *mem_alloc(uint32_t size, uint32_t align);
140 #define virt_to_phys(v) ((unsigned long)(v))
142 /* Prepare the 32bit BIOS */
143 uint32_t highbios_setup(void);
145 /* Miscellaneous. */
146 void cacheattr_init(void);
147 void create_mp_tables(void);
148 int hvm_write_smbios_tables(void);
149 void smp_initialise(void);
151 #ifndef NDEBUG
152 void perform_tests(void);
153 #else
154 #define perform_tests() ((void)0)
155 #endif
157 #define isdigit(c) ((c) >= '0' && (c) <= '9')
159 extern char _start[], _end[];
161 #endif /* __HVMLOADER_UTIL_H__ */