"0x4E4F, 0xA801" translates into:

     TRAP $F
     DC.W $A801.

TRAP $F causes an exception, which results in the processor calling an OS
defined function.  The OS defined function, looks at the 2-byte value
following the instruction (in this case, the $A801) and dispatches based on
it. In the case of library function dispatches, it also looks at the refNum
pushed onto the stack (that's how it knows which dispatch table to use).

-- Keith Rollin






Jeff Ishaq <[EMAIL PROTECTED]> on 05/19/99 06:20:44 PM

Please respond to [EMAIL PROTECTED]

Sent by:  Jeff Ishaq <[EMAIL PROTECTED]>


To:   "'Palm Developer's Forum'" <[EMAIL PROTECTED]>
cc:    (Keith Rollin/HQ/3Com)
Subject:  How SYS_TRAP works?  And, making a >32k shared library




Hardcore M68K programmers please help me figure this stuff out.  Once I get
the nitty-gritty of this figured out, I can put out a very detailed article
and a great sample code project for shared libraries for all to use.  This
is one of the aspects of shared libraries that I feel not too many people
can say they understand, and I think it should be brought to light and
published in at least one on-line article.
I'm curious if anyone ever bothered to digest precisely what this line
does.
extern Err MySharedLibOpen ( UInt uRefNum )   SYS_TRAP( sysLibTrapOpen );
here's the decomposition, assuming PalmOS3 and no emulation:
SYS_TRAP( sysLibTrapOpen ) ->
SYS_TRAP( 0xA801 ) ->
TWOWORD_INLINE(m68kTrapInstr+sysDispatchTrapNum, 0xA801 ) ->
TWOWORD_INLINE( 0x4E40 + 15, 0xA801 ) ->
{ 0x4E40 + 15, 0xA801 } ->
{ 0x4E4F, 0xA801 }
So it turns into this:
extern Err MSLOpen  ( UInt uRefNum )     { 0x4E4F, 0xA801 };
I don't have my Motorola card with me, damne if I didn't leave it at home
today, so I'm not sure if 4E4F turns into an opcode with 0xA801 as an
argument or what's going on here.  I guess this would probably ultimately
load up the PC with the address in a lookup table at offset 0xA801.  That
could only mean that somehow the OS finds at this location the dispatch
table for the shared library.  But if we use these same #define'd constants
in a different shared library, we will end up with the same (0x4E4F,
0xA801)
opcode and arg (?) -- how does the OS differentiate which lib's function we
want to call, etc?
I understand how the dispatch table is basically just a JMP table whose
offsets are calculated at compile-time, and I understand how the address of
this dispatch table is placed into an instance of the shared library's
'dispatchTblP' element.  I just don't get how SYS_TRAP()s can figure out
WHICH lib's dispatchTblP to reference inside of GSysLibTableP.
I've also heard that shared libraries can be larger than 32k in length.  Is
there any magic to this (i.e., putting the dispatch table in the physical
middle of the library so the signed word jumps can be +/-32k from the
table?
How do you do that?), or is this just a Stupid Codewarrior Trick?
If you got this far, thanks!  Uh, even if you didn't get this far, thanks.
Inquiring minds want to know.
-Jeff Ishaq
The Windward Group






Reply via email to