x86 assembler fixes for new code heap layout
parent
40e3a2a063
commit
9dc1a9854a
|
@ -57,6 +57,9 @@ DEFER: %jump-t ( label vreg -- )
|
||||||
! Jump table of addresses (one cell each) is right after this
|
! Jump table of addresses (one cell each) is right after this
|
||||||
DEFER: %dispatch ( vreg -- )
|
DEFER: %dispatch ( vreg -- )
|
||||||
|
|
||||||
|
! Jump table entry
|
||||||
|
DEFER: %target ( label -- )
|
||||||
|
|
||||||
! Return to caller
|
! Return to caller
|
||||||
DEFER: %return ( -- )
|
DEFER: %return ( -- )
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ M: #call-label generate-node ( node -- next )
|
||||||
{ +input { { f "n" } } }
|
{ +input { { f "n" } } }
|
||||||
{ +scratch { { f "scratch" } } }
|
{ +scratch { { f "scratch" } } }
|
||||||
} with-template
|
} with-template
|
||||||
node-children [ <label> dup target-label 2array ] map ;
|
node-children [ <label> dup %target 2array ] map ;
|
||||||
|
|
||||||
: dispatch-body ( label/node -- )
|
: dispatch-body ( label/node -- )
|
||||||
<label> swap [
|
<label> swap [
|
||||||
|
|
|
@ -84,6 +84,8 @@ M: object load-literal ( literal vreg -- )
|
||||||
"n" operand MTLR
|
"n" operand MTLR
|
||||||
BLR ;
|
BLR ;
|
||||||
|
|
||||||
|
: %target ( label -- ) 0 , rel-absolute-cell rel-label ;
|
||||||
|
|
||||||
: %return ( -- ) %epilogue BLR ;
|
: %return ( -- ) %epilogue BLR ;
|
||||||
|
|
||||||
: compile-dlsym ( symbol dll register -- )
|
: compile-dlsym ( symbol dll register -- )
|
||||||
|
|
|
@ -4,6 +4,8 @@ USING: alien arrays assembler generic kernel kernel-internals
|
||||||
math memory namespaces sequences words ;
|
math memory namespaces sequences words ;
|
||||||
IN: compiler
|
IN: compiler
|
||||||
|
|
||||||
|
: code-format 1 ; inline
|
||||||
|
|
||||||
! x86 register assignments
|
! x86 register assignments
|
||||||
! EAX, ECX, EDX integer vregs
|
! EAX, ECX, EDX integer vregs
|
||||||
! XMM0 - XMM7 float vregs
|
! XMM0 - XMM7 float vregs
|
||||||
|
@ -106,6 +108,9 @@ M: object load-literal ( literal vreg -- )
|
||||||
|
|
||||||
: %jump-t ( label -- ) "flag" operand f v>operand CMP JNE ;
|
: %jump-t ( label -- ) "flag" operand f v>operand CMP JNE ;
|
||||||
|
|
||||||
|
: compile-aligned ( -- )
|
||||||
|
compiled-offset [ 8 align ] keep - 0 <array> % ;
|
||||||
|
|
||||||
: %dispatch ( -- )
|
: %dispatch ( -- )
|
||||||
#! Compile a piece of code that jumps to an offset in a
|
#! Compile a piece of code that jumps to an offset in a
|
||||||
#! jump table indexed by the fixnum at the top of the stack.
|
#! jump table indexed by the fixnum at the top of the stack.
|
||||||
|
@ -126,6 +131,8 @@ M: object load-literal ( literal vreg -- )
|
||||||
! Fix up jump table pointer
|
! Fix up jump table pointer
|
||||||
"end" get resolve-label ;
|
"end" get resolve-label ;
|
||||||
|
|
||||||
|
: %target ( label -- ) 0 cell, rel-absolute-cell rel-label ;
|
||||||
|
|
||||||
: %return ( -- ) %epilogue RET ;
|
: %return ( -- ) %epilogue RET ;
|
||||||
|
|
||||||
: %move-int>int ( dst src -- )
|
: %move-int>int ( dst src -- )
|
||||||
|
|
|
@ -266,6 +266,7 @@ GENERIC: PUSH ( op -- )
|
||||||
M: register PUSH f HEX: 50 short-operand ;
|
M: register PUSH f HEX: 50 short-operand ;
|
||||||
M: integer PUSH HEX: 68 , 4, ;
|
M: integer PUSH HEX: 68 , 4, ;
|
||||||
M: callable PUSH 0 PUSH rel-absolute rel-word ;
|
M: callable PUSH 0 PUSH rel-absolute rel-word ;
|
||||||
|
M: label PUSH 0 PUSH rel-absolute rel-label ;
|
||||||
M: operand PUSH BIN: 110 f HEX: ff 1-operand ;
|
M: operand PUSH BIN: 110 f HEX: ff 1-operand ;
|
||||||
|
|
||||||
GENERIC: POP ( op -- )
|
GENERIC: POP ( op -- )
|
||||||
|
@ -280,24 +281,26 @@ M: operand (MOV-I) BIN: 000 t HEX: c7 1-operand 4, ;
|
||||||
GENERIC: MOV ( dst src -- )
|
GENERIC: MOV ( dst src -- )
|
||||||
M: integer MOV swap (MOV-I) ;
|
M: integer MOV swap (MOV-I) ;
|
||||||
M: callable MOV 0 rot (MOV-I) rel-absolute-cell rel-word ;
|
M: callable MOV 0 rot (MOV-I) rel-absolute-cell rel-word ;
|
||||||
|
M: label MOV 0 rot (MOV-I) rel-absolute-cell rel-label ;
|
||||||
M: operand MOV HEX: 89 2-operand ;
|
M: operand MOV HEX: 89 2-operand ;
|
||||||
|
|
||||||
( Control flow )
|
( Control flow )
|
||||||
GENERIC: JMP ( op -- )
|
GENERIC: JMP ( op -- )
|
||||||
! M: integer JMP HEX: e9 , from 4, ;
|
: (JMP) HEX: e9 , 0 4, rel-relative ;
|
||||||
M: callable JMP 0 JMP rel-relative rel-word ;
|
M: callable JMP (JMP) rel-word ;
|
||||||
|
M: label JMP (JMP) rel-label ;
|
||||||
M: operand JMP BIN: 100 t HEX: ff 1-operand ;
|
M: operand JMP BIN: 100 t HEX: ff 1-operand ;
|
||||||
|
|
||||||
GENERIC: CALL ( op -- )
|
GENERIC: CALL ( op -- )
|
||||||
! M: integer CALL HEX: e8 , from 4, ;
|
: (CALL) HEX: e8 , 0 4, rel-relative ;
|
||||||
M: callable CALL 0 CALL rel-relative rel-word ;
|
M: callable CALL (CALL) rel-word ;
|
||||||
|
M: label CALL (CALL) rel-label ;
|
||||||
M: operand CALL BIN: 010 t HEX: ff 1-operand ;
|
M: operand CALL BIN: 010 t HEX: ff 1-operand ;
|
||||||
|
|
||||||
G: JUMPcc ( addr opcode -- ) 1 standard-combination ;
|
G: JUMPcc ( addr opcode -- ) 1 standard-combination ;
|
||||||
! M: integer JUMPcc ( addr opcode -- )
|
: (JUMPcc) HEX: 0f , , 0 4, rel-relative ;
|
||||||
! swap HEX: 0f , swap , from assemble-4 ;
|
M: callable JUMPcc ( addr opcode -- ) (JUMPcc) rel-word ;
|
||||||
M: callable JUMPcc ( addr opcode -- )
|
M: label JUMPcc ( addr opcode -- ) (JUMPcc) rel-label ;
|
||||||
swap >r 0 swap JUMPcc r> rel-relative rel-word ;
|
|
||||||
|
|
||||||
: JO HEX: 80 JUMPcc ;
|
: JO HEX: 80 JUMPcc ;
|
||||||
: JNO HEX: 81 JUMPcc ;
|
: JNO HEX: 81 JUMPcc ;
|
||||||
|
|
Loading…
Reference in New Issue