From a6d48e3941123189084882866361ff009de1ee04 Mon Sep 17 00:00:00 2001 From: Till Straumann Date: Thu, 29 Oct 2009 03:15:03 +0000 Subject: 2009-10-28 Till Straumann * score/cpu/i386/rtems/score/cpu.h: Added #ifdef ASM constructs so that this header can be included from assembly code. Increased CPU_STACK_ALIGNMENT to 16 bytes. Gcc maintains 16-byte alignment and it may be a advantageous to provide initial 16-byte alignment. When using SSE some gcc versions may produce code that crashes if the stack is not 16-byte aligned. Make sure _CPU_Context_Initialize() sets the thread stack up so that it is aligned to CPU_CACHE_ALIGNMENT. * score/cpu/i386/cpu_asm.S: Align stack to CPU_CACHE_ALIGNMENT before calling C-code. --- cpukit/score/cpu/i386/cpu_asm.S | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'cpukit/score/cpu/i386/cpu_asm.S') diff --git a/cpukit/score/cpu/i386/cpu_asm.S b/cpukit/score/cpu/i386/cpu_asm.S index 7630aa3b35..4084e03fb8 100644 --- a/cpukit/score/cpu/i386/cpu_asm.S +++ b/cpukit/score/cpu/i386/cpu_asm.S @@ -14,6 +14,11 @@ */ #include +#include + +#ifndef CPU_STACK_ALIGNMENT +#error "Missing header? CPU_STACK_ALIGNMENT not defined" +#endif /* * Format of i386 Register structure @@ -110,13 +115,17 @@ SYM (_CPU_Context_restore_fp): PUBLIC (_Exception_Handler) SYM (_Exception_Handler): - pusha /* Push general purpose registers */ - pushl esp /* Push exception frame address */ - movl _currentExcHandler, eax /* Call function storead in _currentExcHandler */ + pusha /* Push general purpose registers */ + movl esp, ebp /* Save original SP */ + subl $4, esp /* Reserve space for argument */ + /* Align stack (courtesy for C/gcc) */ + andl $ - CPU_STACK_ALIGNMENT, esp + movl ebp, (esp) /* Store argument */ + movl _currentExcHandler, eax /* Call function stored in _currentExcHandler */ call * eax - addl $4, esp - popa /* restore general purpose registers */ - addl $8, esp /* skill vector number and faultCode */ + movl ebp, esp /* Restore original SP */ + popa /* Restore general purpose registers */ + addl $8, esp /* Skill vector number and faultCode */ iret #define DISTINCT_EXCEPTION_WITH_FAULTCODE_ENTRY(_vector) \ -- cgit v1.2.3