1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-10 10:01:13 +09:00

Kernel: Add exception_code to RegisterDump.

Added the exception_code field to RegisterDump, removing the need
for RegisterDumpWithExceptionCode. To accomplish this, I had to
push a dummy exception code during some interrupt entries to properly
pad out the RegisterDump. Note that we also needed to change some code
in sys$sigreturn to deal with the new RegisterDump layout.
This commit is contained in:
Drew Stratford 2019-10-05 03:31:34 +13:00 committed by Andreas Kling
parent 334e039294
commit 7fc903b97a
Notes: sideshowbarker 2024-07-19 11:45:52 +09:00
6 changed files with 23 additions and 38 deletions

View file

@ -46,6 +46,7 @@ extern "C" void asm_irq_entry();
asm(
".globl asm_irq_entry\n"
"asm_irq_entry: \n"
" pushl $0x0\n"
" pusha\n"
" pushw %ds\n"
" pushw %es\n"
@ -57,10 +58,11 @@ asm(
" popw %es\n"
" popw %ds\n"
" popa\n"
" add $0x4, %esp\n"
" iret\n");
#define EH_ENTRY(ec) \
extern "C" void exception_##ec##_handler(RegisterDumpWithExceptionCode&); \
extern "C" void exception_##ec##_handler(RegisterDump&); \
extern "C" void exception_##ec##_entry(); \
asm( \
".globl exception_" #ec "_entry\n" \
@ -96,6 +98,7 @@ asm(
asm( \
".globl exception_" #ec "_entry\n" \
"exception_" #ec "_entry: \n" \
" pushl $0x0\n" \
" pusha\n" \
" pushw %ds\n" \
" pushw %es\n" \
@ -118,10 +121,10 @@ asm(
" popw %es\n" \
" popw %ds\n" \
" popa\n" \
" add $0x4, %esp\n" \
" iret\n");
template<typename DumpType>
static void dump(const DumpType& regs)
static void dump(const RegisterDump& regs)
{
u16 ss;
u32 esp;
@ -133,9 +136,7 @@ static void dump(const DumpType& regs)
esp = regs.esp_if_crossRing;
}
if constexpr (IsSame<DumpType, RegisterDumpWithExceptionCode>::value) {
kprintf("exception code: %04x\n", regs.exception_code);
}
kprintf(" pc=%04x:%08x ds=%04x es=%04x fs=%04x gs=%04x\n", regs.cs, regs.eip, regs.ds, regs.es, regs.fs, regs.gs);
kprintf(" stk=%04x:%08x\n", ss, esp);
if (current)
@ -157,8 +158,7 @@ static void dump(const DumpType& regs)
}
}
template<typename RegisterDumpType>
static void handle_crash(RegisterDumpType& regs, const char* description, int signal)
static void handle_crash(RegisterDump& regs, const char* description, int signal)
{
if (!current) {
kprintf("%s with !current\n", description);
@ -195,7 +195,7 @@ void exception_0_handler(RegisterDump& regs)
}
EH_ENTRY(13);
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
void exception_13_handler(RegisterDump& regs)
{
handle_crash(regs, "General protection fault", SIGSEGV);
}
@ -232,7 +232,7 @@ void exception_7_handler(RegisterDump& regs)
// 14: Page Fault
EH_ENTRY(14);
void exception_14_handler(RegisterDumpWithExceptionCode& regs)
void exception_14_handler(RegisterDump& regs)
{
ASSERT(current);

View file

@ -333,29 +333,6 @@ private:
};
struct [[gnu::packed]] RegisterDump
{
u16 ss;
u16 gs;
u16 fs;
u16 es;
u16 ds;
u32 edi;
u32 esi;
u32 ebp;
u32 esp;
u32 ebx;
u32 edx;
u32 ecx;
u32 eax;
u32 eip;
u16 cs;
u16 __csPadding;
u32 eflags;
u32 esp_if_crossRing;
u16 ss_if_crossRing;
};
struct [[gnu::packed]] RegisterDumpWithExceptionCode
{
u16 ss;
u16 gs;
@ -380,6 +357,7 @@ struct [[gnu::packed]] RegisterDumpWithExceptionCode
u16 ss_if_crossRing;
};
struct [[gnu::aligned(16)]] FPUState
{
u8 buffer[512];

View file

@ -12,6 +12,7 @@ extern "C" void timer_interrupt_handler(RegisterDump&);
asm(
".globl timer_interrupt_entry \n"
"timer_interrupt_entry: \n"
" pushl $0x0\n"
" pusha\n"
" pushw %ds\n"
" pushw %es\n"
@ -34,6 +35,7 @@ asm(
" popw %es\n"
" popw %ds\n"
" popa\n"
" add $0x4, %esp\n"
" iret\n");
static u32 s_ticks_this_second;

View file

@ -864,9 +864,12 @@ int Process::sys$sigreturn(RegisterDump& registers)
current->m_signal_mask = *stack_ptr;
stack_ptr++;
//pop edi, esi, ebp, esp, ebx, edx, ecx, eax and eip
memcpy(&registers.edi, stack_ptr, 9 * sizeof(u32));
stack_ptr += 9;
//pop edi, esi, ebp, esp, ebx, edx, ecx and eax
memcpy(&registers.edi, stack_ptr, 8 * sizeof(u32));
stack_ptr += 8;
registers.eip = *stack_ptr;
stack_ptr++;
registers.eflags = *stack_ptr;
stack_ptr++;

View file

@ -561,8 +561,8 @@ void Scheduler::timer_tick(RegisterDump& regs)
outgoing_tss.eflags = regs.eflags;
// Compute process stack pointer.
// Add 12 for CS, EIP, EFLAGS (interrupt mechanic)
outgoing_tss.esp = regs.esp + 12;
// Add 16 for CS, EIP, EFLAGS, exception code (interrupt mechanic)
outgoing_tss.esp = regs.esp + 16;
outgoing_tss.ss = regs.ss;
if ((outgoing_tss.cs & 3) != 0) {

View file

@ -13,6 +13,7 @@ extern volatile RegisterDump* syscallRegDump;
asm(
".globl syscall_trap_handler \n"
"syscall_trap_handler:\n"
" pushl $0x0\n"
" pusha\n"
" pushw %ds\n"
" pushw %es\n"
@ -35,6 +36,7 @@ asm(
" popw %es\n"
" popw %ds\n"
" popa\n"
" add $0x4, %esp\n"
" iret\n");
namespace Syscall {