X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Futil.h;h=f93efc8ba2f29bbea15c9915dbf0b14d7ab6e115;hb=23c14b0ba8bac4d39824ae1d848be3058e9f9073;hp=5f3489fe5aaa0ce31ac8b43d0646fdd121766853;hpb=fb3df30d97e3824335a6c17fd8d49b9706b6b3c7;p=dosdemo diff --git a/src/util.h b/src/util.h index 5f3489f..f93efc8 100644 --- a/src/util.h +++ b/src/util.h @@ -1,6 +1,7 @@ #ifndef UTIL_H_ #define UTIL_H_ +#include #include "inttypes.h" #ifdef __GNUC__ @@ -106,12 +107,6 @@ void debug_break(void); void halt(void); #pragma aux halt = "hlt"; - -unsigned int get_cs(void); -#pragma aux get_cs = \ - "xor eax, eax" \ - "mov ax, cs" \ - value[eax]; #endif #ifdef __GNUC__ @@ -178,17 +173,6 @@ static void INLINE memset16(void *dest, uint16_t val, int count) #define halt() \ asm volatile("hlt") - -static unsigned int INLINE get_cs(void) -{ - unsigned int res; - asm volatile ( - "xor %%eax, %%eax\n\t" - "mov %%cs, %0\n\t" - : "=a"(res) - ); - return res; -} #endif #ifdef _MSC_VER @@ -251,6 +235,23 @@ static unsigned int __inline get_cs(void) } #endif -#define get_cpl() ((int)(get_cs() & 7)) +unsigned int get_cs(void); +#define get_cpl() ((int)(get_cs() & 3)) + +void get_msr(uint32_t msr, uint32_t *low, uint32_t *high); +void set_msr(uint32_t msr, uint32_t low, uint32_t high); + + +/* Non-failing versions of malloc/calloc/realloc. They never return 0, they call + * demo_abort on failure. Use the macros, don't call the *_impl functions. + */ +#define malloc_nf(sz) malloc_nf_impl(sz, __FILE__, __LINE__) +void *malloc_nf_impl(size_t sz, const char *file, int line); +#define calloc_nf(n, sz) calloc_nf_impl(n, sz, __FILE__, __LINE__) +void *calloc_nf_impl(size_t num, size_t sz, const char *file, int line); +#define realloc_nf(p, sz) realloc_nf_impl(p, sz, __FILE__, __LINE__) +void *realloc_nf_impl(void *p, size_t sz, const char *file, int line); + + #endif /* UTIL_H_ */