473,795 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a standalone C program?

How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.

Thanks!

Jul 31 '07 #1
7 6564
dspfun wrote:
How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.

Thanks!
You should probably ask this question in a group for your system. Generally,
some amount of native assembler code will be required to set up the
environment that C expects. Also you'll have to find some way to make your
system's firmware load your program into memory and pass control to it. The
details are completely system specific and off-topic for this group. Also
you need to take special steps to compile your program as a freestanding
one. In the process you'll lose access to most functions of the Standard
library, and might have to implement your own replacements.

I suggest the following groups:

alt.lang.asm, comp.lang.asm.x 86 and alt.os.develope ment.

Though your question is not exactly topical for any of the above groups,
they might be able to answer your question better, since they can discuss
system specific topics.

Jul 31 '07 #2
santosh <sa*********@gm ail.comwrites:
[...]
I suggest the following groups:

alt.lang.asm, comp.lang.asm.x 86 and alt.os.develope ment.

Though your question is not exactly topical for any of the above groups,
they might be able to answer your question better, since they can discuss
system specific topics.
or perhaps comp.arch.embed ded, but check its archives and FAQ first.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 31 '07 #3
On Jul 31, 12:08 pm, dspfun <dsp...@hotmail .comwrote:
How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.

Thanks!
This might be of interest to you (although in assembly):
http://www.omninerd.com/2005/11/05/articles/40

Aug 1 '07 #4
dspfun wrote:
How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.

Thanks!
A freestanding *C program* is not really different from a hosted C
program, except that the standard guarantees the existence of only a
small subset of the library functions; your compiler may but doesn't
have to provide more. (There are details like main() but that's beside
the point.)

A true difference comes from how the program is built as an executable.
1. There is magic that starts your program
2. There is magic that creates the C runtime environment once the
program starts
3. There is an implementation of the (available) library functions,
notably I/O and malloc if available.

In many cases, those things come with a compiler capable of or dedicated
to making freestanding applications /of some sort/.

If e.g. you are writing code for a dishwasher, the #1 magic must start
from the CPU reset (which starts your program), which also means your
program must be linked at an absolute address.

If you are writing PC BIOS extension, you can rely on your program being
started by BIOS scan, by which time some basic BIOS services may become
available.

If you convince your OS loader that your program is the default command
shell, you probably have everything the OS provides, except system().

So scenarios vary depending on the level of abstraction from the hardware

-- Ark
Aug 1 '07 #5
On Jul 31, 12:08 pm, dspfun <dsp...@hotmail .comwrote:
How do you create a standalone C program? With standalone C program I
mean it should run "freestandi ng" on a CPU without an OS or other
supporting software/libraries linked to the C program. After the bios/
setup has done its initializations and "stuff" I would like to be able
to continue execution with my own C program. The C program will be
really simple to start with, for example just write an integer value
to a memory address.

Thanks!
These might be of interest to you:
http://www.omninerd.com/2005/11/05/articles/40
http://en.literateprograms.org/Hello...M_PC_bootstrap)

Aug 1 '07 #6
Ark Khasin wrote:
>
.... snip ...
>
If you convince your OS loader that your program is the default command
shell, you probably have everything the OS provides, except system().
Including system(), which just returns a failure indicator, as
specified in the standard.

--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net

--
Posted via a free Usenet account from http://www.teranews.com

Aug 2 '07 #7
On Mon, 13 Aug 2007 07:38:54 -0700, in comp.lang.c , dspfun
<ds****@hotmail .comwrote:
>What I meant with standalone is the same as "freestandi ng" mentioned
in the C standard.
A freestanding implementation is normally one that runs on embedded
hardware such as the chip inside a car engine management system or
mobile phone. You would need specific cross-compilation tools for that
hardware3.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 13 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1359
by: Joe Turner | last post by:
We recently got visual studio .net 2003 for our school. I have installed on networked computers in the classroom as well as a standalone. All are running windows 2000 with service pack 4. The standalone has no problem what so ever creating asp web pages. The networked computers just freeze for a minute and then say cannot locate the local server and lists the temp directory. I have repaired the .net framework as well as registred the...
2
9104
by: David Elliott | last post by:
I can create this: ?xml version="1.0" standalone="yes" ?> <ConfigOpt> <record> <Field_1>Text # 1</Field_1> <Field_2>Text # 2</Field_2> </record> </ConfigOpt>
11
3076
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read files on Windows domain network shared drives and also on shared via Samba Unix drives, which is equivalent to writing/reading to the workgroup computer. Please point, if possible, to detailed step by step description of what needs to be done. Thank...
2
2366
by: JohnR | last post by:
Hi all. In my program I try to handle all obvious potential errors with structured error handling (try-catch) block. What I would like to do is have an 'overall' error handler that would gracefully catch any unanticipated errors. I created a startup module to place my overall error handling for my "real" program which is Form1. My program is structured like this: Module startup
4
3405
by: Paul | last post by:
Hi, I am developing a c# windows .NET application. The application is going to run on a standalone PC and use an access database. I have figured out that I will need to create a project and add it to the custom actions of the my setup project to create the database. How do I create the database and then add a table using C#? Also, should I use an odbc data adapter, which I usually use with Access and if so how do I register the new...
4
2072
by: comp.lang.php | last post by:
I downloaded the tarball and while was able to compile within PHP with no problems, I am having memory timeout issues involving image manipulation with extremely large images (800K - 2mb). Requirements are to create thumbnails for even these banner-sized images, but PHP + GD + = too much memory. I'm trying to prove that it is undoable, though the suggestion was to do a command-line GD call to the image instead of using the PHP...
7
11667
by: tah | last post by:
Hey, Can someone please clarify, confirm, or set me straight on my understanding of a standalone="yes" attribute in the xml version element? I assume it means that the xml document containing it is standalone, and does not refer to any external document to define types. In other words, it doesn't use an external dtd to validate any types - everything used would be defined within the doc itself. In other words, you would never see an xml...
4
1802
by: keo982 | last post by:
Hello guys, hope one of you may help. I am trying to find a way of executing a standalone c++ program from the dos window. i have tried to type programname.exe but with no results. am i mistyping it or is there another way of doing it... Any help would be appreciated. PS. It is a standalone program. so no installation was required. simply had to drop the folder on my system. many thanks
11
2009
by: caine | last post by:
I'm currently working on creating the xml feed since I had data ready in my database after web data extraction. However, it has errors for this line: <xml version="1.0" encoding="ISO-8859-1"> I was unable to solve this. <html> <head>
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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
10216
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...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
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
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
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.