/*
  asm.h, Copyright  (c) by Lukas Ruf, lr@lpr.ch,
  Swiss Federal Institute of Technology,
  Computer Engineering and Networks Laboratory.
 
  TOPSY -- A Teachable Operating System.
           Implementation of a tiny and simple
           micro kernel for teaching purposes.
 
  For further information, please visit http://www.tik.ee.ethz.ch/~topsy
 
  This software is provided under the terms of the GNU General Public Licence.
 
  A full copy of the GNU GPL is provided in the file COPYING found in the 
  development root of Topsy.
*/
/*
	File:                  $Source: /home/ruf/cvs_Topsy/cvs/Topsy/Topsy/ia32/asm.h,v $
 	Author(s):             Lukas Ruf, lr@lpr.ch
 	Affiliation:           ETH Zuerich, TIK
 	Version:               $Revision: 3038 $
 	Creation Date:         
 	Last Date of Change:   $Date: 2007-06-05 00:18:19 +0200 (Die, 05 Jun 2007) $      by: $Author: sryffel $
*/

// ************************************************************************** //
// Copyrights (c) 1998 Lukas Ruf                                              //
// ************************************************************************** //
//                                                                            //
// ************************************************************************** //
#ifndef _ASM_H_
#define _ASM_H_

#define   MARKER "TOPSYi386"    /* marker of the BinFileDesc */
#define   TH_NAME "TOPSYia32"   /* name of the new topsyheader */

#define   SYSCALL \
            int $0x30

#define   ENTER pushl %ebp; movl  %esp,%ebp

#define   LEAVE movl  %ebp,%esp;  popl  %ebp ; ret

#define ASM_PROC_FRAME(_name_)   \
            .align 4 ; \
            .globl _name_ ; \
            _name_:


/* Define some Parameters for Argument passing c->assembler */
#define ARG1      0x08(%ebp)
  #define ARG2      0x0C(%ebp)
  #define ARG3      0x10(%ebp)
  #define ARG4      0x14(%ebp)
  #define ARG5      0x18(%ebp)
  #define ARG6      0x1C(%ebp)

// Positions of TSS Entries:
// *************************
#define _LINKTSS  0x00
  #define _ESP0     0x04
  #define _SS0      0x08
  #define _ESP1     0x0C
  #define _SS1      0x10
  #define _ESP2     0x14
  #define _SS2      0x18
  #define _CR3      0x1C
  #define _EIP      0x20
  #define _EFLAGS   0x24
  #define _EAX      0x28
  #define _ECX      0x2C
  #define _EDX      0x30
  #define _EBX      0x34
  #define _ESP      0x38
  #define _EBP      0x3C
  #define _ESI      0x40
  #define _EDI      0x44
  #define _ES       0x48
  #define _CS       0x4C
  #define _SS       0x50
  #define _DS       0x54
  #define _FS       0x58
  #define _GS       0x5C
  #define _LDT      0x60
  #define _DEBUGbit 0x64
  #define _IOBASE   0x66

/* LR 000701 */
/* Offsets of the single registers within the Processor Context */
/* Used to address the single registers on Assembler Level TMHalAsm.S */
#define GS        0x00(%ebp)
  #define FS        0x04(%ebp)
  #define ES        0x08(%ebp)
  #define DS        0x0C(%ebp)
  #define TRAPNO    0x10(%ebp)
  #define EDI       0x14(%ebp)
  #define ESI       0x18(%ebp)
  #define EBP       0x1C(%ebp)
  #define ESP       0x20(%ebp)
  #define EBX       0x24(%ebp)
  #define EDX       0x28(%ebp)
  #define ECX       0x2C(%ebp)
  #define EAX       0x30(%ebp)
  #define ERR       0x34(%ebp)
  #define EIP       0x38(%ebp)
  #define CS        0x3C(%ebp)
  #define EFLAGS    0x40(%ebp)
  #define U_ESP     0x44(%ebp) /* USER STACK POINTER WHEN INTERRUPT STARTED */
  #define U_SS      0x48(%ebp) /* USER STACK SEGMENT SELECTOR */

/* VERIFY: checks the provided SEGMENT SELECTOR for matching 0x08-Byte
 *         alignment.
 *         In case of failures, the zero flag is non-set (jnz :-)
 */
#define VERIFY(selector)  pushl %eax ; \
                            movl  selector,%eax ; \
                            and   $0x08,%eax ; \
                            popl  %eax
#endif
