Pascal Bare Bones: Difference between revisions

m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
No edit summary
m (Bot: Replace deprecated source tag with syntaxhighlight)
 
(4 intermediate revisions by 2 users not shown)
Line 9:
 
=== stub.asm ===
<sourcesyntaxhighlight lang="asm">
;/////////////////////////////////////////////////////////
;// //
Line 89:
KERNEL_STACK:
resb KERNEL_STACKSIZE
</syntaxhighlight>
</source>
 
=== kernel.pas ===
<sourcesyntaxhighlight lang="pascal">
{
/////////////////////////////////////////////////////////
Line 163:
 
end.
</syntaxhighlight>
</source>
 
=== console.pas ===
<sourcesyntaxhighlight lang="pascal">
{
/////////////////////////////////////////////////////////
Line 314:
 
end.
</syntaxhighlight>
</source>
 
=== multiboot.pas ===
<sourcesyntaxhighlight lang="pascal">
unit multiboot;
 
Line 373:
 
end.
</syntaxhighlight>
</source>
 
=== system.pas ===
Since fpc-3.2.0 there was added necessary parts (in code block that part was highlighted by comment lines), because without them developer could met error like:
<syntaxhighlight lang="bash">
<source>
system.pas(18,1) (system) Parsing implementation of SYSTEM
system.pas(18,1) Fatal: Internal type "TEXCEPTADDR" was not found. Check if you use the correct run time library.
Fatal: Compilation aborted
</syntaxhighlight>
</source>
Valid version of '''system.pas''' on 2022/12/29:
<sourcesyntaxhighlight lang="pascal">
unit system;
 
Line 458:
);
end;
 
var
ExitCode: hresult = 0; export name 'operatingsystem_result';
 
procedure fpc_initializeunits; compilerproc;
 
procedure fpc_do_exit; compilerproc;
 
{ --- End of nessesary part --- }
 
implementation
 
procedure fpc_initializeunits;
begin
end;
 
procedure fpc_do_exit;
begin
end;
 
end.
</syntaxhighlight>
</source>
 
=== Linker script ===
linker.script
<sourcesyntaxhighlight lang="c">
ENTRY(kstart)
SECTIONS
Line 515 ⟶ 500:
end = .; _end = .; __end = .;
}
</syntaxhighlight>
</source>
 
=== Compiling and Linking the modules ===
Assemble stub.asm with:
<sourcesyntaxhighlight lang="bash">nasm -f elf32 stub.asm -o stub.o</sourcesyntaxhighlight>
 
* -f elf32 - needed ''exact'' under x86_64 systems to make correct object file
 
The Pascal modules with:
<sourcesyntaxhighlight lang="bash">fpc -Aelf -n -O3 -Op3 -Si -Sc -Sg -Xd -CX -XXs -Pi386 -Rintel -Tlinux kernel.pas</sourcesyntaxhighlight>
 
* -Aelf - instructs the internal fpc assembler to output an ELF object.;
Line 541 ⟶ 526:
 
Then link the whole thing with:
<sourcesyntaxhighlight lang="bash">i386-elf-ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o</sourcesyntaxhighlight>
 
* --gc-sections -s, in combination with -CX -XXs above, eliminates RTTI symbols from resulting binary
 
In case of trouble linking under x86_64 system try this line:
<sourcesyntaxhighlight lang="bash">i686-elf-ld -A elf-386 --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o system.o console.o</sourcesyntaxhighlight>
 
'''Special sutuation''': last time after building '''binutils''' I've got error
<syntaxhighlight lang="bash">
<source>
i386-linux-ld --gc-sections -s -Tlinker.script -o kernel.obj stub.o kernel.o multiboot.o console.o system.o
ld: i386 architecture of input file `stub.o' is incompatible with i386:x86-64 output
Line 557 ⟶ 542:
ld: i386 architecture of input file `system.o' is incompatible with i386:x86-64 output
make: *** [Makefile:27: _LD] Error 1
</syntaxhighlight>
</source>
That type of error can encounter if ''i386-linux-ld'' have wrong content. In my situation file content edited to:
<sourcesyntaxhighlight lang="bash">
#!/bin/bash
/full/path/to/compiled/cross/binutils/ld-new -A elf32-i386 $@
</syntaxhighlight>
</source>
 
=== makeiso.sh ===
Also a good option is create a bootable ISO file to make run it with VirtualBox or qemu:
 
<sourcesyntaxhighlight lang="bash">
#!/bin/sh
TMPISO=iso
Line 587 ⟶ 572:
grub-mkrescue --output=pascal-kernel.iso iso
rm -rf $TMPISO
</syntaxhighlight>
</source>
 
And simple run:
<sourcesyntaxhighlight lang="bash">qemu-system-i386 pascal-kernel.iso</sourcesyntaxhighlight>
 
=== Alternative compiling: Makefile ===
 
Accumulating the lines from previous part we can make a '''Makefile''':
<sourcesyntaxhighlight lang="bash">
# Freepascal BareboneOS
# Makefile
Line 646 ⟶ 631:
rm -f *.ppu
 
</syntaxhighlight>
</source>
 
==Further Steps==