programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Callbacks, part 3

From: Rick VanNorman <rick_at_forth.com>
Date: Sun, 02 Dec 2001 11:08:29 -0800

----------------------------------------------------------------------
Callbacks, part 3
----------------------------------------------------------------------

In my second installment, I discussed the basics of what the callback
mechanism does, and how it is called from Forth, and how Windows uses it
to "call back" into your application. Tonight I will be discussing how
that callback creates a proper environment for your Forth words to run.

The core of the callback functionality is wrapped in the assembly
language code of RUNCB . This code is essentially an interrupt
handler, and I'll try to examine it as such.

Interrupt handlers are normally wrapped in register-save and
register-restore code. RUNCB is no exception. But, since it isn't
a pure interrupt handler, we only need to save the registers that
Windows cares about. Look at a stripped-down version of RUNCB :

LABEL RUNCB
        8 [ESP] ECX LEA \ ecx points to parameters

        EDI PUSH
        ESI PUSH
        EBP PUSH
        EDX PUSH
        EBX PUSH

        ( ... )

        EBX POP
        EDX POP
        EBP POP \ assuming all is well...
        ESI POP
        EDI POP

        RET END-CODE

What this does is save and restore all the registers that Windows
cares about. In the middle, where the ( ... ) is, you can do almost
anything you want so long as the processor return stack is correct
when you get back to the "EBX POP" instruction.

Since this makes a nice, short bit of information, I'll stop here
for right now.

The ( ... ) represents the setup that SwiftForth needs to execute
words in a context that the programmer can use. Next time, I'll discuss
what that setup actually is and how we accomplish it.

Thanks for listening,
Rick

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Sun Dec 02 2001 - 11:07:26 PST

This archive was generated by hypermail 2.2.0 : Fri Nov 21 2008 - 03:04:20 PST