Changeset 6358 for branches/x8664-call


Ignore:
Timestamp:
Apr 29, 2007, 9:22:23 AM (13 years ago)
Author:
gb
Message:

Functions (and most subprims) called with return address on top of
stack; lots of changes to support this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/x8664-call/ccl/compiler/X86/x86-lapmacros.lisp

    r6331 r6358  
    243243(defx86lapmacro save-simple-frame ()
    244244  `(progn
    245     (pushq (% ra0))
    246245    (pushq (% rbp))
    247246    (movq (% rsp) (% rbp))))
     
    254253    (subq ($ (* $numx8664argregs x8664::node-size)) (% imm0))
    255254    (jle ,push)
    256     (movq (% rbp) (@ (% rsp) (% imm0)))
    257     (leaq (@ (% rsp) (% imm0)) (% rbp))
    258     (movq (% ra0) (@ 8 (% rbp)))
     255    (movq (% rbp) (@ 8 (% rsp) (% imm0)))
     256    (leaq (@ 8 (% rsp) (% imm0)) (% rbp))
     257    (popq (@ 8 (% rbp)))
    259258    (jmp ,done)
    260259    ,push
     
    265264(defx86lapmacro restore-simple-frame ()
    266265  `(progn
    267     (leave)
    268     (popq (% ra0))))
    269 
    270 
    271 ;;; Caller pushed zeros to reserve space for stack frame before
    272 ;;; pushing args.  We have to discard it before returning.
     266    (leave)))
     267
     268
     269
    273270(defx86lapmacro discard-reserved-frame ()
    274271  `(add ($ '2) (% rsp)))
    275272
    276 ;;; Return to caller.  (% RA0) should contain a tagged return
    277 ;;; address inside the caller's (% FN).
    278 (defx86lapmacro single-value-return ()
    279   `(jmp (% ra0)))
     273;;; Return to caller.
     274(defx86lapmacro single-value-return (&optional (words-to-discard 0))
     275  (if (zerop words-to-discard)
     276    `(ret)
     277    `(ret ($ ,(* x8664::node-size words-to-discard)))))
    280278
    281279;;; Using *x8664-backend* here is wrong but expedient.
     
    290288  `(jmp (@ ,(x86-subprim-offset name))))
    291289
    292 (defx86lapmacro xcall-subprim (name)
     290(defx86lapmacro call-subprim (name)
    293291  `(progn
    294292    (:talign 4)
     
    296294    (recover-fn-from-rip)))
    297295
    298 (defx86lapmacro call-subprim (name &optional (recover-fn t))
    299   (declare (ignore recover-fn))
    300   (let* ((label (gensym))
    301          (post (gensym)))
    302     `(progn
    303       (leaq (@ (:^ ,label) (% fn)) (% ra0))
    304       (jmp-subprim ,name)
    305       (:tra ,label)
    306       (lea (@ (- (:^ ,post)) (% rip)) (% fn))
    307       ,post)))
    308296     
    309297(defx86lapmacro %car (src dest)
     
    323311(defx86lapmacro load-constant (constant dest &optional (fn 'fn))
    324312  `(movq (@ ',constant (% ,fn)) (% ,dest)))
     313
     314(defx86lapmacro recover-fn-from-rip ()
     315  (let* ((next (gensym)))
     316    `(progn
     317      (lea (@ (- (:^ ,next)) (% rip)) (% fn))
     318      ,next)))
    325319
    326320;;; call symbol named NAME, setting nargs to NARGS.  Do the TRA
     
    328322;;; to return a single value.
    329323(defx86lapmacro call-symbol (name nargs)
    330   (let* ((return (gensym))
    331          (post (gensym)))
    332     `(progn
    333       (load-constant ,name fname)
    334       (set-nargs ,nargs)
    335       (lea (@ (:^ ,return) (% fn)) (% ra0))
    336       (movq (@ x8664::symbol.fcell (% fname)) (% fn))
    337       (jmp (% fn))
    338       (:tra ,return)
    339       (lea (@ (- (:^ ,post)) (% rip)) (% fn))
    340       ,post)))
    341 
    342 (defx86lapmacro recover-fn-from-rip ()
    343   (let* ((next (gensym)))
    344     `(progn
    345       (lea (@ (- (:^ ,next)) (% rip)) (% fn))
    346       ,next)))
     324  `(progn
     325    (load-constant ,name fname)
     326    (set-nargs ,nargs)
     327    (:talign 4)
     328    (call (@ x8664::symbol.fcell (% fname)))
     329    (recover-fn-from-rip)))
     330
    347331
    348332;;;  tail call the function named by NAME with nargs NARGS.  %FN is
     
    355339  `(progn
    356340    (load-constant ,name fname)
    357     (movq (% fn) (% xfn))
    358     (movq (@ x8664::symbol.fcell (% fname)) (% fn))
    359341    (set-nargs ,nargs)
    360     (jmp (% fn))))
     342    (jmp (@ x8664::symbol.fcell (% fname)))))
    361343
    362344(defx86lapmacro push-argregs ()
Note: See TracChangeset for help on using the changeset viewer.