Kernel/x86 - Added owner field to SHORTLOCK to catch doublelocks
[tpg/acess2.git] / KernelLand / Kernel / arch / x86 / include / arch.h
1 /*
2  * Acess2
3  * - x86 Architecture
4  * arch/x86/include/arch.h
5  */
6 #ifndef _ARCH_H_
7 #define _ARCH_H_
8
9 // - Base Defintions
10 #define KERNEL_BASE     0xC0000000
11 #define BITS    32
12 #define PAGE_SIZE       0x1000
13
14 #define INVLPTR ((void*)-1)
15
16 // Allow nested spinlocks?
17 #define LOCK_DISABLE_INTS       1
18
19 // - Processor/Machine Specific Features
20 #if ARCH != x86 && ARCH != x86_smp
21 # error "Unknown architecture '" #ARCH "'"
22 #endif
23
24 #if USE_MP
25 # define        MAX_CPUS        8
26 #else
27 # define        MAX_CPUS        1
28 #endif
29
30 #if USE_PAE
31 # define        PHYS_BITS       48
32 #else
33 # define        PHYS_BITS       32
34 #endif
35
36 #define __ASM__ __asm__ __volatile__
37
38 // === Spinlocks ===
39 /**
40  * \brief Short Spinlock structure
41  */
42 struct sShortSpinlock {
43         volatile int    Lock;   //!< Lock value
44         
45         #if LOCK_DISABLE_INTS
46          int    IF;     //!< Interrupt state on call to SHORTLOCK
47         #endif
48         void    *LockedBy;
49 };
50
51 // === MACROS ===
52 /**
53  * \brief Halt the CPU (shorter version of yield)
54  */
55 #if 1
56 #define HALT()  do { \
57         Uint32  flags; \
58         __asm__ __volatile__ ("pushf;pop %0" : "=a"(flags)); \
59         if( !(flags & 0x200) )  Panic("HALT called with interrupts disabled"); \
60         __asm__ __volatile__ ("hlt"); \
61 } while(0)
62 #else
63 #define HALT()  __asm__ __volatile__ ("hlt")
64 #endif
65 /**
66  * \brief Fire a magic breakpoint (bochs)
67  */
68 #define MAGIC_BREAK()   __asm__ __volatile__ ("xchg %bx, %bx")
69
70 // === TYPES ===
71 typedef unsigned int    Uint;   // Unsigned machine native integer
72 typedef unsigned char   Uint8;
73 typedef unsigned short  Uint16;
74 typedef unsigned long   Uint32;
75 typedef unsigned long long      Uint64;
76 typedef signed int              Sint;   // Signed Machine Native integer
77 typedef signed char             Sint8;
78 typedef signed short    Sint16;
79 typedef signed long             Sint32;
80 typedef signed long long        Sint64;
81 typedef Uint    size_t;
82 typedef char    BOOL;
83
84 typedef Uint32  tPAddr;
85 typedef Uint32  tVAddr;
86
87 typedef struct {
88         Uint32  gs, fs, es, ds;
89         Uint32  edi, esi, ebp, kesp;
90         Uint32  ebx, edx, ecx, eax;
91         Uint32  int_num, err_code;
92         Uint32  eip, cs;
93         Uint32  eflags, esp, ss;
94 } tRegs;
95
96 typedef struct {
97         Uint    Resvd1[4];      // GS, FS, ES, DS
98         Uint    Arg4, Arg5;     // EDI, ESI
99         Uint    Arg6;   // EBP
100         Uint    Resvd2[1];      // Kernel ESP
101         union {
102                 Uint    Arg1;
103                 Uint    Error;
104         };      // EBX
105         union {
106                 Uint    Arg3;
107                 Uint    RetHi;  // High 32 bits of ret
108         };      // EDX
109         Uint    Arg2;   // ECX
110         union {
111                 Uint    Num;
112                 Uint    Return;
113         };      // EAX
114         Uint    Resvd3[5];      // Int, Err, Eip, CS, ...
115         Uint    StackPointer;   // ESP
116         Uint    Resvd4[1];      // SS
117 } tSyscallRegs;
118
119 // === FUNCTIONS ===
120 extern void     Debug_PutCharDebug(char ch);
121 extern void     Debug_PutStringDebug(const char *String);
122
123 extern int      IS_LOCKED(struct sShortSpinlock *Lock);
124 extern int      CPU_HAS_LOCK(struct sShortSpinlock *Lock);
125 extern void     SHORTLOCK(struct sShortSpinlock *Lock);
126 extern void     SHORTREL(struct sShortSpinlock *Lock);
127
128 #endif  // !defined(_ARCH_H_)

UCC git Repository :: git.ucc.asn.au