From a0d909af75ef5a9ecdedc167c3d083322ce59fcb Mon Sep 17 00:00:00 2001 From: NAKAMURA Gou Date: Tue, 17 Feb 2015 11:23:25 +0900 Subject: [PATCH] add supports for dump analyzer --- arch/x86/kernel/cpu.c | 2 ++ arch/x86/kernel/include/cpulocal.h | 5 +++- arch/x86/kernel/interrupt.S | 43 ++++++++++++++++++++++++++++++ arch/x86/kernel/syscall.c | 14 ++++++++++ kernel/Makefile.build.in | 2 +- kernel/config/builtin-x86.lds | 4 --- 6 files changed, 64 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/cpu.c b/arch/x86/kernel/cpu.c index 0c260b61..e1908ac4 100644 --- a/arch/x86/kernel/cpu.c +++ b/arch/x86/kernel/cpu.c @@ -112,6 +112,7 @@ void reload_idt(void) } static struct list_head handlers[256 - 32]; +extern char nmi[]; extern char page_fault[], general_protection_exception[]; extern char debug_exception[], int3_exception[]; @@ -131,6 +132,7 @@ static void init_idt(void) set_idt_entry(i, generic_common_handlers[i]); } + set_idt_entry(2, (uintptr_t)nmi); set_idt_entry(13, (unsigned long)general_protection_exception); set_idt_entry(14, (unsigned long)page_fault); diff --git a/arch/x86/kernel/include/cpulocal.h b/arch/x86/kernel/include/cpulocal.h index 47e808d5..76c2fbbe 100644 --- a/arch/x86/kernel/include/cpulocal.h +++ b/arch/x86/kernel/include/cpulocal.h @@ -42,7 +42,10 @@ struct x86_cpu_local_variables { uint64_t gdt[10]; /* 128 */ struct tss64 tss; - +/* 232 */ + unsigned long paniced; + uint64_t panic_regs[21]; +/* 408 */ } __attribute__((packed)); struct x86_cpu_local_variables *get_x86_cpu_local_variable(int id); diff --git a/arch/x86/kernel/interrupt.S b/arch/x86/kernel/interrupt.S index 4cdf496b..f66c13eb 100644 --- a/arch/x86/kernel/interrupt.S +++ b/arch/x86/kernel/interrupt.S @@ -130,6 +130,49 @@ general_protection_exception: addq $8, %rsp iretq +.globl nmi +nmi: +#define PANICED 232 +#define PANIC_REGS 240 + movq %rax,%gs:PANIC_REGS+0x00 + movq %rbx,%gs:PANIC_REGS+0x08 + movq %rcx,%gs:PANIC_REGS+0x10 + movq %rdx,%gs:PANIC_REGS+0x18 + movq %rsi,%gs:PANIC_REGS+0x20 + movq %rdi,%gs:PANIC_REGS+0x28 + movq %rbp,%gs:PANIC_REGS+0x30 + movq 0x18(%rsp),%rax /* rsp */ + movq %rax,%gs:PANIC_REGS+0x38 + movq %r8, %gs:PANIC_REGS+0x40 + movq %r9, %gs:PANIC_REGS+0x48 + movq %r10,%gs:PANIC_REGS+0x50 + movq %r11,%gs:PANIC_REGS+0x58 + movq %r12,%gs:PANIC_REGS+0x60 + movq %r13,%gs:PANIC_REGS+0x68 + movq %r14,%gs:PANIC_REGS+0x70 + movq %r15,%gs:PANIC_REGS+0x78 + movq 0x00(%rsp),%rax /* rip */ + movq %rax,%gs:PANIC_REGS+0x80 + movq 0x10(%rsp),%rax /* rflags */ + movl %eax,%gs:PANIC_REGS+0x88 + movq 0x08(%rsp),%rax /* cs */ + movl %eax,%gs:PANIC_REGS+0x8C + movq 0x20(%rsp),%rax /* ss */ + movl %eax,%gs:PANIC_REGS+0x90 + xorq %rax,%rax + movw %ds,%ax + movl %eax,%gs:PANIC_REGS+0x94 + movw %es,%ax + movl %eax,%gs:PANIC_REGS+0x98 + movw %fs,%ax + movl %eax,%gs:PANIC_REGS+0x9C + movw %gs,%ax + movl %eax,%gs:PANIC_REGS+0xA0 + movq $1,%gs:PANICED +1: + hlt + jmp 1b + .globl x86_syscall x86_syscall: cld diff --git a/arch/x86/kernel/syscall.c b/arch/x86/kernel/syscall.c index 0cb69296..f9174d85 100644 --- a/arch/x86/kernel/syscall.c +++ b/arch/x86/kernel/syscall.c @@ -40,6 +40,20 @@ extern void save_fp_regs(struct process *proc); #define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0) #endif +uintptr_t debug_constants[] = { + sizeof(struct cpu_local_var), + offsetof(struct cpu_local_var, current), + offsetof(struct cpu_local_var, runq), + offsetof(struct cpu_local_var, status), + offsetof(struct process, ctx), + offsetof(struct process, sched_list), + offsetof(struct process, ftn), + offsetof(struct fork_tree_node, status), + offsetof(struct fork_tree_node, pid), + offsetof(struct fork_tree_node, tid), + -1, +}; + /* See dkprintf("BSP HW ID = %d, ", bsp_hw_id); (in ./mcos/kernel/ap.c) diff --git a/kernel/Makefile.build.in b/kernel/Makefile.build.in index 04de3905..ca0f9a10 100644 --- a/kernel/Makefile.build.in +++ b/kernel/Makefile.build.in @@ -6,7 +6,7 @@ OBJS += process.o copy.o waitq.o futex.o timer.o plist.o fileobj.o shmobj.o OBJS += zeroobj.o procfs.o devobj.o DEPSRCS=$(wildcard $(SRC)/*.c) -CFLAGS += -I$(SRC)/include -mcmodel=kernel -D__KERNEL__ +CFLAGS += -I$(SRC)/include -mcmodel=kernel -D__KERNEL__ -g LDFLAGS += -e arch_start IHKOBJ = ihk/ihk.o diff --git a/kernel/config/builtin-x86.lds b/kernel/config/builtin-x86.lds index 3390a869..1061fba9 100644 --- a/kernel/config/builtin-x86.lds +++ b/kernel/config/builtin-x86.lds @@ -42,8 +42,4 @@ SECTIONS . = ALIGN(4096); _end = .; - /DISCARD/ : { - *(.eh_frame) - *(.note.gnu.build-id) - } }