My operating system's kernel is written in pascal but procedures in it is not working.Example:
procedure Blabla;....
begin
Sample(6);
end;
procedure Sample(Smp:Longint);stdcall;[public,alias:'Sample'];
begin
...
//Smp is always null (Smp's value is zero but assigned 6 to it)
...
end;
My kernel full code is that:
unit kernel;
{$asmmode intel}
interface
type
cardinal = 0..$FFFFFFFF;
hresult = cardinal;
dword = cardinal;
integer = longint;
pchar = ^char;
procedure kmain; stdcall;
procedure Halt; stdcall;
procedure PrintChar(Cr:Char);stdcall;
implementation
procedure kmain; stdcall; [public, alias: 'kmain'];
begin
PrintChar('B');
Halt;
end;
procedure Halt;stdcall; [public, alias: 'Halt'];
begin
asm
@loop:
jmp @loop
end;
end;
procedure PrintChar(Cr:Char);stdcall;[public, alias: 'PrintChar'];
begin
asm
mov ah,0Eh
mov al,Cr
int 10h
end;
end;
begin
asm
call kmain
ret
end;
end.
I compiled it using FPC.PrintChar(B); prints empty char on screen.I can print "A" char using this code in kernel:
procedure PrintA;stdcall;...;
begin
asm
mov ah,0Eh
mov al,'A'
int 10h
end;
end;
I tried to run it to run in diffrent virtual machines but they gave me same result.Interrupt 0x10 is working good.Here is my builder code:
fpc -Aelf -n -O3 -Op3 -Si -Sc -Sg -Xd -CX -XXs -Rintel -Tlinux kernel.pas
ld -Ttext 0x100000 kernel.o -o kernel.out
call C:\qemu\qemu-system-i386 -kernel kernel.out
objcopy -S -O binary kernel.out kernel.bin