123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- /*++
- Copyright (c) 2013 Minoca Corp. All Rights Reserved
- Module Name:
- stubs.c
- Abstract:
- This module implements stub functions called by various libraries included
- in the firmware.
- Author:
- Evan Green 7-Aug-2013
- Environment:
- Boot
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <minoca/kernel/kernel.h>
- #include <minoca/kernel/kdebug.h>
- #include <minoca/uefi/uefi.h>
- #include "shortcut.h"
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // ----------------------------------------------- Internal Function Prototypes
- //
- //
- // -------------------------------------------------------------------- Globals
- //
- ULONG KeActiveProcessorCount = 1;
- //
- // ------------------------------------------------------------------ Functions
- //
- VOID
- RtlDebugPrint (
- PSTR Format,
- ...
- )
- /*++
- Routine Description:
- This routine prints a printf-style string to the debugger.
- Arguments:
- Format - Supplies the printf-style format string to print. The contents of
- this string determine the rest of the arguments passed.
- ... - Supplies any arguments needed to convert the Format string.
- Return Value:
- None.
- --*/
- {
- va_list ArgumentList;
- CHAR Ascii[128];
- ULONG Index;
- USHORT Wide[128];
- //
- // Simply pass the data on to the debugger's print function.
- //
- va_start(ArgumentList, Format);
- KdPrintWithArgumentList(Format, ArgumentList);
- va_end(ArgumentList);
- if (EfiSystemTable->StdErr != NULL) {
- va_start(ArgumentList, Format);
- RtlFormatString(Ascii,
- sizeof(Ascii) - 1,
- CharacterEncodingAscii,
- Format,
- ArgumentList);
- Index = 0;
- while (Ascii[Index] != '\0') {
- Wide[Index] = Ascii[Index];
- Index += 1;
- }
- Wide[Index] = L'\0';
- va_end(ArgumentList);
- EfiSystemTable->StdErr->OutputString(EfiSystemTable->StdErr, Wide);
- }
- return;
- }
- VOID
- RtlRaiseAssertion (
- PSTR Expression,
- PSTR SourceFile,
- ULONG SourceLine
- )
- /*++
- Routine Description:
- This routine raises an assertion failure exception. If a debugger is
- connected, it will attempt to connect to the debugger.
- Arguments:
- Expression - Supplies the string containing the expression that failed.
- SourceFile - Supplies the string describing the source file of the failure.
- SourceLine - Supplies the source line number of the failure.
- Return Value:
- None.
- --*/
- {
- RtlDebugPrint("\n\n *** Assertion Failure: %s\n *** File: %s, Line %d\n\n",
- Expression,
- SourceFile,
- SourceLine);
- RtlDebugService(EXCEPTION_ASSERTION_FAILURE, NULL);
- return;
- }
- ULONG
- MmValidateMemoryAccessForDebugger (
- PVOID Address,
- ULONG Length,
- PBOOL Writable
- )
- /*++
- Routine Description:
- This routine validates that access to a specified location in memory will
- not cause a page fault.
- Arguments:
- Address - Supplies the virtual address of the memory that will be read or
- written.
- Length - Supplies how many bytes at that location the caller would like to
- read or write.
- Writable - Supplies an optional pointer that receives a boolean indicating
- whether or not the memory range is mapped writable.
- Return Value:
- Returns the number of bytes from the beginning of the address that are
- accessible. If the memory is completely available, the return value will be
- equal to the Length parameter. If the memory is completely paged out, 0
- will be returned.
- --*/
- {
- if (Writable != NULL) {
- *Writable = TRUE;
- }
- return Length;
- }
- VOID
- MmModifyAddressMappingForDebugger (
- PVOID Address,
- BOOL Writable,
- PBOOL WasWritable
- )
- /*++
- Routine Description:
- This routine modifies the mapping properties for the page that contains the
- given address.
- Arguments:
- Address - Supplies the virtual address of the memory whose mapping
- properties are to be changed.
- Writable - Supplies a boolean indicating whether or not to make the page
- containing the address writable (TRUE) or read-only (FALSE).
- WasWritable - Supplies a pointer that receives a boolean indicating whether
- or not the page was writable (TRUE) or read-only (FALSE) before any
- modifications.
- Return Value:
- None.
- --*/
- {
- *WasWritable = TRUE;
- return;
- }
- PPROCESSOR_BLOCK
- KeGetCurrentProcessorBlockForDebugger (
- VOID
- )
- /*++
- Routine Description:
- This routine gets the processor block for the currently executing
- processor. It is intended to be called only by the debugger.
- Arguments:
- None.
- Return Value:
- Returns the current processor block.
- --*/
- {
- return NULL;
- }
- VOID
- KeCrashSystemEx (
- ULONG CrashCode,
- PSTR CrashCodeString,
- ULONGLONG Parameter1,
- ULONGLONG Parameter2,
- ULONGLONG Parameter3,
- ULONGLONG Parameter4
- )
- /*++
- Routine Description:
- This routine officially takes the system down after a fatal system error
- has occurred. This function does not return.
- Arguments:
- CrashCode - Supplies the reason for the system crash.
- CrashCodeString - Supplies the string corresponding to the given crash
- code. This parameter is generated by the macro, and should not be
- filled in directly.
- Parameter1 - Supplies an optional parameter regarding the crash.
- Parameter2 - Supplies an optional parameter regarding the crash.
- Parameter3 - Supplies an optional parameter regarding the crash.
- Parameter4 - Supplies an optional parameter regarding the crash.
- Return Value:
- None. This function does not return.
- --*/
- {
- RtlDebugPrint("\n\n *** Fatal System Error ***\n\n"
- "Error Code: %s (0x%x)\n"
- "Parameter1: 0x%08I64x\n"
- "Parameter2: 0x%08I64x\n"
- "Parameter3: 0x%08I64x\n"
- "Parameter4: 0x%08I64x\n\n",
- CrashCodeString,
- CrashCode,
- Parameter1,
- Parameter2,
- Parameter3,
- Parameter4);
- //
- // Spin forever.
- //
- while (TRUE) {
- RtlDebugBreak();
- }
- }
- KSTATUS
- HlSendIpi (
- IPI_TYPE IpiType,
- PPROCESSOR_SET Processors
- )
- /*++
- Routine Description:
- This routine sends an Inter-Processor Interrupt (IPI) to the given set of
- processors.
- Arguments:
- IpiType - Supplies the type of IPI to deliver.
- Processors - Supplies the set of processors to deliver the IPI to.
- Return Value:
- Status code.
- --*/
- {
- ASSERT(FALSE);
- return STATUS_NOT_SUPPORTED;
- }
- KSTATUS
- HlResetSystem (
- SYSTEM_RESET_TYPE ResetType
- )
- /*++
- Routine Description:
- This routine resets the system.
- Arguments:
- ResetType - Supplies the desired reset type. If the desired reset type is
- not supported, a cold reset will be attempted.
- Return Value:
- Does not return on success, the system is reset.
- STATUS_INVALID_PARAMETER if an invalid reset type was supplied.
- STATUS_NOT_SUPPORTED if the system cannot be reset.
- STATUS_UNSUCCESSFUL if the system did not reset.
- --*/
- {
- EFI_RESET_TYPE EfiResetType;
- switch (ResetType) {
- case SystemResetShutdown:
- EfiResetType = EfiResetShutdown;
- break;
- case SystemResetCold:
- EfiResetType = EfiResetCold;
- break;
- case SystemResetWarm:
- default:
- EfiResetType = EfiResetWarm;
- break;
- }
- if ((EfiRuntimeServices != NULL) &&
- (EfiRuntimeServices->ResetSystem != NULL)) {
- EfiResetSystem(EfiResetType, 0, 0, NULL);
- }
- return STATUS_UNSUCCESSFUL;
- }
- ULONGLONG
- HlQueryTimeCounter (
- VOID
- )
- /*++
- Routine Description:
- This routine queries the time counter hardware and returns a 64-bit
- monotonically non-decreasing value that represents the number of timer ticks
- since the system was started. This value will continue to count through all
- idle and sleep states.
- This routine can be called at any runlevel.
- Arguments:
- None.
- Return Value:
- Returns the number of timer ticks that have elapsed since the system was
- booted. The absolute time between successive ticks can be retrieved from the
- Query Time Counter Frequency function.
- --*/
- {
- return 0;
- }
- ULONGLONG
- HlQueryTimeCounterFrequency (
- VOID
- )
- /*++
- Routine Description:
- This routine returns the frequency of the time counter. This frequency will
- never change after it is set on boot.
- This routine can be called at any runlevel.
- Arguments:
- None.
- Return Value:
- Returns the frequency of the time counter, in Hertz.
- --*/
- {
- ASSERT(FALSE);
- return 1;
- }
- VOID
- HlBusySpin (
- ULONG Microseconds
- )
- /*++
- Routine Description:
- This routine spins for at least the given number of microseconds by
- repeatedly reading a hardware timer. This routine should be avoided if at
- all possible, as it simply burns CPU cycles.
- This routine can be called at any runlevel.
- Arguments:
- Microseconds - Supplies the number of microseconds to spin for.
- Return Value:
- Returns the frequency of the time counter, in Hertz.
- --*/
- {
- if ((EfiBootServices != NULL) && (EfiBootServices->Stall != NULL)) {
- EfiStall(Microseconds);
- }
- return;
- }
- KSTATUS
- SpGetProfilerData (
- PPROFILER_NOTIFICATION ProfilerNotification,
- PULONG Flags
- )
- /*++
- Routine Description:
- This routine fills the provided profiler notification with profiling data.
- A profiler consumer should call this routine to obtain data to send over
- the wire. It is assumed here that consumers will serialize consumption.
- Arguments:
- ProfilerNotification - Supplies a pointer to the profiler notification that
- is to be filled in with profiling data.
- Flags - Supplies a pointer to the types of profiling data the caller wants
- to collect. Upon return, the flags for the returned data will be
- returned.
- Return Value:
- Status code.
- --*/
- {
- ASSERT(FALSE);
- return STATUS_NOT_SUPPORTED;
- }
- ULONG
- SpGetProfilerDataStatus (
- VOID
- )
- /*++
- Routine Description:
- This routine determines if there is profiling data for the current
- processor that needs to be sent to a consumer.
- Arguments:
- None.
- Return Value:
- Returns a set of flags representing which types of profiling data are
- available. Returns zero if nothing is available.
- --*/
- {
- return 0;
- }
- //
- // --------------------------------------------------------- Internal Functions
- //
|