Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have read that the executable file contains some information for the operating system to use before running it. rest it is like any other independent application just using the services of the operating system.
 
my question is that if the compilers generate code dependent on the operating system we are using, then how can we use that compiler to make altogether new operating system from scratch.
 
Yes we can use assemble language but we just can't write the whole coding in assembly language.
 
Please tell me if i am wrong somewhere (or even worst 'everywhere'). Help....
Thanks
Posted 23-Jun-12 19:36pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

When a PC is statered it goes through a boot sequence, and at the end it is able to locate a boot sector on a bootable device, such as a hard disk. Whatever is found there gets loaded into memory by the bios. Then the bios transfers execution to whatever it loaded into memory.
 
This[^] describes how Windows does it, and here is a description of the linux startup process[^].
 
What we call programs, are, as Vitaly mentions, files that are written in a specific file format - usually created by a linker - and the boot loader needs to be able to load and execute files written in the choosen format.
 
Back in the days of 16-bit MS-DOS, compilers and linkers where able to output executable files in something that was called the com format, a simple executable format with no header - the program entry point, that is the first instruction the program was to perform, was located right at the beginning of the file - ideal for writing a simple boot loader.
 
[Update]
The process is detailed here:
How to develop your own Boot Loader[^] - isn't CP wonderful Smile | :)
 
Best regards
Espen Harlinn
  Permalink  
v3
Comments
Vitaly Tomilov at 24-Jun-12 6:36am
   
Correction: COM format wasn't that ideal for a boot loader, because of the starting address in the beginning that it came with. When I tried to use it as boot loader, I found it wasn't easier than EXE, for you just need to specify the exact starting address and size of the block to write into the boot, which made no difference between COM and EXE. Oh, those days with assembler :) COM Format.
P.S. This is just for fun :)
Espen Harlinn at 24-Jun-12 6:42am
   
It's been a few years, but it appears that we dabbled at OS development at the same time ... :)
suvam8694 at 24-Jun-12 10:20am
   
Thanks a lot sir, it is exactly what i needed.
Espen Harlinn at 24-Jun-12 10:24am
   
That's great - you are venturing into a strange and wonderful territory, my best wishes for your effort :-D
 
I didn't know much the first time I tried my hand at this, but I certainly learned a lot that's been pretty useful over the years ...
suvam8694 at 25-Jun-12 3:28am
   
Thank You!!!
CIDev at 25-Jun-12 9:47am
   
Good info, +5
Espen Harlinn at 26-Jun-12 14:53pm
   
Thank you, CIDev :-D
Sandeep Mewara at 26-Jun-12 14:06pm
   
Good answer 5!
Espen Harlinn at 26-Jun-12 14:53pm
   
Thank you, Sandeep :-D
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

EXE files, just like any other binary file, contain a header with information in it specific to the file. Here's the EXE file header on Windows[^]
 
When a high-level compiler is used, rather than assembler, it sets the starting point to additional initialization logic, like dependencies and standard libraries' initialization. Read this[^] to understand it better.
 
Some languages, however, like C++, allow overriding that initialization, or at least in part. In VC++, for instance, there are many pragma and __declspec modifiers that allow custom compiler and/or linker behavior, plus many project configuration switches.
 
We absolutely can, and people do write the whole thing in assembler. In fact, back in 1993 I personally wrote a whole mini OS for 286 just in TASM, as an academical exercise. It was booting off a floppy drive, initialized DPMI, with basic memory management and UI.
 
However, today this cannot be a recommended approach. Only specific parts these days are written in assembler, while most of OS is written in ANSI C, though considering the progress, one can already find OS kernels written in C++, which is perhaps acceptable in some cases. But hey, who am I to judge them - look at guys writing OS in .NET: Develop Your Own Operating System in C# or VB.NET[^]. I personally think that's just crazy, but that's me.
 
There are some good tutorials out there on how to get started with your own OS in C, even on this forum: Building your own operating system[^] Wink | ;)
  Permalink  
v6
Comments
Espen Harlinn at 24-Jun-12 6:22am
   
5'ed!
SoMad at 24-Jun-12 6:40am
   
Good answer, +5.
 
Soren Madsen
Ashish Tyagi 40 at 25-Jun-12 3:33am
   
Good one, my 5.
CIDev at 25-Jun-12 9:47am
   
Good answer, +5
Sandeep Mewara at 26-Jun-12 14:05pm
   
Good answer 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

That is the reason we have platform independent framework like Java and .NET.
 
Java solves the problem of platform-independence by using byte code. The Java compiler does not produce native executable code for a particular machine like a C compiler would. Instead it produces a special format called byte code. Java byte code written in hexadecimal, byte by byte, looks like this:
CA FE BA BE 00 03 00 2D 00 3E 08 00 3B 08 00 01 08 00 20 08
 
This looks a lot like machine language, but unlike machine language Java byte code is exactly the same on every platform. This byte code fragment means the same thing on a Solaris workstation as it does on a Macintosh PowerBook. Java programs that have been compiled into byte code still need an interpreter to execute them on any given platform.
 
The interpreter reads the byte code and translates it into the native language of the host machine on the fly. The most common such interpreter is Sun's program java. Since the byte code is completely platform independent, only the interpreter and a few native libraries need to be ported to get Java to run on a new computer or operating system. The rest of the runtime environment including the compiler and most of the class libraries are written in Java.
 
Hope, it clarifies.
  Permalink  
Comments
suvam8694 at 24-Jun-12 4:50am
   
It was helpful but what that basically means is that if i want to make my own Operating System then i would need a pre-installed JVM or .Net framework.
Linux is has most of its kernel code written in C. what about it? what compiled that source code to make it independent of OS and in fact made it an OS itself.
Vitaly Tomilov at 24-Jun-12 5:48am
   
One only wonders - what does it have to do with writing an OS or EXE header, which was asked?
Espen Harlinn at 24-Jun-12 6:21am
   
I did not downvote your answer, but please reread the question. This may be an answer to something, but it has no relation to this question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 430
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 24 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100