cemu
载入中...
搜索中...
未找到
cemu.h
浏览该文件的文档.
1
12#ifndef CEMU_H
13#define CEMU_H
14
15// ==================================================================== //
16// Include
17// ==================================================================== //
18
19#include "cpu.h"
20#include "loader.h"
21#include "utils.h"
22
23// 测试
24void run_unit_test() {
25 // test
26 ut_print_test();
27}
28
29// ==================================================================== //
30// Monitor Command Callback
31// ==================================================================== //
32
33void help_command_callback() {
34 printf("help info\n");
35}
36
37void run_command_callback(char *args, CPU *cpu) {
38 cpu_step(cpu, -1);
39}
40
41void step_command_callback(char *args, CPU *cpu) {
42 if(args != NULL && strlen(args) > 0){
43 if(!cpu_step(cpu, atoi(args)))
44 log_error("CPU step error!");
45 }else {
46 log_warn("step one");
47 if(!cpu_step(cpu, 1))
48 log_error("CPU step error!");
49 }
50}
51
52// ==================================================================== //
53// Argparse Command Callback
54// ==================================================================== //
55
56ap_def_callback(default_callback) {
57 if(argc <= 1) {
58 log_error("No input file");
59 exit(-1);
60 }
61 CPU cpu;
62 cpu_loop(&cpu, ap_get("input")->value);
63}
64
65ap_def_callback(hello_callback) {
66 log_debug("Hello, World!");
67 log_trace("Hello, World!");
68 log_info("Hello, World!");
69 log_warn("Hello, World!");
70 log_error("Hello, World!");
71 log_assert(5 == 5, "Hello, World!");
72}
73
74ap_def_callback(test_callback) {
75 ap_arg_t* arg_o = ap_get("output");
76 log_assert(arg_o != NULL, "arg_o not NULL");
77 log_assert(arg_o->value == NULL, "");
78
79 if (!arg_o->value) {
80 printf("no value. init: %s\n", arg_o->init.s);
81 } else {
82 printf("option output: %s\n", arg_o->value);
83 }
84 int q_l;
85 if(!ap_get("quiet")->value) {
86 q_l = ap_get("quiet")->init.i;
87 } else {
88 q_l = atoi(ap_get("quiet")->value);
89 }
90 printf("set quiet: %d\n", q_l);
91 ut_set_quiet(q_l);
92 run_unit_test();
93}
94
95ap_def_callback(debug_callback) {
96
97 CPU cpu;
98 // 1. 初始化:cpu, 寄存器 regs 和程序计数器 pc
99 cpu_init(&cpu);
100 // 2. 加载文件
101 if(!ap_get("input")->value) {
102 char* default_input = "./test/temp_02.out";
103 log_warn("No input file, use: %s", default_input);
104 load_elf(&cpu, default_input);
105 } else {
106 load_elf(&cpu, ap_get("input")->value);
107 }
108 linenoiseHistoryLoad("history.txt"); // Load command history from file
109 char *line;
110 while ((line = linenoise(">> ")) != NULL) {
111 if (line[0] != '\0') {
112 linenoiseHistoryAdd(line); // Add command to history
113 linenoiseHistorySave("history.txt"); // Save command history to file
114 char *command = strtok(line, " "); // 解析命令
115 char *args = strtok(NULL, " "); // 解析参数
116 if (strcmp(command, "help") == 0 || strcmp(command, "h" ) == 0) {
117 help_command_callback();
118 } else if (strcmp(command, "run" ) == 0 || strcmp(command, "r" ) == 0) {
119 run_command_callback(args, &cpu);
120 } else if (strcmp(command, "step") == 0 || strcmp(command, "si") == 0) {
121 step_command_callback(args, &cpu);
122 } else if (strcmp(command, "load") == 0 || strcmp(command, "l" ) == 0) {
123 load_elf(&cpu, args);
124 } else if (strcmp(command, "quit") == 0 || strcmp(command, "q" ) == 0) {
125 free(line);
126 log_info("Bye!");
127 exit(0);
128 } else {
129 log_warn("Unknown command: %s", command);
130 }
131 free(line);
132 }
133 }
134}
135
136
137#endif // CEMU_H
static ap_arg_t * ap_get(char *arg_name)
根据参数名获取参数值
Definition argparse-new.h:268
int cpu_step(CPU *cpu, int step)
处理器步进执行
Definition cpu.c:792
void cpu_init(CPU *cpu)
处理器初始化给定的CPU, 将指针指向的CPU中的寄存器全部置 0, 并将程序寄存器pc的值设为内存的起始地址。
Definition cpu.c:592
int cpu_loop(CPU *cpu, char *filename)
处理器循环执行
Definition cpu.c:821
中央处理器头文件
#define NULL
Definition list.h:22
文件加载头文件
#define log_warn(...)
Definition log.h:136
#define log_error(...)
Definition log.h:139
#define log_assert(condition,...)
Definition log.h:149
#define log_info(...)
Definition log.h:133
#define log_debug(...)
Definition log.h:130
#define log_trace(...)
Definition log.h:127
中央处理器结构体
Definition cpu.h:35
Definition argparse-new.h:90
工具头文件