diff options
Diffstat (limited to 'rtl/freebsd')
-rw-r--r-- | rtl/freebsd/aarch64/bsyscall.inc | 1 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/cprt0.as | 157 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/dllprt0.as | 138 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/gprt0.as | 166 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/prt0.as | 147 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/si_c.inc | 89 | ||||
-rw-r--r-- | rtl/freebsd/aarch64/sighnd.inc | 43 | ||||
-rw-r--r-- | rtl/freebsd/signal.inc | 7 | ||||
-rw-r--r-- | rtl/freebsd/ucontexth.inc | 28 |
9 files changed, 776 insertions, 0 deletions
diff --git a/rtl/freebsd/aarch64/bsyscall.inc b/rtl/freebsd/aarch64/bsyscall.inc new file mode 100644 index 0000000000..c690ebeb2c --- /dev/null +++ b/rtl/freebsd/aarch64/bsyscall.inc @@ -0,0 +1 @@ +{ nothing } diff --git a/rtl/freebsd/aarch64/cprt0.as b/rtl/freebsd/aarch64/cprt0.as new file mode 100644 index 0000000000..da2f2914d6 --- /dev/null +++ b/rtl/freebsd/aarch64/cprt0.as @@ -0,0 +1,157 @@ +/* + Start-up code for Free Pascal Compiler when linking with C library. + +*/ + + .text + .align 2 +#APP + .ident "FreePascal 2.6.x/2.7.x series dynlinked to libc" +#NO_APP + .section .note.ABI-tag,"a",@progbits + .p2align 2 + .type abitag, @object + .size abitag, 24 +abitag: + .long 8 + .long 4 + .long 1 + .string "FreeBSD" + .long 120000 +.globl __progname + .section .rodata + +.LC0: + .string "" + .data + .p2align 3 + .type __progname, @object + .size __progname, 8 +__progname: + .quad .LC0 + .text + .p2align 4,,15 + + .globl _start + .type _start,#function +_start: + /* Initialise FP to zero */ + mov x29,#0 + + /* Get argc, argv, envp */ + ldr x1,[x0] + add x2,x0,#8 + add x3,x1,#1 + add x3,x2,x3,lsl #3 + + /* Save argc, argv, envp, environ, __progname and initial stack pointer */ + adrp x10,:got:operatingsystem_parameter_argc + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argc] + str x1,[x10] + adrp x10,:got:operatingsystem_parameter_argv + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argv] + str x2,[x10] + adrp x10,:got:operatingsystem_parameter_envp + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_envp] + str x3,[x10] + + /* save environ */ + adrp x10,environ + ldr x10,[x10,:lo12:environ] + cbnz x10,.LBB0_2 + ldr x10,=environ + str x3,[x10] +.LBB0_2: + /* save __progname */ + ldr w8,=operatingsystem_parameter_argc + cmp w8,#0 + cset w8,le + tbnz w8,#0,.LBB0_9 +// %bb.1: + adrp x8,operatingsystem_parameter_argv + ldr x8,[x8,:lo12:operatingsystem_parameter_argv] + cbz x8,.LBB0_9 +// %bb.2: + ldr x2,[x2] + adrp x9,__progname + adrp x10,__progname + add x10,x10,:lo12:__progname + str x2,[x10] + ldr x8,[x9,:lo12:__progname] + adrp x9,s + add x9,x9,:lo12:s + str x8,[x9] +.LBB0_3: + adrp x8,s + ldr x8,[x8,:lo12:s] + ldrb w9,[x8] + cbz w9,.LBB0_8 +// %bb.4: + adrp x8,s + ldr x8,[x8, :lo12:s] + ldrb w9,[x8] + cmp w9,#47 + b.ne .LBB0_6 +// %bb.5: + adrp x8,s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + adrp x9,__progname + add x9,x9,:lo12:__progname + str x8,[x9] +.LBB0_6: +// %bb.7: + adrp x8,s + adrp x9,s + add x9,x9,:lo12:s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + str x8,[x9] + b .LBB0_3 +.LBB0_8: +.LBB0_9: + /* save stack pointer */ + adrp x10,:got:__stkptr + ldr x10,[x10,#:got_lo12:__stkptr] + mov x6,sp + str x6,[x10] + + bl PASCALMAIN + + /* This should never happen */ + b abort + + .globl _haltproc + .type _haltproc,#function +_haltproc: + adrp x0,:got:operatingsystem_result + ldr x0,[x0,#:got_lo12:operatingsystem_result] + ldr w0,[x0] + mov w8,#1 // SYS_exit + svc #0 + b _haltproc + + /* Define a symbol for the first piece of initialized data. */ + .data + .align 3 + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + + .bss + .align 3 + + .comm __stkptr,8 + + .comm operatingsystem_parameter_envp,8 + .comm operatingsystem_parameter_argc,8 + .comm operatingsystem_parameter_argv,8 + .comm environ,8,8 + +s: + .xword 0 + .size s, 8 + + .section .note.GNU-stack,"",%progbits diff --git a/rtl/freebsd/aarch64/dllprt0.as b/rtl/freebsd/aarch64/dllprt0.as new file mode 100644 index 0000000000..ce71bdd4e3 --- /dev/null +++ b/rtl/freebsd/aarch64/dllprt0.as @@ -0,0 +1,138 @@ +/* + Start-up code for Free Pascal Compiler in a shared library, + not linking with C library. + +*/ + + .text + .align 2 + + .globl _startlib + .type _startlib,#function +_startlib: + .globl FPC_SHARED_LIB_START + .type FPC_SHARED_LIB_START,#function +FPC_SHARED_LIB_START: + stp x29,x30,[sp,#-16]! + + /* Get argc, argv, envp */ + ldr x1,[x0] + add x2,x0,#8 + add x3,x1,#1 + add x3,x2,x3,lsl #3 + + /* Save argc, argv and envp */ + adrp x9,:got:operatingsystem_parameter_argc + ldr x9,[x9,#:got_lo12:operatingsystem_parameter_argc] + str x1,[x9] + adrp x9,:got:operatingsystem_parameter_argv + ldr x9,[x9,#:got_lo12:operatingsystem_parameter_argv] + str x2,[x9] + adrp x9,:got:operatingsystem_parameter_envp + ldr x9,[x9,#:got_lo12:operatingsystem_parameter_envp] + str x3,[x9] + + /* save environ */ + adrp x10,environ + ldr x10,[x10,:lo12:environ] + cbnz x10,.LBB0_2 + adrp x10,environ + add x10,x9,:lo12:environ + str x3,[x10] +.LBB0_2: + /* save __progname */ + adrp x8,:got:operatingsystem_parameter_argc + ldr x8,[x8,#:got_lo12:operatingsystem_parameter_argc] + cmp x8,#0 + cset x8,le + tbnz x8,#0,.LBB0_9 +// %bb.1: + adrp x8,operatingsystem_parameter_argv + ldr x8,[x8,:got_lo12:operatingsystem_parameter_argv] + cbz x8,.LBB0_9 +// %bb.2: + ldr x2,[x2] + adrp x9,:got:__progname + adrp x10,:got:__progname + add x10,x10,:lo12:__progname + str x2,[x10] + ldr x8,[x9,:got_lo12:__progname] + adrp x9,s + add x9,x9,:lo12:s + str x8,[x9] +.LBB0_3: + adrp x8,s + ldr x8,[x8,:lo12:s] + ldrb w9,[x8] + cbz w9,.LBB0_8 +// %bb.4: + adrp x8,s + ldr x8,[x8, :lo12:s] + ldrb w9,[x8] + cmp w9,#47 + b.ne .LBB0_6 +// %bb.5: + adrp x8,s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + adrp x9,:got:__progname + add x9,x9,:lo12:__progname + str x8,[x9] +.LBB0_6: +// %bb.7: + adrp x8,s + adrp x9,s + add x9,x9,:lo12:s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + str x8,[x9] + b .LBB0_3 +.LBB0_8: +.LBB0_9: + /* Save initial stackpointer */ + adrp x9,:got:__stkptr + ldr x9,[x9,#:got_lo12:__stkptr] + mov x10,sp + str x10,[x9] + + /* Call main */ + bl PASCALMAIN + + /* Return */ + ldp x29,x30,[sp],#16 + ret + + .globl _haltproc + .type _haltproc,#function +_haltproc: + adrp x0,:got:operatingsystem_result + ldr x0,[x0,#:got_lo12:operatingsystem_result] + ldr w0,[x0] + mov w8,#1 // SYS_exit + svc #0 + b _haltproc + + /* Define a symbol for the first piece of initialized data. */ + .data + .align 3 + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + + .bss + .align 3 + + .comm __stkptr,8 + + .comm operatingsystem_parameter_envp,8 + .comm operatingsystem_parameter_argc,8 + .comm operatingsystem_parameter_argv,8 + .comm environ,8,8 + +s: + .xword 0 + .size s, 8 + + .section .note.GNU-stack,"",%progbits diff --git a/rtl/freebsd/aarch64/gprt0.as b/rtl/freebsd/aarch64/gprt0.as new file mode 100644 index 0000000000..006479e9e7 --- /dev/null +++ b/rtl/freebsd/aarch64/gprt0.as @@ -0,0 +1,166 @@ +/* + Start-up code for Free Pascal Compiler when linking with C library + with profiling support. +*/ + + .text + .align 2 + + .globl _start + .type _start,#function +_start: + /* Initialise FP to zero */ + mov x29,#0 + + /* Get argc, argv, envp */ + ldr x1,[x0] + add x2,x0,#8 + add x11,x1,#1 + add x11,x2,x11,lsl #3 + + /* Save argc, argv, envp, and initial stack pointer */ + adrp x10,:got:operatingsystem_parameter_argc + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argc] + str x1,[x10] + adrp x10,:got:operatingsystem_parameter_argv + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_argv] + str x2,[x10] + adrp x10,:got:operatingsystem_parameter_envp + ldr x10,[x10,#:got_lo12:operatingsystem_parameter_envp] + str x3,[x10] + + /* save environ */ + adrp x10,environ + ldr x10,[x10,:lo12:environ] + cbnz x10,.LBB0_2 + ldr x10,=environ + str x3,[x10] +.LBB0_2: + /* save __progname */ + ldr w8,=operatingsystem_parameter_argc + cmp w8,#0 + cset w8,le + tbnz w8,#0,.LBB0_9 +// %bb.1: + adrp x8,operatingsystem_parameter_argv + ldr x8,[x8,:lo12:operatingsystem_parameter_argv] + cbz x8,.LBB0_9 +// %bb.2: + ldr x2,[x2] + adrp x9,__progname + adrp x10,__progname + add x10,x10,:lo12:__progname + str x2,[x10] + ldr x8,[x9,:lo12:__progname] + adrp x9,s + add x9,x9,:lo12:s + str x8,[x9] +.LBB0_3: + adrp x8,s + ldr x8,[x8,:lo12:s] + ldrb w9,[x8] + cbz w9,.LBB0_8 +// %bb.4: + adrp x8,s + ldr x8,[x8, :lo12:s] + ldrb w9,[x8] + cmp w9,#47 + b.ne .LBB0_6 +// %bb.5: + adrp x8,s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + adrp x9,__progname + add x9,x9,:lo12:__progname + str x8,[x9] +.LBB0_6: +// %bb.7: + adrp x8,s + adrp x9,s + add x9,x9,:lo12:s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + str x8,[x9] + b .LBB0_3 +.LBB0_8: +.LBB0_9: + adrp x10,:got:__stkptr + ldr x10,[x10,#:got_lo12:__stkptr] + mov x6,sp + str x6,[x10] + + bl main + + /* This should never happen */ + b abort + + .globl _init_dummy + .type _init_dummy,#function +_init_dummy: + ret + + .globl _fini_dummy + .type _fini_dummy,#function +_fini_dummy: + ret + + .globl main_stub + .type main_stub,#function +main_stub: + stp x29,x30,[sp,#-16]! + + /* Save initial stackpointer */ + mov x0,sp + adrp x1,:got:__stkptr + ldr x1,[x1,#:got_lo12:__stkptr] + str x0,[x1] + + /* Initialize gmon */ + adrp x0,:got:_start + ldr x0,[x0,#:got_lo12:_start] + adrp x1,:got:_etext + ldr x1,[x1,#:got_lo12:_etext] + bl __monstartup + adrp x0,:got:_mcleanup + ldr x0,[x0,#:got_lo12:_mcleanup] + bl atexit + + /* Start the program */ + bl PASCALMAIN + b abort + + .globl _haltproc + .type _haltproc,#function +_haltproc: + /* Return to libc */ + adrp x1,:got:__stkptr + ldr x1,[x1,#:got_lo12:__stkptr] + ldr x1,[x1] + mov sp,x1 + ldp x29,x30,[sp],#16 + ret + + /* Define a symbol for the first piece of initialized data. */ + .data + .align 3 + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + + .bss + .align 3 + + .comm __stkptr,8 + + .comm operatingsystem_parameter_envp,8 + .comm operatingsystem_parameter_argc,8 + .comm operatingsystem_parameter_argv,8 + .comm environ,8,8 + +s: + .xword 0 + .size s, 8 + + .section .note.GNU-stack,"",%progbits diff --git a/rtl/freebsd/aarch64/prt0.as b/rtl/freebsd/aarch64/prt0.as new file mode 100644 index 0000000000..cb5a5bc075 --- /dev/null +++ b/rtl/freebsd/aarch64/prt0.as @@ -0,0 +1,147 @@ +/* + Start-up code for Free Pascal Compiler, not in a shared library, + not linking with C library. +*/ + + .text + .align 2 + +#APP + .ident "FreeBSD" +#NO_APP + .section .note.ABI-tag,"a",@progbits + .p2align 2 + .type abitag, @object + .size abitag, 24 +abitag: + .long 8 + .long 4 + .long 1 + .string "FreeBSD" + .long 120000 + + .section .rodata +.LC0: + .string "" +.globl __progname + .data + .p2align 3 + .type __progname, @object + .size __progname, 8 +__progname: + .quad .LC0 + .text + .p2align 2,,3 + + .globl _start + .type _start,#function +_start: + /* Initialise FP to zero */ + mov x29,#0 + + /* Get argc, argv, envp */ + ldr x1,[x0] + add x2,x0,#8 + add x11,x1,#1 + add x11,x2,x11,lsl #3 + + /* Save argc, argv, envp, environ, __progname and initial stack pointer */ + ldr x10,=operatingsystem_parameter_argc + str x1,[x10] + ldr x10,=operatingsystem_parameter_argv + str x2,[x10] + ldr x10,=operatingsystem_parameter_envp + str x11,[x10] + + /* save environ */ + adrp x10,environ + ldr x10,[x10,:lo12:environ] + cbnz x10,.LBB0_2 + ldr x10,=environ + str x11,[x10] +.LBB0_2: + /* save __progname */ + ldr w8,=operatingsystem_parameter_argc + cmp w8,#0 + cset w8,le + tbnz w8,#0,.LBB0_9 +// %bb.1: + adrp x8,operatingsystem_parameter_argv + ldr x8,[x8,:lo12:operatingsystem_parameter_argv] + cbz x8,.LBB0_9 +// %bb.2: + ldr x2,[x2] + adrp x9,__progname + adrp x10,__progname + add x10,x10,:lo12:__progname + str x2,[x10] + ldr x8,[x9,:lo12:__progname] + adrp x9,s + add x9,x9,:lo12:s + str x8,[x9] +.LBB0_3: + adrp x8,s + ldr x8,[x8,:lo12:s] + ldrb w9,[x8] + cbz w9,.LBB0_8 +// %bb.4: + adrp x8,s + ldr x8,[x8, :lo12:s] + ldrb w9,[x8] + cmp w9,#47 + b.ne .LBB0_6 +// %bb.5: + adrp x8,s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + adrp x9,__progname + add x9,x9,:lo12:__progname + str x8,[x9] +.LBB0_6: +// %bb.7: + adrp x8,s + adrp x9,s + add x9,x9,:lo12:s + ldr x8,[x8,:lo12:s] + add x8,x8,#1 + str x8,[x9] + b .LBB0_3 +.LBB0_8: +.LBB0_9: + /* save stack pointer */ + ldr x10,=__stkptr + mov x6,sp + str x6,[x10] + + /* Call main */ + bl PASCALMAIN + + ldr x10,=operatingsystem_result + ldr w0,[x10] + mov w8,#1 // SYS_exit + svc #0 + + /* Define a symbol for the first piece of initialized data. */ + .data + .align 3 + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + + .bss + .align 3 + + .comm __stkptr,8 + + .comm operatingsystem_parameter_envp,8 + .comm operatingsystem_parameter_argc,8 + .comm operatingsystem_parameter_argv,8 + .comm environ,8,8 + +s: + .xword 0 + .size s, 8 + + .section .note.GNU-stack,"",%progbits diff --git a/rtl/freebsd/aarch64/si_c.inc b/rtl/freebsd/aarch64/si_c.inc new file mode 100644 index 0000000000..8d98c22063 --- /dev/null +++ b/rtl/freebsd/aarch64/si_c.inc @@ -0,0 +1,89 @@ + +Type + TCleanup = procedure; cdecl; + +var + environ : ppchar; cvar; public name '__environ'; + progname: pchar = #0#0; cvar; public name '__progname'; + dynamic : pchar; external name '_DYNAMIC'; // #pragma weak + +procedure atexit(prc:TCleanup); cdecl external name 'atexit'; +procedure cleanup(prc:TCleanup); cdecl external name 'cleanup'; +procedure init_tls; cdecl; external name 'init_tls'; +procedure fini; cdecl; external name '_fini'; +procedure init; cdecl; external name '_init'; +procedure libc_exit(exitcode:longint);cdecl; external name 'exit'; +function main(nrarg:longint;pp:ppchar;env:ppchar):longint; cdecl; external name 'main'; + +{$ifdef gcrt} + procedure cmcleanup; cdecl; external name '_mcleanup'; + procedure monstratup(p,p2:pointer); cdecl; external name 'monstartup'; + +var + eprol:longint; external name 'eprol'; + etext:longint; external name 'etext'; +{$endif} + +procedure start(ap:ppchar;cleanup:TCleanup); + +var argc: longint; + argv: ppchar; + env : ppchar; + s : pchar; +begin + argc:=plongint(ap)^; + argv:=ppchar(ap[1]); + env:= ppchar(ap[2+argc]); + environ:=env; + if (argc>0) and (argv[0]<>#0) Then + begin + progname:=argv[0]; + s:=progname; + while s^<>#0 do + begin + if s^='/' then + progname:=@s[1]; + inc(s); + end; + end; + if assigned(pchar(@dynamic)) then // I suspect this is a trick to find + // out runtime if we are shared + // linking, so the same code can be used + // for static and shared linking + atexit(cleanup) + else + init_tls; + {$ifdef GCRT} + atexit(@_mcleanup); + {$endif} + atexit(@fini); + {$ifdef GCRT} + monstartup(@eprol,@etext); + asm + eprol: + end; + {$endif} + init; + libc_exit(main(argc,argv,env)); // doesn't return + asm + { We need this stuff to make gdb behave itself, otherwise + gdb will chokes with SIGILL when trying to debug apps. + } + .section ".note.ABI-tag", "a" + .align 4 + .long 8 + .long 4 + .long 1 + .asciz "FreeBSD" + .align 4 + .long 900044 + .align 4 + .section .note.GNU-stack,"",@progbits + end; +end; + + + +begin +end. + diff --git a/rtl/freebsd/aarch64/sighnd.inc b/rtl/freebsd/aarch64/sighnd.inc new file mode 100644 index 0000000000..1d58896909 --- /dev/null +++ b/rtl/freebsd/aarch64/sighnd.inc @@ -0,0 +1,43 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by Michael Van Canneyt, + member of the Free Pascal development team. + + Signal handler is arch dependant due to processor to language + exception conversion. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} + +{ procedure SignalToRunerror(Sig: longint; SigInfo: PSigInfo; UContext: PUContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl; } +procedure SignalToRunerror(Sig: cint; info : psiginfo; SigContext:PSigContext); public name '_FPC_DEFAULTSIGHANDLER'; cdecl; + +var + res : word; +begin + res:=0; + case sig of + SIGFPE: + res:=207; + SIGILL: + res:=216; + SIGSEGV : + res:=216; + SIGBUS: + res:=214; + SIGINT: + res:=217; + SIGQUIT: + res:=233; + end; + reenable_signal(sig); + { give runtime error at the position where the signal was raised } + if res<>0 then + HandleError(res); +end; diff --git a/rtl/freebsd/signal.inc b/rtl/freebsd/signal.inc index a978ea5f04..eeddb2e550 100644 --- a/rtl/freebsd/signal.inc +++ b/rtl/freebsd/signal.inc @@ -80,6 +80,7 @@ type sigset_t = array[0..3] of Longint; psigcontext = ^sigcontextrec; PSigContextRec = ^SigContextRec; +{$if (defined(CPUi386) or defined(CPUX86_64))} SigContextRec = record sc_mask : sigset_t; { signal mask to restore } sc_onstack : longint; { sigstack state to restore } @@ -120,8 +121,14 @@ type sigset_t = array[0..3] of Longint; fpr_ex_sw : cardinal; fpr_pad : array[0..63] of char; end; +{$endif def x86} +{$ifdef CPUAARCH64} + SigContextRec = record + _dummy : cint; + end; +{$endif cpuaarch64} Sigval = Record Case Boolean OF diff --git a/rtl/freebsd/ucontexth.inc b/rtl/freebsd/ucontexth.inc index aec4d8c69d..05cb11bcb0 100644 --- a/rtl/freebsd/ucontexth.inc +++ b/rtl/freebsd/ucontexth.inc @@ -20,6 +20,7 @@ type end; {$packrecords C} +{$if (defined(CPUi386) or defined(CPUX86_64))} mcontext_t = record {* * The first 20 fields must match the definition of @@ -53,7 +54,34 @@ type mc_fpstate: TMCFPStateArray; mc_spare2: array[0..7] of cInt; end; +{$endif def x86} +{$ifdef CPUAARCH64} + gpregs = record + gp_x: array[0..30] of cInt; { __register_t gp_x[30]; } + gp_lr: cInt; + gp_sp: cInt; + gp_elr: cInt; + gp_spsr: cuint32; + gp_pad: cInt; + end; + + fpregs = record + fp_q: array[0..64] of cInt; { __uint128_t fp_q[32] } + fp_sr: cuint32; + fp_cr: cuint32; + fp_flags: cInt; + fp_pad: cInt; + end; + + mcontext_t = record + mc_gpregs: gpregs; + mc_fpregs: fpregs; + mc_flags: cint32; + mc_pad: cint32; + mc_spare: array[0..8] of cInt; + end; +{$endif cpuaarch64} pucontext_t = ^ucontext_t; ucontext_t = record // required for kse threads |