Update hello.scratch to use namespacing struct

This commit is contained in:
Josh Holtrop 2022-03-28 15:17:07 -04:00
parent d86745d91d
commit bcec23ef89
2 changed files with 31 additions and 28 deletions

View File

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

View File

@ -3,34 +3,37 @@
*/
module hello.scratch;
/* Scratch buffer. */
private align(4096) __gshared ubyte[1024 * 1024] scratch;
struct scratch
{
/* Scratch buffer. */
private static align(4096) __gshared ubyte[1024 * 1024] scratch;
/* Number of scratch buffer bytes used. */
private __gshared size_t scratch_used;
/* Number of scratch buffer bytes used. */
private static __gshared size_t scratch_used;
/**
/**
* Get the number of free bytes in the scratch buffer.
*/
size_t free()
{
public static size_t free()
{
return scratch.sizeof - scratch_used;
}
}
/**
/**
* Get the current free scratch buffer address.
*/
ubyte * current()
{
public static ubyte * current()
{
return &scratch[scratch_used];
}
}
/**
/**
* 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];
scratch_used += 4096u * n;
return address;
}
}