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