From f04501a417999dddd7ec5963b90ab2e152ac3477 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 1 May 2020 17:54:04 +0100 Subject: match OS_protectionRegion --- arm9/asm/OS_protectionRegion.s | 22 ---------------- arm9/lib/include/OS.h | 17 ++++++++++++ arm9/lib/include/OS_alloc.h | 38 +++++++++++++++++++++++++++ arm9/lib/include/OS_arena.h | 41 +++++++++++++++++++++++++++++ arm9/lib/include/OS_protectionRegion.h | 48 ++++++++++++++++++++++++++++++++++ arm9/lib/include/OS_system.h | 33 +++++++++++++++++++++++ arm9/lib/include/nitro.h | 2 +- arm9/lib/include/os.h | 17 ------------ arm9/lib/include/os_alloc.h | 38 --------------------------- arm9/lib/include/os_arena.h | 41 ----------------------------- arm9/lib/include/os_protectionRegion.h | 47 --------------------------------- arm9/lib/include/os_system.h | 33 ----------------------- arm9/lib/src/OS_alloc.c | 4 +-- arm9/lib/src/OS_arena.c | 4 +-- arm9/lib/src/OS_protectionRegion.c | 26 ++++++++++++++++++ 15 files changed, 208 insertions(+), 203 deletions(-) delete mode 100644 arm9/asm/OS_protectionRegion.s create mode 100644 arm9/lib/include/OS.h create mode 100644 arm9/lib/include/OS_alloc.h create mode 100644 arm9/lib/include/OS_arena.h create mode 100644 arm9/lib/include/OS_protectionRegion.h create mode 100644 arm9/lib/include/OS_system.h delete mode 100644 arm9/lib/include/os.h delete mode 100644 arm9/lib/include/os_alloc.h delete mode 100644 arm9/lib/include/os_arena.h delete mode 100644 arm9/lib/include/os_protectionRegion.h delete mode 100644 arm9/lib/include/os_system.h create mode 100644 arm9/lib/src/OS_protectionRegion.c (limited to 'arm9') diff --git a/arm9/asm/OS_protectionRegion.s b/arm9/asm/OS_protectionRegion.s deleted file mode 100644 index 31bf52bd..00000000 --- a/arm9/asm/OS_protectionRegion.s +++ /dev/null @@ -1,22 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - arm_func_start OS_SetDPermissionsForProtectionRegion -OS_SetDPermissionsForProtectionRegion: ; 0x020CC9D8 - mrc p15, 0x0, r2, c5, c0, 0x2 - bic r2, r2, r0 - orr r2, r2, r1 - mcr p15, 0x0, r2, c5, c0, 0x2 - bx lr - - arm_func_start OS_SetProtectionRegion1 -OS_SetProtectionRegion1: ; 0x020CC9EC - mcr p15, 0x0, r0, c6, c1, 0x0 - bx lr - - arm_func_start OS_SetProtectionRegion2 -OS_SetProtectionRegion2: ; 0x020CC9F4 - mcr p15, 0x0, r0, c6, c2, 0x0 - bx lr diff --git a/arm9/lib/include/OS.h b/arm9/lib/include/OS.h new file mode 100644 index 00000000..b152dfb8 --- /dev/null +++ b/arm9/lib/include/OS.h @@ -0,0 +1,17 @@ +// +// Created by mart on 4/12/20. +// + +#ifndef POKEDIAMOND_OS_H +#define POKEDIAMOND_OS_H + +#include "types.h" +#include "consts.h" +#include "OS_protectionRegion.h" +#include "OS_arena.h" +#include "OS_alloc.h" +#include "OS_system.h" + +void OS_Init(); + +#endif //POKEDIAMOND_OS_H diff --git a/arm9/lib/include/OS_alloc.h b/arm9/lib/include/OS_alloc.h new file mode 100644 index 00000000..08fb3224 --- /dev/null +++ b/arm9/lib/include/OS_alloc.h @@ -0,0 +1,38 @@ +// +// Created by mart on 4/23/20. +// + +#ifndef POKEDIAMOND_OS_ALLOC_H +#define POKEDIAMOND_OS_ALLOC_H + +#include "types.h" +#include "OS_arena.h" + +typedef int OSHeapHandle; + +typedef struct Cell Cell; + +struct Cell { + Cell* prev; + Cell* next; + long size; +}; + +typedef struct { + long size; + Cell *free; + Cell *allocated; +} HeapDesc; + +typedef struct { + volatile OSHeapHandle currentHeap; + int numHeaps; + void* arenaStart; + void* arenaEnd; + HeapDesc* heapArray; +} OSHeapInfo; + +void OS_FreeToHeap(OSArenaId id, OSHeapHandle heap, void *ptr); +void* OS_AllocFromHeap(OSArenaId id, OSHeapHandle heap, u32 size); + +#endif //POKEDIAMOND_OS_ALLOC_H diff --git a/arm9/lib/include/OS_arena.h b/arm9/lib/include/OS_arena.h new file mode 100644 index 00000000..f1893a3d --- /dev/null +++ b/arm9/lib/include/OS_arena.h @@ -0,0 +1,41 @@ +// +// Created by red031000 on 2020-04-27. +// + +#ifndef POKEDIAMOND_OS_ARENA_H +#define POKEDIAMOND_OS_ARENA_H + +#include "types.h" + +typedef enum { + OS_ARENA_MAIN = 0, + OS_ARENA_MAIN_SUBPRIV = 1, + OS_ARENA_MAINEX = 2, + OS_ARENA_ITCM = 3, + OS_ARENA_DTCM = 4, + OS_ARENA_SHARED = 5, + OS_ARENA_WRAM_MAIN = 6, + OS_ARENA_WRAM_SUB = 7, + OS_ARENA_WRAM_SUBPRIV = 8, + OS_ARENA_MAX = 9 +} OSArenaId; + +typedef struct { + void* lo[OS_ARENA_MAX]; + void* hi[OS_ARENA_MAX]; + u16 initialized; + u8 padding[2]; +} OSArenaInfo; + +void OS_InitArena(); +void OS_InitArenaEx(); +void* OS_GetArenaHi(OSArenaId id); +void* OS_GetArenaLo(OSArenaId id); +void* OS_GetInitArenaHi(OSArenaId id); +void* OS_GetInitArenaLo(OSArenaId id); +void OS_SetArenaHi(OSArenaId id, void *newHi); +void OS_SetArenaLo(OSArenaId id, void *newLo); +void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align); +void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align); + +#endif //POKEDIAMOND_OS_ARENA_H diff --git a/arm9/lib/include/OS_protectionRegion.h b/arm9/lib/include/OS_protectionRegion.h new file mode 100644 index 00000000..8e25420a --- /dev/null +++ b/arm9/lib/include/OS_protectionRegion.h @@ -0,0 +1,48 @@ +// +// Created by red031000 on 2020-04-24. +// + +#ifndef POKEDIAMOND_OS_PROTECTIONREGION_H +#define POKEDIAMOND_OS_PROTECTIONREGION_H + +#include "types.h" +#include "consts.h" + +void OS_SetDPermissionsForProtectionRegion(register u32 setMask, register u32 flags); +void OS_SetProtectionRegion1(u32 param); +void OS_SetProtectionRegion2(u32 param); + +typedef enum +{ + OSi_PR_BASE_MASK_4KB = 0xfffff000, + OSi_PR_BASE_MASK_8KB = 0xffffe000, + OSi_PR_BASE_MASK_16KB = 0xffffc000, + OSi_PR_BASE_MASK_32KB = 0xffff8000, + OSi_PR_BASE_MASK_64KB = 0xffff0000, + OSi_PR_BASE_MASK_128KB = 0xfffe0000, + OSi_PR_BASE_MASK_256KB = 0xfffc0000, + OSi_PR_BASE_MASK_512KB = 0xfff80000, + OSi_PR_BASE_MASK_1MB = 0xfff00000, + OSi_PR_BASE_MASK_2MB = 0xffe00000, + OSi_PR_BASE_MASK_4MB = 0xffc00000, + OSi_PR_BASE_MASK_8MB = 0xff800000, + OSi_PR_BASE_MASK_16MB = 0xff000000, + OSi_PR_BASE_MASK_32MB = 0xfe000000, + OSi_PR_BASE_MASK_64MB = 0xfc000000, + OSi_PR_BASE_MASK_128MB = 0xf8000000, + OSi_PR_BASE_MASK_256MB = 0xf0000000, + OSi_PR_BASE_MASK_512MB = 0xe0000000, + OSi_PR_BASE_MASK_1GB = 0xc0000000, + OSi_PR_BASE_MASK_2GB = 0x80000000, + OSi_PR_BASE_MASK_4GB = 0x00000000 +} OSiProtectionRegionBaseMask; + +static inline u32 OSi_CalcPRParam(u32 address, u32 size, OSiProtectionRegionBaseMask mask) { + return ((address & mask) | size); +} + +#define OS_SetProtectionRegion(regionNo, address, sizeStr) \ + OS_SetProtectionRegion##regionNo(OSi_CalcPRParam(address, HW_C6_PR_##sizeStr, OSi_PR_BASE_MASK_##sizeStr) \ + | 1) + +#endif //POKEDIAMOND_OS_PROTECTIONREGION_H diff --git a/arm9/lib/include/OS_system.h b/arm9/lib/include/OS_system.h new file mode 100644 index 00000000..c7f121bd --- /dev/null +++ b/arm9/lib/include/OS_system.h @@ -0,0 +1,33 @@ +// +// Created by mart on 4/23/20. +// + +#ifndef POKEDIAMOND_OS_SYSTEM_H +#define POKEDIAMOND_OS_SYSTEM_H + +#include "consts.h" + +typedef enum { + OS_PROCMODE_USER=16, + OS_PROCMODE_FIQ=17, + OS_PROCMODE_IRQ=18, + OS_PROCMODE_SVC=19, + OS_PROCMODE_ABORT=23, + OS_PROCMODE_UNDEF=27, + OS_PROCMODE_SYS=31 +} OSProcMode; + +typedef enum { + OS_INTRMODE_DISABLE = HW_PSR_IRQ_DISABLE, + OS_INTRMODE_ENABLE = 0 +} OSIntrMode; + +OSIntrMode OS_EnableInterrupts(); +OSIntrMode OS_DisableInterrupts(); +OSIntrMode OS_RestoreInterrupts(OSIntrMode state); +OSIntrMode OS_DisableInterrupts_IrqAndFiq(); +OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state); +OSProcMode OS_GetProcMode(); + + +#endif //POKEDIAMOND_OS_SYSTEM_H diff --git a/arm9/lib/include/nitro.h b/arm9/lib/include/nitro.h index 8cf603f5..8d875653 100644 --- a/arm9/lib/include/nitro.h +++ b/arm9/lib/include/nitro.h @@ -8,7 +8,7 @@ extern "C" { // Include all nitro files #include "types.h" #include "consts.h" -#include "os.h" +#include "OS.h" #include "mmap.h" #ifdef __cplusplus diff --git a/arm9/lib/include/os.h b/arm9/lib/include/os.h deleted file mode 100644 index 591d8db0..00000000 --- a/arm9/lib/include/os.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// Created by mart on 4/12/20. -// - -#ifndef POKEDIAMOND_OS_H -#define POKEDIAMOND_OS_H - -#include "types.h" -#include "consts.h" -#include "os_protectionRegion.h" -#include "os_arena.h" -#include "os_alloc.h" -#include "os_system.h" - -void OS_Init(); - -#endif //POKEDIAMOND_OS_H diff --git a/arm9/lib/include/os_alloc.h b/arm9/lib/include/os_alloc.h deleted file mode 100644 index 1c4b6122..00000000 --- a/arm9/lib/include/os_alloc.h +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by mart on 4/23/20. -// - -#ifndef POKEDIAMOND_OS_ALLOC_H -#define POKEDIAMOND_OS_ALLOC_H - -#include "types.h" -#include "os_arena.h" - -typedef int OSHeapHandle; - -typedef struct Cell Cell; - -struct Cell { - Cell* prev; - Cell* next; - long size; -}; - -typedef struct { - long size; - Cell *free; - Cell *allocated; -} HeapDesc; - -typedef struct { - volatile OSHeapHandle currentHeap; - int numHeaps; - void* arenaStart; - void* arenaEnd; - HeapDesc* heapArray; -} OSHeapInfo; - -void OS_FreeToHeap(OSArenaId id, OSHeapHandle heap, void *ptr); -void* OS_AllocFromHeap(OSArenaId id, OSHeapHandle heap, u32 size); - -#endif //POKEDIAMOND_OS_ALLOC_H diff --git a/arm9/lib/include/os_arena.h b/arm9/lib/include/os_arena.h deleted file mode 100644 index f1893a3d..00000000 --- a/arm9/lib/include/os_arena.h +++ /dev/null @@ -1,41 +0,0 @@ -// -// Created by red031000 on 2020-04-27. -// - -#ifndef POKEDIAMOND_OS_ARENA_H -#define POKEDIAMOND_OS_ARENA_H - -#include "types.h" - -typedef enum { - OS_ARENA_MAIN = 0, - OS_ARENA_MAIN_SUBPRIV = 1, - OS_ARENA_MAINEX = 2, - OS_ARENA_ITCM = 3, - OS_ARENA_DTCM = 4, - OS_ARENA_SHARED = 5, - OS_ARENA_WRAM_MAIN = 6, - OS_ARENA_WRAM_SUB = 7, - OS_ARENA_WRAM_SUBPRIV = 8, - OS_ARENA_MAX = 9 -} OSArenaId; - -typedef struct { - void* lo[OS_ARENA_MAX]; - void* hi[OS_ARENA_MAX]; - u16 initialized; - u8 padding[2]; -} OSArenaInfo; - -void OS_InitArena(); -void OS_InitArenaEx(); -void* OS_GetArenaHi(OSArenaId id); -void* OS_GetArenaLo(OSArenaId id); -void* OS_GetInitArenaHi(OSArenaId id); -void* OS_GetInitArenaLo(OSArenaId id); -void OS_SetArenaHi(OSArenaId id, void *newHi); -void OS_SetArenaLo(OSArenaId id, void *newLo); -void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align); -void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align); - -#endif //POKEDIAMOND_OS_ARENA_H diff --git a/arm9/lib/include/os_protectionRegion.h b/arm9/lib/include/os_protectionRegion.h deleted file mode 100644 index 7b212934..00000000 --- a/arm9/lib/include/os_protectionRegion.h +++ /dev/null @@ -1,47 +0,0 @@ -// -// Created by red031000 on 2020-04-24. -// - -#ifndef POKEDIAMOND_OS_PROTECTIONREGION_H -#define POKEDIAMOND_OS_PROTECTIONREGION_H - -#include "types.h" -#include "consts.h" - -void OS_SetProtectionRegion1(u32 param); -void OS_SetProtectionRegion2(u32 param); - -typedef enum -{ - OSi_PR_BASE_MASK_4KB = 0xfffff000, - OSi_PR_BASE_MASK_8KB = 0xffffe000, - OSi_PR_BASE_MASK_16KB = 0xffffc000, - OSi_PR_BASE_MASK_32KB = 0xffff8000, - OSi_PR_BASE_MASK_64KB = 0xffff0000, - OSi_PR_BASE_MASK_128KB = 0xfffe0000, - OSi_PR_BASE_MASK_256KB = 0xfffc0000, - OSi_PR_BASE_MASK_512KB = 0xfff80000, - OSi_PR_BASE_MASK_1MB = 0xfff00000, - OSi_PR_BASE_MASK_2MB = 0xffe00000, - OSi_PR_BASE_MASK_4MB = 0xffc00000, - OSi_PR_BASE_MASK_8MB = 0xff800000, - OSi_PR_BASE_MASK_16MB = 0xff000000, - OSi_PR_BASE_MASK_32MB = 0xfe000000, - OSi_PR_BASE_MASK_64MB = 0xfc000000, - OSi_PR_BASE_MASK_128MB = 0xf8000000, - OSi_PR_BASE_MASK_256MB = 0xf0000000, - OSi_PR_BASE_MASK_512MB = 0xe0000000, - OSi_PR_BASE_MASK_1GB = 0xc0000000, - OSi_PR_BASE_MASK_2GB = 0x80000000, - OSi_PR_BASE_MASK_4GB = 0x00000000 -} OSiProtectionRegionBaseMask; - -static inline u32 OSi_CalcPRParam(u32 address, u32 size, OSiProtectionRegionBaseMask mask) { - return ((address & mask) | size); -} - -#define OS_SetProtectionRegion(regionNo, address, sizeStr) \ - OS_SetProtectionRegion##regionNo(OSi_CalcPRParam(address, HW_C6_PR_##sizeStr, OSi_PR_BASE_MASK_##sizeStr) \ - | 1) - -#endif //POKEDIAMOND_OS_PROTECTIONREGION_H diff --git a/arm9/lib/include/os_system.h b/arm9/lib/include/os_system.h deleted file mode 100644 index c7f121bd..00000000 --- a/arm9/lib/include/os_system.h +++ /dev/null @@ -1,33 +0,0 @@ -// -// Created by mart on 4/23/20. -// - -#ifndef POKEDIAMOND_OS_SYSTEM_H -#define POKEDIAMOND_OS_SYSTEM_H - -#include "consts.h" - -typedef enum { - OS_PROCMODE_USER=16, - OS_PROCMODE_FIQ=17, - OS_PROCMODE_IRQ=18, - OS_PROCMODE_SVC=19, - OS_PROCMODE_ABORT=23, - OS_PROCMODE_UNDEF=27, - OS_PROCMODE_SYS=31 -} OSProcMode; - -typedef enum { - OS_INTRMODE_DISABLE = HW_PSR_IRQ_DISABLE, - OS_INTRMODE_ENABLE = 0 -} OSIntrMode; - -OSIntrMode OS_EnableInterrupts(); -OSIntrMode OS_DisableInterrupts(); -OSIntrMode OS_RestoreInterrupts(OSIntrMode state); -OSIntrMode OS_DisableInterrupts_IrqAndFiq(); -OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state); -OSProcMode OS_GetProcMode(); - - -#endif //POKEDIAMOND_OS_SYSTEM_H diff --git a/arm9/lib/src/OS_alloc.c b/arm9/lib/src/OS_alloc.c index 242c5571..e883656e 100644 --- a/arm9/lib/src/OS_alloc.c +++ b/arm9/lib/src/OS_alloc.c @@ -2,9 +2,9 @@ // Created by mart on 4/23/20. // #include "function_target.h" -#include "os_alloc.h" +#include "OS_alloc.h" #include "consts.h" -#include "os_system.h" +#include "OS_system.h" void* OSiHeapInfo[OS_ARENA_MAX]; diff --git a/arm9/lib/src/OS_arena.c b/arm9/lib/src/OS_arena.c index 58b338f1..eb04e60b 100644 --- a/arm9/lib/src/OS_arena.c +++ b/arm9/lib/src/OS_arena.c @@ -3,8 +3,8 @@ // #include "function_target.h" #include "consts.h" -#include "os_arena.h" -#include "os_protectionRegion.h" +#include "OS_arena.h" +#include "OS_protectionRegion.h" extern u32 OS_GetConsoleType(); extern BOOL OSi_MainExArenaEnabled; diff --git a/arm9/lib/src/OS_protectionRegion.c b/arm9/lib/src/OS_protectionRegion.c new file mode 100644 index 00000000..382310d9 --- /dev/null +++ b/arm9/lib/src/OS_protectionRegion.c @@ -0,0 +1,26 @@ +// +// Created by red031000 on 2020-04-24. +// + +#include "OS_protectionRegion.h" + +asm void OS_SetDPermissionsForProtectionRegion(register u32 setMask, register u32 flags) +{ + mrc p15, 0x0, r2, c5, c0, 0x2 + bic r2, r2, r0 + orr r2, r2, r1 + mcr p15, 0x0, r2, c5, c0, 0x2 + bx lr +} + +asm void OS_SetProtectionRegion1(u32 param) +{ + mcr p15, 0x0, r0, c6, c1, 0x0 + bx lr +} + +asm void OS_SetProtectionRegion2(u32 param) +{ + mcr p15, 0x0, r0, c6, c2, 0x0 + bx lr +} \ No newline at end of file -- cgit v1.2.3