diff --git a/library/bootstrap/boot-stage2.factor b/library/bootstrap/boot-stage2.factor index aa4ea27185..c75f69fc74 100644 --- a/library/bootstrap/boot-stage2.factor +++ b/library/bootstrap/boot-stage2.factor @@ -56,6 +56,7 @@ cpu "x86" = [ cpu "ppc" = [ "/library/compiler/ppc/assembler.factor" "/library/compiler/ppc/stack.factor" + "/library/compiler/ppc/generator.factor" ] pull-in "compile" get cpu "x86" = and [ diff --git a/library/compiler/ppc/assembler.factor b/library/compiler/ppc/assembler.factor index 120128d238..a590dc9fe7 100644 --- a/library/compiler/ppc/assembler.factor +++ b/library/compiler/ppc/assembler.factor @@ -3,6 +3,9 @@ IN: assembler USING: errors kernel math memory words ; +! See the Motorola or IBM documentation for details. The opcode +! names are standard. + : insn ( operand opcode -- ) 26 shift bitor compile-cell ; : b-form ( bo bi bd aa lk -- n ) @@ -10,7 +13,7 @@ USING: errors kernel math memory words ; r> bitor r> bitor r> bitor r> bitor ; : d-form ( d a simm -- n ) - >r 16 shift >r 21 shift r> bitor r> bitor ; + HEX: ffff bitand >r 16 shift >r 21 shift r> bitor r> bitor ; : i-form ( li aa lk -- n ) >r 1 shift bitor r> bitor ; @@ -19,6 +22,7 @@ USING: errors kernel math memory words ; 1 shift >r 11 shift >r 21 shift r> bitor r> bitor ; : ADDI d-form 14 insn ; +: SUBI neg ADDI ; : LI 0 rot ADDI ; : ADDIS d-form 15 insn ; : LIS 0 rot ADDIS ; @@ -30,5 +34,6 @@ USING: errors kernel math memory words ; : MFLR 8 MFSPR ; : MTSPR 5 shift 467 xfx-form 31 insn ; : MTLR 8 MTSPR ; +: LWZ d-form 32 insn ; : STW d-form 36 insn ; : STWU d-form 37 insn ; diff --git a/library/compiler/ppc/generator.factor b/library/compiler/ppc/generator.factor new file mode 100644 index 0000000000..f23bea1372 --- /dev/null +++ b/library/compiler/ppc/generator.factor @@ -0,0 +1,6 @@ +! Copyright (C) 2005 Slava Pestov. +! See http://factor.sf.net/license.txt for BSD license. +IN: compiler +USING: assembler inference kernel words ; + +#return [ drop BLR ] "generator" set-word-prop diff --git a/library/compiler/ppc/stack.factor b/library/compiler/ppc/stack.factor index 73ed5832aa..9bb9045a21 100644 --- a/library/compiler/ppc/stack.factor +++ b/library/compiler/ppc/stack.factor @@ -1,11 +1,18 @@ ! Copyright (C) 2005 Slava Pestov. ! See http://factor.sf.net/license.txt for BSD license. IN: assembler -USING: errors kernel math memory words ; +USING: compiler errors kernel math memory words ; -: PUSH-DS - #! Push r18 on the data stack. - 18 14 4 STWU ; +! Pushing and popping the data stack. +: PEEK-DS 18 14 0 LWZ ; +: POP-DS PEEK-DS 14 14 4 SUBI ; +: PUSH-DS 18 14 4 STWU ; +: REPL-DS 18 14 0 STW ; + +! Pushing and popping the return stack. +: PEEK-CS 18 15 0 LWZ ; +: POP-CS PEEK-CS 15 15 4 SUBI ; +: PUSH-CS 18 15 4 STWU ; : w>h/h dup -16 shift HEX: ffff bitand >r HEX: ffff bitand r> ; @@ -15,8 +22,19 @@ USING: errors kernel math memory words ; 18 LI ] [ w>h/h 18 LIS 18 18 rot ORI - ] ifte PUSH-DS ; + ] ifte ; -: PUSH-CS - #! Push r18 on the return stack. - 18 15 4 STWU ; +#push-immediate [ + immediate-literal PUSH-DS +] "generator" set-word-prop + +#replace-immediate [ + immediate-literal REPL-DS +] "generator" set-word-prop + +\ drop [ drop 14 14 4 SUBI ] "generator" set-word-prop +\ dup [ drop PEEK-DS PUSH-DS ] "generator" set-word-prop +\ over [ drop 18 14 -4 LWZ PUSH-DS ] "generator" set-word-prop +\ pick [ drop 18 14 -8 LWZ PUSH-DS ] "generator" set-word-prop +\ >r [ drop POP-DS PUSH-CS ] "generator" set-word-prop +\ r> [ drop POP-CS PUSH-DS ] "generator" set-word-prop diff --git a/native/compiler.h b/native/compiler.h index e7b91f7800..5eaa294dc6 100644 --- a/native/compiler.h +++ b/native/compiler.h @@ -23,7 +23,7 @@ void primitive_set_literal_top(void); void collect_literals(void); #ifdef FACTOR_PPC -extern void flush_icache(void *start, int len); +void flush_icache(void *start, int len); #else INLINE void flush_icache(void *start, int len) {} #endif diff --git a/native/factor.h b/native/factor.h index 7613978d84..9e01dc2db1 100644 --- a/native/factor.h +++ b/native/factor.h @@ -1,11 +1,7 @@ #ifndef __FACTOR_H__ #define __FACTOR_H__ -#if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32) - #define FACTOR_X86 -#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) - #define FACTOR_PPC -#endif +#include "platform.h" #if defined(WIN32) #define DLLEXPORT __declspec(dllexport) diff --git a/native/icache.S b/native/icache.S index 0de27b42ab..dda9df2048 100644 --- a/native/icache.S +++ b/native/icache.S @@ -1,3 +1,5 @@ +#include "platform.h" + /* Thanks to Joshua Grams for this code. On PowerPC processors, we must flush the instruction cache manually @@ -12,8 +14,8 @@ This function is called from compiler.c. */ /* IN: 3 = start, 4 = len */ - .global _flush_icache -_flush_icache: + .global flush_icache +flush_icache: /* compute number of cache lines to flush */ add 4,4,3 clrrwi 3,3,5 /* align addr to next lower cache line boundary */ diff --git a/native/platform.h b/native/platform.h new file mode 100644 index 0000000000..26dca9f450 --- /dev/null +++ b/native/platform.h @@ -0,0 +1,5 @@ +#if defined(i386) || defined(__i386) || defined(__i386__) || defined(WIN32) + #define FACTOR_X86 +#elif defined(__POWERPC__) || defined(__ppc__) || defined(_ARCH_PPC) + #define FACTOR_PPC +#endif