Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Hello, I would like to learn Assembly programming to better understand the way processors and computer programming works. However, I've seen that there are many kinds of architectures and I do not know where to begin.
I'd like to make my own test Operating System just to get the basic feel of how such a thing is done but, like I said, I've no idea where to begin. Please do recommend good programming languages to learn as I currently only know a few related to web development.
My goal with this little project is to produce an OS that will boot and display either some text or a standard bitmap, or if it goes well then a nice little CLI
I imagine that you'd have had thousands of posts like this from clueless newbies so I apologise if this is irritating but I really do want to learn.
x86 is the most common CPU currently availible and has the most freely availible information and the most people to help you with your project
you should definatly learn some ASM (at least enough to understand how the code is executed and memory access in pm)and C would be extremely usefull as most OSdevers use it(some form of the GCC compiler)
I cant believe it wasnt already mentioned but by FAR the most important resorce would be the Intel i386 system programming manuals availible from the intel website ( http://developer.intel.com )
there are 4 books in this set all four are valuable (esp. #3: system programming)
then you must deside if you want to use GRUB (or another bootloader) or write your own (my preference) a lot of people have strong opinions on this but its your OS
But I don't have an Intel CPU. I'm using an AMD 2ghz processor with my main machine and I'm running Windows XP Pro. I tried to run Bochs but it always fails with various panics.
I'd like to program everything myself as I want to actually understand how it's done and not so much focus on getting it finished.
AMD and Intel processors are EXACTLY ALIKE
more specificaly, the AMD processors are designed to work like the Intel chips so that any program made for one will work on the other
there are a few differences but you can tell what these are by reading the Intel manuals:
CPUID is the only important one and you can get AMDs CPUID documentation from AMDs website
basically Intel assigned each Company a number and if you call CPUID you can get the manufacter and then use there specific number to find out what features that it supports (see volume 2a:CPUID). Recently they changed how future features would be reported but i havnt bothered checking how that works but it should be simpler than the older way
Thanks again. I read the article about making a small example 'os' that boots from a floppy and that seems like an excellent way to go for my project so I'll be trying to do this with a floppy disk.
There is a lot of terminology and everything seems to be geared towards those that already have a good knowledge of C and ASM so I may be asking a few seemingly stupid questions here in the future. I apologise for that in advance
The end of the 'os' that goes on a floppy in the example does an infinate loop so nothing else can be done. But I remember reading in another article on osdever that it's better to halt the processor rather than inf loop it. I guess this will be in the intel guides so I'll check those out, unless you can give a code snippet to do that?
Thank you for the good feedback, this is all really interesting stuff and has surprised me by how much information there is available. It's kind of overwhelming to begin with.
well as you read the intel manuals youll learn a LOT but halting the CPU is really simple:
hlt
but it will resume on interupt so if they are disabled that will permentently halt the CPU but if they arnt a better way would be:
stop:
hlt
jmp stop:
i suggest reading the intel manuals esp. volume 3 cover to cover before starting make sure you understand the difference between real and protected mode and memory addressing within both real and protected mode
be carefull if your writing your own bootloader that you dont fall into the deadly trap of trying to enable A20 and enter pm in the boot sector: it can be done but it makes things FAR more complicated
actually, i do it the same way MS bootloader does it: i parse the FAT table and root dir, load the second stage from file and jmp to it -- despite what some people say its easier to do that within the bootsector than it is to *properly* set up pm
I boot up a similar way. I used an NASM feature where you can include a binary file into your finished executable using an "incbin" statement. Basically the first line in my kernel is
I want to start an OS, I'm read the book "Operating Systems, Design and Implementation. Second Edition" and am starting a course in C. I have got one of those tutorials off the internet using MS-DOS Debug command (Very lame and complicated). What should I do to start a Proper OS like Windows or Linux?
Im also trying to learn about OS development for interest. I got the Intel books and Tannenbaums MOS book. While reading them I got really confused. MOS focuses on building OS's for machines that do not have an MMU, while the intel books talk heavily about using the GDT/LDT stuff for segmentation.
Are we suppose to just setup a very simple entry in the GDT that points to all of memory, and perform any other segmentation using the kernel? So we dont use the LDT and TSS stuff...
---
Unfortunately, while all answers are replies, not all replies are answers
In this model all the segments cover the full address space (Usually 0->4Gb on x86). In essence this means that we completely ignore the A part of our A:B logical address. The reason for this is that most processors don't actually have segmentation (Plus it's a hell of a lot easier for the compiler to optimise).
This leaves you with 2 descriptors per privilege level (Ring 0 and Ring 3 normally), one for code and one for data, which both describe precisely the same segment. The only difference being that the code descriptor is loaded into CS, and the data descriptor is used by all the other segment registers. The reason you need both a code and data descriptor is that the processor will not allow you to load CS with a data descriptor (This is to help with security when using a segmented memory model, and although useless in the flat-memory model it is still required because you can't turn off segmentation).
In general if you want to use the segmentation mechanism, by having the different segment registers represent segments with different base addresses, you won't be able to use a modern C compiler, and may very well be restricted to just Assembly.
So, if you're going to use C, do what the rest of the C world does, which is set up a flat-memory model, use paging, and ignore the fact that segmentation even exists.
---
Unfortunately, while all answers are replies, not all replies are answers
I have heard that there are many Kernels and Shells for download and many books say to download them instead of writing one to save time and complications.
What should I do if I want to make my own interface and stuff like that. Still windows is closed source so I can't study Win's Shell or Kernel. Go to get me one of those free linux of unix systems.
I just published an OS, written in nasm. Most of the things,You need, are already done - very well commented! Look at my homepage www.rcfriz.de
contact me with Your questions at asmos@rcfriz.de
Does anyone know how to write threads using the MSDOS Debug?
To the best of my knowledge, there is no ability within MSDOS to do any multitasking or multithreading without additional extensions. Besides, what are you using Debug for? It generally isn't for writing software as much as figuring out what is wrong with it.