From owner-freebsd-hackers@FreeBSD.ORG Thu May 31 12:36:51 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DA52216A41F for ; Thu, 31 May 2007 12:36:51 +0000 (UTC) (envelope-from rmgls@orange.fr) Received: from smtp23.orange.fr (smtp23.orange.fr [193.252.22.30]) by mx1.freebsd.org (Postfix) with ESMTP id 7BD8613C448 for ; Thu, 31 May 2007 12:36:51 +0000 (UTC) (envelope-from rmgls@orange.fr) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2332.orange.fr (SMTP Server) with ESMTP id 4E46A1C000BC; Thu, 31 May 2007 14:36:50 +0200 (CEST) Received: from orange.fr (ARouen-153-1-12-144.w90-17.abo.wanadoo.fr [90.17.155.144]) by mwinf2332.orange.fr (SMTP Server) with ESMTP id 2DB081C000AB; Thu, 31 May 2007 14:36:50 +0200 (CEST) X-ME-UUID: 20070531123650187.2DB081C000AB@mwinf2332.orange.fr To: freebsd-hackers@freebsd.org Date: Thu, 31 May 2007 14:36:48 +0200 From: Raoul MEGELAS Message-Id: <20070531123650.2DB081C000AB@mwinf2332.orange.fr> X-Mailman-Approved-At: Thu, 31 May 2007 13:06:27 +0000 Cc: Subject: Re: direct I/O access X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 May 2007 12:36:51 -0000 On Thu, 31 May 2007 08:44:33 +0400 Eygene Ryabinkin wrote, Wed, May 30, 2007 at 02:43:07AM -0400, Mike Meyer wrote: >> I believe this should be $0x4, as you want to *set* the values, not >> get them. > Right. >> You also need to open the file "/dev/io". I believe that leaving this >> file open for anything more than a handful of instructions would be a >> bad thing, but I'm not going to verify it. > I feel that the i386_set_ioperm directly manipulates the task's I/O > bitmap referenced by the task state segment (TSS), so you don't > need to mangle with /dev/io. /dev/io itself is the higher-level > semi machine-indenepdent abstraction. Opening /dev/io grants the > global access to all ports, while using i386_set_ioperm gives the > fine-grained access. When you closing /dev/io, the port I/O access > is revoked. > To summarise: either you open /dev/io and do all your port I/O as > in the good old days of the real-mode programs, or you're using > i386_set_ioperm to obtain the access permissions to the I/O port > range and again, do all port I/O as usual. i rewrote my code and this time, all works fine. thanks to Mike and Eygene. here is the code as a proof of the above explanation: # test_io.S .include "system.inc" BUFSIZE = 0x80 .data params: .long 0x70,2,1,0 path: .asciz "/dev/io" .bss buffer: .fill BUFSIZE, 0 .text .global _start err: pushl $0x1 # return failure SysExit _start: addl $8,%esp # discard argc and argv[0] leal params,%eax pushl %eax pushl $4 movl $0xa5,%eax call bsd_kernel addl $12,%esp movl $0X330,%edx inb %dx,%al # if i try to read or write another port than 0x70/0x71, i have a segbus fault. leal path,%ecx pushl $0 # O_RDONLY pushl %ecx SysOpen jc err # open failed addl $8,%esp movl $0X330,%edx inb %dx,%al # all is ok! pushl $0 # return success SysExit Thanks again. Raoul rmgls@wanadoo.fr