Skip to content

Commit

Permalink
Added riscv32 embedded as cross-target.
Browse files Browse the repository at this point in the history
  • Loading branch information
LongDirtyAnimAlf committed Sep 24, 2024
1 parent 2e8e71c commit 2e3f5d3
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/gitrevision.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[master]v2.4.0e-2898(f43e73f)
[master]v2.4.0e-2899(2e8e71c)
3 changes: 1 addition & 2 deletions sources/crossinstallers/m_any_to_embeddedaarch64.pas
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,9 @@ function TAny_Embeddedaarch64.GetBinUtils(Basepath:string): boolean;
end;
{$endif unix}

// Now also allow for arm-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
if not result then
begin
BinPrefixTry:='aarch64-elf-';
BinPrefixTry:=TargetCPUName+'-elf-';
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
result:=SearchBinUtil(BasePath,AsFile);
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
Expand Down
4 changes: 2 additions & 2 deletions sources/crossinstallers/m_any_to_embeddedarm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ function TAny_Embeddedarm.GetBinUtils(Basepath:string): boolean;
end;
{$endif unix}

// Now also allow for arm-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
// Now also allow for cpu-none-eabi- binutilsprefix (e.g. launchpadlibrarian)
if not result then
begin
BinPrefixTry:='arm-none-eabi-';
BinPrefixTry:=TargetCPUName+'-none-eabi-';
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
result:=SearchBinUtil(BasePath,AsFile);
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
Expand Down
223 changes: 223 additions & 0 deletions sources/crossinstallers/m_any_to_embeddedriscv32.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
unit m_any_to_embeddedriscv32;
{ Cross compiles from any platform with correct binutils to Embedded RISCV32
Copyright (C) 2017 Alf
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version with the following modification:
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent modules,and
to copy and distribute the resulting executable under terms of your choice,
provided that you also meet, for each linked independent module, the terms
and conditions of the license of that module. An independent module is a
module which is not derived from or based on this library. If you modify
this library, you may extend this exception to your version of the library,
but you are not obligated to do so. If you do not wish to do so, delete this
exception statement from your version.
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. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
}

{
RV32IM:
RV32I: Base Integer Instruction Set
M: Instructions that multiply and divide values held in two integer registers
binutils:
./configure --with-arch=rv32im --with-abi=ilp32
}

{$mode objfpc}{$H+}

interface

uses
Classes, SysUtils;

implementation

uses
FileUtil, m_crossinstaller, fpcuputil;

type

{ TAny_Embeddedriscv32 }
TAny_Embeddedriscv32 = class(TCrossInstaller)
private
FAlreadyWarned: boolean; //did we warn user about errors and fixes already?
public
function GetLibs(Basepath:string):boolean;override;
function GetBinUtils(Basepath:string):boolean;override;
constructor Create;
destructor Destroy; override;
end;

{ TAny_Embeddedriscv32 }

function TAny_Embeddedriscv32.GetLibs(Basepath:string): boolean;
const
LibName='libgcc.a';
var
aABI:TABI;
S:string;
begin
// Arm-embedded does not need libs by default, but user can add them.
result:=inherited;

if result then exit;

if (FSubArch<>TSUBARCH.saNone) then
ShowInfo('Cross-libs: We have a subarch: '+SubArchName)
else
ShowInfo('Cross-libs: No subarch defined. Expect fatal errors.',etError);

// begin simple: check presence of library file in basedir
result:=SearchLibrary(Basepath,LibName);
// search local paths based on libraries provided for or adviced by fpc itself
if not result then
result:=SimpleSearchLibrary(BasePath,DirName,LibName);

if ((not result) AND (FSubArch<>TSUBARCH.saNone)) then
begin
result:=SimpleSearchLibrary(BasePath,ConcatPaths([DirName,SubArchName]),LibName);
if (not result) then
begin
for aABI in TABI do
begin
if aABI=TABI.default then continue;
result:=SimpleSearchLibrary(BasePath,ConcatPaths([DirName,SubArchName,GetABI(aABI)]),LibName);
if result then break;
end;
end;
end;

SearchLibraryInfo(result);

if result then
begin
FLibsFound:=True;

if PerformLibraryPathMagic(S) then
begin
AddFPCCFGSnippet('-Fl'+S,false);
end
else
begin
// If we do not have magic, add subarch to enclose
AddFPCCFGSnippet('#IFDEF CPU'+UpperCase(SubArchName));
AddFPCCFGSnippet('-Fl'+S);
AddFPCCFGSnippet('#ENDIF CPU'+UpperCase(SubArchName));
end;
end;

if not result then
begin
//libs path is optional; it can be empty
ShowInfo('Libspath ignored; it is optional for this cross compiler.');
FLibsPath:='';
FLibsFound:=True;
result:=true;
end;
end;

function TAny_Embeddedriscv32.GetBinUtils(Basepath:string): boolean;
var
AsFile: string;
BinPrefixTry: string;
{$ifdef unix}
i:integer;
{$endif unix}
begin
result:=inherited;
if result then exit;

// Start with any names user may have given
AsFile:=BinUtilsPrefix+ASFILENAME+GetExeExt;

result:=SearchBinUtil(BasePath,AsFile);
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);

{$ifdef unix}
// User may also have placed them into their regular search path:
if not result then
begin
for i:=Low(UnixBinDirs) to High(UnixBinDirs) do
begin
result:=SearchBinUtil(IncludeTrailingPathDelimiter(UnixBinDirs[i])+DirName, AsFile);
if not result then result:=SearchBinUtil(UnixBinDirs[i], AsFile);
if result then break;
end;
end;
{$endif unix}

// Now also allow for cpu-none-elf- binutilsprefix
if not result then
begin
BinPrefixTry:=TargetCPUName+'-none-elf-';
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
result:=SearchBinUtil(BasePath,AsFile);
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
if result then FBinUtilsPrefix:=BinPrefixTry;
end;

// Now also allow for empty binutilsprefix in the right directory:
if not result then
begin
BinPrefixTry:='';
AsFile:=BinPrefixTry+ASFILENAME+GetExeExt;
result:=SearchBinUtil(BasePath,AsFile);
if not result then result:=SimpleSearchBinUtil(BasePath,DirName,AsFile);
if result then FBinUtilsPrefix:=BinPrefixTry;
end;

SearchBinUtilsInfo(result);

if not result then
begin
FAlreadyWarned:=true;
end
else
begin
FBinsFound:=true;
// Configuration snippet for FPC
AddFPCCFGSnippet('-FD'+BinUtilsPath);
AddFPCCFGSnippet('-XP'+BinUtilsPrefix); {Prepend the binutils names};
end;
end;

constructor TAny_Embeddedriscv32.Create;
begin
inherited Create;
FTargetCPU:=TCPU.riscv32;
FTargetOS:=TOS.embedded;
Reset;
FAlreadyWarned:=false;
ShowInfo;
end;

destructor TAny_Embeddedriscv32.Destroy;
begin
inherited Destroy;
end;

var
Any_Embeddedriscv32:TAny_Embeddedriscv32;

initialization
Any_Embeddedriscv32:=TAny_Embeddedriscv32.Create;
RegisterCrossCompiler(Any_Embeddedriscv32.RegisterName,Any_Embeddedriscv32);

finalization
Any_Embeddedriscv32.Destroy;
end.

22 changes: 22 additions & 0 deletions sources/fpcupdefines.inc
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,25 @@

{.$define DISABLE_PPC_CONFIG_PATH}

{$ifdef FPC}

{$WARN 4104 OFF}
{$WARN 4105 OFF}
{$WARN 4106 OFF}
{$WARN 4107 OFF}
{$WARN 4108 OFF}

{$WARN 5024 OFF}
{$WARN 5027 OFF}
{$WARN 5037 OFF}
{$WARN 5057 OFF}
{$WARN 5091 OFF}
{$WARN 5092 OFF}

{$WARN 6058 OFF}

{$WARN CONSTRUCTING_ABSTRACT ERROR}

{$endif FPC}


10 changes: 10 additions & 0 deletions sources/installermanager.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1891,6 +1891,11 @@ procedure TFPCupManager.GetCrossToolsFileName(out BinsFileName,LibsFileName:stri
if (CrossCPU_Target=TCPU.arm) then toolversion:='V232';
if (CrossCPU_Target=TCPU.i386) then toolversion:='V232';
end;
TOS.embedded:
begin
ostype:='none';
if (CrossCPU_Target=TCPU.riscv32) then toolversion:='V241';
end;
end;
end;

Expand Down Expand Up @@ -1934,6 +1939,11 @@ procedure TFPCupManager.GetCrossToolsFileName(out BinsFileName,LibsFileName:stri
if (CrossCPU_Target in [TCPU.i386,TCPU.x86_64,TCPU.aarch64,TCPU.arm]) then s:='Darwin_All_Clang_12.zip';
if (CrossCPU_Target in [TCPU.powerpc,TCPU.powerpc64]) then s:='Darwin_PowerPC_GNU.zip';
end;
TOS.embedded:
begin
ostype:='none';
if (CrossCPU_Target=TCPU.riscv32) then toolversion:='V241';
end;
end;
end;

Expand Down
4 changes: 1 addition & 3 deletions sources/installeruniversal.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

{$modeswitch advancedrecords}

{$warn 6058 off}

{$i fpcupdefines.inc}

interface
Expand All @@ -56,7 +54,7 @@ TAPkgVersion = record
FMajor: integer;
FMinor: integer;
FRelease: integer;
FBuild: integer;
FBuild: integer;
public
function AsString: string;
procedure GetVersion(alpkdoc:TConfig;key:string);
Expand Down
4 changes: 2 additions & 2 deletions sources/m_crossinstaller.pas
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ interface
type
TCPU = (cpuNone,i386,x86_64,arm,aarch64,powerpc,powerpc64,mips,mipsel,avr,jvm,i8086,sparc,sparc64,riscv32,riscv64,m68k,xtensa,wasm32,loongarch64);
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);
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);
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);
//TABI = (default,sysv,aix,darwin,elfv2,eabi,armeb,eabihf,oldwin32gnu,aarch64ios,riscvhf,linux386_sysv,windowed,call0);
TABI = (default,eabi,eabihf,aarch64ios,riscvhf,windowed,call0);
TARMARCH = (none,armel,armeb,armhf);
Expand All @@ -123,7 +123,7 @@ interface
SUBARCH_AARCH64 = [TSUBARCH.armv8a];
SUBARCH_AVR = [TSUBARCH.avr1..TSUBARCH.avrxmega3];
SUBARCH_MIPSEL = [TSUBARCH.pic32mx];
SUBARCH_RISCV32 = [TSUBARCH.rv32imac..TSUBARCH.rv32i];
SUBARCH_RISCV32 = [TSUBARCH.rv32ec..TSUBARCH.rv32i];
SUBARCH_RISCV64 = [TSUBARCH.rv64imac..TSUBARCH.rv64i];
SUBARCH_XTENSA = [TSUBARCH.lx6..TSUBARCH.lx106];
SUBARCH_ULTIBO = [TSUBARCH.armv6,TSUBARCH.armv7a,TSUBARCH.armv8];
Expand Down
2 changes: 1 addition & 1 deletion sources/revision.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const
{%H-}DELUXEVERSION='2.4.0fp';
{%H-}RevisionStr='503';
{%H-}VersionDate='20240717';
{%H-}VersionDate='20240924';
4 changes: 2 additions & 2 deletions sources/updeluxe/fpcupdeluxemainform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2793,7 +2793,7 @@ procedure ShowInfo(info:string);

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

if (FPCupManager.CrossOS_Target=TOS.freertos) then
begin
success:=(FPCupManager.CrossCPU_Target in [TCPU.xtensa,TCPU.arm]);
success:=(FPCupManager.CrossCPU_Target in [TCPU.xtensa,TCPU.arm,TCPU.riscv32]);
if (NOT success) then
begin
ShowInfo('No valid CPU target for FreeRTOS.');
Expand Down
1 change: 1 addition & 0 deletions up.lpr
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
m_any_to_embeddedarm,
m_any_to_embeddedavr,
m_any_to_embeddedmipsel,
m_any_to_embeddedriscv32,
m_any_to_javajvm,
m_any_to_aixpowerpc,
m_any_to_aixpowerpc64,
Expand Down

0 comments on commit 2e3f5d3

Please sign in to comment.