1 // 2 // Copyright (c) 2010-2024 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 9 using System.Collections.Generic; 10 11 namespace Antmicro.Renode.Peripherals.CPU 12 { 13 public static class LLVMArchitectureMapping 14 { IsSupported(ICPU cpu)15 public static bool IsSupported(ICPU cpu) 16 { 17 return SupportedArchitectures.ContainsKey(cpu.Architecture); 18 } 19 GetTripleAndModelKey(ICPU cpu, uint flags, out string triple, out string model)20 public static void GetTripleAndModelKey(ICPU cpu, uint flags, out string triple, out string model) 21 { 22 triple = SupportedArchitectures[cpu.Architecture]; 23 if(triple == "armv7a" && flags > 0) 24 { 25 triple = "thumb"; 26 } 27 28 if(!ModelTranslations.TryGetValue(cpu.Model, out model)) 29 { 30 model = cpu.Model.ToLower(); 31 } 32 33 if(model == "cortex-r52") 34 { 35 triple = "arm"; 36 } 37 38 // RISC-V extensions Zicsr and Zifencei are not supported in LLVM yet: 39 // https://discourse.llvm.org/t/support-for-zicsr-and-zifencei-extensions/68369 40 // https://reviews.llvm.org/D143924 41 // The LLVM version used by Renode (at the time of adding this logic) is 14.0.0-rc1 42 if(model.Contains("_zicsr")) 43 { 44 model = model.Replace("_zicsr", ""); 45 } 46 47 if(model.Contains("_zifencei")) 48 { 49 model = model.Replace("_zifencei", ""); 50 } 51 } 52 53 private static readonly Dictionary<string, string> SupportedArchitectures = new Dictionary<string, string> 54 { 55 { "arm", "armv7a" }, 56 { "arm-m", "thumb" }, 57 { "arm64", "arm64" }, 58 { "mips", "mipsel" }, 59 { "riscv", "riscv32" }, 60 { "riscv64","riscv64" }, 61 { "ppc", "ppc" }, 62 { "ppc64", "ppc64le" }, 63 { "sparc", "sparc" }, 64 { "i386", "i386" }, 65 { "x86_64", "x86_64" } 66 }; 67 68 private static readonly Dictionary<string, string> ModelTranslations = new Dictionary<string, string> 69 { 70 { "x86" , "i386" }, 71 { "x86_64" , "x86-64" }, 72 // this case is included because of #3250 73 { "arm926" , "arm926ej-s" }, 74 // see: https://reviews.llvm.org/D12692 75 { "cortex-m4f", "cortex-m4" }, 76 { "cortex-r5f", "cortex-r5" }, 77 { "e200z6" , "ppc32" }, 78 { "gr716" , "leon3" } 79 }; 80 } 81 } 82