/kernel/trunk/arch/amd64/src/amd64.c |
---|
46,6 → 46,42 |
#include <panic.h> |
#include <interrupt.h> |
/** Disable I/O on non-privileged levels |
* |
* Clean IOPL(12,13) and NT(14) flags in EFLAGS register |
*/ |
static void clean_IOPL_NT_flags(void) |
{ |
asm |
( |
"pushfq;" |
"pop %%rax;" |
"and $~(0x7000),%%rax;" |
"pushq %%rax;" |
"popfq;" |
: |
: |
:"%rax" |
); |
} |
/** Disable alignment check |
* |
* Clean AM(18) flag in CR0 register |
*/ |
static void clean_AM_flag(void) |
{ |
asm |
( |
"mov %%cr0,%%rax;" |
"and $~(0x40000),%%rax;" |
"mov %%rax,%%cr0;" |
: |
: |
:"%rax" |
); |
} |
void arch_pre_mm_init(void) |
{ |
struct cpu_info cpuid_s; |
63,18 → 99,26 |
/* Enable No-execute pages */ |
set_efer_flag(AMD_NXE_FLAG); |
/* Enable SYSCALL/SYSRET */ |
set_efer_flag(AMD_SCE_FLAG); |
/* Enable FPU */ |
cpu_setup_fpu(); |
/* Initialize segmentation */ |
pm_init(); |
/* Disable I/O on nonprivileged levels |
* clear the NT(nested-thread) flag |
*/ |
clean_IOPL_NT_flags(); |
/* Disable alignment check */ |
clean_AM_flag(); |
if (config.cpu_active == 1) { |
bios_init(); |
i8259_init(); /* PIC */ |
i8254_init(); /* hard clock */ |
exc_register(VECTOR_SYSCALL, "syscall", syscall); |
#ifdef CONFIG_SMP |
exc_register(VECTOR_TLB_SHOOTDOWN_IPI, "tlb_shootdown", |
tlb_shootdown_ipi); |
/kernel/trunk/arch/amd64/src/pm.c |
---|
1,5 → 1,6 |
/* |
* Copyright (C) 2001-2004 Jakub Jermar |
* Copyright (C) 2005-2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
167,15 → 168,8 |
d->present = 1; |
d->type = AR_INTERRUPT; /* masking interrupt */ |
if (i == VECTOR_SYSCALL) { |
/* |
* The syscall interrupt gate must be calleable from userland. |
*/ |
d->dpl |= PL_USER; |
} |
idt_setoffset(d, ((__address) interrupt_handlers) + i*interrupt_handler_size); |
exc_register(i, "undef", null_interrupt); |
exc_register(i, "undef", (iroutine)null_interrupt); |
} |
exc_register(13, "gp_fault", gp_fault); |
exc_register( 7, "nm_fault", nm_fault); |
182,37 → 176,9 |
exc_register(12, "ss_fault", ss_fault); |
} |
/* Clean IOPL(12,13) and NT(14) flags in EFLAGS register */ |
static void clean_IOPL_NT_flags(void) |
{ |
asm |
( |
"pushfq;" |
"pop %%rax;" |
"and $~(0x7000),%%rax;" |
"pushq %%rax;" |
"popfq;" |
: |
: |
:"%rax" |
); |
} |
/* Clean AM(18) flag in CR0 register */ |
static void clean_AM_flag(void) |
{ |
asm |
( |
"mov %%cr0,%%rax;" |
"and $~(0x40000),%%rax;" |
"mov %%rax,%%cr0;" |
: |
: |
:"%rax" |
); |
} |
/** Initialize segmentation - code/data/idt tables |
* |
*/ |
void pm_init(void) |
{ |
struct descriptor *gdt_p = (struct descriptor *) gdtr.base; |
254,7 → 220,4 |
* to its own TSS. We just need to load the TR register. |
*/ |
__asm__("ltr %0" : : "r" ((__u16) gdtselector(TSS_DES))); |
clean_IOPL_NT_flags(); /* Disable I/O on nonprivileged levels */ |
clean_AM_flag(); /* Disable alignment check */ |
} |
/kernel/trunk/arch/amd64/src/asm_utils.S |
---|
34,6 → 34,7 |
#define ERROR_WORD_INTERRUPT_LIST 0x00027D00 |
#include <arch/pm.h> |
#include <arch/context_offset.h> |
.text |
.global interrupt_handlers |
103,38 → 104,40 |
ret |
# Push all general purpose registers on stack except %rbp, %rsp |
.macro push_all_gpr |
pushq %rax |
pushq %rbx |
pushq %rcx |
pushq %rdx |
pushq %rsi |
pushq %rdi |
pushq %r8 |
pushq %r9 |
pushq %r10 |
pushq %r11 |
pushq %r12 |
pushq %r13 |
pushq %r14 |
pushq %r15 |
.macro save_all_gpr |
movq %rbp, IOFFSET_RBP(%rsp) |
movq %rax, IOFFSET_RAX(%rsp) |
movq %rbx, IOFFSET_RBX(%rsp) |
movq %rcx, IOFFSET_RCX(%rsp) |
movq %rdx, IOFFSET_RDX(%rsp) |
movq %rsi, IOFFSET_RSI(%rsp) |
movq %rdi, IOFFSET_RDI(%rsp) |
movq %r8, IOFFSET_R8(%rsp) |
movq %r9, IOFFSET_R9(%rsp) |
movq %r10, IOFFSET_R10(%rsp) |
movq %r11, IOFFSET_R11(%rsp) |
movq %r12, IOFFSET_R12(%rsp) |
movq %r13, IOFFSET_R13(%rsp) |
movq %r14, IOFFSET_R14(%rsp) |
movq %r15, IOFFSET_R15(%rsp) |
.endm |
.macro pop_all_gpr |
popq %r15 |
popq %r14 |
popq %r13 |
popq %r12 |
popq %r11 |
popq %r10 |
popq %r9 |
popq %r8 |
popq %rdi |
popq %rsi |
popq %rdx |
popq %rcx |
popq %rbx |
popq %rax |
.macro restore_all_gpr |
movq IOFFSET_RBP(%rsp), %rbp |
movq IOFFSET_RAX(%rsp), %rax |
movq IOFFSET_RBX(%rsp), %rbx |
movq IOFFSET_RCX(%rsp), %rcx |
movq IOFFSET_RDX(%rsp), %rdx |
movq IOFFSET_RSI(%rsp), %rsi |
movq IOFFSET_RDI(%rsp), %rdi |
movq IOFFSET_R8(%rsp), %r8 |
movq IOFFSET_R9(%rsp), %r9 |
movq IOFFSET_R10(%rsp), %r10 |
movq IOFFSET_R11(%rsp), %r11 |
movq IOFFSET_R12(%rsp), %r12 |
movq IOFFSET_R13(%rsp), %r13 |
movq IOFFSET_R14(%rsp), %r14 |
movq IOFFSET_R15(%rsp), %r15 |
.endm |
## Declare interrupt handlers |
146,14 → 149,11 |
# and call exc_dispatch(). |
# |
.macro handler i n |
pushq %rbp |
movq %rsp,%rbp |
push_all_gpr |
subq $IREGISTER_SPACE, %rsp |
save_all_gpr |
movq $(\i),%rdi # %rdi - first parameter |
movq %rbp, %rsi |
addq $8, %rsi # %rsi - second parameter - original stack |
movq %rsp, %rsi # %rsi - pointer to interrupt_context |
call exc_dispatch # exc_dispatch(i, stack) |
# Test if this is interrupt with error word or not |
168,17 → 168,15 |
# Return with error word |
pop_all_gpr |
popq %rbp; |
addq $8,%rsp; # Skip error word |
restore_all_gpr |
# $8 = Skip error word |
addq $IREGISTER_SPACE + 0x8, %rsp |
iretq |
0: |
# Return with no error word |
pop_all_gpr |
popq %rbp |
restore_all_gpr |
addq $IREGISTER_SPACE, %rsp |
iretq |
.if (\n-\i)-1 |
/kernel/trunk/arch/amd64/src/mm/page.c |
---|
52,7 → 52,7 |
page_mapping_insert(AS_KERNEL, PA2KA(cur), cur, PAGE_CACHEABLE | PAGE_EXEC); |
} |
exc_register(14, "page_fault", page_fault); |
exc_register(14, "page_fault", (iroutine)page_fault); |
write_cr3((__address) AS_KERNEL->page_table); |
} |
else { |
/kernel/trunk/arch/amd64/src/interrupt.c |
---|
58,31 → 58,30 |
printf("\n"); |
} |
*/ |
static void print_info_errcode(int n, void *st) |
static void print_info_errcode(int n, struct interrupt_context *ctx) |
{ |
char *symbol; |
__native *x = (__native *) st; |
__u64 *x = &ctx->stack[0]; |
if (!(symbol=get_symtab_entry(x[1]))) |
symbol = ""; |
printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); |
printf("%%rip: %Q (%s)\n",x[1],symbol); |
printf("ERROR_WORD=%Q\n", x[0]); |
printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", x[2], x[3],read_cr0()); |
printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",x[-2],x[-3],x[-4]); |
printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",x[-5],x[-6],x[-7]); |
printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",x[-8],x[-9],x[-10]); |
printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",x[-11],x[-12],x[-13]); |
printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",x[-14],x[-15],x); |
printf("%%rbp=%Q\n",x[-1]); |
printf("%%rip: %Q (%s)\n",ctx->stack[1],symbol); |
printf("ERROR_WORD=%Q\n", ctx->stack[0]); |
printf("%%rcs=%Q,flags=%Q, %%cr0=%Q\n", ctx->stack[2], |
ctx->stack[3],read_cr0()); |
printf("%%rax=%Q, %%rbx=%Q, %%rcx=%Q\n",ctx->rax,ctx->rbx,ctx->rcx); |
printf("%%rdx=%Q, %%rsi=%Q, %%rdi=%Q\n",ctx->rdx,ctx->rsi,ctx->rdi); |
printf("%%r8 =%Q, %%r9 =%Q, %%r10=%Q\n",ctx->r8,ctx->r9,ctx->r10); |
printf("%%r11=%Q, %%r12=%Q, %%r13=%Q\n",ctx->r11,ctx->r12,ctx->r13); |
printf("%%r14=%Q, %%r15=%Q, %%rsp=%Q\n",ctx->r14,ctx->r15,&ctx->stack[0]); |
printf("%%rbp=%Q\n",ctx->rbp); |
printf("stack: %Q, %Q, %Q\n", x[5], x[6], x[7]); |
printf(" %Q, %Q, %Q\n", x[8], x[9], x[10]); |
printf(" %Q, %Q, %Q\n", x[11], x[12], x[13]); |
printf(" %Q, %Q, %Q\n", x[14], x[15], x[16]); |
printf(" %Q, %Q, %Q\n", x[17], x[18], x[19]); |
printf(" %Q, %Q, %Q\n", x[20], x[21], x[22]); |
printf(" %Q, %Q, %Q\n", x[23], x[24], x[25]); |
// messy_stack_trace(&x[5]); |
} |
94,12 → 93,11 |
void (* enable_irqs_function)(__u16 irqmask) = NULL; |
void (* eoi_function)(void) = NULL; |
void null_interrupt(int n, void *st) |
void null_interrupt(int n, struct interrupt_context *ctx) |
{ |
__native *stack = (__native *) st; |
printf("-----EXCEPTION(%d) OCCURED----- ( %s )\n",n,__FUNCTION__); \ |
printf("stack: %L, %L, %L, %L\n", stack[0], stack[1], stack[2], stack[3]); |
printf("stack: %X, %X, %X, %X\n", ctx->stack[0], ctx->stack[1], |
ctx->stack[2], ctx->stack[3]); |
panic("unserviced interrupt\n"); |
} |
125,24 → 123,18 |
#endif |
} |
void page_fault(int n, void *stack) |
void page_fault(int n, struct interrupt_context *ctx) |
{ |
__address page; |
page = read_cr2(); |
if (!as_page_fault(page)) { |
print_info_errcode(n,stack); |
print_info_errcode(n,ctx); |
printf("Page fault address: %Q\n", page); |
panic("page fault\n"); |
} |
} |
void syscall(int n, void *stack) |
{ |
printf("cpu%d: syscall\n", CPU->id); |
thread_usleep(1000); |
} |
void tlb_shootdown_ipi(int n, void *stack) |
{ |
trap_virtual_eoi(); |