2
0
Эх сурвалжийг харах

Added library search paths.
Removed GP and TP from allocatable registers for now. GP should not be overwritten.
Ported dllprt0.as
Fixed register usage in cprt0.as

git-svn-id: branches/laksen/riscv_new@39522 -

Jeppe Johansen 7 жил өмнө
parent
commit
90d5f5e760

+ 0 - 1
compiler/riscv64/cgcpu.pas

@@ -71,7 +71,6 @@ implementation
           [RS_X10,RS_X11,RS_X12,RS_X13,RS_X14,RS_X15,RS_X16,RS_X17,
           [RS_X10,RS_X11,RS_X12,RS_X13,RS_X14,RS_X15,RS_X16,RS_X17,
            RS_X31,RS_X30,RS_X29,RS_X28,
            RS_X31,RS_X30,RS_X29,RS_X28,
            RS_X5,RS_X6,RS_X7,
            RS_X5,RS_X6,RS_X7,
-           RS_X3,RS_X4,
            RS_X9,RS_X27,RS_X26,RS_X25,RS_X24,RS_X23,RS_X22,
            RS_X9,RS_X27,RS_X26,RS_X25,RS_X24,RS_X23,RS_X22,
            RS_X21,RS_X20,RS_X19,RS_X18],first_int_imreg,[]);
            RS_X21,RS_X20,RS_X19,RS_X18],first_int_imreg,[]);
         rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,
         rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBNONE,

+ 6 - 0
compiler/systems/t_linux.pas

@@ -181,6 +181,12 @@ begin
 {$ifdef sparc64}
 {$ifdef sparc64}
       LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/sparc64-linux-gnu',true);
       LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/sparc64-linux-gnu',true);
 {$endif sparc64}
 {$endif sparc64}
+{$ifdef riscv32}
+      LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/riscv32-linux-gnu',true);
+{$endif riscv32}
+{$ifdef riscv64}
+      LibrarySearchPath.AddPath(sysrootpath,'/usr/lib/riscv64-linux-gnu',true);
+{$endif riscv64}
     end;
     end;
 end;
 end;
 
 

+ 2 - 2
rtl/linux/Makefile

@@ -1,5 +1,5 @@
 #
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2018/07/20]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2018-07-20 rev 39474]
 #
 #
 default: all
 default: all
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded
 MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-netbsd m68k-amiga m68k-atari m68k-palmos m68k-macos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-iphonesim x86_64-aros x86_64-dragonfly arm-linux arm-netbsd arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android arm-aros powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-embedded i8086-msdos i8086-win16 aarch64-linux aarch64-darwin wasm-wasm sparc64-linux riscv32-linux riscv32-embedded riscv64-linux riscv64-embedded
@@ -361,7 +361,7 @@ override LOADERS=
 SYSINIT_UNITS=si_prc si_c si_g si_dll
 SYSINIT_UNITS=si_prc si_c si_g si_dll
 endif
 endif
 ifeq ($(ARCH),riscv64)
 ifeq ($(ARCH),riscv64)
-override LOADERS=prt0 cprt0
+override LOADERS=prt0 cprt0 dllprt0
 endif
 endif
 ifeq ($(ARCH),mipsel)
 ifeq ($(ARCH),mipsel)
 override FPCOPT+=-Ur
 override FPCOPT+=-Ur

+ 1 - 1
rtl/linux/Makefile.fpc

@@ -91,7 +91,7 @@ SYSINIT_UNITS=si_prc si_c si_g si_dll
 endif
 endif
 
 
 ifeq ($(ARCH),riscv64)
 ifeq ($(ARCH),riscv64)
-override LOADERS=prt0 cprt0
+override LOADERS=prt0 cprt0 dllprt0
 endif
 endif
 
 
 # mipsel reuses mips files by including so some file names exist
 # mipsel reuses mips files by including so some file names exist

+ 25 - 38
rtl/linux/riscv64/cprt0.as

@@ -26,17 +26,17 @@
 
 
         At this entry point, most registers' values are unspecified, except:
         At this entry point, most registers' values are unspecified, except:
 
 
-   a1           Contains a function pointer to be registered with `atexit'.
+   a0           Contains a function pointer to be registered with `atexit'.
                 This is how the dynamic linker arranges to have DT_FINI
                 This is how the dynamic linker arranges to have DT_FINI
                 functions called for shared libraries that have been loaded
                 functions called for shared libraries that have been loaded
                 before this code runs.
                 before this code runs.
 
 
    sp           The stack contains the arguments and environment:
    sp           The stack contains the arguments and environment:
                 0(sp)                   argc
                 0(sp)                   argc
-                4(sp)                   argv[0]
+                8(sp)                   argv[0]
                 ...
                 ...
-                (4*argc)(sp)            NULL
-                (4*(argc+1))(sp)        envp[0]
+                (8*argc)(sp)            NULL
+                (8*(argc+1))(sp)        envp[0]
                 ...
                 ...
                                         NULL
                                         NULL
 */
 */
@@ -51,21 +51,23 @@ _start:
         addi  gp, gp, %pcrel_lo(1b)
         addi  gp, gp, %pcrel_lo(1b)
         .option pop
         .option pop
 
 
+        /* Store rtld_fini in a5 */
+        addi a5, a0, 0
+
         /* Clear the frame pointer since this is the outermost frame.  */
         /* Clear the frame pointer since this is the outermost frame.  */
         addi x8, x0, 0
         addi x8, x0, 0
-        ld   a2, 0(sp)
-        addi sp, sp, 8
 
 
-        /* Pop argc off the stack and save a pointer to argv */
-1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argc)
-	sd	a2,%pcrel_lo(1b)(x8)
-1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argv)
-	sd	sp,%pcrel_lo(1b)(x8)
-
-        addi a4, a2, 1
+        /* Pop argc off the stack, and save argc, argv and envp */
+        ld   a1, 0(sp)
+        addi a2, sp, 8
+        addi a4, a1, 1
         slli a4, a4, 3
         slli a4, a4, 3
-        add  a4, sp, a4
+        add  a4, a2, a4
 
 
+1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argc)
+	sd	a1,%pcrel_lo(1b)(x8)
+1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argv)
+	sd	a2,%pcrel_lo(1b)(x8)
 1:auipc	x8,%pcrel_hi(operatingsystem_parameter_envp)
 1:auipc	x8,%pcrel_hi(operatingsystem_parameter_envp)
 	sd	a4,%pcrel_lo(1b)(x8)
 	sd	a4,%pcrel_lo(1b)(x8)
 
 
@@ -75,30 +77,15 @@ _start:
 
 
         /* Fetch address of fini */
         /* Fetch address of fini */
 1:auipc	x8,%pcrel_hi(__libc_csu_fini)
 1:auipc	x8,%pcrel_hi(__libc_csu_fini)
-	addi	a2,x8,%pcrel_lo(1b)
-
-        /* argc already loaded to a2*/
+	addi	a4,x8,%pcrel_lo(1b)
 
 
-        /* load argv */
-        addi a3, sp, 0
-
-        /* Push stack limit */
-        sd   a3, -8(sp)
-        addi sp, sp, -8
-
-        /* Push rtld_fini */
-        sd   a1, -8(sp)
-        addi sp, sp, -8
+        addi a6, sp, 0
 
 
         /* Set up the other arguments in registers */
         /* Set up the other arguments in registers */
 1:auipc	x8,%pcrel_hi(PASCALMAIN)
 1:auipc	x8,%pcrel_hi(PASCALMAIN)
-	addi a1, x8, %pcrel_lo(1b)
+	addi a0, x8, %pcrel_lo(1b)
 1:auipc	x8,%pcrel_hi(__libc_csu_init)
 1:auipc	x8,%pcrel_hi(__libc_csu_init)
-	addi a4, x8, %pcrel_lo(1b)
-
-        /* Push fini */
-        sd   a2, -8(sp)
-        addi sp, sp, -8
+	addi a3, x8, %pcrel_lo(1b)
 
 
         /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
         /* __libc_start_main (main, argc, argv, init, fini, rtld_fini, stack_end) */
 
 
@@ -111,7 +98,7 @@ _start:
         jalr ra, x8, %pcrel_lo(1b)
         jalr ra, x8, %pcrel_lo(1b)
 
 
         .globl  _haltproc
         .globl  _haltproc
-    .type   _haltproc,function
+        .type   _haltproc,function
 _haltproc:
 _haltproc:
 1:auipc	x8,%pcrel_hi(operatingsystem_result)
 1:auipc	x8,%pcrel_hi(operatingsystem_result)
 	lbu	x1,%pcrel_lo(1b)(x8)
 	lbu	x1,%pcrel_lo(1b)(x8)
@@ -128,11 +115,11 @@ __data_start:
         data_start = __data_start
         data_start = __data_start
 
 
 .bss
 .bss
-        .comm __stkptr,4
+        .comm __stkptr,8
 
 
-        .comm operatingsystem_parameter_envp,4
-        .comm operatingsystem_parameter_argc,4
-        .comm operatingsystem_parameter_argv,4
+        .comm operatingsystem_parameter_envp,8
+        .comm operatingsystem_parameter_argc,8
+        .comm operatingsystem_parameter_argv,8
 
 
         .section ".comment"
         .section ".comment"
         .byte 0
         .byte 0

+ 29 - 33
rtl/linux/riscv64/dllprt0.as

@@ -21,60 +21,56 @@ _startlib:
         .globl  FPC_SHARED_LIB_START
         .globl  FPC_SHARED_LIB_START
         .type   FPC_SHARED_LIB_START,function
         .type   FPC_SHARED_LIB_START,function
 FPC_SHARED_LIB_START:
 FPC_SHARED_LIB_START:
-        sw x1, -4(x2)
-        sw x8, -8(x2)
-        addi x8, x2, 0
-        addi x2, x2, -8
+        addi sp, sp, -16
+        sd ra, 8(sp)
+        sd x8, 0(sp)
+        addi x8, sp, 16
 
 
-        /* a1 contains argc, a2 contains argv and a3 contains envp */
-        lui x15, %hi(operatingsystem_parameter_argc)
-        addi x15,x15,%lo(operatingsystem_parameter_argc)
-        sw a1, (x15)
-
-        lui x15, %hi(operatingsystem_parameter_argv)
-        addi x15,x15,%lo(operatingsystem_parameter_argv)
-        sw a2, (x15)
-
-        lui x15, %hi(operatingsystem_parameter_envp)
-        addi x15,x15,%lo(operatingsystem_parameter_envp)
-        sw a3, (x15)
+        /* a0 contains argc, a1 contains argv and a2 contains envp */
+1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argc)
+	sd	a0,%pcrel_lo(1b)(x8)
+1:auipc	x8,%pcrel_hi(operatingsystem_parameter_argv)
+	sd	a1,%pcrel_lo(1b)(x8)
+1:auipc	x8,%pcrel_hi(operatingsystem_parameter_envp)
+	sd	a2,%pcrel_lo(1b)(x8)
 
 
         /* save initial stackpointer */
         /* save initial stackpointer */
-        lui x15, %hi(__stklen)
-        addi x15,x15,%lo(__stklen)
-        sw x2, (x15)
+1:auipc	x8,%pcrel_hi(__stklen)
+	sd	sp,%pcrel_lo(1b)(x8)
 
 
         /* call main and exit normally */
         /* call main and exit normally */
-        jal x1, PASCALMAIN
-        lw x8, -8(x8)
-        lw x1, -4(x8)
+1:auipc	x8,%pcrel_hi(PASCALMAIN)
+        jalr ra, x8, %pcrel_lo(1b)
+
+        ld x8, 0(x8)
+        ld ra, 8(x8)
+        addi sp, sp, 16
 
 
-        jalr x0, x1
+        jalr x0, ra
 
 
         .globl  _haltproc
         .globl  _haltproc
         .type   _haltproc,function
         .type   _haltproc,function
 _haltproc:
 _haltproc:
-        /* reload exitcode */
-        lui x10, %hi(operatingsystem_result)
-        addi x10,x10,%lo(operatingsystem_result)
-        addi x17, x0, 248
-        scall
+1:auipc	x8,%pcrel_hi(operatingsystem_result)
+	lbu	x1,%pcrel_lo(1b)(x8)
+	addi	x17, x0, 94
+	ecall
         jal x0, _haltproc
         jal x0, _haltproc
 
 
 .data
 .data
 
 
         .type operatingsystem_parameters,object
         .type operatingsystem_parameters,object
-        .size operatingsystem_parameters,12
+        .size operatingsystem_parameters,24
 operatingsystem_parameters:
 operatingsystem_parameters:
-        .skip 3*4
+        .skip 3*8
         .global operatingsystem_parameter_envp
         .global operatingsystem_parameter_envp
         .global operatingsystem_parameter_argc
         .global operatingsystem_parameter_argc
         .global operatingsystem_parameter_argv
         .global operatingsystem_parameter_argv
         .set operatingsystem_parameter_envp,operatingsystem_parameters+0
         .set operatingsystem_parameter_envp,operatingsystem_parameters+0
-        .set operatingsystem_parameter_argc,operatingsystem_parameters+4
-        .set operatingsystem_parameter_argv,operatingsystem_parameters+8
+        .set operatingsystem_parameter_argc,operatingsystem_parameters+8
+        .set operatingsystem_parameter_argv,operatingsystem_parameters+16
 
 
 .bss
 .bss
 
 
-        .comm __stkptr,4
+        .comm __stkptr,8