ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

kdx86.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:         ReactOS Kernel
00003  * LICENSE:         GPL - See COPYING in the top level directory
00004  * FILE:            ntoskrnl/kd64/i386/kdx86.c
00005  * PURPOSE:         KD support routines for x86
00006  * PROGRAMMERS:     Alex Ionescu (alex.ionescu@reactos.org)
00007  *                  Stefan Ginsberg (stefan.ginsberg@reactos.org)
00008  */
00009 
00010 /* INCLUDES *****************************************************************/
00011 
00012 #include <ntoskrnl.h>
00013 #define NDEBUG
00014 #include <debug.h>
00015 
00016 /* FUNCTIONS *****************************************************************/
00017 
00018 VOID
00019 NTAPI
00020 KdpGetStateChange(IN PDBGKD_MANIPULATE_STATE64 State,
00021                   IN PCONTEXT Context)
00022 {
00023     PKPRCB Prcb;
00024     ULONG i;
00025 
00026     /* Check for success */
00027     if (NT_SUCCESS(State->u.Continue2.ContinueStatus))
00028     {
00029         /* Check if we're tracing */
00030         if (State->u.Continue2.ControlSet.TraceFlag)
00031         {
00032             /* Enable TF */
00033             Context->EFlags |= EFLAGS_TF;
00034         }
00035         else
00036         {
00037             /* Remove it */
00038             Context->EFlags &= ~EFLAGS_TF;
00039         }
00040 
00041         /* Loop all processors */
00042         for (i = 0; i < KeNumberProcessors; i++)
00043         {
00044             /* Get the PRCB and update DR7 and DR6 */
00045             Prcb = KiProcessorBlock[i];
00046             Prcb->ProcessorState.SpecialRegisters.KernelDr7 =
00047                 State->u.Continue2.ControlSet.Dr7;
00048             Prcb->ProcessorState.SpecialRegisters.KernelDr6 = 0;
00049         }
00050 
00051         /* Check if we have new symbol information */
00052         if (State->u.Continue2.ControlSet.CurrentSymbolStart != 1)
00053         {
00054             /* Update it */
00055             KdpCurrentSymbolStart =
00056                 State->u.Continue2.ControlSet.CurrentSymbolStart;
00057             KdpCurrentSymbolEnd= State->u.Continue2.ControlSet.CurrentSymbolEnd;
00058         }
00059     }
00060 }
00061 
00062 VOID
00063 NTAPI
00064 KdpSetContextState(IN PDBGKD_ANY_WAIT_STATE_CHANGE WaitStateChange,
00065                    IN PCONTEXT Context)
00066 {
00067     PKPRCB Prcb = KeGetCurrentPrcb();
00068 
00069     /* Copy i386 specific debug registers */
00070     WaitStateChange->ControlReport.Dr6 = Prcb->ProcessorState.SpecialRegisters.
00071                                          KernelDr6;
00072     WaitStateChange->ControlReport.Dr7 = Prcb->ProcessorState.SpecialRegisters.
00073                                          KernelDr7;
00074 
00075     /* Copy i386 specific segments */
00076     WaitStateChange->ControlReport.SegCs = (USHORT)Context->SegCs;
00077     WaitStateChange->ControlReport.SegDs = (USHORT)Context->SegDs;
00078     WaitStateChange->ControlReport.SegEs = (USHORT)Context->SegEs;
00079     WaitStateChange->ControlReport.SegFs = (USHORT)Context->SegFs;
00080 
00081     /* Copy EFlags */
00082     WaitStateChange->ControlReport.EFlags = Context->EFlags;
00083 
00084     /* Set Report Flags */
00085     WaitStateChange->ControlReport.ReportFlags = REPORT_INCLUDES_SEGS;
00086     if (WaitStateChange->ControlReport.SegCs == KGDT_R0_CODE)
00087     {
00088         WaitStateChange->ControlReport.ReportFlags |= REPORT_STANDARD_CS;
00089     }
00090 }
00091 
00092 NTSTATUS
00093 NTAPI
00094 KdpSysReadMsr(IN ULONG Msr,
00095               OUT PLARGE_INTEGER MsrValue)
00096 {
00097     /* Wrap this in SEH in case the MSR doesn't exist */
00098     //_SEH2_TRY
00099     {
00100         /* Read from the MSR */
00101         MsrValue->QuadPart = RDMSR(Msr);
00102     }
00103     //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00104     {
00105         /* Invalid MSR */
00106         //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
00107     }
00108     //_SEH2_END;
00109 
00110     /* Success */
00111     return STATUS_SUCCESS;
00112 }
00113 
00114 NTSTATUS
00115 NTAPI
00116 KdpSysWriteMsr(IN ULONG Msr,
00117                IN PLARGE_INTEGER MsrValue)
00118 {
00119     /* Wrap this in SEH in case the MSR doesn't exist */
00120     //_SEH2_TRY
00121     {
00122         /* Write to the MSR */
00123         WRMSR(Msr, MsrValue->QuadPart);
00124     }
00125     //_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
00126     {
00127         /* Invalid MSR */
00128         //_SEH2_YIELD(return STATUS_NO_SUCH_DEVICE);
00129     }
00130     //_SEH2_END;
00131 
00132     /* Success */
00133     return STATUS_SUCCESS;
00134 }
00135 
00136 NTSTATUS
00137 NTAPI
00138 KdpSysReadBusData(IN ULONG BusDataType,
00139                   IN ULONG BusNumber,
00140                   IN ULONG SlotNumber,
00141                   IN ULONG Offset,
00142                   IN PVOID Buffer,
00143                   IN ULONG Length,
00144                   OUT PULONG ActualLength)
00145 {
00146     /* Just forward to HAL */
00147     *ActualLength = HalGetBusDataByOffset(BusDataType,
00148                                           BusNumber,
00149                                           SlotNumber,
00150                                           Buffer,
00151                                           Offset,
00152                                           Length);
00153 
00154     /* Return status */
00155     return *ActualLength != 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
00156 }
00157 
00158 NTSTATUS
00159 NTAPI
00160 KdpSysWriteBusData(IN ULONG BusDataType,
00161                    IN ULONG BusNumber,
00162                    IN ULONG SlotNumber,
00163                    IN ULONG Offset,
00164                    IN PVOID Buffer,
00165                    IN ULONG Length,
00166                    OUT PULONG ActualLength)
00167 {
00168     /* Just forward to HAL */
00169     *ActualLength = HalSetBusDataByOffset(BusDataType,
00170                                           BusNumber,
00171                                           SlotNumber,
00172                                           Buffer,
00173                                           Offset,
00174                                           Length);
00175 
00176     /* Return status */
00177     return *ActualLength != 0 ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
00178 }
00179 
00180 NTSTATUS
00181 NTAPI
00182 KdpSysReadControlSpace(IN ULONG Processor,
00183                        IN ULONG64 BaseAddress,
00184                        IN PVOID Buffer,
00185                        IN ULONG Length,
00186                        OUT PULONG ActualLength)
00187 {
00188     PVOID ControlStart;
00189     ULONG RealLength;
00190 
00191     /* Make sure that this is a valid request */
00192     if ((BaseAddress < sizeof(KPROCESSOR_STATE)) &&
00193         (Processor < KeNumberProcessors))
00194     {
00195         /* Get the actual length */
00196         RealLength = sizeof(KPROCESSOR_STATE) - (ULONG_PTR)BaseAddress;
00197         if (RealLength < Length) Length = RealLength;
00198 
00199         /* Set the proper address */
00200         ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
00201                                (ULONG_PTR)&KiProcessorBlock[Processor]->
00202                                            ProcessorState);
00203 
00204         /* Read the control state safely */
00205         return KdpCopyMemoryChunks((ULONG_PTR)Buffer,
00206                                    ControlStart,
00207                                    Length,
00208                                    0,
00209                                    MMDBG_COPY_UNSAFE | MMDBG_COPY_WRITE,
00210                                    ActualLength);
00211     }
00212     else
00213     {
00214         /* Invalid request */
00215         *ActualLength = 0;
00216         return STATUS_UNSUCCESSFUL;
00217     }
00218 }
00219 
00220 NTSTATUS
00221 NTAPI
00222 KdpSysWriteControlSpace(IN ULONG Processor,
00223                         IN ULONG64 BaseAddress,
00224                         IN PVOID Buffer,
00225                         IN ULONG Length,
00226                         OUT PULONG ActualLength)
00227 {
00228     PVOID ControlStart;
00229 
00230     /* Make sure that this is a valid request */
00231     if (((BaseAddress + Length) <= sizeof(KPROCESSOR_STATE)) &&
00232         (Processor < KeNumberProcessors))
00233     {
00234         /* Set the proper address */
00235         ControlStart = (PVOID)((ULONG_PTR)BaseAddress +
00236                                (ULONG_PTR)&KiProcessorBlock[Processor]->
00237                                            ProcessorState);
00238 
00239         /* Write the control state safely */
00240         return KdpCopyMemoryChunks((ULONG_PTR)Buffer,
00241                                    ControlStart,
00242                                    Length,
00243                                    0,
00244                                    MMDBG_COPY_UNSAFE,
00245                                    ActualLength);
00246     }
00247     else
00248     {
00249         /* Invalid request */
00250         *ActualLength = 0;
00251         return STATUS_UNSUCCESSFUL;
00252     }
00253 }
00254 
00255 NTSTATUS
00256 NTAPI
00257 KdpSysReadIoSpace(IN ULONG InterfaceType,
00258                   IN ULONG BusNumber,
00259                   IN ULONG AddressSpace,
00260                   IN ULONG64 IoAddress,
00261                   IN PVOID DataValue,
00262                   IN ULONG DataSize,
00263                   OUT PULONG ActualDataSize)
00264 {
00265     NTSTATUS Status;
00266 
00267     /* Verify parameters */
00268     if ((InterfaceType != Isa) ||
00269         (BusNumber != 0) ||
00270         (AddressSpace != 1))
00271     {
00272         /* Fail, we don't support this */
00273         *ActualDataSize = 0;
00274         return STATUS_UNSUCCESSFUL;
00275     }
00276 
00277     /* Check the size */
00278     switch (DataSize)
00279     {
00280         case sizeof(UCHAR):
00281 
00282             /* Read 1 byte */
00283             *(PUCHAR)DataValue =
00284                 READ_PORT_UCHAR((PUCHAR)(ULONG_PTR)IoAddress);
00285             *ActualDataSize = sizeof(UCHAR);
00286             Status = STATUS_SUCCESS;
00287             break;
00288 
00289         case sizeof(USHORT):
00290 
00291             /* Make sure the address is aligned */
00292             if ((IoAddress & (sizeof(USHORT) - 1)) != 0)
00293             {
00294                 /* It isn't, bail out */
00295                 *ActualDataSize = 0;
00296                 Status = STATUS_DATATYPE_MISALIGNMENT;
00297                 break;
00298             }
00299 
00300             /* Read 2 bytes */
00301             *(PUSHORT)DataValue =
00302                 READ_PORT_USHORT((PUSHORT)(ULONG_PTR)IoAddress);
00303             *ActualDataSize = sizeof(USHORT);
00304             Status = STATUS_SUCCESS;
00305             break;
00306 
00307         case sizeof(ULONG):
00308 
00309             /* Make sure the address is aligned */
00310             if ((IoAddress & (sizeof(ULONG) - 1)) != 0)
00311             {
00312                 /* It isn't, bail out */
00313                 *ActualDataSize = 0;
00314                 Status = STATUS_DATATYPE_MISALIGNMENT;
00315                 break;
00316             }
00317 
00318             /* Read 4 bytes */
00319             *(PULONG)DataValue =
00320                 READ_PORT_ULONG((PULONG)(ULONG_PTR)IoAddress);
00321             *ActualDataSize = sizeof(ULONG);
00322             Status = STATUS_SUCCESS;
00323             break;
00324 
00325         default:
00326 
00327             /* Invalid size, fail */
00328             *ActualDataSize = 0;
00329             Status = STATUS_INVALID_PARAMETER;
00330     }
00331 
00332     /* Return status */
00333     return Status;
00334 }
00335 
00336 NTSTATUS
00337 NTAPI
00338 KdpSysWriteIoSpace(IN ULONG InterfaceType,
00339                    IN ULONG BusNumber,
00340                    IN ULONG AddressSpace,
00341                    IN ULONG64 IoAddress,
00342                    IN PVOID DataValue,
00343                    IN ULONG DataSize,
00344                    OUT PULONG ActualDataSize)
00345 {
00346     NTSTATUS Status;
00347 
00348     /* Verify parameters */
00349     if ((InterfaceType != Isa) ||
00350         (BusNumber != 0) ||
00351         (AddressSpace != 1))
00352     {
00353         /* Fail, we don't support this */
00354         *ActualDataSize = 0;
00355         return STATUS_UNSUCCESSFUL;
00356     }
00357 
00358     /* Check the size */
00359     switch (DataSize)
00360     {
00361         case sizeof(UCHAR):
00362 
00363             /* Write 1 byte */
00364             WRITE_PORT_UCHAR((PUCHAR)(ULONG_PTR)IoAddress,
00365                              *(PUCHAR)DataValue);
00366             *ActualDataSize = sizeof(UCHAR);
00367             Status = STATUS_SUCCESS;
00368             break;
00369 
00370         case sizeof(USHORT):
00371 
00372             /* Make sure the address is aligned */
00373             if ((IoAddress & (sizeof(USHORT) - 1)) != 0)
00374             {
00375                 /* It isn't, bail out */
00376                 *ActualDataSize = 0;
00377                 Status = STATUS_DATATYPE_MISALIGNMENT;
00378                 break;
00379             }
00380 
00381             /* Write 2 bytes */
00382             WRITE_PORT_USHORT((PUSHORT)(ULONG_PTR)IoAddress,
00383                              *(PUSHORT)DataValue);
00384             *ActualDataSize = sizeof(USHORT);
00385             Status = STATUS_SUCCESS;
00386             break;
00387 
00388         case sizeof(ULONG):
00389 
00390             /* Make sure the address is aligned */
00391             if ((IoAddress & (sizeof(ULONG) - 1)) != 0)
00392             {
00393                 /* It isn't, bail out */
00394                 *ActualDataSize = 0;
00395                 Status = STATUS_DATATYPE_MISALIGNMENT;
00396                 break;
00397             }
00398 
00399             /* Write 4 bytes */
00400             WRITE_PORT_ULONG((PULONG)(ULONG_PTR)IoAddress,
00401                              *(PULONG)DataValue);
00402             *ActualDataSize = sizeof(ULONG);
00403             Status = STATUS_SUCCESS;
00404             break;
00405 
00406         default:
00407 
00408             /* Invalid size, fail */
00409             *ActualDataSize = 0;
00410             Status = STATUS_INVALID_PARAMETER;
00411     }
00412 
00413     /* Return status */
00414     return Status;
00415 }
00416 
00417 NTSTATUS
00418 NTAPI
00419 KdpSysCheckLowMemory(IN ULONG Flags)
00420 {
00421     /* Stubbed as we don't support PAE */
00422     return STATUS_UNSUCCESSFUL;
00423 }
00424 
00425 NTSTATUS
00426 NTAPI
00427 KdpAllowDisable(VOID)
00428 {
00429     LONG i;
00430     ULONG Dr7;
00431 
00432     /* Loop every processor */
00433     for (i = 0; i < KeNumberProcessors; i++)
00434     {
00435         /* Get its DR7 */
00436         Dr7 =  KiProcessorBlock[i]->ProcessorState.SpecialRegisters.KernelDr7;
00437 
00438         /* Check if any processor breakpoints are active */
00439         if (Dr7 != 0)
00440         {
00441             /* We can't allow running without a debugger then */
00442             return STATUS_ACCESS_DENIED;
00443         }
00444     }
00445 
00446     /* No processor breakpoints; allow disabling the debugger */
00447     return STATUS_SUCCESS;
00448 }

Generated on Sat May 26 2012 04:36:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.