:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[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_PREVIOUS_MODE     0x137
30 #define KTHREAD_TRAP_FRAME        0x128
31 #define KTHREAD_CALLBACK_STACK    0x120
32
33 #define ETHREAD_THREADS_PROCESS   0x234
34
35 #define KPROCESS_DIRECTORY_TABLE_BASE 0x18
36
37 #define KPCR_BASE                 0xFF000000
38
39 #define KPCR_EXCEPTION_LIST       0x0
40 #define KPCR_SELF                 0x18
41 #define KPCR_TSS                  0x28
42 #define KPCR_CURRENT_THREAD       0x124 
43
44 #ifndef __ASM__
45
46 /*
47  * Processor Control Region
48  */
49 typedef struct _KPCR
50 {
51   PVOID ExceptionList;               /* 00 */
52   PVOID StackBase;                   /* 04 */
53   PVOID StackLimit;                  /* 08 */
54   PVOID SubSystemTib;                /* 0C */
55   PVOID Reserved1;                   /* 10 */
56   PVOID ArbitraryUserPointer;        /* 14 */
57   struct _KPCR* Self;                /* 18 */
58   UCHAR ProcessorNumber;             /* 1C */
59   KIRQL Irql;                        /* 1D */
60   UCHAR Reserved2[0x2];              /* 1E */
61   PUSHORT IDT;                       /* 20 */
62   PUSHORT GDT;                       /* 24 */
63   KTSS* TSS;                         /* 28 */
64   UCHAR Reserved3[0xF8];             /* 2C */
65   struct _KTHREAD* CurrentThread;    /* 124 */
66 } __attribute__((packed)) KPCR, *PKPCR;
67
68 static inline PKPCR KeGetCurrentKPCR(VOID)
69 {
70   ULONG value;
71
72   __asm__ __volatile__ ("movl %%fs:0x18, %0\n\t"
73           : "=r" (value)
74     : /* no inputs */
75     );
76   return((PKPCR)value);
77 }
78
79 VOID
80 Ki386ContextSwitch(struct _KTHREAD* NewThread, 
81                    struct _KTHREAD* OldThread);
82 NTSTATUS 
83 Ke386InitThread(struct _KTHREAD* Thread, PKSTART_ROUTINE fn, 
84                 PVOID StartContext);
85 NTSTATUS 
86 Ke386InitThreadWithContext(struct _KTHREAD* Thread, PCONTEXT Context);
87 NTSTATUS
88 Ki386ValidateUserContext(PCONTEXT Context);
89
90 #endif /* __ASM__ */
91
92 #endif /* __NTOSKRNL_INCLUDE_INTERNAL_I386_PS_H */
93
94 /* EOF */