From 68281c8ad0020f2923dc2361234ecd79948cd118 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Mon, 18 Apr 2011 15:10:24 +0200 Subject: [PATCH] cosmetic changes, minor code optimization --- arch/x86/kernel/gdt.c | 6 +++--- arch/x86/kernel/irq.c | 8 +++++--- arch/x86/kernel/processor.c | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/gdt.c b/arch/x86/kernel/gdt.c index b4fd61ae..30e165c7 100644 --- a/arch/x86/kernel/gdt.c +++ b/arch/x86/kernel/gdt.c @@ -68,9 +68,6 @@ int arch_fork(task_t* task) memcpy(task_state_segments+id, task_state_segments+curr_task->id, sizeof(tss_t)); memcpy(kstacks[id], kstacks[curr_task->id], KERNEL_STACK_SIZE); task_state_segments[id].cr3 = (uint32_t) (virt_to_phys((size_t)task->pgd)); - task_state_segments[id].eflags = read_eflags(); - // the parent task will enable the IF flag - task_state_segments[id].eflags |= (1 << 9); task_state_segments[id].esp0 = (uint32_t) kstacks[id] + KERNEL_STACK_SIZE - sizeof(size_t); asm volatile("mov %%esp, %0" : "=r"(task_state_segments[id].esp)); @@ -91,6 +88,9 @@ int arch_fork(task_t* task) asm volatile ("pop %0" : "=r"(task_state_segments[id].ecx)); asm volatile ("pop %0" : "=r"(task_state_segments[id].eax)); + // store current EFLAGS and set IF flag + // => the parent task will enable the interrupt handling + task_state_segments[id].eflags = read_eflags() | (1 << 9); // This will be the entry point for the new task. task_state_segments[id].eip = read_eip(); diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c index 708061dd..3542199f 100644 --- a/arch/x86/kernel/irq.c +++ b/arch/x86/kernel/irq.c @@ -226,9 +226,11 @@ void irq_handler(struct state *s) * Find out if we have a custom handler to run for this * IRQ and then finally, run it */ - handler = irq_routines[s->int_no]; - if (handler) - handler(s); + if (BUILTIN_EXPECT(s->int_no < MAX_HANDLERS, 1)) { + handler = irq_routines[s->int_no]; + if (handler) + handler(s); + } else kprintf("Invalid interrupt number %d\n", s->int_no); /* * If the IDT entry that was invoked was greater-than-or-equal to 48, diff --git a/arch/x86/kernel/processor.c b/arch/x86/kernel/processor.c index 2b1c84bf..aa4988f4 100644 --- a/arch/x86/kernel/processor.c +++ b/arch/x86/kernel/processor.c @@ -49,12 +49,12 @@ uint32_t detect_cpu_frequency(void) while((ticks = get_clock_tick()) - old == 0) HALT; - rmb(); + mb(); start = rdtsc(); /* wait a second to determine the frequency */ while(get_clock_tick() - ticks < TIMER_FREQ) HALT; - rmb(); + mb(); end = rdtsc(); diff = end > start ? end - start : start - end; @@ -78,7 +78,7 @@ void udelay(uint32_t usecs) uint64_t deadline = get_cpu_frequency() * usecs; do { - rmb(); + mb(); end = rdtsc(); diff = end > start ? end - start : start - end; } while(diff < deadline);