From 742b77c545817aa3aa606dd977984197a35abc6b Mon Sep 17 00:00:00 2001 From: Tom Lint Date: Sun, 3 Aug 2014 22:44:44 +0200 Subject: [PATCH] Updated project setup Tidied-up SpriteBatch header- and source file --- include/Graphics/SpriteBatch.h | 17 +- include/System/Nullable.h | 5 + include/System/Threading/Thread.h | 17 +- include/System/Windows/DependencyObject.h | 2 +- include/intrin.h | 1119 +++++++++++++++++++++ src/libSystem.Windows/makefile | 12 +- src/libSystem.Xml/libSystem.Xml.vcxproj | 8 +- src/libSystem/libSystem.vcxproj | 8 +- src/libXFX/GraphicsDevice.cpp | 2 + src/libXFX/GraphicsResource.cpp | 2 + src/libXFX/SpriteBatch.cpp | 58 +- src/libmscorlib/Environment.cpp | 1 + src/libmscorlib/Thread.cpp | 48 +- src/libmscorlib/libmscorlib.vcxproj | 4 +- src/libmscorlib/makefile | 2 +- src/libmscorlib/sassert.c | 4 +- src/makefile | 2 +- 17 files changed, 1218 insertions(+), 93 deletions(-) create mode 100644 include/intrin.h diff --git a/include/Graphics/SpriteBatch.h b/include/Graphics/SpriteBatch.h index ee02f03..7aec739 100644 --- a/include/Graphics/SpriteBatch.h +++ b/include/Graphics/SpriteBatch.h @@ -11,6 +11,7 @@ #include "DepthStencilState.h" #include "Effect.h" #include "Enums.h" +#include "GraphicsResource.h" #include #include "RasterizerState.h" #include "SamplerState.h" @@ -38,11 +39,9 @@ namespace XFX /** * Enables a group of sprites to be drawn using the same settings. */ - class SpriteBatch : public IDisposable, public Object + class SpriteBatch : public GraphicsResource, public Object { private: - GraphicsDevice* device; - bool isDisposed; bool inBeginEndPair; //SaveStateMode_t saveStateMode; StateBlock* saveState; @@ -58,23 +57,17 @@ namespace XFX void restoreRenderState(); protected: - virtual void Dispose(bool disposing); + void Dispose(bool disposing); public: - GraphicsDevice* getGraphicsDevice() const; - bool IsDisposed() const; - - EventHandler Disposing; - SpriteBatch(GraphicsDevice * const graphicsDevice); virtual ~SpriteBatch(); void Begin(); void Begin(SpriteSortMode_t sortMode, const BlendState& blendState); void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState); - void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState, Effect* effect); - void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState, Effect* effect, Matrix transformMatrix); - void Dispose(); + void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState, Effect * const effect); + void Begin(SpriteSortMode_t sortMode, const BlendState& blendState, const SamplerState& samplerState, const DepthStencilState& depthStencilState, const RasterizerState& rasterizerState, Effect * const effect, const Matrix transformMatrix); void Draw(Texture2D * const texture, const Rectangle destinationRectangle, Color color); void Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, Color color); void Draw(Texture2D * const texture, const Vector2 position, const Color color); diff --git a/include/System/Nullable.h b/include/System/Nullable.h index 5dcb91b..c34e7a3 100644 --- a/include/System/Nullable.h +++ b/include/System/Nullable.h @@ -21,6 +21,11 @@ namespace System { } + Nullable(T const * const newData) + : data(const_cast(newData)) + { + } + Nullable(const Nullable &obj) : data(obj.data) { diff --git a/include/System/Threading/Thread.h b/include/System/Threading/Thread.h index 7ea242e..a0b8ddc 100644 --- a/include/System/Threading/Thread.h +++ b/include/System/Threading/Thread.h @@ -25,7 +25,8 @@ namespace System HANDLE system_thread_handle; PKSTART_ROUTINE callback; int stack_size; - static ULONG Id; + static ULONG GlobalId; + ULONG Id; PULONG suspendCount; ThreadState_t state; @@ -34,25 +35,25 @@ namespace System void Thread_init(); public: - //Creates a new instance of the Thread class with the specified callback function, but doesn't start yet. + // Initializes a new instance of the Thread class with the specified callback function, but doesn't start yet. Thread(PKSTART_ROUTINE callBack); - //Creates a new instance of the Thread class with the specified callback function and stack size, but doesn't start yet. + // Initializes a new instance of the Thread class with the specified callback function and stack size, but doesn't start yet. Thread(PKSTART_ROUTINE callBack, int stackSize); ~Thread(); void Abort(); void Interrupt(); - //Returns a value indicating whether the thread is running + // Returns a value indicating whether the thread is running bool IsAlive(); - //Resumes a previously suspended thread. + // Resumes a previously suspended thread. void Resume(); - //Set the thread priority, valid values are 0 (Low), 16 (Low_RealTime), 31 (High), 32 (Maximum) + // Set the thread priority, valid values are 0 (Low), 16 (Low_RealTime), 31 (High), 32 (Maximum) void SetPriority(int priority); static void Sleep(int millisecondsTimeout); static void Sleep(TimeSpan timeout); - //Start executing the thread. + // Start executing the thread. void Start(); - //Suspend the thread execution, call Thread::Resume() to resume the thread. + // Suspend the thread execution, call Thread::Resume() to resume the thread. void Suspend(); }; } diff --git a/include/System/Windows/DependencyObject.h b/include/System/Windows/DependencyObject.h index 5a72ca6..9919527 100644 --- a/include/System/Windows/DependencyObject.h +++ b/include/System/Windows/DependencyObject.h @@ -69,7 +69,7 @@ namespace System void SetValue(DependencyProperty p, T * const value) { if (!dependencyProperties.ContainsKey(p.Name)) - dependencyProperties.Add(p.Name, value) + dependencyProperties.Add(p.Name, value); else dependencyProperties[p.Name] = value; } diff --git a/include/intrin.h b/include/intrin.h new file mode 100644 index 0000000..6b97462 --- /dev/null +++ b/include/intrin.h @@ -0,0 +1,1119 @@ +/***************************************************************************** + * intrin.h * + * * + * Copyright (c) XFX Team. All rights reserved. * + * * + * Purpose: * + * This include file contains the declarations for x86-specific * + * intrinsic functions. * + * * + * Original code by ReactOS project (http://www.reactos.org/) * + *****************************************************************************/ +#ifndef _INTRIN_H +#define _INTRIN_H + +#if _MSC_VER +# define __INTRIN_INLINE extern __inline +#elif __GNUC__ +# define __ATTRIBUTE_ARTIFICIAL __attribute__((artificial)) +# define __INTRIN_INLINE extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) __ATTRIBUTE_ARTIFICIAL +#else +# pragma error "Unsupported Compiler" +#endif + +#include +#include + +__INTRIN_INLINE void _mm_lfence(void); +__INTRIN_INLINE void _mm_sfence(void); +__INTRIN_INLINE void _ReadWriteBarrier(void); +__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char *const Destination, const char Exchange, const char Comperand); +__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short *const Destination, const short Exchange, const short Comperand); +__INTRIN_INLINE long _InterlockedCompareExchange(volatile long *const Destination, const long Exchange, const long Comperand); +__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void *volatile *const Destination, void *const Exchange, void *const Comperand); +__INTRIN_INLINE long _InterlockedExchange(volatile long *const Target, const long Value); +__INTRIN_INLINE void * _InterlockedExchangePointer(void *volatile *const Target, void *const Value); +__INTRIN_INLINE short _InterlockedExchangeAdd16(volatile short *const Addend, const short Value); +__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long *const Addend, const long Value); +__INTRIN_INLINE char _InterlockedAnd8(volatile char *const value, const char mask); +__INTRIN_INLINE short _InterlockedAnd16(volatile short *const value, const short mask); +__INTRIN_INLINE long _InterlockedAnd(volatile long *const value, const long mask); +__INTRIN_INLINE char _InterlockedOr8(volatile char *const value, const char mask); +__INTRIN_INLINE short _InterlockedOr16(volatile short *const value, const short mask); +__INTRIN_INLINE long _InterlockedOr(volatile long *const value, const long mask); +__INTRIN_INLINE char _InterlockedXor8(volatile char *const value, const char mask); +__INTRIN_INLINE short _InterlockedXor16(volatile short *const value, const short mask); +__INTRIN_INLINE long _InterlockedXor(volatile long *const value, const long mask); +__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long *const Destination, const long long Exchange, const long long Comperand); +__INTRIN_INLINE long _InterlockedAddLargeStatistic(volatile long long *const Addend, const long Value); +__INTRIN_INLINE long _InterlockedDecrement(volatile long *const lpAddend); +__INTRIN_INLINE long _InterlockedIncrement(volatile long *const lpAddend); +__INTRIN_INLINE short _InterlockedDecrement16(volatile short *const lpAddend); +__INTRIN_INLINE short _InterlockedIncrement16(volatile short *const lpAddend); +__INTRIN_INLINE unsigned char _interlockedbittestandreset(volatile long *a, const long b); +__INTRIN_INLINE unsigned char _interlockedbittestandset(volatile long *a, const long b); +__INTRIN_INLINE void __stosb(unsigned char *Dest, const unsigned char Data, size_t Count); +__INTRIN_INLINE void __stosw(unsigned short *Dest, const unsigned short Data, size_t Count); +__INTRIN_INLINE void __stosd(unsigned long *Dest, const unsigned long Data, size_t Count); +__INTRIN_INLINE void __movsb(unsigned char *Destination, const unsigned char *Source, size_t Count); +__INTRIN_INLINE void __movsw(unsigned short *Destination, const unsigned short *Source, size_t Count); +__INTRIN_INLINE void __movsd(unsigned long *Destination, const unsigned long *Source, size_t Count); +__INTRIN_INLINE void __writefsbyte(const unsigned long Offset, const unsigned char Data); +__INTRIN_INLINE void __writefsword(const unsigned long Offset, const unsigned short Data); +__INTRIN_INLINE void __writefsdword(const unsigned long Offset, const unsigned long Data); +__INTRIN_INLINE unsigned char __readfsbyte(const unsigned long Offset); +__INTRIN_INLINE unsigned short __readfsword(const unsigned long Offset); +__INTRIN_INLINE unsigned long __readfsdword(const unsigned long Offset); +__INTRIN_INLINE void __incfsbyte(const unsigned long Offset); +__INTRIN_INLINE void __incfsword(const unsigned long Offset); +__INTRIN_INLINE void __incfsdword(const unsigned long Offset); +__INTRIN_INLINE void __addfsbyte(const unsigned long Offset, const unsigned char Data); +__INTRIN_INLINE void __addfsword(const unsigned long Offset, const unsigned short Data); +__INTRIN_INLINE void __addfsdword(const unsigned long Offset, const unsigned int Data); +__INTRIN_INLINE unsigned char _BitScanForward(unsigned long *const Index, const unsigned long Mask); +__INTRIN_INLINE unsigned char _BitScanReverse(unsigned long *const Index, const unsigned long Mask); +__INTRIN_INLINE unsigned char _bittest(const long *const a, const long b); +__INTRIN_INLINE unsigned char _bittestandcomplement(long *const a, const long b); +__INTRIN_INLINE unsigned char _bittestandreset(long *const a, const long b); +__INTRIN_INLINE unsigned char _bittestandset(long *const a, const long b); +__INTRIN_INLINE unsigned char _rotl8(unsigned char value, unsigned char shift); +__INTRIN_INLINE unsigned short _rotl16(unsigned short value, unsigned char shift); +__INTRIN_INLINE unsigned int _rotl(unsigned int value, int shift); +__INTRIN_INLINE unsigned int _rotr(unsigned int value, int shift); +__INTRIN_INLINE unsigned char _rotr8(unsigned char value, unsigned char shift); +__INTRIN_INLINE unsigned short _rotr16(unsigned short value, unsigned char shift); +__INTRIN_INLINE unsigned long long __ll_lshift(const unsigned long long Mask, const int Bit); +__INTRIN_INLINE long long __ll_rshift(const long long Mask, const int Bit); +__INTRIN_INLINE unsigned long long __ull_rshift(const unsigned long long Mask, int Bit); +__INTRIN_INLINE unsigned short _byteswap_ushort(unsigned short value); +__INTRIN_INLINE unsigned long _byteswap_ulong(unsigned long value); +__INTRIN_INLINE unsigned long long _byteswap_uint64(unsigned long long value); +__INTRIN_INLINE long long __emul(const int a, const int b); +__INTRIN_INLINE unsigned long long __emulu(const unsigned int a, const unsigned int b); +__INTRIN_INLINE unsigned char __inbyte(const unsigned short Port); +__INTRIN_INLINE unsigned short __inword(const unsigned short Port); +__INTRIN_INLINE unsigned long __indword(const unsigned short Port); +__INTRIN_INLINE void __inbytestring(unsigned short Port, unsigned char *Buffer, unsigned long Count); +__INTRIN_INLINE void __inwordstring(unsigned short Port, unsigned short *Buffer, unsigned long Count); +__INTRIN_INLINE void __indwordstring(unsigned short Port, unsigned long *Buffer, unsigned long Count); +__INTRIN_INLINE void __outbyte(unsigned short const Port, const unsigned char Data); +__INTRIN_INLINE void __outword(unsigned short const Port, const unsigned short Data); +__INTRIN_INLINE void __outdword(unsigned short const Port, const unsigned long Data); +__INTRIN_INLINE void __outbytestring(unsigned short const Port, const unsigned char *const Buffer, const unsigned long Count); +__INTRIN_INLINE void __outwordstring(unsigned short const Port, const unsigned short *const Buffer, const unsigned long Count); +__INTRIN_INLINE void __outdwordstring(unsigned short const Port, const unsigned long *const Buffer, const unsigned long Count); +__INTRIN_INLINE int _inp(unsigned short Port); +__INTRIN_INLINE unsigned short _inpw(unsigned short Port); +__INTRIN_INLINE unsigned long _inpd(unsigned short Port); +__INTRIN_INLINE int _outp(unsigned short Port, int databyte); +__INTRIN_INLINE unsigned short _outpw(unsigned short Port, unsigned short dataword); +__INTRIN_INLINE unsigned long _outpd(unsigned short Port, unsigned long dataword); +__INTRIN_INLINE void __cpuid(int CPUInfo[], const int InfoType); +__INTRIN_INLINE unsigned long long __rdtsc(void); +__INTRIN_INLINE void __writeeflags(uintptr_t Value); +__INTRIN_INLINE uintptr_t __readeflags(void); +__INTRIN_INLINE void __debugbreak(void); +__INTRIN_INLINE void __int2c(void); +__INTRIN_INLINE void _disable(void); +__INTRIN_INLINE void _enable(void); +__INTRIN_INLINE void __halt(void); +__INTRIN_INLINE void __writecr0(const unsigned long long Data); +__INTRIN_INLINE void __writecr3(const unsigned long long Data); +__INTRIN_INLINE void __writecr4(const unsigned long long Data); +#if !defined(__amd64__) +__INTRIN_INLINE unsigned long __readcr0(void); +__INTRIN_INLINE unsigned long __readcr2(void); +__INTRIN_INLINE unsigned long __readcr3(void); +__INTRIN_INLINE unsigned long __readcr4(void); +__INTRIN_INLINE unsigned int __readdr(unsigned int reg); +__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value); +#endif +__INTRIN_INLINE void __invlpg(void *const Address); +__INTRIN_INLINE unsigned long long __readmsr(const int reg); +__INTRIN_INLINE void __writemsr(const unsigned long Register, const unsigned long long Value); +__INTRIN_INLINE unsigned long long __readpmc(const int counter); +__INTRIN_INLINE unsigned long __segmentlimit(const unsigned long a); +__INTRIN_INLINE void __wbinvd(void); +__INTRIN_INLINE void __lidt(void *Source); +__INTRIN_INLINE void __sidt(void *Destination); +__INTRIN_INLINE void _mm_pause(void); + +#if __GNUC__ +__INTRIN_INLINE void _ReadWriteBarrier(void) +{ + __asm__ __volatile__("" : : : "memory"); +} + +#define _ReadBarrier _ReadWriteBarrier +#define _WriteBarrier _ReadWriteBarrier + +__INTRIN_INLINE void _mm_lfence(void) +{ + _ReadBarrier(); + __asm__ __volatile__("lfence"); + _ReadBarrier(); +} + +__INTRIN_INLINE void _mm_sfence(void) +{ + _WriteBarrier(); + __asm__ __volatile__("sfence"); + _WriteBarrier(); +} + +__INTRIN_INLINE char _InterlockedCompareExchange8(volatile char *const Destination, const char Exchange, const char Comperand) +{ + char retval = Comperand; + __asm__("lock; cmpxchgb %b[Exchange], %[Destination]" : [retval] "+a" (retval) : [Destination] "m" (*Destination), [Exchange] "q" (Exchange) : "memory"); + return retval; +} + +__INTRIN_INLINE short _InterlockedCompareExchange16(volatile short *const Destination, const short Exchange, const short Comperand) +{ + short retval = Comperand; + __asm__("lock; cmpxchgw %w[Exchange], %[Destination]" : [retval] "+a" (retval) : [Destination] "m" (*Destination), [Exchange] "q" (Exchange): "memory"); + return retval; +} + +__INTRIN_INLINE long _InterlockedCompareExchange(volatile long *const Destination, const long Exchange, const long Comperand) +{ + long retval = Comperand; + __asm__("lock; cmpxchgl %k[Exchange], %[Destination]" : [retval] "+a" (retval) : [Destination] "m" (*Destination), [Exchange] "q" (Exchange): "memory"); + return retval; +} + +__INTRIN_INLINE void * _InterlockedCompareExchangePointer(void *volatile *const Destination, void *const Exchange, void *const Comperand) +{ + void * retval = (void *)Comperand; + __asm__("lock; cmpxchgl %k[Exchange], %[Destination]" : [retval] "=a" (retval) : "[retval]" (retval), [Destination] "m" (*Destination), [Exchange] "q" (Exchange) : "memory"); + return retval; +} + +__INTRIN_INLINE long _InterlockedExchange(volatile long *const Target, const long Value) +{ + long retval = Value; + __asm__("xchgl %[retval], %[Target]" : [retval] "+r" (retval) : [Target] "m" (*Target) : "memory"); + return retval; +} + +__INTRIN_INLINE void * _InterlockedExchangePointer(void *volatile *const Target, void *const Value) +{ + void * retval = Value; + __asm__("xchgl %[retval], %[Target]" : [retval] "+r" (retval) : [Target] "m" (*Target) : "memory"); + return retval; +} + +__INTRIN_INLINE short _InterlockedExchangeAdd16(volatile short *const Addend, const short Value) +{ + long retval = Value; + __asm__("lock; xaddw %[retval], %[Addend]" : [retval] "+r" (retval) : [Addend] "m" (*Addend) : "memory"); + return (short)retval; +} + +__INTRIN_INLINE long _InterlockedExchangeAdd(volatile long *const Addend, const long Value) +{ + long retval = Value; +#if __x86_64__ + __asm__("lock; xaddq %[retval], %[Addend]" : [retval] "+r" (retval) : [Addend] "m" (*Addend) : "memory"); +#else + __asm__("lock; xaddl %[retval], %[Addend]" : [retval] "+r" (retval) : [Addend] "m" (*Addend) : "memory"); +#endif + return retval; +} + +__INTRIN_INLINE char _InterlockedAnd8(volatile char *const value, const char mask) +{ + char x; + char y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange8(value, x & mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE short _InterlockedAnd16(volatile short *const value, const short mask) +{ + short x; + short y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange16(value, x & mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE long _InterlockedAnd(volatile long *const value, const long mask) +{ + long x; + long y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange(value, x & mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE char _InterlockedOr8(volatile char *const value, const char mask) +{ + char x; + char y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange8(value, x | mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE short _InterlockedOr16(volatile short *const value, const short mask) +{ + short x; + short y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange16(value, x | mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE long _InterlockedOr(volatile long *const value, const long mask) +{ + long x; + long y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange(value, x | mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE char _InterlockedXor8(volatile char *const value, const char mask) +{ + char x; + char y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange8(value, x ^ mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE short _InterlockedXor16(volatile short *const value, const short mask) +{ + short x; + short y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange16(value, x ^ mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE long _InterlockedXor(volatile long *const value, const long mask) +{ + long x; + long y; + + y = *value; + + do + { + x = y; + y = _InterlockedCompareExchange(value, x ^ mask, x); + } + while(y != x); + + return y; +} + +__INTRIN_INLINE long long _InterlockedCompareExchange64(volatile long long *const Destination, const long long Exchange, const long long Comperand) +{ +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 && defined(__x86_64__) + return __sync_val_compare_and_swap(Destination, Comperand, Exchange); +#else + long long retval = Comperand; + + __asm__ + ( + "lock; cmpxchg8b %[Destination]" : + [retval] "+A" (retval) : + [Destination] "m" (*Destination), + "b" ((unsigned long)((Exchange >> 0) & 0xFFFFFFFF)), + "c" ((unsigned long)((Exchange >> 32) & 0xFFFFFFFF)) : + "memory" + ); + + return retval; +#endif +} + +__INTRIN_INLINE long _InterlockedAddLargeStatistic(volatile long long *const Addend, const long Value) +{ + __asm__ + ( + "lock; add %[Value], %[Lo32];" + "jae LABEL%=;" + "lock; adc $0, %[Hi32];" + "LABEL%=:;" : + [Lo32] "+m" (*((volatile long *)(Addend) + 0)), [Hi32] "+m" (*((volatile long *)(Addend) + 1)) : + [Value] "ir" (Value) : + "memory" + ); + + return Value; +} + +__INTRIN_INLINE long _InterlockedDecrement(volatile long *const lpAddend) +{ + return _InterlockedExchangeAdd(lpAddend, -1) - 1; +} + +__INTRIN_INLINE long _InterlockedIncrement(volatile long *const lpAddend) +{ + return _InterlockedExchangeAdd(lpAddend, 1) + 1; +} + +__INTRIN_INLINE short _InterlockedDecrement16(volatile short *const lpAddend) +{ + return (short)(_InterlockedExchangeAdd16(lpAddend, -1) - 1); +} + +__INTRIN_INLINE short _InterlockedIncrement16(volatile short *const lpAddend) +{ + return (short)(_InterlockedExchangeAdd16(lpAddend, 1) + 1); +} + +__INTRIN_INLINE unsigned char _interlockedbittestandreset(volatile long *a, const long b) +{ + unsigned char retval; + __asm__("lock; btrl %[b], %[a]; setb %b[retval]" : [retval] "=q" (retval), [a] "+m" (*a) : [b] "Ir" (b) : "memory"); + return retval; +} + +__INTRIN_INLINE unsigned char _interlockedbittestandset(volatile long *a, const long b) +{ + unsigned char retval; + __asm__("lock; btsl %[b], %[a]; setc %b[retval]" : [retval] "=q" (retval), [a] "+m" (*a) : [b] "Ir" (b) : "memory"); + return retval; +} + +__INTRIN_INLINE void __stosb(unsigned char *Dest, const unsigned char Data, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; stosb" : + [Dest] "=D" (Dest), [Count] "=c" (Count) : + "[Dest]" (Dest), "a" (Data), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __stosw(unsigned short *Dest, const unsigned short Data, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; stosw" : + [Dest] "=D" (Dest), [Count] "=c" (Count) : + "[Dest]" (Dest), "a" (Data), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __stosd(unsigned long * Dest, const unsigned long Data, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; stosl" : + [Dest] "=D" (Dest), [Count] "=c" (Count) : + "[Dest]" (Dest), "a" (Data), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __movsb(unsigned char *Destination, const unsigned char *Source, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; movsb" : + [Destination] "=D" (Destination), [Source] "=S" (Source), [Count] "=c" (Count) : + "[Destination]" (Destination), "[Source]" (Source), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __movsw(unsigned short *Destination, const unsigned short *Source, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; movsw" : + [Destination] "=D" (Destination), [Source] "=S" (Source), [Count] "=c" (Count) : + "[Destination]" (Destination), "[Source]" (Source), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __movsd(unsigned long *Destination, const unsigned long *Source, size_t Count) +{ + __asm__ __volatile__ + ( + "rep; movsd" : + [Destination] "=D" (Destination), [Source] "=S" (Source), [Count] "=c" (Count) : + "[Destination]" (Destination), "[Source]" (Source), "[Count]" (Count) + ); +} + +__INTRIN_INLINE void __writefsbyte(const unsigned long Offset, const unsigned char Data) +{ + __asm__ __volatile__("movb %b[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory"); +} + +__INTRIN_INLINE void __writefsword(const unsigned long Offset, const unsigned short Data) +{ + __asm__ __volatile__("movw %w[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "ir" (Data) : "memory"); +} + +__INTRIN_INLINE void __writefsdword(const unsigned long Offset, const unsigned long Data) +{ + __asm__ __volatile__("movl %k[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "ir" (Data) : "memory"); +} + +__INTRIN_INLINE unsigned char __readfsbyte(const unsigned long Offset) +{ + unsigned char value; + __asm__ __volatile__("movb %%fs:%a[Offset], %b[value]" : [value] "=q" (value) : [Offset] "ir" (Offset)); + return value; +} + +__INTRIN_INLINE unsigned short __readfsword(const unsigned long Offset) +{ + unsigned short value; + __asm__ __volatile__("movw %%fs:%a[Offset], %w[value]" : [value] "=r" (value) : [Offset] "ir" (Offset)); + return value; +} + +__INTRIN_INLINE unsigned long __readfsdword(const unsigned long Offset) +{ + unsigned long value; + __asm__ __volatile__("movl %%fs:%a[Offset], %k[value]" : [value] "=r" (value) : [Offset] "ir" (Offset)); + return value; +} + +__INTRIN_INLINE void __incfsbyte(const unsigned long Offset) +{ + __asm__ __volatile__("incb %%fs:%a[Offset]" : : [Offset] "ir" (Offset) : "memory"); +} + +__INTRIN_INLINE void __incfsword(const unsigned long Offset) +{ + __asm__ __volatile__("incw %%fs:%a[Offset]" : : [Offset] "ir" (Offset) : "memory"); +} + +__INTRIN_INLINE void __incfsdword(const unsigned long Offset) +{ + __asm__ __volatile__("incl %%fs:%a[Offset]" : : [Offset] "ir" (Offset) : "memory"); +} + +__INTRIN_INLINE void __addfsbyte(const unsigned long Offset, const unsigned char Data) +{ + if(!__builtin_constant_p(Offset)) + __asm__ __volatile__("addb %b[Offset], %%fs:%a[Offset]" : : [Offset] "r" (Offset) : "memory"); + else + __asm__ __volatile__("addb %b[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory"); +} + +__INTRIN_INLINE void __addfsword(const unsigned long Offset, const unsigned short Data) +{ + if(!__builtin_constant_p(Offset)) + __asm__ __volatile__("addw %w[Offset], %%fs:%a[Offset]" : : [Offset] "r" (Offset) : "memory"); + else + __asm__ __volatile__("addw %w[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory"); +} + +__INTRIN_INLINE void __addfsdword(const unsigned long Offset, const unsigned int Data) +{ + if(!__builtin_constant_p(Offset)) + __asm__ __volatile__("addl %k[Offset], %%fs:%a[Offset]" : : [Offset] "r" (Offset) : "memory"); + else + __asm__ __volatile__("addl %k[Data], %%fs:%a[Offset]" : : [Offset] "ir" (Offset), [Data] "iq" (Data) : "memory"); +} + +__INTRIN_INLINE unsigned char _BitScanForward(unsigned long *const Index, const unsigned long Mask) +{ + __asm__("bsfl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask)); + return Mask ? 1 : 0; +} + +__INTRIN_INLINE unsigned char _BitScanReverse(unsigned long *const Index, const unsigned long Mask) +{ + __asm__("bsrl %[Mask], %[Index]" : [Index] "=r" (*Index) : [Mask] "mr" (Mask)); + return Mask ? 1 : 0; +} + +__INTRIN_INLINE unsigned char _bittest(const long *const a, const long b) +{ + unsigned char retval; + + if(__builtin_constant_p(b)) + __asm__("bt %[b], %[a]; setb %b[retval]" : [retval] "=q" (retval) : [a] "mr" (*(a + (b / 32))), [b] "Ir" (b % 32)); + else + __asm__("bt %[b], %[a]; setb %b[retval]" : [retval] "=q" (retval) : [a] "mr" (*a), [b] "r" (b)); + + return retval; +} + +__INTRIN_INLINE unsigned char _bittestandcomplement(long *const a, const long b) +{ + unsigned char retval; + + if(__builtin_constant_p(b)) + __asm__("btc %[b], %[a]; setb %b[retval]" : [a] "+mr" (*(a + (b / 32))), [retval] "=q" (retval) : [b] "Ir" (b % 32)); + else + __asm__("btc %[b], %[a]; setb %b[retval]" : [a] "+mr" (*a), [retval] "=q" (retval) : [b] "r" (b)); + + return retval; +} + +__INTRIN_INLINE unsigned char _bittestandreset(long *const a, const long b) +{ + unsigned char retval; + + if(__builtin_constant_p(b)) + __asm__("btr %[b], %[a]; setb %b[retval]" : [a] "+mr" (*(a + (b / 32))), [retval] "=q" (retval) : [b] "Ir" (b % 32)); + else + __asm__("btr %[b], %[a]; setb %b[retval]" : [a] "+mr" (*a), [retval] "=q" (retval) : [b] "r" (b)); + + return retval; +} + +__INTRIN_INLINE unsigned char _bittestandset(long *const a, const long b) +{ + unsigned char retval; + + if(__builtin_constant_p(b)) + __asm__("bts %[b], %[a]; setb %b[retval]" : [a] "+mr" (*(a + (b / 32))), [retval] "=q" (retval) : [b] "Ir" (b % 32)); + else + __asm__("bts %[b], %[a]; setb %b[retval]" : [a] "+mr" (*a), [retval] "=q" (retval) : [b] "r" (b)); + + return retval; +} + +__INTRIN_INLINE unsigned char _rotl8(unsigned char value, unsigned char shift) +{ + unsigned char retval; + __asm__("rolb %b[shift], %b[retval]" : [retval] "=rm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned short _rotl16(unsigned short value, unsigned char shift) +{ + unsigned short retval; + __asm__("rolw %b[shift], %w[retval]" : [retval] "=rm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned int _rotl(unsigned int value, int shift) +{ + unsigned long retval; + __asm__("roll %b[shift], %k[retval]" : [retval] "=rm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned int _rotr(unsigned int value, int shift) +{ + unsigned long retval; + __asm__("rorl %b[shift], %k[retval]" : [retval] "=rm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned char _rotr8(unsigned char value, unsigned char shift) +{ + unsigned char retval; + __asm__("rorb %b[shift], %b[retval]" : [retval] "=qm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned short _rotr16(unsigned short value, unsigned char shift) +{ + unsigned short retval; + __asm__("rorw %b[shift], %w[retval]" : [retval] "=rm" (retval) : "[retval]" (value), [shift] "Nc" (shift)); + return retval; +} + +__INTRIN_INLINE unsigned long long __ll_lshift(const unsigned long long Mask, const int Bit) +{ + unsigned long long retval = Mask; + + __asm__ + ( + "shldl %b[Bit], %%eax, %%edx; sall %b[Bit], %%eax" : + "+A" (retval) : + [Bit] "Nc" ((unsigned char)((unsigned long)Bit) & 0xFF) + ); + + return retval; +} + +__INTRIN_INLINE long long __ll_rshift(const long long Mask, const int Bit) +{ + unsigned long long retval = (unsigned long long)Mask; + + __asm__ + ( + "shldl %b[Bit], %%eax, %%edx; sarl %b[Bit], %%eax" : + "+A" (retval) : + [Bit] "Nc" ((unsigned char)((unsigned long)Bit) & 0xFF) + ); + + return (long long)retval; +} + +__INTRIN_INLINE unsigned long long __ull_rshift(const unsigned long long Mask, int Bit) +{ + unsigned long long retval = Mask; + + __asm__ + ( + "shrdl %b[Bit], %%eax, %%edx; shrl %b[Bit], %%eax" : + "+A" (retval) : + [Bit] "Nc" ((unsigned char)((unsigned long)Bit) & 0xFF) + ); + + return retval; +} + +__INTRIN_INLINE unsigned short _byteswap_ushort(unsigned short value) +{ + unsigned short retval; + __asm__("rorw $8, %w[retval]" : [retval] "=rm" (retval) : "[retval]" (value)); + return retval; +} + +__INTRIN_INLINE unsigned long _byteswap_ulong(unsigned long value) +{ + unsigned long retval; + __asm__("bswapl %[retval]" : [retval] "=r" (retval) : "[retval]" (value)); + return retval; +} + +__INTRIN_INLINE unsigned long long _byteswap_uint64(unsigned long long value) +{ +#if __i386__ + union { + unsigned long long int64part; + struct { + unsigned long lowpart; + unsigned long hipart; + }; + } retval; + retval.int64part = value; + __asm__("bswapl %[lowpart]\n" + "bswapl %[hipart]\n" + : [lowpart] "=r" (retval.hipart), [hipart] "=r" (retval.lowpart) : "[lowpart]" (retval.lowpart), "[hipart]" (retval.hipart) ); + return retval.int64part; +#else + unsigned long long retval; + __asm__("bswapq %[retval]" : [retval] "=r" (retval) : "[retval]" (value)); + return retval; +#endif +} + +__INTRIN_INLINE long long __emul(const int a, const int b) +{ + long long retval; + __asm__("imull %[b]" : "=A" (retval) : [a] "a" (a), [b] "rm" (b)); + return retval; +} + +__INTRIN_INLINE unsigned long long __emulu(const unsigned int a, const unsigned int b) +{ + unsigned long long retval; + __asm__("mull %[b]" : "=A" (retval) : [a] "a" (a), [b] "rm" (b)); + return retval; +} + +__INTRIN_INLINE unsigned char __inbyte(const unsigned short Port) +{ + unsigned char byte; + __asm__ __volatile__("inb %w[Port], %b[byte]" : [byte] "=a" (byte) : [Port] "Nd" (Port)); + return byte; +} + +__INTRIN_INLINE unsigned short __inword(const unsigned short Port) +{ + unsigned short word; + __asm__ __volatile__("inw %w[Port], %w[word]" : [word] "=a" (word) : [Port] "Nd" (Port)); + return word; +} + +__INTRIN_INLINE unsigned long __indword(const unsigned short Port) +{ + unsigned long dword; + __asm__ __volatile__("inl %w[Port], %k[dword]" : [dword] "=a" (dword) : [Port] "Nd" (Port)); + return dword; +} + +__INTRIN_INLINE void __inbytestring(unsigned short Port, unsigned char *Buffer, unsigned long Count) +{ + __asm__ __volatile__ + ( + "rep; insb" : + [Buffer] "=D" (Buffer), [Count] "=c" (Count) : + "d" (Port), "[Buffer]" (Buffer), "[Count]" (Count) : + "memory" + ); +} + +__INTRIN_INLINE void __inwordstring(unsigned short Port, unsigned short *Buffer, unsigned long Count) +{ + __asm__ __volatile__ + ( + "rep; insw" : + [Buffer] "=D" (Buffer), [Count] "=c" (Count) : + "d" (Port), "[Buffer]" (Buffer), "[Count]" (Count) : + "memory" + ); +} + +__INTRIN_INLINE void __indwordstring(unsigned short Port, unsigned long *Buffer, unsigned long Count) +{ + __asm__ __volatile__ + ( + "rep; insl" : + [Buffer] "=D" (Buffer), [Count] "=c" (Count) : + "d" (Port), "[Buffer]" (Buffer), "[Count]" (Count) : + "memory" + ); +} + +__INTRIN_INLINE void __outbyte(unsigned short const Port, const unsigned char Data) +{ + __asm__ __volatile__("outb %b[Data], %w[Port]" : : [Port] "Nd" (Port), [Data] "a" (Data)); +} + +__INTRIN_INLINE void __outword(unsigned short const Port, const unsigned short Data) +{ + __asm__ __volatile__("outw %w[Data], %w[Port]" : : [Port] "Nd" (Port), [Data] "a" (Data)); +} + +__INTRIN_INLINE void __outdword(unsigned short const Port, const unsigned long Data) +{ + __asm__ __volatile__("outl %k[Data], %w[Port]" : : [Port] "Nd" (Port), [Data] "a" (Data)); +} + +__INTRIN_INLINE void __outbytestring(unsigned short const Port, const unsigned char *const Buffer, const unsigned long Count) +{ + __asm__ __volatile__("rep; outsb" : : [Port] "d" (Port), [Buffer] "S" (Buffer), "c" (Count)); +} + +__INTRIN_INLINE void __outwordstring(unsigned short const Port, const unsigned short *const Buffer, const unsigned long Count) +{ + __asm__ __volatile__("rep; outsw" : : [Port] "d" (Port), [Buffer] "S" (Buffer), "c" (Count)); +} + +__INTRIN_INLINE void __outdwordstring(unsigned short const Port, const unsigned long *const Buffer, const unsigned long Count) +{ + __asm__ __volatile__("rep; outsl" : : [Port] "d" (Port), [Buffer] "S" (Buffer), "c" (Count)); +} + +__INTRIN_INLINE int _inp(unsigned short Port) +{ + return __inbyte(Port); +} +__INTRIN_INLINE unsigned short _inpw(unsigned short Port) +{ + return __inword(Port); +} + +__INTRIN_INLINE unsigned long _inpd(unsigned short Port) +{ + return __indword(Port); +} + +__INTRIN_INLINE int _outp(unsigned short Port, int databyte) +{ + __outbyte(Port, (unsigned char)databyte); + return databyte; +} + +__INTRIN_INLINE unsigned short _outpw(unsigned short Port, unsigned short dataword) +{ + __outword(Port, dataword); + return dataword; +} + +__INTRIN_INLINE unsigned long _outpd(unsigned short Port, unsigned long dataword) +{ + __outdword(Port, dataword); + return dataword; +} + +__INTRIN_INLINE void __cpuid(int CPUInfo[], const int InfoType) +{ + __asm__ __volatile__("cpuid" : "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType)); +} + +__INTRIN_INLINE unsigned long long __rdtsc(void) +{ +#ifdef __x86_64__ + unsigned long long low, high; + __asm__ __volatile__("rdtsc" : "=a"(low), "=d"(high)); + return low | (high << 32); +#else + unsigned long long retval; + __asm__ __volatile__("rdtsc" : "=A"(retval)); + return retval; +#endif +} + +__INTRIN_INLINE void __writeeflags(uintptr_t Value) +{ + __asm__ __volatile__("push %0\n popf" : : "rim"(Value)); +} + +__INTRIN_INLINE uintptr_t __readeflags(void) +{ + uintptr_t retval; + __asm__ __volatile__("pushf\n pop %0" : "=rm"(retval)); + return retval; +} + +__INTRIN_INLINE void __debugbreak(void) +{ + __asm__("int $3"); +} + +__INTRIN_INLINE void __int2c(void) +{ + __asm__("int $0x2c"); +} + +__INTRIN_INLINE void _disable(void) +{ + __asm__("cli" : : : "memory"); +} + +__INTRIN_INLINE void _enable(void) +{ + __asm__("sti" : : : "memory"); +} + +__INTRIN_INLINE void __halt(void) +{ + __asm__("hlt\n\t" : : : "memory"); +} + +__INTRIN_INLINE void __writecr0(const unsigned long long Data) +{ + __asm__("mov %[Data], %%cr0" : : [Data] "r" (Data) : "memory"); +} + +__INTRIN_INLINE void __writecr3(const unsigned long long Data) +{ + __asm__("mov %[Data], %%cr3" : : [Data] "r" (Data) : "memory"); +} + +__INTRIN_INLINE void __writecr4(const unsigned long long Data) +{ + __asm__("mov %[Data], %%cr4" : : [Data] "r" (Data) : "memory"); +} + +#if !__x86_64__ +__INTRIN_INLINE unsigned long __readcr0(void) +{ + unsigned long value; + __asm__ __volatile__("mov %%cr0, %[value]" : [value] "=r" (value)); + return value; +} + +__INTRIN_INLINE unsigned long __readcr2(void) +{ + unsigned long value; + __asm__ __volatile__("mov %%cr2, %[value]" : [value] "=r" (value)); + return value; +} + +__INTRIN_INLINE unsigned long __readcr3(void) +{ + unsigned long value; + __asm__ __volatile__("mov %%cr3, %[value]" : [value] "=r" (value)); + return value; +} + +__INTRIN_INLINE unsigned long __readcr4(void) +{ + unsigned long value; + __asm__ __volatile__("mov %%cr4, %[value]" : [value] "=r" (value)); + return value; +} + +__INTRIN_INLINE unsigned int __readdr(unsigned int reg) +{ + unsigned int value; + switch (reg) + { + case 0: + __asm__ __volatile__("mov %%dr0, %[value]" : [value] "=r" (value)); + break; + case 1: + __asm__ __volatile__("mov %%dr1, %[value]" : [value] "=r" (value)); + break; + case 2: + __asm__ __volatile__("mov %%dr2, %[value]" : [value] "=r" (value)); + break; + case 3: + __asm__ __volatile__("mov %%dr3, %[value]" : [value] "=r" (value)); + break; + case 4: + __asm__ __volatile__("mov %%dr4, %[value]" : [value] "=r" (value)); + break; + case 5: + __asm__ __volatile__("mov %%dr5, %[value]" : [value] "=r" (value)); + break; + case 6: + __asm__ __volatile__("mov %%dr6, %[value]" : [value] "=r" (value)); + break; + case 7: + __asm__ __volatile__("mov %%dr7, %[value]" : [value] "=r" (value)); + break; + } + return value; +} + +__INTRIN_INLINE void __writedr(unsigned reg, unsigned int value) +{ + switch (reg) + { + case 0: + __asm__("mov %[value], %%dr0" : : [value] "r" (value) : "memory"); + break; + case 1: + __asm__("mov %[value], %%dr1" : : [value] "r" (value) : "memory"); + break; + case 2: + __asm__("mov %[value], %%dr2" : : [value] "r" (value) : "memory"); + break; + case 3: + __asm__("mov %[value], %%dr3" : : [value] "r" (value) : "memory"); + break; + case 4: + __asm__("mov %[value], %%dr4" : : [value] "r" (value) : "memory"); + break; + case 5: + __asm__("mov %[value], %%dr5" : : [value] "r" (value) : "memory"); + break; + case 6: + __asm__("mov %[value], %%dr6" : : [value] "r" (value) : "memory"); + break; + case 7: + __asm__("mov %[value], %%dr7" : : [value] "r" (value) : "memory"); + break; + } +} +#endif + +__INTRIN_INLINE void __invlpg(void *const Address) +{ + __asm__("invlpg %[Address]" : : [Address] "m" (*((unsigned char *)(Address))) : "memory"); +} + +__INTRIN_INLINE unsigned long long __readmsr(const int reg) +{ +#ifdef __x86_64__ + unsigned long low, high; + __asm__ __volatile__("rdmsr" : "=a" (low), "=d" (high) : "c" (reg)); + return ((unsigned long long)high << 32) | low; +#else + unsigned long long retval; + __asm__ __volatile__("rdmsr" : "=A" (retval) : "c" (reg)); + return retval; +#endif +} + +__INTRIN_INLINE void __writemsr(const unsigned long Register, const unsigned long long Value) +{ +#ifdef __x86_64__ + __asm__ __volatile__("wrmsr" : : "a" (Value), "d" (Value >> 32), "c" (Register)); +#else + __asm__ __volatile__("wrmsr" : : "A" (Value), "c" (Register)); +#endif +} + +__INTRIN_INLINE unsigned long long __readpmc(const int counter) +{ + unsigned long long retval; + __asm__ __volatile__("rdpmc" : "=A" (retval) : "c" (counter)); + return retval; +} + +__INTRIN_INLINE unsigned long __segmentlimit(const unsigned long a) +{ + unsigned long retval; + __asm__ __volatile__("lsl %[a], %[retval]" : [retval] "=r" (retval) : [a] "rm" (a)); + return retval; +} + +__INTRIN_INLINE void __wbinvd(void) +{ + __asm__ __volatile__("wbinvd" : : : "memory"); +} + +__INTRIN_INLINE void __lidt(void *Source) +{ + __asm__ __volatile__("lidt %0" : : "m"(*(short*)Source)); +} + +__INTRIN_INLINE void __sidt(void *Destination) +{ + __asm__ __volatile__("sidt %0" : : "m"(*(short*)Destination) : "memory"); +} + +__INTRIN_INLINE void _mm_pause(void) +{ + __asm__ __volatile__("pause" : : : "memory"); +} +#endif + +#endif //_INTRIN_H diff --git a/src/libSystem.Windows/makefile b/src/libSystem.Windows/makefile index 3c76be2..141bffd 100644 --- a/src/libSystem.Windows/makefile +++ b/src/libSystem.Windows/makefile @@ -2,13 +2,13 @@ # update this variable to wherever you installed the OpenXDK libraries # ######################################################################### -PREFIX = /openxdk +PREFIX = /usr/local/openxdk -CC = xbox-gcc -CCAS = xbox-gcc -CPP = xbox-g++ -AR = xbox-ar rcu -RANLIB = xbox-ranlib +CC = gcc +CCAS = gcc +CPP = g++ +AR = ar rcu +RANLIB = ranlib CXBE = $(PREFIX)/bin/cxbe SDLFLAGS = -DENABLE_XBOX -DDEBUG diff --git a/src/libSystem.Xml/libSystem.Xml.vcxproj b/src/libSystem.Xml/libSystem.Xml.vcxproj index c2deca6..a93ba95 100644 --- a/src/libSystem.Xml/libSystem.Xml.vcxproj +++ b/src/libSystem.Xml/libSystem.Xml.vcxproj @@ -39,10 +39,10 @@ <_ProjectFileVersion>10.0.40219.1 $(SolutionDir)$(Configuration)\ $(Configuration)\ - C:\cygwin\bin\make -f makefile all 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - C:\cygwin\bin\make -f makefile rebuild 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - C:\cygwin\bin\make -f makefile clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - + make -f makefile all 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + make -f makefile rebuild 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + make -f makefile clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + libSystem.xml.a ENABLE_XBOX; DEBUG;$(NMakePreprocessorDefinitions) C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include\SDL;..\..\include;$(NMakeIncludeSearchPath) $(NMakeForcedIncludes) diff --git a/src/libSystem/libSystem.vcxproj b/src/libSystem/libSystem.vcxproj index 9ca5f51..cec34a2 100644 --- a/src/libSystem/libSystem.vcxproj +++ b/src/libSystem/libSystem.vcxproj @@ -38,10 +38,10 @@ <_ProjectFileVersion>10.0.40219.1 $(SolutionDir)$(Configuration)\ $(Configuration)\ - C:\cygwin\bin\make -f makefile all 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - C:\cygwin\bin\make -f makefile rebuild 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - C:\cygwin\bin\make -f makefile clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 - + make -f makefile all 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + make -f makefile rebuild 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + make -f makefile clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 + libSystem.a ENABLE_XBOX; DEBUG;$(NMakePreprocessorDefinitions) C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include\SDL;..\..\include;$(NMakeIncludeSearchPath) $(NMakeForcedIncludes) diff --git a/src/libXFX/GraphicsDevice.cpp b/src/libXFX/GraphicsDevice.cpp index 6cd836d..9c412e3 100644 --- a/src/libXFX/GraphicsDevice.cpp +++ b/src/libXFX/GraphicsDevice.cpp @@ -215,10 +215,12 @@ namespace XFX { // clear the depth buffer } + if ((options & ClearOptions::Stencil) != 0) { // clear the stencil buffer } + if ((options & ClearOptions::Target) != 0) { // clear the current render target diff --git a/src/libXFX/GraphicsResource.cpp b/src/libXFX/GraphicsResource.cpp index 9d725fb..9a505d5 100644 --- a/src/libXFX/GraphicsResource.cpp +++ b/src/libXFX/GraphicsResource.cpp @@ -62,7 +62,9 @@ namespace XFX void GraphicsResource::Dispose(bool disposing) { if(isDisposed) + { return; + } isDisposed = true; diff --git a/src/libXFX/SpriteBatch.cpp b/src/libXFX/SpriteBatch.cpp index 4cca96d..2f6aff5 100644 --- a/src/libXFX/SpriteBatch.cpp +++ b/src/libXFX/SpriteBatch.cpp @@ -53,8 +53,8 @@ namespace XFX const Type SpriteBatchTypeInfo("SpriteBatch", "XFX::Graphics::SpriteBatch", TypeCode::Object); SpriteBatch::SpriteBatch(GraphicsDevice * const graphicsDevice) - : device(graphicsDevice) { + this->graphicsDevice = graphicsDevice; } SpriteBatch::~SpriteBatch() @@ -62,16 +62,6 @@ namespace XFX Dispose(false); } - GraphicsDevice* SpriteBatch::getGraphicsDevice() const - { - return device; - } - - bool SpriteBatch::IsDisposed() const - { - return isDisposed; - } - void SpriteBatch::Begin() { Begin(SpriteSortMode::Deferred, BlendState::AlphaBlend); @@ -97,43 +87,41 @@ namespace XFX sassert(!inBeginEndPair, "Begin cannot be called again until End has been successfully called."); spriteSortMode = sortMode; + if (sortMode == SpriteSortMode::Immediate) { applyGraphicsDeviceSettings(); } + inBeginEndPair = true; } - + void SpriteBatch::Dispose(bool disposing) { - if (disposing && !isDisposed) + if (disposing && !IsDisposed()) { - Disposing(this, EventArgs::Empty); + // TODO: dispose of resources } - isDisposed = true; + + GraphicsResource::Dispose(disposing); } - - void SpriteBatch::Dispose() - { - Dispose(true); - } - + void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Color color) { - Draw(texture, destinationRectangle, Rectangle::Empty, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); + Draw(texture, destinationRectangle, NULL, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Color color) { Rectangle destination = Rectangle((int)position.X, (int)position.Y, texture->Width, texture->Height); - Draw(texture, destination, Rectangle::Empty, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); + Draw(texture, destination, NULL, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - + void SpriteBatch::Draw(Texture2D * const texture, const Rectangle destinationRectangle, const Nullable sourceRectangle, const Color color) { Draw(texture, destinationRectangle, sourceRectangle, color, 0.0f, Vector2::Zero, SpriteEffects::None, 0.0f); } - + void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color) { Rectangle destination = Rectangle((int)position.X, (int)position.Y, texture->Width, texture->Height); @@ -154,13 +142,16 @@ namespace XFX SpriteList.Add(sprite); if (spriteSortMode == SpriteSortMode::Immediate) + { Flush(); + } } void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const Vector2 scale, const SpriteEffects_t effects, const float layerDepth) { int width; int height; + if (sourceRectangle.HasValue()) { width = (int)(sourceRectangle.getValue().Width * scale.X); @@ -171,14 +162,16 @@ namespace XFX width = (int)(texture->Width * scale.X); height = (int)(texture->Height * scale.Y); } + Rectangle destination = Rectangle((int)position.X, (int)position.Y, width, height); Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); } - + void SpriteBatch::Draw(Texture2D * const texture, const Vector2 position, const Nullable sourceRectangle, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth) { int width; int height; + if (sourceRectangle.HasValue()) { width = (int)(sourceRectangle.getValue().Width * scale); @@ -189,12 +182,13 @@ namespace XFX width = (int)(texture->Width * scale); height = (int)(texture->Height * scale); } + Rectangle destination = Rectangle((int)position.X, (int)position.Y, width, height); Draw(texture, destination, sourceRectangle, color, rotation, origin, effects, layerDepth); } - + void SpriteBatch::DrawString(SpriteFont * const spriteFont, String& text, const Vector2 position, const Color color) - { + { spriteFont->Draw(text, this, position, color, 0.0f, Vector2::Zero, Vector2::One, SpriteEffects::None, 0.0f); } @@ -202,7 +196,7 @@ namespace XFX { spriteFont->Draw(text, this, position, color, rotation, origin, scale, effects, layerDepth); } - + void SpriteBatch::DrawString(SpriteFont * const spriteFont, String& text, const Vector2 position, const Color color, const float rotation, const Vector2 origin, const float scale, const SpriteEffects_t effects, const float layerDepth) { Vector2 vector = Vector2::Zero; @@ -210,9 +204,9 @@ namespace XFX vector.Y = scale; spriteFont->Draw(text, this, position, color, rotation, origin, vector, effects, layerDepth); } - + void SpriteBatch::End() - { + { sassert(inBeginEndPair, "Begin must be called successfully before End can be called."); if (spriteSortMode != SpriteSortMode::Immediate) @@ -226,7 +220,7 @@ namespace XFX glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix();*/ - + restoreRenderState(); inBeginEndPair = false; diff --git a/src/libmscorlib/Environment.cpp b/src/libmscorlib/Environment.cpp index e6d0e6c..39fba4e 100644 --- a/src/libmscorlib/Environment.cpp +++ b/src/libmscorlib/Environment.cpp @@ -71,6 +71,7 @@ namespace System #if ENABLE_XBOX const char* Environment::NewLine = "\r\n"; #else + const char* Environment::NewLine = "\n"; #endif OperatingSystem Environment::OSVersion() diff --git a/src/libmscorlib/Thread.cpp b/src/libmscorlib/Thread.cpp index e5053c5..afc5ef7 100644 --- a/src/libmscorlib/Thread.cpp +++ b/src/libmscorlib/Thread.cpp @@ -31,21 +31,21 @@ namespace System { namespace Threading { - ULONG Thread::Id = 0; - + ULONG Thread::GlobalId = 0; + void Thread::Thread_init() { - PsCreateSystemThreadEx(&system_thread_handle, //Thread Handle - 0, //KernelStackSize - stack_size, //Stack Size - 0, //TlsDataSize - &Id, //Thread ID - NULL, //StartContext1 - NULL, //StartContext2 - TRUE, //CreateSuspended - FALSE, //DebugStack - (PKSTART_ROUTINE)&callback); //StartRoutine - + PsCreateSystemThreadEx(&system_thread_handle, // Thread Handle + 0, // KernelStackSize + stack_size, // Stack Size + 0, // TlsDataSize + &Id, // Thread ID + NULL, // StartContext1 + NULL, // StartContext2 + TRUE, // CreateSuspended + FALSE, // DebugStack + (PKSTART_ROUTINE)&callback); // StartRoutine + ObReferenceObjectByHandle(system_thread_handle, (POBJECT_TYPE)PsThreadObjectType, &system_thread_handle); //#define LOW_PRIORITY 0 @@ -54,10 +54,10 @@ namespace System //#define MAXIMUM_PRIORITY 32 KeSetBasePriorityThread((PKTHREAD)system_thread_handle, (PVOID)0); //Default the thread to low priority - + state = ThreadState::Unstarted; - - Id++; //increment Id so every thread Id is unique + + Id = GlobalId++; //increment Id so every thread Id is unique } void Thread::Abort() @@ -76,8 +76,10 @@ namespace System Thread::Thread(PKSTART_ROUTINE callBack, int stackSize) { if(stackSize < 131072) + { stack_size = 65536; //Default stack size is 65536, which should be enough, unless there is need for a > 128k stack. - + } + stack_size = stackSize; callback = callBack; Thread_init(); @@ -91,17 +93,21 @@ namespace System void Thread::SetPriority(int priority) { - if((priority != 0) && (priority != 16) && (priority != 31) && (priority != 32)) + if ((priority != 0) && (priority != 16) && (priority != 31) && (priority != 32)) + { return; //no valid values - + } + ObReferenceObjectByHandle(system_thread_handle, (POBJECT_TYPE)PsThreadObjectType, &system_thread_handle); KeSetBasePriorityThread((PKTHREAD)system_thread_handle, (PVOID)priority); } void Thread::Sleep(int millisecondsTimeout) { - if(millisecondsTimeout <= 0) + if (millisecondsTimeout <= 0) + { return; //no reason to sleep. We could also throw an ArgumentOutOfRangeException, but what's the point in that? + } LARGE_INTEGER pli; @@ -113,7 +119,9 @@ namespace System void Thread::Sleep(TimeSpan timeout) { if(timeout == TimeSpan::Zero) + { return; //! no reason to sleep + } LARGE_INTEGER pli; diff --git a/src/libmscorlib/libmscorlib.vcxproj b/src/libmscorlib/libmscorlib.vcxproj index 8997c6c..7793d5d 100644 --- a/src/libmscorlib/libmscorlib.vcxproj +++ b/src/libmscorlib/libmscorlib.vcxproj @@ -44,7 +44,7 @@ make clean 2>&1 | sed -e %27s/\(\w\+\):\([0-9]\+\):/\1(\2):/%27 libmscorlib.a ENABLE_XBOX; DEBUG;$(NMakePreprocessorDefinitions) - C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include\SDL;..\..\include;$(NMakeIncludeSearchPath) + C:\devKitPro\msys\local\openxdk\include;C:\devKitPro\msys\local\openxdk\i386-pc-xbox\include;C:\devKitPro\msys\local\openxdk\include\SDL;$(SolutionDir)include;$(NMakeIncludeSearchPath) $(NMakeForcedIncludes) $(NMakeAssemblySearchPath) $(NMakeForcedUsingAssemblies) @@ -55,7 +55,7 @@ - C:\cygwin\usr\include;C:\cygwin\usr\local\openxdk\i386-pc-xbox\include;C:\cygwin\usr\local\openxdk\include;C:\cygwin\usr\local\openxdk\include\SDL;$(SolutionDir)include + C:\devKitPro\msys\include;C:\devKitPro\msys\local\openxdk\i386-pc-xbox\include;C:\devKitPro\msys\local\openxdk\include;C:\devKitPro\msys\local\openxdk\include\SDL;$(SolutionDir)include diff --git a/src/libmscorlib/makefile b/src/libmscorlib/makefile index f6c6579..b516c4e 100644 --- a/src/libmscorlib/makefile +++ b/src/libmscorlib/makefile @@ -26,7 +26,7 @@ LD_FLAGS = $(CLINK) $(ALIGN) $(SHARED) $(ENTRYPOINT) $(STRIP) LD_DIRS = -L$(PREFIX)/i386-pc-xbox/lib -L$(PREFIX)/lib LD_LIBS = $(LD_DIRS) -lm -lopenxdk -lhal -lc -lusb -lc -lxboxkrnl -lc -lhal -lxboxkrnl -lhal -lopenxdk -lc -lgcc -lstdc++ -OBJS = BinaryReader.o BinaryWriter.o BitConverter.o Boolean.o Byte.o Calendar.o Comparer.o Console.o DateTime.o DaylightTime.o Directory.o DirectoryInfo.o Double.o Environment.o EventArgs.o File.o FileStream.o FrameworkResources.o Int32.o Int64.o Math.o Object.o OperatingSystem.o Path.o sassert.o SByte.o Single.o Stream.o StreamAsyncResult.o StreamReader.o StreamWriter.o String.o StringBuilder.o Thread.o TimeSpan.o UInt16.o UInt32.o UInt64.o Version.o +OBJS = BinaryReader.o BinaryWriter.o BitConverter.o Boolean.o Byte.o Calendar.o Comparer.o Console.o DateTime.o DaylightTime.o Directory.o DirectoryInfo.o Double.o Environment.o EventArgs.o File.o FileStream.o FrameworkResources.o Int32.o Int64.o Math.o Object.o OperatingSystem.o Path.o sassert.o SByte.o Single.o Stream.o StreamAsyncResult.o StreamReader.o StreamWriter.o String.o StringBuilder.o Thread.o TimeSpan.o Type.o UInt16.o UInt32.o UInt64.o Version.o all: libmscorlib.a diff --git a/src/libmscorlib/sassert.c b/src/libmscorlib/sassert.c index 5a3b757..bbb1156 100644 --- a/src/libmscorlib/sassert.c +++ b/src/libmscorlib/sassert.c @@ -6,9 +6,9 @@ void __sassert(const char *fileName, int lineNumber, const char* conditionString, const char* message) { debugClearScreen(); - debugPrint("\tAssertion!\n\tFile: \n%s\n\nLine: %d\n\nCondition:\n%s\n\n\t%s", fileName, lineNumber, conditionString, message); + debugPrint("\tAssertion!\n\tFile: \n%s\n\nLine: %d\n\nCondition:\n%s\n\n\t%s", fileName, lineNumber, conditionString, message); XSleep(100); - __asm__ ("cli\nhlt"); + __asm__ ("cli\nhlt"); } diff --git a/src/makefile b/src/makefile index 2643d9a..4bdd8e1 100644 --- a/src/makefile +++ b/src/makefile @@ -3,7 +3,7 @@ # ######################################################################### PREFIX = /usr/local/openxdk -XFX_PREFIX = /cygdrive/j/XFX +XFX_PREFIX = /usr/local/XFX CC = gcc CCAS = gcc