1

I have some very specific questions about writing operating systems that I was hoping could get answered:

  1. How much assembly code would I need to write to load a minimal C Kernel if I use GRUB as a boot loader?

  2. My kernel will be written in C, It will load a command line shell that I wrote in C++, it does not make any API calls only standard library calls, will I need to rewrite the entire C++ Standard library to do so?

  3. Can I write video, keyboard and floppy drivers in C++?

  4. Do GCC and G++ output 16 bit real mode code?

  5. Can I write this all using Mingw on Windows or will I have to write it on Linux?

  6. Do I need to be in real mode in order to write directly to the video memory?

If anyone can answer my questions I will be very thankful

PgrAm
  • 671
  • 2
  • 7
  • 19
  • 1
    whoa! An entire Operating system? looks like we are talking about a few years of effort here! – Alok Save Sep 17 '11 at 17:14
  • 3
    http://wiki.osdev.org/Main_Page has the answer to all your questions. – user786653 Sep 17 '11 at 17:14
  • 2 things, one have you ever modified an OS before? If not, you may just want to start off with that. Grab a linux distro and modify some stuff, see how it works. Second about 5, I've done a bunch of programming stuff from mingw in windows and besides a few times where i need some files, i have never had a problem. My suggestion though is just to install a virtual machine in case you do need, plus you can test your OS. Virtualbox is pretty nice and it's free. – Matt Sep 17 '11 at 17:17
  • 2
    @Matt I don't agree with that. The linux distro is orders of orders of magnitudes more complex than what you need to get a trivial kernel up and running. Personally it's much more helpful to look at the Linux 0.1 sources (nice history lesson at that as well). – Voo Sep 17 '11 at 18:17
  • @Voo, True, but i was thinking about more of the smaller distros like busy box or damn small linux, just to see how some of the workings actually work. Then just modify something and see if it works. This is how i learned how an OS can work. May not work for everyone, but doing and trying helped me. – Matt Sep 17 '11 at 20:46
  • Better still, Minix 1. That was written to be educational, and still is. Tannenbaum's polished minimal effort would make more sense than alpha-linux, I expect. – Nicholas Wilson Sep 17 '11 at 20:53
  • @Matt I was thinking of the complete linux kernel, don't know much about what the distros you mentioned now use. If you can find a small and simple enough kernel that may be interesting - probably comes down to personal preferences. I like building everything from ground up, but it certainly needs quite some low level knowledge (and you still spend lots of time in Intel manuals) so that may be a good alternative, especially if one just wants to see how all this works (or doesn't want to do all the tedious groundwork) – Voo Sep 17 '11 at 21:25
  • 1
    Even if he hasn't done any direct fiddling with a linux distro/the linux kernel, write a very skeletal OS of your own is still a great learning experience, even if it sucks. – Chris Covert Sep 18 '11 at 01:25
  • It's an approach a little different from yours, but you might want to check out this SO discussion – Pete Wilson Sep 17 '11 at 17:22
  • 1
    @AlokSave: We implemented one in _six_ months as a college project, before saying such (discouraging) blanket statements, one should think of "how _big_ the OS in question is?" :) – legends2k Jan 13 '13 at 17:07
  • Voting to close as too broad, too many questions in one. – Ciro Santilli OurBigBook.com Aug 15 '15 at 20:22

1 Answers1

2

1: You should only need a small amount of assembly to handle the boot process and load the C code. Shouldn't be more than like 20-30 lines I think.

2-4: I haven't really used C++ with OS dev, but I think I remember reading that it takes more work to get it running somewhere. Sorry I can't be of more help.

5: You "can" do it using MinGW, but from my experience it mostly complicates things. I could never really get a Windows environment working, but I also gave up without too much effort.

EDIT: Here is a link to some example assembly. This is all I ever had to use: http://www.jamesmolloy.co.uk/tutorial_html/2.-Genesis.html

The rest of that site is a pretty good tutorial too if you are at all interested in that kind of thing.

Chris Covert
  • 2,684
  • 3
  • 24
  • 31
  • Just a couple things to add. 4 is a plain "No". Very few compilers can still produce 16 bit code. 6 is also a "No". You can write to video memory from any mode as long as its mapped into your virtual memory. – ughoavgfhw Sep 17 '11 at 17:24
  • Note that some parts of the tutorial have some subtle bugs, so be careful there (eg assuming that arbitrary memory is cleared before the first use). Though still a good tutorial - I should really write the author about the problems some time. But then anyone following the tutorial and trying to understand the code should notice them anyway. – Voo Sep 17 '11 at 18:16