4 * arch/i386/include/arch.h
10 #define KERNEL_BASE 0xC0000000
13 // - Processor/Machine Specific Features
14 #if ARCH != i386 && ARCH != i486 && ARCH != i586
15 # error "Unknown architecture '" #ARCH "'"
30 #define __ASM__ __asm__ __volatile__
34 * \brief Short Spinlock structure
36 struct sShortSpinlock {
37 volatile int Lock; //!< Lock value
38 int IF; //!< Interrupt state on call to SHORTLOCK
41 * \brief Determine if a short spinlock is locked
42 * \param Lock Lock pointer
44 static inline int IS_LOCKED(struct sShortSpinlock *Lock) {
48 * \brief Acquire a Short Spinlock
49 * \param Lock Lock pointer
51 * This type of mutex should only be used for very short sections of code,
52 * or in places where a Mutex_* would be overkill, such as appending
53 * an element to linked list (usually two assignement lines in C)
55 * \note This type of lock halts interrupts, so ensure that no timing
56 * functions are called while it is held.
58 static inline void SHORTLOCK(struct sShortSpinlock *Lock) {
61 // Save interrupt state
62 __ASM__ ("pushf;\n\tpop %%eax" : "=a"(Lock->IF));
68 // Wait for another CPU to release
70 __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
73 * \brief Release a short lock
74 * \param Lock Lock pointer
76 static inline void SHORTREL(struct sShortSpinlock *Lock) {
78 #if 0 // Which is faster?, meh the test is simpler
79 __ASM__ ("pushf;\n\tor %0, (%%esp);\n\tpopf" : : "a"(Lock->IF));
81 if(Lock->IF) __ASM__ ("sti");
89 #define HALT() __asm__ __volatile__ ("hlt")
91 * \brief Fire a magic breakpoint (bochs)
93 #define MAGIC_BREAK() __asm__ __volatile__ ("xchg %bx, %bx")
96 typedef unsigned int Uint; // Unsigned machine native integer
97 typedef unsigned char Uint8;
98 typedef unsigned short Uint16;
99 typedef unsigned long Uint32;
100 typedef unsigned long long Uint64;
101 typedef signed int Sint; // Signed Machine Native integer
102 typedef signed char Sint8;
103 typedef signed short Sint16;
104 typedef signed long Sint32;
105 typedef signed long long Sint64;
108 typedef Uint64 tPAddr;
109 typedef Uint32 tVAddr;
113 Uint edi, esi, ebp, kesp;
114 Uint ebx, edx, ecx, eax;
115 Uint int_num, err_code;
117 Uint eflags, esp, ss;
121 Uint Resvd1[4]; // GS, FS, ES, DS
122 Uint Arg4, Arg5; // EDI, ESI
124 Uint Resvd2[1]; // Kernel ESP
131 Uint RetHi; // High 32 bits of ret
138 Uint Resvd3[5]; // Int, Err, Eip, CS, ...
139 Uint StackPointer; // ESP
140 Uint Resvd4[1]; // SS
155 #endif // !defined(_ARCH_H_)