Page 1 of 1

Linux hardware I/O

Posted: Sun Feb 15, 2009 4:07 pm
by infratec
Hi together!

I want to write a small I/O wrapper which is working in windows AND Linux.
Window part is working. But I have problems with the Linux part.

I call iopl and it seems that it works (Result = 0)
But than I got an error at my out dx, ax command.

I checked, that inp() and out() are only macros in Linux for an inline assembly.
So I do the same.

Here is the code:

Code: Select all

;
; Wrapper for the well known inpout32.dll
;
; http://logix4u.net
;


Global InpOutLib = #False

Global *Inp
Global *Out



Procedure InitInpOut()

 Result = #False

CompilerIf #PB_Compiler_OS = #PB_OS_Linux

 InpOutLib = OpenLibrary(#PB_Any, "libc.so.6")
 If InpOutLib
  Result = CallCFunction(InpOutLib, "iopl", 0)
  If Result = 0 : Result = #True : EndIf
 EndIf
 
CompilerElse

 InpOutLib = OpenLibrary(#PB_Any, "inpout32.dll")
 
 If InpOutLib
  *Inp = GetFunction(InpOutLib, "Inp32")
  *Out = GetFunction(InpOutLib, "Out32")
  Result = #True
 EndIf
 
CompilerEndIf
 
 ProcedureReturn Result
EndProcedure


Procedure CloseInpOut()
 If InpOutLib : CloseLibrary(InpOutLib) : EndIf
EndProcedure


Procedure Inp(Port.w)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
 EnableASM
 mov dx, Port
 in ax, dx
 DisableASM
 ProcedureReturn
CompilerElse
 ProcedureReturn CallFunctionFast(*Inp, Port)
CompilerEndIf
EndProcedure


Procedure Out(Port.w, Value.w)
CompilerIf #PB_Compiler_OS = #PB_OS_Linux
 EnableASM
 mov dx, Port
 mov ax, Value
 out dx, ax
 DisableASM
CompilerElse
 CallFunctionFast(*Out, Port, Value)
CompilerEndIf
EndProcedure
Any ideas ?


Bernd

Posted: Sun Feb 15, 2009 6:17 pm
by flaith

Posted: Sun Feb 15, 2009 6:28 pm
by infratec
Hi Flaith,

I know how to do hardware access in Linux with 'C'.
That's not my problem :(
(I'm programming embedded devices based on Linux)


My problems are:

1. Is the PB inline assembler correct ?
2. If yes, why I got an error messages during runtime?
(I run the program with root rights, of course of iopl(),
but the error is still here)


Best regards,

Bernd