stubs.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*++
  2. Copyright (c) 2013 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. stubs.c
  5. Abstract:
  6. This module implements stub functions called by various libraries included
  7. in the loader.
  8. Author:
  9. Evan Green 7-Aug-2013
  10. Environment:
  11. Boot
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <minoca/kernel/kernel.h>
  17. #include "firmware.h"
  18. #include "bootlib.h"
  19. //
  20. // ---------------------------------------------------------------- Definitions
  21. //
  22. //
  23. // ------------------------------------------------------ Data Type Definitions
  24. //
  25. //
  26. // ----------------------------------------------- Internal Function Prototypes
  27. //
  28. //
  29. // -------------------------------------------------------------------- Globals
  30. //
  31. ULONG KeActiveProcessorCount = 1;
  32. //
  33. // ------------------------------------------------------------------ Functions
  34. //
  35. KERNEL_API
  36. PVOID
  37. MmAllocatePool (
  38. POOL_TYPE PoolType,
  39. UINTN Size,
  40. ULONG Tag
  41. )
  42. /*++
  43. Routine Description:
  44. This routine allocates memory from a kernel pool.
  45. Arguments:
  46. PoolType - Supplies the type of pool to allocate from. Valid choices are:
  47. PoolTypeNonPaged - This type of memory will never be paged out. It is a
  48. scarce resource, and should only be allocated if paged pool is not
  49. an option. This memory is marked no-execute.
  50. PoolTypePaged - This is normal memory that may be transparently paged if
  51. memory gets tight. The caller may not touch paged pool at run-levels at
  52. or above dispatch, and is not suitable for DMA (as its physical address
  53. may change unexpectedly.) This pool type should be used for most normal
  54. allocations. This memory is marked no-execute.
  55. Size - Supplies the size of the allocation, in bytes.
  56. Tag - Supplies an identifier to associate with the allocation, useful for
  57. debugging and leak detection.
  58. Return Value:
  59. Returns the allocated memory if successful, or NULL on failure.
  60. --*/
  61. {
  62. return BoAllocateMemory(Size);
  63. }
  64. KERNEL_API
  65. VOID
  66. MmFreePool (
  67. POOL_TYPE PoolType,
  68. PVOID Allocation
  69. )
  70. /*++
  71. Routine Description:
  72. This routine frees memory allocated from a kernel pool.
  73. Arguments:
  74. PoolType - Supplies the type of pool the memory was allocated from. This
  75. must agree with the type of pool the allocation originated from, or
  76. the system will become unstable.
  77. Allocation - Supplies a pointer to the allocation to free. This pointer
  78. may not be referenced after this function completes.
  79. Return Value:
  80. None.
  81. --*/
  82. {
  83. BoFreeMemory(Allocation);
  84. return;
  85. }
  86. ULONG
  87. MmValidateMemoryAccessForDebugger (
  88. PVOID Address,
  89. ULONG Length,
  90. PBOOL Writable
  91. )
  92. /*++
  93. Routine Description:
  94. This routine validates that access to a specified location in memory will
  95. not cause a page fault.
  96. Arguments:
  97. Address - Supplies the virtual address of the memory that will be read or
  98. written.
  99. Length - Supplies how many bytes at that location the caller would like to
  100. read or write.
  101. Writable - Supplies an optional pointer that receives a boolean indicating
  102. whether or not the memory range is mapped writable.
  103. Return Value:
  104. Returns the number of bytes from the beginning of the address that are
  105. accessible. If the memory is completely available, the return value will be
  106. equal to the Length parameter. If the memory is completely paged out, 0
  107. will be returned.
  108. --*/
  109. {
  110. if (Writable != NULL) {
  111. *Writable = TRUE;
  112. }
  113. return Length;
  114. }
  115. VOID
  116. MmModifyAddressMappingForDebugger (
  117. PVOID Address,
  118. BOOL Writable,
  119. PBOOL WasWritable
  120. )
  121. /*++
  122. Routine Description:
  123. This routine modifies the mapping properties for the page that contains the
  124. given address.
  125. Arguments:
  126. Address - Supplies the virtual address of the memory whose mapping
  127. properties are to be changed.
  128. Writable - Supplies a boolean indicating whether or not to make the page
  129. containing the address writable (TRUE) or read-only (FALSE).
  130. WasWritable - Supplies a pointer that receives a boolean indicating whether
  131. or not the page was writable (TRUE) or read-only (FALSE) before any
  132. modifications.
  133. Return Value:
  134. None.
  135. --*/
  136. {
  137. *WasWritable = TRUE;
  138. return;
  139. }
  140. PPROCESSOR_BLOCK
  141. KeGetCurrentProcessorBlockForDebugger (
  142. VOID
  143. )
  144. /*++
  145. Routine Description:
  146. This routine gets the processor block for the currently executing
  147. processor. It is intended to be called only by the debugger.
  148. Arguments:
  149. None.
  150. Return Value:
  151. Returns the current processor block.
  152. --*/
  153. {
  154. return NULL;
  155. }
  156. VOID
  157. KeCrashSystemEx (
  158. ULONG CrashCode,
  159. PSTR CrashCodeString,
  160. ULONGLONG Parameter1,
  161. ULONGLONG Parameter2,
  162. ULONGLONG Parameter3,
  163. ULONGLONG Parameter4
  164. )
  165. /*++
  166. Routine Description:
  167. This routine officially takes the system down after a fatal system error
  168. has occurred. This function does not return.
  169. Arguments:
  170. CrashCode - Supplies the reason for the system crash.
  171. CrashCodeString - Supplies the string corresponding to the given crash
  172. code. This parameter is generated by the macro, and should not be
  173. filled in directly.
  174. Parameter1 - Supplies an optional parameter regarding the crash.
  175. Parameter2 - Supplies an optional parameter regarding the crash.
  176. Parameter3 - Supplies an optional parameter regarding the crash.
  177. Parameter4 - Supplies an optional parameter regarding the crash.
  178. Return Value:
  179. None. This function does not return.
  180. --*/
  181. {
  182. RtlDebugPrint("\n\n *** Fatal System Error ***\n\n"
  183. "Error Code: %s (0x%x)\n"
  184. "Parameter1: 0x%08I64x\n"
  185. "Parameter2: 0x%08I64x\n"
  186. "Parameter3: 0x%08I64x\n"
  187. "Parameter4: 0x%08I64x\n\n",
  188. CrashCodeString,
  189. CrashCode,
  190. Parameter1,
  191. Parameter2,
  192. Parameter3,
  193. Parameter4);
  194. //
  195. // Spin forever.
  196. //
  197. while (TRUE) {
  198. KdBreak();
  199. }
  200. }
  201. KSTATUS
  202. HlSendIpi (
  203. IPI_TYPE IpiType,
  204. PPROCESSOR_SET Processors
  205. )
  206. /*++
  207. Routine Description:
  208. This routine sends an Inter-Processor Interrupt (IPI) to the given set of
  209. processors.
  210. Arguments:
  211. IpiType - Supplies the type of IPI to deliver.
  212. Processors - Supplies the set of processors to deliver the IPI to.
  213. Return Value:
  214. Status code.
  215. --*/
  216. {
  217. ASSERT(FALSE);
  218. return STATUS_NOT_SUPPORTED;
  219. }
  220. ULONGLONG
  221. HlQueryTimeCounter (
  222. VOID
  223. )
  224. /*++
  225. Routine Description:
  226. This routine queries the time counter hardware and returns a 64-bit
  227. monotonically non-decreasing value that represents the number of timer ticks
  228. since the system was started. This value will continue to count through all
  229. idle and sleep states.
  230. This routine can be called at any runlevel.
  231. Arguments:
  232. None.
  233. Return Value:
  234. Returns the number of timer ticks that have elapsed since the system was
  235. booted. The absolute time between successive ticks can be retrieved from the
  236. Query Time Counter Frequency function.
  237. --*/
  238. {
  239. return 0;
  240. }
  241. ULONGLONG
  242. HlQueryTimeCounterFrequency (
  243. VOID
  244. )
  245. /*++
  246. Routine Description:
  247. This routine returns the frequency of the time counter. This frequency will
  248. never change after it is set on boot.
  249. This routine can be called at any runlevel.
  250. Arguments:
  251. None.
  252. Return Value:
  253. Returns the frequency of the time counter, in Hertz.
  254. --*/
  255. {
  256. ASSERT(FALSE);
  257. return 1;
  258. }
  259. VOID
  260. HlBusySpin (
  261. ULONG Microseconds
  262. )
  263. /*++
  264. Routine Description:
  265. This routine spins for at least the given number of microseconds by
  266. repeatedly reading a hardware timer. This routine should be avoided if at
  267. all possible, as it simply burns CPU cycles.
  268. This routine can be called at any runlevel.
  269. Arguments:
  270. Microseconds - Supplies the number of microseconds to spin for.
  271. Return Value:
  272. Returns the frequency of the time counter, in Hertz.
  273. --*/
  274. {
  275. FwStall(Microseconds);
  276. return;
  277. }
  278. KSTATUS
  279. HlResetSystem (
  280. SYSTEM_RESET_TYPE ResetType
  281. )
  282. /*++
  283. Routine Description:
  284. This routine resets the system.
  285. Arguments:
  286. ResetType - Supplies the desired reset type. If the desired reset type is
  287. not supported, a cold reset will be attempted.
  288. Return Value:
  289. Does not return on success, the system is reset.
  290. STATUS_INVALID_PARAMETER if an invalid reset type was supplied.
  291. STATUS_NOT_SUPPORTED if the system cannot be reset.
  292. STATUS_UNSUCCESSFUL if the system did not reset.
  293. --*/
  294. {
  295. return FwResetSystem(ResetType);
  296. }
  297. KSTATUS
  298. SpGetProfilerData (
  299. PPROFILER_NOTIFICATION ProfilerNotification,
  300. PULONG Flags
  301. )
  302. /*++
  303. Routine Description:
  304. This routine fills the provided profiler notification with profiling data.
  305. A profiler consumer should call this routine to obtain data to send over
  306. the wire. It is assumed here that consumers will serialize consumption.
  307. Arguments:
  308. ProfilerNotification - Supplies a pointer to the profiler notification that
  309. is to be filled in with profiling data.
  310. Flags - Supplies a pointer to the types of profiling data the caller wants
  311. to collect. Upon return, the flags for the returned data will be
  312. returned.
  313. Return Value:
  314. Status code.
  315. --*/
  316. {
  317. ASSERT(FALSE);
  318. return STATUS_NOT_SUPPORTED;
  319. }
  320. ULONG
  321. SpGetProfilerDataStatus (
  322. VOID
  323. )
  324. /*++
  325. Routine Description:
  326. This routine determines if there is profiling data for the current
  327. processor that needs to be sent to a consumer.
  328. Arguments:
  329. None.
  330. Return Value:
  331. Returns a set of flags representing which types of profiling data are
  332. available. Returns zero if nothing is available.
  333. --*/
  334. {
  335. return 0;
  336. }
  337. //
  338. // --------------------------------------------------------- Internal Functions
  339. //