* fixed an assembler bug in "addl reg -> mem"
This commit is contained in:
parent
297e47db32
commit
8294a8dee9
|
@ -1,6 +1,6 @@
|
|||
|
||||
#CFLAGS = -I/opt/local/include -Wall -DNDEBUG -O3 #-fomit-frame-pointer
|
||||
CFLAGS = -I/opt/local/include -Wall -g
|
||||
CFLAGS = -I/opt/local/include -Wall -DNDEBUG -O3 #-fomit-frame-pointer
|
||||
#CFLAGS = -I/opt/local/include -Wall -g
|
||||
LDFLAGS = -L/opt/local/lib -g -ldl -lgmp #-rdynamic
|
||||
CC = gcc
|
||||
all: ikarus
|
||||
|
|
BIN
bin/ikarus
BIN
bin/ikarus
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
|
||||
#!/usr/bin/env ikarus --script
|
||||
(define (asm-test res ls)
|
||||
(printf "Testing:\n")
|
||||
(for-each (lambda (x)
|
||||
|
@ -50,6 +50,20 @@
|
|||
[movl (disp -4 %esp) %eax]
|
||||
[ret]))
|
||||
|
||||
(asm-test 2
|
||||
'([movl 4 %ebx]
|
||||
[movl 4 (disp -8 %esp)]
|
||||
[addl %ebx (disp -8 %esp)]
|
||||
[movl (disp -8 %esp) %eax]
|
||||
[ret]))
|
||||
|
||||
(asm-test 2
|
||||
'([movl 4 %eax]
|
||||
[movl 4 (disp -8 %esp)]
|
||||
[addl %eax (disp -8 %esp)]
|
||||
[movl 0 %eax]
|
||||
[movl (disp -8 %esp) %eax]
|
||||
[ret]))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -48,7 +48,10 @@ sub gen3{
|
|||
}
|
||||
}
|
||||
|
||||
gen1 "addl \$0x12345678, 7(r1)\n";
|
||||
#gen1 "addl \$0x12345678, 7(r1)\n";
|
||||
|
||||
#gen2 "addl 0x23(r1), r2\n";
|
||||
gen2 "addl r1, 0x23(r2)\n";
|
||||
|
||||
#gen1 "movb \$0, 4(r1)\n";
|
||||
#gen1 "movb -2(r1), %ah\n";
|
||||
|
|
|
@ -1,9 +1,65 @@
|
|||
.text
|
||||
addl $0x12345678, 7(%eax)
|
||||
addl $0x12345678, 7(%ecx)
|
||||
addl $0x12345678, 7(%edx)
|
||||
addl $0x12345678, 7(%ebx)
|
||||
addl $0x12345678, 7(%esp)
|
||||
addl $0x12345678, 7(%ebp)
|
||||
addl $0x12345678, 7(%esi)
|
||||
addl $0x12345678, 7(%edi)
|
||||
addl %eax, 0x23(%eax)
|
||||
addl %eax, 0x23(%ecx)
|
||||
addl %eax, 0x23(%edx)
|
||||
addl %eax, 0x23(%ebx)
|
||||
addl %eax, 0x23(%esp)
|
||||
addl %eax, 0x23(%ebp)
|
||||
addl %eax, 0x23(%esi)
|
||||
addl %eax, 0x23(%edi)
|
||||
addl %ecx, 0x23(%eax)
|
||||
addl %ecx, 0x23(%ecx)
|
||||
addl %ecx, 0x23(%edx)
|
||||
addl %ecx, 0x23(%ebx)
|
||||
addl %ecx, 0x23(%esp)
|
||||
addl %ecx, 0x23(%ebp)
|
||||
addl %ecx, 0x23(%esi)
|
||||
addl %ecx, 0x23(%edi)
|
||||
addl %edx, 0x23(%eax)
|
||||
addl %edx, 0x23(%ecx)
|
||||
addl %edx, 0x23(%edx)
|
||||
addl %edx, 0x23(%ebx)
|
||||
addl %edx, 0x23(%esp)
|
||||
addl %edx, 0x23(%ebp)
|
||||
addl %edx, 0x23(%esi)
|
||||
addl %edx, 0x23(%edi)
|
||||
addl %ebx, 0x23(%eax)
|
||||
addl %ebx, 0x23(%ecx)
|
||||
addl %ebx, 0x23(%edx)
|
||||
addl %ebx, 0x23(%ebx)
|
||||
addl %ebx, 0x23(%esp)
|
||||
addl %ebx, 0x23(%ebp)
|
||||
addl %ebx, 0x23(%esi)
|
||||
addl %ebx, 0x23(%edi)
|
||||
addl %esp, 0x23(%eax)
|
||||
addl %esp, 0x23(%ecx)
|
||||
addl %esp, 0x23(%edx)
|
||||
addl %esp, 0x23(%ebx)
|
||||
addl %esp, 0x23(%esp)
|
||||
addl %esp, 0x23(%ebp)
|
||||
addl %esp, 0x23(%esi)
|
||||
addl %esp, 0x23(%edi)
|
||||
addl %ebp, 0x23(%eax)
|
||||
addl %ebp, 0x23(%ecx)
|
||||
addl %ebp, 0x23(%edx)
|
||||
addl %ebp, 0x23(%ebx)
|
||||
addl %ebp, 0x23(%esp)
|
||||
addl %ebp, 0x23(%ebp)
|
||||
addl %ebp, 0x23(%esi)
|
||||
addl %ebp, 0x23(%edi)
|
||||
addl %esi, 0x23(%eax)
|
||||
addl %esi, 0x23(%ecx)
|
||||
addl %esi, 0x23(%edx)
|
||||
addl %esi, 0x23(%ebx)
|
||||
addl %esi, 0x23(%esp)
|
||||
addl %esi, 0x23(%ebp)
|
||||
addl %esi, 0x23(%esi)
|
||||
addl %esi, 0x23(%edi)
|
||||
addl %edi, 0x23(%eax)
|
||||
addl %edi, 0x23(%ecx)
|
||||
addl %edi, 0x23(%edx)
|
||||
addl %edi, 0x23(%ebx)
|
||||
addl %edi, 0x23(%esp)
|
||||
addl %edi, 0x23(%ebp)
|
||||
addl %edi, 0x23(%esi)
|
||||
addl %edi, 0x23(%edi)
|
||||
|
|
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -147,6 +147,7 @@
|
|||
[$fxsll v]
|
||||
[$fxsra v]
|
||||
[$fxlogand v]
|
||||
[$fxlognot v]
|
||||
[$fxmodulo v]
|
||||
[$fxzero? p]
|
||||
[$fx> p]
|
||||
|
@ -159,7 +160,9 @@
|
|||
[$char<= p]
|
||||
[$char= p]
|
||||
[$char->fixnum v]
|
||||
[$fixnum->char v]
|
||||
|
||||
[$make-vector v]
|
||||
[$vector-ref v]
|
||||
[$vector-set! e]
|
||||
|
||||
|
@ -191,6 +194,9 @@
|
|||
[$seal-frame-and-call tail]
|
||||
[$frame->continuation v]
|
||||
|
||||
[$make-call-with-values-procedure v]
|
||||
[$make-values-procedure v]
|
||||
|
||||
))
|
||||
(define library-prims
|
||||
'(vector
|
||||
|
@ -319,38 +325,45 @@
|
|||
(make-primcall '$cpref (list cpvar (make-constant i)))]
|
||||
[else (f (cdr free*) (fxadd1 i))])))
|
||||
;;;
|
||||
(define (make-closure x)
|
||||
(record-case x
|
||||
[(closure code free*)
|
||||
(cond
|
||||
[(null? free*) x]
|
||||
[else
|
||||
(make-primcall '$make-cp
|
||||
(list code (make-constant (length free*))))])]))
|
||||
;;;
|
||||
(define (closure-sets var x ac)
|
||||
(record-case x
|
||||
[(closure code free*)
|
||||
(let f ([i 0] [free* free*])
|
||||
(cond
|
||||
[(null? free*) ac]
|
||||
[else
|
||||
(make-seq
|
||||
(make-primcall '$cpset!
|
||||
(list var (make-constant i)
|
||||
(Var (car free*))))
|
||||
(f (fxadd1 i) (cdr free*)))]))]))
|
||||
;;;
|
||||
;;; (define (make-closure x)
|
||||
;;; (record-case x
|
||||
;;; [(closure code free*)
|
||||
;;; (cond
|
||||
;;; [(null? free*) x]
|
||||
;;; [else
|
||||
;;; (make-primcall '$make-cp
|
||||
;;; (list code (make-constant (length free*))))])]))
|
||||
;;; ;;;
|
||||
;;; (define (closure-sets var x ac)
|
||||
;;; (record-case x
|
||||
;;; [(closure code free*)
|
||||
;;; (let f ([i 0] [free* free*])
|
||||
;;; (cond
|
||||
;;; [(null? free*) ac]
|
||||
;;; [else
|
||||
;;; (make-seq
|
||||
;;; (make-primcall '$cpset!
|
||||
;;; (list var (make-constant i)
|
||||
;;; (Var (car free*))))
|
||||
;;; (f (fxadd1 i) (cdr free*)))]))]))
|
||||
|
||||
;;; (define (do-fix lhs* rhs* body)
|
||||
;;; (make-bind
|
||||
;;; lhs* (map make-closure rhs*)
|
||||
;;; (let f ([lhs* lhs*] [rhs* rhs*])
|
||||
;;; (cond
|
||||
;;; [(null? lhs*) body]
|
||||
;;; [else
|
||||
;;; (closure-sets (car lhs*) (car rhs*)
|
||||
;;; (f (cdr lhs*) (cdr rhs*)))]))))
|
||||
|
||||
(define (do-fix lhs* rhs* body)
|
||||
(make-bind
|
||||
lhs* (map make-closure rhs*)
|
||||
(let f ([lhs* lhs*] [rhs* rhs*])
|
||||
(cond
|
||||
[(null? lhs*) body]
|
||||
[else
|
||||
(closure-sets (car lhs*) (car rhs*)
|
||||
(f (cdr lhs*) (cdr rhs*)))]))))
|
||||
;;;
|
||||
(define (handle-closure x)
|
||||
(record-case x
|
||||
[(closure code free*)
|
||||
(make-closure code (map Var free*))]))
|
||||
(make-fix lhs* (map handle-closure rhs*) body))
|
||||
|
||||
(define (Expr x)
|
||||
(record-case x
|
||||
[(constant) x]
|
||||
|
@ -455,6 +468,8 @@
|
|||
[(funcall) (Predicafy x)]
|
||||
[(jmpcall) (Predicafy x)]
|
||||
[(forcall) (Predicafy x)]
|
||||
[(fix lhs* rhs* body)
|
||||
(make-fix lhs* rhs* (P body))]
|
||||
[(primcall op rands)
|
||||
(case (prim-context op)
|
||||
[(v) (Predicafy x)]
|
||||
|
@ -479,6 +494,8 @@
|
|||
(mkseq (E e0) (E e1))]
|
||||
[(bind lhs* rhs* body)
|
||||
(mkbind lhs* (map V rhs*) (E body))]
|
||||
[(fix lhs* rhs* body)
|
||||
(make-fix lhs* rhs* (E body))]
|
||||
[(conditional e0 e1 e2)
|
||||
(let ([e1 (E e1)] [e2 (E e2)])
|
||||
(cond
|
||||
|
@ -516,6 +533,8 @@
|
|||
(mkif (P e0) (V e1) (V e2))]
|
||||
[(bind lhs* rhs* body)
|
||||
(mkbind lhs* (map V rhs*) (V body))]
|
||||
[(fix lhs* rhs* body)
|
||||
(make-fix lhs* rhs* (V body))]
|
||||
[(funcall rator rand*)
|
||||
(make-funcall (V rator) (map V rand*))]
|
||||
[(jmpcall label rator rand*)
|
||||
|
@ -577,6 +596,83 @@
|
|||
;;;
|
||||
(define nop (make-primcall 'nop '()))
|
||||
;;;
|
||||
(define (handle-fix lhs* rhs* body)
|
||||
(define (closure-size x)
|
||||
(record-case x
|
||||
[(closure code free*)
|
||||
(if (null? free*)
|
||||
0
|
||||
(align (+ disp-closure-data
|
||||
(* (length free*) wordsize))))]))
|
||||
(define (partition p? lhs* rhs*)
|
||||
(cond
|
||||
[(null? lhs*) (values '() '() '() '())]
|
||||
[else
|
||||
(let-values ([(a* b* c* d*)
|
||||
(partition p? (cdr lhs*) (cdr rhs*))]
|
||||
[(x y) (values (car lhs*) (car rhs*))])
|
||||
(cond
|
||||
[(p? x y)
|
||||
(values (cons x a*) (cons y b*) c* d*)]
|
||||
[else
|
||||
(values a* b* (cons x c*) (cons y d*))]))]))
|
||||
(define (combinator? lhs rhs)
|
||||
(record-case rhs
|
||||
[(closure code free*) (null? free*)]))
|
||||
(define (sum n* n)
|
||||
(cond
|
||||
[(null? n*) n]
|
||||
[else (sum (cdr n*) (+ n (car n*)))]))
|
||||
(define (adders lhs n n*)
|
||||
(cond
|
||||
[(null? n*) '()]
|
||||
[else
|
||||
(cons (prm 'int+ (list lhs (K n)))
|
||||
(adders lhs (+ n (car n*)) (cdr n*)))]))
|
||||
(define (build-closures lhs* rhs* body)
|
||||
(let ([lhs (car lhs*)] [rhs (car rhs*)]
|
||||
[lhs* (cdr lhs*)] [rhs* (cdr rhs*)])
|
||||
(let ([n (closure-size rhs)]
|
||||
[n* (map closure-size rhs*)])
|
||||
(make-bind (list lhs)
|
||||
(list (prm 'alloc
|
||||
(K (sum n* n))
|
||||
(K closure-tag)))
|
||||
(make-bind lhs* (adders lhs n n*)
|
||||
body)))))
|
||||
(define (build-setters lhs* rhs* body)
|
||||
(define (build-setter lhs rhs body)
|
||||
(record-case rhs
|
||||
[(closure code free*)
|
||||
(make-seq
|
||||
(prm 'mset! lhs
|
||||
(K (- disp-closure-code closure-tag))
|
||||
(Value code))
|
||||
(let f ([ls free*]
|
||||
[i (- disp-closure-data closure-tag)])
|
||||
(cond
|
||||
[(null? ls) body]
|
||||
[else
|
||||
(make-seq
|
||||
(prm 'mset! lhs (K i) (Value (car ls)))
|
||||
(f (cdr ls) (+ i wordsize)))])))]))
|
||||
(cond
|
||||
[(null? lhs*) body]
|
||||
[else
|
||||
(build-setter (car lhs*) (car rhs*)
|
||||
(build-setters (cdr lhs*) (cdr rhs*) body))]))
|
||||
(let-values ([(flhs* frhs* clhs* crhs*)
|
||||
(partition combinator? lhs* rhs*)])
|
||||
(cond
|
||||
[(null? clhs*) (make-bind flhs* (map Value frhs*) body)]
|
||||
[(null? flhs*)
|
||||
(build-closures clhs* crhs*
|
||||
(build-setters clhs* crhs* body))]
|
||||
[else
|
||||
(make-bind flhs* (map Value frhs*)
|
||||
(build-closures clhs* crhs*
|
||||
(build-setters clhs* crhs* body)))])))
|
||||
;;;
|
||||
(define (constant-rep x)
|
||||
(let ([c (constant-value x)])
|
||||
(cond
|
||||
|
@ -619,6 +715,8 @@
|
|||
(make-conditional (Pred e0) (Effect e1) (Effect e2))]
|
||||
[(seq e0 e1)
|
||||
(make-seq (Effect e0) (Effect e1))]
|
||||
[(fix lhs* rhs* body)
|
||||
(handle-fix lhs* rhs* (Effect body))]
|
||||
[(primcall op arg*)
|
||||
(case op
|
||||
[(nop) nop]
|
||||
|
@ -694,6 +792,8 @@
|
|||
(make-conditional (Pred e0) (Pred e1) (Pred e2))]
|
||||
[(seq e0 e1)
|
||||
(make-seq (Effect e0) (Pred e1))]
|
||||
[(fix lhs* rhs* body)
|
||||
(handle-fix lhs* rhs* (Pred body))]
|
||||
[(primcall op arg*)
|
||||
(case op
|
||||
[(eq?) (make-primcall '= (map Value arg*))]
|
||||
|
@ -767,6 +867,14 @@
|
|||
;;;
|
||||
(define (err x)
|
||||
(error who "invalid form ~s" (unparse x)))
|
||||
;;;
|
||||
(define (align-code unknown-amt known-amt)
|
||||
(prm 'sll
|
||||
(prm 'sra
|
||||
(prm 'int+ unknown-amt
|
||||
(K (+ known-amt (sub1 object-alignment))))
|
||||
(K align-shift))
|
||||
(K align-shift)))
|
||||
;;; value
|
||||
(define (Value x)
|
||||
(record-case x
|
||||
|
@ -780,6 +888,8 @@
|
|||
[(closure) (make-constant x)]
|
||||
[(bind lhs* rhs* body)
|
||||
(make-bind lhs* (map Value rhs*) (Value body))]
|
||||
[(fix lhs* rhs* body)
|
||||
(handle-fix lhs* rhs* (Value body))]
|
||||
[(conditional e0 e1 e2)
|
||||
(make-conditional (Pred e0) (Value e1) (Value e2))]
|
||||
[(seq e0 e1)
|
||||
|
@ -832,6 +942,31 @@
|
|||
(make-seq
|
||||
(prm 'mset! t (K i) (car t*))
|
||||
(f (cdr t*) (+ i wordsize)))]))))))))]
|
||||
[($make-vector)
|
||||
(unless (= (length arg*) 1)
|
||||
(error who "incorrect args to $make-vector"))
|
||||
(let ([len (car arg*)])
|
||||
(record-case len
|
||||
[(constant i)
|
||||
(unless (fixnum? i) (error who "invalid ~s" x))
|
||||
(tbind ([v (prm 'alloc
|
||||
(K (align (+ (* i wordsize)
|
||||
disp-vector-data)))
|
||||
(K vector-tag))])
|
||||
(seq*
|
||||
(prm 'mset! v
|
||||
(K (- disp-vector-length vector-tag))
|
||||
(K (make-constant (* i fixnum-scale))))
|
||||
v))]
|
||||
[else
|
||||
(tbind ([len (Value len)])
|
||||
(tbind ([alen (align-code len disp-vector-data)])
|
||||
(tbind ([v (prm 'alloc alen (K vector-tag))])
|
||||
(seq*
|
||||
(prm 'mset! v
|
||||
(K (- disp-vector-length vector-tag))
|
||||
len)
|
||||
v))))]))]
|
||||
[($make-record)
|
||||
(let ([rtd (car arg*)] [len (cadr arg*)])
|
||||
(tbind ([rtd (Value rtd)])
|
||||
|
@ -849,20 +984,14 @@
|
|||
rtd)
|
||||
t))]
|
||||
[else
|
||||
(tbind ([ln
|
||||
(prm 'sll
|
||||
(prm 'sra
|
||||
(prm 'int+ (Value len)
|
||||
(K (+ disp-record-data
|
||||
(sub1 object-alignment))))
|
||||
(K align-shift))
|
||||
(K align-shift))])
|
||||
(tbind ([t (prm 'alloc ln (K vector-tag))])
|
||||
(seq*
|
||||
(prm 'mset! t
|
||||
(K (- disp-record-rtd vector-tag))
|
||||
rtd)
|
||||
t)))])))]
|
||||
(tbind ([len (Value len)])
|
||||
(tbind ([ln (align-code len disp-record-data)])
|
||||
(tbind ([t (prm 'alloc ln (K vector-tag))])
|
||||
(seq*
|
||||
(prm 'mset! t
|
||||
(K (- disp-record-rtd vector-tag))
|
||||
rtd)
|
||||
t))))])))]
|
||||
[($record-rtd)
|
||||
(prm 'mref (Value (car arg*))
|
||||
(K (- disp-record-rtd vector-tag)))]
|
||||
|
@ -906,10 +1035,19 @@
|
|||
[else (error who "nonconst arg to fxsra ~s" c)]))]
|
||||
[($fxlogand)
|
||||
(prm 'logand (Value (car arg*)) (Value (cadr arg*)))]
|
||||
[($fxlogxor)
|
||||
(prm 'logxor (Value (car arg*)) (Value (cadr arg*)))]
|
||||
[($fxlognot)
|
||||
(Value (prm '$fxlogxor (car arg*) (K -1)))]
|
||||
[($char->fixnum)
|
||||
(prm 'sra
|
||||
(Value (car arg*))
|
||||
(K (- char-shift fixnum-shift)))]
|
||||
[($fixnum->char)
|
||||
(prm 'logor
|
||||
(prm 'sll (Value (car arg*))
|
||||
(K (- char-shift fixnum-shift)))
|
||||
(K char-tag))]
|
||||
[($current-frame) ;; PCB NEXT-CONTINUATION
|
||||
(prm 'mref pcr (K 20))]
|
||||
[($seal-frame-and-call)
|
||||
|
@ -947,12 +1085,15 @@
|
|||
(seq*
|
||||
(prm 'mset! t
|
||||
(K (- disp-closure-code closure-tag))
|
||||
(make-constant
|
||||
(make-code-loc SL_continuation_code)))
|
||||
(K (make-code-loc SL_continuation_code)))
|
||||
(prm 'mset! t
|
||||
(K (- disp-closure-data closure-tag))
|
||||
arg)
|
||||
t)))]
|
||||
[($make-call-with-values-procedure)
|
||||
(K (make-closure (make-code-loc SL_call_with_values) '()))]
|
||||
[($make-values-procedure)
|
||||
(K (make-closure (make-code-loc SL_values) '()))]
|
||||
[($cpref)
|
||||
(let ([a0 (car arg*)] [a1 (cadr arg*)])
|
||||
(record-case a1
|
||||
|
@ -1158,7 +1299,7 @@
|
|||
(S* rands
|
||||
(lambda (rands)
|
||||
(make-set d (make-disp (car rands) (cadr rands)))))]
|
||||
[(logand logxor int+ int-)
|
||||
[(logand logxor logor int+ int-)
|
||||
(make-seq
|
||||
(V d (car rands))
|
||||
(S (cadr rands)
|
||||
|
@ -1224,9 +1365,6 @@
|
|||
(caddr s*))))]
|
||||
[(nop) x]
|
||||
[else (error 'impose-effect "invalid instr ~s" x)])]
|
||||
; (S* rands
|
||||
; (lambda (rands)
|
||||
; (make-primcall op rands)))]
|
||||
[(funcall rator rands)
|
||||
(handle-nontail-call rator rands #f #f)]
|
||||
[(jmpcall label rator rands)
|
||||
|
@ -1246,9 +1384,17 @@
|
|||
[(bind lhs* rhs* e)
|
||||
(do-bind lhs* rhs* (P e))]
|
||||
[(primcall op rands)
|
||||
(S* rands
|
||||
(lambda (rands)
|
||||
(make-asm-instr op (car rands) (cadr rands))))]
|
||||
(let ([a (car rands)] [b (cadr rands)])
|
||||
(cond
|
||||
[(and (constant? a) (constant? b))
|
||||
(let ([t (unique-var 'tmp)])
|
||||
(P (make-bind (list t) (list a)
|
||||
(make-primcall op (list t b)))))]
|
||||
[else
|
||||
(S* rands
|
||||
(lambda (rands)
|
||||
(let ([a (car rands)] [b (cadr rands)])
|
||||
(make-asm-instr op a b))))]))]
|
||||
[else (error who "invalid pred ~s" x)]))
|
||||
;;;
|
||||
(define (handle-tail-call target rator rands)
|
||||
|
@ -1842,7 +1988,7 @@
|
|||
(make-conditional (P e0) (E e1) (E e2))]
|
||||
[(asm-instr op a b)
|
||||
(case op
|
||||
[(logor logand int+ int-)
|
||||
[(logor logxor logand int+ int-)
|
||||
(cond
|
||||
[(and (mem? a) (mem? b))
|
||||
(let ([u (mku)])
|
||||
|
@ -2304,9 +2450,8 @@
|
|||
(let* (
|
||||
;[foo (print-code x)]
|
||||
[x (remove-primcalls x)]
|
||||
;[foo (printf "1")]
|
||||
[x (eliminate-fix x)]
|
||||
;[foo (printf "2")]
|
||||
;[foo (printf "1")]
|
||||
[x (normalize-context x)]
|
||||
;[foo (printf "3")]
|
||||
;[foo (print-code x)]
|
||||
|
|
|
@ -67,14 +67,14 @@
|
|||
[%ch 8 5]
|
||||
[%dh 8 6]
|
||||
[%bh 8 7]
|
||||
[/0 0 0]
|
||||
[/1 0 1]
|
||||
[/2 0 2]
|
||||
[/3 0 3]
|
||||
[/4 0 4]
|
||||
[/5 0 5]
|
||||
[/6 0 6]
|
||||
[/7 0 7]
|
||||
[/0 0 0]
|
||||
[/1 0 1]
|
||||
[/2 0 2]
|
||||
[/3 0 3]
|
||||
[/4 0 4]
|
||||
[/5 0 5]
|
||||
[/6 0 6]
|
||||
[/7 0 7]
|
||||
))
|
||||
|
||||
(define register-index
|
||||
|
@ -314,15 +314,6 @@
|
|||
ac)])))
|
||||
|
||||
|
||||
;;(define CODErd
|
||||
;; (lambda (c r1 disp ac)
|
||||
;; (with-args disp
|
||||
;; (lambda (i/r r2)
|
||||
;; (if (reg? i/r)
|
||||
;; (CODE c (RegReg r1 i/r r2 ac))
|
||||
;; (CODErri c r1 r2 i/r ac))))))
|
||||
|
||||
|
||||
(define IMM32*2
|
||||
(lambda (i1 i2 ac)
|
||||
(cond
|
||||
|
@ -365,8 +356,8 @@
|
|||
(error 'CODEdi "unsupported2")]
|
||||
[else (error 'CODEdi "unhandled ~s" disp)])))))
|
||||
|
||||
; 81 /0 id ADD r/m32,imm32 Valid Valid Add imm32 to
|
||||
(define (CODE/r c /?)
|
||||
; 81 /0 id ADD r/m32,imm32 Valid Add imm32 to
|
||||
(define (CODE/digit c /d)
|
||||
(lambda (dst ac)
|
||||
(cond
|
||||
[(mem? dst)
|
||||
|
@ -374,9 +365,26 @@
|
|||
(lambda (a0 a1)
|
||||
(cond
|
||||
[(and (imm8? a0) (reg? a1))
|
||||
(CODE c (ModRM 1 /? a1 (IMM8 a0 ac)))]
|
||||
[else (error 'CODE/r "unhandled ~s ~s" a0 a1)])))]
|
||||
[else (error 'CODE/r "unhandled ~s" dst)])))
|
||||
(CODE c (ModRM 1 /d a1 (IMM8 a0 ac)))]
|
||||
[else (error 'CODE/digit "unhandled ~s ~s" a0 a1)])))]
|
||||
[else (error 'CODE/digit "unhandled ~s" dst)])))
|
||||
|
||||
; 01 /r ADD r/m32, r32 Valid Add r32 to r/m32.
|
||||
;;;(define (CODE/r c /r)
|
||||
;;; (lambda (dst ac)
|
||||
;;; (cond
|
||||
;;; [(mem? dst)
|
||||
;;; (with-args dst
|
||||
;;; (lambda (a0 a1)
|
||||
;;; (cond
|
||||
;;; [(and (imm8? a0) (reg? a1))
|
||||
;;; (CODE c (ModRM 1 /r a1 (IMM8 a0 ac)))]
|
||||
;;; [else (error 'CODE/r "unhandled ~s ~s" a0 a1)])))]
|
||||
;;; [else (error 'CODE/r "unhandled ~s" dst)])))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(define CODEid
|
||||
(lambda (c /? n disp ac)
|
||||
|
@ -501,9 +509,10 @@
|
|||
[(and (mem? src) (reg? dst))
|
||||
(CODErd #x03 dst src ac)]
|
||||
[(and (imm? src) (mem? dst))
|
||||
((CODE/r #x81 '/0) dst (IMM32 src ac))]
|
||||
((CODE/digit #x81 '/0) dst (IMM32 src ac))]
|
||||
[(and (reg? src) (mem? dst))
|
||||
(CODErd #x81 src dst ac)]
|
||||
(printf "code=~s\n" ((CODE/digit #x01 src) dst '()))
|
||||
((CODE/digit #x01 src) dst ac)]
|
||||
[else (error who "invalid ~s" instr)])]
|
||||
[(subl src dst)
|
||||
(cond
|
||||
|
@ -526,8 +535,8 @@
|
|||
(CODE #xC1 (ModRM 3 '/4 dst (IMM8 src ac)))]
|
||||
[(and (imm8? src) (mem? dst))
|
||||
(printf "sall ~s ~s\n" src dst)
|
||||
(printf "=> ~s\n" ((CODE/r #xC1 '/4) dst (IMM8 src '())))
|
||||
((CODE/r #xC1 '/4) dst (IMM8 src ac))]
|
||||
(printf "=> ~s\n" ((CODE/digit #xC1 '/4) dst (IMM8 src '())))
|
||||
((CODE/digit #xC1 '/4) dst (IMM8 src ac))]
|
||||
[(and (eq? src '%cl) (reg? dst))
|
||||
(CODE #xD3 (ModRM 3 '/4 dst ac))]
|
||||
[else (error who "invalid ~s" instr)])]
|
||||
|
@ -548,8 +557,8 @@
|
|||
(CODE #xC1 (ModRM 3 '/7 dst (IMM8 src ac)))]
|
||||
[(and (imm8? src) (mem? dst))
|
||||
(printf "sarl ~s ~s\n" src dst)
|
||||
(printf "=> ~s\n" ((CODE/r #xC1 '/7) dst (IMM8 src '())))
|
||||
((CODE/r #xC1 '/7) dst (IMM8 src ac))]
|
||||
(printf "=> ~s\n" ((CODE/digit #xC1 '/7) dst (IMM8 src '())))
|
||||
((CODE/digit #xC1 '/7) dst (IMM8 src ac))]
|
||||
[(and (eq? src '%cl) (reg? dst))
|
||||
(CODE #xD3 (ModRM 3 '/7 dst ac))]
|
||||
[else (error who "invalid ~s" instr)])]
|
||||
|
@ -680,43 +689,43 @@
|
|||
[(reg? dst)
|
||||
(CODE #xFF (ModRM 3 '/2 dst ac))]
|
||||
[else (error who "invalid jmp target ~s" dst)])]
|
||||
[(seta dst) (conditional-set #x97 dst ac)]
|
||||
[(setae dst) (conditional-set #x93 dst ac)]
|
||||
[(setb dst) (conditional-set #x92 dst ac)]
|
||||
[(setbe dst) (conditional-set #x96 dst ac)]
|
||||
[(setg dst) (conditional-set #x9F dst ac)]
|
||||
[(setge dst) (conditional-set #x9D dst ac)]
|
||||
[(setl dst) (conditional-set #x9C dst ac)]
|
||||
[(setle dst) (conditional-set #x9E dst ac)]
|
||||
[(sete dst) (conditional-set #x94 dst ac)]
|
||||
[(setna dst) (conditional-set #x96 dst ac)]
|
||||
[(setnae dst) (conditional-set #x92 dst ac)]
|
||||
[(setnb dst) (conditional-set #x93 dst ac)]
|
||||
[(setnbe dst) (conditional-set #x97 dst ac)]
|
||||
[(setng dst) (conditional-set #x9E dst ac)]
|
||||
[(setnge dst) (conditional-set #x9C dst ac)]
|
||||
[(setnl dst) (conditional-set #x9D dst ac)]
|
||||
[(setnle dst) (conditional-set #x9F dst ac)]
|
||||
[(setne dst) (conditional-set #x95 dst ac)]
|
||||
[(ja dst) (conditional-jump #x87 dst ac)]
|
||||
[(jae dst) (conditional-jump #x83 dst ac)]
|
||||
[(jb dst) (conditional-jump #x82 dst ac)]
|
||||
[(jbe dst) (conditional-jump #x86 dst ac)]
|
||||
[(jg dst) (conditional-jump #x8F dst ac)]
|
||||
[(jge dst) (conditional-jump #x8D dst ac)]
|
||||
[(jl dst) (conditional-jump #x8C dst ac)]
|
||||
[(jle dst) (conditional-jump #x8E dst ac)]
|
||||
[(je dst) (conditional-jump #x84 dst ac)]
|
||||
[(jna dst) (conditional-jump #x86 dst ac)]
|
||||
[(jnae dst) (conditional-jump #x82 dst ac)]
|
||||
[(jnb dst) (conditional-jump #x83 dst ac)]
|
||||
[(jnbe dst) (conditional-jump #x87 dst ac)]
|
||||
[(jng dst) (conditional-jump #x8E dst ac)]
|
||||
[(jnge dst) (conditional-jump #x8C dst ac)]
|
||||
[(jnl dst) (conditional-jump #x8D dst ac)]
|
||||
[(jnle dst) (conditional-jump #x8F dst ac)]
|
||||
[(jne dst) (conditional-jump #x85 dst ac)]
|
||||
[(jo dst) (conditional-jump #x80 dst ac)]
|
||||
[(seta dst) (conditional-set #x97 dst ac)]
|
||||
[(setae dst) (conditional-set #x93 dst ac)]
|
||||
[(setb dst) (conditional-set #x92 dst ac)]
|
||||
[(setbe dst) (conditional-set #x96 dst ac)]
|
||||
[(setg dst) (conditional-set #x9F dst ac)]
|
||||
[(setge dst) (conditional-set #x9D dst ac)]
|
||||
[(setl dst) (conditional-set #x9C dst ac)]
|
||||
[(setle dst) (conditional-set #x9E dst ac)]
|
||||
[(sete dst) (conditional-set #x94 dst ac)]
|
||||
[(setna dst) (conditional-set #x96 dst ac)]
|
||||
[(setnae dst) (conditional-set #x92 dst ac)]
|
||||
[(setnb dst) (conditional-set #x93 dst ac)]
|
||||
[(setnbe dst) (conditional-set #x97 dst ac)]
|
||||
[(setng dst) (conditional-set #x9E dst ac)]
|
||||
[(setnge dst) (conditional-set #x9C dst ac)]
|
||||
[(setnl dst) (conditional-set #x9D dst ac)]
|
||||
[(setnle dst) (conditional-set #x9F dst ac)]
|
||||
[(setne dst) (conditional-set #x95 dst ac)]
|
||||
[(ja dst) (conditional-jump #x87 dst ac)]
|
||||
[(jae dst) (conditional-jump #x83 dst ac)]
|
||||
[(jb dst) (conditional-jump #x82 dst ac)]
|
||||
[(jbe dst) (conditional-jump #x86 dst ac)]
|
||||
[(jg dst) (conditional-jump #x8F dst ac)]
|
||||
[(jge dst) (conditional-jump #x8D dst ac)]
|
||||
[(jl dst) (conditional-jump #x8C dst ac)]
|
||||
[(jle dst) (conditional-jump #x8E dst ac)]
|
||||
[(je dst) (conditional-jump #x84 dst ac)]
|
||||
[(jna dst) (conditional-jump #x86 dst ac)]
|
||||
[(jnae dst) (conditional-jump #x82 dst ac)]
|
||||
[(jnb dst) (conditional-jump #x83 dst ac)]
|
||||
[(jnbe dst) (conditional-jump #x87 dst ac)]
|
||||
[(jng dst) (conditional-jump #x8E dst ac)]
|
||||
[(jnge dst) (conditional-jump #x8C dst ac)]
|
||||
[(jnl dst) (conditional-jump #x8D dst ac)]
|
||||
[(jnle dst) (conditional-jump #x8F dst ac)]
|
||||
[(jne dst) (conditional-jump #x85 dst ac)]
|
||||
[(jo dst) (conditional-jump #x80 dst ac)]
|
||||
[(byte x)
|
||||
(unless (byte? x) (error who "~s is not a byte" x))
|
||||
(cons (byte x) ac)]
|
||||
|
|
Loading…
Reference in New Issue