1
0

stubs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  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 firmware.
  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 <minoca/kernel/kdebug.h>
  18. #include <minoca/uefi/uefi.h>
  19. #include "shortcut.h"
  20. //
  21. // ---------------------------------------------------------------- Definitions
  22. //
  23. //
  24. // ------------------------------------------------------ Data Type Definitions
  25. //
  26. //
  27. // ----------------------------------------------- Internal Function Prototypes
  28. //
  29. //
  30. // -------------------------------------------------------------------- Globals
  31. //
  32. ULONG KeActiveProcessorCount = 1;
  33. //
  34. // ------------------------------------------------------------------ Functions
  35. //
  36. VOID
  37. RtlDebugPrint (
  38. PSTR Format,
  39. ...
  40. )
  41. /*++
  42. Routine Description:
  43. This routine prints a printf-style string to the debugger.
  44. Arguments:
  45. Format - Supplies the printf-style format string to print. The contents of
  46. this string determine the rest of the arguments passed.
  47. ... - Supplies any arguments needed to convert the Format string.
  48. Return Value:
  49. None.
  50. --*/
  51. {
  52. va_list ArgumentList;
  53. CHAR Ascii[128];
  54. ULONG Index;
  55. USHORT Wide[128];
  56. //
  57. // Simply pass the data on to the debugger's print function.
  58. //
  59. va_start(ArgumentList, Format);
  60. KdPrintWithArgumentList(Format, ArgumentList);
  61. va_end(ArgumentList);
  62. if (EfiSystemTable->StdErr != NULL) {
  63. va_start(ArgumentList, Format);
  64. RtlFormatString(Ascii,
  65. sizeof(Ascii) - 1,
  66. CharacterEncodingAscii,
  67. Format,
  68. ArgumentList);
  69. Index = 0;
  70. while (Ascii[Index] != '\0') {
  71. Wide[Index] = Ascii[Index];
  72. Index += 1;
  73. }
  74. Wide[Index] = L'\0';
  75. va_end(ArgumentList);
  76. EfiSystemTable->StdErr->OutputString(EfiSystemTable->StdErr, Wide);
  77. }
  78. return;
  79. }
  80. VOID
  81. RtlRaiseAssertion (
  82. PSTR Expression,
  83. PSTR SourceFile,
  84. ULONG SourceLine
  85. )
  86. /*++
  87. Routine Description:
  88. This routine raises an assertion failure exception. If a debugger is
  89. connected, it will attempt to connect to the debugger.
  90. Arguments:
  91. Expression - Supplies the string containing the expression that failed.
  92. SourceFile - Supplies the string describing the source file of the failure.
  93. SourceLine - Supplies the source line number of the failure.
  94. Return Value:
  95. None.
  96. --*/
  97. {
  98. RtlDebugPrint("\n\n *** Assertion Failure: %s\n *** File: %s, Line %d\n\n",
  99. Expression,
  100. SourceFile,
  101. SourceLine);
  102. RtlDebugService(EXCEPTION_ASSERTION_FAILURE, NULL);
  103. return;
  104. }
  105. ULONG
  106. MmValidateMemoryAccessForDebugger (
  107. PVOID Address,
  108. ULONG Length,
  109. PBOOL Writable
  110. )
  111. /*++
  112. Routine Description:
  113. This routine validates that access to a specified location in memory will
  114. not cause a page fault.
  115. Arguments:
  116. Address - Supplies the virtual address of the memory that will be read or
  117. written.
  118. Length - Supplies how many bytes at that location the caller would like to
  119. read or write.
  120. Writable - Supplies an optional pointer that receives a boolean indicating
  121. whether or not the memory range is mapped writable.
  122. Return Value:
  123. Returns the number of bytes from the beginning of the address that are
  124. accessible. If the memory is completely available, the return value will be
  125. equal to the Length parameter. If the memory is completely paged out, 0
  126. will be returned.
  127. --*/
  128. {
  129. if (Writable != NULL) {
  130. *Writable = TRUE;
  131. }
  132. return Length;
  133. }
  134. VOID
  135. MmModifyAddressMappingForDebugger (
  136. PVOID Address,
  137. BOOL Writable,
  138. PBOOL WasWritable
  139. )
  140. /*++
  141. Routine Description:
  142. This routine modifies the mapping properties for the page that contains the
  143. given address.
  144. Arguments:
  145. Address - Supplies the virtual address of the memory whose mapping
  146. properties are to be changed.
  147. Writable - Supplies a boolean indicating whether or not to make the page
  148. containing the address writable (TRUE) or read-only (FALSE).
  149. WasWritable - Supplies a pointer that receives a boolean indicating whether
  150. or not the page was writable (TRUE) or read-only (FALSE) before any
  151. modifications.
  152. Return Value:
  153. None.
  154. --*/
  155. {
  156. *WasWritable = TRUE;
  157. return;
  158. }
  159. PPROCESSOR_BLOCK
  160. KeGetCurrentProcessorBlockForDebugger (
  161. VOID
  162. )
  163. /*++
  164. Routine Description:
  165. This routine gets the processor block for the currently executing
  166. processor. It is intended to be called only by the debugger.
  167. Arguments:
  168. None.
  169. Return Value:
  170. Returns the current processor block.
  171. --*/
  172. {
  173. return NULL;
  174. }
  175. VOID
  176. KeCrashSystemEx (
  177. ULONG CrashCode,
  178. PSTR CrashCodeString,
  179. ULONGLONG Parameter1,
  180. ULONGLONG Parameter2,
  181. ULONGLONG Parameter3,
  182. ULONGLONG Parameter4
  183. )
  184. /*++
  185. Routine Description:
  186. This routine officially takes the system down after a fatal system error
  187. has occurred. This function does not return.
  188. Arguments:
  189. CrashCode - Supplies the reason for the system crash.
  190. CrashCodeString - Supplies the string corresponding to the given crash
  191. code. This parameter is generated by the macro, and should not be
  192. filled in directly.
  193. Parameter1 - Supplies an optional parameter regarding the crash.
  194. Parameter2 - Supplies an optional parameter regarding the crash.
  195. Parameter3 - Supplies an optional parameter regarding the crash.
  196. Parameter4 - Supplies an optional parameter regarding the crash.
  197. Return Value:
  198. None. This function does not return.
  199. --*/
  200. {
  201. RtlDebugPrint("\n\n *** Fatal System Error ***\n\n"
  202. "Error Code: %s (0x%x)\n"
  203. "Parameter1: 0x%08I64x\n"
  204. "Parameter2: 0x%08I64x\n"
  205. "Parameter3: 0x%08I64x\n"
  206. "Parameter4: 0x%08I64x\n\n",
  207. CrashCodeString,
  208. CrashCode,
  209. Parameter1,
  210. Parameter2,
  211. Parameter3,
  212. Parameter4);
  213. //
  214. // Spin forever.
  215. //
  216. while (TRUE) {
  217. RtlDebugBreak();
  218. }
  219. }
  220. KSTATUS
  221. HlSendIpi (
  222. IPI_TYPE IpiType,
  223. PPROCESSOR_SET Processors
  224. )
  225. /*++
  226. Routine Description:
  227. This routine sends an Inter-Processor Interrupt (IPI) to the given set of
  228. processors.
  229. Arguments:
  230. IpiType - Supplies the type of IPI to deliver.
  231. Processors - Supplies the set of processors to deliver the IPI to.
  232. Return Value:
  233. Status code.
  234. --*/
  235. {
  236. ASSERT(FALSE);
  237. return STATUS_NOT_SUPPORTED;
  238. }
  239. KSTATUS
  240. HlResetSystem (
  241. SYSTEM_RESET_TYPE ResetType
  242. )
  243. /*++
  244. Routine Description:
  245. This routine resets the system.
  246. Arguments:
  247. ResetType - Supplies the desired reset type. If the desired reset type is
  248. not supported, a cold reset will be attempted.
  249. Return Value:
  250. Does not return on success, the system is reset.
  251. STATUS_INVALID_PARAMETER if an invalid reset type was supplied.
  252. STATUS_NOT_SUPPORTED if the system cannot be reset.
  253. STATUS_UNSUCCESSFUL if the system did not reset.
  254. --*/
  255. {
  256. EFI_RESET_TYPE EfiResetType;
  257. switch (ResetType) {
  258. case SystemResetShutdown:
  259. EfiResetType = EfiResetShutdown;
  260. break;
  261. case SystemResetCold:
  262. EfiResetType = EfiResetCold;
  263. break;
  264. case SystemResetWarm:
  265. default:
  266. EfiResetType = EfiResetWarm;
  267. break;
  268. }
  269. if ((EfiRuntimeServices != NULL) &&
  270. (EfiRuntimeServices->ResetSystem != NULL)) {
  271. EfiResetSystem(EfiResetType, 0, 0, NULL);
  272. }
  273. return STATUS_UNSUCCESSFUL;
  274. }
  275. ULONGLONG
  276. HlQueryTimeCounter (
  277. VOID
  278. )
  279. /*++
  280. Routine Description:
  281. This routine queries the time counter hardware and returns a 64-bit
  282. monotonically non-decreasing value that represents the number of timer ticks
  283. since the system was started. This value will continue to count through all
  284. idle and sleep states.
  285. This routine can be called at any runlevel.
  286. Arguments:
  287. None.
  288. Return Value:
  289. Returns the number of timer ticks that have elapsed since the system was
  290. booted. The absolute time between successive ticks can be retrieved from the
  291. Query Time Counter Frequency function.
  292. --*/
  293. {
  294. return 0;
  295. }
  296. ULONGLONG
  297. HlQueryTimeCounterFrequency (
  298. VOID
  299. )
  300. /*++
  301. Routine Description:
  302. This routine returns the frequency of the time counter. This frequency will
  303. never change after it is set on boot.
  304. This routine can be called at any runlevel.
  305. Arguments:
  306. None.
  307. Return Value:
  308. Returns the frequency of the time counter, in Hertz.
  309. --*/
  310. {
  311. ASSERT(FALSE);
  312. return 1;
  313. }
  314. VOID
  315. HlBusySpin (
  316. ULONG Microseconds
  317. )
  318. /*++
  319. Routine Description:
  320. This routine spins for at least the given number of microseconds by
  321. repeatedly reading a hardware timer. This routine should be avoided if at
  322. all possible, as it simply burns CPU cycles.
  323. This routine can be called at any runlevel.
  324. Arguments:
  325. Microseconds - Supplies the number of microseconds to spin for.
  326. Return Value:
  327. Returns the frequency of the time counter, in Hertz.
  328. --*/
  329. {
  330. if ((EfiBootServices != NULL) && (EfiBootServices->Stall != NULL)) {
  331. EfiStall(Microseconds);
  332. }
  333. return;
  334. }
  335. KSTATUS
  336. SpGetProfilerData (
  337. PPROFILER_NOTIFICATION ProfilerNotification,
  338. PULONG Flags
  339. )
  340. /*++
  341. Routine Description:
  342. This routine fills the provided profiler notification with profiling data.
  343. A profiler consumer should call this routine to obtain data to send over
  344. the wire. It is assumed here that consumers will serialize consumption.
  345. Arguments:
  346. ProfilerNotification - Supplies a pointer to the profiler notification that
  347. is to be filled in with profiling data.
  348. Flags - Supplies a pointer to the types of profiling data the caller wants
  349. to collect. Upon return, the flags for the returned data will be
  350. returned.
  351. Return Value:
  352. Status code.
  353. --*/
  354. {
  355. ASSERT(FALSE);
  356. return STATUS_NOT_SUPPORTED;
  357. }
  358. ULONG
  359. SpGetProfilerDataStatus (
  360. VOID
  361. )
  362. /*++
  363. Routine Description:
  364. This routine determines if there is profiling data for the current
  365. processor that needs to be sent to a consumer.
  366. Arguments:
  367. None.
  368. Return Value:
  369. Returns a set of flags representing which types of profiling data are
  370. available. Returns zero if nothing is available.
  371. --*/
  372. {
  373. return 0;
  374. }
  375. //
  376. // --------------------------------------------------------- Internal Functions
  377. //