On Thu, 10 Oct 2019 23:37:19 +0800, Johann 'Myrkraverk' Oskarsson
<joh...@myrkraverk.invalid> wrote:
>On 10/10/2019 3:42 am,
nospa...@efbe.prima.de wrote:
>>> Dear o.u.c_cpp,
>>>
>>> How do I write a #pragma aux for the HLT instruction? And how do I use
>>> said #pragma aux? Are there any cotchas I need to be aware of when I
>>> use the HLT instruction?
>>>
>>> For context, I'm writing a DOS extended program with CauseWay, and want
>>> to be nice to the CPU fan in my program's idle loop for people such as
>>> myself who run DOS operating systems in a virtual machine.
>>>
>>>
>> You have seen this info about Auxiliary Pragmas in the C Guide?
>
>Thank you for the info. I got some help on IRC, and ended up with this
>definition.
>
>void hlt( void );
>#pragma aux hlt = "hlt" modify exact [] nomemory;
>
>Unfortunately, it just ends with an error because it's a privileged
>instruction and I can't use it in protected mode.
Is this the one?
'In the x86 computer architecture, HLT (halt) is an assembly language
instruction which halts the central processing unit (CPU) until the
next external interrupt is fired.[1] Interrupts are signals sent by
hardware devices to the CPU alerting it that an event occurred to
which it should react. For example, hardware timers send interrupts to
the CPU at regular intervals.
'The HLT instruction is executed by the operating system when there is
no immediate work to be done, and the system enters its idle state. In
Windows NT, for example, this instruction is run in the "System Idle
Process". On x86 processors, the opcode of HLT is 0xF4.'
If so, no wonder it's restricted -- just because /your/ program isn't
doing anything doesn't mean something else isn't. There /are/ other
processes outside the virtual machine, are there not?
I don't have any experience with virtual machines. When your program
is in an idle loop, is it checking for something, like a keystroke? If
so, I would expect that call to eventually become a call to the host
OS, which I would expect to suspend the virtual machine until the
keystroke (or whatever) happens. But that is just what I would expect;
reality may be quite quite different.
--
"I begin to envy Petronius."
"I have envied him long since."