From ffa403689382378eb178c564343f1d6c4efbaf5a Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Tue, 31 May 2016 08:25:24 -0400 Subject: [PATCH] Just docs, basically. --- doc/bytecode.md | 23 +++++++++++++++++++++++ doc/todo.md | 36 ++++++++++++++++++------------------ source/patch/aadowngrade.c | 28 ++++++++++++++++++++++++++++ source/patch/base.c | 13 +++++++++++++ source/patch/prot.c | 36 ++++++++++++++++++++++++++++++++++++ 5 files changed, 118 insertions(+), 18 deletions(-) create mode 100644 doc/bytecode.md diff --git a/doc/bytecode.md b/doc/bytecode.md new file mode 100644 index 0000000..6c9f6f3 --- /dev/null +++ b/doc/bytecode.md @@ -0,0 +1,23 @@ +Bytecode format +=================== + +All instructions are dwords (four bytes) - this is for optimization reasons. + +Registers +------------------- +r1-r4 - General +pc - Current offset in bytecode +mem - Memory offset set. + +Instruction List +------------------- +1) call index +2) add reg, reg +3) sub reg, reg +4) mul reg, reg +5) div reg, reg +6) mov reg/ref/imm, reg/ref/imm +7) push reg +8) pop +9) .byte byte + diff --git a/doc/todo.md b/doc/todo.md index 2c13d3f..2655d5b 100644 --- a/doc/todo.md +++ b/doc/todo.md @@ -1,32 +1,32 @@ Next ------------- - * Make config file for corbenik plaintext. Nobody likes binary configs. They suck. + * Make config file for corbenik plaintext. Nobody likes binary configs. They suck. Massively. Especially when you fuck up a setting and need to change it on something that isn't a 3ds. Shortterm ------------- - * Implement some kind of curses-like backend and replace terrible printf rewind on top screen. - * Alternatively, implement a monochrome GUI. - * We also need UTF8 support. I want translation support. - * Dragging in freetype or a bitmap font tool. - * Ugh, VWF. Not like I haven't done it before... - * Kconfig? + * Implement some kind of GUI menu functionality. + * We also probably need UTF8 support. I want translations. + * Dragging in freetype or a bitmap font tool is likely needed. + * Also, VWF. Not like I haven't done it before...but ugh. It's still a pain. + * Kconfig-based menus? + * The logic can't be easily ported from linux, and would need to be reimplemented. + + * Implement program loading as...something else. The current linker is broken. There's multiple ways to go about this: + * Figure out why it breaks. Fix it up. (Deemed impossible without static linking, which defeats the point.) + * Scripting language / VM maybe? + * Lua is the obvious choice, but there's a few negatives to this. + * It isn't terribly hard to write an assembler and bytecode VM. Maybe I'll do that. + * Has the advantages of code plus ARM9/ARM11 independence. Longterm ------------- + * Optimize the buffer logic out of printf. Render directly to the FB and keep track of dirty areas instead. * Attempt to create a replacement handler for Service 0x3D, AKA OutputDebugString(void const, int) to log to a file on SD. * Might be a pipe dream. It still would be cool to capture debug logs from games. * Pretty sure this goes over JTAG on PARTNER units and anything else >/dev/null. - * Config fragments for modules; and these need to be part of the modules, not corbenik's options menu. - * Oppa Kconfig style. - * Busybox may be helpful. - * Probably need to reimplement anyways due to lack of userland. - * Implement program loading as...something else. The current linker is broken. There's multiple ways to go about this: - * Figure out why it breaks, and fix it up. - * Embed a function table in corbenik itself, and rip this table out and generate a header post-compile which can be used by modules. - * Allow modules to be internal AND external, and to build either way. Think of the whole kmod-versus-builtin deal. - * All in all, this simplifies testing and allows multiple release types. + * Maybe replace svc 0xFF with something fancy. * Rewrite all hardcoded constants that are machine code as assembly. - * Read: all the patches - * Change some stdlib functions to more closely imitate their real userland counterparts + * Read: all the patches. + * Change some stdlib functions to more closely imitate their userland counterparts diff --git a/source/patch/aadowngrade.c b/source/patch/aadowngrade.c index 631682b..23622fd 100644 --- a/source/patch/aadowngrade.c +++ b/source/patch/aadowngrade.c @@ -2,6 +2,34 @@ // Do you like examples? +/* In bytecode assembly: + + aadowngrade: + rel firm_mem + mov4 r1, pattern + mov4 r2, 6 + call memfind + jmpz notfound + + found: + add r1, 5 + mov1 [r1], 0xE0 + mov4 r1, 0 + return + + notfound: + mov4 r1, 1 + return + + pattern: + .byte 0x89 + .byte 0x0A + .byte 0x81 + .byte 0x42 + .byte 0x02 + .byte 0xD2 + */ + PATCH(aadowngrade) { exefs_h* firm_p9_exefs = get_firm_proc9_exefs(); diff --git a/source/patch/base.c b/source/patch/base.c index 847740a..d5675b2 100644 --- a/source/patch/base.c +++ b/source/patch/base.c @@ -2,6 +2,19 @@ // Do you like examples? +/* Bytecode assembly: + + example: + mov r1, 2 + mov r2, string + call fprintf + mov r1, 0 + return + + string: + .str "Testing, testing, 1, 2, 3...\n" + */ + PATCH(example) { fprintf(stderr, "Testing, testing, 1, 2, 3, 4..\n"); diff --git a/source/patch/prot.c b/source/patch/prot.c index 869bb5e..ef2ddc2 100644 --- a/source/patch/prot.c +++ b/source/patch/prot.c @@ -2,6 +2,42 @@ // This patch applies the FIRM protection code needed for safe a9lh usage. +/* Bytecode assembly: + + firmprot: + rel firm_mem + mov r1, exe_str + mov r2, 4 + call memfind + jmpz nostr + + mov r3, r1 + mov r1, 2 + mov r2, str_atoff + call fprintf + + + + nostr: + mov r1, 2 + mov r2, noexe_str_str + call fprintf + mov r1, 0 + return + + exe_str: + .str "exe:" + noexe_str_str: + .str "Couldn't find 'exe' string.\n" + str_atoff: + .str "Firmprot: 'exe:' string @ %x\n" + firmprot_code: + .byte 0x00 + .byte 0x28 + .byte 0x01 + .byte 0xDA + */ + PATCH(firmprot) { exefs_h* firm_p9_exefs = get_firm_proc9_exefs(); -- 2.39.5