[panic] Add separate kernel-mode panic handler

Created the framework for using different loadable panic handlers,
loaded by the bootloader. Initial panic handler is panic.serial, which
contains its own serial driver and stacktrace code.

Other related changes:

- Asserts are now based on the NMI handler - panic handlers get
  installed as the NMI interrupt handler
- Changed symbol table generation: now use nm's own demangling and
  sorting, and include symbol size in the table
- Move the linker script argument out of the kernel target, and into the
  kernel's specific module, so that other programs (ie, panic handlers)
  can use the kernel target as well
- Some asm changes to boot.s to help GDB see stack frames - but this
  might not actually be all that useful
- Renamed user_rsp to just rsp in cpu_state - everything in there is
  describing the 'user' state
This commit is contained in:
Justin C. Miller
2021-08-01 14:03:10 -07:00
parent fce22b0d35
commit ea9d20a250
37 changed files with 462 additions and 225 deletions

View File

@@ -33,6 +33,8 @@ const loader::program_desc kern_desc = {L"kernel", L"jsix.elf"};
const loader::program_desc init_desc = {L"init server", L"srv.init.elf"};
const loader::program_desc fb_driver = {L"UEFI framebuffer driver", L"drv.uefi_fb.elf"};
const loader::program_desc panic_handler = {L"Serial panic handler", L"panic.serial.elf"};
const loader::program_desc extra_programs[] = {
{L"test application", L"testapp.elf"},
};
@@ -86,16 +88,17 @@ load_resources(init::args *args, video::screen *screen, uefi::handle image, uefi
loader::load_module(disk, fb_driver);
}
args->symbol_table = loader::load_file(disk, {L"symbol table", L"symbol_table.dat"});
buffer symbol_table = loader::load_file(disk, {L"symbol table", L"symbol_table.dat"});
args->symbol_table = reinterpret_cast<uintptr_t>(symbol_table.pointer);
args->kernel = loader::load_program(disk, kern_desc, true);
args->init = loader::load_program(disk, init_desc);
args->panic = loader::load_program(disk, panic_handler);
for (auto &desc : extra_programs)
loader::load_module(disk, desc);
loader::verify_kernel_header(*args->kernel);
}
memory::efi_mem_map
@@ -144,15 +147,14 @@ efi_main(uefi::handle image, uefi::system_table *st)
status_bar status {screen}; // Switch to fb status display
// Map the kernel to the appropriate address
init::program &kernel = *args->kernel;
for (auto &section : kernel.sections)
paging::map_section(args, section);
// Map the kernel and panic handler to the appropriate addresses
paging::map_program(args, *args->kernel);
paging::map_program(args, *args->panic);
memory::fix_frame_blocks(args);
init::entrypoint kentry =
reinterpret_cast<init::entrypoint>(kernel.entrypoint);
reinterpret_cast<init::entrypoint>(args->kernel->entrypoint);
//status.next();
hw::setup_control_regs();
@@ -161,7 +163,6 @@ efi_main(uefi::handle image, uefi::system_table *st)
change_pointer(args);
change_pointer(args->pml4);
change_pointer(args->symbol_table.pointer);
change_pointer(args->kernel);
change_pointer(args->kernel->sections.pointer);

View File

@@ -265,5 +265,14 @@ map_section(
has_flag(section.type, section_flags::execute));
}
void
map_program(
kernel::init::args *args,
kernel::init::program &program)
{
for (auto &section : program.sections)
paging::map_section(args, section);
}
} // namespace paging
} // namespace boot

View File

@@ -50,14 +50,13 @@ void map_pages(
uintptr_t phys, uintptr_t virt,
size_t count, bool write_flag, bool exe_flag);
/// Map a program section in physical memory to its virtual address in the
/// given page tables.
/// Map the sections of a program in physical memory to their virtual memory
/// addresses in the given page tables.
/// \arg args The kernel args struct, used for the page table cache and pml4
/// \arg section The program section to load
void map_section(
/// \arg program The program to load
void map_program(
kernel::init::args *args,
const kernel::init::program_section &section);
kernel::init::program &program);
} // namespace paging
} // namespace boot