Rename hello.output to hello.console
This commit is contained in:
parent
79b34477ed
commit
1e00d7a9e9
@ -1,9 +1,20 @@
|
||||
module hello.output;
|
||||
/**
|
||||
* HELLO console support.
|
||||
*/
|
||||
module hello.console;
|
||||
|
||||
import uefi;
|
||||
import hello.hello;
|
||||
import core.stdc.stdarg;
|
||||
|
||||
/**
|
||||
* Format a hexadecimal value to a string.
|
||||
*
|
||||
* @param s String buffer.
|
||||
* @param v Value to format.
|
||||
* @param ptr If true, always output all 16 digits, and separate the upper and
|
||||
* lower halves with an underscore.
|
||||
*/
|
||||
private size_t format_hex(CHAR16 * s, ulong v, bool ptr)
|
||||
{
|
||||
string hex_chars = "0123456789ABCDEF";
|
||||
@ -28,6 +39,12 @@ private size_t format_hex(CHAR16 * s, ulong v, bool ptr)
|
||||
return si;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a decimal value to a string.
|
||||
*
|
||||
* @param s String buffer.
|
||||
* @param v Value to format.
|
||||
*/
|
||||
private size_t format_dec(CHAR16 * s, ulong v)
|
||||
{
|
||||
string dec_chars = "0123456789";
|
||||
@ -47,6 +64,12 @@ private size_t format_dec(CHAR16 * s, ulong v)
|
||||
return buf_i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
* @param args Variable arguments structure.
|
||||
*/
|
||||
void write(string s, va_list args)
|
||||
{
|
||||
__gshared static CHAR16[256] s16;
|
||||
@ -106,6 +129,11 @@ void write(string s, va_list args)
|
||||
st.ConOut.OutputString(st.ConOut, &s16[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
extern (C) void write(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -114,6 +142,11 @@ extern (C) void write(string s, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
extern (C) void writeln(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -122,3 +155,24 @@ extern (C) void writeln(string s, ...)
|
||||
write("\r\n", args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a message to press any key and wait for a key to be pressed.
|
||||
*/
|
||||
void wait_key()
|
||||
{
|
||||
writeln("Press any key...");
|
||||
st.ConIn.Reset(st.ConIn, FALSE);
|
||||
EFI_INPUT_KEY key;
|
||||
while (st.ConIn.ReadKeyStroke(st.ConIn, &key) == EFI_NOT_READY)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the console.
|
||||
*/
|
||||
void clear()
|
||||
{
|
||||
st.ConOut.ClearScreen(st.ConOut);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
module hello.hello;
|
||||
|
||||
import uefi;
|
||||
import hello.output;
|
||||
import console = hello.console;
|
||||
import hello.scratch;
|
||||
import hulk.bootinfo;
|
||||
import hos.page_table;
|
||||
@ -14,16 +14,6 @@ __gshared UINTN memory_map_key;
|
||||
extern extern(C) __gshared ubyte hulk_start;
|
||||
extern extern(C) __gshared ubyte hulk_end;
|
||||
|
||||
private void wait_key()
|
||||
{
|
||||
writeln("Press any key...");
|
||||
st.ConIn.Reset(st.ConIn, FALSE);
|
||||
EFI_INPUT_KEY key;
|
||||
while (st.ConIn.ReadKeyStroke(st.ConIn, &key) == EFI_NOT_READY)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private bool in_qemu()
|
||||
{
|
||||
ulong * firmware_vendor = cast(ulong *) st.FirmwareVendor;
|
||||
@ -45,7 +35,7 @@ private bool set_graphics_mode()
|
||||
&gop_guid, null, &buffer_size, handles);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
writeln("LocateHandle: error %x", status);
|
||||
console.writeln("LocateHandle: error %x", status);
|
||||
return false;
|
||||
}
|
||||
EFI_HANDLE gop_handle = handles[0];
|
||||
@ -54,12 +44,12 @@ private bool set_graphics_mode()
|
||||
&gop_guid, &gop_interface);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
writeln("HandleProtocol: error %x", status);
|
||||
console.writeln("HandleProtocol: error %x", status);
|
||||
return false;
|
||||
}
|
||||
if (gop_interface == null)
|
||||
{
|
||||
writeln("null interface from HandleProtocol");
|
||||
console.writeln("null interface from HandleProtocol");
|
||||
return false;
|
||||
}
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL * gop = cast(EFI_GRAPHICS_OUTPUT_PROTOCOL *)gop_interface;
|
||||
@ -81,7 +71,7 @@ private bool set_graphics_mode()
|
||||
}
|
||||
if ((status = gop.SetMode(gop, best_mode_number)) != EFI_SUCCESS)
|
||||
{
|
||||
writeln("SetMode: Error %x\n", status);
|
||||
console.writeln("SetMode: Error %x\n", status);
|
||||
return false;
|
||||
}
|
||||
bootinfo.fb.buffer = cast(uint *)gop.Mode.FrameBufferBase;
|
||||
@ -106,7 +96,7 @@ private ulong get_memory_map()
|
||||
&descriptor_version);
|
||||
if (status != EFI_SUCCESS)
|
||||
{
|
||||
writeln("GetMemoryMap: Error %x", status);
|
||||
console.writeln("GetMemoryMap: Error %x", status);
|
||||
return 0u;
|
||||
}
|
||||
ulong max_physical_address;
|
||||
@ -116,7 +106,7 @@ private ulong get_memory_map()
|
||||
{
|
||||
if (count > bootinfo.memory_map.length)
|
||||
{
|
||||
writeln("Memory map too large");
|
||||
console.writeln("Memory map too large");
|
||||
for (;;)
|
||||
{
|
||||
}
|
||||
@ -263,14 +253,15 @@ extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
|
||||
{
|
||||
.st = st;
|
||||
|
||||
st.ConOut.ClearScreen(st.ConOut);
|
||||
console.clear();
|
||||
|
||||
writeln("HELLO, HOS EFI Lightweight LOader, v0.1.0");
|
||||
writeln("Firmware vendor: '%S', version: 0x%x", st.FirmwareVendor, st.FirmwareVendor);
|
||||
console.writeln("HELLO, HOS EFI Lightweight LOader, v0.1.0");
|
||||
console.writeln("Firmware vendor: '%S', version: 0x%x", st.FirmwareVendor, st.FirmwareVendor);
|
||||
wait_key();
|
||||
|
||||
if (!set_graphics_mode())
|
||||
{
|
||||
wait_key();
|
||||
console.wait_key();
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@ -288,8 +279,8 @@ extern (C) EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * st)
|
||||
{
|
||||
break;
|
||||
}
|
||||
writeln("ExitBootServices: Error %x", status);
|
||||
wait_key();
|
||||
console.writeln("ExitBootServices: Error %x", status);
|
||||
console.wait_key();
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user