Multithread gdbstub and execution, with cont/halt

This commit is contained in:
2023-10-08 17:42:44 +02:00
parent a10f56446a
commit f52699a8bf
4 changed files with 28 additions and 1 deletions

View File

@@ -42,6 +42,7 @@ void cpu_init()
{
cpu0 = calloc(1, sizeof(rv32_cpu_t));
pthread_mutex_init(&cpu0_mutex, 0);
pthread_cond_init(&cpu0->sim_condition, 0);
cpu0->regs.zero = 0;
}
@@ -651,6 +652,9 @@ void cpu_loop(rv32_cpu_t* cpu)
pthread_mutex_lock(&cpu0_mutex);
pthread_mutex_lock(&memory_mutex);
while(!cpu->sim_ticks_left)
pthread_cond_wait(&cpu0->sim_condition, &cpu0_mutex);
// Fetch
raw_instruction_t raw_instruction;
if(cpu->pc > memory_size - 4)
@@ -675,6 +679,11 @@ void cpu_loop(rv32_cpu_t* cpu)
cpu->pc += 4;
// Update simulation data
cpu->sim_ticks_done++;
if(cpu->sim_ticks_left != (-1))
cpu->sim_ticks_left--;
// Let go of cpu and memory mutex
pthread_mutex_unlock(&cpu0_mutex);
pthread_mutex_unlock(&memory_mutex);

View File

@@ -3,6 +3,7 @@
#include <stdint.h>
#include <pthread.h>
#include <stdlib.h>
/*
* This is a structure encoding for the registers of
@@ -184,8 +185,14 @@ typedef struct RV32_CPU_REGS
typedef struct RV32_CPU
{
// CPU values
rv32_cpu_regs_t regs;
uint32_t pc;
// Simulation data
ssize_t sim_ticks_left; // -1 : simulate forever
size_t sim_ticks_done;
pthread_cond_t sim_condition;
} rv32_cpu_t;
extern rv32_cpu_t* cpu0;