boot2c - a simple way to write standalone programs for i386

This forums is for OS project announcements including project openings, new releases, update notices, test requests, and job openings (both paying and volunteer).
Post Reply
luke64
Posts: 3
Joined: Wed Jun 17, 2015 4:05 pm

boot2c - a simple way to write standalone programs for i386

Post by luke64 »

Hi there,

I was recently wondering how hard would it be to run C programs on i386 without an OS, and created a GitHub repo to share my approach. I traded portability for simplicity, so it's not the most correct way, but maybe someone will find it useful:

https://github.com/luke8086/boot2c

Any feedback will be appreciated!
User avatar
iansjack
Member
Member
Posts: 4688
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: boot2c - a simple way to write standalone programs for i

Post by iansjack »

You ask in your readme.md
So why bother doing such a thing in 2019?
I've got to agree - why, when it is so simple to produce bootable DOS media which would allow you access to more facilities?
luke64
Posts: 3
Joined: Wed Jun 17, 2015 4:05 pm

Re: boot2c - a simple way to write standalone programs for i

Post by luke64 »

I've got to agree - why, when it is so simple to produce bootable DOS media which would allow you access to more facilities?
Well, the whole premise was not to use any operating system.
User avatar
bzt
Member
Member
Posts: 1584
Joined: Thu Oct 13, 2016 4:55 pm
Contact:

Re: boot2c - a simple way to write standalone programs for i

Post by bzt »

Hi,
luke64 wrote:I was recently wondering how hard would it be to run C programs on i386 without an OS
Are you familiar with Bellard's Tiny C compiler? It is capable of compiling and running C programs in memory (no disks involved). It is perfectly valid to do some script like this under Linux:

Code: Select all

#!/usr/local/bin/tcc -run
#include <stdio.h>

int main() 
{
    printf("Hello World\n");
    return 0;
}
Using this feature you can truly boot a C program directly, compiled at boot time. However you'll need to integrate a minimal libc at least.

Cheers,
bzt
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: boot2c - a simple way to write standalone programs for i

Post by alexfru »

Or Smaller C + e.g. BootProg (or FreeDOS).
Unreal mode is supported by the compiler.
User avatar
eekee
Member
Member
Posts: 872
Joined: Mon May 22, 2017 5:56 am
Location: Kerbin
Discord: eekee
Contact:

Re: boot2c - a simple way to write standalone programs for i

Post by eekee »

luke64 wrote:I was recently wondering how hard would it be to run C programs on i386 without an OS, and created a GitHub repo to share my approach. I traded portability for simplicity, so it's not the most correct way, but maybe someone will find it useful:
If I was writing my OS in C, I'd almost be interested. :) I wouldn't because I'm not so keen on gcc & clang. I'd rather use Watcom or bcc which takes away the fun for you because they can do this already. Or I guess Smaller C, which is evidently better than bcc and might be better than Watcom for making bootable images. I'm a bit impressed by the build process producing a USB boot image, USB boot is a bit difficult. Char-cell snake gives me retro feels. :) If you add editing and search to hexview, it could be a useful debugging tool for native OSdev. Especially regexp search; could you just link in a suitable library?
Kaph — a modular OS intended to be easy and fun to administer and code for.
"May wisdom, fun, and the greater good shine forth in all your work." — Leo Brodie
Post Reply