From df230e7cd9a191352473f3efe8fecac9e503975c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 23 Dec 2005 06:41:33 +0000 Subject: [PATCH] some assembler tweaks, and a fix for indirect literal load relocation --- TODO.FACTOR.txt | 1 + library/compiler/amd64/architecture.factor | 9 +++++++-- library/compiler/x86/architecture.factor | 5 ++++- library/compiler/x86/assembler.factor | 8 ++++++-- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 6d86920998..db71891dc2 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -1,5 +1,6 @@ + 0.80: +- make-image leaks memory if there is an error while parsing files - runtime primitives like fopen: check for null input - make = for sequences more efficient - zero-height gadgets mess up hit testing diff --git a/library/compiler/amd64/architecture.factor b/library/compiler/amd64/architecture.factor index 6faae65601..ff9e5276a1 100644 --- a/library/compiler/amd64/architecture.factor +++ b/library/compiler/amd64/architecture.factor @@ -1,6 +1,6 @@ IN: compiler-backend -USING: alien assembler compiler compiler-backend kernel -sequences ; +USING: alien arrays assembler compiler compiler-backend kernel +math sequences ; ! AMD64 register assignments ! RAX RCX RDX RSI RDI R8 R9 R10 R11 vregs @@ -48,3 +48,8 @@ M: float-regs fastcall-regs drop 0 ; : compile-prologue RSP 8 SUB ; inline : compile-epilogue RSP 8 ADD ; inline + +: load-indirect ( dest literal -- ) + #! We use RIP-relative addressing. The '3' is a hardcoded + #! instruction length. + add-literal from 3 - 1array MOV ; inline diff --git a/library/compiler/x86/architecture.factor b/library/compiler/x86/architecture.factor index 78eababc1b..d1a5cee1f4 100644 --- a/library/compiler/x86/architecture.factor +++ b/library/compiler/x86/architecture.factor @@ -1,5 +1,5 @@ IN: compiler-backend -USING: alien assembler compiler compiler-backend kernel +USING: alien arrays assembler compiler compiler-backend kernel sequences ; ! x86 register assignments @@ -45,3 +45,6 @@ M: float-regs fastcall-regs drop 0 ; : compile-prologue ; inline : compile-epilogue ; inline + +: load-indirect ( dest literal -- ) + add-literal 1array MOV rel-absolute-cell rel-address ; inline diff --git a/library/compiler/x86/assembler.factor b/library/compiler/x86/assembler.factor index b405802d2a..51e52a2f96 100644 --- a/library/compiler/x86/assembler.factor +++ b/library/compiler/x86/assembler.factor @@ -6,6 +6,10 @@ lists math namespaces parser sequences words ; ! A postfix assembler for x86 and AMD64. +! In 32-bit mode, { 1234 } is absolute indirect addressing. +! In 64-bit mode, { 1234 } is RIP-relative. +! Beware! + : byte? -128 127 between? ; GENERIC: modifier ( op -- mod ) @@ -76,7 +80,7 @@ PREDICATE: array displaced M: displaced modifier second byte? BIN: 01 BIN: 10 ? ; M: displaced register first register ; M: displaced displacement - second dup byte? [ assemble-1 ] [ assemble-cell ] if ; + second dup byte? [ assemble-1 ] [ assemble-4 ] if ; M: displaced canonicalize dup first EBP = not over second 0 = and [ first 1array ] when ; @@ -92,7 +96,7 @@ M: disp-only register #! x86 encodes displacement-only as { EBP }. drop BIN: 101 ; M: disp-only displacement - first assemble-cell ; + first assemble-4 ; ( Utilities ) UNION: operand register indirect displaced disp-only ;