[yalo commit] r121 - trunk/cc wiki

0 views
Skip to first unread message

codesite...@google.com

unread,
Feb 17, 2009, 8:59:34 AM2/17/09
to yalo-...@googlegroups.com
Author: yujian.zhang
Date: Tue Feb 17 05:53:58 2009
New Revision: 121

Modified:
trunk/cc/lap.lisp
trunk/cc/test-cc.lisp
wiki/AssemblyX64Overview.wiki

Log:
Add support of rex prefix.

Modified: trunk/cc/lap.lisp
==============================================================================
--- trunk/cc/lap.lisp (original)
+++ trunk/cc/lap.lisp Tue Feb 17 05:53:58 2009
@@ -73,7 +73,7 @@
"Processing the list with asm, and pretty print the bytes with pp-hex."
(pp-hex (asm listing)))

-(defun arith-syntax-1 (mnemonic)
+(defun arith-syntax-1 (mnemonic 64bit-only?)
"Return syntax table for arithmetic operations: add/and/cmp/or/sub/xor."
(let ((base ; Base opcode for operation on r/m8 r8.
(ecase mnemonic
@@ -83,23 +83,32 @@
(ecase mnemonic
(add '/0) (and '/4) (cmp '/7)
(or '/1) (sub '/5) (xor '/6))))
- `(((,mnemonic al imm8) . (,(+ base #x04) ib))
- ((,mnemonic ax (imm16 imm8)) . (o16 ,(+ base #x05) iw))
- ((,mnemonic eax (imm32 imm16 imm8)) . (o32 ,(+ base #x05) id))
- ((,mnemonic (r/m8 r8) imm8) . (#x80 ,opcode ib))
- ((,mnemonic byte m imm8) . (#x80 ,opcode ib))
- ((,mnemonic (r/m16 r16 m) imm16) . (o16 #x81 ,opcode iw))
- ((,mnemonic (r/m32 r32 m) imm32) . (o32 #x81 ,opcode id))
- ((,mnemonic (r/m16 r16) imm8) . (o16 #x83 ,opcode ib))
- ((,mnemonic (r/m32 r32) imm8) . (o32 #x83 ,opcode ib))
- ((,mnemonic word m imm8) . (o16 #x83 ,opcode ib))
- ((,mnemonic dword m imm8) . (o32 #x83 ,opcode ib))
- ((,mnemonic (r/m8 r8 m) r8) . (,base /r))
- ((,mnemonic (r/m16 r16 m) r16) . (o16 ,(+ base #x01) /r))
- ((,mnemonic (r/m32 r32 m) r32) . (o32 ,(+ base #x01) /r))
- ((,mnemonic r8 (r/m8 r8 m)) . (,(+ base #x02) /r))
- ((,mnemonic r16 (r/m16 r16 m)) . (o16 ,(+ base #x03) /r))
- ((,mnemonic r32 (r/m32 r32 m)) . (o32 ,(+ base #x03) /r)))))
+ (if 64bit-only?
+ `(;; TODO: For imm8, encode with imm8 seems to save 3 bytes.
+ ((,mnemonic rax (imm32 imm16 imm8)) . (,(+ base #x05) id))
+ ((,mnemonic (r/m64 r64) (imm32 imm16)) . (#x81 ,opcode id))
+ ((,mnemonic qword m (imm32 imm16)) . (#x81 ,opcode id))
+ ((,mnemonic (r/m64 r64) imm8) . (#x83 ,opcode ib))
+ ((,mnemonic qword m imm8) . (#x83 ,opcode ib)))
+ `(((,mnemonic al imm8) . (,(+ base #x04) ib))
+ ((,mnemonic ax (imm16 imm8)) . (o16 ,(+ base #x05) iw))
+ ((,mnemonic eax (imm32 imm16 imm8)) . (o32 ,(+ base #x05) id))
+ ((,mnemonic (r/m8 r8) imm8) . (#x80 ,opcode ib))
+ ((,mnemonic byte m imm8) . (#x80 ,opcode ib))
+ ((,mnemonic (r/m16 r16) imm16) . (o16 #x81 ,opcode iw))
+ ((,mnemonic word m imm16) . (o16 #x81 ,opcode iw))
+ ((,mnemonic (r/m32 r32) (imm32 imm16)) . (o32 #x81 ,opcode id))
+ ((,mnemonic dword m (imm32 imm16)) . (o32 #x81 ,opcode id))
+ ((,mnemonic (r/m16 r16) imm8) . (o16 #x83 ,opcode ib))
+ ((,mnemonic (r/m32 r32) imm8) . (o32 #x83 ,opcode ib))
+ ((,mnemonic word m imm8) . (o16 #x83 ,opcode ib))
+ ((,mnemonic dword m imm8) . (o32 #x83 ,opcode ib))
+ ((,mnemonic (r/m8 r8 m) r8) . (,base /r))
+ ((,mnemonic (r/m16 r16 m) r16) . (o16 ,(+ base #x01) /r))
+ ((,mnemonic (r/m32 r32 m) r32) . (o32 ,(+ base #x01) /r))
+ ((,mnemonic r8 (r/m8 r8 m)) . (,(+ base #x02) /r))
+ ((,mnemonic r16 (r/m16 r16 m)) . (o16 ,(+ base #x03) /r))
+ ((,mnemonic r32 (r/m32 r32 m)) . (o32 ,(+ base #x03)
/r))))))

(defun arith-syntax-2 (mnemonic)
"Return syntax table for arithmetic operations: div/mul/neg/not."
@@ -138,12 +147,12 @@
;;; refer to http://code.google.com/p/yalo/wiki/AssemblyX64Overview")

(defparameter *x86-64-syntax-common*
- `(,@(arith-syntax-1 'add)
- ,@(arith-syntax-1 'and)
+ `(,@(arith-syntax-1 'add nil)
+ ,@(arith-syntax-1 'and nil)
((clc) . (#xf8))
((cld) . (#xfc))
((cli) . (#xfa))
- ,@(arith-syntax-1 'cmp)
+ ,@(arith-syntax-1 'cmp nil)
,@(arith-syntax-2 'div)
((hlt) . (#xf4))
((in al imm8) . (#xe4 ib))
@@ -175,7 +184,7 @@
,@(arith-syntax-2 'neg)
((nop) . (#x90))
,@(arith-syntax-2 'not)
- ,@(arith-syntax-1 'or)
+ ,@(arith-syntax-1 'or nil)
((out imm8 r8) . (#xe6 ib)) ; (out imm8 al)
((out imm8 r16) . (#xe7 ib)) ; (out imm8 ax)
((out dx al) . (#xee))
@@ -190,7 +199,7 @@
((sti) . (#xfb))
((stosb) . (#xaa))
((stosw) . (#xab))
- ,@(arith-syntax-1 'sub)
+ ,@(arith-syntax-1 'sub nil)
((test al imm8) . (#xa8 ib))
((test ax (imm16 imm8)) . (#xa9 iw))
((test (r/m8 r8) imm8) . (#xf6 /0 ib))
@@ -199,7 +208,7 @@
((test word m (imm16 imm8)) . (#xf7 /0 iw))
((test (r/m8 r8 m) r8) . (#x84 /r))
((test (r/m16 r16 m) r16) . (#x85 /r))
- ,@(arith-syntax-1 'xor))
+ ,@(arith-syntax-1 'xor nil))
"Valid for both 16-bit and 64-bit modes.")

(defparameter *x86-64-syntax-16/32-bit-only*
@@ -216,7 +225,7 @@
"Valid for 16-bit mode only.")

(defparameter *x86-64-syntax-64-bit-only*
- `(((add rax (imm32 imm16 imm8)) . (rex.w #x05 id))))
+ `(,@(arith-syntax-1 'add t)))

(defparameter *x86-64-syntax-16/32-bit*
(append *x86-64-syntax-common* *x86-64-syntax-16/32-bit-only*)
@@ -275,7 +284,7 @@
(if (member (car it) '(o16 o32 a16 a32))
(append (size-prefix (car it) bits) (copy-list (cdr it)))
(copy-list it)))
- ((assoc* e (x86-64-syntax bits)
+ ((assoc e (x86-64-syntax bits)
:test #'(lambda (x y)
(and (> (length y) 1)
(equal (subseq x 0 2) (subseq y 0 2))
@@ -283,7 +292,7 @@
(numberp (elt x 2)))))
;; Some registers are explicitly given as destination operand,
;; e.g. (add al imm8).
- (encode-complex e (instruction-type e) it cursor bits))
+ (encode-complex e (canonical-type (car it)) (cdr it) cursor bits))
((assoc* e (x86-64-syntax bits)
:test #'(lambda (x y)
(and (member (car x) '(shl shr))
@@ -323,36 +332,62 @@
(encode-complex e type opcode cursor bits)))

(defun encode-complex (instruction type opcode cursor bits)
- "Return opcode for the given instruction."
- (mapcan
- #'(lambda (on)
- (cond
- ((numberp on) (list on))
- ((listp on)
- (ecase (car on)
- (+ (ecase (caddr on)
- (r (list (+ (cadr on) (reg->int (second
instruction)))))))))
- (t
- (ecase on
- (rex.w (list (encode-rex 1 0 0 0)))
- ((o16 o32 a16 a32) (size-prefix on bits))
- ((ib iw id io)
- (try-encode-bytes (instruction-value instruction type (on->in
on))
- (on-length on)))
- ((rb rw rd ro)
- (try-encode-bytes
- `(- ,(instruction-value instruction type (on->in on))
- ,(+ cursor 1 (on-length on)))
- (on-length on)))
- ((/0 /1 /2 /3 /4 /5 /6 /7)
- (encode-r/m-sib-disp
- (instruction-value instruction type (find-r/m instruction
type))
- on bits))
- (/r (encode-r/m-sib-disp
- (instruction-value instruction type (find-r/m instruction
type))
- (instruction-value instruction type (find-reg instruction
type))
- bits))))))
- opcode))
+ "Encode instruction (with optional rex prefix). Other prefixes like
+lock are directly handled in encode()."
+ (let* (rex-set ; Possibly containing a subset of {w r x b}.
+ (dummy (when (member* '(r/m64 r64 rax qword) type)
+ (push 'w rex-set)))
+ (remaining
+ (mapcan
+ #'(lambda (on)
+ (cond
+ ((numberp on) (list on))
+ ((listp on)
+ (ecase (car on)
+ (+ (ecase (caddr on)
+ (r (list (+ (cadr on)
+ (reg->int (second instruction)))))))))
+ (t
+ (ecase on
+ ((o16 o32 a16 a32) (size-prefix on bits))
+ ((ib iw id io)
+ (try-encode-bytes (instruction-value instruction type
+ (on->in on))
+ (on-length on)))
+ ((rb rw rd ro)
+ (try-encode-bytes
+ `(- ,(instruction-value instruction type (on->in on))
+ ,(+ cursor 1 (on-length on)))
+ (on-length on)))
+ ((/0 /1 /2 /3 /4 /5 /6 /7)
+ (multiple-value-bind (mod-sib-disp rex-set*)
+ (encode-r/m-sib-disp
+ (instruction-value instruction type
+ (find-r/m instruction type))
+ on bits)
+ (setf rex-set (append rex-set rex-set*))
+ mod-sib-disp))
+ (/r
+ (multiple-value-bind (mod-sib-disp rex-set*)
+ (encode-r/m-sib-disp
+ (instruction-value instruction type
+ (find-r/m instruction type))
+ (instruction-value instruction type
+ (find-reg instruction type))
+ bits)
+ (setf rex-set (append rex-set rex-set*))
+ mod-sib-disp))))))
+ opcode)))
+ (declare (ignore dummy))
+ (when (and rex-set (/= bits 64))
+ (error "Instruction ~A only supported in 64-bit mode." instruction))
+ (append (if (null rex-set)
+ nil
+ (list (encode-rex (if (member 'w rex-set) 1 0)
+ (if (member 'r rex-set) 1 0)
+ (if (member 'x rex-set) 1 0)
+ (if (member 'b rex-set) 1 0))))
+ remaining)))

(defun size-prefix (op bits)
"Handles operand/address-size override prefix o16 & o32. Returns nil
@@ -360,9 +395,11 @@
(let* ((s (str op))
(st (symb (subseq s 0 1)))
(sbit (read-from-string (subseq s 1 3))))
- (if (= sbit bits) nil (list (ecase st
- (o #x66)
- (a #x67))))))
+ (if (or (= sbit bits) (and (member bits '(32 64)) (member sbit '(32
64))))
+ nil
+ (list (ecase st
+ (o #x66)
+ (a #x67))))))

(defun find-r/m (instruction type)
"Return the r/m contained in type."
@@ -377,42 +414,57 @@
(error "No (s)reg operand in ~A~%" instruction)))

(defun encode-r/m-sib-disp (r/m reg/opcode bits)
- "Encode ModR/M, SIB byte (if any) and displacement (if any)."
- (let ((r/o (case reg/opcode
- ((/0 /1 /2 /3 /4 /5 /6 /7)
- (- (char-code (elt (symbol-name reg/opcode) 1)) 48))
- (t (case (operand-type reg/opcode)
- (sreg (sreg->int reg/opcode))
- (t (reg->int reg/opcode)))))))
- (multiple-value-bind (mod rm sib disp disp-length)
+ "Return 2 values:
+ - Encode ModR/M, SIB byte (if any) and displacement (if any).
+ - A list of (w r x b) if present."
+ (let* (rex-set
+ (r/o (case reg/opcode
+ ((/0 /1 /2 /3 /4 /5 /6 /7)
+ (- (char-code (elt (symbol-name reg/opcode) 1)) 48))
+ (t (case (operand-type reg/opcode)
+ (sreg (sreg->int reg/opcode))
+ (t (multiple-value-bind (regi rex)
+ (reg->int reg/opcode)
+ (when rex (push (ecase rex
+ (p 'p)
+ (e 'r))
+ rex-set))
+ regi)))))))
+ (multiple-value-bind (mod rm sib disp disp-length rex-set*)
(r/m-values r/m bits)
- (append (list (encode-modr/m mod rm r/o))
- (when sib
- (list sib))
- (when disp
- (try-encode-bytes disp disp-length))))))
+ (values (append (list (encode-modr/m mod rm r/o))
+ (when sib (list sib))
+ (when disp (try-encode-bytes disp disp-length)))
+ (append rex-set rex-set*)))))

(defun r/m-values (r/m bits)
- "Return values: mod, r/m for encoding, sib, disp, and length of disp
-in bytes.
+ "Return values: mod, r/m for encoding, sib, disp, length of disp
+in bytes, and rex-set.

Note
1. If sib is not needed, return nil.
2. If disp is not needed, return nil as disp and disp-length
could be arbitrary."
(ecase (operand-type r/m)
- ((r8 r16 r32 r64) (values #b11 (reg->int r/m) nil nil 0))
+ ((r8 r16 r32 r64)
+ (multiple-value-bind (regi rex)
+ (reg->int r/m)
+ (values #b11 regi nil nil 0 (if rex
+ (list (ecase rex
+ (p 'p)
+ (e 'b)))
+ nil))))
(m (ecase bits ;; FIXME: should be directly related to address mode.
(16 (r/m-values-16 r/m))
(32 (r/m-values-32 r/m))))))

(defun r/m-values-16 (r/m)
(if (equal r/m '(bp)) ; Special handling of (bp)
- (values 1 #b110 nil 0 1)
+ (values 1 #b110 nil 0 1 nil)
(let ((type (mapcar #'operand-type r/m)))
(if (and (= (length r/m) 1) ; Special handling of (disp16)
(member* '(imm8 imm16 label) type))
- (values 0 #b110 nil (car r/m) 2)
+ (values 0 #b110 nil (car r/m) 2 nil)
(let* ((mod (cond
((member 'imm8 type) 1)
((member 'imm16 type) 2)
@@ -432,29 +484,30 @@
((member 'bx r/m) #b111)
(t (error "Incorrect memory addressing: ~A~%"
r/m)))))
- (values mod rm nil disp mod))))))
+ (values mod rm nil disp mod nil))))))

(defun r/m-values-32 (r/m)
(cond
((equal r/m '(ebp)) ; Special handling of (ebp)
- (values 1 #b101 nil 0 1))
+ (values 1 #b101 nil 0 1 nil))
((equal r/m '(esp)) ; Special handling of (esp)
- (values 0 #b100 (encode-sib 0 #b100 4) nil 0))
+ (values 0 #b100 (encode-sib 0 #b100 4) nil 0 nil))
(t
(let ((type (mapcar #'operand-type r/m)))
(cond
((and (= (length r/m) 1) ; Special handling of (disp32)
(member* '(imm8 imm16 imm32 label) type))
- (values 0 #b101 nil (car r/m) 4))
+ (values 0 #b101 nil (car r/m) 4 nil))
((and (= (length r/m) 2) (member 'esp r/m) (member 'imm8 type))
;; Special handling of (esp + disp8)
(values 1 #b100 (encode-sib 0 #b100 4)
- (instruction-value r/m type 'imm8) 1))
+ (instruction-value r/m type 'imm8) 1 nil))
((and (= (length r/m) 2) (member 'esp r/m)
(member* '(imm16 imm32) type))
;; Special handling of (esp + disp32)
(values 2 #b100 (encode-sib 0 #b100 4)
- (instruction-value r/m type (member* '(imm16 imm32)
type)) 4))
+ (instruction-value r/m type (member* '(imm16 imm32)
type)) 4
+ nil))
(t (let* ((mod (cond
((member 'imm8 type) 1)
((member* '(imm16 imm32) type) 2)
@@ -497,7 +550,7 @@
#b100
(reg->int (member* '(eax ecx edx ebx ebp esi
edi)
r/m)))))
- (values mod rm sib disp disp-length))))))))
+ (values mod rm sib disp disp-length nil))))))))

(defun try-encode-bytes (x length)
"If x is evaluable, run encode-bytes.
@@ -648,32 +701,51 @@
(t 'm)))
(t
(case operand
- ((al cl dl bl ah ch dh bh bpl spl dil sil) 'r8)
- ((ax cx dx bx sp bp si di) 'r16)
- ((eax ecx edx ebx esp ebp esi edi) 'r32)
+ ((al cl dl bl ah ch dh bh bpl spl dil sil
+ r8l r9l r10l r11l r12l r13l r14l r15l) 'r8)
+ ((ax cx dx bx sp bp si di
+ r8w r9w r10w r11w r12w r13w r14w r15w) 'r16)
+ ((eax ecx edx ebx esp ebp esi edi
+ r8d r9d r10d r11d r12d r13d r14d r15d) 'r32)
((rax rcx rdx rbx rsp rbp rsi rdi
- r8 r9 r10 r11 r12 r13 r14 r15) 'r64)
- ((cs ds es ss fs gs) 'sreg)
- ((short byte word dword qword) operand)
- (t 'label)
- ))))
+ r8 r9 r10 r11 r12 r13 r14 r15) 'r64)
+ ((cs ds es ss fs gs) 'sreg)
+ ((short byte word dword qword) operand)
+ (t 'label)))))

(defun r32? (op)
"Returns T if operand op is a 32-bit general purpose register."
(eq (operand-type op) 'r32))

(defun reg->int (reg)
- "Returns the integer representation for register when encoding
-ModR/M byte."
+ "Returns values of:
+ - the integer representation for register when encoding
+ ModR/M byte.
+ - whether extension (e.g. rex.b) is needed:
+ * nil: no REX extension
+ * p: REX extension is present but no field (e.g. rex.b or rex.r) is
used.
+ * e: REX extension is used and one field will be set."
(ecase reg
- ((al ax eax mm0 xmm0) 0)
- ((cl cx ecx mm1 xmm1) 1)
- ((dl dx edx mm2 xmm2) 2)
- ((bl bx ebx mm3 xmm3) 3)
- ((ah sp esp mm4 xmm4) 4)
- ((ch bp ebp mm5 xmm5) 5)
- ((dh si esi mm6 xmm6) 6)
- ((bh di edi mm7 xmm7) 7)))
+ ((al ax eax rax mm0 xmm0) (values 0 nil))
+ ((cl cx ecx rcx mm1 xmm1) (values 1 nil))
+ ((dl dx edx rdx mm2 xmm2) (values 2 nil))
+ ((bl bx ebx rbx mm3 xmm3) (values 3 nil))
+ ((ah sp esp rsp mm4 xmm4) (values 4 nil))
+ ((ch bp ebp rbp mm5 xmm5) (values 5 nil))
+ ((dh si esi rsi mm6 xmm6) (values 6 nil))
+ ((bh di edi rdi mm7 xmm7) (values 7 nil))
+ (spl (values 4 'p))
+ (bpl (values 5 'p))
+ (sil (values 6 'p))
+ (dil (values 7 'p))
+ ((r8l r8w r8d r8) (values 0 'e))
+ ((r9l r9w r9d r9) (values 1 'e))
+ ((r10l r10w r10d r10) (values 2 'e))
+ ((r11l r11w r11d r11) (values 3 'e))
+ ((r12l r12w r12d r12) (values 4 'e))
+ ((r13l r13w r13d r13) (values 5 'e))
+ ((r14l r14w r14d r14) (values 6 'e))
+ ((r15l r15w r15d r15) (values 7 'e))))

(defun sreg->int (sreg)
"Returns the integer representation for segment register when

Modified: trunk/cc/test-cc.lisp
==============================================================================
--- trunk/cc/test-cc.lisp (original)
+++ trunk/cc/test-cc.lisp Tue Feb 17 05:53:58 2009
@@ -16,7 +16,7 @@
(,mnemonic bl 3)
(,mnemonic byte (msg) 4)
(,mnemonic bx 1234)
- (,mnemonic (msg) 5678)
+ (,mnemonic word (msg) 5678)
(,mnemonic cx 9)
(,mnemonic word (msg) 12)
(,mnemonic al bl)
@@ -79,39 +79,47 @@
(add ax 1000)

(bits 64)
+ (add ebx 1000)
(add rax #x10010203)
+ (add rax 10)
+ (add rbx 267)
+ (add r15 #x123456)
+ (add r10d 3)
+ (add sil 6)

(db msg "Hello World! ")
endmsg)
"Arithmetic instructions are tested separately.")

(defparameter *arith-code*
- '(4 8 5 232 3 128 195 3 128 6 219 125 4 129 195 210 4 129 6 219 125
- 46 22 131 193 9 131 6 219 125 12 0 216 0 46 219 125 1 217 1 22 219
- 125 2 46 219 125 3 22 219 125 36 8 37 232 3 128 227 3 128 38 219
- 125 4 129 227 210 4 129 38 219 125 46 22 131 225 9 131 38 219 125
- 12 32 216 32 46 219 125 33 217 33 22 219 125 34 46 219 125 35 22
- 219 125 60 8 61 232 3 128 251 3 128 62 219 125 4 129 251 210 4 129
- 62 219 125 46 22 131 249 9 131 62 219 125 12 56 216 56 46 219 125
- 57 217 57 22 219 125 58 46 219 125 59 22 219 125 246 245 246 54
- 219 125 247 247 247 114 3 246 229 246 38 219 125 247 231 247 98 3
- 246 221 246 30 219 125 247 223 247 90 3 246 213 246 22 219 125 247
- 215 247 82 3 12 8 13 232 3 128 203 3 128 14 219 125 4 129 203 210
- 4 129 14 219 125 46 22 131 201 9 131 14 219 125 12 8 216 8 46 219
- 125 9 217 9 22 219 125 10 46 219 125 11 22 219 125 208 230 208 38
- 219 125 210 230 210 38 219 125 192 230 5 192 38 219 125 5 209 226
- 209 38 219 125 211 226 211 38 219 125 193 226 5 193 38 219 125 5
- 208 238 208 46 219 125 210 238 210 46 219 125 192 238 5 192 46 219
- 125 5 209 234 209 46 219 125 211 234 211 46 219 125 193 234 5 193
- 46 219 125 5 44 8 45 232 3 128 235 3 128 46 219 125 4 129 235 210
- 4 129 46 219 125 46 22 131 233 9 131 46 219 125 12 40 216 40 46
- 219 125 41 217 41 22 219 125 42 46 219 125 43 22 219 125 168 8 169
- 232 3 246 195 3 246 6 219 125 4 247 195 210 4 247 6 219 125 46 22
- 132 216 132 46 219 125 133 217 133 22 219 125 52 8 53 232 3 128
- 243 3 128 54 219 125 4 129 243 210 4 129 54 219 125 46 22 131 241
- 9 131 54 219 125 12 48 216 48 46 219 125 49 217 49 22 219 125 50
- 46 219 125 51 22 219 125 102 5 232 3 72 5 3 2 1 16 72 101 108 108
- 111 32 87 111 114 108 100 33 32))
+ '(4 8 5 232 3 128 195 3 128 6 253 125 4 129 195 210 4 129 6 253 125
+ 46 22 131 193 9 131 6 253 125 12 0 216 0 46 253 125 1 217 1 22 253
+ 125 2 46 253 125 3 22 253 125 36 8 37 232 3 128 227 3 128 38 253
+ 125 4 129 227 210 4 129 38 253 125 46 22 131 225 9 131 38 253 125
+ 12 32 216 32 46 253 125 33 217 33 22 253 125 34 46 253 125 35 22
+ 253 125 60 8 61 232 3 128 251 3 128 62 253 125 4 129 251 210 4 129
+ 62 253 125 46 22 131 249 9 131 62 253 125 12 56 216 56 46 253 125
+ 57 217 57 22 253 125 58 46 253 125 59 22 253 125 246 245 246 54
+ 253 125 247 247 247 114 3 246 229 246 38 253 125 247 231 247 98 3
+ 246 221 246 30 253 125 247 223 247 90 3 246 213 246 22 253 125 247
+ 215 247 82 3 12 8 13 232 3 128 203 3 128 14 253 125 4 129 203 210
+ 4 129 14 253 125 46 22 131 201 9 131 14 253 125 12 8 216 8 46 253
+ 125 9 217 9 22 253 125 10 46 253 125 11 22 253 125 208 230 208 38
+ 253 125 210 230 210 38 253 125 192 230 5 192 38 253 125 5 209 226
+ 209 38 253 125 211 226 211 38 253 125 193 226 5 193 38 253 125 5
+ 208 238 208 46 253 125 210 238 210 46 253 125 192 238 5 192 46 253
+ 125 5 209 234 209 46 253 125 211 234 211 46 253 125 193 234 5 193
+ 46 253 125 5 44 8 45 232 3 128 235 3 128 46 253 125 4 129 235 210
+ 4 129 46 253 125 46 22 131 233 9 131 46 253 125 12 40 216 40 46
+ 253 125 41 217 41 22 253 125 42 46 253 125 43 22 253 125 168 8 169
+ 232 3 246 195 3 246 6 253 125 4 247 195 210 4 247 6 253 125 46 22
+ 132 216 132 46 253 125 133 217 133 22 253 125 52 8 53 232 3 128
+ 243 3 128 54 253 125 4 129 243 210 4 129 54 253 125 46 22 131 241
+ 9 131 54 253 125 12 48 216 48 46 253 125 49 217 49 22 253 125 50
+ 46 253 125 51 22 253 125 102 5 232 3 129 195 232 3 0 0 72 5 3 2 1
+ 16 72 5 10 0 0 0 72 129 195 11 1 0 0 73 129 199 86 52 18 0 65 131
+ 194 3 64 128 198 6 72 101 108 108 111 32 87 111 114 108 100 33
+ 32))

(defparameter *misc-asm*
'((bits 16)
@@ -261,27 +269,28 @@
123 137 76 123 8 137 84 141 123 137 76 178 8 137 156 213 64 226 1
0 137 84 249 8 72 101 108 108 111 32 87 111 114 108 100 33 32))

+(defparameter *bootloader-code*
+ '(180 3 205 16 184 1 19 187 15 0 185 15 0 189 20 124 205 16 235 254
+ 72 101 108 108 111 32 87 111 114 108 100 33 32 13 10 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 85 170))
+
(deftest test-cc ()
(check
- (equal
- (asm *bootloader*)
- '(180 3 205 16 184 1 19 187 15 0 185 15 0 189 20 124 205 16 235
- 254 72 101 108 108 111 32 87 111 114 108 100 33 32 13 10 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 85 170))
+ (equal (asm *bootloader*) *bootloader-code*)
(equal (asm *address-asm*) *address-code*)
(equal (asm *arith-asm*) *arith-code*)
(equal (asm *misc-asm*) *misc-code*)))

Modified: wiki/AssemblyX64Overview.wiki
==============================================================================
--- wiki/AssemblyX64Overview.wiki (original)
+++ wiki/AssemblyX64Overview.wiki Tue Feb 17 05:53:58 2009
@@ -93,7 +93,9 @@
* *a16, a32*: address-size override prefix. a16 generates no code in
16-bit mode, but indicates a 67h prefix in 32/64-bit mode; similarly, a32
generates
no code in 32/64-bit mode, but indicates a 67h prefix in 16-bit mode.
-* *rex.w*: prefix to promote operand size to 64-bits. The value of rex.w
is 48h.
+
+Note that REX prefix are not used in opcode notations. The prefix is
+automatically generated by analyzing the operands.

Reply all
Reply to author
Forward
0 new messages