My learning went like this:
Learn about bochs
Learn about GRUB
Get a cross compiler working (GCC on Cygwin)
Get my code called - setup stack and perform initial paging
Printing to screen
Jump to C and get real paging working
Learn about and install GDT
Learn about and install IDT
Create a physical mem manager (i used a stack of free pages)
Learn about and setup some tasks - working tonight
Next is to get a scheduler going and start switching to tasks. I can then start to think the next stage of booting and getting into user land. But first a cold beer.
Cheers
Small OS plan, need some guide lines
Re:Small OS plan, need some guide lines
I'm not sure what mar-rih is on about, DJGPP is good enough, if it doesn't work for you though you can install Cygwin and build a GCC cross-compiler on it.
Other than GCC you can use MS Visual C++ (see the Wiki and associated thread).
Other than GCC you can use MS Visual C++ (see the Wiki and associated thread).
Re:Small OS plan, need some guide lines
i depend in my replay above on the reply of Clicker to me about the probelm that occur when i try to compile the artical example of BKERNDEV
http://www.mega-tokyo.com/forum/index.p ... eadid=7663
this what Clicker had said...
http://www.mega-tokyo.com/forum/index.p ... eadid=7663
this what Clicker had said...
indeed, i think your MingW is the problem. I don't suggest DJGPP, but rather CYGWIN.
Re:Small OS plan, need some guide lines
Got my task switching working
What I needed to get my head around
Get local APIC timer setup and generating interrupts (have to use irq > 32)
set up idt to handle irq - I decided to use a task gate.
Learn how to create tasks using TSS's and GDT - remember to set int flag so that interrupts are enabled when running a task.
To perform switch to task set link in the interrupt handlers tss to the new tasks tss. Perform an iret.
I have 2 tasks running just printing A and B.
I fear after each step, things get more complex.
What I needed to get my head around
Get local APIC timer setup and generating interrupts (have to use irq > 32)
set up idt to handle irq - I decided to use a task gate.
Learn how to create tasks using TSS's and GDT - remember to set int flag so that interrupts are enabled when running a task.
To perform switch to task set link in the interrupt handlers tss to the new tasks tss. Perform an iret.
I have 2 tasks running just printing A and B.
I fear after each step, things get more complex.
Re:Small OS plan, need some guide lines
Hi,
Just some notes...
For the timer IRQ, use an "interrupt gate" and then (if a task switch is needed) use a far jump to switch tasks. This saves task switches - if you use an "interrupt task gate" then the CPU would always do one task switch to get to the timer IRQ handler and then another task switch to return (2 task switches every IRQ). Using an "interrupt gate" means you end up with only one task switch, and only when it's necessary.
Often there's only one task that is ready to run (no task switch needed), and most scheduler designs do a task switch after many IRQs - eg. set the timer for an IRQ every 1 mS and switch tasks after 20 mS. This is normally done when the same timer IRQ is used to maintain the "system timer tick". For example:
Of course this isn't the only way to the timing (but IMHO it is the most common)...
Cheers,
Brendan
Just some notes...
For older single-CPU computers (before Pentium 4) the local APIC is normally disabled by the BIOS during boot, and can't be re-enabled. For these computers use the PIT timer, which is easier. Depending on whether you'll support these older computers or not I'd suggest making the OS work with the PIT and worry about the local APIC timer later.Mark wrote:Get local APIC timer setup and generating interrupts (have to use irq > 32)
For most interrupts, using a task gate is slow, and it doesn't work for shared IRQs (PCI, serial ports) where the IRQ handlers need to be chained. Interrupt task gates aren't normally needed, except for a few exception handlers (e.g. double fault), but even then it's optional (easier to write the OS so that doesn't need interrupt task gates at all).Mark wrote:set up idt to handle irq - I decided to use a task gate.
For the timer IRQ, use an "interrupt gate" and then (if a task switch is needed) use a far jump to switch tasks. This saves task switches - if you use an "interrupt task gate" then the CPU would always do one task switch to get to the timer IRQ handler and then another task switch to return (2 task switches every IRQ). Using an "interrupt gate" means you end up with only one task switch, and only when it's necessary.
Often there's only one task that is ready to run (no task switch needed), and most scheduler designs do a task switch after many IRQs - eg. set the timer for an IRQ every 1 mS and switch tasks after 20 mS. This is normally done when the same timer IRQ is used to maintain the "system timer tick". For example:
Code: Select all
timerIRQ:
current_time += time_between_timer_IRQs;
send_timer_EOI();
if (next_task_switch_time < current_time) {
new_task = find_another_task_to_run();
next_task_switch_time = current_time + time_this_task_runs(new_task);
if (new_task != current_task) {
switch_tasks();
}
}
iret
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:Small OS plan, need some guide lines
Cheers for the info.
My little project is a learning exercise so I thought it might be interesting to look at the APIC. Same reason for using tasks for the timer irq handling.
I will try other methods too time permitting (British summer being what it is I suspect there will be plenty of spare time)
I was thinking about experimenting with scheduler algorithmns. I will try a few out for experimentation.
Cheers
Mark
My little project is a learning exercise so I thought it might be interesting to look at the APIC. Same reason for using tasks for the timer irq handling.
I will try other methods too time permitting (British summer being what it is I suspect there will be plenty of spare time)
I was thinking about experimenting with scheduler algorithmns. I will try a few out for experimentation.
Cheers
Mark