update for HEAD-2003091401
[reactos.git] / ntoskrnl / include / internal / i386 / ps.h
1 /*
2  *  ReactOS kernel
3  *  Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19 #ifndef __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H
20 #define __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H
21
22 /*
23  * Defines for accessing KPCR and KTHREAD structure members
24  */
25 #define KTHREAD_INITIAL_STACK     0x18
26 #define KTHREAD_STACK_LIMIT       0x1C
27 #define KTHREAD_TEB               0x20
28 #define KTHREAD_KERNEL_STACK      0x28
29 #define KTHREAD_SERVICE_TABLE     0xDC
30 #define KTHREAD_PREVIOUS_MODE     0x137
31 #define KTHREAD_TRAP_FRAME        0x128
32 #define KTHREAD_CALLBACK_STACK    0x120
33
34 #define ETHREAD_THREADS_PROCESS   0x234
35
36 #define KPROCESS_DIRECTORY_TABLE_BASE 0x18
37 #define KPROCESS_LDT_DESCRIPTOR0      0x20
38 #define KPROCESS_LDT_DESCRIPTOR1      0x24
39 #define KPROCESS_IOPM_OFFSET          0x30
40
41 #define KPCR_BASE                 0xFF000000
42
43 #define KPCR_EXCEPTION_LIST       0x0
44 #define KPCR_SELF                 0x18
45 #define KPCR_TSS                  0x3C
46 #define KPCR_CURRENT_THREAD       0x124 
47
48 #ifndef __ASM__
49
50 #ifndef __USE_W32API
51
52 #pragma pack(push,4)
53
54 /*
55  * Processor Control Region Thread Information Block
56  */
57 typedef struct _KPCR_TIB {
58   PVOID  ExceptionList;         /* 00 */
59   PVOID  StackBase;             /* 04 */
60   PVOID  StackLimit;            /* 08 */
61   PVOID  SubSystemTib;          /* 0C */
62   union {
63     PVOID  FiberData;           /* 10 */
64     DWORD  Version;             /* 10 */
65   };
66   PVOID  ArbitraryUserPointer;  /* 14 */
67 } KPCR_TIB, *PKPCR_TIB; /* 18 */
68
69 typedef struct _KPCR {
70   KPCR_TIB  Tib;                /* 00 */
71   struct _KPCR  *Self;          /* 18 */
72   struct _KPRCB  *PCRCB;        /* 1C */
73   KIRQL  Irql;                  /* 20 */
74   ULONG  IRR;                   /* 24 */
75   ULONG  IrrActive;             /* 28 */
76   ULONG  IDR;                   /* 2C */
77   PVOID  KdVersionBlock;        /* 30 */
78   PUSHORT  IDT;                 /* 34 */
79   PUSHORT  GDT;                 /* 38 */
80   struct _KTSS  *TSS;           /* 3C */
81   USHORT  MajorVersion;         /* 40 */
82   USHORT  MinorVersion;         /* 42 */
83   KAFFINITY  SetMember;         /* 44 */
84   ULONG  StallScaleFactor;      /* 48 */
85   UCHAR  DebugActive;           /* 4C */
86   UCHAR  ProcessorNumber;       /* 4D */
87   UCHAR  Reserved[2];           /* 4E */
88 } KPCR;
89
90 #pragma pack(pop)
91
92 typedef struct _KPCR *PKPCR;
93
94 #endif /* __USE_W32API */
95
96 #pragma pack(push,4)
97
98 /*
99  * Processor Control Region
100  * The first part of this structure must match the KPCR structure in w32api
101  */
102 typedef struct _IKPCR {
103   KPCR_TIB  Tib;                /* 00 */
104   struct _KPCR  *Self;          /* 18 */
105   struct _KPRCB  *PCRCB;        /* 1C */
106   KIRQL  Irql;                  /* 20 */
107   ULONG  IRR;                   /* 24 */
108   ULONG  IrrActive;             /* 28 */
109   ULONG  IDR;                   /* 2C */
110   PVOID  KdVersionBlock;        /* 30 */
111   PUSHORT  IDT;                 /* 34 */
112   PUSHORT  GDT;                 /* 38 */
113   struct _KTSS  *TSS;           /* 3C */
114   USHORT  MajorVersion;         /* 40 */
115   USHORT  MinorVersion;         /* 42 */
116   KAFFINITY  SetMember;         /* 44 */
117   ULONG  StallScaleFactor;      /* 48 */
118   UCHAR  DebugActive;           /* 4C */
119   UCHAR  ProcessorNumber;       /* 4D */
120   UCHAR  Reserved[2];           /* 4E */
121   UCHAR  Reserved2[0xD4];       /* 50 */
122   struct _KTHREAD* CurrentThread; /* 124 */
123 } IKPCR, *PIKPCR;
124
125 #pragma pack(pop)
126
127 #ifndef __USE_W32API
128
129 static inline PKPCR KeGetCurrentKPCR(VOID)
130 {
131   ULONG value;
132
133   __asm__ __volatile__ ("movl %%fs:0x18, %0\n\t"
134           : "=r" (value)
135     : /* no inputs */
136     );
137   return((PKPCR)value);
138 }
139
140 #endif /* __USE_W32API */
141
142 VOID
143 Ki386ContextSwitch(struct _KTHREAD* NewThread, 
144                    struct _KTHREAD* OldThread);
145 NTSTATUS 
146 Ke386InitThread(struct _KTHREAD* Thread, PKSTART_ROUTINE fn, 
147                 PVOID StartContext);
148 NTSTATUS 
149 Ke386InitThreadWithContext(struct _KTHREAD* Thread, PCONTEXT Context);
150 NTSTATUS
151 Ki386ValidateUserContext(PCONTEXT Context);
152
153 #endif /* __ASM__ */
154
155 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H */
156
157 /* EOF */