How to ask my OS to "DO NOTHING"

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
thinklogic

How to ask my OS to "DO NOTHING"

Post by thinklogic »

i got one question more.

let say i already wrote my small OS

after the BIOS read my 512 bytes file at 7c00h
i want it to DO NOTHING. just stop that

if i write

loopagain:
jmp loopagain

it will use 100% CPU Usage....

any idea just make the computer to stay there and don't move after it print my welcome message "Welcome to Hello World! Operating System" any without using any CPU resource (coz it does nothing after printed out the welcome text).


any INTERRUPT that will just make the CPU HALTED or IDLE(DO NOTHING).

any idea to know the CPU state, eg if it is IDLE?, BUSY?, WAITING? or whatsoever?
Schol-R-LEA

Re:How to ask my OS to "DO NOTHING"

Post by Schol-R-LEA »

Try adding a halt instruction into the do-nothing loop:

Code: Select all

spin: hlt
        jmp short spin
The HLT (halt) instruction forces the CPU to idle until the next interrupt occurs; by looping on that, it ensures that it will continue to pause even after any interrupts. This is also how most null processes work.

BTW, the SHORT specifier isn't really necessary here, as NASM defaults to short jumps if the target is within 127 addresses, but I prefer to state it explicitly.
Post Reply