1.0.17.24: refactor handling of constants in the compiler
[sbcl.git] / src / compiler / x86-64 / insts.lisp
index 6140711..75cf555 100644 (file)
   (accum :type 'accum)
   (imm))
 
+(sb!disassem:define-instruction-format (two-bytes 16
+                                        :default-printer '(:name))
+  (op :fields (list (byte 8 0) (byte 8 8))))
+
 ;;; A one-byte instruction with a #x66 prefix, used to indicate an
 ;;; operand size of :word.
 (sb!disassem:define-instruction-format (x66-byte 16
                                      :default-printer '(:name :tab code))
  (op :field (byte 8 0))
  (code :field (byte 8 8)))
+
+;;; Two byte instruction with an immediate byte argument.
+;;;
+(sb!disassem:define-instruction-format (word-imm 24
+                                     :default-printer '(:name :tab code))
+  (op :field (byte 16 0))
+  (code :field (byte 8 16)))
+
 \f
 ;;;; primitive emitters
 
                                             (- (label-position where)
                                                (+ posn 4))))))
      (fixup
-      (emit-byte segment #b11101000)
-      (emit-relative-fixup segment where))
+      ;; There is no CALL rel64...
+      (error "Cannot CALL a fixup: ~S" where))
      (t
       (maybe-emit-rex-for-ea segment where nil :operand-size :do-not-set)
       (emit-byte segment #b11111111)
           (emit-byte segment #b11111111)
           (emit-ea segment where #b100)))))
 
-(define-instruction jmp-short (segment label)
-  (:emitter
-   (emit-byte segment #b11101011)
-   (emit-byte-displacement-backpatch segment label)))
-
 (define-instruction ret (segment &optional stack-delta)
   (:printer byte ((op #b11000011)))
   (:printer byte ((op #b11000010) (imm nil :type 'imm-word-16))
          (t
           (emit-byte segment #b11000011)))))
 
-(define-instruction jecxz (segment target)
+(define-instruction jrcxz (segment target)
   (:printer short-jump ((op #b0011)))
   (:emitter
    (emit-byte segment #b11100011)
     ;; Lisp (with (DESCRIBE 'BYTE-IMM-CODE)) than to definitively deduce
     ;; from first principles whether it's defined in some way that genesis
     ;; can't grok.
-    (case (byte-imm-code chunk dstate)
+    (case #!-darwin (byte-imm-code chunk dstate)
+          #!+darwin (word-imm-code chunk dstate)
       (#.error-trap
        (nt "error trap")
        (sb!disassem:handle-break-args #'snarf-error-junk stream dstate))
 
 (define-instruction break (segment code)
   (:declare (type (unsigned-byte 8) code))
-  (:printer byte-imm ((op #b11001100)) '(:name :tab code)
-            :control #'break-control)
-  (:emitter
-   (emit-byte segment #b11001100)
+  #!-darwin (:printer byte-imm ((op #b11001100)) '(:name :tab code)
+                     :control #'break-control)
+  #!+darwin (:printer word-imm ((op #b0000101100001111)) '(:name :tab code)
+                     :control #'break-control)
+  (:emitter
+   #!-darwin (emit-byte segment #b11001100)
+   ;; On darwin, trap handling via SIGTRAP is unreliable, therefore we
+   ;; throw a sigill with 0x0b0f instead and check for this in the
+   ;; SIGILL handler and pass it on to the sigtrap handler if
+   ;; appropriate
+   #!+darwin (emit-word segment #b0000101100001111)
    (emit-byte segment code)))
 
 (define-instruction int (segment number)
    (emit-byte segment #x0f)
    (emit-byte segment #xae)
    (emit-ea segment dst 3)))
+
+;;;; Miscellany
+
+(define-instruction cpuid (segment)
+  (:printer two-bytes ((op '(#b00001111 #b10100010))))
+  (:emitter
+   (emit-byte segment #b00001111)
+   (emit-byte segment #b10100010)))
+
+(define-instruction rdtsc (segment)
+  (:printer two-bytes ((op '(#b00001111 #b00110001))))
+  (:emitter
+   (emit-byte segment #b00001111)
+   (emit-byte segment #b00110001)))