Hi, this is my first post,
It's been a long time since I started reading various books and tutorials on OSdev, but I am still afraid going in protected mode, and doing all of the nice tricks described in the how-tos. And besides I am interested in playing with low level hardware more than writing an entire, useful OS. The thing is I would like to play a little more with the BIOS before I make the next step. As I understand to program an OS capable of switching between processes a couple of times in a second, you need to set the system timer to issue an interrupt. The queston is: is there a mechanism of setting a timer alarm which makes the BIOS redirect the execution flow to another location in the memory? I know I am not using the correct terms, and I apologize for that. I would like to write a simple os, that can do (or mimic) a basic process scheduling and multitasking without going in protected mode. Kindly asking for your advice Thanks!
Playing with timer interrupts in real mode, how?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Playing with timer interrupts in real mode, how?
the BIOS per se do not provide such service. If you want to have multitasking in real mode (which will of course not be hardware-assisted multitasking), you need to install a IRQ0 interrupt handler that will capture the current state of the thread, save it in e.g. threads[curr_th], tell what's the next thread to be run and restore the saved state of threads[next_th] on the cpu.
When i say "save state" or "restore state", it mainly means that you'll have to move registers content in some memory location and reload all registers with some new content.
see the OSFAQ for details.
When i say "save state" or "restore state", it mainly means that you'll have to move registers content in some memory location and reload all registers with some new content.
see the OSFAQ for details.
Re:Playing with timer interrupts in real mode, how?
Thanks for the clarification, now I just need to figure out how to install the irq0 handler. I think I can do the rest, but I have absolutely no idea where and how to install the handler. All of the docs I found the yesterday were pointing to protected mode and the PIC device.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Playing with timer interrupts in real mode, how?
it will be in the Interrupt Vector Table, located at 0000:0000 in memory (4 bytes per interrupt). IRQ0 is interrupt #8 unless you reprogram the PIC so you can just write your handler's segment and offset in 0:0x20 and have it called. A tutorial on MS-DOS programming should easily show you how to do, what to care about, etc.
Re:Playing with timer interrupts in real mode, how?
Great, thanks for the help! I knew that the IVT should be there, but when I dumped that part of the memory in Bochs it was filled with 0x00. I was obviously dumping the memory too early, before the IVT was written by the BIOS. Your post made me try again and solve the mistery. Thanks again!