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:


idle_loop:
jmp idle_loop

Any ideas?
Thanks
Posted on 2003-10-28 19:40:13 by GogetaSSJ4
Maybe the CPL isn't 0? The CPL has to be 0.
Posted on 2003-10-29 12:28:42 by Sephiroth3

Maybe the CPL isn't 0? The CPL has to be 0.

It is 0.
Posted on 2003-10-29 20:09:46 by GogetaSSJ4


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.
Posted on 2003-10-29 21:05:09 by hitchhikr



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). [...]
Posted on 2003-10-30 12:35:55 by MazeGen



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?
Posted on 2003-10-30 21:19:22 by GogetaSSJ4
Implement this at ring0 (maybe by using an interrupt as gate).



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.
Posted on 2003-10-30 22:32:58 by hitchhikr
Ok, but the code I pasted above should work. Why it doesn't?
Posted on 2003-10-30 23:23:14 by GogetaSSJ4
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.
Posted on 2003-10-31 11:06:14 by hitchhikr

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).
Posted on 2003-10-31 12:39:03 by GogetaSSJ4
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.
Posted on 2003-10-31 13:03:35 by hitchhikr

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?
Posted on 2003-10-31 23:42:36 by GogetaSSJ4
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.
Posted on 2003-11-01 00:13:20 by hitchhikr

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?
Posted on 2003-11-02 00:37:22 by GogetaSSJ4
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.
Posted on 2003-11-02 12:16:18 by hitchhikr
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.
Posted on 2003-11-02 12:19:58 by f0dder
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.
Posted on 2003-11-02 12:30:02 by hitchhikr
This is what the source says (Minix 2.0.2):


!*===========================================================================*
!* 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.
Posted on 2003-11-02 13:37:50 by GogetaSSJ4
heh, "a hlt before this fails in protected mode" - sounds like minix is shit ;)
Posted on 2003-11-02 13:45:06 by f0dder

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.
Posted on 2003-11-02 20:41:52 by GogetaSSJ4