[yalo commit] r134 - trunk/cc wiki

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 3, 2009, 9:08:30 AM3/3/09
to yalo-...@googlegroups.com
Author: yujian.zhang
Date: Tue Mar 3 05:24:30 2009
New Revision: 134

Modified:
trunk/cc/lap.lisp
trunk/cc/test-cc.lisp
trunk/cc/x86-64-syntax.lisp
wiki/AssemblyX64C.wiki
wiki/AssemblyX64J.wiki
wiki/AssemblyX64Overview.wiki

Log:
Add instruction cmpxchg8b/16b.

Modified: trunk/cc/lap.lisp
==============================================================================
--- trunk/cc/lap.lisp (original)
+++ trunk/cc/lap.lisp Tue Mar 3 05:24:30 2009
@@ -177,7 +177,8 @@
"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)
+ (dummy (when (or (member* '(r/m64 r64 rax qword) type)
+ (eq (car instruction) 'cmpxchg16b))
(push 'w rex-set)))
(encoded-len 0) ; Tracking for (R)IP relative encoding.
(remaining
@@ -306,7 +307,8 @@
nil))))
(m (ecase bits ;; FIXME: should be directly related to address mode.
(16 (r/m-values-16 r/m))
- ((32 64) (r/m-values-32 r/m))))))
+ (32 (r/m-values-32 r/m))
+ (64 (r/m-values-64 r/m))))))

(defun r/m-values-16 (r/m)
(if (equal r/m '(bp)) ; Special handling of (bp)
@@ -399,6 +401,73 @@
(rm (if sib
#b100
(reg->int (member* '(eax ecx edx ebx ebp esi
edi)
+ r/m)))))
+ (values mod rm sib disp disp-length nil))))))))
+
+(defun r/m-values-64 (r/m)
+ ;; TODO: overhaul (currently only something like a placeholder).
+ (cond
+ ((equal r/m '(rbp)) ; Special handling of (rbp)
+ (values 1 #b101 nil 0 1 nil))
+ ((equal r/m '(rsp)) ; Special handling of (rsp)
+ (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 nil))
+ ((and (= (length r/m) 2) (member 'rsp r/m) (member 'imm8 type))
+ ;; Special handling of (rsp + disp8)
+ (values 1 #b100 (encode-sib 0 #b100 4)
+ (instruction-value r/m type 'imm8) 1 nil))
+ ((and (= (length r/m) 2) (member 'rsp r/m)
+ (member* '(imm16 imm32) type))
+ ;; Special handling of (rsp + disp32)
+ (values 2 #b100 (encode-sib 0 #b100 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)
+ (t 0)))
+ (disp (ecase mod
+ (1 (instruction-value r/m type 'imm8))
+ (2 (instruction-value r/m type
+ (member* '(imm16 imm32)
type)))
+ (0 nil)))
+ (disp-length
+ (if (= mod 2)
+ 4
+ mod))
+ (sib (cond
+ ((some #'scaled-index? r/m)
+ (let* ((si (find-if #'scaled-index? r/m))
+ (sis (str si))
+ (scale (floor (log (read-from-string
+ (subseq sis 4 5))
+ 2)))
+ (index (reg->int (symb (subseq sis 0
3))))
+ (base-reg (find-if #'r32? r/m))
+ (base (if base-reg (reg->int base-reg)
5)))
+ (unless base-reg
+ ;; Special case of (scaled-index + disp32)
+ (setf mod 0
+ disp (instruction-value
+ r/m type
+ (member* '(imm8 imm16 imm32)
type))
+ disp-length 4))
+ (encode-sib scale index base)))
+ ((= (count-if #'r32? r/m) 2)
+ (let* ((scale 0)
+ (base (reg->int (find-if #'r32? r/m)))
+ (index (reg->int (find-if #'r32? r/m
+ :from-end t))))
+ (encode-sib scale index base)))
+ (t nil)))
+ (rm (if sib
+ #b100
+ (reg->int (member* '(rax rcx rdx rbx rbp rsi
rdi)
r/m)))))
(values mod rm sib disp disp-length nil))))))))


Modified: trunk/cc/test-cc.lisp
==============================================================================
--- trunk/cc/test-cc.lisp (original)
+++ trunk/cc/test-cc.lisp Tue Mar 3 05:24:30 2009
@@ -105,7 +105,7 @@
(add sil 6)
(add r9l 8)
(add r10 rbx)
- (add rsi (ebx))
+ (add rsi (rbx))
(dec di)
(dec ecx)
(dec r10)
@@ -218,6 +218,8 @@
(cmova ax bx)
(cmovc eax edx)
(cmove rdx r10)
+ (cmpxchg8b (rbx))
+ (cmpxchg16b (rbx))
(jb near msg)
(syscall)
(sysret)
@@ -233,15 +235,15 @@
"Miscellaneous instructions.")

(defparameter *misc-code*
- '(232 124 0 248 252 250 244 228 3 229 4 236 237 204 205 16 116 254
- 235 252 15 1 22 127 124 15 1 30 127 124 15 0 210 15 0 22 127 124
- 172 173 226 230 180 9 187 13 0 137 200 137 30 127 124 139 14 123
- 28 199 6 127 124 123 0 142 195 140 200 144 230 3 231 4 238 239 81
+ '(232 131 0 248 252 250 244 228 3 229 4 236 237 204 205 16 116 254
+ 235 252 15 1 22 134 124 15 1 30 134 124 15 0 210 15 0 22 134 124
+ 172 173 226 230 180 9 187 13 0 137 200 137 30 134 124 139 14 123
+ 28 199 6 134 124 123 0 142 195 140 200 144 230 3 231 4 238 239 81
14 22 30 6 90 23 31 7 243 164 243 165 243 102 165 195 249 253 251
170 171 15 203 72 15 200 73 15 202 102 15 71 195 15 66 194 73 15
- 68 210 15 130 6 0 0 0 15 5 15 7 127 124 72 101 108 108 111 32 87
- 111 114 108 100 33 32 0 0 0 85 170 64 226 1 0 67 104 120 0 0 0 230
- 130 217 250 11 0))
+ 68 210 15 199 11 72 15 199 11 15 130 6 0 0 0 15 5 15 7 134 124 72
+ 101 108 108 111 32 87 111 114 108 100 33 32 0 0 0 85 170 64 226 1
+ 0 67 104 120 0 0 0 230 130 217 250 11 0))

(defparameter *address-asm*
'((org #x7c00)

Modified: trunk/cc/x86-64-syntax.lisp
==============================================================================
--- trunk/cc/x86-64-syntax.lisp (original)
+++ trunk/cc/x86-64-syntax.lisp Tue Mar 3 05:24:30 2009
@@ -97,6 +97,7 @@
((cmovcc r16 (r/m16 r16 m)) . (o16 #x0f (+ #x40 cc) /r))
((cmovcc r32 (r/m32 r32 m)) . (o32 #x0f (+ #x40 cc) /r))
,@(arith-syntax-1 'cmp nil)
+ ((cmpxchg8b m) . (#x0f #xc7 /1))
((dec (r/m8 r8)) . (#xfe /1))
((dec byte m) . (#xfe /1))
((dec (r/m16 r16)) . (o16 #xff /1))
@@ -193,6 +194,7 @@
,@(arith-syntax-1 'and t)
((bswap r64) . (#x0f (+ #xc8 r)))
((cmovcc r64 (r/m64 r64 m)) . (#x0f (+ #x40 cc) /r))
+ ((cmpxchg16b m) . (#x0f #xc7 /1))
,@(arith-syntax-1 'cmp t)
((dec (r/m64 r64)) . (#xff /1))
((dec qword m) . (#xff /1))

Modified: wiki/AssemblyX64C.wiki
==============================================================================
--- wiki/AssemblyX64C.wiki (original)
+++ wiki/AssemblyX64C.wiki Tue Mar 3 05:24:30 2009
@@ -36,9 +36,11 @@

Please refer [AssemblyX64Overview#Conditional_Codes conditional codes] for
details.

+--------
+
= cmp: Compare =

-|| Instruction || Opcode || 64-Bit Mode || 16/32-Bit Mode ||
Description ||
+|| Instruction || Opcode || 64-Bit Mode || 16/32-Bit Mode ||
Description ||
|| cmp al imm8 || 3C ib || Valid || Valid || Compare
imm8 with al ||
|| cmp ax imm16 || 3D iw || Valid || Valid || Compare
imm16 with ax ||
|| cmp r/m8 imm8 || 80 /7 ib || Valid || Valid || Compare
imm8 with r/m8 ||
@@ -49,3 +51,10 @@
|| cmp r8 r/m8 || 3A /r || Valid || Valid || Compare
r/m8 with r8 ||
|| cmp r16 r/m16 || 3B /r || Valid || Valid || Compare
r/m16 with r16 ||

+--------
+
+= cmpxchg8b/cmpxchg16b: Compare and Exchange Bytes =
+
+|| Instruction || Opcode || 64-Bit Mode || 16/32-Bit Mode ||
Description ||
+|| cmpxchg8b m64 || 0F C7 /1 || Valid || Valid |
| ||
+|| cmpxchg16b m128 || 0F C7 /1 || Valid || ~~N.E.~~ |
| ||

Modified: wiki/AssemblyX64J.wiki
==============================================================================
--- wiki/AssemblyX64J.wiki (original)
+++ wiki/AssemblyX64J.wiki Tue Mar 3 05:24:30 2009
@@ -7,13 +7,13 @@
= jcc: Conditional Branch =

|| Instruction || Opcode || 64-Bit Mode || 16/32-Bit Mode ||
Description ||
-|| jcc imm8 || (+ 70 cc) rb || Valid || Valid ||
Short conditional jump ||
-|| jcc near imm32 || 0F (+ 80 cc) rd || Valid || Valid ||
Near conditional jump ||
+|| jcc imm || (+ 70 cc) rb || Valid || Valid ||
Short conditional jump ||
+|| jcc near imm || 0F (+ 80 cc) rd || Valid || Valid ||
Near conditional jump ||

Please refer [AssemblyX64Overview#Conditional_Codes conditional codes] for
details.

= jmp: Jump =

|| Instruction || Opcode || 64-Bit Mode || 16/32-Bit Mode ||
Description ||
-|| jmp short imm8 || EB rb || Valid || Valid || Jump
short ||
+|| jmp short imm || EB rb || Valid || Valid || Jump
short ||


Modified: wiki/AssemblyX64Overview.wiki
==============================================================================
--- wiki/AssemblyX64Overview.wiki (original)
+++ wiki/AssemblyX64Overview.wiki Tue Mar 3 05:24:30 2009
@@ -39,7 +39,7 @@
* *!r16*: one of the word general-purpose registers: ax, cx, dx, bx, sp,
bp, si, di.
* *!r32*: one of the doubleword general-purpose registers: eax, ecx, edx,
ebx, esp, ebp, esi, edi.
* *!r64*: one of the quadword general-purpose registers: rax, rcx, rdx,
rbx, rsp, rbp, rsi, rdi, !r8-!r15.
- * *m8, m16, m32, m64*: memory references. Specifier (`byte`, `word`,
`dword`, `qword`) is needed for ambiguous cases. For example in `(mov word
[12345] 16).
+ * *m8, m16, m32, m64, m128*: memory references. Specifier (`byte`,
`word`, `dword`, `qword`) is needed for ambiguous cases. For example in
`(mov word [12345] 16).
* *m16&32*, *m16&16*, *m32&32*, *m16&64*, a memory operand containing one
pair whose sizes are indicated on the left and right size of the ampersand.
* *r/m8, r/m16, r/m32, r/m64*: register or memeory choices. For example,
r/m8 means that either r8 or m8 can be used as operand.
* *sreg*: segment register.

Reply all
Reply to author
Forward
0 new messages