00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#ifndef _MIPSH_
00022
#define _MIPSH_
00023
00024
00025
00026
#if defined(_MIPS_)
00027
00028
00029
00030
00031
00032
#define FLUSH_MULTIPLE_MAXIMUM 16
00033
00034
00035
00036
00037
00038
#define ALLOC_PRAGMA 1
00039
00040
00041
00042
00043
00044
00045
00046
00047
#if (defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_) || defined(_NTHAL_)) && !defined (_BLDR_)
00048
00049
#define NTKERNELAPI DECLSPEC_IMPORT // wdm
00050
00051
#else
00052
00053
#define NTKERNELAPI
00054
00055
#endif
00056
00057
00058
00059
00060
00061
00062
#if !defined(_NTHAL_) && !defined(_BLDR_)
00063
00064
#define NTHALAPI DECLSPEC_IMPORT // wdm
00065
00066
#else
00067
00068
#define NTHALAPI
00069
00070
#endif
00071
00072
00073
00074
00075
00076
00077
#define IMPORT_NAME(name) __imp_##name
00078
00079
00080
00081
00082
00083
#define RESULT_ZERO 0
00084
#define RESULT_NEGATIVE -2
00085
#define RESULT_POSITIVE -1
00086
00087
00088
00089
00090
00091
00092
typedef enum _INTERLOCKED_RESULT {
00093 ResultNegative = RESULT_NEGATIVE,
00094 ResultZero = RESULT_ZERO,
00095 ResultPositive = RESULT_POSITIVE
00096 } INTERLOCKED_RESULT;
00097
00098
00099
00100
00101
00102
#define ExInterlockedIncrementLong(Addend, Lock) \
00103
ExMipsInterlockedIncrementLong(Addend)
00104
00105
#define ExInterlockedDecrementLong(Addend, Lock) \
00106
ExMipsInterlockedDecrementLong(Addend)
00107
00108
#define ExInterlockedExchangeAddLargeInteger(Target, Value, Lock) \
00109
ExpInterlockedExchangeAddLargeInteger(Target, Value)
00110
00111
#define ExInterlockedExchangeUlong(Target, Value, Lock) \
00112
ExMipsInterlockedExchangeUlong(Target, Value)
00113
00114
NTKERNELAPI
00115 INTERLOCKED_RESULT
00116 ExMipsInterlockedIncrementLong (
00117 IN PLONG Addend
00118 );
00119
00120
NTKERNELAPI
00121 INTERLOCKED_RESULT
00122 ExMipsInterlockedDecrementLong (
00123 IN PLONG Addend
00124 );
00125
00126
NTKERNELAPI
00127 LARGE_INTEGER
00128 ExpInterlockedExchangeAddLargeInteger (
00129 IN PLARGE_INTEGER Addend,
00130 IN LARGE_INTEGER Increment
00131 );
00132
00133
NTKERNELAPI
00134 ULONG
00135 ExMipsInterlockedExchangeUlong (
00136 IN PULONG Target,
00137 IN ULONG Value
00138 );
00139
00140
00141
00142
00143
00144
00145
00146
#if defined(_M_MRX000) && !defined(RC_INVOKED)
00147
00148
#define InterlockedIncrement _InterlockedIncrement
00149
#define InterlockedDecrement _InterlockedDecrement
00150
#define InterlockedExchange _InterlockedExchange
00151
#define InterlockedExchangeAdd _InterlockedExchangeAdd
00152
#define InterlockedCompareExchange _InterlockedCompareExchange
00153
00154 LONG
00155 InterlockedIncrement(
00156 IN OUT PLONG Addend
00157 );
00158
00159 LONG
00160 InterlockedDecrement(
00161 IN OUT PLONG Addend
00162 );
00163
00164 LONG
00165 InterlockedExchange(
00166 IN OUT PLONG Target,
00167 IN LONG Increment
00168 );
00169
00170 LONG
00171 InterlockedExchangeAdd(
00172 IN OUT PLONG Addend,
00173 IN LONG Value
00174 );
00175
00176 PVOID
00177 InterlockedCompareExchange (
00178 IN OUT PVOID *Destination,
00179 IN PVOID Exchange,
00180 IN PVOID Comperand
00181 );
00182
00183
#pragma intrinsic(_InterlockedIncrement)
00184
#pragma intrinsic(_InterlockedDecrement)
00185
#pragma intrinsic(_InterlockedExchange)
00186
#pragma intrinsic(_InterlockedExchangeAdd)
00187
#pragma intrinsic(_InterlockedCompareExchange)
00188
00189
#if _MSC_VER >= 1100
00190
00191
#define InterlockedCompareExchange64 _InterlockedCompareExchange64
00192
00193 ULONGLONG
00194 InterlockedCompareExchange64 (
00195 IN PULONGLONG Destination,
00196 IN PULONGLONG Exchange,
00197 IN PULONGLONG Comperand
00198 );
00199
00200
#pragma intrinsic(_InterlockedCompareExchange64)
00201
00202
#else
00203
00204
#define InterlockedCompareExchange64 ExpInterlockedCompareExchange64
00205
00206
NTKERNELAPI
00207 ULONGLONG
00208 ExpInterlockedCompareExchange64 (
00209 IN PULONGLONG Destination,
00210 IN PULONGLONG Exchange,
00211 IN PULONGLONG Comperand
00212 );
00213
00214
#endif
00215
00216
#endif
00217
00218
00219
00220
00221
00222
00223
00224
#define DISPATCH_LENGTH 4 // Length of dispatch code in instructions
00225
00226
00227
00228
00229
00230
#define PASSIVE_LEVEL 0 // Passive release level
00231
#define LOW_LEVEL 0 // Lowest interrupt level
00232
#define APC_LEVEL 1 // APC interrupt level
00233
#define DISPATCH_LEVEL 2 // Dispatcher level
00234
#define IPI_LEVEL 7 // Interprocessor interrupt level
00235
#define POWER_LEVEL 7 // Power failure level
00236
#define PROFILE_LEVEL 8 // Profiling level
00237
#define HIGH_LEVEL 8 // Highest interrupt level
00238
#define SYNCH_LEVEL (IPI_LEVEL - 1) // synchronization level
00239
00240
00241
00242
00243
00244
#define DEFAULT_PROFILE_COUNT 0x40000000 // ~= 20 seconds @50mhz
00245
#define DEFAULT_PROFILE_INTERVAL (10 * 500) // 500 microseconds
00246
#define MAXIMUM_PROFILE_INTERVAL (10 * 1000 * 1000) // 1 second
00247
#define MINIMUM_PROFILE_INTERVAL (10 * 40) // 40 microseconds
00248
00249
00250
00251
#define KiProfileIrql PROFILE_LEVEL // enable portable code
00252
00253
00254
00255
00256
00257
extern ULONG KiInterruptTemplate[];
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
#define SANITIZE_FSR(fsr, mode) ( \
00270
((mode) == KernelMode ? \
00271
((0x00000000L) | ((fsr) & 0xffffffff)) : \
00272
((0x00000000L) | ((fsr) & 0xfffc0fff))))
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
#define SANITIZE_PSR(psr, mode) ( \
00289
((mode) == KernelMode ? \
00290
((0xa0000082L) | ((psr) & 0xd000ff33)) : \
00291
((0xa00000b3L) | (PCR->IrqlTable[PASSIVE_LEVEL] << 8))))
00292
00293
00294
00295
00296
00297
00298
#define KIPCR 0xfffff000 // kernel address of first PCR
00299
#define KIPCR2 0xffffe000 // kernel address of second PCR
00300
00301
00302
00303
00304
00305
#define PCR ((volatile KPCR * const)KIPCR)
00306
#define SharedUserData ((KUSER_SHARED_DATA * const)KIPCR2)
00307
00308
00309
00310
00311
00312
#define KeGetCurrentIrql() PCR->CurrentIrql
00313
00314
00315
00316
00317
00318
#define KeGetCurrentPrcb() PCR->Prcb
00319
00320
00321
00322
00323
00324
#define KeGetPcr() PCR
00325
00326
00327
00328
00329
00330
#define KeGetCurrentThread() PCR->CurrentThread
00331
00332
00333
00334
00335
00336
00337
00338
#define KeGetCurrentProcessorNumber() PCR->Number
00339
00340
00341
00342
00343
00344
00345
#define KeGetDcacheFillSize() PCR->DcacheFillSize
00346
00347
00348
00349
00350
00351
00352
00353
#define KeGetPreviousMode() (KPROCESSOR_MODE)PCR->CurrentThread->PreviousMode
00354
00355
00356
00357
00358
00359
#define KeIsExecutingDpc() (PCR->DpcRoutineActive != 0)
00360
00361
00362
00363
00364
00365
00366
#define KeSaveFloatingPointState(a) STATUS_SUCCESS
00367
#define KeRestoreFloatingPointState(a) STATUS_SUCCESS
00368
00369
00370
00371
00372
00373
00374
00375
NTKERNELAPI
00376
VOID
00377 KeFillEntryTb (
00378 IN HARDWARE_PTE Pte[2],
00379 IN PVOID Virtual,
00380 IN BOOLEAN Invalid
00381 );
00382
00383
NTKERNELAPI
00384
VOID
00385 KeFillLargeEntryTb (
00386 IN HARDWARE_PTE Pte[2],
00387 IN PVOID Virtual,
00388 IN ULONG PageSize
00389 );
00390
00391
00392
00393
00394
00395
NTKERNELAPI
00396
VOID
00397 KeFillFixedEntryTb (
00398 IN HARDWARE_PTE Pte[2],
00399 IN PVOID Virtual,
00400 IN ULONG Index
00401 );
00402
00403
00404
00405
00406
00407
00408
NTKERNELAPI
00409
VOID
00410
KeChangeColorPage (
00411 IN PVOID NewColor,
00412 IN PVOID OldColor,
00413 IN ULONG PageFrame
00414 );
00415
00416
NTKERNELAPI
00417
VOID
00418
KeSweepDcache (
00419 IN BOOLEAN AllProcessors
00420 );
00421
00422
#define KeSweepCurrentDcache() \
00423
HalSweepDcache();
00424
00425
NTKERNELAPI
00426
VOID
00427
KeSweepIcache (
00428 IN BOOLEAN AllProcessors
00429 );
00430
00431
#define KeSweepCurrentIcache() \
00432
HalSweepIcache(); \
00433
HalSweepDcache();
00434
00435
NTKERNELAPI
00436
VOID
00437
KeSweepIcacheRange (
00438 IN BOOLEAN AllProcessors,
00439 IN PVOID BaseAddress,
00440 IN ULONG Length
00441 );
00442
00443
00444
00445
00446
00447
00448
NTKERNELAPI
00449
VOID
00450
KeFlushIoBuffers (
00451 IN
PMDL Mdl,
00452 IN BOOLEAN ReadOperation,
00453 IN BOOLEAN DmaOperation
00454 );
00455
00456
00457
00458
00459
00460
00461
00462
struct _KEXCEPTION_FRAME;
00463
struct _KTRAP_FRAME;
00464
00465
NTKERNELAPI
00466
VOID
00467 KeIpiInterrupt (
00468 IN
struct _KTRAP_FRAME *TrapFrame
00469 );
00470
00471
NTKERNELAPI
00472
VOID
00473
KeProfileInterrupt (
00474 IN
struct _KTRAP_FRAME *TrapFrame
00475 );
00476
00477
NTKERNELAPI
00478
VOID
00479
KeProfileInterruptWithSource (
00480 IN
struct _KTRAP_FRAME *TrapFrame,
00481 IN KPROFILE_SOURCE ProfileSource
00482 );
00483
00484
NTKERNELAPI
00485
VOID
00486 KeUpdateRuntime (
00487 IN
struct _KTRAP_FRAME *TrapFrame
00488 );
00489
00490
NTKERNELAPI
00491
VOID
00492
KeUpdateSystemTime (
00493 IN
struct _KTRAP_FRAME *TrapFrame
00494 );
00495
00496
00497
00498
00499
00500
#if defined(NT_UP)
00501
00502
#define KiAcquireSpinLock(SpinLock)
00503
00504
#else
00505
00506
NTKERNELAPI
00507
VOID
00508 KiAcquireSpinLock (
00509 IN PKSPIN_LOCK SpinLock
00510 );
00511
00512
#endif
00513
00514
#if defined(NT_UP)
00515
00516
#define KiReleaseSpinLock(SpinLock)
00517
00518
#else
00519
00520
NTKERNELAPI
00521
VOID
00522 KiReleaseSpinLock (
00523 IN PKSPIN_LOCK SpinLock
00524 );
00525
00526
#endif
00527
00528
00529
00530
00531
00532
typedef
00533
VOID
00534 (*PKCACHE_ERROR_ROUTINE) (
00535
VOID
00536 );
00537
00538
#define CACHE_ERROR_VECTOR 0xa0000ffc // address of cache error routine
00539
00540
NTKERNELAPI
00541
VOID
00542
KeSetCacheErrorRoutine (
00543 IN PKCACHE_ERROR_ROUTINE Routine
00544 );
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
#if defined(NT_UP) && !defined(_NTDDK_) && !defined(_NTIFS_)
00559
#define ExAcquireSpinLock(Lock, OldIrql) \
00560
*(OldIrql) = KeRaiseIrqlToDpcLevel()
00561
00562
#define ExReleaseSpinLock(Lock, OldIrql) KeLowerIrql((OldIrql))
00563
#define ExAcquireSpinLockAtDpcLevel(Lock)
00564
#define ExReleaseSpinLockFromDpcLevel(Lock)
00565
#else
00566
00567
00568
00569
#define ExAcquireSpinLock(Lock, OldIrql) \
00570
*(OldIrql) = KeAcquireSpinLockRaiseToDpc((Lock))
00571
00572
#define ExReleaseSpinLock(Lock, OldIrql) KeReleaseSpinLock((Lock), (OldIrql))
00573
#define ExAcquireSpinLockAtDpcLevel(Lock) KeAcquireSpinLockAtDpcLevel(Lock)
00574
#define ExReleaseSpinLockFromDpcLevel(Lock) KeReleaseSpinLockFromDpcLevel(Lock)
00575
00576
00577
00578
#endif
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
#if defined(_M_MRX000)
00590
00591
VOID
00592 _disable (
00593 VOID
00594 );
00595
00596
VOID
00597 _enable (
00598 VOID
00599 );
00600
00601
#pragma intrinsic(_disable)
00602
#pragma intrinsic(_enable)
00603
00604
#endif
00605
00606
00607
00608
#if defined(NT_UP) && !DBG
00609
#define ExAcquireFastLock(Lock, OldIrql) _disable()
00610
#else
00611
#define ExAcquireFastLock(Lock, OldIrql) \
00612
ExAcquireSpinLock(Lock, OldIrql)
00613
#endif
00614
00615
#if defined(NT_UP) && !DBG
00616
#define ExReleaseFastLock(Lock, OldIrql) _enable()
00617
#else
00618
#define ExReleaseFastLock(Lock, OldIrql) \
00619
ExReleaseSpinLock(Lock, OldIrql)
00620
#endif
00621
00622
00623
00624
00625
00626 BOOLEAN
00627
KeBusError (
00628 IN PEXCEPTION_RECORD ExceptionRecord,
00629 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00630 IN
struct _KTRAP_FRAME *TrapFrame,
00631 IN PVOID VirtualAddress,
00632 IN PHYSICAL_ADDRESS PhysicalAddress
00633 );
00634
00635
VOID
00636
KiDataBusError (
00637 IN PEXCEPTION_RECORD ExceptionRecord,
00638 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00639 IN
struct _KTRAP_FRAME *TrapFrame
00640 );
00641
00642
VOID
00643
KiInstructionBusError (
00644 IN PEXCEPTION_RECORD ExceptionRecord,
00645 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00646 IN
struct _KTRAP_FRAME *TrapFrame
00647 );
00648
00649
00650
00651
00652
00653
00654
00655
00656
#define KiQuerySystemTime(CurrentTime) \
00657
(CurrentTime)->QuadPart = SharedUserData->SystemTime.Alignment
00658
00659
00660
00661
00662
00663
#if defined(_NTDRIVER_) || defined(_NTDDK_) || defined(_NTIFS_)
00664
00665
00666
00667
#define KeQueryTickCount(CurrentCount) { \
00668
PKSYSTEM_TIME _TickCount = *((PKSYSTEM_TIME *)(&KeTickCount)); \
00669
(CurrentCount)->QuadPart = _TickCount->Alignment; \
00670
}
00671
00672
00673
00674
#else
00675
00676
00677
#define KiQueryTickCount(CurrentCount) \
00678
(CurrentCount)->QuadPart = KeTickCount.Alignment
00679
00680
NTKERNELAPI
00681
VOID
00682
KeQueryTickCount (
00683 OUT PLARGE_INTEGER CurrentCount
00684 );
00685
00686
00687
#endif
00688
00689
#define KiQueryLowTickCount() KeTickCount.LowPart
00690
00691
00692
00693
00694
00695
#define KiQueryInterruptTime(CurrentTime) \
00696
(CurrentTime)->QuadPart = SharedUserData->InterruptTime.Alignment
00697
00698
00699
00700
00701
00702
00703 ULONG
00704
KiEmulateBranch (
00705 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00706 IN
struct _KTRAP_FRAME *TrapFrame
00707 );
00708
00709 BOOLEAN
00710
KiEmulateFloating (
00711 IN OUT PEXCEPTION_RECORD ExceptionRecord,
00712 IN OUT
struct _KEXCEPTION_FRAME *ExceptionFrame,
00713 IN OUT
struct _KTRAP_FRAME *TrapFrame
00714 );
00715
00716 BOOLEAN
00717
KiEmulateReference (
00718 IN OUT PEXCEPTION_RECORD ExceptionRecord,
00719 IN OUT
struct _KEXCEPTION_FRAME *ExceptionFrame,
00720 IN OUT
struct _KTRAP_FRAME *TrapFrame
00721 );
00722
00723 ULONG
00724
KiGetRegisterValue (
00725 IN ULONG Register,
00726 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00727 IN
struct _KTRAP_FRAME *TrapFrame
00728 );
00729
00730
VOID
00731
KiSetRegisterValue (
00732 IN ULONG Register,
00733 IN ULONG Value,
00734 OUT
struct _KEXCEPTION_FRAME *ExceptionFrame,
00735 OUT
struct _KTRAP_FRAME *TrapFrame
00736 );
00737
00738 ULONGLONG
00739
KiGetRegisterValue64 (
00740 IN ULONG Register,
00741 IN
struct _KEXCEPTION_FRAME *ExceptionFrame,
00742 IN
struct _KTRAP_FRAME *TrapFrame
00743 );
00744
00745
VOID
00746
KiSetRegisterValue64 (
00747 IN ULONG Register,
00748 IN ULONGLONG Value,
00749 OUT
struct _KEXCEPTION_FRAME *ExceptionFrame,
00750 OUT
struct _KTRAP_FRAME *TrapFrame
00751 );
00752
00753
NTKERNELAPI
00754
VOID
00755
KiRequestSoftwareInterrupt (
00756 ULONG RequestIrql
00757 );
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
#define ProbeForRead64(Address, Length, Alignment) \
00776
ASSERT(((Alignment) == 1) || ((Alignment) == 2) || \
00777
((Alignment) == 4) || ((Alignment) == 8)); \
00778
\
00779
if ((Length) != 0) { \
00780
if (((ULONGLONG)(Address) & ((Alignment) - 1)) != 0) { \
00781
ExRaiseDatatypeMisalignment(); \
00782
\
00783
} else if ((((ULONGLONG)(Address) + (Length)) < (ULONGLONG)(Address)) || \
00784
(((ULONGLONG)(Address) + (Length)) > (ULONGLONG)MM_HIGHEST_USER_ADDRESS64)) { \
00785
ExRaiseAccessViolation(); \
00786
} \
00787
}
00788
00789
00790
00791
00792
00793
NTKERNELAPI
00794
VOID
00795 ProbeForWrite64 (
00796 IN PVOID64 Address,
00797 IN ULONG Length,
00798 IN ULONG Alignment
00799 );
00800
00801
00802
00803
00804
00805
00806
#define READ_REGISTER_UCHAR(x) \
00807
*(volatile UCHAR * const)(x)
00808
00809
#define READ_REGISTER_USHORT(x) \
00810
*(volatile USHORT * const)(x)
00811
00812
#define READ_REGISTER_ULONG(x) \
00813
*(volatile ULONG * const)(x)
00814
00815
#define READ_REGISTER_BUFFER_UCHAR(x, y, z) { \
00816
PUCHAR registerBuffer = x; \
00817
PUCHAR readBuffer = y; \
00818
ULONG readCount; \
00819
for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
00820
*readBuffer = *(volatile UCHAR * const)(registerBuffer); \
00821
} \
00822
}
00823
00824
#define READ_REGISTER_BUFFER_USHORT(x, y, z) { \
00825
PUSHORT registerBuffer = x; \
00826
PUSHORT readBuffer = y; \
00827
ULONG readCount; \
00828
for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
00829
*readBuffer = *(volatile USHORT * const)(registerBuffer); \
00830
} \
00831
}
00832
00833
#define READ_REGISTER_BUFFER_ULONG(x, y, z) { \
00834
PULONG registerBuffer = x; \
00835
PULONG readBuffer = y; \
00836
ULONG readCount; \
00837
for (readCount = z; readCount--; readBuffer++, registerBuffer++) { \
00838
*readBuffer = *(volatile ULONG * const)(registerBuffer); \
00839
} \
00840
}
00841
00842
#define WRITE_REGISTER_UCHAR(x, y) { \
00843
*(volatile UCHAR * const)(x) = y; \
00844
KeFlushWriteBuffer(); \
00845
}
00846
00847
#define WRITE_REGISTER_USHORT(x, y) { \
00848
*(volatile USHORT * const)(x) = y; \
00849
KeFlushWriteBuffer(); \
00850
}
00851
00852
#define WRITE_REGISTER_ULONG(x, y) { \
00853
*(volatile ULONG * const)(x) = y; \
00854
KeFlushWriteBuffer(); \
00855
}
00856
00857
#define WRITE_REGISTER_BUFFER_UCHAR(x, y, z) { \
00858
PUCHAR registerBuffer = x; \
00859
PUCHAR writeBuffer = y; \
00860
ULONG writeCount; \
00861
for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
00862
*(volatile UCHAR * const)(registerBuffer) = *writeBuffer; \
00863
} \
00864
KeFlushWriteBuffer(); \
00865
}
00866
00867
#define WRITE_REGISTER_BUFFER_USHORT(x, y, z) { \
00868
PUSHORT registerBuffer = x; \
00869
PUSHORT writeBuffer = y; \
00870
ULONG writeCount; \
00871
for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
00872
*(volatile USHORT * const)(registerBuffer) = *writeBuffer; \
00873
} \
00874
KeFlushWriteBuffer(); \
00875
}
00876
00877
#define WRITE_REGISTER_BUFFER_ULONG(x, y, z) { \
00878
PULONG registerBuffer = x; \
00879
PULONG writeBuffer = y; \
00880
ULONG writeCount; \
00881
for (writeCount = z; writeCount--; writeBuffer++, registerBuffer++) { \
00882
*(volatile ULONG * const)(registerBuffer) = *writeBuffer; \
00883
} \
00884
KeFlushWriteBuffer(); \
00885
}
00886
00887
00888
#define READ_PORT_UCHAR(x) \
00889
*(volatile UCHAR * const)(x)
00890
00891
#define READ_PORT_USHORT(x) \
00892
*(volatile USHORT * const)(x)
00893
00894
#define READ_PORT_ULONG(x) \
00895
*(volatile ULONG * const)(x)
00896
00897
#define READ_PORT_BUFFER_UCHAR(x, y, z) { \
00898
PUCHAR readBuffer = y; \
00899
ULONG readCount; \
00900
for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
00901
*readBuffer = *(volatile UCHAR * const)(x); \
00902
} \
00903
}
00904
00905
#define READ_PORT_BUFFER_USHORT(x, y, z) { \
00906
PUSHORT readBuffer = y; \
00907
ULONG readCount; \
00908
for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
00909
*readBuffer = *(volatile USHORT * const)(x); \
00910
} \
00911
}
00912
00913
#define READ_PORT_BUFFER_ULONG(x, y, z) { \
00914
PULONG readBuffer = y; \
00915
ULONG readCount; \
00916
for (readCount = 0; readCount < z; readCount++, readBuffer++) { \
00917
*readBuffer = *(volatile ULONG * const)(x); \
00918
} \
00919
}
00920
00921
#define WRITE_PORT_UCHAR(x, y) { \
00922
*(volatile UCHAR * const)(x) = y; \
00923
KeFlushWriteBuffer(); \
00924
}
00925
00926
#define WRITE_PORT_USHORT(x, y) { \
00927
*(volatile USHORT * const)(x) = y; \
00928
KeFlushWriteBuffer(); \
00929
}
00930
00931
#define WRITE_PORT_ULONG(x, y) { \
00932
*(volatile ULONG * const)(x) = y; \
00933
KeFlushWriteBuffer(); \
00934
}
00935
00936
#define WRITE_PORT_BUFFER_UCHAR(x, y, z) { \
00937
PUCHAR writeBuffer = y; \
00938
ULONG writeCount; \
00939
for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
00940
*(volatile UCHAR * const)(x) = *writeBuffer; \
00941
KeFlushWriteBuffer(); \
00942
} \
00943
}
00944
00945
#define WRITE_PORT_BUFFER_USHORT(x, y, z) { \
00946
PUSHORT writeBuffer = y; \
00947
ULONG writeCount; \
00948
for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
00949
*(volatile USHORT * const)(x) = *writeBuffer; \
00950
KeFlushWriteBuffer(); \
00951
} \
00952
}
00953
00954
#define WRITE_PORT_BUFFER_ULONG(x, y, z) { \
00955
PULONG writeBuffer = y; \
00956
ULONG writeCount; \
00957
for (writeCount = 0; writeCount < z; writeCount++, writeBuffer++) { \
00958
*(volatile ULONG * const)(x) = *writeBuffer; \
00959
KeFlushWriteBuffer(); \
00960
} \
00961
}
00962
00963
00964
00965
00966
00967
00968
00969
00970
00971
typedef struct _KEXCEPTION_FRAME {
00972
union {
00973 ULONG Argument[8];
00974 DOUBLE Alignment;
00975 };
00976
00977
00978
00979
00980
00981
union {
00982
00983
00984
00985
00986
00987
struct {
00988 ULONG FltF20;
00989 ULONG FltF21;
00990 ULONG FltF22;
00991 ULONG FltF23;
00992 ULONG FltF24;
00993 ULONG FltF25;
00994 ULONG FltF26;
00995 ULONG FltF27;
00996 ULONG FltF28;
00997 ULONG FltF29;
00998 ULONG FltF30;
00999 ULONG FltF31;
01000 };
01001
01002
01003
01004
01005
01006
struct {
01007 ULONGLONG XFltF20;
01008 ULONGLONG XFltF22;
01009 ULONGLONG XFltF24;
01010 ULONGLONG XFltF26;
01011 ULONGLONG XFltF28;
01012 ULONGLONG XFltF30;
01013 };
01014 };
01015
01016
01017
01018
01019
01020 ULONG IntS0;
01021 ULONG IntS1;
01022 ULONG IntS2;
01023 ULONG IntS3;
01024 ULONG IntS4;
01025 ULONG IntS5;
01026 ULONG IntS6;
01027 ULONG IntS7;
01028 ULONG IntS8;
01029 ULONG SwapReturn;
01030 ULONG IntRa;
01031 } KEXCEPTION_FRAME, *PKEXCEPTION_FRAME;
01032
01033
01034
01035
01036
01037
01038
01039
typedef struct _KTRAP_FRAME {
01040
union {
01041 ULONG Argument[4];
01042 ULONGLONG Alignment;
01043 };
01044
01045
01046
01047
01048
01049
union {
01050
01051
01052
01053
01054
01055
struct {
01056 ULONG FltF0;
01057 ULONG FltF1;
01058 ULONG FltF2;
01059 ULONG FltF3;
01060 ULONG FltF4;
01061 ULONG FltF5;
01062 ULONG FltF6;
01063 ULONG FltF7;
01064 ULONG FltF8;
01065 ULONG FltF9;
01066 ULONG FltF10;
01067 ULONG FltF11;
01068 ULONG FltF12;
01069 ULONG FltF13;
01070 ULONG FltF14;
01071 ULONG FltF15;
01072 ULONG FltF16;
01073 ULONG FltF17;
01074 ULONG FltF18;
01075 ULONG FltF19;
01076 };
01077
01078
01079
01080
01081
01082
struct {
01083 ULONGLONG XFltF0;
01084 ULONGLONG XFltF1;
01085 ULONGLONG XFltF2;
01086 ULONGLONG XFltF3;
01087 ULONGLONG XFltF4;
01088 ULONGLONG XFltF5;
01089 ULONGLONG XFltF6;
01090 ULONGLONG XFltF7;
01091 ULONGLONG XFltF8;
01092 ULONGLONG XFltF9;
01093 ULONGLONG XFltF10;
01094 ULONGLONG XFltF11;
01095 ULONGLONG XFltF12;
01096 ULONGLONG XFltF13;
01097 ULONGLONG XFltF14;
01098 ULONGLONG XFltF15;
01099 ULONGLONG XFltF16;
01100 ULONGLONG XFltF17;
01101 ULONGLONG XFltF18;
01102 ULONGLONG XFltF19;
01103 ULONGLONG XFltF21;
01104 ULONGLONG XFltF23;
01105 ULONGLONG XFltF25;
01106 ULONGLONG XFltF27;
01107 ULONGLONG XFltF29;
01108 ULONGLONG XFltF31;
01109 };
01110 };
01111
01112
01113
01114
01115
01116
01117
struct {
01118 ULONGLONG XIntZero;
01119 ULONGLONG XIntAt;
01120 ULONGLONG XIntV0;
01121 ULONGLONG XIntV1;
01122 ULONGLONG XIntA0;
01123 ULONGLONG XIntA1;
01124 ULONGLONG XIntA2;
01125 ULONGLONG XIntA3;
01126 ULONGLONG XIntT0;
01127 ULONGLONG XIntT1;
01128 ULONGLONG XIntT2;
01129 ULONGLONG XIntT3;
01130 ULONGLONG XIntT4;
01131 ULONGLONG XIntT5;
01132 ULONGLONG XIntT6;
01133 ULONGLONG XIntT7;
01134 ULONGLONG XIntS0;
01135 ULONGLONG XIntS1;
01136 ULONGLONG XIntS2;
01137 ULONGLONG XIntS3;
01138 ULONGLONG XIntS4;
01139 ULONGLONG XIntS5;
01140 ULONGLONG XIntS6;
01141 ULONGLONG XIntS7;
01142 ULONGLONG XIntT8;
01143 ULONGLONG XIntT9;
01144 ULONGLONG XIntK0;
01145 ULONGLONG XIntK1;
01146 ULONGLONG XIntGp;
01147 ULONGLONG XIntSp;
01148 ULONGLONG XIntS8;
01149 ULONGLONG XIntRa;
01150 ULONGLONG XIntLo;
01151 ULONGLONG XIntHi;
01152 };
01153
01154 ULONG Fsr;
01155 ULONG Fir;
01156 ULONG Psr;
01157 UCHAR ExceptionRecord[(
sizeof(EXCEPTION_RECORD) + 7) & (~7)];
01158 UCHAR OldIrql;
01159 UCHAR PreviousMode;
01160 UCHAR SavedFlag;
01161
union {
01162 ULONG OnInterruptStack;
01163 ULONG TrapFrame;
01164 } u;
01165
01166 } KTRAP_FRAME, *PKTRAP_FRAME;
01167
01168
#define KTRAP_FRAME_ARGUMENTS (4 * 16)
01169
#define KTRAP_FRAME_LENGTH (sizeof(KTRAP_FRAME))
01170
#define KTRAP_FRAME_ALIGN (sizeof(DOUBLE))
01171
#define KTRAP_FRAME_ROUND (KTRAP_FRAME_ALIGN - 1)
01172
01173
01174
01175
01176
01177
typedef struct _KCALLOUT_FRAME {
01178 ULONG SaveArgs[4];
01179 ULONG F20;
01180 ULONG F21;
01181 ULONG F22;
01182 ULONG F23;
01183 ULONG F24;
01184 ULONG F25;
01185 ULONG F26;
01186 ULONG F27;
01187 ULONG F28;
01188 ULONG F29;
01189 ULONG F30;
01190 ULONG F31;
01191 ULONG S0;
01192 ULONG S1;
01193 ULONG S2;
01194 ULONG S3;
01195 ULONG S4;
01196 ULONG S5;
01197 ULONG S6;
01198 ULONG S7;
01199 ULONG S8;
01200 ULONG CbStk;
01201 ULONG TrFr;
01202 ULONG Fsr;
01203 ULONG InStk;
01204 ULONG Ra;
01205 ULONG A0;
01206 ULONG
A1;
01207 } KCALLOUT_FRAME, *PKCALLOUT_FRAME;
01208
01209
typedef struct _UCALLOUT_FRAME {
01210 ULONG SaveArgs[4];
01211 PVOID
Buffer;
01212 ULONG Length;
01213 ULONG ApiNumber;
01214 ULONG Pad;
01215 LONGLONG Sp;
01216 LONGLONG Ra;
01217 } UCALLOUT_FRAME, *PUCALLOUT_FRAME;
01218
01219
01220
01221
01222
01223
01224
typedef struct _KFLOATING_SAVE {
01225 ULONG Reserved;
01226 } KFLOATING_SAVE, *PKFLOATING_SAVE;
01227
01228
01229
01230
01231
01232
01233
typedef struct _TB_ENTRY {
01234 ENTRYLO Entrylo0;
01235 ENTRYLO Entrylo1;
01236 ENTRYHI Entryhi;
01237 PAGEMASK Pagemask;
01238 } TB_ENTRY, *PTB_ENTRY;
01239
01240
typedef struct _KPROCESSOR_STATE {
01241
struct _CONTEXT ContextFrame;
01242 TB_ENTRY TbEntry[64];
01243 } KPROCESSOR_STATE, *PKPROCESSOR_STATE;
01244
01245
01246
01247
01248
01249
#define PRCB_MINOR_VERSION 1
01250
#define PRCB_MAJOR_VERSION 1
01251
#define PRCB_BUILD_DEBUG 0x0001
01252
#define PRCB_BUILD_UNIPROCESSOR 0x0002
01253
01254
struct _RESTART_BLOCK;
01255
01256
typedef struct _KPRCB {
01257
01258
01259
01260
01261
01262
USHORT MinorVersion;
01263
USHORT MajorVersion;
01264
01265
01266
01267
01268
01269
01270
01271
01272
struct _KTHREAD *CurrentThread;
01273
struct _KTHREAD *RESTRICTED_POINTER NextThread;
01274
struct _KTHREAD *IdleThread;
01275 CCHAR Number;
01276 CCHAR Reserved;
01277
USHORT BuildType;
01278 KAFFINITY
SetMember;
01279
struct _RESTART_BLOCK *RestartBlock;
01280 ULONG PcrPage;
01281
01282
01283
01284
01285
01286 ULONG SystemReserved[16];
01287
01288
01289
01290
01291
01292 ULONG HalReserved[16];
01293
01294
01295
01296
01297
01298 ULONG DpcTime;
01299 ULONG InterruptTime;
01300 ULONG KernelTime;
01301 ULONG UserTime;
01302 ULONG AdjustDpcThreshold;
01303 ULONG InterruptCount;
01304 ULONG ApcBypassCount;
01305 ULONG DpcBypassCount;
01306 ULONG
Spare6[5];
01307
01308
01309
01310
01311
01312 PVOID Spare1;
01313 PVOID
Spare2;
01314
volatile ULONG IpiFrozen;
01315
struct _KPROCESSOR_STATE ProcessorState;
01316 PVOID
Spare3[3];
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329 ULONG
CcFastReadNoWait;
01330 ULONG
CcFastReadWait;
01331 ULONG
CcFastReadNotPossible;
01332 ULONG
CcCopyReadNoWait;
01333 ULONG
CcCopyReadWait;
01334 ULONG
CcCopyReadNoWaitMiss;
01335
01336
01337
01338
01339
01340 ULONG KeAlignmentFixupCount;
01341 ULONG KeContextSwitches;
01342 ULONG
KeDcacheFlushCount;
01343 ULONG KeExceptionDispatchCount;
01344 ULONG KeFirstLevelTbFills;
01345 ULONG KeFloatingEmulationCount;
01346 ULONG
KeIcacheFlushCount;
01347 ULONG KeSecondLevelTbFills;
01348 ULONG KeSystemCalls;
01349
01350
01351
01352
01353
01354 ULONG ReservedCounter[8];
01355
01356
01357
01358
01359
01360 ULONG ReservedPad[16 * 8];
01361
01362
01363
01364
01365
01366
01367
01368
volatile PVOID CurrentPacket[3];
01369
volatile KAFFINITY TargetSet;
01370
volatile PKIPI_WORKER WorkerRoutine;
01371 ULONG CachePad1[3];
01372
01373
01374
01375
01376
01377
volatile ULONG RequestSummary;
01378
volatile struct _KPRCB *SignalDone;
01379 ULONG CachePad2[6];
01380
01381
01382
01383
01384
01385 ULONG DpcInterruptRequested;
01386 ULONG CachePad3[7];
01387
01388
01389
01390
01391
01392 ULONG MaximumDpcQueueDepth;
01393 ULONG MinimumDpcRate;
01394
01395
01396
01397
01398
01399 ULONG
Spare4[2];
01400
01401
01402
01403
01404
01405 PVOID SmallIrpFreeEntry;
01406 PVOID LargeIrpFreeEntry;
01407 PVOID MdlFreeEntry;
01408
01409
01410
01411
01412
01413 PVOID CreateInfoFreeEntry;
01414 PVOID NameBufferFreeEntry;
01415
01416
01417
01418
01419
01420 PVOID SharedCacheMapEntry;
01421
01422
01423
01424
01425
01426 ULONG
Spare5[2];
01427
01428
01429
01430
01431
01432
PKIPI_COUNTS IpiCounts;
01433 LARGE_INTEGER StartCount;
01434
01435
01436
01437
01438
01439 KSPIN_LOCK DpcLock;
01440 LIST_ENTRY DpcListHead;
01441 ULONG DpcQueueDepth;
01442 ULONG DpcCount;
01443 ULONG DpcLastCount;
01444 ULONG DpcRequestRate;
01445 ULONG DpcRoutineActive;
01446 BOOLEAN SkipTick;
01447 ULONG CachePad4[5];
01448
01449
01450
01451
01452 PROCESSOR_POWER_STATE PowerState;
01453
01454 } KPRCB, *PKPRCB, *RESTRICTED_POINTER PRKPRCB;
01455
01456
01457
01458
01459
01460
01461
01462
#define PAGE_SIZE (ULONG)0x1000
01463
01464
01465
01466
01467
01468
01469
01470
#define PAGE_SHIFT 12L
01471
01472
01473
01474
01475
01476
01477
01478
#define PDI_SHIFT 22
01479
01480
01481
01482
01483
01484
01485
#define PTI_SHIFT 12
01486
01487
01488
01489
01490
01491
01492
01493
01494
#define MM_HIGHEST_USER_ADDRESS (PVOID)0x7FFEFFFF // highest user address
01495
#define MM_SYSTEM_RANGE_START (PVOID)KSEG0_BASE // start of system space
01496
#define MM_USER_PROBE_ADDRESS 0x7FFF0000 // starting address of guard page
01497
01498
01499
01500
01501
01502
extern PVOID
MmHighestUserAddress;
01503
extern PVOID
MmSystemRangeStart;
01504
extern ULONG
MmUserProbeAddress;
01505
01506
01507
01508
01509
01510
#define MM_LOWEST_USER_ADDRESS (PVOID)0x00010000
01511
01512
01513
01514
#define MmGetProcedureAddress(Address) (Address)
01515
#define MmLockPagableCodeSection(Address) MmLockPagableDataSection(Address)
01516
01517
01518
01519
01520
01521
01522
01523
#define PDE_BASE (ULONG)0xC0300000
01524
#define PTE_BASE (ULONG)0xC0000000
01525
#define PDE64_BASE (ULONG)0xC0302000
01526
#define PTE64_BASE (ULONG)0xC0800000
01527
01528
01529
01530
01531
01532
01533
#define MM_LOWEST_SYSTEM_ADDRESS (PVOID)0xC0800000
01534
#define SYSTEM_BASE 0xc0800000 // start of system space (no typecast)
01535
01536
01537
#endif // defined(_MIPS_)
01538
01539
01540
01541
01542
01543
01544 #define UNCACHED_POLICY 2 // uncached
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565 #define KiIsThreadNumericStateSaved(a) TRUE
01566
01567
01568
01569
01570
01571
01572
01573
01574
01575
01576 #define KiRundownThread(a)
01577
01578
01579
01580
01581
01582
01583
01584 #define Isx86FeaturePresent(_f_) TRUE
01585
01586
#endif // _MIPSH_