public void RegisterLink() { CoreRegisterGroup <uint> x = new CoreRegisterGroup <uint>(16); CoreRegister <uint> x0 = x.LinkRegister(0); x0.Value = 0xF1FF0000; Assert.AreEqual(x0.Value, x[0]); }
public void RV32ICoreInitializeTest() { RV32ICore core = new RV32ICore(); CoreRegister <uint> ra = typeof(RV32ICore).GetField("abi_ra", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(core) as CoreRegister <uint>; CoreRegisterGroup <uint> rGroup = typeof(RV32ICore).GetField("coreRegisterGroup", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(core) as CoreRegisterGroup <uint>; ra.Value = 0x00100020; Assert.AreEqual(ra.Value, rGroup[1]); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // The following line enables Application Insights telemetry collection. services.AddApplicationInsightsTelemetry(); services.AddControllers(); // Register Api services.AddScoped <IAuthService, AuthService>(); services.AddScoped <IOidcService, OidcService>(); services.AddScoped <IJwtGenerator, JwtGenerator>(); services.AddScoped <IJwtValidator, JwtValidator>(); services.AddScoped <IJwtDecoder, JwtDecoder>(); // Register Infrastructure InfrastructureRegister.RegisterDbContext(services, Configuration.GetConnectionString("DefaultConnection")); InfrastructureRegister.RegisterRepository(services); // Register Core CoreRegister.RegisterServices(services); // Register Identity & Authentication services.AddIdentity <User, Role>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(cfg => { cfg.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = Configuration["Jwt:Issuer"], ValidAudience = Configuration["Jwt:Issuer"], IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])), ClockSkew = TimeSpan.Zero // remove delay of token when expire }; }); // Register the Swagger generator, defining 1 or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "API", Version = "v1" }); }); }
public void RV32InstructionFetch32BTest() { RV32ICore core = new RV32ICore(); uint instruction = 0b0100000_00011_00010_000_00001_0110011U; // sub r1, r2, r3 byte[] buffer = BitConverter.GetBytes(instruction); core.OpenInstructionStream(BitConverter.IsLittleEndian ? buffer : buffer.Reverse().ToArray()); core.ResetCore(); MethodInfo fetch = typeof(RV32ICore).GetMethod($"{nameof(RISCVSharp)}.{nameof(IRV32Fetch32B)}.Fetch32B", BindingFlags.Instance | BindingFlags.NonPublic); fetch.Invoke(core, null); FieldInfo fetched = typeof(RV32ICore).GetField("fetchRegister", BindingFlags.Instance | BindingFlags.NonPublic); CoreRegister <uint> reg = fetched.GetValue(core) as CoreRegister <uint>; Console.WriteLine($"Instruction in memory = {instruction.ToString("X8")}, Instruction fetched = {reg.Value.ToString("X8") }"); Assert.AreEqual(reg.Value, instruction); }
public void RV32InstructionSplitDecodeTest() { RV32ICore core = new RV32ICore(); core.ResetCore(); uint instruction = 0b0100000_00011_00010_000_00001_0110011U; // sub r1, r2, r3 // Direct set fetch register FieldInfo fetched = typeof(RV32ICore).GetField("fetchRegister", BindingFlags.Instance | BindingFlags.NonPublic); CoreRegister <uint> freg = new CoreRegister <uint>(instruction); fetched.SetValue(core, freg); // Decode MethodInfo decode = typeof(RV32ICore).GetMethod($"{nameof(RISCVSharp)}.{nameof(IRV32Decode)}.InstructionSplitDecode32B", BindingFlags.Instance | BindingFlags.NonPublic); decode.Invoke(core, null); Dictionary <string, uint> asserts = new Dictionary <string, uint>() { { "decodeOpcodeRegister", 0b0110011U },
/// <summary> /// Create a RV32I 32-bit integer RISC-V Core /// </summary> public RV32ICore() { coreRegisterGroup = new CoreRegisterGroup <uint>(coreRegisterCount); // Link the specific function registers constant_0 = coreRegisterGroup.LinkRegister(0); abi_ra = coreRegisterGroup.LinkRegister(1); abi_sp = coreRegisterGroup.LinkRegister(2); abi_gp = coreRegisterGroup.LinkRegister(3); abi_tp = coreRegisterGroup.LinkRegister(4); // The x0 register always 0 constant_0.Value = 0; // All register set to zero foreach (CoreRegister <uint> register in coreRegisterGroup) { register.Value = 0; } // Clear program counter (PC) reg_pc = new CoreRegister <uint>(0); }