NO

Author Topic: This might be a C question, but I'm not too sure  (Read 4448 times)

codez1

  • Guest
This might be a C question, but I'm not too sure
« on: September 14, 2011, 09:56:43 PM »
Is it possible to write a program in C that boots from the bios. I'm not referring to operating system programming, but instead, binary code that executes at boot. I understand in asm there are jumps and calls and bios interrupts that allow you to use the bios to do this. Can you for example compile a C program from Pelles C to do this. How much asm or inline asm would be necessary.

If you can answer the next question it would help.

How can i write to sepcific areas of the disk from a C program. For example theboot sector. I have 2 hard drives, one is empty. How could I write code to the boot sector of that hard drive. Is this possible without literally having to send a stream of binary data.

One more - are there libraries out there, graphics libraries that someone can use without an os and its facilities.

The project would be this. Start computer load a demo and jump to boot the operating system. Simple project, but difficult to get the right info on how much asm is necessary and what you can do with C.
« Last Edit: September 14, 2011, 09:58:29 PM by codez1 »

CommonTater

  • Guest
Re: This might be a C question, but I'm not too sure
« Reply #1 on: September 14, 2011, 11:24:03 PM »
Ok, right up front I don't know how to do any of those things...

BUT, I do want to throw in a word of caution about it... It's almost certain any decent virus scanner would detect your software as a "Root Kit"... and may cause you a lot of problems trying to get it to run.  Trusting that your software is not for nefarious purposes... I'd suggest you find a different way to get your demo to run.



Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: This might be a C question, but I'm not too sure
« Reply #2 on: September 15, 2011, 08:14:07 AM »
Take a look at the source code of ReactOS, since all your questions are in one way or the other tasks of an O/S.

Even if you don't want to build an O/S, you like to run without an O/S, which implies building an O/S.
---
Stefan

Proud member of the UltraDefrag Development Team

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: This might be a C question, but I'm not too sure
« Reply #3 on: September 15, 2011, 10:39:45 AM »
The answer is YES you can (look at my demo OS), but it requires a lot of knowledge.
The PE executable format is ready to run starting at the absolute location specified with the linker switch /BASE. Using the switch /SUBSYSTEM:NATIVE you can link your executable without any system library.
The switch /ENTRY allows you to define a start code entry point, but this address is only write in the PE header, without an underlying OS there is no automatic system to start your code. The most used technique is to "touch" your executable replacing the first bytes (and overwriting the PE header) with a small code that reads that start address and then jumps to it.
Up to here is the simple part. Now comes the difficult:
- The BIOS bootstrap loads just few sectors of disk in the specific area. You have to study the booting mechanism.
- The BIOS starts in X86 real mode, 16 bits segmented. The pellesC can compile only 32bits code. You have to switch the processor mode to use C, or program only in assembler. Setup the main memory pointers: stack, interrupts, etc.
- Switching the processor requires memory management (BIOS doesn't have any memory management, unless a minimal support for segmented code) and hardware management (errors etc.)
- BIOS support for video is minimal, no graphical support. You have to deal with video chip registers.
- Disk access in BIOS is limited to sectors access, no file system support. You have to write a file system code (driver) to access data.

In other words many hours of study and work without any debugger because there is no OS to handle debugging.

Another solution is to use one of the many open OS loaders that you can find around (LILO, GRUB) and hack them.
Good luck
« Last Edit: September 15, 2011, 10:47:35 AM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide