From 9c0a8b3250f24555b94c03d066ece12721df871d Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 19 Sep 2012 08:40:18 -0700 Subject: [PATCH] cpu.x86: Fix load order. --- basis/cpu/x86/32/32.factor | 31 ++++++++++++++++------- basis/cpu/x86/64/64.factor | 29 +++++++++++++-------- basis/cpu/x86/features/features.factor | 35 ++++---------------------- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/basis/cpu/x86/32/32.factor b/basis/cpu/x86/32/32.factor index c15e43c848..4c9680f0ba 100755 --- a/basis/cpu/x86/32/32.factor +++ b/basis/cpu/x86/32/32.factor @@ -1,14 +1,13 @@ ! Copyright (C) 2005, 2011 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: locals alien alien.c-types alien.libraries alien.syntax -arrays kernel fry math namespaces sequences system layouts io -vocabs.loader accessors init classes.struct combinators make -words compiler.constants compiler.codegen.gc-maps -compiler.codegen.labels compiler.codegen.relocation -compiler.cfg.instructions compiler.cfg.builder -compiler.cfg.builder.alien.boxing compiler.cfg.intrinsics -compiler.cfg.stack-frame cpu.x86.assembler -cpu.x86.assembler.operands cpu.x86 cpu.architecture vm vocabs ; +USING: accessors alien alien.c-types arrays classes.struct +combinators compiler.cfg.builder.alien.boxing +compiler.codegen.gc-maps compiler.codegen.labels +compiler.codegen.relocation compiler.constants cpu.architecture +cpu.x86 cpu.x86.assembler cpu.x86.assembler.operands +cpu.x86.features kernel locals make math namespaces sequences +specialized-arrays system vocabs ; +SPECIALIZED-ARRAY: uint FROM: layouts => cell ; IN: cpu.x86.32 @@ -231,4 +230,18 @@ M: x86.32 flatten-struct-type M: x86.32 struct-return-on-stack? os linux? not ; +M: x86.32 (cpuid) ( n regs -- ) + void { uint void* } cdecl [ + ! Save ds-reg, rs-reg + EDI PUSH + EAX ESP 4 [+] MOV + CPUID + EDI ESP 8 [+] MOV + EDI [] EAX MOV + EDI 4 [+] EBX MOV + EDI 8 [+] ECX MOV + EDI 12 [+] EDX MOV + EDI POP + ] alien-assembly ; + check-cpu-features diff --git a/basis/cpu/x86/64/64.factor b/basis/cpu/x86/64/64.factor index 1934b0ebb6..8270dc758c 100644 --- a/basis/cpu/x86/64/64.factor +++ b/basis/cpu/x86/64/64.factor @@ -1,15 +1,13 @@ ! Copyright (C) 2005, 2011 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays kernel math namespaces make sequences -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 ; +USING: alien alien.c-types assocs combinators +compiler.cfg.intrinsics compiler.codegen.gc-maps +compiler.codegen.labels compiler.codegen.relocation +compiler.constants cpu.architecture cpu.x86 cpu.x86.assembler +cpu.x86.assembler.operands cpu.x86.features kernel locals math +sequences specialized-arrays system vocabs ; FROM: layouts => cell cells ; +SPECIALIZED-ARRAY: uint IN: cpu.x86.64 : param-reg ( n -- reg ) int-regs cdecl param-regs at nth ; @@ -133,12 +131,21 @@ M: x86.64 float-on-stack? f ; M: x86.64 struct-return-on-stack? f ; +M: x86.64 (cpuid) ( n regs -- ) + void { uint void* } cdecl [ + RAX param-reg-0 MOV + RSI param-reg-1 MOV + CPUID + RSI [] EAX MOV + RSI 4 [+] EBX MOV + RSI 8 [+] ECX MOV + RSI 12 [+] EDX MOV + ] alien-assembly ; + ! The result of reading 4 bytes from memory is a fixnum on ! x86-64. enable-alien-4-intrinsics -USE: vocabs - { { [ os unix? ] [ "cpu.x86.64.unix" require ] } { [ os windows? ] [ "cpu.x86.64.windows" require ] } diff --git a/basis/cpu/x86/features/features.factor b/basis/cpu/x86/features/features.factor index 9b5dc20338..1ad8f93cf3 100644 --- a/basis/cpu/x86/features/features.factor +++ b/basis/cpu/x86/features/features.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2009, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs sequences alien alien.c-types -combinators compiler compiler.codegen.labels compiler.units -cpu.architecture cpu.x86.assembler cpu.x86.assembler.operands -init io kernel locals math math.order math.parser memoize -namespaces system arrays specialized-arrays cpu.x86.64 ; +USING: alien alien.c-types arrays assocs combinators +compiler.codegen.labels cpu.architecture cpu.x86.assembler +cpu.x86.assembler.operands init kernel math math.order +math.parser memoize namespaces sequences +specialized-arrays system ; SPECIALIZED-ARRAY: uint IN: cpu.x86.features @@ -87,31 +87,6 @@ MEMO: sse-version ( -- n ) HOOK: (cpuid) cpu ( n regs -- ) -M: x86.32 (cpuid) ( n regs -- ) - void { uint void* } cdecl [ - ! Save ds-reg, rs-reg - EDI PUSH - EAX ESP 4 [+] MOV - CPUID - EDI ESP 8 [+] MOV - EDI [] EAX MOV - EDI 4 [+] EBX MOV - EDI 8 [+] ECX MOV - EDI 12 [+] EDX MOV - EDI POP - ] alien-assembly ; - -M: x86.64 (cpuid) ( n regs -- ) - void { uint void* } cdecl [ - RAX param-reg-0 MOV - RSI param-reg-1 MOV - CPUID - RSI [] EAX MOV - RSI 4 [+] EBX MOV - RSI 8 [+] ECX MOV - RSI 12 [+] EDX MOV - ] alien-assembly ; - : cpuid ( n -- 4array ) 4 [ (cpuid) ] keep >array ;