home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!hela.iti.org!usc!rpi!deweeset
- From: deweeset@ptolemy3.rdrc.rpi.edu (Thomas E. DeWeese)
- Subject: Jump tables, and creating functions
- Message-ID: <g!j2!zf@rpi.edu>
- Nntp-Posting-Host: ptolemy3.rdrc.rpi.edu
- Organization: Rensselaer Polytechnic Institute, Troy, NY
- Date: Sun, 13 Dec 1992 20:03:53 GMT
- Lines: 51
-
- Hello, I am trying to write a program that will create a function, then
- call that function. I think I have my program generating correct code,
- but I can't seem to convice my program to JSR to it.
- Let me expain my situation a little. I am developing on a MacII, using
- Think C 5.0.4, Under system 7.1. There really is a good reason for writing
- self modifying code, in this case. Namely this is a very time critical
- function, and the program generated function will be about 3-4 times faster
- than any hand coded version could be.
- Now I must admit that I am a bit of a novice when it comes to programming
- in assembly on a 68000, (I learned IBM370 assembly, about 4 years ago).
- But so far the real problem has been the function interface. Here is what
- I have learned so far. Functions in Think C are all referenced through a
- "Jump Table". if you take the address of a function you will get a pointer
- to this jump table (which consists of a JSR <ea> followed by a RTS I think)
- where the <ea> is the actual address of the function. This allows for
- functions to be moved in memory (as long as the jump table doesn't move), and
- it should even allow code segments to be unloaded (as long as you substitue
- a JSR to a function to load the code, and then jump to the proper address).
- All of that is pretty neat and well thought out.
- But what I have is a pointer to the actual function I want to execute.
- EG the first thing is an UNLINK ... Now I have already tried
-
- myfunc(windPtr, dataPtr);
-
- But it never even thought of working, it didn't even make it to my code
- (I did a "g <address of my function>" command in Macs Bugs), and it
- hit an illegal instruction before it stopped at the top of my function. BTW
- I can't seem to trace the execution of my program with MacsBugs. From the
- Think Debugger, if I drop it into the monitor it seems to be in a little
- function which simply brings the Think Debugger to the front (dropping it
- out of MacsBugs!!), I don't know if this is a bug in the Think Debugger
- or in MacsBugs, but I don't think that this should be what happens.
-
- I also tried to do the JSR my self with
-
- asm{
- MOVE.L windPtr,-(SP)
- MOVE.L dataPtr,-(SP)
- JSR myfunc
- ADD.L #0x08, SP
- }
- Now I don't see how it could possibly not JSR to myfunc, but it didn't.
- Am I missing something really important?
- How do I use Macsbug with the Think Debugger. It says the PC is four off
- but I don't think that has anything to do with it.
- Where can I learn more about the internals of function calls on the mac?
- I will try to read all replies to the news group, but if you mail me
- directly I will compile a summary of responses and my final solution (if
- I find one). If I get my code working I will probably release it to the PD.
- Thomas DeWeese
- deweeset@rdrc.rpi.edu
-