Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A bit off topic; setjmp/longjmp

Reply
Thread Tools

A bit off topic; setjmp/longjmp

 
 
Jrferguson
Guest
Posts: n/a
 
      10-29-2004
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

 
Reply With Quote
 
 
 
 
E. Robert Tisdale
Guest
Posts: n/a
 
      10-29-2004
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?
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      10-29-2004
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 ...

--
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      10-29-2004
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
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      11-02-2004
In <clu7iv$fsd$(E-Mail Removed)> Eric Sosman <(E-Mail Removed)> 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: (E-Mail Removed)
Currently looking for a job in the European Union
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Reversing Bit Order.. i.e. MSB becomes bit 0, LSB becomes bit 15 benn686@hotmail.com C++ 9 08-22-2007 12:13 AM
"LoadLibrary" of a 32 bit so with 64 bit java on a 64 bit machine markryde@gmail.com Java 3 01-19-2007 10:30 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments