This is a trivial hello-world Free Pascal application. It does't currently work because of missing syscall instruction support. https://github.com/cloudius-systems/osv/issues/590 Hopefully it will begin working when OSv adds syscall instruction support.
Stack trace we get in fpc initialization function: 4 0x0000000000482754 in invalid_opcode (ef=0xffff800002a2b088) at arch/x64/exceptions.cc:320 5 <signal handler called> 6 0x0000100000c07b72 in SYSTEM_$$_FPSYSCALL$INT64$INT64$INT64$$INT64 () 7 0x0000100000c0839a in SYSTEM_$$_FPGETRLIMIT$LONGINT$PRLIMIT$$LONGINT () 8 0x0000000c000ff3b0 in ?? () 9 0x0000100000c2a357 in SYSTEM_$$_CHECKINITIALSTKLEN$QWORD$$QWORD () 10 0x0000000000000000 in ?? () Note that to see these function names, you'll need to remove the strip command from the script ppash.sh automatically generated by fpc, and run it again. This example was based on http://wiki.lazarus.freepascal.org/Free_Pascal_on_OSv but I wanted to not need the special linking instructions. Signed-off-by: Nadav Har'El <n...@scylladb.com> --- fpc-example/module.py | 3 +++ fpc-example/Makefile | 11 +++++++++++ fpc-example/README | 1 + fpc-example/fpc-hello.pas | 20 ++++++++++++++++++++ fpc-example/usr.manifest | 1 + 5 files changed, 36 insertions(+) create mode 100644 fpc-example/module.py create mode 100644 fpc-example/Makefile create mode 100644 fpc-example/README create mode 100644 fpc-example/fpc-hello.pas create mode 100644 fpc-example/usr.manifest diff --git a/fpc-example/module.py b/fpc-example/module.py new file mode 100644 index 0000000..cc4b4bd --- /dev/null +++ b/fpc-example/module.py @@ -0,0 +1,3 @@ +from osv.modules import api + +default = api.run("/fpc-hello") diff --git a/fpc-example/Makefile b/fpc-example/Makefile new file mode 100644 index 0000000..3733869 --- /dev/null +++ b/fpc-example/Makefile @@ -0,0 +1,11 @@ +.PHONY: module +module: fpc-hello + + +fpc-hello: fpc-hello.pas + fpc -fPIC -XD -Xc -s -ofpc-hello fpc-hello.pas + # if we drop -init and -fini from link line, it works. Like this it doesn't, currently. + sh ppas.sh + +clean: + rm -f fpc-hello fpc-hello.o link.res ppas.sh diff --git a/fpc-example/README b/fpc-example/README new file mode 100644 index 0000000..8eb493d --- /dev/null +++ b/fpc-example/README @@ -0,0 +1 @@ +Doesn't work - check out https://github.com/cloudius-systems/osv/issues/590 diff --git a/fpc-example/fpc-hello.pas b/fpc-example/fpc-hello.pas new file mode 100644 index 0000000..3659f42 --- /dev/null +++ b/fpc-example/fpc-hello.pas @@ -0,0 +1,20 @@ +library hello; + +uses + unixtype; + +// use the C function 'write' +function CWrite(fd : cInt; buf:pChar; nbytes : unixtype.TSize): TSsize; external name 'write'; + +// start function for OSv +function main: longint; cdecl; +const + MyText: PChar = 'It works!'; +begin + CWrite(StdOutputHandle,MyText,strlen(MyText)); + main:=0; +end; + +exports main name 'main'; // OSv searches for 'main' in the library + +end. diff --git a/fpc-example/usr.manifest b/fpc-example/usr.manifest new file mode 100644 index 0000000..c3c1304 --- /dev/null +++ b/fpc-example/usr.manifest @@ -0,0 +1 @@ +/fpc-hello: ${MODULE_DIR}/fpc-hello -- 2.7.4 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.