Hi...
I'm porting some code from my C/C++ to Pascal. In this particular case i'm writting a dll to detect all features in cpu. The code is mostly assembler.
The dll was build with no error's or problems. The real question is when i try to call the function from a simple console app. Every time it runs give the error: "Project teste.exe raised execption class 'External: SIGSEGV'.
here is the code of the dll:
library cpulib;
{$ASMMODE INTEL}
const
ID_BIT = $200000;
function HasCPUID : Boolean; assembler;
asm
pushfd { save original EFLAGS to stack }
pop eax { store EFLAGS in EAX }
mov edx,eax { save in EDX for later testing }
xor eax, ID_BIT { flip ID bit in EFLAGS }
push eax { save new EFLAGS value on stack }
popfd { replace current EFLAGS value }
pop eax { get new EFLAGS }
xor eax, edx { check if ID bit changed }
jz @exit { no, CPUID not available }
mov eax, True { yes, CPUID is available }
@exit:
end;
function HasFPU : Boolean; assembler;
var
_FCW : word;
_FSW : word;
asm
mov eax, False { Initialize return register }
mov _FSW, $5A5A { store a non-zero value }
fninit { must use non-wait form }
fnstsw _FSW { store the status }
cmp _FSW, 0 { was the correct status read ? }
jne @exit { no, FPU not available }
fnstcw _FCW { yes, now save control word }
mov dx, _FCW { get the control word }
and dx, $103F { mask the proper status bits }
cmp dx, $3F { is a numeric processor installed ? }
jne @exit { no, FPU not installed }
mov eax, True { yes, FPU is installed }
@exit:
end;
exports
HasCPUID,
HasFPU;
end.
and here is the code of the console app:
program teste;
function HasCPUID: Boolean; external 'cpulib.dll';
begin
if (HasCPUID) then
Writeln('The CPUID instruction is present.')
else
Writeln('No CPUID instruction available.');
end.
Any comments about the problem would be great....
TIA