By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

unhandled exception : Privileged instruction

P: n/a
I would like access to direct addess port via Giveio.sys device driver
(with windows xp e 2k).

i don't understand why this source for pilot a uart controller tra an
exception in _asm cli instruction.

How can I do run un assembler instruction with pricilege mode ??

//************** source code
void Serial_Write (unsigned char ch) {
while (!((unsigned char)Read_UART(port_in_use, REG_LSR) &
0x20)){}

//clear interrupts
_asm cli

Write_UART(port_in_use, REG_THR, (int)ch);

//set interrupts
_asm sti
}
//********************
thanks a lot
ilcario

Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ilcario <il*****@iol.it> scribbled the following
on comp.lang.c:
I would like access to direct addess port via Giveio.sys device driver
(with windows xp e 2k).


This is a question about the Windows platform, not about the C or C++
languages. The only group on your list where your question would be
even remotely topical is comp.lang.asm.x86. I suggest you also try
comp.os.ms-windows.programmer.win32.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"As a boy, I often dreamed of being a baseball, but now we must go forward, not
backward, upward, not forward, and always whirling, whirling towards freedom!"
- Kang

Jul 22 '05 #2

P: n/a
il*****@iol.it (ilcario) wrote in message news:<3e**************************@posting.google. com>...
I would like access to direct addess port via Giveio.sys device driver
(with windows xp e 2k).

i don't understand why this source for pilot a uart controller tra an
exception in _asm cli instruction.

How can I do run un assembler instruction with pricilege mode ??

//************** source code
void Serial_Write (unsigned char ch) {
while (!((unsigned char)Read_UART(port_in_use, REG_LSR) &
0x20)){}

//clear interrupts
_asm cli

Write_UART(port_in_use, REG_THR, (int)ch);

//set interrupts
_asm sti
}
//********************

While GiveIO will let you hit selected I/O ports from an application,
it will not let you disable interrupts. In short, you can't disable
interrupts from an application. Even in a device driver, where you
can execute privileged instructions, it's rather more complicated than
that. While you can get away with disabling interrupts for a short
period, in most cases that does *not* solve the problems you're trying
to solve on multi-processor systems. In a DD you'll generally want to
use a lock of some sort, or manage your IRQL.

Second, direct access to the UART isn't a great idea for a Win32
program. Not only are you assuming a particular type of hardware (eg.
an 8250 compatible serial port - which is a dead wrong assumption on
most current laptops, among other systems), you're probably assuming
it's at a fixed I/O location, and you're probably not managing
interacting with other users of the serial port. At the very least
you should disable the normal Windows support for the serial port in
question.

If you're running 16 bit (DOS) code, access to the UART will be
simulated by the OS with a virtual device driver. You'll also be able
to disable interrupts within the virtual DOS machine, but certainly
not the real ones.

Jul 22 '05 #3

P: n/a
> I would like access to direct addess port via Giveio.sys device driver
(with windows xp e 2k).


AFAIK, giveio.sys just enables you access to ports by setting appropriate
bits in TSS's port map. To execute CLI, you need CPL <= IOPL. CPL is 3.
Thus, you have to make IOPL=3. Remedies:

1) set IOPL to 3 from a driver (this is VERY unsafe and IMO will not work
since OS may change IOPL)
2) set your task's IOPL to 3 from a user-mode service (this is much safer
because (i) OS itself supports it and (ii) only your app will work at
IOPL=3);

ZwSetInformationProcess(hProcess, 16, 0, 0); // SeTcbPrivilege required

Then, you don't need giveio at all.

Ivan
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.