Compare commits

..

No commits in common. "f904ec2b48cfbae8b10947f2bc178d14a3bc8758" and "d86745d91d392ebc6f401e4982774b78882d0cc6" have entirely different histories.

3 changed files with 174 additions and 180 deletions

View File

@ -7,8 +7,6 @@ import uefi;
import hello.hello; import hello.hello;
import core.stdc.stdarg; import core.stdc.stdarg;
struct console
{
/** /**
* Format a hexadecimal value to a string. * Format a hexadecimal value to a string.
* *
@ -17,7 +15,7 @@ struct console
* @param ptr If true, always output all 16 digits, and separate the upper and * @param ptr If true, always output all 16 digits, and separate the upper and
* lower halves with an underscore. * lower halves with an underscore.
*/ */
private static size_t format_hex(CHAR16 * s, ulong v, bool ptr) private size_t format_hex(CHAR16 * s, ulong v, bool ptr)
{ {
string hex_chars = "0123456789ABCDEF"; string hex_chars = "0123456789ABCDEF";
bool print = ptr; bool print = ptr;
@ -47,7 +45,7 @@ struct console
* @param s String buffer. * @param s String buffer.
* @param v Value to format. * @param v Value to format.
*/ */
private static size_t format_dec(CHAR16 * s, ulong v) private size_t format_dec(CHAR16 * s, ulong v)
{ {
string dec_chars = "0123456789"; string dec_chars = "0123456789";
bool print; bool print;
@ -72,7 +70,7 @@ struct console
* @param s Format string. * @param s Format string.
* @param args Variable arguments structure. * @param args Variable arguments structure.
*/ */
public static void write(string s, va_list args) void write(string s, va_list args)
{ {
__gshared static CHAR16[256] s16; __gshared static CHAR16[256] s16;
size_t i = 0u; size_t i = 0u;
@ -136,7 +134,7 @@ struct console
* *
* @param s Format string. * @param s Format string.
*/ */
public static extern (C) void write(string s, ...) extern (C) void write(string s, ...)
{ {
va_list args; va_list args;
va_start(args, s); va_start(args, s);
@ -149,7 +147,7 @@ struct console
* *
* @param s Format string. * @param s Format string.
*/ */
public static extern (C) void writeln(string s, ...) extern (C) void writeln(string s, ...)
{ {
va_list args; va_list args;
va_start(args, s); va_start(args, s);
@ -161,7 +159,7 @@ struct console
/** /**
* Write a message to press any key and wait for a key to be pressed. * Write a message to press any key and wait for a key to be pressed.
*/ */
public static void wait_key() void wait_key()
{ {
writeln("Press any key..."); writeln("Press any key...");
st.ConIn.Reset(st.ConIn, FALSE); st.ConIn.Reset(st.ConIn, FALSE);
@ -174,8 +172,7 @@ struct console
/** /**
* Clear the console. * Clear the console.
*/ */
public static void clear() void clear()
{ {
st.ConOut.ClearScreen(st.ConOut); st.ConOut.ClearScreen(st.ConOut);
} }
}

View File

@ -4,8 +4,8 @@
module hello.hello; module hello.hello;
import uefi; import uefi;
import hello.console; import console = hello.console;
import hello.scratch; import scratch = hello.scratch;
import hulk.bootinfo; import hulk.bootinfo;
import hulk.header; import hulk.header;
import hos.page_table; import hos.page_table;

View File

@ -3,18 +3,16 @@
*/ */
module hello.scratch; module hello.scratch;
struct scratch
{
/* Scratch buffer. */ /* Scratch buffer. */
private static align(4096) __gshared ubyte[1024 * 1024] scratch; private align(4096) __gshared ubyte[1024 * 1024] scratch;
/* Number of scratch buffer bytes used. */ /* Number of scratch buffer bytes used. */
private static __gshared size_t scratch_used; private __gshared size_t scratch_used;
/** /**
* Get the number of free bytes in the scratch buffer. * Get the number of free bytes in the scratch buffer.
*/ */
public static size_t free() size_t free()
{ {
return scratch.sizeof - scratch_used; return scratch.sizeof - scratch_used;
} }
@ -22,7 +20,7 @@ struct scratch
/** /**
* Get the current free scratch buffer address. * Get the current free scratch buffer address.
*/ */
public static ubyte * current() ubyte * current()
{ {
return &scratch[scratch_used]; return &scratch[scratch_used];
} }
@ -30,10 +28,9 @@ struct scratch
/** /**
* Allocate pages from the scratch buffer. * Allocate pages from the scratch buffer.
*/ */
public static ubyte * alloc(size_t n = 1) ubyte * alloc(size_t n = 1)
{ {
ubyte * address = &scratch[scratch_used]; ubyte * address = &scratch[scratch_used];
scratch_used += 4096u * n; scratch_used += 4096u * n;
return address; return address;
} }
}