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 // int cpu = GetCPUNum() + 1;
63 // Save interrupt state and clear interrupts
64 __ASM__ ("pushf;\n\tcli;\n\tpop %%eax" : "=a"(IF));
67 // Wait for another CPU to release
69 __ASM__("xchgl %%eax, (%%edi)":"=a"(v):"a"(1),"D"(&Lock->Lock));
74 * \brief Release a short lock
75 * \param Lock Lock pointer
77 static inline void SHORTREL(struct sShortSpinlock *Lock) {
78 // Lock->IF can change anytime once Lock->Lock is zeroed
92 #define HALT() __asm__ __volatile__ ("hlt")
94 * \brief Fire a magic breakpoint (bochs)
96 #define MAGIC_BREAK() __asm__ __volatile__ ("xchg %bx, %bx")
99 typedef unsigned int Uint; // Unsigned machine native integer
100 typedef unsigned char Uint8;
101 typedef unsigned short Uint16;
102 typedef unsigned long Uint32;
103 typedef unsigned long long Uint64;
104 typedef signed int Sint; // Signed Machine Native integer
105 typedef signed char Sint8;
106 typedef signed short Sint16;
107 typedef signed long Sint32;
108 typedef signed long long Sint64;
111 typedef Uint64 tPAddr;
112 typedef Uint32 tVAddr;
116 Uint edi, esi, ebp, kesp;
117 Uint ebx, edx, ecx, eax;
118 Uint int_num, err_code;
120 Uint eflags, esp, ss;
124 Uint Resvd1[4]; // GS, FS, ES, DS
125 Uint Arg4, Arg5; // EDI, ESI
127 Uint Resvd2[1]; // Kernel ESP
134 Uint RetHi; // High 32 bits of ret
141 Uint Resvd3[5]; // Int, Err, Eip, CS, ...
142 Uint StackPointer; // ESP
143 Uint Resvd4[1]; // SS
158 #endif // !defined(_ARCH_H_)