6570f8e83904e03903ec80a79963eff37b34086e
[bertos.git] / bertos / emul / switch_i386.S
1 /*!
2  * \file
3  * <!--
4  * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 1999,2000,2001 Bernardo Innocenti <bernie@develer.com>
6  * This file is part of DevLib - See devlib/README for information.
7  * -->
8  *
9  * \brief i386 context switch
10  *
11  * \version $Id$
12  *
13  * \author Bernardo Innocenti <bernie@develer.com>
14  */
15
16
17
18 #ifdef __APPLE__
19     //This workaround is necessary to compile under OS X assembler.
20     #define SWITCH_CONTEXT _asm_switch_context
21     #define SWITCH_VERSION _asm_switch_version
22 #else
23     #define SWITCH_CONTEXT asm_switch_context
24     #define SWITCH_VERSION asm_switch_version
25 #endif
26
27 /* void asm_switch_context(void ** new_sp, void ** save_sp) */
28 .globl SWITCH_CONTEXT
29 SWITCH_CONTEXT:
30         pushl   %eax
31         pushl   %ebx
32         pushl   %ecx
33         pushl   %edx
34         pushl   %esi
35         pushl   %edi
36         pushl   %ebp
37         movl    0x24(%esp),%ebp         /* ebp = save_sp */
38         movl    %esp,(%ebp)             /* *save_sp = esp */
39         movl    0x20(%esp),%ebp         /* ebp = new_sp */
40         movl    (%ebp),%esp             /* esp = *new_sp */
41         popl    %ebp
42         popl    %edi
43         popl    %esi
44         popl    %edx
45         popl    %ecx
46         popl    %ebx
47         popl    %eax
48         ret
49
50 /* int asm_switch_version(void) */
51 .globl SWITCH_VERSION
52 SWITCH_VERSION:
53         mov     $1,%eax
54         ret
55