Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.development > #9553

Re: Questions about the Implementation of the ELF format

From "Mike Gonta" <mikegonta@gmail.com>
Newsgroups alt.os.development
Subject Re: Questions about the Implementation of the ELF format
Date 2016-05-24 10:34 -0400
Organization Aioe.org NNTP Server
Message-ID <ni1op3$1ndv$1@gioia.aioe.org> (permalink)
References <06b38764-b3ee-4eed-9b82-f62c1d68b0ec@googlegroups.com>

Show all headers | View raw


"Isaac D. Cohen" wrote:
> I’m trying to figure out how to include C/C++ in my
> operating system. So I googled around and found that I
> have to cross-compile the C/C++ file into some kind of
> format, for example ELF. So my first question is, why? Why
> can’t the compiler just generate plain binary files?

If you want to use GCC on Windows - that's the way it is.

> Anyway, I quickly realized that I’m going to have to learn
> all about ELFs, ....

No need to if you're going to generate a flat binary file.
Simple link the object files and specify:

OUTPUT_FORMAT("binary")

in the linker file.

> because otherwise, I won’t know how to jump into the
> executable from an assembly file in my OS.

Simply link with the asm object file and include a jmp or
call to the function name used in the "C" file.
Another simple technique to use when running a loaded flat
binary from the OS is to call the beginning address of the
loaded file. In this case since you can never be sure of
where the actually address of the "main" function will be in
the actual binary simply put an inline asm statement at the
end of a "#include"d file:

  __asm__ ("jmp main");

and the linker will take care of the rest.
Also, for example, if you load the the file to (for example)
0x400000, you can call it from "C" in the OS loader with:

  ((int (*)(void ))0x400000)();

(with the appropriate return type and parameters).


Mike Gonta
look and see - many look but few see

http://mikegonta.com
http://tawk.to/mikegonta

Back to alt.os.development | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-23 22:07 -0700
  Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-24 03:48 -0400
  Questions about the Implementation of the ELF format Peter Cheung <mcheung63@gmail.com> - 2016-05-24 01:10 -0700
  Re: Questions about the Implementation of the ELF format "Alexei A. Frounze" <alexfrunews@gmail.com> - 2016-05-24 01:18 -0700
  Re: Questions about the Implementation of the ELF format "Mike Gonta" <mikegonta@gmail.com> - 2016-05-24 10:34 -0400
  Re: Questions about the Implementation of the ELF format Herbert Kleebauer <klee@unibwm.de> - 2016-05-24 17:24 +0200
  Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-24 14:18 -0700
    Re: Questions about the Implementation of the ELF format "Alexei A. Frounze" <alexfrunews@gmail.com> - 2016-05-25 02:21 -0700
  Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-25 15:02 -0700
    Re: Questions about the Implementation of the ELF format "Mike Gonta" <mikegonta@gmail.com> - 2016-05-25 19:03 -0400
      Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-26 14:51 -0700
        Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-27 02:55 -0400
          Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-27 13:43 -0700
            Re: Questions about the Implementation of the ELF format "Mike Gonta" <mikegonta@gmail.com> - 2016-05-27 17:40 -0400
              Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-05-28 20:15 -0700
                Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-29 02:35 -0400
                Re: Questions about the Implementation of the ELF format "Isaac D. Cohen" <8switchsoftware@gmail.com> - 2016-06-15 13:51 -0700
        Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-27 03:09 -0400
        Re: Questions about the Implementation of the ELF format "Alexei A. Frounze" <alexfrunews@gmail.com> - 2016-05-27 00:10 -0700
        Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-06-02 16:25 -0400
      Re: Questions about the Implementation of the ELF format Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-05-27 02:38 -0400
        Re: Questions about the Implementation of the ELF format "Mike Gonta" <mikegonta@gmail.com> - 2016-05-27 04:11 -0400
    Re: Questions about the Implementation of the ELF format "Alexei A. Frounze" <alexfrunews@gmail.com> - 2016-05-25 22:18 -0700

csiph-web