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
7 * PROGRAMMERS: David Welch (welch@mcmail.com)
10 /* INCLUDES *****************************************************************/
15 #include <ppcmmu/mmu.h>
17 /* EXTERNS *******************************************************************/
21 MmNotPresentFault(KPROCESSOR_MODE Mode
,
24 extern ULONG
KiKernelTrapHandler(PKTRAP_FRAME Tf
, ULONG ExceptionNr
, PVOID Cr2
);
26 /* FUNCTIONS *****************************************************************/
28 VOID
MmpPpcTrapFrameToTrapFrame(ppc_trap_frame_t
*frame
, PKTRAP_FRAME Tf
)
30 RtlCopyMemory(&Tf
->Gpr0
, frame
->gpr
, 12 * sizeof(ULONG
));
35 Tf
->Iar
= frame
->srr0
;
36 Tf
->Msr
= frame
->srr1
& 0xffff;
38 Tf
->Dr1
= frame
->dsisr
;
41 void CopyFrame(int *oldframe
, int *ourframe
)
45 for (i
= 0; i
< sizeof(ppc_trap_frame_t
) / sizeof(int); i
++)
47 ourframe
[i
] = GetPhys((int)&oldframe
[i
]);
51 void KiPageFaultHandler(int trap
, ppc_trap_frame_t
*frame
)
53 NTSTATUS Status
= STATUS_SUCCESS
;
57 BOOLEAN AccessFault
= !!(frame
->dsisr
& (1<<28));
59 PVOID TrapInfo
= NULL
;
61 /* get the faulting address */
62 if (trap
== 4) /* Instruction miss */
63 VirtualAddr
= frame
->srr0
;
65 VirtualAddr
= frame
->dar
;
68 Mode
= frame
->srr1
& 0x4000 ? UserMode
: KernelMode
;
69 DPRINT("Page Fault at %08x\n", frame
->srr0
);
71 /* handle the fault */
74 Status
= MmAccessFault(Mode
, (PVOID
)VirtualAddr
, FALSE
, TrapInfo
);
78 Status
= MmNotPresentFault(Mode
, VirtualAddr
, FALSE
);
81 if (NT_SUCCESS(Status
))
86 if (KeGetCurrentThread()->ApcState
.UserApcPending
)
90 KeRaiseIrql(APC_LEVEL
, &oldIrql
);
91 KiDeliverApc(UserMode
, NULL
, NULL
);
95 MmpPpcTrapFrameToTrapFrame(frame
, &Tf
);
97 Er
.ExceptionCode
= STATUS_ACCESS_VIOLATION
;
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
;
105 /* FIXME: Which exceptions are noncontinuable? */
106 Er
.ExceptionFlags
= 0;
108 KiDispatchException(&Er
, 0, &Tf
, Mode
, TRUE
);