mirror of
https://github.com/CloverHackyColor/CloverBootloader.git
synced 2024-11-10 09:40:53 +01:00
c1ce6aa406
Create displayFreeMemory(). Few renaming and details that doesn't change behavior.
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
/*
|
|
* posix_additions.cpp
|
|
*
|
|
* Created on: Feb 5, 2021
|
|
* Author: jief
|
|
*/
|
|
|
|
#include "posix_additions.h"
|
|
#include "stdio.h"
|
|
#include "stddef.h"
|
|
/*
|
|
* We need to use AsciiSPrint to be able to use %r and %g
|
|
*/
|
|
extern "C" {
|
|
//# include <Library/UefiLib.h>
|
|
# include <Library/PrintLib.h>
|
|
|
|
// UINTN
|
|
// EFIAPI
|
|
// AsciiSPrint (
|
|
// OUT CHAR8 *StartOfBuffer,
|
|
// IN UINTN BufferSize,
|
|
// IN CONST CHAR8 *FormatString,
|
|
// ...
|
|
// );
|
|
|
|
}
|
|
|
|
#include "../../cpp_foundation/XString.h"
|
|
|
|
static XString8 stdio_static_buf = XString8().takeValueFrom("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX "); // prealloc stdio_static_buf. It has to be at least 2 chars because of 'while ( n > size - 2 )' in strguid and efiStrError
|
|
|
|
const char* efiStrError(EFI_STATUS Status)
|
|
{
|
|
size_t size = stdio_static_buf.allocatedSize();
|
|
UINTN n = 0;
|
|
n = AsciiSPrint(stdio_static_buf.dataSized(size-1), size-1, "%r", Status); // dataSized(size)-1 is important to avoid stdio_static_buf grow by 1 at each call.
|
|
while ( n > size - 3 )
|
|
{
|
|
size += 10;
|
|
n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%r", Status);
|
|
}
|
|
return stdio_static_buf.s();
|
|
}
|
|
|
|
//
|
|
////this function print guid in LittleEndian format while we need BigEndian as Apple do
|
|
//const char* strguid(const EFI_GUID& guid)
|
|
//{
|
|
// size_t size = stdio_static_buf.allocatedSize();
|
|
// UINTN n = 0;
|
|
// n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%g", &guid);
|
|
// while ( n > size - 2 )
|
|
// {
|
|
// size += 10;
|
|
// n = AsciiSPrint(stdio_static_buf.dataSized(size), size, "%g", &guid);
|
|
// }
|
|
// return stdio_static_buf.s();
|
|
//}
|