1 Reply Latest reply: Oct 7, 2009 6:18 PM by 807557 RSS

    OBP assembler call

    807557
      How do I call routine on a certain address from OBP? It looks like I should be able to do it with 'code' keyword, but it's not clear how.
      Creating an empty routine works:
      ok code t1 c;
      ok see t1
      code t1
      ffd460f4     jmp     %g3, 0, %g0
      ffd460f8     add     %g0, %g0, %g0
      but how to put something useful in there?
      ok code t2 ffd08af0 ba c;
      Stack Changed
      ok see t2
      t2 ?
        • 1. Re: OBP assembler call
          807557
          The following code from my archived source tree looks relevant. I don't remember whether it is already included in OBP or not.

          If you want to contact me directly for other questions, my email address is wmb at firmworks dot com .

          \ Shared code for ccall interface. This file is used in conjunction with
          \ ccall.fth. The 2 files are separate because the code in this file must
          \ be resident, while the code in ccall.fth can be transient.
          \
          \ do-ccall is a shared subroutine which is called from code generated by
          \ "ccall". The calling sequence looks like:
          \
          \ <code to transfer arguments from the stack to registers>
          \ sethi %hi(c_entry_point), %l0
          \ call do-ccall
          \ or %l0, %lo(c_entry_point), %l0
          \ <code to push results, if any, on the stack>

          label do-ccall          \ Subroutine address in %l0, return address in %o7

          sp 'user saved-sp nput     \ Save for callbacks
          rp 'user saved-rp nput     \ Save for callbacks

          %o7 %l1 move          \ Exchange %l0 and %o7
          %l0 %o7 move
          %l1 %l0 move

          \ Save the globals in case C changes them
          %g1 %l1 move
          %g2 %l2 move
          %g3 %l3 move
          %g4 %l4 move
          %g5 %l5 move
          %g6 %l6 move
          %o7 0 %o7 jmpl
          %g7 %l7 move     \ Delay slot

          \ Restore the globals
          %l1 %g1 move
          %l2 %g2 move
          %l3 %g3 move
          %l4 %g4 move
          %l5 %g5 move
          %l6 %g6 move
          %l0 8 %g0 jmpl     \ Return
          %l7 %g7 move
          end-code

          \ From Forth, call the C subroutine whose address is on the stack

          code call ( [ arg5 .. arg0 ] adr -- [ arg5 .. arg0 ] result )
          \ Pass up to 6 arguments
          sp 0 /n* %o0 nget
          sp 1 /n* %o1 nget
          sp 2 /n* %o2 nget
          sp 3 /n* %o3 nget
          sp 4 /n* %o4 nget
          sp 5 /n* %o5 nget

          do-ccall call
          tos %l0 move

          %o0 tos move     \ Return subroutine result
          c;