473,777 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A bit off topic; setjmp/longjmp

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
4 2126
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
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 "freestandi ng" 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
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
In <cl**********@n ews1brm.Central .Sun.COM> Eric Sosman <er*********@su n.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2296
by: Thomas Baruchel | last post by:
Hi, wondering about: func1: setjmp() ; func2(); func2: {FILE *f; f = fopen(); func3(); fclose(f)} func3 : if() longjmp; else return; Note that FILE *fis a local variable in func2.
6
4857
by: someone | last post by:
I have *thought* that setjmp/longjmp() should take a pointer to jmp_buf. And the calling function should hold the actual struct data. But ... I trid on both Win32 and Linux, it seems that setjmp/longjmp() are taking stuct: c:\> dmc sj.c (Digital Mars Compiler Version 8.38n) link sj,,,user32+kernel32/noi; c:\> sj.exe sizeof(jmp_buf) = 64 ----------------------------------------------------------------- sj.c
12
3330
by: Michael B Allen | last post by:
Should setjmp/longjmp really be used in a fast mundane ANSI C piece of code? Or is it frowned apon like goto? I have a need but I don't want to use something that is costly, isn't supported consistenly, or something that might pull in exotic text segments, etc. Specifically I have a hairly algorithm loop that uses what is currently a macro V. Here's a snipplet: for (k = d; k >= -d; k -= 2) { if (k == -d || (k != d && V(fwd, m, k - 1)...
5
1875
by: candy | last post by:
hi all, Consider the following C code: void funct(){ }
20
2324
by: JS | last post by:
When setjmp is called how can the if statement evaluate to true or false when setjmp only returns 0 or non-zero? struct pcb { void *(*start_routine) (void *); void *arg; jmp_buf state; int stack; };
4
7564
by: Sreekanth | last post by:
Hi All I am trying to write a code in which I have to access an array of jmp_buf so i have declared it as jmp_buf mybuf Now when i am doing a longjmp like
15
2432
by: rover8898 | last post by:
Hello all, I used setjmp() in a recent of program of mine (it is not completed, so I have not the chance to test it out yet). I am not very profocient in C coding as are some of my co-workers. They (my co-workers) say (with vehement ardor ;) ) that the usage of setjmp() emplyoyed in function"C" that was called from function "B" that was called from function "A" that was called form the main(), will cause havoc in the stack. And it makes...
4
1359
by: nicho | last post by:
Could some knowledgable soul tell me if the following setjmp/longjmp structure will work from a logical standpoint ? The problem is that bar() needs to suspend processing and return control to foo() but save it's current spot so that foo() can call bar() and have it pick up where it left off. I'm fairly certain that bar() can longjmp to foo(), but I'm uncertain as to whether foo() can then longjmp back to bar(). Thanks in advance for any...
3
1898
by: no_click_there | last post by:
Hi, I'm learning to use the setjmp/longjmp functions and still can't really grasp what's going on here. I'd basically like to be able to jump back and forth from (or to) two given functions. Let's consider the following toy-example (yes, the example is stupid but never mind...) BEGIN CODE =====================
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10122
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8954
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.