2006-01-24 19:56:08 -05:00
|
|
|
! Copyright (C) 2005, 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2006-04-03 02:18:56 -04:00
|
|
|
IN: compiler
|
2006-05-11 02:22:51 -04:00
|
|
|
USING: alien arrays assembler generic kernel kernel-internals
|
|
|
|
math namespaces sequences ;
|
2005-12-02 01:23:09 -05:00
|
|
|
|
|
|
|
! AMD64 register assignments
|
2006-05-11 02:22:51 -04:00
|
|
|
! RAX RCX RDX RSI RDI R8 R9 R10 integer vregs
|
2006-05-04 18:08:52 -04:00
|
|
|
! XMM0 - XMM7 float vregs
|
2006-02-23 20:29:53 -05:00
|
|
|
! R13 cards_offset
|
2005-12-04 02:30:19 -05:00
|
|
|
! R14 datastack
|
|
|
|
! R15 callstack
|
|
|
|
|
2005-12-07 00:14:24 -05:00
|
|
|
: ds-reg R14 ; inline
|
|
|
|
: cs-reg R15 ; inline
|
|
|
|
: remainder-reg RDX ; inline
|
|
|
|
|
2006-01-24 20:20:20 -05:00
|
|
|
M: int-regs return-reg drop RAX ;
|
2006-05-12 17:07:56 -04:00
|
|
|
M: int-regs vregs drop { RAX RCX RDX RSI RDI R8 R9 R10 R11 } ;
|
2006-05-05 02:00:17 -04:00
|
|
|
M: int-regs fastcall-regs drop { RDI RSI RDX RCX R8 R9 } ;
|
2005-12-10 01:02:13 -05:00
|
|
|
|
2006-05-11 02:22:51 -04:00
|
|
|
M: float-regs return-reg drop XMM0 ;
|
|
|
|
M: float-regs vregs drop { XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7 } ;
|
|
|
|
M: float-regs fastcall-regs vregs ;
|
|
|
|
|
2006-05-12 17:07:56 -04:00
|
|
|
: address-operand ( address -- operand )
|
|
|
|
#! On AMD64, we have to load 64-bit addresses into a
|
|
|
|
#! scratch register first. The usage of R11 here is a hack.
|
|
|
|
#! This word can only be called right before a subroutine
|
|
|
|
#! call, where all vregs have been flushed anyway.
|
|
|
|
R11 [ swap MOV ] keep ; inline
|
|
|
|
|
2005-12-10 01:27:41 -05:00
|
|
|
: compile-c-call ( symbol dll -- )
|
2006-05-12 17:07:56 -04:00
|
|
|
2dup dlsym address-operand rel-absolute-cell rel-dlsym CALL ;
|
2005-12-10 01:02:13 -05:00
|
|
|
|
2006-01-24 20:20:20 -05:00
|
|
|
: compile-c-call* ( symbol dll args -- )
|
|
|
|
T{ int-regs } fastcall-regs
|
|
|
|
swap [ MOV ] 2each compile-c-call ;
|
2005-12-10 01:02:13 -05:00
|
|
|
|
2005-12-04 22:55:02 -05:00
|
|
|
: fixnum>slot@ drop ; inline
|
2005-12-07 03:37:05 -05:00
|
|
|
|
|
|
|
: prepare-division CQO ; inline
|
2005-12-20 03:22:01 -05:00
|
|
|
|
2006-05-11 02:22:51 -04:00
|
|
|
M: object load-literal ( literal vreg -- )
|
2005-12-23 01:41:33 -05:00
|
|
|
#! We use RIP-relative addressing. The '3' is a hardcoded
|
|
|
|
#! instruction length.
|
2006-05-11 02:22:51 -04:00
|
|
|
v>operand swap add-literal from 3 - [] MOV ;
|
2006-01-25 01:18:12 -05:00
|
|
|
|
|
|
|
: stack-increment \ stack-reserve get 16 align 8 + ;
|
|
|
|
|
2006-05-11 02:22:51 -04:00
|
|
|
: %prologue ( n -- )
|
|
|
|
\ stack-reserve set RSP stack-increment SUB ;
|
|
|
|
|
|
|
|
: %epilogue ( -- )
|
|
|
|
RSP stack-increment ADD ;
|