Compare commits

...

2 Commits

3 changed files with 180 additions and 174 deletions

View File

@ -7,6 +7,8 @@ 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.
* *
@ -15,7 +17,7 @@ import core.stdc.stdarg;
* @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 size_t format_hex(CHAR16 * s, ulong v, bool ptr) private static size_t format_hex(CHAR16 * s, ulong v, bool ptr)
{ {
string hex_chars = "0123456789ABCDEF"; string hex_chars = "0123456789ABCDEF";
bool print = ptr; bool print = ptr;
@ -45,7 +47,7 @@ private size_t format_hex(CHAR16 * s, ulong v, bool ptr)
* @param s String buffer. * @param s String buffer.
* @param v Value to format. * @param v Value to format.
*/ */
private size_t format_dec(CHAR16 * s, ulong v) private static size_t format_dec(CHAR16 * s, ulong v)
{ {
string dec_chars = "0123456789"; string dec_chars = "0123456789";
bool print; bool print;
@ -70,7 +72,7 @@ private size_t format_dec(CHAR16 * s, ulong v)
* @param s Format string. * @param s Format string.
* @param args Variable arguments structure. * @param args Variable arguments structure.
*/ */
void write(string s, va_list args) public static 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;
@ -134,7 +136,7 @@ void write(string s, va_list args)
* *
* @param s Format string. * @param s Format string.
*/ */
extern (C) void write(string s, ...) public static extern (C) void write(string s, ...)
{ {
va_list args; va_list args;
va_start(args, s); va_start(args, s);
@ -147,7 +149,7 @@ extern (C) void write(string s, ...)
* *
* @param s Format string. * @param s Format string.
*/ */
extern (C) void writeln(string s, ...) public static extern (C) void writeln(string s, ...)
{ {
va_list args; va_list args;
va_start(args, s); va_start(args, s);
@ -159,7 +161,7 @@ extern (C) void writeln(string s, ...)
/** /**
* 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.
*/ */
void wait_key() public static void wait_key()
{ {
writeln("Press any key..."); writeln("Press any key...");
st.ConIn.Reset(st.ConIn, FALSE); st.ConIn.Reset(st.ConIn, FALSE);
@ -172,7 +174,8 @@ void wait_key()
/** /**
* Clear the console. * Clear the console.
*/ */
void clear() public static 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 console = hello.console; import hello.console;
import scratch = hello.scratch; import 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,16 +3,18 @@
*/ */
module hello.scratch; module hello.scratch;
struct scratch
{
/* Scratch buffer. */ /* Scratch buffer. */
private align(4096) __gshared ubyte[1024 * 1024] scratch; private static align(4096) __gshared ubyte[1024 * 1024] scratch;
/* Number of scratch buffer bytes used. */ /* Number of scratch buffer bytes used. */
private __gshared size_t scratch_used; private static __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.
*/ */
size_t free() public static size_t free()
{ {
return scratch.sizeof - scratch_used; return scratch.sizeof - scratch_used;
} }
@ -20,7 +22,7 @@ size_t free()
/** /**
* Get the current free scratch buffer address. * Get the current free scratch buffer address.
*/ */
ubyte * current() public static ubyte * current()
{ {
return &scratch[scratch_used]; return &scratch[scratch_used];
} }
@ -28,9 +30,10 @@ ubyte * current()
/** /**
* Allocate pages from the scratch buffer. * Allocate pages from the scratch buffer.
*/ */
ubyte * alloc(size_t n = 1) public static 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;
} }
}