; -*- mode: asm -*-
;
; Copyright 2003 Lars T Hansen
; Machine description for x86-nasm port of Larceny.
;
; $Id: i386-machine.ah 4000 2007-02-15 19:45:47Z pnkfelix $
;
; Notes on the representations.
;
; EAX is used as a temp for generated code, and to pass SECOND on
; calls to millicode.  EAX is never a root for garbage collection, so
; SECOND must be flushed to memory by millicode.
;
; GLOBALS must be mapped mapped to ESP to make millicode calls
; compact.  The GLOBALS pointer points to element 1 of the globals
; vector; element 0 is normally unused.  To call millicode one
; executes an indirect CALL instruction; the return address will
; be pushed into the first element of GLOBALS.  Millicode
; must pop the value to adjust GLOBALS and save the address.
;
; REG0 is not mapped to a hardware reg because there are few hardware
; regs available and computation is probably more important than access
; to the procedure.  I don't have any data to back this up.
;
; ECX and EDI must be mapped to VM registers to make it easy to write
; code that uses the REP STOS instructions without knowing too much
; about the register layout.
;
; Using the low byte of registers when possible reduces code size.
; The instruction macros know that RESULT and TEMP have a low byte
; register, but otherwise rely on hwreg_has_low() to test the mapping.

%ifndef I386_MACHINE_ASM
%define I386_MACHINE_ASM

%define wordsize        4
%define object_align    8
%define code_align      4

%include "config.ah"
%include "asmdefs.h"

%define G_REGALIAS_ECX	G_REG1	; used by rep stos constructions
%define G_REGALIAS_EDI	G_REG3	; ditto

%define FIRST_HWREG	1
%define LAST_HWREG	4

%define hwreg_has_low(r)  (r==1 || r==2)

%ifdef WIN32
%define EXTNAME(x) _ %+ x
%else
%ifdef MACOS_X
%define EXTNAME(x) _ %+ x
%else
%define EXTNAME(x) x
%endif
%endif

%define LASTREG 31

%define PROC_CONSTVECTOR            CONSTVECTOR   ; byte offset
%define PROC_CODEVECTOR_NATIVE      CODEVECTOR    ; byte offset

%define EX_PROCEDURE_REF	    EX_PREF
%define EX_MAKE_BYTEVECTOR	    EX_MKBVL	  ; FIXME
%define EX_BYTEVECTOR_LENGTH	    EX_BVLEN
%define EX_BYTEVECTOR_LIKE_LENGTH   EX_BVLLEN
%define EX_BYTEVECTOR_LIKE_REF	    EX_BVLREF
%define EX_BYTEVECTOR_LIKE_SET	    EX_BVLSET
%define EX_MAKE_STRING		    EX_MKBVL	  ; FIXME
%define EX_STRING_LENGTH	    EX_SLEN
%define EX_STRING_REF		    EX_SREF
%define EX_STRING_SET		    EX_SSET
%define EX_MAKE_VECTOR		    EX_MKVL       ; FIXME
%define EX_VECTOR_LENGTH	    EX_VLEN
%define EX_VECTOR_REF		    EX_VREF
%define EX_VECTOR_SET		    EX_VSET
%define EX_VECTOR_LIKE_LENGTH	    EX_VLLEN
%define EX_VECTOR_LIKE_REF	    EX_VLREF
%define EX_VECTOR_LIKE_SET	    EX_VLSET
%define EX_BYTEVECTOR_REF	    EX_BVREF
%define EX_BYTEVECTOR_SET	    EX_BVSET
%define EX_MAKE_PROCEDURE	    EX_MKVL	  ; FIXME
%define EX_PROCEDURE_LENGTH	    EX_PLEN
%define EX_PROCEDURE_REF	    EX_PREF
%define EX_PROCEDURE_SET	    EX_PSET

%endif ; ndef I386_MACHINE_ASM
