4

Although the title is part of my question, the second part won't be as simple. The First part: Let's say I want to create my own operating system. How do I even go about doing that? I understand I have to create a bootloader. But where do I go from there? I would have to send it to another program, but to do that, that program already has to be there, and I have to know exactly where it's at in the memory space. Any tips/tutorials?

The second question. I'm currently studying memory management, and I think I have a theory on a better implementation for a placement algorithm, but I have no way to really test it except in theory. Once I can create the OS (so this is for future reference), how do I actually mess with main memory, and move processes around?

P.S.: Also, would I have to write my own filesystem?

Edit: After reading over the current comments I want to revise what I said. When I said "the second part won't be as simple", that seems to be a poor choice in words. I know both will be very difficult endeavors, but that doesn't matter to me. I just enjoy learning new things. And I didn't mean for someone to write a tutorial for me, just to point me in the right direction.

Nicholas Roge
  • 160
  • 2
  • 12
  • 5
    What sort of Coding experience do you have? – Varriount Dec 07 '10 at 01:27
  • I've been coding for several years, and can code fluently in C++ and fairly fluently (save a few things) in Java. And I've done a bit of work in assembly (though I would love to do more. It's so much fun.). – Nicholas Roge Dec 07 '10 at 02:22

9 Answers9

5

Phew. Now that's quite a question! I don't think any answer you get here will cover such a huge ground (unless someone sits down to write and revise for an hour or two).

I suggest you read up on operating systems first -- try Tanenbaum's books, and OSDev.org for quick references.

You can use GRUB as your bootloader -- that should simplify things.

salezica
  • 74,081
  • 25
  • 105
  • 166
3

I don't agree that the title is the simple part. You may consider studying minix

Eric Fortis
  • 16,372
  • 6
  • 41
  • 62
  • Well, ha ha, I suppose simple would be a relative term here. – Nicholas Roge Dec 07 '10 at 01:52
  • 1
    My advise is to learn from Tanenbaum (ast), he's by far the most comprehensible author. If you want to get your feet wet fast here is a link to exams w/ answers of my OS professor, http://ece.uprm.edu/~noack/icom5007/exams/ – Eric Fortis Dec 07 '10 at 02:47
  • 1
    P.S. In the exams Noack uses a lot "avoid RADQ", which means avoid Right Answer for a Different Question. – Eric Fortis Dec 07 '10 at 02:53
3

You may want to consider simulating (in whole or in part) an operating system, as opposed to actually writing one. Depending on the model, it may get more out of it while putting in less effort.

I know in my undergrad, we wrote disk-scanning algorithms in Java; it was all Java with a few classes and interfaces. It didn't really scan the disk, but did a decent enough job that we could measure, test, and tweak the algorithm to see how it changed.

So I propose something simpler: if you're just after memory algorithms, maybe you can write a small testable, tweakable application that would let you skip straight to what you want to do, and not worry about "that other OS stuff" you'd have to write otherwise.

Alternatively, playing with an existing (UNIX/Linux) OS might be less effort than writing something new from scratch.

ashes999
  • 9,925
  • 16
  • 73
  • 124
  • Hrm... You're post gave me a bit of an idea (which may be what you were getting at). I may be able to create a program the reserves a good amount of space in memory, and then using the __asm{} directive, I could use the memory I allocated and play with that. – Nicholas Roge Dec 07 '10 at 02:19
  • Right. The other benefit of simulation is testing against different types of applications (with different memory usage profiles). You can just code a simulated app with usage. But the downside of simulation is that it's not tested with real-world apps. Then again, if you benchmark your results, maybe that will suffice to prove the improvement (or non-improvement) of your algorithm. – ashes999 Dec 07 '10 at 14:35
1

This is not a simple endeavor but one in which you will learn a lot. I recommend heading over to http://wiki.osdev.org/Main_Page as that site has many tutorials and will get you started for sure.

linuxuser27
  • 7,183
  • 1
  • 26
  • 22
1

Most of components you've described (memory manager, FS) can be implemented, tested and used without writing an OS for them.

Also, the bootloader isn't really the first thing you should start with. You see, there should be something that would be loaded by it. And this something (that have to be developed and tested) would be much more difficult than a bootloader.

It seems that you underestimate the amount of work (and knowledge!) required to do it. The best you can do is to find a friend who's willing to explain it to you, and chat an hour with him.

ruslik
  • 14,714
  • 1
  • 39
  • 40
  • How would you test a memory manager within the realm of an already running operating system? Wouldn't that conflict with the OS's manager? Or am I just going about it the wrong way? Also, how do you add breaks to comments? I've tried shift+enter and an html break, but neither worked. – Nicholas Roge Dec 07 '10 at 01:56
  • You mean virtual memory manager? Well.. by booting in DOS in a VM and peforming a jump into protected mode you can play with it as well. The problem is that you will need **lots** of carefully written code for that. – ruslik Dec 07 '10 at 02:00
  • @Nicholas: I suppose you could create a much-simplified virtual machine that lets you test different memory manager schemes and extract statistics. Also, you cannot add line breaks in comments. – Cameron Dec 07 '10 at 02:01
0

A theoretical book on operating systems Operating System Concepts would really aid you. Any OS will need a scheduler which will handle task switching, context switching, traps and such.

Novikov
  • 4,399
  • 3
  • 28
  • 36
0

Another good reference book that you might want to consider revising is:

Good luck with this endeavor. I mean it, good luck.

A Salcedo
  • 6,378
  • 8
  • 31
  • 42
0

Study Linux, and the better bits of Minix, and if you go with a ready-made bootloader as some here have suggested, I'd go with LILO over GRUB (these are just personal prefs, of course).

Wesley Rice
  • 2,711
  • 19
  • 8
0

Pritam Zope and theMike97 have amazing tutorials on Youtube on writing an os from scratch. theMike97 has a loong series on writing your own bootloader and Pritam zope teaches you how to write your own kernel in asm and c. heres my curent bootloader if you want something to start with. it just prints hello world.

org 0x7c00
mov si, message       ;The message location *you can change this*
call print            ;CALL tells the pc to jump back here when done
jmp $
print:
  mov ah, 0Eh         ;Set function

.run:
  lodsb               ;Get the char
; cmp al, 0x00        ;I would use this but ya know u dont so use:
  cmp al, 0           ;0 has a HEX code of 0x48 so its not 0x00
  je .done            ;Jump to done if ending code is found
  int 10h             ;Else print
  jmp .run            ; and jump back to .run

.done:
  ret                 ;Return

message           db  'Hello, world', 0 ;IF you use 0x00
;message          db  'Hello, world', 0x00


times 510-($-$$) db 0
dw 0xaa55
~

save this code in a file called main.asm compile it with nasm -fbin main.asm -o main.bin run it with qemu-system-x86_64 main.bin