mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:07:34 +00: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:
parent
334e039294
commit
7fc903b97a
6 changed files with 23 additions and 38 deletions
|
@ -46,6 +46,7 @@ extern "C" void asm_irq_entry();
|
||||||
asm(
|
asm(
|
||||||
".globl asm_irq_entry\n"
|
".globl asm_irq_entry\n"
|
||||||
"asm_irq_entry: \n"
|
"asm_irq_entry: \n"
|
||||||
|
" pushl $0x0\n"
|
||||||
" pusha\n"
|
" pusha\n"
|
||||||
" pushw %ds\n"
|
" pushw %ds\n"
|
||||||
" pushw %es\n"
|
" pushw %es\n"
|
||||||
|
@ -57,10 +58,11 @@ asm(
|
||||||
" popw %es\n"
|
" popw %es\n"
|
||||||
" popw %ds\n"
|
" popw %ds\n"
|
||||||
" popa\n"
|
" popa\n"
|
||||||
|
" add $0x4, %esp\n"
|
||||||
" iret\n");
|
" iret\n");
|
||||||
|
|
||||||
#define EH_ENTRY(ec) \
|
#define EH_ENTRY(ec) \
|
||||||
extern "C" void exception_##ec##_handler(RegisterDumpWithExceptionCode&); \
|
extern "C" void exception_##ec##_handler(RegisterDump&); \
|
||||||
extern "C" void exception_##ec##_entry(); \
|
extern "C" void exception_##ec##_entry(); \
|
||||||
asm( \
|
asm( \
|
||||||
".globl exception_" #ec "_entry\n" \
|
".globl exception_" #ec "_entry\n" \
|
||||||
|
@ -96,6 +98,7 @@ asm(
|
||||||
asm( \
|
asm( \
|
||||||
".globl exception_" #ec "_entry\n" \
|
".globl exception_" #ec "_entry\n" \
|
||||||
"exception_" #ec "_entry: \n" \
|
"exception_" #ec "_entry: \n" \
|
||||||
|
" pushl $0x0\n" \
|
||||||
" pusha\n" \
|
" pusha\n" \
|
||||||
" pushw %ds\n" \
|
" pushw %ds\n" \
|
||||||
" pushw %es\n" \
|
" pushw %es\n" \
|
||||||
|
@ -118,10 +121,10 @@ asm(
|
||||||
" popw %es\n" \
|
" popw %es\n" \
|
||||||
" popw %ds\n" \
|
" popw %ds\n" \
|
||||||
" popa\n" \
|
" popa\n" \
|
||||||
|
" add $0x4, %esp\n" \
|
||||||
" iret\n");
|
" iret\n");
|
||||||
|
|
||||||
template<typename DumpType>
|
static void dump(const RegisterDump& regs)
|
||||||
static void dump(const DumpType& regs)
|
|
||||||
{
|
{
|
||||||
u16 ss;
|
u16 ss;
|
||||||
u32 esp;
|
u32 esp;
|
||||||
|
@ -133,9 +136,7 @@ static void dump(const DumpType& regs)
|
||||||
esp = regs.esp_if_crossRing;
|
esp = regs.esp_if_crossRing;
|
||||||
}
|
}
|
||||||
|
|
||||||
if constexpr (IsSame<DumpType, RegisterDumpWithExceptionCode>::value) {
|
kprintf("exception code: %04x\n", regs.exception_code);
|
||||||
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(" 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);
|
kprintf(" stk=%04x:%08x\n", ss, esp);
|
||||||
if (current)
|
if (current)
|
||||||
|
@ -157,8 +158,7 @@ static void dump(const DumpType& regs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename RegisterDumpType>
|
static void handle_crash(RegisterDump& regs, const char* description, int signal)
|
||||||
static void handle_crash(RegisterDumpType& regs, const char* description, int signal)
|
|
||||||
{
|
{
|
||||||
if (!current) {
|
if (!current) {
|
||||||
kprintf("%s with !current\n", description);
|
kprintf("%s with !current\n", description);
|
||||||
|
@ -195,7 +195,7 @@ void exception_0_handler(RegisterDump& regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
EH_ENTRY(13);
|
EH_ENTRY(13);
|
||||||
void exception_13_handler(RegisterDumpWithExceptionCode& regs)
|
void exception_13_handler(RegisterDump& regs)
|
||||||
{
|
{
|
||||||
handle_crash(regs, "General protection fault", SIGSEGV);
|
handle_crash(regs, "General protection fault", SIGSEGV);
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ void exception_7_handler(RegisterDump& regs)
|
||||||
|
|
||||||
// 14: Page Fault
|
// 14: Page Fault
|
||||||
EH_ENTRY(14);
|
EH_ENTRY(14);
|
||||||
void exception_14_handler(RegisterDumpWithExceptionCode& regs)
|
void exception_14_handler(RegisterDump& regs)
|
||||||
{
|
{
|
||||||
ASSERT(current);
|
ASSERT(current);
|
||||||
|
|
||||||
|
|
|
@ -333,29 +333,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct [[gnu::packed]] RegisterDump
|
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 ss;
|
||||||
u16 gs;
|
u16 gs;
|
||||||
|
@ -380,6 +357,7 @@ struct [[gnu::packed]] RegisterDumpWithExceptionCode
|
||||||
u16 ss_if_crossRing;
|
u16 ss_if_crossRing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct [[gnu::aligned(16)]] FPUState
|
struct [[gnu::aligned(16)]] FPUState
|
||||||
{
|
{
|
||||||
u8 buffer[512];
|
u8 buffer[512];
|
||||||
|
|
|
@ -12,6 +12,7 @@ extern "C" void timer_interrupt_handler(RegisterDump&);
|
||||||
asm(
|
asm(
|
||||||
".globl timer_interrupt_entry \n"
|
".globl timer_interrupt_entry \n"
|
||||||
"timer_interrupt_entry: \n"
|
"timer_interrupt_entry: \n"
|
||||||
|
" pushl $0x0\n"
|
||||||
" pusha\n"
|
" pusha\n"
|
||||||
" pushw %ds\n"
|
" pushw %ds\n"
|
||||||
" pushw %es\n"
|
" pushw %es\n"
|
||||||
|
@ -34,6 +35,7 @@ asm(
|
||||||
" popw %es\n"
|
" popw %es\n"
|
||||||
" popw %ds\n"
|
" popw %ds\n"
|
||||||
" popa\n"
|
" popa\n"
|
||||||
|
" add $0x4, %esp\n"
|
||||||
" iret\n");
|
" iret\n");
|
||||||
|
|
||||||
static u32 s_ticks_this_second;
|
static u32 s_ticks_this_second;
|
||||||
|
|
|
@ -864,9 +864,12 @@ int Process::sys$sigreturn(RegisterDump& registers)
|
||||||
current->m_signal_mask = *stack_ptr;
|
current->m_signal_mask = *stack_ptr;
|
||||||
stack_ptr++;
|
stack_ptr++;
|
||||||
|
|
||||||
//pop edi, esi, ebp, esp, ebx, edx, ecx, eax and eip
|
//pop edi, esi, ebp, esp, ebx, edx, ecx and eax
|
||||||
memcpy(®isters.edi, stack_ptr, 9 * sizeof(u32));
|
memcpy(®isters.edi, stack_ptr, 8 * sizeof(u32));
|
||||||
stack_ptr += 9;
|
stack_ptr += 8;
|
||||||
|
|
||||||
|
registers.eip = *stack_ptr;
|
||||||
|
stack_ptr++;
|
||||||
|
|
||||||
registers.eflags = *stack_ptr;
|
registers.eflags = *stack_ptr;
|
||||||
stack_ptr++;
|
stack_ptr++;
|
||||||
|
|
|
@ -561,8 +561,8 @@ void Scheduler::timer_tick(RegisterDump& regs)
|
||||||
outgoing_tss.eflags = regs.eflags;
|
outgoing_tss.eflags = regs.eflags;
|
||||||
|
|
||||||
// Compute process stack pointer.
|
// Compute process stack pointer.
|
||||||
// Add 12 for CS, EIP, EFLAGS (interrupt mechanic)
|
// Add 16 for CS, EIP, EFLAGS, exception code (interrupt mechanic)
|
||||||
outgoing_tss.esp = regs.esp + 12;
|
outgoing_tss.esp = regs.esp + 16;
|
||||||
outgoing_tss.ss = regs.ss;
|
outgoing_tss.ss = regs.ss;
|
||||||
|
|
||||||
if ((outgoing_tss.cs & 3) != 0) {
|
if ((outgoing_tss.cs & 3) != 0) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ extern volatile RegisterDump* syscallRegDump;
|
||||||
asm(
|
asm(
|
||||||
".globl syscall_trap_handler \n"
|
".globl syscall_trap_handler \n"
|
||||||
"syscall_trap_handler:\n"
|
"syscall_trap_handler:\n"
|
||||||
|
" pushl $0x0\n"
|
||||||
" pusha\n"
|
" pusha\n"
|
||||||
" pushw %ds\n"
|
" pushw %ds\n"
|
||||||
" pushw %es\n"
|
" pushw %es\n"
|
||||||
|
@ -35,6 +36,7 @@ asm(
|
||||||
" popw %es\n"
|
" popw %es\n"
|
||||||
" popw %ds\n"
|
" popw %ds\n"
|
||||||
" popa\n"
|
" popa\n"
|
||||||
|
" add $0x4, %esp\n"
|
||||||
" iret\n");
|
" iret\n");
|
||||||
|
|
||||||
namespace Syscall {
|
namespace Syscall {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue