diff --git a/.gitignore b/.gitignore index 5e44124..d89083e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build* *.cfg +commit.txt diff --git a/Makefile b/Makefile index 5e261fc..b74c87f 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ # #--- MAJOR := 0 -MINOR := 8 +MINOR := 9 PATCH := 0 EXTRAVERSION := @@ -236,16 +236,18 @@ target-$(tname)-objcopy := $(CONFIG.TOOLCHAIN)-objcopy # generate platform specific flags ifeq ($1,fx) target-$(tname)-cflags += -D FX9860G -m3 + target-$(tname)-cflags += $(FX_INCLUDE) $(FX_CFLAGS) target-$(tname)-ldflags += -T fx9860g.ld target-$(tname)-libs := -L. -L $(GCC_INCLUDE_FX) - target-$(tname)-libs += -lgint-fx -lgintrace-fx -lgint-fx -lgcc + target-$(tname)-libs += -lgint-fx -lgintrace-fx -lgint-fx -lc -lgcc target-$(tname)-exec := $3.g1a endif ifeq ($1,cg) target-$(tname)-cflags += -D FXCG50 -m4-nofpu + target-$(tname)-cflags += $(CG_INCLUDE) $(CG_CFLAGS) target-$(tname)-ldflags += -T fxcg50.ld target-$(tname)-libs := -L. -L $(GCC_INCLUDE_CG) - target-$(tname)-libs += -lgint-cg -lgintrace-cg -lgint-cg -lgcc + target-$(tname)-libs += -lgint-cg -lgintrace-cg -lgint-cg -lc -lgcc target-$(tname)-exec := $3.g3a endif diff --git a/TODO b/TODO index e888b58..371b994 100644 --- a/TODO +++ b/TODO @@ -3,15 +3,17 @@ * fix fx9860 support @update +* session: add custom world in each session * makefile: handle header dependencies * makefile: handle dynamic lib generation * makefile: generate the documentation * context: refacto printXY() ! * hexdump: search commands * callgraph: improve user interface. -* icon @feature +* be compilent with giteapc +* switch to cmake * add documentation * switch to justUI * add drivers menu diff --git a/assets/cg/icon-cg-sel.png b/assets/cg/icon-cg-sel.png index 7137b50..9503f54 100644 Binary files a/assets/cg/icon-cg-sel.png and b/assets/cg/icon-cg-sel.png differ diff --git a/assets/cg/icon-cg-uns.png b/assets/cg/icon-cg-uns.png index 3c99f62..45d5867 100644 Binary files a/assets/cg/icon-cg-uns.png and b/assets/cg/icon-cg-uns.png differ diff --git a/demo/main.c b/demo/main.c index ecda3e9..c028e19 100644 --- a/demo/main.c +++ b/demo/main.c @@ -1,5 +1,6 @@ #include "gintrace/tracer.h" + #include #include #include @@ -36,15 +37,22 @@ int main(void) } #endif +#ifdef FXCG50 /* get syscall address */ systab = *(void ***)0x8002007c; - //syscall = systab[0x1e48]; // Fugue_debug_menu - syscall = systab[0x1da3]; // Bfile_OpenFile_OS - + //syscall = systab[0x1e48]; // Fugue_debug_menu() + //syscall = systab[0x1da3]; // Bfile_OpenFile_OS() + //syscall = systab[0x1353]; // Comm_Open() + //syscall = systab[0x1dac]; // Bfile_ReadFile_OS() + syscall = systab[0x1630]; // App_optimize() + //syscall = systab[0x1e56]; +#endif /* prepare tracer */ - session = tracer_create_session(syscall, - TRACER_DISASM | TRACER_CONTEXT | TRACER_HEXDUMP | TRACER_CALLGRAPH); + session = tracer_create_session( + syscall, + TRACER_DISASM | TRACER_CONTEXT | TRACER_HEXDUMP + ); if (session == NULL) { dclear(C_WHITE); dtext(0, 0, C_BLACK, "Unable to create tracer session"); @@ -59,12 +67,24 @@ int main(void) //--- // TEST part //--- - void (*bfile_openfile_os)(const uint16_t *filename, int mode, int p3); + void (*app_optimize)(void) = (void*)syscall; + gint_world_switch(GINT_CALL(app_optimize)); + + +#if 0 + int (*bfile_openfile_os)(const uint16_t *filename, int mode, int p3); + int (*bfile_readfile_os)(int handle, void *b, size_t n, off_t p); + //void (*comm_open)(int mode) = syscall; + uint8_t buffer[128]; + int handle; gint_switch_to_world(kernel_env_casio); - bfile_openfile_os = syscall; - bfile_openfile_os(u"\\\\fls0\\abcdefgijklmn", BFile_ReadOnly, 0); + bfile_openfile_os = systab[0x1da3]; + handle = bfile_openfile_os(u"\\\\fls0\\azerty", BFile_ReadOnly, 0); + bfile_readfile_os = systab[0x1dac]; + bfile_readfile_os(handle, buffer, 128, 0); gint_switch_to_world(kernel_env_gint); +#endif diff --git a/gintrace.g3a b/gintrace.g3a index 0351cf7..4e19d28 100644 Binary files a/gintrace.g3a and b/gintrace.g3a differ diff --git a/libgintrace-cg.a b/libgintrace-cg.a index ea4ba1f..927edab 100644 Binary files a/libgintrace-cg.a and b/libgintrace-cg.a differ diff --git a/src/gint.c b/src/gint.c deleted file mode 100644 index f2dc2d1..0000000 --- a/src/gint.c +++ /dev/null @@ -1,57 +0,0 @@ -#include "gintrace/ubc.h" - -#include -#include -#include -#include -#include - -/* external symbols */ -extern void *kernel_env_casio; -extern void *kernel_env_gint; -extern void *kernel_env_tracer; - -/* gint_switch(): Temporarily switch out of gint */ -void gint_switch(void (*function)(void)) -{ - void *buffctx_current; - void *buffctx; - - /* check useless action */ - if (function == NULL) - return; - - /* check useless world switch */ - buffctx_current = drivers_get_current(); - if (kernel_env_casio == buffctx_current) { - function(); - return; - } - - /* Switch from gint to the OS after a short wait */ - ubc_uninstall(); - buffctx = drivers_switch(kernel_env_casio); - ubc_install(); - - /* involve the function */ - function(); - - /* then switch back to gint once the os finishes working */ - ubc_uninstall(); - drivers_switch(buffctx); - ubc_install(); -} - -/* Switch from gint to the OS after a short wait */ -void *gint_switch_to_world(void *buffctx) -{ - void *buffctx_current; - - buffctx_current = drivers_get_current(); - if (buffctx != buffctx_current) { - ubc_uninstall(); - drivers_switch(buffctx); - ubc_install(); - } - return (buffctx_current); -} diff --git a/src/menu/callgraph.c b/src/menu/callgraph.c index 603674d..fbf77d8 100644 --- a/src/menu/callgraph.c +++ b/src/menu/callgraph.c @@ -14,11 +14,6 @@ #include "./src/menu/internal/dictionary.h" -/* internal info (TODO: move me) */ -extern void *kernel_env_gint; -extern void *kernel_env_casio; -extern void *gint_switch_to_world(void *buffctx); - //--- // callode management //--- @@ -311,11 +306,12 @@ static void callgraph_command(struct tsession *session, int argc, char **argv) input_write("argument missing"); return; } - if (strcmp(argv[0], "export") != 0) { + //if (strcmp(argv[0], "export") != 0) { input_write("'%s': command unknown", argv[0]); - return; - } + // return; + //} +#if 0 /* convert the filename (arg2) into Bfile pathname */ int i = -1; uint16_t pathname[14 + strlen(argv[1]) + 1]; @@ -377,6 +373,7 @@ static void callgraph_command(struct tsession *session, int argc, char **argv) BFile_Close(fd); gint_switch_to_world(kernel_env_gint); input_write("success"); +#endif } /* callgraph_special_ctor(): Special constructor used to generate the graph */ diff --git a/src/menu/context.c b/src/menu/context.c index 331b701..e5cacd4 100644 --- a/src/menu/context.c +++ b/src/menu/context.c @@ -57,11 +57,15 @@ static void context_ctor(struct tsession *session) /* context_display(); Display trace information */ static void context_display(struct tsession *session) { + uintptr_t __vbr; int x; int y; + __asm__ volatile ("stc vbr, %0": "=r"(__vbr)::); + x = session->menu.context.cursor.hoffset; y = session->menu.context.cursor.voffset; + printXY(0 + x, 0 + y, "vbr : %p", __vbr); printXY(0 + x, 0 + y, "gbr : %p", session->info.context->gbr); printXY(0 + x, 1 + y, "macl : %p", session->info.context->mach); printXY(0 + x, 2 + y, "mach : %p", session->info.context->macl); diff --git a/src/menu/internal/dictionary/syscalls.c b/src/menu/internal/dictionary/syscalls.c index 48d3a22..e412ca3 100644 --- a/src/menu/internal/dictionary/syscalls.c +++ b/src/menu/internal/dictionary/syscalls.c @@ -615,17 +615,33 @@ const struct sysname casio_syscalls[] = { // // Yatis // + {.syscall = 0x0dc0, .name = "void SMEM_Optimize(void)"}, + {.syscall = 0x0dd2, .name = "int SMEM_fugue_retval_to_bfile_revet(int retval);"}, + {.syscall = 0x0de2, .name = "int SMEM_bfile_get_file_info(int handle, uint8_t buffer[540]);"}, {.syscall = 0x0db0, .name = "int fugue_unmount(void);"}, {.syscall = 0x0db1, .name = "int fugue_mount(void);"}, {.syscall = 0x0dd2, .name = "const uint16_t *FONTCHARACTER_convert_to_FUGUECHARACTER(const uint16_t *src, uint8_t *dest);"}, + {.syscall = 0x0de2, .name = "int SMEM_get_file_info(int handle, uint8_t buffer[540]);"}, {.syscall = 0x0ea6, .name = "void Debug_menu_TestMode(void);"}, {.syscall = 0x0ea7, .name = "void Debug_menu_TestMode(int unknown);"}, - {.syscall = 0x1da1, .name = "int fugue_logical_format(void);"}, + {.syscall = 0x134e, .name = "int USB_Open(int param);"}, + {.syscall = 0x135d, .name = "int Comm_IsOpen(void);"}, + {.syscall = 0x135e, .name = "int Comm_GetCurrentSelector(void);"}, + {.syscall = 0x135f, .name = "int Comm_OS_wait(int delay_ms);"}, + {.syscall = 0x1361, .name = "int Serial_Reset(int action);"}, + {.syscall = 0x14ba, .name = "int USB_PowerOn(void);"}, + {.syscall = 0x14bb, .name = "int USB_PowerOff(void);"}, + {.syscall = 0x1da1, .name = "int SMEM_logical_format(void *unknown, int mode, int unknown);"}, {.syscall = 0x1e44, .name = "void Debug_menu_FileSystem(void);"}, {.syscall = 0x1e45, .name = "void Debug_menu_Fugue_OpenFileInfo(void);"}, {.syscall = 0x1e48, .name = "void Debug_menu_Fugue_VolumeInfo(void);"}, {.syscall = 0x1e49, .name = "void Debug_menu_Fugue_LogInfo(void);"}, {.syscall = 0x1e66, .name = "void Debug_menu_stackAndHeap(void);"}, + {.syscall = 0x1ece, .name = "void USB_InterruptHandler(void);"}, + {.syscall = 0x1d99, .name = "int SD_isMounted(void);"}, + {.syscall = 0x1dc3, .name = "int Bfile_Optimize(const uint16_t *device);"}, + {.syscall = 0x1263, .name = "int SD_read(int handle, void *buffer, size_t nb, off_t pos);"}, + {.syscall = 0x1267, .name = "int SD_optimize(void);"}, // // Stop diff --git a/src/tracer.c b/src/tracer.c index 9b9d086..62ff63c 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -6,6 +6,9 @@ /* global session (TODO: thread-safe) */ struct tsession *session = NULL; +//TODO: ELF PIE world +//TODO: custom world selection + /* tracer_new_session(): Create a new session */ struct tsession *tracer_create_session(void *address, int menu) { diff --git a/src/ubc/handler.c b/src/ubc/handler.c index 2a1c07a..38714b4 100644 --- a/src/ubc/handler.c +++ b/src/ubc/handler.c @@ -6,9 +6,7 @@ #include "gintrace/ubc.h" #include "gintrace/tracer.h" -/* world information */ -extern void *kernel_env_tracer; -extern void *gint_switch_to_world(void *buffctx); +#include /* gintrac_handler(): UBC handler * @note: @@ -40,7 +38,7 @@ void gintrace_handler(struct ucontext *context) } /* user break point */ - session->info.buffctx = gint_switch_to_world(kernel_env_tracer); + gint_world_switch_in(gint_world_os, gint_world_addin); menu_init(session->display.gmenu); while (menu_is_open(session->display.gmenu) == 0) { menu_draw(session->display.gmenu); @@ -56,5 +54,5 @@ void gintrace_handler(struct ucontext *context) /* unblock UBC interrupt */ ubc_unblock(); - gint_switch_to_world(session->info.buffctx); + gint_world_switch_out(gint_world_addin, gint_world_os); } diff --git a/src/ubc/kernel.S b/src/ubc/kernel.S index d41182c..71977ae 100644 --- a/src/ubc/kernel.S +++ b/src/ubc/kernel.S @@ -83,8 +83,8 @@ ubc_kernel_inth_prologue: lds.l @r15+, pr ! Clean exit. - rte ! Interrupt Exit. - nop ! (db) Safety first. + rte + nop .align 4 ubc_handler: .long _ubc_handler diff --git a/src/ubc/ubc.c b/src/ubc/ubc.c index 569afb6..ddfc5bf 100644 --- a/src/ubc/ubc.c +++ b/src/ubc/ubc.c @@ -8,10 +8,6 @@ struct sh7305_ubc_context ubctx; void (*ubc_handler)(struct ucontext *ctx) = NULL; int ubc_driver_installed = 0; -extern void *kernel_env_gint; -void *kernel_env_tracer = NULL; - - /* ubc_install(): Install the UBC driver */ void ubc_install(void) { @@ -47,10 +43,6 @@ void ubc_install(void) SH7305_UBC.CBR1.CE = 0; SH7305_UBC.CBCR.UBDE = 1; - /* generate the "tracer" tmp context */ - if (kernel_env_tracer == NULL) - drivers_context_duplicate(&kernel_env_tracer, kernel_env_gint); - /* indicate that the UBC driver is installed */ ubc_driver_installed = 1; }