Hi.
I'm trying to make the OS use hlt in its idle loop, but it fails miserably in protected mode. Is there a way to use it?
What ca I do so it does not just loop doing nothing? (like Win2K or Linux do)
Currently it's:
Any ideas?
Thanks
I'm trying to make the OS use hlt in its idle loop, but it fails miserably in protected mode. Is there a way to use it?
What ca I do so it does not just loop doing nothing? (like Win2K or Linux do)
Currently it's:
idle_loop:
jmp idle_loop
Any ideas?
Thanks
Maybe the CPL isn't 0? The CPL has to be 0.
Maybe the CPL isn't 0? The CPL has to be 0.
It is 0.
sti
hlt
cli
ret
To be used in ring0.
This might be implemented as a never ending task (provided that you handle tasks of course).
Have fun.
h.
sti
hlt
cli
ret
Be careful here, because STI sets Interrupt Flag after the NEXT instruction, not in the instant.
Intel STI description:
Sets the interrupt flag (IF) in the EFLAGS register. After the IF flag is set, the processor begins
responding to external, maskable interrupts after the next instruction is executed. The delayed
effect of this instruction is provided to allow interrupts to be enabled just before returning from
a procedure (or subroutine). [...]
sti
hlt
cli
ret
To be used in ring0.
This might be implemented as a never ending task (provided that you handle tasks of course).
Have fun.
h.
sti and cli shouldn't be necesary, and since it's not a function, ret shouldn't be needed too.
Any other ideas?
Implement this at ring0 (maybe by using an interrupt as gate).
It works, i've seen it before (don't remember where)
h.
Idling:
push Idle
call ToRing0 ; pass thru interrupt
pop eax
jmp Idling
Idle:
sti
hlt
cli
ret
It works, i've seen it before (don't remember where)
h.
Ok, but the code I pasted above should work. Why it doesn't?
How would i know ?
It depends on how you implement your tasks.
(a task with idling purpose is usually implemented as any other, except that it have a idle priority, which is handled by the scheduler).
h.
It depends on how you implement your tasks.
(a task with idling purpose is usually implemented as any other, except that it have a idle priority, which is handled by the scheduler).
h.
How would i know ?
It depends on how you implement your tasks.
(a task with idling purpose is usually implemented as any other, except that it have a idle priority, which is handled by the scheduler).
h.
The task is executed all right. The problem isn't that. The problem is that after executing hlt it hangs with an exception.
This task is implemented somehow that way. When nothing else is running, it gets called for a quantum (no preemtion).
Since hlt is resumed with an interrupt there must be somekind of jam in one of them.
Do you know what is the exception number and where it occurs ?
h.
Do you know what is the exception number and where it occurs ?
h.
Since hlt is resumed with an interrupt there must be somekind of jam in one of them.
Do you know what is the exception number and where it occurs ?
h.
No, I don't. How would I get that info?
I suggest you to go there:
http://bochs.sourceforge.net/
To download bochs (a virtual pc).
and there:
http://bfe.sf.net/
To download a gui front end for bochs debugger.
This should help you to trace errors. ;)
h.
http://bochs.sourceforge.net/
To download bochs (a virtual pc).
and there:
http://bfe.sf.net/
To download a gui front end for bochs debugger.
This should help you to trace errors. ;)
h.
I suggest you to go there:
http://bochs.sourceforge.net/
To download bochs (a virtual pc).
and there:
http://bfe.sf.net/
To download a gui front end for bochs debugger.
This should help you to trace errors. ;)
h.
I couldn't get it to run on Boch (yet, at least). The OS is not mine, it's Minix actually, and I'm playing with it.
One of the things I wanted to change was that, so it would not use all my CPU while running inside VMware (where it is right now).
What else should I try?
Looks like minix is a great source of inspiration, as far as i know this unix does use the hlt instruction to handle idle tasks (very similar to the example i pasted previously even).
Never seen vmware anywhere, but what makes you believe that it is not vmware itself that consumes all the cpu time instead of the nature of what it is emulating ?
I don't think that adding a hlt into the code emulated by vmware will change anything (is this instruction really emulated, btw ?).
h.
Never seen vmware anywhere, but what makes you believe that it is not vmware itself that consumes all the cpu time instead of the nature of what it is emulating ?
I don't think that adding a hlt into the code emulated by vmware will change anything (is this instruction really emulated, btw ?).
h.
when vmwaring winxp, I have idle CPU usage when the emulated XP is idling... but perhaps it requires that vmware has specific OS-knowledge of the emulated OS to be able to do this.
Minix (at least the lastest version 2.0.3) uses hlt to idle.
And eats 100% cpu time (at least reported) when emulated with bochs under win2000 (but my cpu is only a p133).
h.
And eats 100% cpu time (at least reported) when emulated with bochs under win2000 (but my cpu is only a p133).
h.
This is what the source says (Minix 2.0.2):
I tried it, it's true.
As f0dder said, the CPU is idle when WinXP/2K are running, but not DOS for example. And as he said, it may well have specifc knowledge of these OS's. But I think it's reasonable to think that a hlt would realy idle the CPU (that's what I want to prove/disprove with this).
I'll check Minix 2.0.3 to see what changed.
!*===========================================================================*
!* idle_task *
!*===========================================================================*
_idle_task: ! executed when there is no work
jmp _idle_task ! a "hlt" before this fails in protected mode
I tried it, it's true.
As f0dder said, the CPU is idle when WinXP/2K are running, but not DOS for example. And as he said, it may well have specifc knowledge of these OS's. But I think it's reasonable to think that a hlt would realy idle the CPU (that's what I want to prove/disprove with this).
I'll check Minix 2.0.3 to see what changed.
heh, "a hlt before this fails in protected mode" - sounds like minix is shit ;)
heh, "a hlt before this fails in protected mode" - sounds like minix is shit ;)
Jeje....it is.
But, as hitchhikr said, 2.0.3 does use hlt.
I'm downloading it now.