Minor fix.
[bertos.git] / bertos / emul / switch_x86_64.s
index df511d669de79683a2094deba00709012fd2e77e..ea76d2c98ed9d1246652f3aac29f1ad2152c0f19 100644 (file)
@@ -1,71 +1,72 @@
-/*!
+/**
  * \file
  * <!--
- * Copyright 2004 Develer S.r.l. (http://www.develer.com/)
- * Copyright 1999,2000,2001 Bernie Innocenti <bernie@codewiz.org>
- * This file is part of DevLib - See devlib/README for information.
- * -->
+ * This file is part of BeRTOS.
  *
- * \brief i386 context switch
+ * Bertos is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * \version $Id$
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
  *
- * \author Bernie Innocenti <bernie@codewiz.org>
- */
-
-/*
- * $Log$
- * Revision 1.4  2006/09/20 14:02:49  marco
- * C-style comment.
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *
- * Revision 1.3  2006/02/24 01:35:40  bernie
- * Update for new emulator.
+ * As a special exception, you may use this file as part of a free software
+ * library without restriction.  Specifically, if other files instantiate
+ * templates or use macros or inline functions from this file, or you compile
+ * this file and link it with other files to produce an executable, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU General Public License.  This exception does not however
+ * invalidate any other reasons why the executable file might be covered by
+ * the GNU General Public License.
  *
- * Revision 1.2  2006/02/24 01:17:05  bernie
- * Update for new emulator.
+ * Copyright 2004, 2008 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 1999, 2000, 2001 Bernie Innocenti <bernie@codewiz.org>
+ * -->
  *
- * Revision 1.1  2005/11/27 03:06:15  bernie
- * Add x86_64 task switching (to be updated to new-style scheduler).
+ * \author Bernie Innocenti <bernie@codewiz.org>
  *
- * Revision 1.1  2005/11/14 21:06:38  bernie
- * Add x86_64 support.
+ * \brief x86_64 context switch
  *
- * Revision 1.2  2004/06/06 16:14:12  bernie
- * Add DevLib license information.
+ * x86_64 function call convention:
+ * --------------------------------
+ *  arguments           |  callee-saved      | extra caller-saved | return
+ * [callee-clobbered]   |                    | [callee-clobbered] |
+ * -------------------------------------------------------------------------
+ * rdi rsi rdx rcx r8-9 | rbx rbp [*] r12-15 | r10-11             | rax, rdx
  *
- * Revision 1.1  2004/05/23 17:27:00  bernie
- * Import kern/ subdirectory.
+ *  [*]  In the frame-pointers case rbp must hold a base address for the
+ *       current stack frame.
  *
+ * asm_switch_context() can be considered as a normal function call, so we need
+ * to save all the callee-clobbered registers minus the return registers.
  */
 
-/* I know it's ugly... */
-/* .intel_syntax */
-
-/* void AsmSwitchContext(void **new_sp, void **save_sp) */
-/*                       %rdi           %rsi            */
+/* void asm_switch_context(void **new_sp [%rdi], void **save_sp [%rsi]) */
 .globl asm_switch_context
 asm_switch_context:
-       pushq   %rax
-       pushq   %rbx
-       pushq   %rcx
-       pushq   %rdx
-       pushq   %rsi
-       pushq   %rdi
        pushq   %rbp
+       pushq   %rdi
+       pushq   %rsi
+       pushq   %rcx
+       pushq   %r8
+       pushq   %r9
+       pushq   %r10
+       pushq   %r11
        movq    %rsp,(%rsi)             /* *save_sp = rsp */
        movq    (%rdi),%rsp             /* rsp = *new_sp */
-       popq    %rbp
-       popq    %rdi
-       popq    %rsi
-       popq    %rdx
+       popq    %r11
+       popq    %r10
+       popq    %r9
+       popq    %r8
        popq    %rcx
-       popq    %rbx
-       popq    %rax
-       ret
-
-/* int asm_switch_version(void) */
-.globl asm_switch_version
-asm_switch_version:
-       mov     $1,%rax
+       popq    %rsi
+       popq    %rdi
+       popq    %rbp
        ret
-