0

I am trying to create a DOS-like OS. I have read multiple articles, read multiple books (I even paid a lifetime subscription for O'Reilly Media), but to no avail, I found nothing useful. I want to learn how to make operating system libraries, which rises the question which is: are libraries which you code for a program the same if you are compiling it for an operating system?

I know Operating Systems are very challenging to make and the very few programmers that do attempt to make one never produce a functioning one which is why it's described as "the great pinnacle of programming.". But still, I'm going to make an attempt at making one (just for fun, and maybe learn a few pointers on the way).

All I need to do this is basically learning how to make the libraries, C (which I already know and love), assembly (which I kind-of know how to use along with C) and a compiler (I use the GNU toolchain). The only thing I am having trouble with are coding the libraries. I'm like wow right now, who knew that coding libraries are so hard, like point me to a book or something! But no. I'm not asking for a book right here, all I'm asking for is some advice on how to do this like:

  • How do you start making some basic I/O libraries

  • Is it the same as making a regular C library

  • And finally, is it going to be hard? (JK I know already that this is going to be extremely hard which is why I prepared so much)

In summary, the main question is, how I can make this work or is there a pre-built library that would most likely speed up the process?

halfer
  • 19,824
  • 17
  • 99
  • 186
Joe
  • 415
  • 1
  • 5
  • 15
  • 2
    Don't try it. It's boring and difficult. I tried it once and I doubt I'll ever complete mine. I/O is extremely difficult without low-level knowledge and knocking out a whole bunch of other stuff like the interrupt handler first. A C library is a piece of cake compared to this. Even a standard C library is. – S.S. Anne Oct 12 '19 at 23:25
  • 1
    Writing some of the basic I/O libraries requires first understanding how the information is stored on the disks. Then I believe there is usually some way of accessing the information through the BIOS chip. So this will be platform dependent (?), I'd recommend developing with some emulator like QEMU – avlec Oct 12 '19 at 23:26
  • 1
    I'd give this a look as it has some good information and I think covers what you'd be interested in https://github.com/cfenollosa/os-tutorial – avlec Oct 12 '19 at 23:26
  • My main take-away from my undergraduate classes on operating-system design was "here's how we did it in the past and here's how we do it now; never do it yourself or you'll repeat the same mistakes we did" – Dai Oct 12 '19 at 23:35
  • 3
    @AlecC BIOS is a nasty, and obsolete x86 abomination. There is not an equivalent in ARM SoCs. I don't think it's a given that UEFI provides a BIOS compatibility mode or any IO services for the operating system to use any more. Any operating system will be enumerating hardware and interacting with devices directly. This is distinctly non-trivial. – marko Oct 12 '19 at 23:40
  • 1
    `FreeDOS` is a DOS-compatible open source OS written partially in `C`. It probably contains some `C` libraries to look at – xmojmr Oct 14 '19 at 06:06

1 Answers1

1

Are libraries which you code for a program the same if you are compiling it for an operating system?

Absolutely not. A user-space C library at its lowest level makes system calls to an operating system to interact with hardware via device drivers; it is the device driver and interaction with hardware you will be writing.

From my experience doing embedded system bringups, the way you start is with a development board with a legacy RS-232 port. It's about the easiest possible device to write a driver for - you write bytes to a memory mapped IO address, wait a bit then write some more. This is where your first debug output goes too.

You might find yourself waggling IO pins and probing them with a logic analyser or DSO on the route to this though - hence why you want a development board where the signals are accessible.

None of the standard C-library will be available to you - so you'll need to equivalents of some of things it provides - but in kernel space - including type definitions, memory management, and intrinsics the compiler expects - particularly those for memory barriers. The C-library doesn't provide any data structures or algorithms anyway, but you'll definitely be wanting to write some early on.

marko
  • 9,029
  • 4
  • 30
  • 46