ReactOS  0.4.14-dev-991-g696cdc6
pfault.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: ntoskrnl/mm/powerpc/pfault.c
5  * PURPOSE: Paging file functions
6  *
7  * PROGRAMMERS: David Welch (welch@mcmail.com)
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 #include <ppcmmu/mmu.h>
16 
17 /* EXTERNS *******************************************************************/
18 
20 NTAPI
23  BOOLEAN FromMdl);
24 extern ULONG KiKernelTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2);
25 
26 /* FUNCTIONS *****************************************************************/
27 
29 {
30  RtlCopyMemory(&Tf->Gpr0, frame->gpr, 12 * sizeof(ULONG));
31  Tf->Lr = frame->lr;
32  Tf->Cr = frame->cr;
33  Tf->Ctr = frame->ctr;
34  Tf->Xer = frame->xer;
35  Tf->Iar = frame->srr0;
36  Tf->Msr = frame->srr1 & 0xffff;
37  Tf->Dr0 = frame->dar;
38  Tf->Dr1 = frame->dsisr;
39 }
40 
41 void CopyFrame(int *oldframe, int *ourframe)
42 {
43  int i;
44 
45  for (i = 0; i < sizeof(ppc_trap_frame_t) / sizeof(int); i++)
46  {
47  ourframe[i] = GetPhys((int)&oldframe[i]);
48  }
49 }
50 
51 void KiPageFaultHandler(int trap, ppc_trap_frame_t *frame)
52 {
56  KTRAP_FRAME Tf;
57  BOOLEAN AccessFault = !!(frame->dsisr & (1<<28));
58  vaddr_t VirtualAddr;
59  PVOID TrapInfo = NULL;
60 
61  /* get the faulting address */
62  if (trap == 4) /* Instruction miss */
63  VirtualAddr = frame->srr0;
64  else /* Data miss */
65  VirtualAddr = frame->dar;
66 
67  /* MSR_PR */
68  Mode = frame->srr1 & 0x4000 ? UserMode : KernelMode;
69  DPRINT("Page Fault at %08x\n", frame->srr0);
70 
71  /* handle the fault */
72  if (AccessFault)
73  {
74  Status = MmAccessFault(Mode, (PVOID)VirtualAddr, FALSE, TrapInfo);
75  }
76  else
77  {
78  Status = MmNotPresentFault(Mode, VirtualAddr, FALSE);
79  }
80 
81  if (NT_SUCCESS(Status))
82  {
84  }
85 
86  if (KeGetCurrentThread()->ApcState.UserApcPending)
87  {
88  KIRQL oldIrql;
89 
90  KeRaiseIrql(APC_LEVEL, &oldIrql);
92  KeLowerIrql(oldIrql);
93  }
94 
95  MmpPpcTrapFrameToTrapFrame(frame, &Tf);
96 
98  Er.ExceptionFlags = 0;
99  Er.ExceptionRecord = NULL;
100  Er.ExceptionAddress = (PVOID)frame->srr0;
101  Er.NumberParameters = 2;
102  Er.ExceptionInformation[0] = AccessFault;
103  Er.ExceptionInformation[1] = VirtualAddr;
104 
105  /* FIXME: Which exceptions are noncontinuable? */
106  Er.ExceptionFlags = 0;
107 
108  KiDispatchException(&Er, 0, &Tf, Mode, TRUE);
109  MmuCallbackRet();
110 }
111 
unsigned long cr
Definition: mmu.h:115
ULONG Cr
Definition: ketypes.h:130
NTSTATUS NTAPI MmNotPresentFault(KPROCESSOR_MODE Mode, ULONG_PTR Address, BOOLEAN FromMdl)
Definition: mmfault.c:110
static void MmuCallbackRet()
Definition: mmu.h:257
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
_In_ ULONG Mode
Definition: hubbusif.h:303
NTSTATUS NTAPI MmAccessFault(IN ULONG FaultCode, IN PVOID Address, IN KPROCESSOR_MODE Mode, IN PVOID TrapInformation)
Definition: mmfault.c:204
void KiPageFaultHandler(int trap, ppc_trap_frame_t *frame)
Definition: pfault.c:51
ULONG Msr
Definition: ketypes.h:132
LONG NTSTATUS
Definition: precomp.h:26
unsigned long srr1
Definition: mmu.h:115
ULONG KiKernelTrapHandler(PKTRAP_FRAME Tf, ULONG ExceptionNr, PVOID Cr2)
ULONG Lr
Definition: ketypes.h:365
PVOID ExceptionAddress
Definition: compat.h:199
uint32_t ULONG_PTR
Definition: typedefs.h:64
DWORD ExceptionCode
Definition: compat.h:196
UCHAR KIRQL
Definition: env_spec_w32.h:591
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned long dsisr
Definition: mmu.h:115
VOID NTAPI KiDispatchException(PEXCEPTION_RECORD ExceptionRecord, PKEXCEPTION_FRAME ExceptionFrame, PKTRAP_FRAME Tf, KPROCESSOR_MODE PreviousMode, BOOLEAN SearchFrames)
unsigned long vaddr_t
Definition: mmu.h:90
struct _ppc_trap_frame_t ppc_trap_frame_t
VOID MmpPpcTrapFrameToTrapFrame(ppc_trap_frame_t *frame, PKTRAP_FRAME Tf)
Definition: pfault.c:28
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
void DPRINT(...)
Definition: polytest.cpp:61
ULONG Gpr0
Definition: ketypes.h:102
void * PVOID
Definition: retypes.h:9
unsigned long dar
Definition: mmu.h:115
unsigned long srr0
Definition: mmu.h:115
unsigned long xer
Definition: mmu.h:115
ULONG Xer
Definition: ketypes.h:131
ULONG_PTR ExceptionInformation[EXCEPTION_MAXIMUM_PARAMETERS]
Definition: compat.h:201
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
unsigned long lr
Definition: mmu.h:115
ULONG GetPhys(ULONG Addr)
CCHAR KPROCESSOR_MODE
Definition: ketypes.h:7
ULONG Ctr
Definition: ketypes.h:135
UINT64 Dr1
Definition: ketypes.h:343
unsigned long ctr
Definition: mmu.h:115
UINT64 Dr0
Definition: ketypes.h:342
Status
Definition: gdiplustypes.h:24
struct _EXCEPTION_RECORD * ExceptionRecord
Definition: compat.h:198
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
unsigned long gpr[32]
Definition: mmu.h:113
_Out_ PKAPC_STATE ApcState
Definition: mm.h:1492
void CopyFrame(int *oldframe, int *ourframe)
Definition: pfault.c:41
unsigned int ULONG
Definition: retypes.h:1
DWORD ExceptionFlags
Definition: compat.h:197
ULONG Iar
Definition: ketypes.h:133
DWORD NumberParameters
Definition: compat.h:200
#define KeGetCurrentThread
Definition: hal.h:44
return STATUS_SUCCESS
Definition: btrfs.c:2938
VOID NTAPI KiDeliverApc(IN KPROCESSOR_MODE DeliveryMode, IN PKEXCEPTION_FRAME ExceptionFrame, IN PKTRAP_FRAME TrapFrame)
Definition: apc.c:302
#define APC_LEVEL
Definition: env_spec_w32.h:695