2011-09-14 00:38:03 -04:00
|
|
|
! Copyright (C) 2005, 2011 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2010-01-02 07:03:30 -05:00
|
|
|
USING: accessors arrays kernel math namespaces make sequences
|
2011-09-14 00:38:03 -04:00
|
|
|
system layouts alien alien.c-types alien.accessors
|
|
|
|
alien.libraries slots splitting assocs combinators fry locals
|
|
|
|
compiler.constants classes.struct compiler.codegen
|
|
|
|
compiler.codegen.gc-maps compiler.codegen.labels
|
|
|
|
compiler.codegen.relocation compiler.cfg.instructions
|
|
|
|
compiler.cfg.builder compiler.cfg.intrinsics
|
|
|
|
compiler.cfg.stack-frame cpu.x86.assembler
|
|
|
|
cpu.x86.assembler.operands cpu.x86 cpu.architecture vm ;
|
2010-01-10 07:20:32 -05:00
|
|
|
FROM: layouts => cell cells ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: cpu.x86.64
|
|
|
|
|
2010-05-16 03:43:02 -04:00
|
|
|
: param-reg ( n -- reg ) int-regs cdecl param-regs at nth ;
|
|
|
|
|
|
|
|
: param-reg-0 ( -- reg ) 0 param-reg ; inline
|
|
|
|
: param-reg-1 ( -- reg ) 1 param-reg ; inline
|
|
|
|
: param-reg-2 ( -- reg ) 2 param-reg ; inline
|
|
|
|
: param-reg-3 ( -- reg ) 3 param-reg ; inline
|
2009-10-20 06:02:42 -04:00
|
|
|
|
|
|
|
M: x86.64 pic-tail-reg RBX ;
|
|
|
|
|
2010-05-16 03:43:02 -04:00
|
|
|
M: x86.64 return-regs
|
|
|
|
{
|
|
|
|
{ int-regs { RAX EDX } }
|
|
|
|
{ float-regs { XMM0 XMM1 } }
|
|
|
|
} ;
|
2009-10-20 06:02:42 -04:00
|
|
|
|
|
|
|
M: x86.64 ds-reg R14 ;
|
|
|
|
M: x86.64 rs-reg R15 ;
|
|
|
|
M: x86.64 stack-reg RSP ;
|
2010-01-02 07:03:30 -05:00
|
|
|
M: x86.64 frame-reg RBP ;
|
2009-10-20 06:02:42 -04:00
|
|
|
|
2008-10-07 21:00:38 -04:00
|
|
|
M: x86.64 machine-registers
|
|
|
|
{
|
2010-01-10 07:20:32 -05:00
|
|
|
{ int-regs { RAX RCX RDX RBX RBP RSI RDI R8 R9 R10 R11 R12 } }
|
2009-08-07 18:44:50 -04:00
|
|
|
{ float-regs {
|
2008-10-07 21:00:38 -04:00
|
|
|
XMM0 XMM1 XMM2 XMM3 XMM4 XMM5 XMM6 XMM7
|
|
|
|
XMM8 XMM9 XMM10 XMM11 XMM12 XMM13 XMM14 XMM15
|
|
|
|
} }
|
|
|
|
} ;
|
|
|
|
|
2010-01-10 07:20:32 -05:00
|
|
|
: vm-reg ( -- reg ) R13 ; inline
|
2010-03-26 22:44:43 -04:00
|
|
|
: nv-reg ( -- reg ) RBX ; inline
|
2010-01-10 07:20:32 -05:00
|
|
|
|
|
|
|
M: x86.64 %mov-vm-ptr ( reg -- )
|
|
|
|
vm-reg MOV ;
|
|
|
|
|
2010-04-01 20:06:18 -04:00
|
|
|
M: x86.64 %vm-field ( dst offset -- )
|
|
|
|
[ vm-reg ] dip [+] MOV ;
|
2010-02-03 03:27:18 -05:00
|
|
|
|
2010-05-03 17:23:03 -04:00
|
|
|
M:: x86.64 %load-vector ( dst val rep -- )
|
|
|
|
dst 0 [RIP+] rep copy-memory* val rc-relative rel-binary-literal ;
|
|
|
|
|
2010-04-01 20:06:18 -04:00
|
|
|
M: x86.64 %set-vm-field ( src offset -- )
|
|
|
|
[ vm-reg ] dip [+] swap MOV ;
|
|
|
|
|
|
|
|
M: x86.64 %vm-field-ptr ( dst offset -- )
|
|
|
|
[ vm-reg ] dip [+] LEA ;
|
2010-01-10 07:20:32 -05:00
|
|
|
|
2010-02-03 03:27:18 -05:00
|
|
|
M: x86.64 %prepare-jump
|
2010-04-04 19:42:57 -04:00
|
|
|
pic-tail-reg xt-tail-pic-offset [RIP+] LEA ;
|
2010-02-03 03:27:18 -05:00
|
|
|
|
2009-10-15 23:07:03 -04:00
|
|
|
: load-cards-offset ( dst -- )
|
|
|
|
0 MOV rc-absolute-cell rel-cards-offset ;
|
|
|
|
|
|
|
|
M: x86.64 %mark-card
|
|
|
|
dup load-cards-offset
|
|
|
|
[+] card-mark <byte> MOV ;
|
|
|
|
|
|
|
|
: load-decks-offset ( dst -- )
|
|
|
|
0 MOV rc-absolute-cell rel-decks-offset ;
|
|
|
|
|
|
|
|
M: x86.64 %mark-deck
|
2009-10-16 00:29:56 -04:00
|
|
|
dup load-decks-offset
|
2009-10-15 23:07:03 -04:00
|
|
|
[+] card-mark <byte> MOV ;
|
|
|
|
|
2010-07-14 17:47:21 -04:00
|
|
|
M:: x86.64 %load-stack-param ( vreg rep n -- )
|
|
|
|
rep return-reg n next-stack@ rep %copy
|
2010-07-14 17:59:51 -04:00
|
|
|
vreg rep return-reg rep %copy ;
|
2010-07-14 17:47:21 -04:00
|
|
|
|
|
|
|
M:: x86.64 %store-stack-param ( vreg rep n -- )
|
2010-07-14 17:59:51 -04:00
|
|
|
rep return-reg vreg rep %copy
|
2010-07-14 17:47:21 -04:00
|
|
|
n reserved-stack-space + stack@ rep return-reg rep %copy ;
|
|
|
|
|
2010-07-13 07:40:14 -04:00
|
|
|
M:: x86.64 %load-reg-param ( vreg rep reg -- )
|
|
|
|
vreg reg rep %copy ;
|
2010-05-16 03:43:02 -04:00
|
|
|
|
2010-07-13 07:40:14 -04:00
|
|
|
M:: x86.64 %store-reg-param ( vreg rep reg -- )
|
|
|
|
reg vreg rep %copy ;
|
2010-05-16 03:43:02 -04:00
|
|
|
|
2010-08-14 12:14:22 -04:00
|
|
|
M: x86.64 %discard-reg-param ( rep reg -- )
|
2010-08-14 02:19:30 -04:00
|
|
|
2drop ;
|
|
|
|
|
2010-05-11 19:11:31 -04:00
|
|
|
M:: x86.64 %unbox ( dst src func rep -- )
|
|
|
|
param-reg-0 src tagged-rep %copy
|
|
|
|
param-reg-1 %mov-vm-ptr
|
2010-07-13 07:40:14 -04:00
|
|
|
func f f %c-invoke
|
2010-05-16 03:43:02 -04:00
|
|
|
dst rep %load-return ;
|
2009-08-07 18:44:50 -04:00
|
|
|
|
2010-06-13 17:36:08 -04:00
|
|
|
M:: x86.64 %box ( dst src func rep gc-map -- )
|
2010-05-16 03:43:02 -04:00
|
|
|
0 rep reg-class-of cdecl param-regs at nth src rep %copy
|
2010-04-19 15:05:55 -04:00
|
|
|
rep int-rep? os windows? or param-reg-1 param-reg-0 ? %mov-vm-ptr
|
2010-07-13 07:40:14 -04:00
|
|
|
func f gc-map %c-invoke
|
2010-05-16 03:43:02 -04:00
|
|
|
dst int-rep %load-return ;
|
|
|
|
|
2010-07-13 07:40:14 -04:00
|
|
|
M: x86.64 %c-invoke
|
2010-06-13 17:36:08 -04:00
|
|
|
[ R11 0 MOV rc-absolute-cell rel-dlsym R11 CALL ] dip
|
|
|
|
gc-map-here ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-03-26 22:44:43 -04:00
|
|
|
M: x86.64 %begin-callback ( -- )
|
|
|
|
param-reg-0 %mov-vm-ptr
|
2010-04-01 22:12:45 -04:00
|
|
|
param-reg-1 0 MOV
|
2010-07-13 07:40:14 -04:00
|
|
|
"begin_callback" f f %c-invoke ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2010-03-26 22:44:43 -04:00
|
|
|
M: x86.64 %end-callback ( -- )
|
2010-01-02 07:03:30 -05:00
|
|
|
param-reg-0 %mov-vm-ptr
|
2010-07-13 07:40:14 -04:00
|
|
|
"end_callback" f f %c-invoke ;
|
2010-03-26 22:44:43 -04:00
|
|
|
|
2010-07-19 16:03:39 -04:00
|
|
|
M: x86.64 %prepare-var-args ( -- ) RAX RAX XOR ;
|
|
|
|
|
2010-07-13 07:40:14 -04:00
|
|
|
M: x86.64 stack-cleanup 3drop 0 ;
|
|
|
|
|
|
|
|
M: x86.64 %cleanup 0 assert= ;
|
|
|
|
|
2011-10-18 01:43:19 -04:00
|
|
|
M: x86.64 %safepoint
|
|
|
|
0 [RIP+] EAX MOV rc-relative rel-safepoint ;
|
|
|
|
|
2010-05-11 19:11:31 -04:00
|
|
|
M: x86.64 long-long-on-stack? f ;
|
|
|
|
|
2010-05-12 01:40:41 -04:00
|
|
|
M: x86.64 float-on-stack? f ;
|
|
|
|
|
2010-05-11 19:11:31 -04:00
|
|
|
M: x86.64 struct-return-on-stack? f ;
|
2010-04-01 23:56:43 -04:00
|
|
|
|
2008-10-20 06:55:57 -04:00
|
|
|
! The result of reading 4 bytes from memory is a fixnum on
|
|
|
|
! x86-64.
|
|
|
|
enable-alien-4-intrinsics
|
2008-10-13 23:43:32 -04:00
|
|
|
|
2011-11-02 14:23:41 -04:00
|
|
|
USE: vocabs
|
2008-11-07 21:33:32 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
{ [ os unix? ] [ "cpu.x86.64.unix" require ] }
|
2011-09-18 21:25:06 -04:00
|
|
|
{ [ os windows? ] [ "cpu.x86.64.windows" require ] }
|
2008-11-07 21:33:32 -05:00
|
|
|
} cond
|
2010-05-17 11:43:42 -04:00
|
|
|
|
2011-12-12 19:43:49 -05:00
|
|
|
check-cpu-features
|