Update hello.scratch to use namespacing struct
This commit is contained in:
parent
d86745d91d
commit
bcec23ef89
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user