I know that my question is a little bit off any topic here, but I want to write a program which can be run with no operating system at all. This process should run in a protected mode and have a single thread only. I want to write it in C (using some ANSI functions from the runtime library) and partially in ASM. This process should also run on Windows (Linux might seem a better option, but I need it to be Windows) , so it can be debugged.
Can anyone here suggest me something? I mean what C compiler should I use. I suppose I need a compiler which doesn't add some specific startup code. And C library should link statically with no special initialization.
Posted on 2003-07-13 15:52:34 by Vaxon

...This process should run in a protected mode...


Small suggestion: don't forget before loading operating system from a disc is computer (IBM-PC) preseted in real mode, 16-bit operands size and memory access size (like under old MS-DOS). So whatever coding is very different opposite Win32 programming...
Posted on 2003-07-13 17:30:25 by MazeGen
what kind of process is this?

i'm doing os-development without any (good) debugging-ablilities. if there's a specific piece of code i rewrite it in win32 and test just this routine. then i can debug it with softice.
other suggestion: if you write your code in 16 bit mode but use 32-bit operands (i.e. use the directive use32 ( in nasm)) you can write into a .com file wich can be executed in a dosbox and be debugged (with softice).
Posted on 2003-07-14 14:37:31 by hartyl
This process works with memory and some specific harware a lot. The reason it should be 32-bit is that the data and code exceeds 1MB. COM files can't be larger than 64 kB as I recall. I wanted to make some kind of a simple boot loader in a COM file, which initializes hardware and switches to protected mode. Than I wanted to make the main 32-bit process, the loader should load into memory and give control to. I want this process to work on the Windows system also, so it can be debugged there.
Posted on 2003-07-14 16:19:18 by Vaxon
Well... here's an idea. The very first thing to do in your boot sector is to load some more sectors. Set up paging and protected mode. The first 4MB should be mapped to address 0. This can be done easily by setting the first page directory entry to 87h. Call BIOS in V86 mode to read the next 2 sectors. This could be the beginning of a PE file. Load the sections described in the header at consecutive addresses, skipping addresses A0000h-100000h. Now set up a page directory for the 400000h-7ff000h region. Set it to point to the program you loaded, taking account the skip at A0000h. Now if this PE file has the image base set to 0x400000, you only have to call the entry point. There are no relocations to worry about.
If you write the program in C, just make sure you define your own entry point and don't use the library's entry point, and don't use any functions that might call system functions (such as malloc, printf, etc). If you want to be fancy, you could implement some functions such as for printing on the screen. Then you could just call OutputDebugString or something like that in the PE program, and it would work in both systems.
Posted on 2003-07-14 22:02:54 by Sephiroth3
The problem seems to be two fold. Each part is solvable independently...

1. Program to load from boot - enter protected mode and function...

* Program must handle everything: reading files, updating screen, shutting down.

2. program must run in win32 - already in protected mode

* Operating system handles everything.

Therefore you must have separate boot strap to load program (if from cold start). Program must determine whether it is running in win32 (linux etc). If win32, then each operation must jump (possibly table jump) to win32 code otherwise jump to self-sufficient code.
Posted on 2003-07-14 23:20:44 by V Coder