Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

547 lines
12 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991-1994 Microsoft Corporation
  3. Module Name:
  4. xxinithl.c
  5. Abstract:
  6. This module implements the initialization of the system dependent
  7. functions that define the Hardware Architecture Layer (HAL) for a
  8. MIPS R4000 system.
  9. Author:
  10. David N. Cutler (davec) 25-Apr-1991
  11. Environment:
  12. Kernel mode only.
  13. Revision History:
  14. --*/
  15. #include "halp.h"
  16. //
  17. // Define forward referenced prototypes.
  18. //
  19. VOID
  20. HalpBugCheckCallback (
  21. IN PVOID Buffer,
  22. IN ULONG Length
  23. );
  24. BOOLEAN
  25. HalpBusError (
  26. IN PEXCEPTION_RECORD ExceptionRecord,
  27. IN PKEXCEPTION_FRAME ExceptionFrame,
  28. IN PKTRAP_FRAME TrapFrame,
  29. IN PVOID VirtualAddress,
  30. IN PHYSICAL_ADDRESS PhysicalAddress
  31. );
  32. //
  33. // Put all code for HAL initialization in the INIT section. It will be
  34. // deallocated by memory management when phase 1 initialization is
  35. // completed.
  36. //
  37. #if defined(ALLOC_PRAGMA)
  38. #pragma alloc_text(INIT, HalInitSystem)
  39. #pragma alloc_text(INIT, HalInitializeProcessor)
  40. #pragma alloc_text(INIT, HalStartNextProcessor)
  41. #endif
  42. //
  43. // Define global spin locks used to synchronize various HAL operations.
  44. //
  45. KSPIN_LOCK HalpBeepLock;
  46. KSPIN_LOCK HalpDisplayAdapterLock;
  47. KSPIN_LOCK HalpSystemInterruptLock;
  48. //
  49. // Define bug check information buffer and callback record.
  50. //
  51. typedef struct _HALP_BUGCHECK_BUFFER {
  52. ULONG FailedAddress;
  53. ULONG DiagnosticLow;
  54. ULONG DiagnosticHigh;
  55. } HALP_BUGCHECK_BUFFER, *PHALP_BUGCHECK_BUFFER;
  56. HALP_BUGCHECK_BUFFER HalpBugCheckBuffer;
  57. KBUGCHECK_CALLBACK_RECORD HalpCallbackRecord;
  58. UCHAR HalpComponentId[] = "hal.dll";
  59. BOOLEAN
  60. HalInitSystem (
  61. IN ULONG Phase,
  62. IN PLOADER_PARAMETER_BLOCK LoaderBlock
  63. )
  64. /*++
  65. Routine Description:
  66. This function initializes the Hardware Architecture Layer (HAL) for a
  67. MIPS R3000 or R4000 system.
  68. Arguments:
  69. Phase - Supplies the initialization phase (zero or one).
  70. LoaderBlock - Supplies a pointer to a loader parameter block.
  71. Return Value:
  72. A value of TRUE is returned is the initialization was successfully
  73. complete. Otherwise a value of FALSE is returend.
  74. --*/
  75. {
  76. ULONG FailedAddress;
  77. PKPRCB Prcb;
  78. PHYSICAL_ADDRESS PhysicalAddress;
  79. PHYSICAL_ADDRESS ZeroAddress;
  80. ULONG AddressSpace;
  81. //
  82. // Initialize the HAL components based on the phase of initialization
  83. // and the processor number.
  84. //
  85. Prcb = PCR->Prcb;
  86. PCR->DataBusError = HalpBusError;
  87. PCR->InstructionBusError = HalpBusError;
  88. if ((Phase == 0) || (Prcb->Number != 0)) {
  89. //
  90. // Phase 0 initialization.
  91. //
  92. // N.B. Phase 0 initialization is executed on all processors.
  93. //
  94. // Verify that the processor block major version number conform
  95. // to the system that is being loaded.
  96. //
  97. if (Prcb->MajorVersion != PRCB_MAJOR_VERSION) {
  98. KeBugCheck(MISMATCHED_HAL);
  99. }
  100. //
  101. // Map the fixed TB entries.
  102. //
  103. HalpMapFixedTbEntries();
  104. //
  105. // If processor 0 is being initialized, then initialize various
  106. // variables, spin locks, and the display adapter.
  107. //
  108. if (Prcb->Number == 0) {
  109. //
  110. // Set the number of process id's and TB entries.
  111. //
  112. **((PULONG *)(&KeNumberProcessIds)) = 256;
  113. **((PULONG *)(&KeNumberTbEntries)) = 48;
  114. //
  115. // Set the interval clock increment value.
  116. //
  117. HalpCurrentTimeIncrement = MAXIMUM_INCREMENT;
  118. HalpNextTimeIncrement = MAXIMUM_INCREMENT;
  119. HalpNextIntervalCount = 0;
  120. KeSetTimeIncrement(MAXIMUM_INCREMENT, MINIMUM_INCREMENT);
  121. //
  122. // Initialize all spin locks.
  123. //
  124. #if defined(_DUO_)
  125. KeInitializeSpinLock(&HalpBeepLock);
  126. KeInitializeSpinLock(&HalpDisplayAdapterLock);
  127. KeInitializeSpinLock(&HalpSystemInterruptLock);
  128. #endif
  129. //
  130. // Set address of cache error routine.
  131. //
  132. KeSetCacheErrorRoutine(HalpCacheErrorRoutine);
  133. //
  134. // Initialize the display adapter.
  135. //
  136. HalpInitializeDisplay0(LoaderBlock);
  137. //
  138. // Allocate map register memory.
  139. //
  140. HalpAllocateMapRegisters(LoaderBlock);
  141. //
  142. // Initialize and register a bug check callback record.
  143. //
  144. KeInitializeCallbackRecord(&HalpCallbackRecord);
  145. KeRegisterBugCheckCallback(&HalpCallbackRecord,
  146. HalpBugCheckCallback,
  147. &HalpBugCheckBuffer,
  148. sizeof(HALP_BUGCHECK_BUFFER),
  149. &HalpComponentId[0]);
  150. }
  151. //
  152. // Clear memory address error registers.
  153. //
  154. #if defined(_DUO_)
  155. FailedAddress = ((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InvalidAddress.Long;
  156. #endif
  157. FailedAddress = ((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->MemoryFailedAddress.Long;
  158. //
  159. // Initialize interrupts
  160. //
  161. HalpInitializeInterrupts();
  162. return TRUE;
  163. } else {
  164. //
  165. // Phase 1 initialization.
  166. //
  167. // N.B. Phase 1 initialization is only executed on processor 0.
  168. //
  169. // Complete initialization of the display adapter.
  170. //
  171. if (HalpInitializeDisplay1(LoaderBlock) == FALSE) {
  172. return FALSE;
  173. } else {
  174. //
  175. // Map I/O space, calibrate the stall execution scale factor,
  176. // and create DMA data structures.
  177. //
  178. HalpMapIoSpace();
  179. HalpCalibrateStall();
  180. HalpCreateDmaStructures();
  181. //
  182. // Map EISA memory space so the x86 bios emulator emulator can
  183. // initialze a video adapter in an EISA slot.
  184. //
  185. ZeroAddress.QuadPart = 0;
  186. AddressSpace = 0;
  187. HalTranslateBusAddress(Isa,
  188. 0,
  189. ZeroAddress,
  190. &AddressSpace,
  191. &PhysicalAddress);
  192. HalpEisaMemoryBase = MmMapIoSpace(PhysicalAddress,
  193. PAGE_SIZE * 256,
  194. FALSE);
  195. HalpInitializeX86DisplayAdapter();
  196. return TRUE;
  197. }
  198. }
  199. }
  200. VOID
  201. HalpBugCheckCallback (
  202. IN PVOID Buffer,
  203. IN ULONG Length
  204. )
  205. /*++
  206. Routine Description:
  207. This function is called when a bug check occurs. Its function is
  208. to dump the state of the memory error registers into a bug check
  209. buffer.
  210. Arguments:
  211. Buffer - Supplies a pointer to the bug check buffer.
  212. Length - Supplies the length of the bug check buffer in bytes.
  213. Return Value:
  214. None.
  215. --*/
  216. {
  217. PHALP_BUGCHECK_BUFFER DumpBuffer;
  218. //
  219. // Capture the failed memory address and diagnostic registers.
  220. //
  221. DumpBuffer = (PHALP_BUGCHECK_BUFFER)Buffer;
  222. #if defined(_DUO_)
  223. DumpBuffer->DiagnosticLow =
  224. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InvalidAddress.Long;
  225. DumpBuffer->DiagnosticHigh =
  226. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->EccDiagnostic.u.LargeInteger.HighPart;
  227. #else
  228. DumpBuffer->DiagnosticLow =
  229. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->ParityDiagnosticLow.Long;
  230. DumpBuffer->DiagnosticHigh =
  231. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->ParityDiagnosticHigh.Long;
  232. #endif
  233. DumpBuffer->FailedAddress = (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->MemoryFailedAddress.Long;
  234. return;
  235. }
  236. BOOLEAN
  237. HalpBusError (
  238. IN PEXCEPTION_RECORD ExceptionRecord,
  239. IN PKEXCEPTION_FRAME ExceptionFrame,
  240. IN PKTRAP_FRAME TrapFrame,
  241. IN PVOID VirtualAddress,
  242. IN PHYSICAL_ADDRESS PhysicalAddress
  243. )
  244. /*++
  245. Routine Description:
  246. This function provides the default bus error handling routine for NT.
  247. N.B. There is no return from this routine.
  248. Arguments:
  249. ExceptionRecord - Supplies a pointer to an exception record.
  250. ExceptionFrame - Supplies a pointer to an exception frame.
  251. TrapFrame - Supplies a pointer to a trap frame.
  252. VirtualAddress - Supplies the virtual address of the bus error.
  253. PhysicalAddress - Supplies the physical address of the bus error.
  254. Return Value:
  255. None.
  256. --*/
  257. {
  258. ULONG DiagnosticHigh;
  259. ULONG DiagnosticLow;
  260. ULONG FailedAddress;
  261. //
  262. // Bug check specifying the exception code, the virtual address, the
  263. // failed memory address, and either the ECC diagnostic registers or
  264. // the parity diagnostic registers depending on the platform.
  265. //
  266. #if defined(_DUO_)
  267. DiagnosticLow =
  268. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->InvalidAddress.Long;
  269. DiagnosticHigh =
  270. (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->EccDiagnostic.u.LargeInteger.HighPart;
  271. #else
  272. DiagnosticLow = (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->ParityDiagnosticLow.Long;
  273. DiagnosticHigh = (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->ParityDiagnosticHigh.Long;
  274. #endif
  275. FailedAddress = (ULONG)((PDMA_REGISTERS)DMA_VIRTUAL_BASE)->MemoryFailedAddress.Long;
  276. KeBugCheckEx(ExceptionRecord->ExceptionCode & 0xffff,
  277. (ULONG)VirtualAddress,
  278. FailedAddress,
  279. DiagnosticLow,
  280. DiagnosticHigh);
  281. return FALSE;
  282. }
  283. VOID
  284. HalInitializeProcessor (
  285. IN ULONG Number
  286. )
  287. /*++
  288. Routine Description:
  289. This function is called early in the initialization of the kernel
  290. to perform platform dependent initialization for each processor
  291. before the HAL Is fully functional.
  292. N.B. When this routine is called, the PCR is present but is not
  293. fully initialized.
  294. Arguments:
  295. Number - Supplies the number of the processor to initialize.
  296. Return Value:
  297. None.
  298. --*/
  299. {
  300. return;
  301. }
  302. BOOLEAN
  303. HalStartNextProcessor (
  304. IN PLOADER_PARAMETER_BLOCK LoaderBlock,
  305. IN PKPROCESSOR_STATE ProcessorState
  306. )
  307. /*++
  308. Routine Description:
  309. This function is called to start the next processor.
  310. Arguments:
  311. LoaderBlock - Supplies a pointer to the loader parameter block.
  312. ProcessorState - Supplies a pointer to the processor state to be
  313. used to start the processor.
  314. Return Value:
  315. If a processor is successfully started, then a value of TRUE is
  316. returned. Otherwise a value of FALSE is returned. If a value of
  317. TRUE is returned, then the logical processor number is stored
  318. in the processor control block specified by the loader block.
  319. --*/
  320. {
  321. #if defined(_DUO_)
  322. PRESTART_BLOCK NextRestartBlock;
  323. ULONG Number;
  324. PKPRCB Prcb;
  325. //
  326. // If the address of the first restart parameter block is NULL, then
  327. // the host system is a uniprocessor system running with old firmware.
  328. // Otherwise, the host system may be a multiprocessor system if more
  329. // than one restart block is present.
  330. //
  331. // N.B. The first restart parameter block must be for the boot master
  332. // and must represent logical processor 0.
  333. //
  334. NextRestartBlock = SYSTEM_BLOCK->RestartBlock;
  335. if (NextRestartBlock == NULL) {
  336. return FALSE;
  337. }
  338. //
  339. // Scan the restart parameter blocks for a processor that is ready,
  340. // but not running. If a processor is found, then fill in the restart
  341. // processor state, set the logical processor number, and set start
  342. // in the boot status.
  343. //
  344. Number = 0;
  345. do {
  346. if ((NextRestartBlock->BootStatus.ProcessorReady != FALSE) &&
  347. (NextRestartBlock->BootStatus.ProcessorStart == FALSE)) {
  348. RtlZeroMemory(&NextRestartBlock->u.Mips, sizeof(MIPS_RESTART_STATE));
  349. NextRestartBlock->u.Mips.IntA0 = ProcessorState->ContextFrame.IntA0;
  350. NextRestartBlock->u.Mips.Fir = ProcessorState->ContextFrame.Fir;
  351. Prcb = (PKPRCB)(LoaderBlock->Prcb);
  352. Prcb->Number = (CCHAR)Number;
  353. Prcb->RestartBlock = NextRestartBlock;
  354. NextRestartBlock->BootStatus.ProcessorStart = 1;
  355. return TRUE;
  356. }
  357. Number += 1;
  358. NextRestartBlock = NextRestartBlock->NextRestartBlock;
  359. } while (NextRestartBlock != NULL);
  360. #endif
  361. return FALSE;
  362. }
  363. VOID
  364. HalpVerifyPrcbVersion(
  365. VOID
  366. )
  367. /*++
  368. Routine Description:
  369. This function ?
  370. Arguments:
  371. None.
  372. Return Value:
  373. None.
  374. --*/
  375. {
  376. return;
  377. }