Add console, klog, and writef modules.
They are not complete, but adding to checkpoint progress.
This commit is contained in:
1 parent
e214a9c3de
commit
06242a0c9f
5 files changed
+373
No files matched your search
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* HULK Kernel Log buffer.
|
||||
*/
|
||||
module hulk.klog;
|
||||
|
||||
import core.stdc.stdarg;
|
||||
import hulk.console;
|
||||
static import hulk.writef;
|
||||
|
||||
/**
|
||||
* Kernel buffer size log.
|
||||
* 16 gives a kernel buffer size of 64KB.
|
||||
*/
|
||||
enum size_t KLOG_SIZE_LOG = 16u;
|
||||
|
||||
/** Kernel buffer size. */
|
||||
enum size_t KLOG_SIZE = 1u << KLOG_SIZE_LOG;
|
||||
|
||||
/** Kernel log buffer. */
|
||||
private __gshared align(4096) char[KLOG_SIZE] klog_buffer;
|
||||
|
||||
/** Write index in the kernel log buffer. */
|
||||
private __gshared size_t klog_index;
|
||||
|
||||
/** Pointer to the console to use for kernel log output. */
|
||||
private __gshared Console * console;
|
||||
|
||||
/**
|
||||
* Initialize the klog module.
|
||||
*
|
||||
* @param console Pointer to the Console to use for kernel output.
|
||||
*/
|
||||
void initialize(Console * console)
|
||||
{
|
||||
.console = console;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string to the kernel log.
|
||||
*
|
||||
* @param s Format string.
|
||||
* @param args Variable arguments structure.
|
||||
*/
|
||||
void writef(string s, va_list args)
|
||||
{
|
||||
hulk.writef.writef(s, args, function void(ubyte ch) {
|
||||
console.write(ch);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string to the kernel log.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
extern (C) void writef(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
writef(s, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a formatted string and newline to the console.
|
||||
*
|
||||
* @param s Format string.
|
||||
*/
|
||||
extern (C) void writefln(string s, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, s);
|
||||
writef(s, args);
|
||||
writef("\n", args);
|
||||
va_end(args);
|
||||
}
|
||||
Reference in new issue
Block a user