linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "John T. Williams" <jowillia@vt.edu>
To: kaushal <kaushal@rocsys.com>
Cc: linux-c-programming <linux-c-programming@vger.kernel.org>
Subject: Re: Boot code in C
Date: Mon, 05 Jul 2004 13:36:05 -0400	[thread overview]
Message-ID: <1089048965.8347.16.camel@localhost> (raw)
In-Reply-To: <1089035369.7299.48.camel@kaushal>

there are a couple of issues involved.
1.  when you compile C programs they are linked against the at least the
C library on your computer.  You can take care of that by using the
-static directive with either the linker or the gcc, but you have to
have already installed the static version all libraries you link
against. which you can find out using the ldd tool
2.  System calls are part of The OS, so if you want a program to execute
w/o first loading the kernel, you can't make any system calls.  This
includes every input output function that I know of.  
3.  you need a boot loader.  The BIOS will load the bootsector of a
floppy into memory, and if your program is small enough to fit in the
boot sector, then you have no problem, otherwise you have to write code
to open your disk's filesystem, find your program, load it into memory
and then start executing it.  

In short, if you really want a program which runs off a floppy, and does
anything useful, you need to learn a little assembly.

	



On Mon, 2004-07-05 at 09:49, kaushal wrote:
> Hello  all,
>           I want to know if there is a way to  generate a binary file,
> from  a C program(Not from an assembly code)(can use any Linux
> tools)that can be burned on to a floppy and which ,say--  just prints a
> string on to the screen.
> I tried out to the following:
> 
> 
> 1.[kaushal@linuxbox]#cc Hello.c -static -o Hello
>   [kaushal@linuxbox]#strip Hello
>   [kaushal@linuxbox]#objcopy -O binary Hello Hello.bin
>   [kaushal@linuxbox]#dd if=Hello.bin of=/dev/floppy
> 
> 
> 2.[kaushal@linuxbox]#cc Hello.c -S 
>   [kaushal@linuxbox]#as Hello.s -o Hello
>   [kaushal@linuxbox]#strip Hello
>   [kaushal@linuxbox]#objcopy -O binary Hello Hello.bin
>   [kaushal@linuxbox]#dd if=Hello.bin of=/dev/floppy
> 
> In the second case (2.)(Even if I don't give a "-static" switch for the
> first one(1.)) the Hello size is MUCH less than its counterpart of case
> (1.)
> Either way it did not work.I think the problem occurs because of absence
> of OS at boot time.So is there any way of atleast generating the
> required assembly code from the C code(The optimised one).
> 
> 
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  reply	other threads:[~2004-07-05 17:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-05 13:49 Boot code in C kaushal
2004-07-05 17:36 ` John T. Williams [this message]
2004-07-06  5:26 ` Progga
2004-12-11  7:15   ` itmncm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1089048965.8347.16.camel@localhost \
    --to=jowillia@vt.edu \
    --cc=jtwilliams@vt.edu \
    --cc=kaushal@rocsys.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).