far-hc11.s 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;;; Test 68HC11 FAR trampoline generation
  2. ;;; 2 trampolines are generated:
  3. ;;; - one for '_far_bar'
  4. ;;; - one for '_far_foo'
  5. ;;; 'far_no_tramp' does not have any trampoline generated.
  6. ;;;
  7. .sect .text
  8. .globl _start
  9. _start:
  10. start:
  11. lds #stack
  12. ldx #0xabcd
  13. pshx
  14. ldd #0x1234
  15. ldx #0x5678
  16. bsr _far_bar ; Call to trampoline generated code
  17. cpx #0x1234
  18. bne fail ; X and D preserved (swapped by _far_bar)
  19. cpd #0x5678
  20. bne fail
  21. pulx
  22. cpx #0xabcd ; Stack parameter preserved
  23. bne fail
  24. ldd #_far_foo ; Get address of trampoline handler
  25. xgdx
  26. jsr 0,x
  27. ldd #_far_bar ; Likewise (unique trampoline check)
  28. xgdy
  29. jsr 0,y
  30. ldaa #%page(_far_no_tramp)
  31. ldy #%addr(_far_no_tramp)
  32. bsr __call_a16 ; No trampoline generated for _far_no_tramp
  33. clra
  34. clrb
  35. wai
  36. fail:
  37. ldd #1
  38. wai
  39. bra start
  40. .global __return
  41. __return:
  42. ins
  43. rts
  44. .sect .bank1,"ax"
  45. .globl _far_bar
  46. .far _far_bar ; Must mark symbol as far
  47. _far_bar:
  48. jsr local_bank1
  49. xgdx
  50. jmp __return
  51. local_bank1:
  52. rts
  53. .sect .bank2,"ax"
  54. .globl _far_foo
  55. .far _far_foo
  56. _far_foo:
  57. jsr local_bank2
  58. jmp __return
  59. local_bank2:
  60. rts
  61. .sect .bank3,"ax"
  62. .globl _far_no_tramp
  63. .far _far_no_tramp
  64. _far_no_tramp:
  65. jsr local_bank3
  66. jmp __return
  67. local_bank3:
  68. rts
  69. .sect .text
  70. .globl __far_trampoline
  71. __far_trampoline:
  72. psha ; (2) Save function parameter (high)
  73. ;; <Read current page in A>
  74. psha ; (2)
  75. ;; <Set currenge page from B>
  76. pshx ; (4)
  77. tsx ; (3)
  78. ldab 4,x ; (4) Restore function parameter (low)
  79. ldaa 2,x ; (4) Get saved page number
  80. staa 4,x ; (4) Save it below return PC
  81. pulx ; (5)
  82. pula ; (3)
  83. pula ; (3) Restore function parameter (high)
  84. jmp 0,y ; (4)
  85. .globl __call_a16
  86. __call_a16:
  87. ;; xgdx ; (3)
  88. ;; <Read current page in A> ; (3) ldaa _current_page
  89. psha ; (2)
  90. ;; <Set current page from B> ; (4) staa _current_page
  91. ;; xgdx ; (3)
  92. jmp 0,y ; (4)
  93. .sect .page0
  94. .skip 100
  95. stack: