By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,701 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

A bit off topic; setjmp/longjmp

P: n/a
I have a C program that I am trying to port to a Motorola 68k based system. It
makes use of setjmp and longjmp which are not supported by my C compiler. I
understand the general principle behind setjmp/longjmp, but I am somewhat lost
in the detail of how to actually implement this in assembler. (My compiler
supports in-line assembler which I hope will prove usefull). I will be very
gratefull for any help or pointers with this problem. I am conversant with the
x86 architecture, so an example from one of these platforms would probably be
illuminating as well.
John Ferguson

Nov 14 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jrferguson wrote:
I have a C program that I am trying to port to a Motorola 68k based system.
It makes use of setjmp and longjmp which are not supported by my C compiler.


Why don't you just get a C compiler that supports setjmp and longjmp?
Nov 14 '05 #2

P: n/a
Jrferguson wrote:
I have a C program that I am trying to port to a Motorola 68k based system. It
makes use of setjmp and longjmp which are not supported by my C compiler. I
understand the general principle behind setjmp/longjmp, but I am somewhat lost
in the detail of how to actually implement this in assembler. (My compiler
supports in-line assembler which I hope will prove usefull). I will be very
gratefull for any help or pointers with this problem. I am conversant with the
x86 architecture, so an example from one of these platforms would probably be
illuminating as well.


Are you sure setjmp() and longjmp() are not provided?
They are required to be present (and to work as advertised)
in any Standard-conforming hosted implementation.

A conforming "freestanding" implementation can omit most
of the Standard library facilities, including setjmp() and
longjmp(). If your implementation does in fact omit them,
the job of coming up with substitutes is likely to be more
than a little difficult. Not only must setjmp() and longjmp()
have intimate knowledge of the way the compiler generates code,
but the compiler must often be made aware that setjmp() and
longjmp() are "special" and violate the ordinary flow of
control. If setjmp() and longjmp() are absent, I'd suggest
you look long and hard for a suitable implementation that
provides them before undertaking to add them yourself. The
widely-available gcc compiler supports various M68K-based
systems, and it might well be easier to switch than fight.

Unfortunately, we here in comp.lang.c can't help you much
if you are eventually forced to roll your own. The tricks
you'll need to use will be highly specific to your machine
and to your compiler, and will have little or nothing to do
with the C language.

One thing we *might* be able to help with is rearranging
the code so it doesn't require setjmp() and longjmp() in the
first place. That's not always practical, but in cases where
it happens to be so the techniques you'll use will be part of
the C language and hence topical here.

Good luck: I have a feeling you'll need it ...

--
Er*********@sun.com

Nov 14 '05 #3

P: n/a
Jrferguson wrote:
I have a C program that I am trying to port to a Motorola 68k based system. It
makes use of setjmp and longjmp which are not supported by my C compiler. I
understand the general principle behind setjmp/longjmp, but I am somewhat lost
in the detail of how to actually implement this in assembler. (My compiler
supports in-line assembler which I hope will prove usefull). I will be very
gratefull for any help or pointers with this problem. I am conversant with the
x86 architecture, so an example from one of these platforms would probably be
illuminating as well.
John Ferguson

Having done that for the x86 architecture the principle is as follows:
1: You need a buffer large enough to hold all registers.
2: setjump saves all registers into that buffer
3: longjmp restores all registers from the buffer

Now, you should take care with the return and the result.
In setjmp, save the return address in the buffer. Return zero.
In longjmp, after restoring all registers (without restoring the
instruction pointer of course) set the result register to 1,
and jump to the saved return address instead of returning from the
procedure.

Looks simple but it isn't.

Good luck.

Jacob
Nov 14 '05 #4

P: n/a
In <cl**********@news1brm.Central.Sun.COM> Eric Sosman <er*********@sun.com> writes:
control. If setjmp() and longjmp() are absent, I'd suggest
you look long and hard for a suitable implementation that
provides them before undertaking to add them yourself. The
widely-available gcc compiler supports various M68K-based
systems, and it might well be easier to switch than fight.


I have news for you: gcc is *not* a complete implementation; it is missing
*exactly* the part the OP needs: the standard C library. No point in
directing the OP to another compiler without what he needs.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Currently looking for a job in the European Union
Nov 14 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.