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.
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.
I don't agree that the title is the simple part. You may consider studying minix
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.
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.
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.
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.
Another good reference book that you might want to consider revising is:
- Operating Systems by William Stallings. I believe the latest edition is the 6th edition.
- A site for the 5th edition might also help some.
Good luck with this endeavor. I mean it, good luck.
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).
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
精彩评论