2024-01-23 13:33:04 +00:00
|
|
|
/* simdata.c
|
|
|
|
|
|
|
|
This file is part of the "First" CPU simulator project.
|
|
|
|
|
|
|
|
Copyright (c) 2024 Efthymios Kritikos
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include "simdata.h"
|
2024-01-23 19:35:57 +00:00
|
|
|
#include <stdio.h>
|
2024-01-22 12:11:07 +00:00
|
|
|
|
|
|
|
struct simdata_t *init_simdata(){
|
|
|
|
struct simdata_t * ret=malloc(sizeof(struct simdata_t));
|
2024-01-23 19:35:57 +00:00
|
|
|
|
|
|
|
if(!ret){
|
2024-01-22 12:11:07 +00:00
|
|
|
ret->current_clock=0;
|
2024-01-23 19:35:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret->RAM=malloc(16777216); //Maximum addressable memory
|
|
|
|
if(!ret->RAM){
|
|
|
|
printf("failed to allocate 16MiB of memory for the system ram");
|
|
|
|
free(ret);
|
|
|
|
return 0;
|
2024-01-22 12:11:07 +00:00
|
|
|
}
|
2024-01-23 19:35:57 +00:00
|
|
|
|
2024-02-05 21:25:00 +00:00
|
|
|
ret->registers=NULL;
|
2024-02-06 23:14:33 +00:00
|
|
|
ret->cpu_state=CPU_RUNNING;
|
2024-02-07 00:31:23 +00:00
|
|
|
ret->cpu_gui_hints=malloc(sizeof(struct cpu_gui_hints_t));
|
|
|
|
ret->cpu_gui_hints->decoding_list=NULL;
|
|
|
|
ret->cpu_gui_hints->fetching_list=NULL;
|
|
|
|
ret->cpu_gui_hints->executing_list=NULL;
|
2024-01-23 23:56:40 +00:00
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-02-07 00:31:23 +00:00
|
|
|
void free_instr_list(struct instr_list_t **addr_of_tofree){
|
|
|
|
struct instr_list_t *tofree=*addr_of_tofree;
|
|
|
|
while(tofree){
|
|
|
|
struct instr_list_t *temp=tofree;
|
|
|
|
tofree=tofree->next;
|
|
|
|
free(temp);
|
|
|
|
}
|
|
|
|
*addr_of_tofree=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int add_to_instr_list(struct instr_list_t **toadd,uint32_t address){
|
|
|
|
while(*toadd){
|
|
|
|
toadd=&((*toadd)->next);
|
|
|
|
}
|
|
|
|
*toadd=malloc(sizeof(struct instr_list_t));
|
|
|
|
(*toadd)->address=address;
|
|
|
|
(*toadd)->next=NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
void free_simdata(struct simdata_t *p){
|
2024-01-23 19:35:57 +00:00
|
|
|
free(p->RAM);
|
2024-02-07 00:31:23 +00:00
|
|
|
free_instr_list(&p->cpu_gui_hints->decoding_list);
|
|
|
|
free_instr_list(&p->cpu_gui_hints->fetching_list);
|
|
|
|
free_instr_list(&p->cpu_gui_hints->executing_list);
|
|
|
|
free(p->cpu_gui_hints);
|
2024-01-22 12:11:07 +00:00
|
|
|
free(p);
|
|
|
|
}
|