Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I use #pragma aux with the HLT instruction?

13 views
Skip to first unread message

Johann 'Myrkraverk' Oskarsson

unread,
Oct 9, 2019, 1:31:37 PM10/9/19
to
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.


--
Johann | email: invalid -> com | www.myrkraverk.com/blog/
I'm not from the Internet, I just work there. | twitter: @myrkraverk

nospa...@efbe.prima.de

unread,
Oct 9, 2019, 3:42:03 PM10/9/19
to
Am 09.10.19 um 19:31 schrieb Johann 'Myrkraverk' Oskarsson:
> 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?

...
In the following DOS example, Open Watcom C/C++ will generate the
sequence of bytes following the "="
character in the auxiliary pragma whenever a call to mode4 is
encountered. mode4 is called an in-line
function.

void mode4(void);
#pragma aux mode4 = \
0xb4 0x00 /* mov AH,0 */ \
0xb0 0x04 /* mov AL,4 */ \
0xcd 0x10 /* int 10H */ \
modify [ AH AL ];

The sequence in the above DOS example represents the following lines of
assembly language instructions.
mov AH,0 ; select function "set mode"
mov AL,4 ; specify mode (mode 4)
int 10H ; BIOS video call

The above example demonstrates how to generate BIOS function calls
in-line without writing an assembly
language function and calling it from your C/C++ program. The C
prototype for the function mode4 is not
necessary but is included so that we can take advantage of the argument
type checking provided by Open Watcom C/C++.
The following DOS example is equivalent to the above example but
mnemonics for the assembly language
instructions are used instead of the binary encoding of the assembly
language instructions.

void mode4(void);
#pragma aux mode4 =
"mov AH,0",
"mov AL,4",
"int 10H"
modify [ AH AL ];
...

CU/2
Frank

Johann 'Myrkraverk' Oskarsson

unread,
Oct 10, 2019, 11:37:22 AM10/10/19
to
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.

Paul S Person

unread,
Oct 10, 2019, 12:07:33 PM10/10/19
to
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."

Johann 'Myrkraverk' Oskarsson

unread,
Oct 10, 2019, 12:18:45 PM10/10/19
to
On 11/10/2019 12:07 am, Paul S Person wrote:
>
> 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.

The situation is not that simple or I'd have used blocking reads on
getch() -- which presumably tells DOS I'm not busy.

The problem is detecting mouse events too. The only way I've seen (and
others have concurred) is a busy loop that checks for the mouse state
and whether a key has been hit with kbhit().

Frank Beythien

unread,
Oct 10, 2019, 12:43:33 PM10/10/19
to
Am 10.10.19 um 18:18 schrieb Johann 'Myrkraverk' Oskarsson:
> On 11/10/2019 12:07 am, Paul S Person wrote:
>>
>> 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.
>
> The situation is not that simple or I'd have used blocking reads on
> getch() -- which presumably tells DOS I'm not busy.
>
> The problem is detecting mouse events too.  The only way I've seen (and
> others have concurred) is a busy loop that checks for the mouse state
> and whether a key has been hit with kbhit().

For Causeway there is an OW replacement for kbhit()
See Causeway programmer guide cw.{inf,pdf}
CU/2
Frank

Steven Levine

unread,
Oct 12, 2019, 1:57:32 PM10/12/19
to
On Thu, 10 Oct 2019 15:37:19 UTC, Johann 'Myrkraverk' Oskarsson
<joh...@myrkraverk.invalid> wrote:

Hi,

> 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.

Since you are writing to Causeway, I recommend checking the docs for a
yield() function. This may use the hlt instruction.

Steven

--
---------------------------------------------------------------------
Steven Levine <ste...@earthlink.bogus.net>
DIY/ArcaOS/Warp etc. www.scoug.com www.arcanoae.com www.warpcave.com
---------------------------------------------------------------------
0 new messages