diff --git a/include/hardware/pxi.h b/include/hardware/pxi.h index 5bc2df0..73b0568 100644 --- a/include/hardware/pxi.h +++ b/include/hardware/pxi.h @@ -58,38 +58,16 @@ #define PXI_ENABLE_SEND_RECV_FIFO (1u<<15) -typedef enum -{ - PXI_CMD9_FMOUNT = 0, - PXI_CMD9_FUNMOUNT = 1, - PXI_CMD9_FOPEN = 2, - PXI_CMD9_FCLOSE = 3, - PXI_CMD9_FREAD = 4, - PXI_CMD9_FWRITE = 5, - PXI_CMD9_FOPEN_DIR = 6, - PXI_CMD9_FREAD_DIR = 7, - PXI_CMD9_FCLOSE_DIR = 8, - PXI_CMD9_FUNLINK = 9, - PXI_CMD9_FGETFREE = 10, - PXI_CMD9_READ_SECTORS = 11, - PXI_CMD9_WRITE_SECTORS = 12, - PXI_CMD9_MALLOC = 13, - PXI_CMD9_FREE = 14, - PXI_CMD9_LOAD_VERIFY_FIRM = 15, - PXI_CMD9_FIRM_LAUNCH = 16, - PXI_CMD9_PREPA_POWER = 17, - PXI_CMD9_PANIC = 18, - PXI_CMD9_EXCEPTION = 19 -} PxiCmd9; - -typedef enum -{ - PXI_CMD11_PRINT_MSG = 0, - PXI_CMD11_PANIC = 1, - PXI_CMD11_EXCEPTION = 2 -} PxiCmd11; - - void PXI_init(void); u32 PXI_sendCmd(u32 cmd, const u32 *const buf, u8 words); + +static inline u32 PXI_recvWord(void) +{ +#ifdef ARM9 + return REG_PXI_RECV9; +#endif +#ifdef ARM11 + return REG_PXI_RECV11; +#endif +} diff --git a/include/ipc_handler.h b/include/ipc_handler.h new file mode 100644 index 0000000..c20071a --- /dev/null +++ b/include/ipc_handler.h @@ -0,0 +1,57 @@ +#pragma once + +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "types.h" + + +typedef enum +{ + IPC_CMD9_FMOUNT = 0, + IPC_CMD9_FUNMOUNT = 1, + IPC_CMD9_FOPEN = 2, + IPC_CMD9_FCLOSE = 3, + IPC_CMD9_FREAD = 4, + IPC_CMD9_FWRITE = 5, + IPC_CMD9_FOPEN_DIR = 6, + IPC_CMD9_FREAD_DIR = 7, + IPC_CMD9_FCLOSE_DIR = 8, + IPC_CMD9_FUNLINK = 9, + IPC_CMD9_FGETFREE = 10, + IPC_CMD9_READ_SECTORS = 11, + IPC_CMD9_WRITE_SECTORS = 12, + IPC_CMD9_MALLOC = 13, + IPC_CMD9_FREE = 14, + IPC_CMD9_LOAD_VERIFY_FIRM = 15, + IPC_CMD9_FIRM_LAUNCH = 16, + IPC_CMD9_PREPA_POWER = 17, + IPC_CMD9_PANIC = 18, + IPC_CMD9_EXCEPTION = 19 +} IpcCmd9; + +typedef enum +{ + IPC_CMD11_PRINT_MSG = 0, + IPC_CMD11_PANIC = 1, + IPC_CMD11_EXCEPTION = 2 +} IpcCmd11; + + + +u32 IPC_handleCmd(u8 cmd, UNUSED u8 params); diff --git a/source/arm11/hardware/pxi.c b/source/arm11/hardware/pxi.c index c7a6ba4..ceb0a13 100644 --- a/source/arm11/hardware/pxi.c +++ b/source/arm11/hardware/pxi.c @@ -20,6 +20,7 @@ #include "hardware/pxi.h" #include "arm11/hardware/interrupt.h" //#include "arm11/debug.h" +#include "ipc_handler.h" @@ -38,27 +39,15 @@ static void pxiIrqHandler(UNUSED u32 intSource) { - u32 result = 0; const u32 cmdCode = REG_PXI_RECV11; + const u8 params = cmdCode>>16 & 0xFFu; - if((cmdCode>>16 & 0xFFu) != PXI_DATA_RECEIVED(REG_PXI_SYNC11)) + if(params != PXI_DATA_RECEIVED(REG_PXI_SYNC11)) { //panic(); } - switch(cmdCode>>24) - { - case PXI_CMD11_PRINT_MSG: - break; - case PXI_CMD11_PANIC: - break; - case PXI_CMD11_EXCEPTION: - break; - default: ; - //panic(); - } - - REG_PXI_SEND11 = result; + REG_PXI_SEND11 = IPC_handleCmd(cmdCode>>24, params); } u32 PXI_sendCmd(u32 cmd, const u32 *const buf, u8 words) diff --git a/source/arm11/ipc_handler.c b/source/arm11/ipc_handler.c new file mode 100644 index 0000000..e914144 --- /dev/null +++ b/source/arm11/ipc_handler.c @@ -0,0 +1,43 @@ +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "types.h" +#include "ipc_handler.h" +#include "hardware/pxi.h" +//#include "arm11/debug.h" + + + +u32 IPC_handleCmd(u8 cmd, UNUSED u8 params) +{ + u32 result = 0; + + switch(cmd) + { + case IPC_CMD11_PRINT_MSG: + break; + case IPC_CMD11_PANIC: + break; + case IPC_CMD11_EXCEPTION: + break; + default: ; + //panic(); + } + + return result; +} diff --git a/source/arm9/hardware/pxi.c b/source/arm9/hardware/pxi.c index 1ceaf03..016ae46 100644 --- a/source/arm9/hardware/pxi.c +++ b/source/arm9/hardware/pxi.c @@ -20,6 +20,7 @@ #include "hardware/pxi.h" #include "arm9/hardware/interrupt.h" #include "arm9/debug.h" +#include "ipc_handler.h" @@ -38,61 +39,15 @@ static void pxiIrqHandler(UNUSED u32 id) { - u32 result = 0; const u32 cmdCode = REG_PXI_RECV9; + const u8 params = cmdCode>>16 & 0xFFu; - if((cmdCode>>16 & 0xFFu) != PXI_DATA_RECEIVED(REG_PXI_SYNC9)) + if(params != PXI_DATA_RECEIVED(REG_PXI_SYNC9)) { panic(); } - switch(cmdCode>>24) - { - case PXI_CMD9_FMOUNT: - break; - case PXI_CMD9_FUNMOUNT: - break; - case PXI_CMD9_FOPEN: - break; - case PXI_CMD9_FCLOSE: - break; - case PXI_CMD9_FREAD: - break; - case PXI_CMD9_FWRITE: - break; - case PXI_CMD9_FOPEN_DIR: - break; - case PXI_CMD9_FREAD_DIR: - break; - case PXI_CMD9_FCLOSE_DIR: - break; - case PXI_CMD9_FUNLINK: - break; - case PXI_CMD9_FGETFREE: - break; - case PXI_CMD9_READ_SECTORS: - break; - case PXI_CMD9_WRITE_SECTORS: - break; - case PXI_CMD9_MALLOC: - break; - case PXI_CMD9_FREE: - break; - case PXI_CMD9_LOAD_VERIFY_FIRM: - break; - case PXI_CMD9_FIRM_LAUNCH: - break; - case PXI_CMD9_PREPA_POWER: - break; - case PXI_CMD9_PANIC: - break; - case PXI_CMD9_EXCEPTION: - break; - default: - panic(); - } - - REG_PXI_SEND9 = result; + REG_PXI_SEND9 = IPC_handleCmd(cmdCode>>24, params); } u32 PXI_sendCmd(u32 cmd, const u32 *const buf, u8 words) diff --git a/source/arm9/ipc_handler.c b/source/arm9/ipc_handler.c new file mode 100644 index 0000000..e98c215 --- /dev/null +++ b/source/arm9/ipc_handler.c @@ -0,0 +1,82 @@ +/* + * This file is part of fastboot 3DS + * Copyright (C) 2017 derrek, profi200 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "types.h" +#include "ipc_handler.h" +#include "hardware/pxi.h" +#include "arm9/debug.h" +#include "fatfs/ff.h" + + + +u32 IPC_handleCmd(u8 cmd, u8 params) +{ + u32 result = 0; + + switch(cmd) + { + case IPC_CMD9_FMOUNT: + break; + case IPC_CMD9_FUNMOUNT: + break; + case IPC_CMD9_FOPEN: + break; + case IPC_CMD9_FCLOSE: + break; + case IPC_CMD9_FREAD: + break; + case IPC_CMD9_FWRITE: + break; + case IPC_CMD9_FOPEN_DIR: + break; + case IPC_CMD9_FREAD_DIR: + break; + case IPC_CMD9_FCLOSE_DIR: + break; + case IPC_CMD9_FUNLINK: + break; + case IPC_CMD9_FGETFREE: + break; + case IPC_CMD9_READ_SECTORS: + break; + case IPC_CMD9_WRITE_SECTORS: + break; + case IPC_CMD9_MALLOC: + if(params != 1) panic(); + result = (u32)malloc(PXI_recvWord()); + break; + case IPC_CMD9_FREE: + if(params != 1) panic(); + free((void*)PXI_recvWord()); + break; + case IPC_CMD9_LOAD_VERIFY_FIRM: + break; + case IPC_CMD9_FIRM_LAUNCH: + break; + case IPC_CMD9_PREPA_POWER: + case IPC_CMD9_PANIC: + case IPC_CMD9_EXCEPTION: + // Close and deinitalize everything. + break; + default: + panic(); + } + + return result; +}