|
519 | 519 | '(#x08 #x07 #x06 #x05 #x04 #x03 #x02 #x01) |
520 | 520 | (u8vector->list b)))) |
521 | 521 |
|
522 | | -;; --- asm-template :postamble --- |
| 522 | +;; --- link-template :postamble --- |
523 | 523 |
|
524 | | -;; No postamble: bytes size equals assembled code size. |
525 | | -(let () |
526 | | - (define tmpl (asm-template '((ret)) :postamble 0)) |
527 | | - (receive (b _) (link-template tmpl '()) |
528 | | - (test* "asm-template :postamble 0" |
| 524 | +;; :postamble 0: no change to output size. |
| 525 | +(let ([tmpl (asm-template '((ret)))]) |
| 526 | + (receive (b _) (link-template tmpl '() :postamble 0) |
| 527 | + (test* "link-template :postamble 0" |
529 | 528 | '(#xc3) |
530 | 529 | (u8vector->list b)))) |
531 | 530 |
|
532 | | -;; :postamble 8: eight zero bytes appended after the code. |
533 | | -(let () |
534 | | - (define tmpl (asm-template '((ret)) :postamble 8)) |
535 | | - (receive (b _) (link-template tmpl '()) |
536 | | - (test* "asm-template :postamble 8 size" |
| 531 | +;; :postamble 8: eight zero bytes appended after the linked bytes. |
| 532 | +(let ([tmpl (asm-template '((ret)))]) |
| 533 | + (receive (b _) (link-template tmpl '() :postamble 8) |
| 534 | + (test* "link-template :postamble 8 size" |
537 | 535 | 9 |
538 | 536 | (uvector-size b)) |
539 | | - (test* "asm-template :postamble 8 content" |
| 537 | + (test* "link-template :postamble 8 content" |
540 | 538 | '(#xc3 0 0 0 0 0 0 0 0) |
541 | 539 | (u8vector->list b)))) |
542 | 540 |
|
543 | | -;; :postamble preserves labels (labels point into code, not postamble). |
544 | | -(let () |
545 | | - (define tmpl (asm-template '(entry: (ret)) :postamble 4)) |
546 | | - (receive (_ labels) (link-template tmpl '()) |
547 | | - (test* "asm-template :postamble labels preserved" |
548 | | - '((entry: . 0)) |
549 | | - labels))) |
550 | | - |
551 | | -;; .align at end of insn list pads code; postamble follows the aligned size. |
552 | | -;; ret (1 byte) + .align 8 (7 padding bytes) = 8 bytes of code. |
553 | | -(let () |
554 | | - (define tmpl (asm-template '((ret) (.align 8)) :postamble 8)) |
555 | | - (receive (b _) (link-template tmpl '()) |
556 | | - (test* "asm-template ends with .align + :postamble" |
557 | | - (append '(#xc3 0 0 0 0 0 0 0) ; ret + 7 align bytes |
558 | | - '(0 0 0 0 0 0 0 0)) ; 8-byte postamble |
559 | | - (u8vector->list b)))) |
560 | | - |
561 | | -;; offset-form can fill into the postamble region using a patch as anchor. |
562 | | -;; Template: (.dataq :anchor) [8 bytes] + postamble [8 bytes] = 16 bytes. |
563 | | -;; :anchor patch is at offset 0; extra-offset 8 reaches into the postamble. |
564 | | -(let () |
565 | | - (define tmpl (asm-template '((.dataq :anchor)) :postamble 8)) |
| 541 | +;; :postamble region can be filled via offset form. |
| 542 | +;; Template: (.dataq :anchor) at offset 0 (8 bytes); postamble adds 8 more. |
| 543 | +;; Offset 8 from :anchor reaches into the postamble. |
| 544 | +(let ([tmpl (asm-template '((.dataq :anchor)))]) |
566 | 545 | (receive (b _) (link-template tmpl `((:anchor ,<uint64> #xfeedface00000000 0) |
567 | | - (:anchor ,<uint32> #xdeadbeef 8))) |
568 | | - (test* "asm-template :postamble filled via offset form" |
569 | | - (append '(#x00 #x00 #x00 #x00 #xce #xfa #xed #xfe) ; .dataq |
570 | | - '(#xef #xbe #xad #xde 0 0 0 0)) ; postamble |
| 546 | + (:anchor ,<uint32> #xdeadbeef 8)) |
| 547 | + :postamble 8) |
| 548 | + (test* "link-template :postamble filled via offset form" |
| 549 | + (append '(#x00 #x00 #x00 #x00 #xce #xfa #xed #xfe) |
| 550 | + '(#xef #xbe #xad #xde 0 0 0 0)) |
571 | 551 | (u8vector->list b)))) |
572 | 552 |
|
| 553 | +;; labels are unchanged regardless of :postamble. |
| 554 | +(let ([tmpl (asm-template '(entry: (ret)))]) |
| 555 | + (receive (_ labels) (link-template tmpl '() :postamble 4) |
| 556 | + (test* "link-template :postamble labels unchanged" |
| 557 | + '((entry: . 0)) |
| 558 | + labels))) |
| 559 | + |
573 | 560 | ;; --- offset parameter form (keyword native-type value extra-offset) --- |
574 | 561 |
|
575 | 562 | ;; Template: 16 zero bytes, one 8-byte patch at offset 0 for :base. |
|
0 commit comments