X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Futil.h;h=f93efc8ba2f29bbea15c9915dbf0b14d7ab6e115;hb=e23b27a06797d931992ab9b8d21055f789371e2a;hp=8a46036494309bfdb97ab586c461c57433dbf230;hpb=b49854e0980a030cc8338a7f4ee779ecde1aae38;p=dosdemo diff --git a/src/util.h b/src/util.h index 8a46036..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__ @@ -168,14 +169,14 @@ static void INLINE memset16(void *dest, uint16_t val, int count) : "%eax", "%ebx", "%ecx", "%edx") #define debug_break() \ - asm volatile ("int $3") + asm volatile("int $3") #define halt() \ asm volatile("hlt") #endif #ifdef _MSC_VER -void __inline memset16(void *dest, uint16_t val, int count) +static void __inline memset16(void *dest, uint16_t val, int count) { __asm { cld @@ -221,6 +222,36 @@ void __inline memset16(void *dest, uint16_t val, int count) do { \ __asm { int 3 } \ } while(0) + +static unsigned int __inline get_cs(void) +{ + unsigned int res; + __asm { + xor eax, eax + mov ax, cs + mov [res], ax + } + return res; +} #endif +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_ */