|
| 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 | + |
0 commit comments