mirror of
https://github.com/fail0verflow/mini.git
synced 2024-11-24 12:19:21 +01:00
USBGecko code cleanup, exposing only gecko_printf() with the ability to turn off debug spew via an IPC call.
This commit is contained in:
parent
7a26537f8a
commit
90f794db6c
80
gecko.c
80
gecko.c
@ -4,6 +4,9 @@
|
||||
#include "string.h"
|
||||
#include "utils.h"
|
||||
#include "hollywood.h"
|
||||
#include "gecko.h"
|
||||
|
||||
static u8 gecko_console_enabled = 0;
|
||||
|
||||
// These two don't really seem to be needed
|
||||
// Maybe only for boot buffer or some PPC stuff
|
||||
@ -40,6 +43,7 @@ static u32 _gecko_sendbyte(char sendbyte)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static u32 _gecko_recvbyte(char *recvbyte)
|
||||
{
|
||||
u32 i = 0;
|
||||
@ -70,24 +74,9 @@ static u32 _gecko_checkrecv(void)
|
||||
return 1; // Return 1 if safe to recv
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void gecko_init(void)
|
||||
{
|
||||
write32(EXI0_CSR, 0);
|
||||
write32(EXI1_CSR, 0);
|
||||
write32(EXI2_CSR, 0);
|
||||
write32(EXI0_CSR, 0x2000);
|
||||
write32(EXI0_CSR, 3<<10);
|
||||
write32(EXI1_CSR, 3<<10);
|
||||
}
|
||||
|
||||
void gecko_flush(void)
|
||||
{
|
||||
char tmp;
|
||||
while(_gecko_recvbyte(&tmp));
|
||||
}
|
||||
|
||||
int gecko_isalive(void)
|
||||
static int gecko_isalive(void)
|
||||
{
|
||||
u32 i = 0;
|
||||
i = _gecko_command(0x90000000);
|
||||
@ -96,7 +85,14 @@ int gecko_isalive(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gecko_recvbuffer(void *buffer, u32 size)
|
||||
#if 0
|
||||
static void gecko_flush(void)
|
||||
{
|
||||
char tmp;
|
||||
while(_gecko_recvbyte(&tmp));
|
||||
}
|
||||
|
||||
static int gecko_recvbuffer(void *buffer, u32 size)
|
||||
{
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
@ -111,8 +107,9 @@ int gecko_recvbuffer(void *buffer, u32 size)
|
||||
_gecko_release();
|
||||
return (size - left);
|
||||
}
|
||||
#endif
|
||||
|
||||
int gecko_sendbuffer(const void *buffer, u32 size)
|
||||
static int gecko_sendbuffer(const void *buffer, u32 size)
|
||||
{
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
@ -128,7 +125,8 @@ int gecko_sendbuffer(const void *buffer, u32 size)
|
||||
return (size - left);
|
||||
}
|
||||
|
||||
int gecko_recvbuffer_safe(void *buffer, u32 size)
|
||||
#if 0
|
||||
static int gecko_recvbuffer_safe(void *buffer, u32 size)
|
||||
{
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
@ -146,7 +144,7 @@ int gecko_recvbuffer_safe(void *buffer, u32 size)
|
||||
return (size - left);
|
||||
}
|
||||
|
||||
int gecko_sendbuffer_safe(const void *buffer, u32 size)
|
||||
static int gecko_sendbuffer_safe(const void *buffer, u32 size)
|
||||
{
|
||||
u32 left = size;
|
||||
char *ptr = (char*)buffer;
|
||||
@ -166,29 +164,39 @@ int gecko_sendbuffer_safe(const void *buffer, u32 size)
|
||||
_gecko_release();
|
||||
return (size - left);
|
||||
}
|
||||
#endif
|
||||
|
||||
int gecko_putchar(int ic)
|
||||
void gecko_init(void)
|
||||
{
|
||||
char b = ic;
|
||||
return gecko_sendbuffer(&b, 1);
|
||||
write32(EXI0_CSR, 0);
|
||||
write32(EXI1_CSR, 0);
|
||||
write32(EXI2_CSR, 0);
|
||||
write32(EXI0_CSR, 0x2000);
|
||||
write32(EXI0_CSR, 3<<10);
|
||||
write32(EXI1_CSR, 3<<10);
|
||||
|
||||
if (!gecko_isalive())
|
||||
return;
|
||||
|
||||
gecko_console_enabled = 1;
|
||||
}
|
||||
|
||||
int gecko_getchar(void)
|
||||
u8 gecko_enable_console(const u8 enable)
|
||||
{
|
||||
char b;
|
||||
if(gecko_recvbuffer_safe(&b, 1) != 1)
|
||||
return -1;
|
||||
return b;
|
||||
}
|
||||
if (enable) {
|
||||
if (gecko_isalive())
|
||||
gecko_console_enabled = 1;
|
||||
} else
|
||||
gecko_console_enabled = 0;
|
||||
|
||||
int gecko_puts(const char *s)
|
||||
{
|
||||
//udelay(10000);
|
||||
return gecko_sendbuffer(s, strlen(s));
|
||||
return gecko_console_enabled;
|
||||
}
|
||||
|
||||
int gecko_printf(const char *fmt, ...)
|
||||
{
|
||||
if (!gecko_console_enabled)
|
||||
return 0;
|
||||
|
||||
va_list args;
|
||||
char buffer[256];
|
||||
int i;
|
||||
@ -196,6 +204,6 @@ int gecko_printf( const char *fmt, ...)
|
||||
va_start(args, fmt);
|
||||
i = vsprintf(buffer, fmt, args);
|
||||
va_end(args);
|
||||
gecko_puts(buffer);
|
||||
return i;
|
||||
|
||||
return gecko_sendbuffer(buffer, i);
|
||||
}
|
||||
|
12
gecko.h
12
gecko.h
@ -3,16 +3,8 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void gecko_flush(void);
|
||||
int gecko_isalive(void);
|
||||
int gecko_recvbuffer(void *buffer, u32 size);
|
||||
int gecko_sendbuffer(const void *buffer, u32 size);
|
||||
int gecko_recvbuffer_safe(void *buffer, u32 size);
|
||||
int gecko_sendbuffer_safe(const void *buffer, u32 size);
|
||||
int gecko_putchar(int c);
|
||||
int gecko_getchar(void);
|
||||
int gecko_puts(const char *s);
|
||||
int gecko_printf( const char *fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
void gecko_init(void);
|
||||
u8 gecko_enable_console(const u8 enable);
|
||||
int gecko_printf(const char *fmt, ...) __attribute__((format (printf, 1, 2)));
|
||||
|
||||
#endif
|
||||
|
4
ipc.c
4
ipc.c
@ -161,6 +161,10 @@ static void process_in(void)
|
||||
case IPC_SYS_PING:
|
||||
ipc_post(req->code, req->tag, 0);
|
||||
break;
|
||||
case IPC_SYS_DBGMSG:
|
||||
ipc_post(req->code, req->tag, 1,
|
||||
gecko_enable_console(req->args[0]));
|
||||
break;
|
||||
case IPC_SYS_WRITE32:
|
||||
write32(req->args[0], req->args[1]);
|
||||
break;
|
||||
|
1
ipc.h
1
ipc.h
@ -15,6 +15,7 @@
|
||||
|
||||
#define IPC_SYS_PING 0x0000
|
||||
#define IPC_SYS_JUMP 0x0001
|
||||
#define IPC_SYS_DBGMSG 0x0002
|
||||
#define IPC_SYS_WRITE32 0x0100
|
||||
#define IPC_SYS_WRITE16 0x0101
|
||||
#define IPC_SYS_WRITE8 0x0102
|
||||
|
40
main.c
40
main.c
@ -104,7 +104,7 @@ static void patch_mem(u8 *offset, u32 size, u64 titleID)
|
||||
}
|
||||
|
||||
void boot2_patchelf(u8 *elf, u64 titleID) {
|
||||
gecko_puts("Patching boot2 ELF...\n");
|
||||
gecko_printf("Patching boot2 ELF...\n");
|
||||
|
||||
if(memcmp("\x7F" "ELF\x01\x02\x01\x61\x01",elf,9)) {
|
||||
gecko_printf("Invalid ELF header! 0x%02x 0x%02x 0x%02x 0x%02x\n",elf[0], elf[1], elf[2], elf[3]);
|
||||
@ -133,7 +133,7 @@ void boot2_patchelf(u8 *elf, u64 titleID) {
|
||||
}
|
||||
phdr++;
|
||||
}
|
||||
gecko_puts("Done!\n");
|
||||
gecko_printf("Done!\n");
|
||||
}
|
||||
|
||||
#define PPC_BOOT_FILE "/system/ppcboot.elf"
|
||||
@ -147,7 +147,7 @@ void *patch_boot2(void *base, u64 titleID)
|
||||
ioshdr *parhdr = (ioshdr*)hdr->argument;
|
||||
u8 *elf;
|
||||
|
||||
gecko_puts("Patching BOOT2 for leet hax\n");
|
||||
gecko_printf("Patching BOOT2 for leet hax\n");
|
||||
gecko_printf("Parent BOOT2 header (@%p):\n",parhdr);
|
||||
gecko_printf(" Header size: %08x\n", parhdr->hdrsize);
|
||||
gecko_printf(" Loader size: %08x\n", parhdr->loadersize);
|
||||
@ -173,11 +173,11 @@ void *_main(void *base)
|
||||
int res;
|
||||
|
||||
gecko_init();
|
||||
gecko_puts("mini v0.2 loading\n");
|
||||
gecko_printf("mini v0.2 loading\n");
|
||||
|
||||
gecko_puts("Initializing exceptions...\n");
|
||||
gecko_printf("Initializing exceptions...\n");
|
||||
exception_initialize();
|
||||
gecko_puts("Configuring caches and MMU...\n");
|
||||
gecko_printf("Configuring caches and MMU...\n");
|
||||
mem_initialize();
|
||||
|
||||
gecko_printf("IOSflags: %08x %08x %08x\n",
|
||||
@ -190,27 +190,27 @@ void *_main(void *base)
|
||||
irq_enable(IRQ_GPIO1B);
|
||||
irq_enable(IRQ_GPIO1);
|
||||
irq_enable(IRQ_RESET);
|
||||
gecko_puts("Interrupts initialized\n");
|
||||
gecko_printf("Interrupts initialized\n");
|
||||
|
||||
crypto_initialize();
|
||||
gecko_puts("crypto support initialized\n");
|
||||
gecko_printf("crypto support initialized\n");
|
||||
|
||||
nand_initialize();
|
||||
gecko_puts("NAND initialized.\n");
|
||||
gecko_printf("NAND initialized.\n");
|
||||
|
||||
boot2_init();
|
||||
|
||||
gecko_puts("Initializing IPC...\n");
|
||||
gecko_printf("Initializing IPC...\n");
|
||||
ipc_initialize();
|
||||
|
||||
gecko_puts("Initializing SD...\n");
|
||||
gecko_printf("Initializing SD...\n");
|
||||
sd_initialize();
|
||||
|
||||
gecko_puts("Mounting SD...\n");
|
||||
gecko_printf("Mounting SD...\n");
|
||||
fres = f_mount(0, &fatfs);
|
||||
|
||||
if (read32(0x0d800190) & 2) {
|
||||
gecko_puts("GameCube compatibility mode detected...\n");
|
||||
gecko_printf("GameCube compatibility mode detected...\n");
|
||||
boot2_run(1, 0x101);
|
||||
goto shutdown;
|
||||
}
|
||||
@ -220,24 +220,24 @@ void *_main(void *base)
|
||||
panic2(0, PANIC_MOUNT);
|
||||
}
|
||||
|
||||
gecko_puts("Trying to boot:" PPC_BOOT_FILE "\n");
|
||||
gecko_printf("Trying to boot:" PPC_BOOT_FILE "\n");
|
||||
|
||||
res = powerpc_load_file(PPC_BOOT_FILE);
|
||||
if(res < 0) {
|
||||
gecko_printf("Failed to boot PPC: %d\n", res);
|
||||
gecko_puts("Continuing anyway\n");
|
||||
gecko_printf("Continuing anyway\n");
|
||||
}
|
||||
|
||||
gecko_puts("Going into IPC mainloop...\n");
|
||||
gecko_printf("Going into IPC mainloop...\n");
|
||||
ipc_process_slow();
|
||||
gecko_puts("IPC mainloop done!\n");
|
||||
gecko_puts("Shutting down IPC...\n");
|
||||
gecko_printf("IPC mainloop done!\n");
|
||||
gecko_printf("Shutting down IPC...\n");
|
||||
ipc_shutdown();
|
||||
|
||||
shutdown:
|
||||
gecko_puts("Shutting down interrupts...\n");
|
||||
gecko_printf("Shutting down interrupts...\n");
|
||||
irq_shutdown();
|
||||
gecko_puts("Shutting down caches and MMU...\n");
|
||||
gecko_printf("Shutting down caches and MMU...\n");
|
||||
mem_shutdown();
|
||||
|
||||
gecko_printf("Vectoring to %p...\n",vector);
|
||||
|
@ -38,7 +38,7 @@ int powerpc_load_file(const char *path)
|
||||
}
|
||||
|
||||
if(elfhdr.e_phoff == 0 || elfhdr.e_phnum == 0) {
|
||||
gecko_puts("ELF has no program headers!\n");
|
||||
gecko_printf("ELF has no program headers!\n");
|
||||
return -102;
|
||||
}
|
||||
if(elfhdr.e_phnum > PHDR_MAX) {
|
||||
@ -84,10 +84,10 @@ int powerpc_load_file(const char *path)
|
||||
|
||||
dc_flushall();
|
||||
|
||||
gecko_puts("ELF load done, booting PPC...\n");
|
||||
gecko_printf("ELF load done, booting PPC...\n");
|
||||
powerpc_upload_stub(NULL,0);
|
||||
powerpc_reset();
|
||||
gecko_puts("PPC booted!\n");
|
||||
gecko_printf("PPC booted!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user