How to start? + Descriptors and tables question
How to start? + Descriptors and tables question
Hey all!
I'm new here!
Yesterday I wrote my first boot loader from diskette in asm, for now it just hangs since it have nothing to boot
However I have few questions:
1. There are some advanced technique like PM mode and the need to open A20 line, and set GDT and IDT, but I don't understand it. So I would like to ask should I jump straight to 32bit and use PM mode and etc? or since I'm new to the topic maybe its better going with a 16bit kernel in real mode?
2. Again as a beginner should I try a single-tasking or multi-tasking os?
3. I use qemu and consider trying Bochs are they good?
4. I understood that I can't use all standard function of C/C++, so I should implant my own printf/scanf/malloc/free and etc?
That's it for now, thank you for your time
I'm new here!
Yesterday I wrote my first boot loader from diskette in asm, for now it just hangs since it have nothing to boot
However I have few questions:
1. There are some advanced technique like PM mode and the need to open A20 line, and set GDT and IDT, but I don't understand it. So I would like to ask should I jump straight to 32bit and use PM mode and etc? or since I'm new to the topic maybe its better going with a 16bit kernel in real mode?
2. Again as a beginner should I try a single-tasking or multi-tasking os?
3. I use qemu and consider trying Bochs are they good?
4. I understood that I can't use all standard function of C/C++, so I should implant my own printf/scanf/malloc/free and etc?
That's it for now, thank you for your time
Last edited by skwee on Tue Jan 13, 2009 1:31 pm, edited 1 time in total.
TCP/IP: Connecting people...
Re: How to start?
it all depends on what you want to accomplish.
I'd suggest entering 32-bit protected mode, setup paging, and write some good memory management.
Yes, you will need to implement your own printf, malloc, etc... unless of course you want to try and port a pre-existing library to your OS.
I'd get as many emulators/real-hardware as you can, and test on all. Personally, i prefer BOCHS + VirtualBox, but some people swear by QEMU and such. Find what works, and stick with it, just make sure you test on the others occasionally.
Stick with single-tasking until you have a rock-solid memory manager and have a good understanding of interrupts (IDT/ISR's).
I'd suggest entering 32-bit protected mode, setup paging, and write some good memory management.
Yes, you will need to implement your own printf, malloc, etc... unless of course you want to try and port a pre-existing library to your OS.
I'd get as many emulators/real-hardware as you can, and test on all. Personally, i prefer BOCHS + VirtualBox, but some people swear by QEMU and such. Find what works, and stick with it, just make sure you test on the others occasionally.
Stick with single-tasking until you have a rock-solid memory manager and have a good understanding of interrupts (IDT/ISR's).
Website: https://joscor.com
Re: How to start?
You have to do what you prefer, when i started i choose for 32bit OS.skwo wrote:Hey all!
I'm new here!
Yesterday I wrote my first boot loader from diskette in asm, for now it just hangs since it have nothing to boot
However I have few questions:
1. There are some advanced technique like PM mode and the need to open A20 line, and set GDT and IDT, but I don't understand it. So I would like to ask should I jump straight to 32bit and use PM mode and etc? or since I'm new to the topic maybe its better going with a 16bit kernel in real mode?
Obviously single-tasking could be easier, but i think that the answer is only your choice.skwo wrote: 2. Again as a beginner should I try a single-tasking or multi-tasking os?
Yeah, but never forget real pc, sometimes happens that an OS works fine with bochs, and qemu and when you try it in real PC you find tons of problems.skwo wrote:3. I use qemu and consider trying Bochs are they good?
Yeah, you cannot use them, you have to begin from scratch, first you have to do basic i/o functions, after Exceptions/IRQ handling, etc, and you have to rewrite standard libraries (or maybe take them somewhere and use them for your os, but probably you have to adapt them to your os).skwo wrote: 4. I understood that I can't use all standard function of C/C++, so I should implant my own printf/scanf/malloc/free and etc?
Obviously you can choose to use non standard libraries, is in your choice!!
Good Luck
Re: How to start?
Wow thanks for that
Ill try to read more about GDT and IDT (btw do I need IDT?), A20 line I already know how to open.
One more question: all C-stuff (I mean functions) should be implanted via BIOS interrupts?
Thanks again!
Ill try to read more about GDT and IDT (btw do I need IDT?), A20 line I already know how to open.
One more question: all C-stuff (I mean functions) should be implanted via BIOS interrupts?
Thanks again!
TCP/IP: Connecting people...
Re: How to start?
Yes, you need both, GDT is needed for enabling PMODE, IDT is needed for interrupt and exception handling.skwo wrote:Wow thanks for that
Ill try to read more about GDT and IDT (btw do I need IDT?),
If you go in PMODE No, BIOS Interrupts works only in real mode, when you go in pmode they don't work.
http://www.intel.com/products/processor ... /index.htm here you find the intel manuals (if you still haven't). They are very useful (you can order a printed copy for free).
Bye.
Last edited by finarfin on Mon Jan 12, 2009 4:39 am, edited 1 time in total.
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
Re: How to start?
Hi,
Yes, you do need an IDT - if not, you won't be able to handle exceptions (you won't be able to tell when a fault happened) and you won't be able to handle hardware interrupts (timer and scheduling, telling when a disk IO operation has completed and so on). You also need an IDT for multitasking.
On the BIOS interrupts thing, you can only use them in real mode (OK, OK - or v86, or unreal mode...). Generally, your OS will expose a system call mechanism that applications can use to provide library functionality and so on.
Cheers,
Adam
Yes, you do need an IDT - if not, you won't be able to handle exceptions (you won't be able to tell when a fault happened) and you won't be able to handle hardware interrupts (timer and scheduling, telling when a disk IO operation has completed and so on). You also need an IDT for multitasking.
On the BIOS interrupts thing, you can only use them in real mode (OK, OK - or v86, or unreal mode...). Generally, your OS will expose a system call mechanism that applications can use to provide library functionality and so on.
Cheers,
Adam
Re: How to start?
Not entirely true, when using cooperative multitasking one doesn't per se :).AJ wrote:You also need an IDT for multitasking.
JAL
Re: How to start?
That actually crossed my mind when I was posting, but I assumed that you would support yield() via a software interrupt in addition to SYSCALL/SYSENTER support. I didn't put anything because I didn't think anyone would be that pedantic
Re: How to start?
I encountered some problems.
First of all I want to say I did search in wiki and in forum but wiki is too generic and forum keep telling me "The following words are too common".
Anyway the first stage boot loader works fine, it does load the 2nd stage from floppy and passes control to it (A little question: where is the best place to load the kernel? I know that 0x00000500 to 0x00007BFF are not used and also 0x00007E00 till 0x0009FFFF not used too is it a good place to load the kernel?).
Now the problems are that I don't know how exactly load GDT and IDT (and also do I need LDT? It too few information about it on the web).
I know that GDT is a descriptors that allows to map more that 1MB of memory, each descriptor is 8Byte, and the first on is always zero (the NULL descriptor), now I found the following table:
http://www.brokenthorn.com/Resources/OSDev8.html
Is this table correct? And also most of the GDT I don't understand (Seems like I cant understand what is Descriptor in global).
And last questions I would like to ask, do I load the GDT and IDT (and LDT if needed) before I pass control to kernel? I mean Bootloader stage 1 loads stage 2, stage 2 enables A20 Line, load GDT, IDT (LDT), set PMode bit and executes main function of kernel OR stage 2 just passes control to kernel and kernel loads all this stuff? (The kernel will be written in C/C++ so is it a good way to declare the GDT/IDT/LDT structures in C/C++ and the load them with assembly?)
I pretty sure most of the questions already have been asked but as I said I tried to search and found nothing help full.
Thanks a lot for help!
First of all I want to say I did search in wiki and in forum but wiki is too generic and forum keep telling me "The following words are too common".
Anyway the first stage boot loader works fine, it does load the 2nd stage from floppy and passes control to it (A little question: where is the best place to load the kernel? I know that 0x00000500 to 0x00007BFF are not used and also 0x00007E00 till 0x0009FFFF not used too is it a good place to load the kernel?).
Now the problems are that I don't know how exactly load GDT and IDT (and also do I need LDT? It too few information about it on the web).
I know that GDT is a descriptors that allows to map more that 1MB of memory, each descriptor is 8Byte, and the first on is always zero (the NULL descriptor), now I found the following table:
http://www.brokenthorn.com/Resources/OSDev8.html
Is this table correct? And also most of the GDT I don't understand (Seems like I cant understand what is Descriptor in global).
And last questions I would like to ask, do I load the GDT and IDT (and LDT if needed) before I pass control to kernel? I mean Bootloader stage 1 loads stage 2, stage 2 enables A20 Line, load GDT, IDT (LDT), set PMode bit and executes main function of kernel OR stage 2 just passes control to kernel and kernel loads all this stuff? (The kernel will be written in C/C++ so is it a good way to declare the GDT/IDT/LDT structures in C/C++ and the load them with assembly?)
I pretty sure most of the questions already have been asked but as I said I tried to search and found nothing help full.
Thanks a lot for help!
TCP/IP: Connecting people...
Re: How to start? + Descriptors and tables question
For kernel start you can choose, normally is above the first mb of memory.
For the GDT, i suggest you to read the intel manual, volume 3 - System Programming Guide
No LDT isn't needed.
You have to load first of all a valid GDT (if you want you can write gdt handlng later, you only need a valid GDT).
The IDT can be loaded after you jump from bootloader to kernel, in protect mode.
Normally at the very beginning you have to do:
1. Some basic I/O routines
2. Interrupt Handling
3. IRQ Handling (for be able to receive keyboard interrupts) but 3 depends on 2
I hope i was clear ...
For the GDT, i suggest you to read the intel manual, volume 3 - System Programming Guide
No LDT isn't needed.
You have to load first of all a valid GDT (if you want you can write gdt handlng later, you only need a valid GDT).
The IDT can be loaded after you jump from bootloader to kernel, in protect mode.
Normally at the very beginning you have to do:
1. Some basic I/O routines
2. Interrupt Handling
3. IRQ Handling (for be able to receive keyboard interrupts) but 3 depends on 2
I hope i was clear ...
Elen síla lúmenn' omentielvo
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs
- DreamOS64 - My latest attempt with osdev: https://github.com/dreamos82/Dreamos64
- Osdev Notes - My notes about osdeving! https://github.com/dreamos82/Osdev-Notes
- My old Os Project: https://github.com/dreamos82/DreamOs