From bcec23ef89902330b1a93d418d2562c4819db0f5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 28 Mar 2022 15:17:07 -0400 Subject: [PATCH] Update hello.scratch to use namespacing struct --- src/hello/hello.d | 2 +- src/hello/scratch.d | 57 ++++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/hello/hello.d b/src/hello/hello.d index 3e58224..3ebab2c 100644 --- a/src/hello/hello.d +++ b/src/hello/hello.d @@ -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; diff --git a/src/hello/scratch.d b/src/hello/scratch.d index d949fa9..a076d77 100644 --- a/src/hello/scratch.d +++ b/src/hello/scratch.d @@ -3,34 +3,37 @@ */ module hello.scratch; -/* Scratch buffer. */ -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() +struct scratch { - return scratch.sizeof - scratch_used; -} + /* Scratch buffer. */ + private static align(4096) __gshared ubyte[1024 * 1024] scratch; -/** - * Get the current free scratch buffer address. - */ -ubyte * current() -{ - return &scratch[scratch_used]; -} + /* Number of scratch buffer bytes used. */ + private static __gshared size_t scratch_used; -/** - * Allocate pages from the scratch buffer. - */ -ubyte * alloc(size_t n = 1) -{ - ubyte * address = &scratch[scratch_used]; - scratch_used += 4096u * n; - return address; + /** + * Get the number of free bytes in the scratch buffer. + */ + public static size_t free() + { + return scratch.sizeof - scratch_used; + } + + /** + * 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; + } }