This is a rather large commit that is widely focused on cleaning things out of the 'junk drawer' that is src/include. Most notably, several things that were put in there because they needed somewhere where both the kernel, boot, and init could read them have been moved to a new lib, 'bootproto'. - Moved kernel_args.h and init_args.h to bootproto as kernel.h and init.h, respectively. - Moved counted.h and pointer_manipulation.h into util, renaming the latter to util/pointers.h. - Created a new src/include/arch for very arch-dependent definitions, and moved some kernel_memory.h constants like frame size, page table entry count, etc to arch/amd64/memory.h. Also created arch/memory.h which detects platform and includes the former. - Got rid of kernel_memory.h entirely in favor of a new, cog-based approach. The new definitions/memory_layout.csv lists memory regions in descending order from the top of memory, their sizes, and whether they are shared outside the kernel (ie, boot needs to know them). The new header bootproto/memory.h exposes the addresses of the shared regions, while the kernel's memory.h gains the start and size of all the regions. Also renamed the badly-named page-offset area the linear area. - The python build scripts got a few new features: the ability to parse the csv mentioned above in a new memory.py module; the ability to add dependencies to existing source files (The list of files that I had to pull out of the main list just to add them with the dependency on memory.h was getting too large. So I put them back into the sources list, and added the dependency post-hoc.); and the ability to reference 'source_root', 'build_root', and 'module_root' variables in .module files. - Some utility functions that were in the kernel's memory.h got moved to util/pointers.h and util/misc.h, and misc.h's byteswap was renamed byteswap32 to be more specific.
70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
#include "error.h"
|
|
#include "console.h"
|
|
#include "status.h"
|
|
|
|
namespace boot {
|
|
namespace error {
|
|
|
|
struct error_code_desc {
|
|
uefi::status code;
|
|
const wchar_t *name;
|
|
};
|
|
|
|
struct error_code_desc error_table[] = {
|
|
#define STATUS_ERROR(name, num) { uefi::status::name, L#name },
|
|
#define STATUS_WARNING(name, num) { uefi::status::name, L#name },
|
|
#include "uefi/errors.inc"
|
|
#undef STATUS_ERROR
|
|
#undef STATUS_WARNING
|
|
{ uefi::status::success, nullptr }
|
|
};
|
|
|
|
const wchar_t *
|
|
message(uefi::status status)
|
|
{
|
|
int32_t i = -1;
|
|
while (error_table[++i].name != nullptr) {
|
|
if (error_table[i].code == status) return error_table[i].name;
|
|
}
|
|
|
|
if (uefi::is_error(status))
|
|
return L"Unknown Error";
|
|
else
|
|
return L"Unknown Warning";
|
|
}
|
|
|
|
[[ noreturn ]] static void
|
|
cpu_assert(uefi::status s, const wchar_t *message, size_t line)
|
|
{
|
|
asm volatile (
|
|
"movq $0xeeeeeeebadbadbad, %%r8;"
|
|
"movq %0, %%r9;"
|
|
"movq %1, %%r10;"
|
|
"movq %2, %%r11;"
|
|
"movq $0, %%rdx;"
|
|
"divq %%rdx;"
|
|
:
|
|
: "r"((uint64_t)s), "r"(message), "r"(line)
|
|
: "rax", "rdx", "r8", "r9", "r10");
|
|
while (1) asm("hlt");
|
|
}
|
|
|
|
[[ noreturn ]] void
|
|
raise(uefi::status status, const wchar_t *message, size_t line)
|
|
{
|
|
if(status_line::fail(message, status))
|
|
while (1) asm("hlt");
|
|
else
|
|
cpu_assert(status, message, line);
|
|
}
|
|
|
|
|
|
} // namespace error
|
|
} // namespace boot
|
|
|
|
void debug_break()
|
|
{
|
|
volatile int go = 0;
|
|
while (!go);
|
|
}
|