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
Bernd

