diff --git a/gdb.sh b/gdb.sh index 93a2d7f..d5c448a 100755 --- a/gdb.sh +++ b/gdb.sh @@ -1,2 +1,4 @@ #!/bin/bash -gdb-multiarch -ex 'target remote localhost:1234' -ex 'b abort' -ex 'c' ./elfloader3 +# T10884xxxxxxxxxxxxxxxxxxxxx +gdb-multiarch -ex 'target remote localhost:12309' -ex 'b abort' \ +-ex 'c' ./elfloader3 diff --git a/rootfs/ELKA/Cache/default/frdb.pd b/rootfs/ELKA/Cache/default/frdb.pd index 59e95fb..9a06335 100644 --- a/rootfs/ELKA/Cache/default/frdb.pd +++ b/rootfs/ELKA/Cache/default/frdb.pd @@ -1,3 +1,4 @@ -000042:T:ENTRY_0000000000.RESIDENTMIDLET=0 -000036:T:ENTRY_0000000000.READONLY=0 -000078:T:ENTRY_0000000000.FILENAME=0:\Applications\PhotoEditor\PhotoEditor.jar +000042:T:ENTRY_0000000000.RESIDENTMIDLET=0 +000036:T:ENTRY_0000000000.READONLY=0 +000061:T:ENTRY_0000000000.FILENAME=0:\Games\Sudoku\Sudoku.jar +000044:T:wallpaper=0:\Pictures\wallpaper.png diff --git a/rootfs/NSG/Cache/default/frdb.pd b/rootfs/NSG/Cache/default/frdb.pd index d3f5a12..9a06335 100644 --- a/rootfs/NSG/Cache/default/frdb.pd +++ b/rootfs/NSG/Cache/default/frdb.pd @@ -1 +1,4 @@ - +000042:T:ENTRY_0000000000.RESIDENTMIDLET=0 +000036:T:ENTRY_0000000000.READONLY=0 +000061:T:ENTRY_0000000000.FILENAME=0:\Games\Sudoku\Sudoku.jar +000044:T:wallpaper=0:\Pictures\wallpaper.png diff --git a/src/elfloader/loadlib.c b/src/elfloader/loadlib.c index 09a1235..0e93485 100644 --- a/src/elfloader/loadlib.c +++ b/src/elfloader/loadlib.c @@ -360,6 +360,7 @@ try_again: * Вычесть общее количество клиентов либ */ void loader_lib_unref_clients(Elf32_Lib *lib) { + printf("loader_lib_unref_clients(%s)=%d\n", lib->soname, lib->users_cnt-1); lib->users_cnt--; } diff --git a/src/main.cpp b/src/main.cpp index 659ddcf..904952e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -136,7 +136,7 @@ int main(int argc, char **argv) { GUI_Init(); loader_init_switab(); - loader_set_debug(false); + loader_set_debug(true); loader_gdb_init(); GBS_RunInContext(MMI_CEPID, [=]() { @@ -156,9 +156,11 @@ int main(int argc, char **argv) { fname = SieFs::path2sie(std::filesystem::canonical(elf_arg)); auto entry = (int (*)(const char *, const char *, const void *)) loader_elf_entry(ex); - printf("run entry at %p (exe=%s, fname=%s)\n", entry, exe_name.c_str(), fname.c_str()); + fprintf(stderr, "run entry at %p (exe=%s, fname=%s)\n", entry, exe_name.c_str(), fname.c_str()); int ret = entry(exe_name.c_str(), fname.c_str(), nullptr); LOGD("entry ret = %d\n", ret); + + // loader_elf_close(ex); }); LOGD("Running loop...\n"); diff --git a/src/swi.cpp b/src/swi.cpp index d3c2705..ad2ddaa 100644 --- a/src/swi.cpp +++ b/src/swi.cpp @@ -206,8 +206,7 @@ void loader_init_switab() { switab_functions[0x818A - 0x8000] = (void *) GUI_HeaderH(); switab_functions[0x818B - 0x8000] = (void *) GUI_SoftkeyH(); switab_functions[0x80E0 - 0x8000] = (void *) GUI_RamScreenBuffer(); - switab_functions[0x80F5 - 0x8000] = (void *) GUI_RamMainLCDLayer(); - switab_functions[0x80F6 - 0x8000] = (void *) GUI_RamMMILCDLayer(); + switab_functions[0x83D8 - 0x8000] = (void *) GUI_GetLCDLayerList(); // SettingsAE switab_functions[0x02E4] = (void *) SettingsAE_Update_ws; diff --git a/src/swi.h b/src/swi.h index 836f3f0..1eed876 100644 --- a/src/swi.h +++ b/src/swi.h @@ -143,9 +143,9 @@ int FS_close(int fd, uint32_t *errp); int FS_flush(int fd, uint32_t *errp); long FS_lseek(int fd, uint32_t offset, uint32_t origin, uint32_t *errp, uint32_t *errp2); int FS_mkdir(const char *pathname, uint32_t *errp); -int FS_GetFileAttrib(const char *cFileName, uint8_t *cAttribute, uint32_t *errp); -int FS_SetFileAttrib(const char *cFileName, uint8_t cAttribute, uint32_t *errp); -int FS_setfilesize(int FileHandler, uint32_t iNewFileSize, uint32_t *errp); +int FS_GetFileAttrib(const char *filename, uint8_t *attrs, uint32_t *errp); +int FS_SetFileAttrib(const char *filename, uint8_t attrs, uint32_t *errp); +int FS_setfilesize(int fd, uint32_t new_size, uint32_t *errp); int FS_FindFirstFile(DIR_ENTRY *de, const char *mask, uint32_t *errp); int FS_FindNextFile(DIR_ENTRY *de ,uint32_t *errp); int FS_FindClose(DIR_ENTRY *de, uint32_t *errp); @@ -310,7 +310,7 @@ void GBS_StopTimer(GBSTMR *tmr); int GBS_IsTimerProcessing(GBSTMR * param1); void GBS_RunInContext(int cepid, std::function callback); void GBS_CreateProc(int cepid, const char *name, GbsProcCallback on_msg, int prio, int unk_zero); -int GBS_GetCurCepid(void); +short GBS_GetCurCepid(void); void GBS_KillProc(int cepid); void GBS_PendMessage(GBS_MSG * param1); void GBS_SendMessage(int cepid_to, int msg, int submess, void *data0, void *data1); @@ -898,8 +898,7 @@ int GUI_ScreenH(); int GUI_HeaderH(); int GUI_SoftkeyH(); -LCDLAYER *GUI_RamMainLCDLayer(); -LCDLAYER **GUI_RamMMILCDLayer(); +LCDLAYER **GUI_GetLCDLayerList(); void GUI_SetDepthBuffer(uint8_t depth); void GUI_SetDepthBufferOnLCDLAYER(LCDLAYER *layer, uint8_t depth); diff --git a/src/swi/csm.cpp b/src/swi/csm.cpp index 3c7b884..3dcd421 100644 --- a/src/swi/csm.cpp +++ b/src/swi/csm.cpp @@ -103,5 +103,11 @@ CSM_RAM *CSM_Current() { } void CloseCSM(int id) { - fprintf(stderr, "%s not implemented!\n", __func__); + if (FindCSMbyID(id)) { + fprintf(stderr, "%s !!!!!\n", __func__); + FindCSMbyID(id)->state = CSM_STATE_CLOSED; + CSM_GarbageCollector(); + } else { + fprintf(stderr, "%s not implemented!\n", __func__); + } } diff --git a/src/swi/fs.cpp b/src/swi/fs.cpp index 456e1cb..33f95e9 100644 --- a/src/swi/fs.cpp +++ b/src/swi/fs.cpp @@ -63,55 +63,36 @@ int FS_open(const char *path, uint32_t f, uint32_t m, uint32_t *errp) { ret = open(SieFs::sie2path(path).c_str(), flags, mode); } - if (SWI_TRACE) { - fprintf(stderr, "[strace] open(%s, %d, %d) = %d\n", SieFs::sie2path(path).c_str(), flags, mode, ret); - } - _set_errno(ret, errp); return ret; } int FS_read(int fd, void *buff, int count, uint32_t *errp) { int ret = read(fd, buff, count); - if (SWI_TRACE) { - fprintf(stderr, "[strace] read(%d, %p, %d) = %d\n", fd, buff, count, ret); - } _set_errno(ret, errp); return ret; } int FS_write(int fd, const void *buff, int count, uint32_t *errp) { int ret = write(fd, buff, count); - if (SWI_TRACE) { - fprintf(stderr, "[strace] write(%d, %p, %d) = %d\n", fd, buff, count, ret); - } _set_errno(ret, errp); return ret; } int FS_close(int fd, uint32_t *errp) { int ret = close(fd); - if (SWI_TRACE) { - fprintf(stderr, "[strace] close(%d) = %d\n", fd, ret); - } _set_errno(ret, errp); return ret; } int FS_flush(int fd, uint32_t *errp) { int ret = fsync(fd); - if (SWI_TRACE) { - fprintf(stderr, "[strace] fsync(%d) = %d\n", fd, ret); - } _set_errno(ret, errp); return ret; } long FS_lseek(int fd, uint32_t offset, uint32_t origin, uint32_t *errp, uint32_t *errp2) { int ret = lseek(fd, offset, origin); - if (SWI_TRACE) { - fprintf(stderr, "[strace] lseek(%d, %d, %d) = %d\n", fd, offset, origin, ret); - } _set_errno(ret, errp); _set_errno(ret, errp2); return ret; @@ -119,29 +100,26 @@ long FS_lseek(int fd, uint32_t offset, uint32_t origin, uint32_t *errp, uint32_t int FS_mkdir(const char *pathname, uint32_t *errp) { int ret = mkdir(SieFs::sie2path(pathname).c_str(), 0755); - if (SWI_TRACE) { - fprintf(stderr, "[strace] mkdir(%s) = %d\n", SieFs::sie2path(pathname).c_str(), ret); - } _set_errno(ret, errp); return ret; } -int FS_GetFileAttrib(const char *cFileName, uint8_t *cAttribute, uint32_t *ErrorNumber) { +int FS_GetFileAttrib(const char *filename, uint8_t *attrs, uint32_t *errp) { fprintf(stderr, "%s not implemented!\n", __func__); abort(); return 0; } -int FS_SetFileAttrib(const char *cFileName, uint8_t cAttribute, uint32_t *ErrorNumber) { +int FS_SetFileAttrib(const char *filename, uint8_t attrs, uint32_t *errp) { fprintf(stderr, "%s not implemented!\n", __func__); abort(); return 0; } -int FS_setfilesize(int FileHandler, uint32_t iNewFileSize, uint32_t *ErrorNumber) { - fprintf(stderr, "%s not implemented!\n", __func__); - abort(); - return 0; +int FS_setfilesize(int fd, uint32_t new_size, uint32_t *errp) { + int ret = ftruncate(fd, new_size); + _set_errno(ret, errp); + return ret; } static void _fillDirEntry(DIR_ENTRY *de, const std::string &file) { @@ -241,27 +219,18 @@ int FS_fmove(const char *src, const char *dst, uint32_t *errp) { std::string src_path = SieFs::sie2path(src); std::string dst_path = SieFs::sie2path(dst); int ret = rename(src_path.c_str(), dst_path.c_str()); - if (SWI_TRACE) { - fprintf(stderr, "[strace] fmove(%s, %s) = %d\n", src_path.c_str(), dst_path.c_str(), ret); - } _set_errno(ret, errp); return ret; } int FS_rmdir(const char *path, uint32_t *errp) { int ret = rmdir(SieFs::sie2path(path).c_str()); - if (SWI_TRACE) { - fprintf(stderr, "[strace] rmdir(%s) = %d\n", SieFs::sie2path(path).c_str(), ret); - } _set_errno(ret, errp); return ret; } int FS_unlink(const char *path, uint32_t *errp) { int ret = unlink(SieFs::sie2path(path).c_str()); - if (SWI_TRACE) { - fprintf(stderr, "[strace] unlink(%s) = %d\n", SieFs::sie2path(path).c_str(), ret); - } _set_errno(ret, errp); return ret; } @@ -276,9 +245,7 @@ int FS_isdir(const char *path, uint32_t *errp) { std::string file = SieFs::sie2path(path); struct stat st; int ret = lstat(file.c_str(), &st); - if (SWI_TRACE) { - fprintf(stderr, "[strace] stat(%s) = %d\n", SieFs::sie2path(path).c_str(), ret); - } + if (ret == 0) { return ((st.st_mode & S_IFMT) == S_IFDIR); } else { @@ -291,9 +258,7 @@ int FS_GetFileStats(const char *siemens_file, FSTATS *out_st, uint32_t *errp) { std::string file = SieFs::sie2path(siemens_file); struct stat st; int ret = lstat(file.c_str(), &st); - if (SWI_TRACE) { - fprintf(stderr, "[strace] stat(%s) = %d\n", file.c_str(), ret); - } + if (ret == 0) { if (errp) *errp = 0; diff --git a/src/swi/gbs.cpp b/src/swi/gbs.cpp index 4075452..04a8304 100644 --- a/src/swi/gbs.cpp +++ b/src/swi/gbs.cpp @@ -116,7 +116,7 @@ void GBS_CreateProc(int cepid, const char *name, GbsProcCallback msg_handler, in thread2cepid[gbs_processes[cepid]->threadId()] = cepid; } -int GBS_GetCurCepid(void) { +short GBS_GetCurCepid(void) { auto tid = std::this_thread::get_id(); if (thread2cepid.find(tid) != thread2cepid.end()) return thread2cepid[tid]; diff --git a/src/swi/gui.cpp b/src/swi/gui.cpp index aafdb08..af7dac2 100644 --- a/src/swi/gui.cpp +++ b/src/swi/gui.cpp @@ -15,7 +15,9 @@ // Currently we have only one layer static LCDLAYER mmi_layer = {}; -static LCDLAYER *mmi_layer_ptr = &mmi_layer; +static LCDLAYER *mmi_layers[10] = { + &mmi_layer, nullptr +}; static std::queue gui_to_destroy; static std::map id2gui = {}; @@ -127,8 +129,11 @@ int GUI_CreateWithDummyCSM_30or2(GUI *gui, int flag) { // WTF void GUI_HandleKeyPress(GBS_MSG *msg) { int top_id = GUI_GetTopID(); - if (top_id < 0) + if (top_id < 0 && msg->submess == 60) { + LOGD("msg %d\n", msg->submess); + CloseCSM(0); return; + } GUI_RAM *gui_ram = GUI_GetById(top_id); @@ -138,7 +143,7 @@ void GUI_HandleKeyPress(GBS_MSG *msg) { if (gui_ram->gui->state == CSM_GUI_STATE_FOCUSED) { LOGD("[GUI:%d] onKey\n", gui_ram->id); int ret = gui_ram->gui->methods->onKey(gui_ram->gui, &gui_msg); - if (ret) { + if (ret||1) { LOGD("[GUI:%d] onKey ret=%d (gui close)\n", gui_ram->id, ret); int id = gui_ram->id; GBS_RunInContext(MMI_CEPID, [id]() { @@ -293,13 +298,8 @@ void GUI_REDRAW() { GUI_DirectRedrawGUI(); } -LCDLAYER *GUI_RamMainLCDLayer() { - // Not implemented - return nullptr; -} - -LCDLAYER **GUI_RamMMILCDLayer() { - return &mmi_layer_ptr; +LCDLAYER **GUI_GetLCDLayerList() { + return mmi_layers; } void GUI_SetDepthBuffer(uint8_t depth) { diff --git a/src/swi/gui/TextRender.cpp b/src/swi/gui/TextRender.cpp index 26f20a2..a880dd5 100644 --- a/src/swi/gui/TextRender.cpp +++ b/src/swi/gui/TextRender.cpp @@ -217,7 +217,6 @@ std::pair TextRender::measureString(int font_id, uint16_t *str, int le line_width += img->w; if (line_height < img->h) line_height = img->h; - i++; } return { line_width, line_height };