Subj : IOPL code with Watcom C
To : All
From : Vitus Jensen
Date : Sun Nov 26 2000 06:55 pm
Hi All!
I'm trying to create a sample program for Watcom C 10.5 which demonstrates IOPL
code. Usually I'm doing this with ALP and IBM Visual Age but this time it has
to be an all Watcom solution (16 bit C, 32 bit C(++), wlink).
Well, it doesn't work (obviously, that's why I'm writing this msg :-|). The
problem isn't the 16 bit code (that's the same i used with VAC++), it's the
thunking which isn't working right. Watcom keeps on calling the IOPL directly
from it's 16 bit thunking code instead of using a callgate.
Perhaps someone can tell me what I'm doing wrong...
extern unsigned char APIENTRY16 inb(unsigned short __port);
...
======================<end>=================================
The whole thing compiles to the following assembler code:
=====================<start>================================
`W?command_write$n(i)v`:
push esp
push 00000004H
push 00000024H
call near ptr __TNK
push esi
sub esp,00000018H
mov dword ptr +10H[esp],000003beH
mov ecx,00000002H
lea esi,+10H[esp]
mov eax,INB ; 0x000E0000
call near ptr __Far16Func2
and al,0d0H
movzx edx,al
...
======================<end>=================================
This looks quite good (don't know nothing about __TNK), the address of INB is
indeed 000E:0000, selector 000E is ring 2 and '__Far16Func2' sounds like a
thunking call.
But when I run the executable, __Far16Func2 finally ends here:
The call fails (GPE) and IMHO because 0017 is ring 3 and 000E is ring 2 and you
can't call ring 2 directly from ring 3.
Again, where is my fault?
Bye,
Vitus
PS: there is sample code for watcom floating around but it uses either IOPL
code or 32->16 bit calls not both combined.
PPS: complete source code on request.