Author: ros-arm-bringup Date: Tue Mar 11 11:13:43 2008 New Revision: 32659
URL: http://svn.reactos.org/svn/reactos?rev=3D32659&view=3Drev Log: - Convert all Loader Block structures to virtual addresses (By adding KSEG0= _BASE) since the kernel eventually unmaps the page table responsible for th= e physical->virtual identity mapping, but we'll still need to access the lo= ader block. - Implement proper trap prolog/epilog code -- currently used and tested in = the data abort handler. Currently hacked away some KTRAP_FRAME stuff on ARM. - The data abort handler has a very rudimentary check to detect page faults= and will call MmAccessFaults, this means we now support paged pool! - We now succesfully go past MmInitSystem and go all the way until ObInitSy= stem (still in Phase 0).
Modified: trunk/reactos/boot/freeldr/freeldr/arch/arm/loader.c trunk/reactos/include/ndk/arm/ketypes.h trunk/reactos/ntoskrnl/include/internal/arm/intrin_i.h trunk/reactos/ntoskrnl/include/internal/arm/ksarm.h trunk/reactos/ntoskrnl/ke/arm/trap.s trunk/reactos/ntoskrnl/ke/arm/trapc.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/arm/loader.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/= arch/arm/loader.c?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/boot/freeldr/freeldr/arch/arm/loader.c (original) +++ trunk/reactos/boot/freeldr/freeldr/arch/arm/loader.c Tue Mar 11 11:13:4= 3 2008 @@ -30,6 +30,7 @@ CHAR ArmArcHalPath[64]; CHAR ArmNtHalPath[64]; CHAR ArmNtBootPath[64]; +WCHAR ArmModuleName[64]; PNLS_DATA_BLOCK ArmNlsDataBlock; PLOADER_PARAMETER_EXTENSION ArmExtension; BIOS_MEMORY_DESCRIPTOR ArmBoardMemoryDescriptors[16] =3D {{0}}; @@ -1042,7 +1043,7 @@ // // Jump to Kernel // - (*KernelEntryPoint)(Magic, (PVOID)ArmLoaderBlock); + (*KernelEntryPoint)(Magic, (PVOID)((ULONG_PTR)ArmLoaderBlock | KSEG0_B= ASE)); } =
VOID @@ -1054,6 +1055,7 @@ NTSTATUS Status; ULONG Dummy, i; PLDR_DATA_TABLE_ENTRY LdrEntry; + PLIST_ENTRY NextEntry, OldEntry; =
// // Allocate the ARM Shared Heap @@ -1080,7 +1082,7 @@ // // Setup the extension and setup block // - ArmLoaderBlock->Extension =3D ArmExtension; + ArmLoaderBlock->Extension =3D (PVOID)((ULONG_PTR)ArmExtension | KSEG0_= BASE); ArmLoaderBlock->SetupLdrBlock =3D NULL; =
// @@ -1223,6 +1225,7 @@ // // Setup loader entry for the kernel // + wcscpy(ArmModuleName, L"ntoskrnl.exe"); LdrEntry =3D ArmAllocateFromSharedHeap(sizeof(LDR_DATA_TABLE_ENTRY)); RtlZeroMemory(LdrEntry, sizeof(LDR_DATA_TABLE_ENTRY)); LdrEntry->DllBase =3D (PVOID)KernelBase; @@ -1230,6 +1233,10 @@ LdrEntry->EntryPoint =3D KernelEntryPoint; LdrEntry->LoadCount =3D 1; LdrEntry->Flags =3D LDRP_IMAGE_DLL | LDRP_ENTRY_PROCESSED; + RtlInitUnicodeString(&LdrEntry->FullDllName, ArmModuleName); + RtlInitUnicodeString(&LdrEntry->BaseDllName, ArmModuleName); + LdrEntry->FullDllName.Buffer =3D (PVOID)((ULONG_PTR)LdrEntry->FullDllN= ame.Buffer | KSEG0_BASE); + LdrEntry->BaseDllName.Buffer =3D (PVOID)((ULONG_PTR)LdrEntry->BaseDllN= ame.Buffer | KSEG0_BASE); InsertTailList(&ArmLoaderBlock->LoadOrderListHead, &LdrEntry->InLoadOr= derLinks); =
// @@ -1253,6 +1260,36 @@ if (Status !=3D STATUS_SUCCESS) return; } =
+ =
+ // + // Loop driver list + // =
+ NextEntry =3D ArmLoaderBlock->LoadOrderListHead.Flink; + while (NextEntry !=3D &ArmLoaderBlock->LoadOrderListHead) + { + // + // Remember the physical entry + // + OldEntry =3D NextEntry->Flink; + =
+ // + // Edit the data + // + NextEntry->Flink =3D (PVOID)((ULONG_PTR)NextEntry->Flink | KSEG0_B= ASE); + NextEntry->Blink =3D (PVOID)((ULONG_PTR)NextEntry->Blink | KSEG0_B= ASE); + =
+ // + // Keep looping + // + NextEntry =3D OldEntry; + } + + // + // Now edit the root itself + // + NextEntry->Flink =3D (PVOID)((ULONG_PTR)NextEntry->Flink | KSEG0_BASE); + NextEntry->Blink =3D (PVOID)((ULONG_PTR)NextEntry->Blink | KSEG0_BASE); + =
// // Setup extension parameters // @@ -1276,7 +1313,7 @@ // Set the ARC Boot Path // strncpy(ArmArcBootPath, ArmCommandLine, 63); - ArmLoaderBlock->ArcBootDeviceName =3D ArmArcBootPath; + ArmLoaderBlock->ArcBootDeviceName =3D (PVOID)((ULONG_PTR)ArmArcBootPat= h | KSEG0_BASE); =
// // The rest of the string is the NT path @@ -1286,22 +1323,31 @@ ArmNtBootPath[0] =3D '\'; strncat(ArmNtBootPath, BootPath + 1, 63); strcat(ArmNtBootPath,"\"); - ArmLoaderBlock->NtBootPathName =3D ArmNtBootPath; + ArmLoaderBlock->NtBootPathName =3D (PVOID)((ULONG_PTR)ArmNtBootPath | = KSEG0_BASE); =
// // Set the HAL paths // strncpy(ArmArcHalPath, ArmArcBootPath, 63); - ArmLoaderBlock->ArcHalDeviceName =3D ArmArcHalPath; + ArmLoaderBlock->ArcHalDeviceName =3D (PVOID)((ULONG_PTR)ArmArcHalPath = | KSEG0_BASE); strcpy(ArmNtHalPath, "\"); - ArmLoaderBlock->NtHalPathName =3D ArmNtHalPath; - =
- /* Use this new command line */ + ArmLoaderBlock->NtHalPathName =3D (PVOID)((ULONG_PTR)ArmNtHalPath | KS= EG0_BASE); + =
+ // + // Use this new command line + // strncpy(ArmLoaderBlock->LoadOptions, HalPath + 2, 255); =
- /* Parse it and change every slash to a space */ + // + // Parse it and change every slash to a space + // BootPath =3D ArmLoaderBlock->LoadOptions; do {if (*BootPath =3D=3D '/') *BootPath =3D ' ';} while (*BootPath++); + + // + // Fixup command-line pointer + // + ArmLoaderBlock->LoadOptions =3D (PVOID)((ULONG_PTR)ArmLoaderBlock->Loa= dOptions | KSEG0_BASE); =
// // Setup cache information @@ -1412,6 +1458,35 @@ ArmLoaderBlock->Prcb =3D KSEG0_BASE | (ULONG)Base; ArmLoaderBlock->Process =3D ArmLoaderBlock->Prcb + sizeof(KPRCB); ArmLoaderBlock->Thread =3D ArmLoaderBlock->Process + sizeof(EPROCESS); + =
+ // + // Loop memory list + // =
+ NextEntry =3D ArmLoaderBlock->MemoryDescriptorListHead.Flink; + while (NextEntry !=3D &ArmLoaderBlock->MemoryDescriptorListHead) + { + // + // Remember the physical entry + // + OldEntry =3D NextEntry->Flink; + =
+ // + // Edit the data + // + NextEntry->Flink =3D (PVOID)((ULONG_PTR)NextEntry->Flink | KSEG0_B= ASE); + NextEntry->Blink =3D (PVOID)((ULONG_PTR)NextEntry->Blink | KSEG0_B= ASE); + =
+ // + // Keep looping + // + NextEntry =3D OldEntry; + } + =
+ // + // Now edit the root itself + // + NextEntry->Flink =3D (PVOID)((ULONG_PTR)NextEntry->Flink | KSEG0_BASE); + NextEntry->Blink =3D (PVOID)((ULONG_PTR)NextEntry->Blink | KSEG0_BASE); } =
VOID
Modified: trunk/reactos/include/ndk/arm/ketypes.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/arm/ketyp= es.h?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/include/ndk/arm/ketypes.h (original) +++ trunk/reactos/include/ndk/arm/ketypes.h Tue Mar 11 11:13:43 2008 @@ -59,6 +59,7 @@ // typedef struct _KTRAP_FRAME { + ULONG Spsr; ULONG R0; ULONG R1; ULONG R2; @@ -72,17 +73,17 @@ ULONG R10; ULONG R11; ULONG R12; - ULONG Sp; - ULONG Lr; + ULONG UserSp; + ULONG UserLr; + ULONG SvcSp; + ULONG SvcLr; ULONG Pc; - ULONG Psr; =
- UCHAR ExceptionRecord[(sizeof(EXCEPTION_RECORD) + 7) & (~7)]; - UCHAR OldIrql; - UCHAR PreviousMode; - ULONG Fpscr; - ULONG FpExc; - ULONG S[33]; - ULONG FpExtra[8]; +// UCHAR OldIrql; +// UCHAR PreviousMode; +// ULONG Fpscr; +// ULONG FpExc; +// ULONG S[33]; +// ULONG FpExtra[8]; } KTRAP_FRAME, *PKTRAP_FRAME; =
#ifndef NTOS_MODE_USER
Modified: trunk/reactos/ntoskrnl/include/internal/arm/intrin_i.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/inte= rnal/arm/intrin_i.h?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/ntoskrnl/include/internal/arm/intrin_i.h (original) +++ trunk/reactos/ntoskrnl/include/internal/arm/intrin_i.h Tue Mar 11 11:13= :43 2008 @@ -26,6 +26,24 @@ { ARM_ID_CODE_REGISTER Value; __asm__ __volatile__ ("mrc p15, 0, %0, c0, c0, 0" : "=3Dr"(Value.AsUlo= ng) : : "cc"); + return Value; +} + +FORCEINLINE +ULONG +KeArmFaultStatusRegisterGet(VOID) +{ + ULONG Value; + __asm__ __volatile__ ("mrc p15, 0, %0, c5, c0, 0" : "=3Dr"(Value) : : = "cc"); + return Value; +} + +FORCEINLINE +ULONG +KeArmFaultAddressRegisterGet(VOID) +{ + ULONG Value; + __asm__ __volatile__ ("mrc p15, 0, %0, c6, c0, 0" : "=3Dr"(Value) : : = "cc"); return Value; } =
Modified: trunk/reactos/ntoskrnl/include/internal/arm/ksarm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/inte= rnal/arm/ksarm.h?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/ntoskrnl/include/internal/arm/ksarm.h (original) +++ trunk/reactos/ntoskrnl/include/internal/arm/ksarm.h Tue Mar 11 11:13:43= 2008 @@ -9,6 +9,7 @@ .equ CPSR_SVC_MODE, 0x13 .equ CPSR_ABORT_MODE, 0x17 .equ CPSR_UND_MODE, 0x1B +.equ CPSR_MODES, 0x1F =
=
/*
Modified: trunk/reactos/ntoskrnl/ke/arm/trap.s URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/arm/trap.= s?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/ntoskrnl/ke/arm/trap.s (original) +++ trunk/reactos/ntoskrnl/ke/arm/trap.s Tue Mar 11 11:13:43 2008 @@ -62,32 +62,107 @@ =
NESTED_ENTRY KiDataAbortException PROLOG_END KiDataAbortException - - // - // Save space for trap frame - // - sub sp, #TrapFrameLength =
// - // Build the register part of the trap frame + // Fixup lr // - stm sp, {r0-r15} + sub lr, lr, #8 + =
+ // + // Save the bottom 4 registers + // + stmdb sp, {r0-r3} + =
+ // + // Save the abort lr, sp, spsr, cpsr + // + mov r0, lr + mov r1, sp + mrs r2, cpsr + mrs r3, spsr + =
+ // + // Switch to SVC mode + // + bic r2, r2, #CPSR_MODES + orr r2, r2, #CPSR_SVC_MODE + msr cpsr_c, r2 + =
+ // + // Save the SVC sp before we modify it + // + mov r2, sp + =
+ // + // Save the abort lr + // + str r0, [sp, #-4]! + =
+ // + // Save the SVC lr and sp + // + str lr, [sp, #-4]! + str r2, [sp, #-4]! + =
+ // + // Restore the saved SPSR + // + msr spsr_all, r3 + =
+ // + // Restore our 4 registers + // + ldmdb r1, {r0-r3} + =
+ // + // Make space for the trap frame + // + sub sp, sp, #(4*15) // TrapFrameLength + =
+ // + // Save user-mode registers + // + stmia sp, {r0-r12} + add r0, sp, #(4*13) + stmia r0, {r13-r14}^ + =
+ // + // Save SPSR + // + mrs r0, spsr_all + str r0, [sp, #-4]! =
- // - // TOOD: We'll worry about the rest later... - // - =
// // Call the C handler // - mov a1, sp - b KiDataAbortHandler + adr lr, AbortExit + mov r0, sp + ldr pc, =3DKiDataAbortHandler + +AbortExit: =
// - // Restore state + // Get the SPSR and restore it // + ldr r0, [sp], #4 + msr spsr_all, r0 + =
+ // + // Restore the registers + // + ldmia sp, {r0-r14}^ + mov r0, r0 + =
+ // + // Advance in the trap frame + // + add sp, sp, #(4*15) + =
+ // + // Restore program execution state + // + ldmia sp, {sp, lr, pc}^ b . - =
ENTRY_END KiDataAbortException =
NESTED_ENTRY KiInterruptException
Modified: trunk/reactos/ntoskrnl/ke/arm/trapc.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/arm/trapc= .c?rev=3D32659&r1=3D32658&r2=3D32659&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- trunk/reactos/ntoskrnl/ke/arm/trapc.c (original) +++ trunk/reactos/ntoskrnl/ke/arm/trapc.c Tue Mar 11 11:13:43 2008 @@ -19,7 +19,23 @@ NTSTATUS KiDataAbortHandler(IN PKTRAP_FRAME TrapFrame) { - DPRINT1("Data Abort (%p) @ %p\n", TrapFrame, TrapFrame->Lr - 8); + NTSTATUS Status; + PVOID Address =3D (PVOID)KeArmFaultAddressRegisterGet(); + DPRINT1("Data Abort (%x) @ %p %p\n", Address, TrapFrame->SvcLr, TrapFr= ame->Pc); + DPRINT1("Abort Reason: %d\n", KeArmFaultStatusRegisterGet()); + =
+ // + // Check if this is a page fault + // + if (KeArmFaultStatusRegisterGet() =3D=3D 21) + { + Status =3D MmAccessFault(FALSE, + Address, + KernelMode, + TrapFrame); + DPRINT1("Status: %x\n", Status); + if (Status =3D=3D STATUS_SUCCESS) return Status; + } =
while (TRUE); return STATUS_SUCCESS;