try catch 不处理动态内存,拆分riscv_rest
This commit is contained in:
6
make.py
6
make.py
@@ -25,9 +25,9 @@ CC = 'gcc'
|
||||
# HEX = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O ihex'
|
||||
# BIN = 'C:\\ARM_GCC\\bin\\arm-none-eabi-objcopy' + ' -O binary -S'
|
||||
|
||||
CSRC = ["main.c","test/signal_test.c"]
|
||||
CSRC = ["main.c","test/riscv_test.c","test/signal_test.c"]
|
||||
|
||||
CINC = ['-Isoft',"-Icpu", "-I./","-Itest"]
|
||||
CINC = ['-Isoft',"-Iriscv_cpu", "-I./","-Itest"]
|
||||
|
||||
CDEF = ["-DTEST","-DLINUX"]
|
||||
|
||||
@@ -194,7 +194,7 @@ def main():
|
||||
os.makedirs(BUILD_DIR)
|
||||
|
||||
CSRC+=find_type('soft',['c','C'])
|
||||
CSRC+=find_type('cpu',['c','C'])
|
||||
CSRC+=find_type('riscv_cpu',['c','C'])
|
||||
CSRC=search_lambda(CSRC)
|
||||
moc_file_create(f"{BUILD_DIR}/moc_tmp.c",list(item[2:] for item in CINC))
|
||||
CSRC.append(f"{BUILD_DIR}/moc_tmp.c")
|
||||
|
@@ -6,9 +6,7 @@
|
||||
#include "errno.h"
|
||||
#include "string.h"
|
||||
|
||||
// cpu外设
|
||||
#include "print.h"
|
||||
#include "timer.h"
|
||||
|
||||
|
||||
#include "../main.h"
|
||||
|
||||
@@ -827,64 +825,3 @@ int riscv_run(riscv_t* riscv) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
long get_file_size(FILE *stream)
|
||||
{
|
||||
long file_size = -1;
|
||||
long cur_offset = ftell(stream); // 获取当前偏移位置
|
||||
if (cur_offset == -1) {
|
||||
printf("ftell failed :%s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fseek(stream, 0, SEEK_END) != 0) { // 移动文件指针到文件末尾
|
||||
printf("fseek failed: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
file_size = ftell(stream); // 获取此时偏移值,即文件大小
|
||||
if (file_size == -1) {
|
||||
printf("ftell failed :%s\n", strerror(errno));
|
||||
}
|
||||
if (fseek(stream, cur_offset, SEEK_SET) != 0) { // 将文件指针恢复初始位置
|
||||
printf("fseek failed: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return file_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
riscv_t riscv = { 0 };
|
||||
|
||||
|
||||
int thread_fun_r(void* t)
|
||||
{
|
||||
int argc;
|
||||
char** argv;
|
||||
argc = get_argv(&argv);
|
||||
|
||||
char *bin_name="riscv.bin";
|
||||
if(argc>1){
|
||||
bin_name=argv[1];
|
||||
}
|
||||
|
||||
printf("riscv start\n");
|
||||
FILE *file=fopen(bin_name, "rb" );
|
||||
if(file==NULL)
|
||||
{
|
||||
printf("open file %s error\n",bin_name);
|
||||
return -1;
|
||||
}
|
||||
riscv.rom_size = get_file_size(file);
|
||||
printf("rom size: %d\n", riscv.rom_size);
|
||||
riscv.rom = calloc((riscv.rom_size + 3) / 4, 4);
|
||||
fread(riscv.rom, 1, riscv.rom_size, file);
|
||||
fclose(file);
|
||||
|
||||
riscv_register_device(&riscv, print_dev());
|
||||
riscv_register_device(&riscv, timer_dev());
|
||||
riscv_init(&riscv, riscv.rom, 0x80000000, riscv.rom_size);
|
||||
riscv_device_init(&riscv);
|
||||
riscv_run(&riscv);
|
||||
|
||||
return 0;
|
||||
}
|
@@ -248,4 +248,12 @@ typedef struct riscv_t{
|
||||
#define IRQ_M_TIMER 7
|
||||
#define IRQ_M_EXT 11
|
||||
|
||||
|
||||
|
||||
int riscv_register_device(riscv_t* riscv, const device_t* device);
|
||||
int riscv_init(riscv_t* riscv, uint32_t* rom, uint32_t rom_addr_base, uint32_t rom_size);
|
||||
int riscv_device_init(riscv_t* riscv);
|
||||
int riscv_run(riscv_t* riscv);
|
||||
|
||||
|
||||
#endif
|
@@ -8,6 +8,7 @@
|
||||
#include "debug.h"
|
||||
#include "string.h"
|
||||
#include "ctype.h"
|
||||
#include "mystdlib.h"
|
||||
|
||||
|
||||
// c语言词法分析
|
||||
|
@@ -4,7 +4,8 @@
|
||||
#define exception_h__
|
||||
|
||||
#include "setjmp.h"
|
||||
#include "mystdlib.h"
|
||||
#include "stdlib.h"
|
||||
// #include "mystdlib.h"
|
||||
|
||||
#define THROW_LOG__MAX_SIZE 1024
|
||||
|
||||
@@ -12,7 +13,7 @@
|
||||
typedef struct _jmp_fram{
|
||||
struct _jmp_fram *next;
|
||||
struct _jmp_fram *last;
|
||||
map_def *mem;
|
||||
// map_def *mem;
|
||||
jmp_buf fram;
|
||||
}jmp_fram;
|
||||
|
||||
@@ -41,9 +42,9 @@ typedef struct{
|
||||
#define jmp_last(j) {\
|
||||
if((*j)){\
|
||||
jmp_fram *l=(*j)->last;\
|
||||
if(l){\
|
||||
/*if(l){\
|
||||
__mem_mov(&(l)->mem,&(*j)->mem);\
|
||||
}\
|
||||
}*/\
|
||||
free(*j);\
|
||||
(*j)=l;\
|
||||
if(*j){\
|
||||
@@ -56,7 +57,7 @@ typedef struct{
|
||||
#define jmp_clear(j) {\
|
||||
if((*j)){\
|
||||
jmp_fram *l=(*j)->last;\
|
||||
__mem_clear(&(*j)->mem);\
|
||||
/*__mem_clear(&(*j)->mem);*/\
|
||||
free(*j);\
|
||||
(*j)=l;\
|
||||
if(*j){\
|
||||
|
@@ -88,3 +88,6 @@ mythread_t *sigthread_init() {
|
||||
}
|
||||
|
||||
|
||||
__attribute__((weak)) void* signal_find_slot_func(const char* name) {
|
||||
return 0;
|
||||
}
|
||||
|
@@ -11,18 +11,22 @@
|
||||
|
||||
|
||||
|
||||
typedef struct _map_def{
|
||||
size_t map_size;
|
||||
size_t mam_used;
|
||||
size_t mem_map[0];
|
||||
}map_def;
|
||||
// typedef struct _map_def{
|
||||
// size_t map_size;
|
||||
// size_t mam_used;
|
||||
// size_t mem_map[0];
|
||||
// }map_def;
|
||||
|
||||
|
||||
void __mem_clear(map_def **m);
|
||||
void __mem_mov(map_def **d,map_def **s);
|
||||
// void __mem_clear(map_def **m);
|
||||
// void __mem_mov(map_def **d,map_def **s);
|
||||
|
||||
void *mem_calloc(size_t memb_num, size_t memb_size);
|
||||
void *mem_malloc(size_t size);
|
||||
void mem_free(void *p);
|
||||
// void *mem_calloc(size_t memb_num, size_t memb_size);
|
||||
// void *mem_malloc(size_t size);
|
||||
// void mem_free(void *p);
|
||||
|
||||
#define mem_calloc calloc
|
||||
#define mem_malloc malloc
|
||||
#define mem_free free
|
||||
|
||||
#endif
|
||||
|
75
test/riscv_test.c
Normal file
75
test/riscv_test.c
Normal file
@@ -0,0 +1,75 @@
|
||||
|
||||
#include "stdio.h"
|
||||
#include "errno.h"
|
||||
#include "stdlib.h"
|
||||
#include "string.h"
|
||||
#include "../main.h"
|
||||
|
||||
#include "../riscv_cpu/riscv.h"
|
||||
// cpu外设
|
||||
#include "../riscv_cpu/print.h"
|
||||
#include "../riscv_cpu/timer.h"
|
||||
|
||||
|
||||
long get_file_size(FILE *stream)
|
||||
{
|
||||
long file_size = -1;
|
||||
long cur_offset = ftell(stream); // 获取当前偏移位置
|
||||
if (cur_offset == -1) {
|
||||
printf("ftell failed :%s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if (fseek(stream, 0, SEEK_END) != 0) { // 移动文件指针到文件末尾
|
||||
printf("fseek failed: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
file_size = ftell(stream); // 获取此时偏移值,即文件大小
|
||||
if (file_size == -1) {
|
||||
printf("ftell failed :%s\n", strerror(errno));
|
||||
}
|
||||
if (fseek(stream, cur_offset, SEEK_SET) != 0) { // 将文件指针恢复初始位置
|
||||
printf("fseek failed: %s\n", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return file_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
riscv_t riscv = { 0 };
|
||||
|
||||
|
||||
int thread_fun(void* t)
|
||||
{
|
||||
int argc;
|
||||
char** argv;
|
||||
argc = get_argv(&argv);
|
||||
|
||||
char *bin_name="riscv.bin";
|
||||
if(argc>1){
|
||||
bin_name=argv[1];
|
||||
}
|
||||
|
||||
printf("riscv start\n");
|
||||
FILE *file=fopen(bin_name, "rb" );
|
||||
if(file==NULL)
|
||||
{
|
||||
printf("open file %s error\n",bin_name);
|
||||
return -1;
|
||||
}
|
||||
riscv.rom_size = get_file_size(file);
|
||||
printf("rom size: %d\n", riscv.rom_size);
|
||||
riscv.rom = calloc((riscv.rom_size + 3) / 4, 4);
|
||||
fread(riscv.rom, 1, riscv.rom_size, file);
|
||||
fclose(file);
|
||||
|
||||
riscv_register_device(&riscv, print_dev());
|
||||
riscv_register_device(&riscv, timer_dev());
|
||||
riscv_init(&riscv, riscv.rom, 0x80000000, riscv.rom_size);
|
||||
riscv_device_init(&riscv);
|
||||
riscv_run(&riscv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -6,6 +6,7 @@
|
||||
#include "errno.h"
|
||||
#include "stdio.h"
|
||||
#include "string.h"
|
||||
#include "exception.h"
|
||||
|
||||
#include "signal_test.h"
|
||||
|
||||
@@ -120,7 +121,7 @@ static test_sig_obj g_sig_obj = { .test_var = 1, };
|
||||
static test_sig_obj2 g_sig_obj2 = { .test_var = 2, };
|
||||
static test_sig_obj3 g_sig_obj3;
|
||||
|
||||
int thread_fun(void* t) {
|
||||
int thread_fun_s(void* t) {
|
||||
mythread_t* th = sigthread_init();
|
||||
printf("thread_fun start\n");
|
||||
connect(&g_sig_obj, test_signal, th, &g_sig_obj2, test_slot);
|
||||
@@ -132,6 +133,8 @@ int thread_fun(void* t) {
|
||||
emit test_signal2(&g_sig_obj, 5, 6,"hello world");
|
||||
mdelay(1000);
|
||||
printf("test end\n");
|
||||
throw_("my err");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user