From abf41fdf99342accdc5047eb146b7b54c8d4a7eb Mon Sep 17 00:00:00 2001 From: Till Straumann Date: Thu, 29 Oct 2009 03:20:21 +0000 Subject: 2009-10-28 Till Straumann * shared/irq/irq_asm.S: Make sure stack is aligned to CPU_STACK_ALIGNMENT before invoking C-code. --- c/src/lib/libbsp/i386/shared/irq/irq_asm.S | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'c/src/lib/libbsp/i386/shared/irq') diff --git a/c/src/lib/libbsp/i386/shared/irq/irq_asm.S b/c/src/lib/libbsp/i386/shared/irq/irq_asm.S index c8f3df3b5e..d39ff81e72 100644 --- a/c/src/lib/libbsp/i386/shared/irq/irq_asm.S +++ b/c/src/lib/libbsp/i386/shared/irq/irq_asm.S @@ -13,6 +13,11 @@ #include #include +#include + +#ifndef CPU_STACK_ALIGNMENT +#error "Missing header? CPU_STACK_ALIGNMENT is not defined here" +#endif BEGIN_CODE @@ -95,26 +100,35 @@ SYM (_ISR_Handler): nested: incl SYM (_ISR_Nest_level) /* one nest level deeper */ incl SYM (_Thread_Dispatch_disable_level) /* disable multitasking */ + + /* + * Ensure CPU_STACK_ALIGNMENT for C-code. + * esp = (esp - 4) & ~(CPU_STACK_ALIGNMENT - 1) + * makes sure 'esp' is aligned AND there is enough space + * for the vector argument on the stack! + */ + subl $4, esp + + andl $ - CPU_STACK_ALIGNMENT, esp /* * re-enable interrupts at processor level as the current * interrupt source is now masked via i8259 */ sti - /* + /* * ECX is preloaded with the vector number but it is a scratch register * so we must save it again. */ - pushl ecx /* push vector number */ + movl ecx, (esp) /* store vector arg in stack */ call C_dispatch_isr - addl $4, esp /* * disable interrupts_again */ cli - popl ecx /* ecx = vector number */ + /* * restore stack */ -- cgit v1.2.3