summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-03-12 21:27:51 +0000
committerflorian <florian@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-03-12 21:27:51 +0000
commite4012965427d70001bee905e09fe3b5ced50d599 (patch)
treea091c3343f465ef82e4d7c48de2301e98de0e2ca
parent960c2b1f75a5b611df7fc228cf41c0cf262754c1 (diff)
downloadfpc-e4012965427d70001bee905e09fe3b5ced50d599.tar.gz
+ RiscV: initial implementation of gprof support
* cleanup git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@48945 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--rtl/linux/Makefile2
-rw-r--r--rtl/linux/Makefile.fpc2
-rw-r--r--rtl/linux/riscv64/si_c.inc4
-rw-r--r--rtl/linux/riscv64/si_g.inc106
4 files changed, 108 insertions, 6 deletions
diff --git a/rtl/linux/Makefile b/rtl/linux/Makefile
index 62da828ee1..4db1d00e38 100644
--- a/rtl/linux/Makefile
+++ b/rtl/linux/Makefile
@@ -382,7 +382,7 @@ SYSINIT_UNITS=si_prc si_dll si_c
endif
ifeq ($(ARCH),riscv64)
override LOADERS=
-SYSINIT_UNITS=si_prc si_dll si_c
+SYSINIT_UNITS=si_prc si_dll si_c si_g
endif
ifeq ($(ARCH),mipsel)
override FPCOPT+=-Ur
diff --git a/rtl/linux/Makefile.fpc b/rtl/linux/Makefile.fpc
index 310d467d84..fca8b2ef55 100644
--- a/rtl/linux/Makefile.fpc
+++ b/rtl/linux/Makefile.fpc
@@ -98,7 +98,7 @@ endif
ifeq ($(ARCH),riscv64)
override LOADERS=
-SYSINIT_UNITS=si_prc si_dll si_c
+SYSINIT_UNITS=si_prc si_dll si_c si_g
endif
# mipsel reuses mips files by including so some file names exist
diff --git a/rtl/linux/riscv64/si_c.inc b/rtl/linux/riscv64/si_c.inc
index 2319967c40..87dcd050b6 100644
--- a/rtl/linux/riscv64/si_c.inc
+++ b/rtl/linux/riscv64/si_c.inc
@@ -16,11 +16,7 @@
******************************************************************************}
var
- dlexitproc : pointer;
-
-var
BSS_START: record end; external name '__bss_start';
- STACK_PTR: record end; external name '__stkptr';
{ as we do not call these procedures directly, calling conventions do not matter and
even if we did, we use c calling conventions anyways }
diff --git a/rtl/linux/riscv64/si_g.inc b/rtl/linux/riscv64/si_g.inc
new file mode 100644
index 0000000000..64131f8948
--- /dev/null
+++ b/rtl/linux/riscv64/si_g.inc
@@ -0,0 +1,106 @@
+{
+ This file is part of the Free Pascal run time library.
+ Copyright (c) 2019 by Jeppe Johansen.
+
+ 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.
+
+ **********************************************************************}
+
+{******************************************************************************
+ Process start/halt
+ ******************************************************************************}
+{$linklib c}
+{$linklib gcc}
+
+var
+ BSS_START: record end; external name '__bss_start';
+ _etext: pointer; external name '_etext';
+
+{ as we do not call these procedures directly, calling conventions do not matter and
+ even if we did, we use c calling conventions anyways }
+procedure __libc_csu_init; external name '__libc_csu_init';
+procedure __libc_csu_fini; external name '__libc_csu_fini';
+
+procedure libc_start_main(main: TProcedure; argc: ptruint; argv: ppchar; init, fini, rtld_fini: TProcedure; stack_end: pointer); cdecl; external name '__libc_start_main';
+procedure libc_exit(code: ptruint); cdecl; external name 'exit';
+
+procedure monstartup(low_pc,high_pc: pointer); cdecl; external;
+procedure _mcleanup; cdecl; external;
+procedure atexit(p: pointer); cdecl; external;
+
+procedure _FPC_rv_enter(at_exit: TProcedure; sp: pptruint);
+ var
+ argc: ptruint;
+ argv: ppchar;
+ begin
+ argc:=sp[0];
+ argv:=@sp[1];
+
+ initialstkptr:=sp;
+ operatingsystem_parameter_argc:=argc;
+ operatingsystem_parameter_argv:=argv;
+ operatingsystem_parameter_envp:=@sp[argc+2];
+
+ monstartup(@_FPC_rv_enter,@_etext);
+ atexit(@_mcleanup);
+
+ libc_start_main(@PascalMain, argc, argv, @__libc_csu_init, @__libc_csu_fini, at_exit, sp);
+ end;
+
+
+procedure _FPC_proc_start; assembler; nostackframe; public name '_start';
+ asm
+ { set up GP }
+ .option push
+ .option norelax
+.L1:
+ auipc gp, %pcrel_hi(BSS_START+0x800)
+ addi gp, gp, %pcrel_lo(.L1)
+ .option pop
+
+ { Initialise FP to zero }
+ addi fp, x0, 0
+
+ { atexit is in a0 }
+ addi a1, sp, 0
+ jal x1, _FPC_rv_enter
+ end;
+
+
+procedure _FPC_rv_exit(e:longint); assembler; nostackframe;
+ asm
+ addi a7, x0, 94
+ ecall
+ end;
+
+
+procedure _FPC_proc_haltproc(e:longint); cdecl; public name '_haltproc';
+ begin
+ while true do
+ begin
+ libc_exit(e);
+ _FPC_rv_exit(e);
+ end;
+ end;
+
+
+ procedure initgp; assembler; nostackframe;
+ asm
+ .Linitgp:
+ .option push
+ .option norelax
+ .L1:
+ auipc gp, %pcrel_hi(BSS_START+0x800)
+ addi gp, gp, %pcrel_lo(.L1)
+ .option pop
+ jalr x0, x1
+
+ .section ".preinit_array","aw"
+ .dc.a .Linitgp
+ .text
+ end;