Port access

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
hunter
Posts: 12
Joined: Fri Jan 05, 2007 9:47 am

Port access

Post by hunter »

Hello,

is it possible to disable the ports and cli,sti,... for ring3 tasks ??
Could somebody give me a example ?

Hunter
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Re: Port access

Post by Jeko »

hunter wrote:Hello,

is it possible to disable the ports and cli,sti,... for ring3 tasks ??
Could somebody give me a example ?

Hunter
I think you must use the TSS. cli and sti are already disabled in ring3.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Hi,

If you want to disable all ports in ring 3, simply set the IOPL bits in EFLAGS to zero. This means that any ring 3 task attempting port access will cause a GP fault. This needs to be appropriately handled by your kernel, which can decide whether or not to allow the read/write.

Cheers,
Adam
hunter
Posts: 12
Joined: Fri Jan 05, 2007 9:47 am

Post by hunter »

cli and sti are already disabled in ring3
But if i use cli in a ring3 task the system stops ... Should i have to do something to disable them ??

Hunter
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

No. If you are really running in ring 3, you will generate a GPF if you try to cli.

Also, you *cannot* modify IF with the POPF instruction if IOPL is set below the current privilege level.

Cheers,
Adam
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Once again: check IOPL

Also, some people forgot to read the manual page on CLI:
AMD's Big Book of Patterns wrote:In protected mode and virtual-8086-mode, this instruction is IOPL-sensitive. If the CPL is less than or equal to the rFLAGS.IOPL field, the instruction clears IF to 0.

In protected mode, if IOPL < 3, CPL = 3, and protected mode virtual interrupts are enabled (CR4.PVI = 1), then the instruction instead clears rFLAGS.VIF to 0. If none of these conditions apply, the processor raises a general-purpose exception (#GP).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply