From 19416ae1b01ce4fc4d430c5bcf6fe74b3027ebf3 Mon Sep 17 00:00:00 2001
From: "Guillermo J. Rozas" <edu/mit/csail/zurich/gjr>
Date: Sun, 9 Feb 1992 14:55:51 +0000
Subject: [PATCH] Split into two files.

---
 v7/src/compiler/machines/i386/instr1.scm | 367 ++++-------------------
 1 file changed, 53 insertions(+), 314 deletions(-)

diff --git a/v7/src/compiler/machines/i386/instr1.scm b/v7/src/compiler/machines/i386/instr1.scm
index 32d709081..39a9b9413 100644
--- a/v7/src/compiler/machines/i386/instr1.scm
+++ b/v7/src/compiler/machines/i386/instr1.scm
@@ -1,6 +1,6 @@
 #| -*-Scheme-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/machines/i386/instr1.scm,v 1.3 1992/02/09 03:44:53 jinx Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/compiler/machines/i386/instr1.scm,v 1.4 1992/02/09 14:55:51 jinx Exp $
 
 Copyright (c) 1992 Massachusetts Institute of Technology
 
@@ -116,11 +116,11 @@ MIT in each case. |#
 	     (ModR/M ,digit target)
 	     (IMMEDIATE value OPERAND UNSIGNED))
 
-	    ((B (? target r/m8) (R (? source)))
+	    ((B (? target r/mB) (R (? source)))
 	     (BYTE (8 ,opcode))
 	     (ModR/M source target))
 
-	    ((B (R (? target)) (? source r/m8))
+	    ((B (R (? target)) (? source r/mB))
 	     (BYTE (8 ,(+ opcode 2)))
 	     (ModR/M target source))
 
@@ -132,12 +132,12 @@ MIT in each case. |#
 	     (BYTE (8 ,(+ opcode 4))
 		   (8 value UNSIGNED)))
 
-	    ((B (? target r/m8) (& (? value)))
+	    ((B (? target r/mB) (& (? value)))
 	     (BYTE (8 #x80))
 	     (ModR/M ,digit target)
 	     (BYTE (8 value SIGNED)))
-
-	    ((B (? target r/m8) (&U (? value)))
+
+	    ((B (? target r/mB) (&U (? value)))
 	     (BYTE (8 #x80))
 	     (ModR/M ,digit target)
 	     (BYTE (8 value UNSIGNED)))))))
@@ -197,7 +197,7 @@ MIT in each case. |#
   (define-bit-test-instruction BTC #xbb 7)
   (define-bit-test-instruction BTR #xb3 6)
   (define-bit-test-instruction BTS #xab 5))
-  
+  
 (define-instruction CALL
   (((@PCR ,dest))
    (BYTE (8 #xe8))
@@ -211,11 +211,11 @@ MIT in each case. |#
    (BYTE (8 #xff))
    (ModR/M 2 dest))
 
-  ((I (? dest mW))
+  ((F (? dest mW))
    (BYTE (8 #xff))
    (ModR/M 3 dest))
 
-  ((I (SEGMENT (? seg)) (OFFSET (? off)))
+  ((F (SEGMENT (? seg)) (OFFSET (? off)))
    (BYTE (8 #x9a))
    (BYTE (16 seg))
    (IMMEDIATE off ADDRESS)))
@@ -228,20 +228,31 @@ MIT in each case. |#
 (define-trivial-instruction CLTS #x0f #x06)
 (define-trivial-instruction CMC #xf5)
 
-(define-instruction CMPS
-  ((W)
-   (BYTE (8 #xa7)))
+(let-syntax
+    ((define-string-instruction
+       (macro (mnemonic opcode)
+	 `(define-instruction ,mnemonic
+	    ((W)
+	     (BYTE (8 ,(1+ opcode))))
+
+	    ((B)
+	     (BYTE (8 ,opcode)))))))
 
-  ((B)
-   (BYTE (8 #xa6))))
+  (define-string-instruction CMPS #xa6)
+  (define-string-instruction LODS #xac)
+  (define-string-instruction INS  #x6c)
+  (define-string-instruction MOVS #xa4)
+  (define-string-instruction OUTS #x6e)
+  (define-string-instruction SCAS #xae)
+  (define-string-instruction STOS #xaa))
 
-(define-instruction CMPXCHG
+(define-instruction CMPXCHG			; 486 only
   ((W (? target r/mW) (R (? reg)))
    (BYTE (8 #x0f)
 	 (8 #xa7))
    (ModR/M reg target))
 
-  ((B (? target r/m8) (R (? reg)))
+  ((B (? target r/mB) (R (? reg)))
    (BYTE (8 #x0f)
 	 (8 #xa6))
    (ModR/M reg target)))
@@ -250,7 +261,7 @@ MIT in each case. |#
 (define-trivial-instruction CDQ #x99)
 (define-trivial-instruction DAA #x27)
 (define-trivial-instruction DAS #x2f)
-
+
 (let-syntax
     ((define-inc/dec
        (macro (mnemonic digit opcode)
@@ -262,7 +273,7 @@ MIT in each case. |#
 	     (BYTE (8 #xff))
 	     (ModR/M ,digit target))
 
-	    ((B (? target r/m8))
+	    ((B (? target r/mB))
 	     (BYTE (8 #xfe))
 	     (ModR/M ,digit target))))))
 
@@ -277,7 +288,7 @@ MIT in each case. |#
 	     (BYTE (8 #xf7))
 	     (ModR/M digit operand))
 
-	    ((B (R 0) (? operand r/m8))
+	    ((B (R 0) (? operand r/mB))
 	     (BYTE (8 #xf6))
 	     (ModR/M digit operand))))))
 
@@ -318,12 +329,12 @@ MIT in each case. |#
    (BYTE (8 #x69))
    (ModR/M target source)
    (IMMEDIATE value OPERAND UNSIGNED))
-
+
   ((W ((R 2) : (R 0)) (? source r/mW))
    (BYTE (8 #xf7))
    (ModR/M 5 source))
 
-  ((B (R 0) (? source r/m8))
+  ((B (R 0) (? source r/mB))
    (BYTE (8 #xf6))
    (ModR/M 5 source)))
 
@@ -342,13 +353,6 @@ MIT in each case. |#
   ((B (R 0) (R 2))
    (BYTE (8 #xec))))
 
-(define-instruction INS
-  ((W)
-   (BYTE (8 #x6d)))
-
-  ((B)
-   (BYTE (8 #x6c))))
-
 (define-instruction INT
   ((3)
    (BYTE (8 #xcc)))
@@ -358,14 +362,7 @@ MIT in each case. |#
 	 (8 vector))))
 
 (define-trivial-instruction INTO #xce)
-(define-trivial-instruction INVD #x0f #x08)	; 486 only?
-
-(define-instruction INVLPG			; 486 only?
-  (((? address mW))
-   (BYTE (8 #x0f)
-	 (8 #x01))
-   (ModR/M 7 address)))
-
+(define-trivial-instruction INVD #x0f #x08)	; 486 only
 (define-trivial-instruction IRET #xcf)
 
 (let-syntax
@@ -401,7 +398,7 @@ MIT in each case. |#
 	     (BYTE (8 #x0f)
 		   (8 ,opcode2))
 	     (IMMEDIATE displ ADDRESS))))))
-
+
   (define-jump-instruction JA   #x77 #x87)
   (define-jump-instruction JAE  #x73 #x83)
   (define-jump-instruction JB   #x72 #x82)
@@ -468,7 +465,7 @@ MIT in each case. |#
   (((? dest r/mW))
    (BYTE (8 #xff))
    (ModR/M 4 dest))
-
+
   ((B (@PCR (? dest)))
    (BYTE (8 #xeb)
 	 (8 `(- ,dest (+ *PC* 1)) SIGNED)))
@@ -485,11 +482,11 @@ MIT in each case. |#
    (BYTE (8 #xe9))
    (IMMEDIATE displ ADDRESS))
 
-  ((I (? dest mW))
+  ((F (? dest mW))
    (BYTE (8 #xff))
    (ModR/M 5 dest))
 
-  ((I (SEGMENT (? seg)) (OFFSET (? off)))
+  ((F (SEGMENT (? seg)) (OFFSET (? off)))
    (BYTE (8 #xea))
    (BYTE (16 seg))
    (IMMEDIATE off ADDRESS)))
@@ -509,283 +506,25 @@ MIT in each case. |#
 
 (define-trivial-instruction LEAVE #xc9)
 
-(define-instruction LGDT
-  (((? source mW))
-   (BYTE (8 #x0f)
-	 (8 #x01))
-   (ModR/M 2 source)))
-
-(define-instruction LIDT
-  (((? source mW))
-   (BYTE (8 #x0f)
-	 (8 #x01))
-   (ModR/M 3 source)))
-
-(let-syntax
-    ((define-load-segment
-       (macro (mnemonic . bytes)
-	 `(define-instruction ,mnemonic
-	    (((R (? reg)) (? pointer mW))
-	     (BYTE ,@(map (lambda (byte)
-			    `(8 ,byte))
-			  bytes))
-	     (ModR/M reg pointer))))))
-
-  (define-load-segment LDS #xc5)
-  (define-load-segment LSS #x0f #xb2)
-  (define-load-segment LES #xc4)
-  (define-load-segment LFS #x0f #xb4)
-  (define-load-segment LGS #x0f #xb5))
-
 (let-syntax
-    ((define-load-state
+    ((define-load/store-state
        (macro (mnemonic opcode digit)
 	 `(define-instruction ,mnemonic
-	    (((? source r/mW))
-	     (BYTE (8 #x0f)
-		   (8 ,opcode))
-	     (ModR/M ,digit source))))))
-
-  (define-load-state LLDT #x00 2)
-  (define-load-state LMSW #x01 6))
-
-(define-trivial-instruction LOCK #xf0)
-
-(define-instruction LODS
-  ((B)
-   (BYTE (8 #xac)))
-
-  ((W)
-   (BYTE (8 #xad))))
-
-(define-instruction LSL
-  (((R (? reg)) (? source r/mW))
-   (BYTE (8 #x0f)
-	 (8 #x03))
-   (ModR/M reg source)))
-
-(define-instruction LTR
-  (((? source r/mW))
-   (BYTE (8 #x0f)
-	 (8 #x00))
-   (ModR/M 3 source)))
-
-(define-instruction MOV
-  ;; **** Missing MOV to/from special registers ****
-  ((W (R (? target)) (? source r/mW))
-   (BYTE (8 #x8b))
-   (ModR/M target source))
-
-  ((W (? target r/mW) (R (? source)))
-   (BYTE (8 #x89))
-   (ModR/M source target))
-
-  ((W (R (? reg)) (& (? value)))
-   (BYTE (8 (+ #xb8 reg)))
-   (IMMEDIATE value))
-
-  ((W (? target r/mW) (& (? value)))
-   (BYTE (8 #xc7))
-   (ModR/M 0 target)
-   (IMMEDIATE value))
-
-  ((W (R (? reg)) (&U (? value)))
-   (BYTE (8 (+ #xb8 reg)))
-   (IMMEDIATE value OPERAND UNSIGNED))
-
-  ((W (? target r/mW) (&U (? value)))
-   (BYTE (8 #xc7))
-   (ModR/M 0 target)
-   (IMMEDIATE value OPERAND UNSIGNED))
-
-  ((B (R (? target)) (? source r/m8))
-   (BYTE (8 #x8a))
-   (ModR/M target source))
-
-  ((B (? target r/m8) (R (? source)))
-   (BYTE (8 #x88))
-   (ModR/M source target))
-
-  ((B (R (? reg)) (& (? value)))
-   (BYTE (8 (+ #xb0 reg))
-	 (8 value SIGNED)))
-
-  ((B (? target r/m8) (& (? value)))
-   (BYTE (8 #xc6))
-   (ModR/M 0 target)
-   (BYTE (8 value SIGNED)))
-
-  ((B (R (? reg)) (&U (? value)))
-   (BYTE (8 (+ #xb0 reg))
-	 (8 value UNSIGNED)))
-
-  ((B (? target r/m8) (&U (? value)))
-   (BYTE (8 #xc6))
-   (ModR/M 0 target)
-   (BYTE (8 value UNSIGNED)))
-
-  ((W (R 0) (@ (? offset)))
-   (BYTE (8 #xa1))
-   (IMMEDIATE offset))
-
-  ((W (@ (? offset)) (R 0))
-   (BYTE (8 #xa3))
-   (IMMEDIATE offset))
-
-  ((B (R 0) (@ (? offset)))
-   (BYTE (8 #xa0)
-	 (8 offset SIGNED)))
-
-  ((B (@ (? offset)) (R 0))
-   (BYTE (8 #xa2)
-	 (8 offset SIGNED)))
-
-  (((? target r/mW) (S (? source)))
-   (BYTE (8 #x8c))
-   (ModR/M source target))
-
-  (((S (? target)) (? source r/mW))
-   (BYTE (8 #x8e))
-   (ModR/M target source)))
-
-(define-instruction MOVS
-  ((B)
-   (BYTE (8 #xa4)))
-
-  ((W)
-   (BYTE (8 #xa5))))
-
-(let-syntax
-    ((define-data-extension
-       (macro (mnemonic opcode)
-	 `(define-instruction ,mnemonic
-	    ((B (R (? target)) (? source r/m8))
+	    (((? operand mW))
 	     (BYTE (8 #x0f)
 		   (8 ,opcode))
-	     (ModR/M target source))
-
-	    ((H (R (? target)) (? source r/mW))
-	     (BYTE (8 #x0f)
-		   (8 ,(1+ opcode)))
-	     (ModR/M target source))))))
-
-  (define-data-extension MOVSX #xbe)
-  (define-data-extension MOVZX #xb6))
-
-(let-syntax
-    ((define-unary
-       (macro (mnemonic digit)
-	 `(define-instruction ,mnemonic
-	    ((W (? operand r/mW))
-	     (BYTE (8 #xf7))
-	     (ModR/M ,digit operand))
-
-	    ((B (? operand r/m8))
-	     (BYTE (8 #xf6))
-	     (ModR/M ,digit operand))))))
-
-  (define-unary NEG 3)
-  (define-unary NOT 2))
-
-(define-trivial-instruction NOP #x90)
-
-(define-instruction OUT
-  ((W (& (? port)) (R 0))
-   (BYTE (8 #xe7)
-	 (8 port)))
-
-  ((W (R 2) (R 0))
-   (BYTE (8 #xef)))
-
-  ((B (& (? port)) (R 0))
-   (BYTE (8 #xe6)
-	 (8 port)))
-
-  ((B (R 2) (R 0))
-   (BYTE (8 #xee))))
-
-(define-instruction OUTS
-  ((W)
-   (BYTE (8 #x6f)))
-
-  ((B)
-   (BYTE (8 #x6e))))
-
-(define-instruction POP
-  (((R (? target)))
-   (BYTE (8 (+ #x58 target))))
-
-  (((? target mW))
-   (BYTE (8 #x8f))
-   (ModR/M 0 target))
-
-  (((DS))
-   (BYTE (8 #x1f)))
-
-  (((ES))
-   (BYTE (8 #x07)))
-
-  (((SS))
-   (BYTE (8 #x17)))
-
-  (((FS))
-   (BYTE (8 #x0f)
-	 (8 #xa1)))
-
-  (((GS))
-   (BYTE (8 #x0f)
-	 (8 #xa9))))
-
-(define-trivial-instruction POPA #x61)
-(define-trivial-instruction POPAD #x61)
-(define-trivial-instruction POPF #x9d)
-(define-trivial-instruction POPFD #x9d)
-
-(define-instruction PUSH
-  (((R (? source)))
-   (BYTE (8 (+ #x50 source))))
-
-  (((? source mW))
-   (BYTE (8 #xff))
-   (ModR/M 6 source))
-
-  ((W (& (? value)))
-   (BYTE (8 #x68))
-   (IMMEDIATE value))
-
-  ((W (&U (? value)))
-   (BYTE (8 #x6a))
-   (IMMEDIATE value OPERAND UNSIGNED))
-
-  ((B (& (? value)))
-   (BYTE (8 #x6a)
-	 (8 value)))
-
-  ((B (&U (? value)))
-   (BYTE (8 #x6a)
-	 (8 value UNSIGNED)))
-
-  (((CS))
-   (BYTE (8 #x0e)))
-
-  (((SS))
-   (BYTE (8 #x16)))
-
-  (((DS))
-   (BYTE (8 #x1e)))
-
-  (((ES))
-   (BYTE (8 #x06)))
-
-  (((FS))
-   (BYTE (8 #x0f)
-	 (8 #xa0)))
-
-  (((GS))
-   (BYTE (8 #x0f)
-	 (8 #xa8))))
+	     (ModR/M digit operand))))))
 
-(define-trivial-instruction PUSHA  #x60)
-(define-trivial-instruction PUSHAD #x60)
-(define-trivial-instruction PUSHF  #x9c)
-(define-trivial-instruction PUSHFD #x9c)
\ No newline at end of file
+  (define-load/store-state INVLPG #x01 7)	; 486 only
+  (define-load/store-state LGDT   #x01 2)
+  (define-load/store-state LIDT   #x01 3)
+  (define-load/store-state LLDT   #x00 2)
+  (define-load/store-state LMSW   #x01 6)
+  (define-load/store-state LTR    #x00 3)
+  (define-load/store-state SGDT   #x01 0)
+  (define-load/store-state SIDT   #x01 1)
+  (define-load/store-state SLDT   #x00 0)
+  (define-load/store-state SMSW   #x01 4)
+  (define-load/store-state STR    #x00 1)
+  (define-load/store-state VERR   #x00 4)
+  (define-load/store-state VERW   #x00 5))
\ No newline at end of file
-- 
2.25.1