Skip to content

Commit 2e3f5d3

Browse files
Added riscv32 embedded as cross-target.
1 parent 2e8e71c commit 2e3f5d3

11 files changed

+266
-13
lines changed

public/gitrevision.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[master]v2.4.0e-2898(f43e73f)
1+
[master]v2.4.0e-2899(2e8e71c)

sources/crossinstallers/m_any_to_embeddedaarch64.pas

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,9 @@ function TAny_Embeddedaarch64.GetBinUtils(Basepath:string): boolean;
139139
end;
140140
{$endif unix}
141141

142-
// Now also allow for arm-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
143142
if not result then
144143
begin
145-
BinPrefixTry:='aarch64-elf-';
144+
BinPrefixTry:=TargetCPUName+'-elf-';
146145
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
147146
result:=SearchBinUtil(BasePath,AsFile);
148147
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);

sources/crossinstallers/m_any_to_embeddedarm.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ function TAny_Embeddedarm.GetBinUtils(Basepath:string): boolean;
151151
end;
152152
{$endif unix}
153153

154-
// Now also allow for arm-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
154+
// Now also allow for cpu-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
155155
if not result then
156156
begin
157-
BinPrefixTry:='arm-none-eabi-';
157+
BinPrefixTry:=TargetCPUName+'-none-eabi-';
158158
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
159159
result:=SearchBinUtil(BasePath,AsFile);
160160
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
unit m_any_to_embeddedriscv32;
2+
{ Cross compiles from any platform with correct binutils to Embedded RISCV32
3+
Copyright (C) 2017 Alf
4+
5+
This library is free software; you can redistribute it and/or modify it
6+
under the terms of the GNU Library General Public License as published by
7+
the Free Software Foundation; either version 2 of the License, or (at your
8+
option) any later version with the following modification:
9+
10+
As a special exception, the copyright holders of this library give you
11+
permission to link this library with independent modules to produce an
12+
executable, regardless of the license terms of these independent modules,and
13+
to copy and distribute the resulting executable under terms of your choice,
14+
provided that you also meet, for each linked independent module, the terms
15+
and conditions of the license of that module. An independent module is a
16+
module which is not derived from or based on this library. If you modify
17+
this library, you may extend this exception to your version of the library,
18+
but you are not obligated to do so. If you do not wish to do so, delete this
19+
exception statement from your version.
20+
21+
This program is distributed in the hope that it will be useful, but WITHOUT
22+
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
24+
for more details.
25+
26+
You should have received a copy of the GNU Library General Public License
27+
along with this library; if not, write to the Free Software Foundation,
28+
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29+
}
30+
31+
{
32+
RV32IM:
33+
RV32I: Base Integer Instruction Set
34+
M: Instructions that multiply and divide values held in two integer registers
35+
36+
binutils:
37+
./configure --with-arch=rv32im --with-abi=ilp32
38+
}
39+
40+
{$mode objfpc}{$H+}
41+
42+
interface
43+
44+
uses
45+
Classes, SysUtils;
46+
47+
implementation
48+
49+
uses
50+
FileUtil, m_crossinstaller, fpcuputil;
51+
52+
type
53+
54+
{ TAny_Embeddedriscv32 }
55+
TAny_Embeddedriscv32 = class(TCrossInstaller)
56+
private
57+
FAlreadyWarned: boolean; //did we warn user about errors and fixes already?
58+
public
59+
function GetLibs(Basepath:string):boolean;override;
60+
function GetBinUtils(Basepath:string):boolean;override;
61+
constructor Create;
62+
destructor Destroy; override;
63+
end;
64+
65+
{ TAny_Embeddedriscv32 }
66+
67+
function TAny_Embeddedriscv32.GetLibs(Basepath:string): boolean;
68+
const
69+
LibName='libgcc.a';
70+
var
71+
aABI:TABI;
72+
S:string;
73+
begin
74+
// Arm-embedded does not need libs by default, but user can add them.
75+
result:=inherited;
76+
77+
if result then exit;
78+
79+
if (FSubArch<>TSUBARCH.saNone) then
80+
ShowInfo('Cross-libs: We have a subarch: '+SubArchName)
81+
else
82+
ShowInfo('Cross-libs: No subarch defined. Expect fatal errors.',etError);
83+
84+
// begin simple: check presence of library file in basedir
85+
result:=SearchLibrary(Basepath,LibName);
86+
// search local paths based on libraries provided for or adviced by fpc itself
87+
if not result then
88+
result:=SimpleSearchLibrary(BasePath,DirName,LibName);
89+
90+
if ((not result) AND (FSubArch<>TSUBARCH.saNone)) then
91+
begin
92+
result:=SimpleSearchLibrary(BasePath,ConcatPaths([DirName,SubArchName]),LibName);
93+
if (not result) then
94+
begin
95+
for aABI in TABI do
96+
begin
97+
if aABI=TABI.default then continue;
98+
result:=SimpleSearchLibrary(BasePath,ConcatPaths([DirName,SubArchName,GetABI(aABI)]),LibName);
99+
if result then break;
100+
end;
101+
end;
102+
end;
103+
104+
SearchLibraryInfo(result);
105+
106+
if result then
107+
begin
108+
FLibsFound:=True;
109+
110+
if PerformLibraryPathMagic(S) then
111+
begin
112+
AddFPCCFGSnippet('-Fl'+S,false);
113+
end
114+
else
115+
begin
116+
// If we do not have magic, add subarch to enclose
117+
AddFPCCFGSnippet('#IFDEF CPU'+UpperCase(SubArchName));
118+
AddFPCCFGSnippet('-Fl'+S);
119+
AddFPCCFGSnippet('#ENDIF CPU'+UpperCase(SubArchName));
120+
end;
121+
end;
122+
123+
if not result then
124+
begin
125+
//libs path is optional; it can be empty
126+
ShowInfo('Libspath ignored; it is optional for this cross compiler.');
127+
FLibsPath:='';
128+
FLibsFound:=True;
129+
result:=true;
130+
end;
131+
end;
132+
133+
function TAny_Embeddedriscv32.GetBinUtils(Basepath:string): boolean;
134+
var
135+
AsFile: string;
136+
BinPrefixTry: string;
137+
{$ifdef unix}
138+
i:integer;
139+
{$endif unix}
140+
begin
141+
result:=inherited;
142+
if result then exit;
143+
144+
// Start with any names user may have given
145+
AsFile:=BinUtilsPrefix+ASFILENAME+GetExeExt;
146+
147+
result:=SearchBinUtil(BasePath,AsFile);
148+
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
149+
150+
{$ifdef unix}
151+
// User may also have placed them into their regular search path:
152+
if not result then
153+
begin
154+
for i:=Low(UnixBinDirs) to High(UnixBinDirs) do
155+
begin
156+
result:=SearchBinUtil(IncludeTrailingPathDelimiter(UnixBinDirs[i])+DirName, AsFile);
157+
if not result then result:=SearchBinUtil(UnixBinDirs[i], AsFile);
158+
if result then break;
159+
end;
160+
end;
161+
{$endif unix}
162+
163+
// Now also allow for cpu-none-elf- binutilsprefix
164+
if not result then
165+
begin
166+
BinPrefixTry:=TargetCPUName+'-none-elf-';
167+
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
168+
result:=SearchBinUtil(BasePath,AsFile);
169+
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
170+
if result then FBinUtilsPrefix:=BinPrefixTry;
171+
end;
172+
173+
// Now also allow for empty binutilsprefix in the right directory:
174+
if not result then
175+
begin
176+
BinPrefixTry:='';
177+
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
178+
result:=SearchBinUtil(BasePath,AsFile);
179+
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
180+
if result then FBinUtilsPrefix:=BinPrefixTry;
181+
end;
182+
183+
SearchBinUtilsInfo(result);
184+
185+
if not result then
186+
begin
187+
FAlreadyWarned:=true;
188+
end
189+
else
190+
begin
191+
FBinsFound:=true;
192+
// Configuration snippet for FPC
193+
AddFPCCFGSnippet('-FD'+BinUtilsPath);
194+
AddFPCCFGSnippet('-XP'+BinUtilsPrefix); {Prepend the binutils names};
195+
end;
196+
end;
197+
198+
constructor TAny_Embeddedriscv32.Create;
199+
begin
200+
inherited Create;
201+
FTargetCPU:=TCPU.riscv32;
202+
FTargetOS:=TOS.embedded;
203+
Reset;
204+
FAlreadyWarned:=false;
205+
ShowInfo;
206+
end;
207+
208+
destructor TAny_Embeddedriscv32.Destroy;
209+
begin
210+
inherited Destroy;
211+
end;
212+
213+
var
214+
Any_Embeddedriscv32:TAny_Embeddedriscv32;
215+
216+
initialization
217+
Any_Embeddedriscv32:=TAny_Embeddedriscv32.Create;
218+
RegisterCrossCompiler(Any_Embeddedriscv32.RegisterName,Any_Embeddedriscv32);
219+
220+
finalization
221+
Any_Embeddedriscv32.Destroy;
222+
end.
223+

sources/fpcupdefines.inc

+22
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,25 @@
5353

5454
{.$define DISABLE_PPC_CONFIG_PATH}
5555

56+
{$ifdef FPC}
57+
58+
{$WARN 4104 OFF}
59+
{$WARN 4105 OFF}
60+
{$WARN 4106 OFF}
61+
{$WARN 4107 OFF}
62+
{$WARN 4108 OFF}
63+
64+
{$WARN 5024 OFF}
65+
{$WARN 5027 OFF}
66+
{$WARN 5037 OFF}
67+
{$WARN 5057 OFF}
68+
{$WARN 5091 OFF}
69+
{$WARN 5092 OFF}
70+
71+
{$WARN 6058 OFF}
72+
73+
{$WARN CONSTRUCTING_ABSTRACT ERROR}
74+
75+
{$endif FPC}
76+
77+

sources/installermanager.pas

+10
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,11 @@ procedure TFPCupManager.GetCrossToolsFileName(out BinsFileName,LibsFileName:stri
18911891
if (CrossCPU_Target=TCPU.arm) then toolversion:='V232';
18921892
if (CrossCPU_Target=TCPU.i386) then toolversion:='V232';
18931893
end;
1894+
TOS.embedded:
1895+
begin
1896+
ostype:='none';
1897+
if (CrossCPU_Target=TCPU.riscv32) then toolversion:='V241';
1898+
end;
18941899
end;
18951900
end;
18961901

@@ -1934,6 +1939,11 @@ procedure TFPCupManager.GetCrossToolsFileName(out BinsFileName,LibsFileName:stri
19341939
if (CrossCPU_Target in [TCPU.i386,TCPU.x86_64,TCPU.aarch64,TCPU.arm]) then s:='Darwin_All_Clang_12.zip';
19351940
if (CrossCPU_Target in [TCPU.powerpc,TCPU.powerpc64]) then s:='Darwin_PowerPC_GNU.zip';
19361941
end;
1942+
TOS.embedded:
1943+
begin
1944+
ostype:='none';
1945+
if (CrossCPU_Target=TCPU.riscv32) then toolversion:='V241';
1946+
end;
19371947
end;
19381948
end;
19391949

sources/installeruniversal.pas

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333

3434
{$modeswitch advancedrecords}
3535

36-
{$warn 6058 off}
37-
3836
{$i fpcupdefines.inc}
3937

4038
interface
@@ -56,7 +54,7 @@ TAPkgVersion = record
5654
FMajor: integer;
5755
FMinor: integer;
5856
FRelease: integer;
59-
FBuild: integer;
57+
FBuild: integer;
6058
public
6159
function AsString: string;
6260
procedure GetVersion(alpkdoc:TConfig;key:string);

sources/m_crossinstaller.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ interface
102102
type
103103
TCPU = (cpuNone,i386,x86_64,arm,aarch64,powerpc,powerpc64,mips,mipsel,avr,jvm,i8086,sparc,sparc64,riscv32,riscv64,m68k,xtensa,wasm32,loongarch64);
104104
TOS = (osNone,win32,win64,linux,android,darwin,freebsd,openbsd,aix,wince,iphonesim,embedded,java,msdos,haiku,solaris,dragonfly,netbsd,morphos,aros,amiga,go32v2,freertos,ios,ultibo,wasi,atari);
105-
TSUBARCH = (saNone,armv4,armv4t,armv6,armv6m,armv7a,armv7em,armv7m,armv8,armv8a,avr1,avr2,avr25,avr35,avr4,avr5,avr51,avr6,avrtiny,avrxmega3,pic32mx,rv32imac,rv32ima,rv32im,rv32i,rv64imac,rv64ima,rv64im,rv64i,lx6,lx106);
105+
TSUBARCH = (saNone,armv4,armv4t,armv6,armv6m,armv7a,armv7em,armv7m,armv8,armv8a,avr1,avr2,avr25,avr35,avr4,avr5,avr51,avr6,avrtiny,avrxmega3,pic32mx,rv32ec,rv32e,rv32imac{,rv32ima,rv32im},rv32i,rv64imac{,rv64ima,rv64im},rv64i,lx6,lx106);
106106
//TABI = (default,sysv,aix,darwin,elfv2,eabi,armeb,eabihf,oldwin32gnu,aarch64ios,riscvhf,linux386_sysv,windowed,call0);
107107
TABI = (default,eabi,eabihf,aarch64ios,riscvhf,windowed,call0);
108108
TARMARCH = (none,armel,armeb,armhf);
@@ -123,7 +123,7 @@ interface
123123
SUBARCH_AARCH64 = [TSUBARCH.armv8a];
124124
SUBARCH_AVR = [TSUBARCH.avr1..TSUBARCH.avrxmega3];
125125
SUBARCH_MIPSEL = [TSUBARCH.pic32mx];
126-
SUBARCH_RISCV32 = [TSUBARCH.rv32imac..TSUBARCH.rv32i];
126+
SUBARCH_RISCV32 = [TSUBARCH.rv32ec..TSUBARCH.rv32i];
127127
SUBARCH_RISCV64 = [TSUBARCH.rv64imac..TSUBARCH.rv64i];
128128
SUBARCH_XTENSA = [TSUBARCH.lx6..TSUBARCH.lx106];
129129
SUBARCH_ULTIBO = [TSUBARCH.armv6,TSUBARCH.armv7a,TSUBARCH.armv8];

sources/revision.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
const
22
{%H-}DELUXEVERSION='2.4.0fp';
33
{%H-}RevisionStr='503';
4-
{%H-}VersionDate='20240717';
4+
{%H-}VersionDate='20240924';

sources/updeluxe/fpcupdeluxemainform.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -2793,7 +2793,7 @@ procedure ShowInfo(info:string);
27932793

27942794
if (FPCupManager.CrossOS_Target=TOS.embedded) then
27952795
begin
2796-
success:=(FPCupManager.CrossCPU_Target in [TCPU.avr,TCPU.arm,TCPU.aarch64,TCPU.mipsel,TCPU.wasm32]);
2796+
success:=(FPCupManager.CrossCPU_Target in [TCPU.avr,TCPU.arm,TCPU.aarch64,TCPU.mipsel,TCPU.wasm32,TCPU.riscv32,TCPU.riscv64]);
27972797
if (NOT success) then
27982798
begin
27992799
ShowInfo('No valid CPU target for embedded.');
@@ -2803,7 +2803,7 @@ procedure ShowInfo(info:string);
28032803

28042804
if (FPCupManager.CrossOS_Target=TOS.freertos) then
28052805
begin
2806-
success:=(FPCupManager.CrossCPU_Target in [TCPU.xtensa,TCPU.arm]);
2806+
success:=(FPCupManager.CrossCPU_Target in [TCPU.xtensa,TCPU.arm,TCPU.riscv32]);
28072807
if (NOT success) then
28082808
begin
28092809
ShowInfo('No valid CPU target for FreeRTOS.');

up.lpr

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
m_any_to_embeddedarm,
122122
m_any_to_embeddedavr,
123123
m_any_to_embeddedmipsel,
124+
m_any_to_embeddedriscv32,
124125
m_any_to_javajvm,
125126
m_any_to_aixpowerpc,
126127
m_any_to_aixpowerpc64,

0 commit comments

Comments
 (0)