2

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
user2590769
  • 75
  • 1
  • 10
  • 1
    If you can use `int 10h` that means you are still in real mode, so verify fpc generates real mode code (which I doubt). – Jester Jul 15 '15 at 16:09
  • How can i verify it? @Jester – user2590769 Jul 15 '15 at 16:30
  • I don't think fpc can produce 16 bit real mode code, at least it isn't obvious from a glance at the documentation. `-Aelf` is certainly 32 bit code. – Jester Jul 15 '15 at 16:34
  • I know that it does not supports 16 bit codes but it does not working with 32 bit codes too.I gave an example on assembly but it does not work with any kind of code. – user2590769 Jul 15 '15 at 16:40
  • In 32 bit protected mode you can't simply use `int 10h` so that's out of the question already. Furthermore, you need to check your virtual machine's documentation as to whether it switches to protected mode for you or not, in which case you will have to do it yourself. – Jester Jul 15 '15 at 16:48
  • The problem here is not int 10h.All of the interrupts are working!I mean problem here is not with protected mode or real mode. http://wiki.osdev.org/Pascal_Bare_Bones that code is working but when i try to insert it to my kernel it prints empty -.- – user2590769 Jul 15 '15 at 16:54
  • The osdev link **does** include multiboot header so that **is** 32 bit code, and that **does not** use interrupts for printing since those do not work in protected mode. The very fact that your interrupt is working means you are still in 16 bit real mode, but fpc creates code for 32 bit which will cause your problems. – Jester Jul 15 '15 at 17:05
  • I can use Interrupts in osdev link.And it is working fine!Problem here is not with protected mode.I am pretty sure about it. – user2590769 Jul 15 '15 at 17:11
  • 1
    The only way `int 10h` can work is if you omit the multiboot stuff from the osdev code and then you stay in 16 bit real mode, but then other stuff will break because fpc expects 32 bit mode (as you can see...) I am pretty sure that is your problem :) – Jester Jul 15 '15 at 17:25
  • I tried to make it run on kernel code and it worked fine :D When i take code which can print to screen on 32 bit protected mode it also not working because Procedure variable is always empty. – user2590769 Jul 15 '15 at 17:40
  • Did you include the multiboot stuff and the `stub.asm`? Otherwise you stay in real mode and it won't work ... just doing what you posted in the questions **is not enough**. – Jester Jul 15 '15 at 17:44
  • Jester do you have e mail? – user2590769 Jul 15 '15 at 17:50
  • Only the upcoming FPC 3.0.x will support 16-bit real mode. The most logical would be to inspect the generated code with fpc -a or objdump, stdcall means first param is in eax, so it seems all logical – Marco van de Voort Jul 21 '15 at 14:01
  • stdcall is a stack convention, change it to "register" to make it a register cc. – Marco van de Voort Jul 21 '15 at 18:37
  • @MarcovandeVoort It is still not working with register Here is my sample www.afcos.comuf.com/OSSAMPLE.7z – user2590769 Jul 22 '15 at 15:54
  • Is this still an issue? Can you give the output of `objdump -xtTG kernel.out` ? – Daniel Jour Oct 08 '15 at 17:46

0 Answers0