diff options
Diffstat (limited to 'riscv_new/rtl/riscv64')
-rw-r--r-- | riscv_new/rtl/riscv64/int64p.inc | 14 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/makefile.cpu | 6 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/math.inc | 15 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/mathu.inc | 151 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/riscv64.inc | 124 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/set.inc | 15 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/setjump.inc | 132 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/setjumph.inc | 39 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/strings.inc | 18 | ||||
-rw-r--r-- | riscv_new/rtl/riscv64/stringss.inc | 18 |
10 files changed, 532 insertions, 0 deletions
diff --git a/riscv_new/rtl/riscv64/int64p.inc b/riscv_new/rtl/riscv64/int64p.inc new file mode 100644 index 0000000000..1cb045808f --- /dev/null +++ b/riscv_new/rtl/riscv64/int64p.inc @@ -0,0 +1,14 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team + + This file contains some helper routines for int64 and qword + + 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. + + **********************************************************************} diff --git a/riscv_new/rtl/riscv64/makefile.cpu b/riscv_new/rtl/riscv64/makefile.cpu new file mode 100644 index 0000000000..03bae91aca --- /dev/null +++ b/riscv_new/rtl/riscv64/makefile.cpu @@ -0,0 +1,6 @@ +# +# Here we set processor dependent include file names. +# + +CPUNAMES=riscv64 int64p math set setjump setjumph strings stringss +CPUINCNAMES=$(addsuffix .inc,$(CPUNAMES)) diff --git a/riscv_new/rtl/riscv64/math.inc b/riscv_new/rtl/riscv64/math.inc new file mode 100644 index 0000000000..472337688e --- /dev/null +++ b/riscv_new/rtl/riscv64/math.inc @@ -0,0 +1,15 @@ +{ + + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team. + + Implementation of mathematical Routines (only for real) + + 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. + + **********************************************************************} diff --git a/riscv_new/rtl/riscv64/mathu.inc b/riscv_new/rtl/riscv64/mathu.inc new file mode 100644 index 0000000000..74743e0a6e --- /dev/null +++ b/riscv_new/rtl/riscv64/mathu.inc @@ -0,0 +1,151 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2014 by Jonas Maebe + member of the Free Pascal development team + + 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. + +**********************************************************************} + +function getfpcr: dword; nostackframe; assembler; + asm + end; + + +procedure setfpcr(val: dword); nostackframe; assembler; + asm + end; + + +function getfpsr: dword; nostackframe; assembler; + asm + end; + + +procedure setfpsr(val: dword); nostackframe; assembler; + asm + end; + + +function GetRoundMode: TFPURoundingMode; + const + bits2rm: array[0..3] of TFPURoundingMode = (rmNearest,rmUp,rmDown,rmTruncate); + begin + result:=TFPURoundingMode(bits2rm[(getfpcr shr 22) and 3]) + end; + + +function SetRoundMode(const RoundMode: TFPURoundingMode): TFPURoundingMode; + const + rm2bits: array[TFPURoundingMode] of byte = (0,2,1,3); + begin + softfloat_rounding_mode:=RoundMode; + SetRoundMode:=RoundMode; + setfpcr((getfpcr and $ff3fffff) or (rm2bits[RoundMode] shl 22)); + end; + + +function GetPrecisionMode: TFPUPrecisionMode; + begin + result:=pmDouble; + end; + + +function SetPrecisionMode(const Precision: TFPUPrecisionMode): TFPUPrecisionMode; + begin + result:=pmDouble; + end; + + +const + fpu_ioe = 1 shl 8; + fpu_dze = 1 shl 9; + fpu_ofe = 1 shl 10; + fpu_ufe = 1 shl 11; + fpu_ixe = 1 shl 12; + fpu_ide = 1 shl 15; + fpu_exception_mask = fpu_ioe or fpu_dze or fpu_ofe or fpu_ufe or fpu_ixe or fpu_ide; + fpu_exception_mask_to_status_mask_shift = 8; + + +function GetExceptionMask: TFPUExceptionMask; + var + fpcr: dword; + begin + fpcr:=getfpcr; + result:=[]; + if ((fpcr and fpu_ioe)=0) then + result := result+[exInvalidOp]; + if ((fpcr and fpu_ofe)=0) then + result := result+[exOverflow]; + if ((fpcr and fpu_ufe)=0) then + result := result+[exUnderflow]; + if ((fpcr and fpu_dze)=0) then + result := result+[exZeroDivide]; + if ((fpcr and fpu_ixe)=0) then + result := result+[exPrecision]; + if ((fpcr and fpu_ide)=0) then + result := result+[exDenormalized]; + end; + + +function SetExceptionMask(const Mask: TFPUExceptionMask): TFPUExceptionMask; + var + newfpcr: dword; + begin + softfloat_exception_mask:=mask; + newfpcr:=fpu_exception_mask; + if exInvalidOp in Mask then + newfpcr:=newfpcr and not(fpu_ioe); + if exOverflow in Mask then + newfpcr:=newfpcr and not(fpu_ofe); + if exUnderflow in Mask then + newfpcr:=newfpcr and not(fpu_ufe); + if exZeroDivide in Mask then + newfpcr:=newfpcr and not(fpu_dze); + if exPrecision in Mask then + newfpcr:=newfpcr and not(fpu_ixe); + if exDenormalized in Mask then + newfpcr:=newfpcr and not(fpu_ide); + { clear "exception happened" flags } + ClearExceptions(false); + { set new exception mask } + setfpcr((getfpcr and not(fpu_exception_mask)) or newfpcr); + { unsupported mask bits will remain 0 -> read exception mask again } + result:=GetExceptionMask; + softfloat_exception_mask:=result; + end; + + +procedure ClearExceptions(RaisePending: Boolean); + var + fpsr: dword; + f: TFPUException; + begin + fpsr:=getfpsr; + if raisepending then + begin + if (fpsr and (fpu_dze shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exZeroDivide); + if (fpsr and (fpu_ofe shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exOverflow); + if (fpsr and (fpu_ufe shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exUnderflow); + if (fpsr and (fpu_ioe shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exInvalidOp); + if (fpsr and (fpu_ixe shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exPrecision); + if (fpsr and (fpu_ide shr fpu_exception_mask_to_status_mask_shift)) <> 0 then + float_raise(exDenormalized); + { now the soft float exceptions } + for f in softfloat_exception_flags do + float_raise(f); + end; + softfloat_exception_flags:=[]; + setfpsr(fpsr and not(fpu_exception_mask shr fpu_exception_mask_to_status_mask_shift)); + end; diff --git a/riscv_new/rtl/riscv64/riscv64.inc b/riscv_new/rtl/riscv64/riscv64.inc new file mode 100644 index 0000000000..3b71640ca5 --- /dev/null +++ b/riscv_new/rtl/riscv64/riscv64.inc @@ -0,0 +1,124 @@ +{ + + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team. + + Processor dependent implementation for the system unit for + AVR + + 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 fpc_cpuinit;{$ifdef SYSTEMINLINE}inline;{$endif} + begin + end; + + +{$IFNDEF INTERNAL_BACKTRACE} +{$define FPC_SYSTEM_HAS_GET_FRAME} +function get_frame:pointer;assembler;nostackframe; + asm + addi a0, fp, 0 + end; +{$ENDIF not INTERNAL_BACKTRACE} + + +{$define FPC_SYSTEM_HAS_GET_CALLER_ADDR} +function get_caller_addr(framebp:pointer;addr:pointer=nil):pointer;assembler; + asm + ld a0, -8*2(a0) + end; + + +{$define FPC_SYSTEM_HAS_GET_CALLER_FRAME} +function get_caller_frame(framebp:pointer;addr:pointer=nil):pointer;assembler; + asm + ld a0, -8*1(a0) + end; + + +{$define FPC_SYSTEM_HAS_SPTR} +Function Sptr : pointer;assembler; + asm + addi a0, sp, 0 + end; + + +function InterLockedDecrement (var Target: longint) : longint; + begin + dec(Target); + Result:=Target; + end; + + +function InterLockedIncrement (var Target: longint) : longint; + begin + inc(Target); + Result:=Target; + end; + + +function InterLockedExchange (var Target: longint;Source : longint) : longint; + begin + Result:=Target; + Target:=Source; + end; + + +function InterlockedCompareExchange(var Target: longint; NewValue: longint; Comperand: longint): longint; + begin + Result:=Target; + if Target=Comperand then + Target:=NewValue; + end; + + +function InterLockedExchangeAdd (var Target: longint;Source : longint) : longint; + begin + Result:=Target; + inc(Target,Source); + end; + + + +function InterLockedDecrement64 (var Target: int64) : int64; + begin + dec(Target); + Result:=Target; + end; + + +function InterLockedIncrement64 (var Target: int64) : int64; + begin + inc(Target); + Result:=Target; + end; + + +function InterLockedExchange64 (var Target: int64;Source : int64) : int64; + begin + Result:=Target; + Target:=Source; + end; + + +function InterlockedCompareExchange64(var Target: int64; NewValue: int64; Comperand: int64): int64; + begin + Result:=Target; + if Target=Comperand then + Target:=NewValue; + end; + + +function InterLockedExchangeAdd64 (var Target: int64;Source : int64) : int64; + begin + Result:=Target; + inc(Target,Source); + end; + diff --git a/riscv_new/rtl/riscv64/set.inc b/riscv_new/rtl/riscv64/set.inc new file mode 100644 index 0000000000..681a4b7cbb --- /dev/null +++ b/riscv_new/rtl/riscv64/set.inc @@ -0,0 +1,15 @@ +{ + + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team. + + Include file with set operations called by the compiler + + 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. + + **********************************************************************} diff --git a/riscv_new/rtl/riscv64/setjump.inc b/riscv_new/rtl/riscv64/setjump.inc new file mode 100644 index 0000000000..bb238b7aba --- /dev/null +++ b/riscv_new/rtl/riscv64/setjump.inc @@ -0,0 +1,132 @@ +{ + + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team. + + SetJmp and LongJmp implementation for exception handling + + 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. + + **********************************************************************} + +function fpc_setjmp(var S : jmp_buf) : longint;assembler;nostackframe;[Public, alias : 'FPC_SETJMP'];nostackframe;compilerproc; + asm + sd ra, 0*8(a0) + sd s0, 1*8(a0) + sd s1, 2*8(a0) + sd s2, 3*8(a0) + sd s3, 4*8(a0) + sd s4, 5*8(a0) + sd s5, 6*8(a0) + sd s6, 7*8(a0) + sd s7, 8*8(a0) + sd s8, 9*8(a0) + sd s9, 10*8(a0) + sd s10, 11*8(a0) + sd s11, 12*8(a0) + sd sp, 13*8(a0) + +{$if defined(FPUFD) or defined(FPUD)} + frcsr s0 + + sd s0, 14*8(a0) + + fsd f8, 15*8(a0) + fsd f9, 16*8(a0) + fsd f18, 17*8(a0) + fsd f19, 18*8(a0) + fsd f20, 19*8(a0) + fsd f21, 20*8(a0) + fsd f22, 21*8(a0) + fsd f23, 22*8(a0) + fsd f24, 23*8(a0) + fsd f25, 24*8(a0) + fsd f26, 25*8(a0) + fsd f27, 26*8(a0) +{$endif FPUFD or FPUD} +{$if defined(FPUF)} + frcsr s0 + + sd s0, 14*8(a0) + + fsw f8, 30*4(a0) + fsw f9, 31*4(a0) + fsw f18, 32*4(a0) + fsw f19, 33*4(a0) + fsw f20, 34*4(a0) + fsw f21, 35*4(a0) + fsw f22, 36*4(a0) + fsw f23, 37*4(a0) + fsw f24, 38*4(a0) + fsw f25, 39*4(a0) + fsw f26, 40*4(a0) + fsw f27, 41*4(a0) +{$endif FPUF} + + addi x10, x0, 0 + end; + + +procedure fpc_longjmp(var S : jmp_buf;value : longint);assembler;nostackframe;[Public, alias : 'FPC_LONGJMP'];compilerproc; + asm + ld ra, 0*8(a0) + ld s0, 1*8(a0) + ld s1, 2*8(a0) + ld s2, 3*8(a0) + ld s3, 4*8(a0) + ld s4, 5*8(a0) + ld s5, 6*8(a0) + ld s6, 7*8(a0) + ld s7, 8*8(a0) + ld s8, 9*8(a0) + ld s9, 10*8(a0) + ld s10,11*8(a0) + ld s11,12*8(a0) + +{$if defined(FPUFD) or defined(FPUD)} + ld sp, 14*8(a0) + + fld f8, 15*8(a0) + fld f9, 16*8(a0) + fld f18, 17*8(a0) + fld f19, 18*8(a0) + fld f20, 19*8(a0) + fld f21, 20*8(a0) + fld f22, 21*8(a0) + fld f23, 22*8(a0) + fld f24, 23*8(a0) + fld f25, 24*8(a0) + fld f26, 25*8(a0) + fld f27, 26*8(a0) + + fscsr sp +{$endif FPUFD or FPUD} +{$if defined(FPUF)} + ld sp, 14*8(a0) + + flw f8, 30*4(a0) + flw f9, 31*4(a0) + flw f18, 32*4(a0) + flw f19, 33*4(a0) + flw f20, 34*4(a0) + flw f21, 35*4(a0) + flw f22, 36*4(a0) + flw f23, 37*4(a0) + flw f24, 38*4(a0) + flw f25, 39*4(a0) + flw f26, 40*4(a0) + flw f27, 41*4(a0) + + fscsr sp +{$endif FPUF} + ld sp, 13*8(a0) + + sltiu a0, a1, 1 + add a0, a0, a1 + end; + diff --git a/riscv_new/rtl/riscv64/setjumph.inc b/riscv_new/rtl/riscv64/setjumph.inc new file mode 100644 index 0000000000..fa0c4a14c6 --- /dev/null +++ b/riscv_new/rtl/riscv64/setjumph.inc @@ -0,0 +1,39 @@ +{ + + This file is part of the Free Pascal run time library. + Copyright (c) 2008 by the Free Pascal development team. + + SetJmp/Longjmp declarations + + 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. + + **********************************************************************} + +type + jmp_buf = packed record + ra, + x8,x9,x18,x19,x20,x21, + x22,x23,x24,x25,x26, + x27,x2: qword; +{$if defined(FPUFD) or defined(FPUD)} + fcsr, + f8,f9,f18,f19,f20,f21, + f22,f23,f24,f25,f26,f27: qword; +{$endif FPUFD or FPUD} +{$if defined(FPUF)} + fcsr: qword; + f8,f9,f18,f19,f20,f21, + f22,f23,f24,f25,f26,f27: longword; +{$endif FPUF} + end; + pjmp_buf = ^jmp_buf; + +function setjmp(var S : jmp_buf) : longint;[external name 'FPC_SETJMP']; +procedure longjmp(var S : jmp_buf;value : longint);[external name 'FPC_LONGJMP']; + + diff --git a/riscv_new/rtl/riscv64/strings.inc b/riscv_new/rtl/riscv64/strings.inc new file mode 100644 index 0000000000..0d10cd5002 --- /dev/null +++ b/riscv_new/rtl/riscv64/strings.inc @@ -0,0 +1,18 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2000 by Jonas Maebe, member of the + Free Pascal development team + + Processor dependent part of strings.pp, that can be shared with + sysutils unit. + + 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. + + **********************************************************************} + + diff --git a/riscv_new/rtl/riscv64/stringss.inc b/riscv_new/rtl/riscv64/stringss.inc new file mode 100644 index 0000000000..b30572827e --- /dev/null +++ b/riscv_new/rtl/riscv64/stringss.inc @@ -0,0 +1,18 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 1999-2000 by Jonas Maebe, member of the + Free Pascal development team + + Processor dependent part of strings.pp, not shared with + sysutils unit. + + 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. + + **********************************************************************} + + |