summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlaksen <laksen@3ad0048d-3df7-0310-abae-a5850022a9f2>2016-09-03 23:47:20 +0000
committerlaksen <laksen@3ad0048d-3df7-0310-abae-a5850022a9f2>2016-09-03 23:47:20 +0000
commit6bee2371246941af5e5097892f31cf6d82c2e219 (patch)
treed56f9c46418b77217a87e8fc3b6c3e7fe6318c89
parent71354347d93d6860de9f8045da2ac9666efbfd79 (diff)
downloadfpc-6bee2371246941af5e5097892f31cf6d82c2e219.tar.gz
Update to use AUIPC+JALR instead of JAL to jump and link.
Fix 64bit calls to mod/div. Fix startup code for RV64. git-svn-id: http://svn.freepascal.org/svn/fpc/branches/laksen@34420 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--riscv/trunk/compiler/riscv/aasmcpu.pas2
-rw-r--r--riscv/trunk/compiler/riscv/cgrv.pas49
-rw-r--r--riscv/trunk/compiler/riscv/hlcgrv.pas16
-rw-r--r--riscv/trunk/compiler/riscv64/nrv64mat.pas9
-rw-r--r--riscv/trunk/rtl/linux/riscv64/prt0.as16
-rw-r--r--riscv/trunk/rtl/linux/riscv64/syscall.inc14
-rw-r--r--riscv/trunk/rtl/linux/riscv64/sysnr.inc31
7 files changed, 75 insertions, 62 deletions
diff --git a/riscv/trunk/compiler/riscv/aasmcpu.pas b/riscv/trunk/compiler/riscv/aasmcpu.pas
index 501f31def1..30acbaa154 100644
--- a/riscv/trunk/compiler/riscv/aasmcpu.pas
+++ b/riscv/trunk/compiler/riscv/aasmcpu.pas
@@ -419,7 +419,7 @@ uses cutils, cclasses;
// UJ type
A_JAL:
- if opnr=1 then
+ if opnr=0 then
result:=operand_write
else
result:=operand_read;
diff --git a/riscv/trunk/compiler/riscv/cgrv.pas b/riscv/trunk/compiler/riscv/cgrv.pas
index 5ae166f3ee..9b1bf4f667 100644
--- a/riscv/trunk/compiler/riscv/cgrv.pas
+++ b/riscv/trunk/compiler/riscv/cgrv.pas
@@ -74,11 +74,27 @@ unit cgrv;
procedure tcgrv.a_call_name(list : TAsmList;const s : string; weak: boolean);
+ var
+ tmpreg: TRegister;
+ href: treference;
begin
- if not(weak) then
+ if not(weak) then
+ reference_reset_symbol(href,current_asmdata.RefAsmSymbol(s,AT_FUNCTION),0,0)
+ else
+ reference_reset_symbol(href,current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION),0,0);
+
+ tmpreg:=getintregister(list,OS_ADDR);
+
+ href.refaddr:=addr_hi20;
+ list.concat(taicpu.op_reg_ref(A_AUIPC,tmpreg,href));
+ href.refaddr:=addr_lo12;
+ //href.base:=tmpreg;
+ list.concat(taicpu.op_reg_reg_ref(A_JALR,NR_RETURN_ADDRESS_REG,tmpreg,href));
+
+ {if not(weak) then
list.concat(taicpu.op_reg_sym(A_JAL,NR_RETURN_ADDRESS_REG,current_asmdata.RefAsmSymbol(s,AT_FUNCTION)))
else
- list.concat(taicpu.op_reg_sym(A_JAL,NR_RETURN_ADDRESS_REG,current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)));
+ list.concat(taicpu.op_reg_sym(A_JAL,NR_RETURN_ADDRESS_REG,current_asmdata.WeakRefAsmSymbol(s,AT_FUNCTION)));}
{ not assigned while generating external wrappers }
if assigned(current_procinfo) then
include(current_procinfo.flags,pi_do_call);
@@ -196,20 +212,45 @@ unit cgrv;
procedure tcgrv.a_jmp_name(list : TAsmList;const s : string);
var
ai: taicpu;
+ href: treference;
+ tmpreg: TRegister;
begin
- ai:=taicpu.op_reg_sym(A_JAL,NR_X0,current_asmdata.RefAsmSymbol(s));
+ reference_reset_symbol(href,current_asmdata.RefAsmSymbol(s,AT_FUNCTION),0,0);
+
+ tmpreg:=getintregister(list,OS_ADDR);
+
+ href.refaddr:=addr_hi20;
+ list.concat(taicpu.op_reg_ref(A_AUIPC,tmpreg,href));
+ href.refaddr:=addr_lo12;
+ ai:=taicpu.op_reg_reg_ref(A_JALR,NR_X0,tmpreg,href);
ai.is_jmp:=true;
list.concat(ai);
+
+ //ai:=taicpu.op_reg_sym(A_JAL,NR_X0,current_asmdata.RefAsmSymbol(s));
+ //ai.is_jmp:=true;
end;
procedure tcgrv.a_jmp_always(list : TAsmList;l: tasmlabel);
var
ai: taicpu;
+ href: treference;
+ tmpreg: TRegister;
begin
- ai:=taicpu.op_reg_sym(A_JAL,NR_X0,l);
+ reference_reset_symbol(href,l,0,0);
+
+ tmpreg:=getintregister(list,OS_ADDR);
+
+ href.refaddr:=addr_hi20;
+ list.concat(taicpu.op_reg_ref(A_AUIPC,tmpreg,href));
+ href.refaddr:=addr_lo12;
+ ai:=taicpu.op_reg_reg_ref(A_JALR,NR_X0,tmpreg,href);
ai.is_jmp:=true;
list.concat(ai);
+
+ //ai:=taicpu.op_reg_sym(A_JAL,NR_X0,l);
+ //ai.is_jmp:=true;
+ //list.concat(ai);
end;
diff --git a/riscv/trunk/compiler/riscv/hlcgrv.pas b/riscv/trunk/compiler/riscv/hlcgrv.pas
index c68f6dcabf..a1b9aa5fbc 100644
--- a/riscv/trunk/compiler/riscv/hlcgrv.pas
+++ b/riscv/trunk/compiler/riscv/hlcgrv.pas
@@ -125,10 +125,11 @@ implementation
var
make_global : boolean;
- tmpref : treference;
+ tmpref , href: treference;
l : TAsmLabel;
hsym: tsym;
paraloc: PCGParaLocation;
+ tmpreg: TRegister;
begin
if not(procdef.proctypeoption in [potype_function,potype_procedure]) then
Internalerror(200006137);
@@ -187,7 +188,18 @@ implementation
op_onr12methodaddr;
end
else
- list.concat(taicpu.op_reg_sym(A_JAL,NR_X0,current_asmdata.RefAsmSymbol(procdef.mangledname)));
+ begin
+ reference_reset_symbol(href,current_asmdata.RefAsmSymbol(procdef.mangledname,AT_FUNCTION),0,0);
+
+ tmpreg:=NR_X5;
+
+ href.refaddr:=addr_hi20;
+ list.concat(taicpu.op_reg_ref(A_AUIPC,tmpreg,href));
+ href.refaddr:=addr_lo12;
+ list.concat(taicpu.op_reg_reg_ref(A_JALR,NR_X0,tmpreg,href));
+
+ //list.concat(taicpu.op_reg_sym(A_JAL,NR_X0,current_asmdata.RefAsmSymbol(procdef.mangledname)));
+ end;
list.concatlist(current_procinfo.aktlocaldata);
current_procinfo.Free;
diff --git a/riscv/trunk/compiler/riscv64/nrv64mat.pas b/riscv/trunk/compiler/riscv64/nrv64mat.pas
index 2e29682db0..bbf6d777a3 100644
--- a/riscv/trunk/compiler/riscv64/nrv64mat.pas
+++ b/riscv/trunk/compiler/riscv64/nrv64mat.pas
@@ -31,7 +31,6 @@ unit nrv64mat;
type
trv64moddivnode = class(tcgmoddivnode)
- function use_moddiv64bitint_helper: boolean; override;
procedure emit_div_reg_reg(signed: boolean; denum, num: tregister); override;
procedure emit_mod_reg_reg(signed: boolean; denum, num: tregister); override;
function first_moddivint: tnode; override;
@@ -95,14 +94,6 @@ implementation
end;
end;
- function trv64moddivnode.use_moddiv64bitint_helper: boolean;
- begin
- result:=
- (left.resultdef.typ=orddef) and
- (right.resultdef.typ=orddef) and
- (is_64bitint(left.resultdef) or is_64bitint(right.resultdef));
- end;
-
procedure trv64moddivnode.emit_div_reg_reg(signed: boolean; denum, num: tregister);
var
op: TAsmOp;
diff --git a/riscv/trunk/rtl/linux/riscv64/prt0.as b/riscv/trunk/rtl/linux/riscv64/prt0.as
index fcff554869..524ccc213c 100644
--- a/riscv/trunk/rtl/linux/riscv64/prt0.as
+++ b/riscv/trunk/rtl/linux/riscv64/prt0.as
@@ -13,7 +13,7 @@
_dynamic_start:
lui x5,%hi(__dl_fini)
addi x5,x5,%lo(__dl_fini)
- sw x10, (x5)
+ sd x10, (x5)
jal x0, _start
.globl _start
@@ -32,7 +32,7 @@ _start:
bltu t0, t1, 2b
/* Get argc, argv, envp */
- lw x5,(x2)
+ ld x5,(x2)
addi x6,x2,8
addi x7,x5,1
slli x7,x7,3
@@ -41,17 +41,17 @@ _start:
/* Save argc, argv, envp, and initial stack pointer */
lui x8,%hi(operatingsystem_parameter_argc)
addi x8,x8,%lo(operatingsystem_parameter_argc)
- sw x5,(x8)
+ sd x5,(x8)
lui x8,%hi(operatingsystem_parameter_argv)
addi x8,x8,%lo(operatingsystem_parameter_argv)
- sw x6,(x8)
+ sd x6,(x8)
lui x8,%hi(operatingsystem_parameter_envp)
addi x8,x8,%lo(operatingsystem_parameter_envp)
- sw x7,(x8)
+ sd x7,(x8)
lui x5,%hi(__stkptr)
addi x5,x8,%lo(__stkptr)
addi x6, x2, 0
- sw x6,(x5)
+ sd x6,(x5)
/* Initialise FP to zero */
addi x8,x0,0
@@ -64,13 +64,13 @@ _start:
_haltproc:
lui x10,%hi(__dl_fini)
addi x10,x10,%lo(__dl_fini)
- lw x10,(x10)
+ ld x10,(x10)
beq x10,x0,.Lexit
jalr x1,x10
.Lexit:
lui x10,%hi(operatingsystem_result)
addi x10,x10,%lo(operatingsystem_result)
- lw x10,(x10)
+ ld x10,(x10)
addi x17, x0, 94
scall
jal x0, _haltproc
diff --git a/riscv/trunk/rtl/linux/riscv64/syscall.inc b/riscv/trunk/rtl/linux/riscv64/syscall.inc
index a7ecca5d8c..146250e826 100644
--- a/riscv/trunk/rtl/linux/riscv64/syscall.inc
+++ b/riscv/trunk/rtl/linux/riscv64/syscall.inc
@@ -11,7 +11,7 @@ function FpSysCall(sysnr:TSysParam):TSysResult;
assembler; nostackframe; [public,alias:'FPC_SYSCALL0'];
asm
addi x17, sysnr, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -28,7 +28,7 @@ assembler; nostackframe; [public,alias:'FPC_SYSCALL1'];
asm
addi x17, sysnr, 0
addi x10, x11, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -46,7 +46,7 @@ asm
addi x17, sysnr, 0
addi x10, x11, 0
addi x11, x12, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -65,7 +65,7 @@ asm
addi x10, x11, 0
addi x11, x12, 0
addi x12, x13, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -85,7 +85,7 @@ asm
addi x11, x12, 0
addi x12, x13, 0
addi x13, x14, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -106,7 +106,7 @@ asm
addi x12, x13, 0
addi x13, x14, 0
addi x14, x15, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
@@ -128,7 +128,7 @@ asm
addi x13, x14, 0
addi x14, x15, 0
addi x15, x16, 0
- scall
+ ecall
bge x10,x0,.Ldone
sw x1, -4(x2)
addi x2, x2, -4
diff --git a/riscv/trunk/rtl/linux/riscv64/sysnr.inc b/riscv/trunk/rtl/linux/riscv64/sysnr.inc
index fed37a6fe2..3763caa818 100644
--- a/riscv/trunk/rtl/linux/riscv64/sysnr.inc
+++ b/riscv/trunk/rtl/linux/riscv64/sysnr.inc
@@ -1,32 +1 @@
{$i ../sysnr-gen.inc}
-
-{const
- syscall_nr_time = 1062;
- syscall_nr_open = 1024;
- syscall_nr_unlink = 1026;
- syscall_nr_stat = 1038;
- syscall_nr_mkdir = 1030;
- syscall_nr_rmdir = 1;
- syscall_nr_fork = 2;
- syscall_nr_WaitPID = 3;
- syscall_nr_access = 1033;
- syscall_nr_dup2 = 4;
- syscall_nr_readlink = 78;
- syscall_nr_rename = 6;
-
- syscall_nr_getpgrp = 7;
- syscall_nr_link = 1025;
- syscall_nr_mknod = 8;
- syscall_nr_chmod = 9;
- syscall_nr_utime = 10;
- syscall_nr_pipe = 11;
- syscall_nr__newselect = 12;
- syscall_nr_poll = 13;
- syscall_nr_lstat = 1039;
- syscall_nr_nice = 14;
- syscall_nr_symlink = 15;
- syscall_nr_chown = 16;
-
- syscall_nr_epoll_create = 17;
- syscall_nr_epoll_wait = 18;
- syscall_nr_inotify_init = 19;}