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/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 ----------------------- 11 files changed, 178 insertions(+), 177 deletions(-) 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 (limited to 'arm9/lib/include') 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 -- cgit v1.2.3 From 7b3404b932a8fadddb44774407b22127b0f02115 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 1 May 2020 20:10:48 +0100 Subject: remove include/nitro and shift everything to arm9/lib --- arm9/lib/include/OS.h | 17 ----------------- arm9/lib/include/OS_init.h | 17 +++++++++++++++++ arm9/lib/include/OS_system.h | 13 +++++++++---- arm9/lib/include/consts.h | 8 +++++--- arm9/lib/include/nitro.h | 2 +- 5 files changed, 32 insertions(+), 25 deletions(-) delete mode 100644 arm9/lib/include/OS.h create mode 100644 arm9/lib/include/OS_init.h (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/OS.h b/arm9/lib/include/OS.h deleted file mode 100644 index b152dfb8..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_init.h b/arm9/lib/include/OS_init.h new file mode 100644 index 00000000..c556253a --- /dev/null +++ b/arm9/lib/include/OS_init.h @@ -0,0 +1,17 @@ +// +// Created by mart on 4/12/20. +// + +#ifndef POKEDIAMOND_OS_INIT_H +#define POKEDIAMOND_OS_INIT_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_INIT_H diff --git a/arm9/lib/include/OS_system.h b/arm9/lib/include/OS_system.h index c7f121bd..20228cbf 100644 --- a/arm9/lib/include/OS_system.h +++ b/arm9/lib/include/OS_system.h @@ -17,17 +17,22 @@ typedef enum { OS_PROCMODE_SYS=31 } OSProcMode; +#pragma enumsalwaysint on typedef enum { - OS_INTRMODE_DISABLE = HW_PSR_IRQ_DISABLE, + OS_INTRMODE_DISABLE_IRQ = HW_PSR_DISABLE_IRQ, + OS_INTRMODE_DISABLE_FIQ = HW_PSR_DISABLE_FIQ, OS_INTRMODE_ENABLE = 0 } OSIntrMode; +#pragma enumsalwaysint reset OSIntrMode OS_EnableInterrupts(); OSIntrMode OS_DisableInterrupts(); -OSIntrMode OS_RestoreInterrupts(OSIntrMode state); +OSIntrMode OS_RestoreInterrupts(register OSIntrMode state); OSIntrMode OS_DisableInterrupts_IrqAndFiq(); -OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state); +OSIntrMode OS_RestoreInterrupts_IrqAndFiq(register OSIntrMode state); +OSIntrMode OS_GetCpsrIrq(); OSProcMode OS_GetProcMode(); - +void OS_SpinWait(); +void OS_WaitVBlankIntr(); #endif //POKEDIAMOND_OS_SYSTEM_H diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h index 6fc71be2..930f9af5 100644 --- a/arm9/lib/include/consts.h +++ b/arm9/lib/include/consts.h @@ -9,9 +9,9 @@ #define HW_PSR_CPU_MODE_MASK 0x1f // CPU mode -#define HW_PSR_FIQ_DISABLE 0x40 // Disable FIQ -#define HW_PSR_IRQ_DISABLE 0x80 // Disable IRQ -#define HW_PSR_IRQ_FIQ_DISABLE 0xc0 // Disable FIQ and IRQ +#define HW_PSR_DISABLE_FIQ 0x40 // Disable FIQ +#define HW_PSR_DISABLE_IRQ 0x80 // Disable IRQ +#define HW_PSR_DISABLE_IRQ_FIQ 0xc0 // Disable FIQ and IRQ #define HW_C6_PR_4KB 0x16 #define HW_C6_PR_8KB 0x18 @@ -42,4 +42,6 @@ #define OSi_TRUNC(n, a) (((u32) (n)) & ~((a) - 1)) #define OSi_ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1)) +#define OS_IE_V_BLANK (1UL << 0) + #endif //POKEDIAMOND_CONSTS_H diff --git a/arm9/lib/include/nitro.h b/arm9/lib/include/nitro.h index 8d875653..f7397fb0 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_init.h" #include "mmap.h" #ifdef __cplusplus -- cgit v1.2.3 From 527b257015fa32ac4007b1d7e9198ac37d8e1542 Mon Sep 17 00:00:00 2001 From: red031000 Date: Fri, 1 May 2020 20:38:36 +0100 Subject: macro and register --- arm9/lib/include/OS_system.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/OS_system.h b/arm9/lib/include/OS_system.h index 20228cbf..93903315 100644 --- a/arm9/lib/include/OS_system.h +++ b/arm9/lib/include/OS_system.h @@ -17,19 +17,19 @@ typedef enum { OS_PROCMODE_SYS=31 } OSProcMode; -#pragma enumsalwaysint on +ENUMS_ALWAYS_INT_ON typedef enum { OS_INTRMODE_DISABLE_IRQ = HW_PSR_DISABLE_IRQ, OS_INTRMODE_DISABLE_FIQ = HW_PSR_DISABLE_FIQ, OS_INTRMODE_ENABLE = 0 } OSIntrMode; -#pragma enumsalwaysint reset +ENUMS_ALWAYS_INT_RESET OSIntrMode OS_EnableInterrupts(); OSIntrMode OS_DisableInterrupts(); -OSIntrMode OS_RestoreInterrupts(register OSIntrMode state); +OSIntrMode OS_RestoreInterrupts(OSIntrMode state); OSIntrMode OS_DisableInterrupts_IrqAndFiq(); -OSIntrMode OS_RestoreInterrupts_IrqAndFiq(register OSIntrMode state); +OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state); OSIntrMode OS_GetCpsrIrq(); OSProcMode OS_GetProcMode(); void OS_SpinWait(); -- cgit v1.2.3 From 2ee7030776461ee835dbbd44149f90ae79e7d4c5 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 3 May 2020 01:42:55 +0100 Subject: temp OS_entropy --- arm9/lib/include/OS_entropy.h | 10 +++++++++ arm9/lib/include/OS_init.h | 3 +++ arm9/lib/include/OS_spinLock.h | 14 ++++++++++++ arm9/lib/include/OS_thread.h | 23 ++++++++++++++++++++ arm9/lib/include/mmap.h | 49 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+) create mode 100644 arm9/lib/include/OS_entropy.h create mode 100644 arm9/lib/include/OS_spinLock.h create mode 100644 arm9/lib/include/OS_thread.h (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/OS_entropy.h b/arm9/lib/include/OS_entropy.h new file mode 100644 index 00000000..f4eef4b5 --- /dev/null +++ b/arm9/lib/include/OS_entropy.h @@ -0,0 +1,10 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_ENTROPY_H +#define POKEDIAMOND_OS_ENTROPY_H + +void OS_GetLowEntropyData(u32 * arr); + +#endif //POKEDIAMOND_OS_ENTROPY_H diff --git a/arm9/lib/include/OS_init.h b/arm9/lib/include/OS_init.h index c556253a..1ff2837c 100644 --- a/arm9/lib/include/OS_init.h +++ b/arm9/lib/include/OS_init.h @@ -7,7 +7,10 @@ #include "types.h" #include "consts.h" +#include "OS_spinLock.h" +#include "OS_thread.h" #include "OS_protectionRegion.h" +#include "OS_entropy.h" #include "OS_arena.h" #include "OS_alloc.h" #include "OS_system.h" diff --git a/arm9/lib/include/OS_spinLock.h b/arm9/lib/include/OS_spinLock.h new file mode 100644 index 00000000..b7f0a571 --- /dev/null +++ b/arm9/lib/include/OS_spinLock.h @@ -0,0 +1,14 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_SPINLOCK_H +#define POKEDIAMOND_OS_SPINLOCK_H + +typedef volatile struct OSLockWord { + u32 lockFlag; + u16 ownerID; + u16 extension; +} OSLockWord; + +#endif //POKEDIAMOND_OS_SPINLOCK_H diff --git a/arm9/lib/include/OS_thread.h b/arm9/lib/include/OS_thread.h new file mode 100644 index 00000000..4fb70bf7 --- /dev/null +++ b/arm9/lib/include/OS_thread.h @@ -0,0 +1,23 @@ +// +// Created by red031000 on 2020-05-03. +// + +#ifndef POKEDIAMOND_OS_THREAD_H +#define POKEDIAMOND_OS_THREAD_H + +typedef struct _OSThread OSThread; + +typedef struct OSThreadInfo { + u16 isNeedRescheduling; + u16 irqDepth; + OSThread* current; + OSThread* list; + void* switchCallback; // type: OSSwitchThreadCallback +} OSThreadInfo; + +struct _OSThread +{ + u8 padding[0x80]; //todo: not the correct size but idfk +}; + +#endif //POKEDIAMOND_OS_THREAD_H diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h index 14820c39..ddbd8883 100644 --- a/arm9/lib/include/mmap.h +++ b/arm9/lib/include/mmap.h @@ -26,6 +26,7 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #define HW_ARENA_INFO_BUF (HW_MAIN_MEM + 0x007ffda0) // Arena data structure #define HW_ROM_HEADER_BUF (HW_MAIN_MEM + 0x007ffe00) // ROM registration area data buffer #define HW_RED_RESERVED (HW_MAIN_MEM + 0x007ff800) // Some kind of reserved data for shared memory +#define HW_MAIN_MEM_SYSTEM (HW_MAIN_MEM + 0x007ffc00) #define HW_MAIN_MEM_MAIN_END (HW_MAIN_MEM + HW_MAIN_MEM_MAIN_SIZE) #define HW_MAIN_MEM_EX_END (HW_MAIN_MEM + HW_MAIN_MEM_EX_SIZE) #define HW_MAIN_MEM_SHARED (HW_MAIN_MEM_EX_END - HW_MAIN_MEM_SHARED_SIZE) @@ -42,4 +43,52 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #define OSi_WRAM_MAIN_ARENA_HI_DEFAULT (HW_WRAM) #define OSi_WRAM_MAIN_ARENA_LO_DEFAULT (HW_WRAM) +#include "OS_thread.h" //not ideal but it's necessary +#include "OS_spinLock.h" + +typedef struct { + u8 bootCheckInfo[0x20]; // 000-01f: 32byte boot check info + u32 resetParameter; // 020-023: 4byte reset parameter + u8 padding5[0x8]; // 024-02c: (8byte) + u32 romBaseOffset; // 02c-02f: 4byte ROM offset of own program + u8 cartridgeModuleInfo[12]; // 030-03b: 12byte cartridge module info + u32 vblankCount; // 03c-03f: 4byte V-Blank Count + u8 wmBootBuf[0x40]; // 040-07f: 64byte WM multiboot buffer + u8 nvramUserInfo[0x100]; // 080-17f: 256bytes NVRAM user info + u8 isd_reserved1[0x20]; // 180-19f: 32bytes ISDebugger reserved + u8 arenaInfo[0x48]; // 1a0-1e7: 72byte Arena information + u8 real_time_clock[8]; // 1e8-1ef: 8bytes RTC + u32 dmaClearBuf[4]; // 1f0-1ff: 16bytes DMA clear information buffer (for ARM9-TEG) + u8 rom_header[0x160]; // 200-35f: 352bytes ROM registration area info storage buffer + u8 isd_reserved2[32]; // 360-37f: 32bytes ISDebugger reserved + u32 pxiSignalParam[2]; // 380-387: 8bytes Param for PXI Signal + u32 pxiHandleChecker[2]; // 388-38f: 8bytes Flag for PXI Command Handler Installed + u32 mic_last_address; // 390-393: 4bytes MIC latest sampling result storage address + u16 mic_sampling_data; // 394-395: 2bytes MIC sampling result + u16 wm_callback_control; // 396-397: 2bytes Parameter for WM callback synchronization + u16 wm_rssi_pool; // 398-399: 2bytes Random number source depends on WM received signal intensity + u8 padding3[2]; // 39a-39b: (2bytes) + u32 component_param; // 39c-39f: 4bytes Parameter for Component synchronization + OSThreadInfo *threadinfo_mainp; // 3a0-3a3: 4bytes Verify that the pointer to ARM9 thread information is initial value 0 + OSThreadInfo *threadinfo_subp; // 3a4-3a7: 4bytes Verify that the pointer to ARM7 thread information is initial value 0 + u16 button_XY; // 3a8-3a9: 2bytes XY button information storage location + u8 touch_panel[4]; // 3aa-3ad: 4bytes Touch Screen information storage location + u16 autoloadSync; // 3ae-3af: 2bytes autoload sync between processors + u32 lockIDFlag_mainp[2]; // 3b0-3b7: 8bytes lockID management flag (ARM9) + u32 lockIDFlag_subp[2]; // 3b8-3bf: 8bytes lockID management flag (ARM7) + struct OSLockWord lock_VRAM_C; // 3c0-3c7: 8bytes C - lock buffer + struct OSLockWord lock_VRAM_D; // 3c8-3cf: 8bytes VRAM-D - lock buffer + struct OSLockWord lock_WRAM_BLOCK0; // 3d0-3d7: 8bytes Block0 - lock buffer + struct OSLockWord lock_WRAM_BLOCK1; // 3d8-3df: 8bytes CPU internal work RAM - Block1 - lock buffer + struct OSLockWord lock_CARD; // 3e0-3e7: 8bytes Game Card - lock buffer + struct OSLockWord lock_CARTRIDGE; // 3e8-3ef: 8bytes DS Pak - lock buffer + struct OSLockWord lock_INIT; // 3f0-3f7: 8bytes Initialization lock buffer + u16 mmem_checker_mainp; // 3f8-3f9: 2bytes MainMomory Size Checker for Main processor + u16 mmem_checker_subp; // 3fa-3fb: 2bytes MainMomory Size Checker for Sub processor + u8 padding4[2]; // 3fc-3fd: (2bytes) + u16 command_area; // 3fe-3ff: 2bytes Command Area +} OSSystemWork; + +#define OS_GetSystemWork() ((OSSystemWork *)HW_MAIN_MEM_SYSTEM) + #endif \ No newline at end of file -- cgit v1.2.3 From 4f6c75ac8381a7a3c2902c97870066ee90f1d320 Mon Sep 17 00:00:00 2001 From: red031000 Date: Sun, 3 May 2020 19:22:26 +0100 Subject: match OS_GetLowEntropyData --- arm9/lib/include/OS_entropy.h | 17 +++++++++++++++++ arm9/lib/include/consts.h | 13 +++++++++++++ arm9/lib/include/mmap.h | 2 ++ arm9/lib/include/types.h | 10 ++++++++++ 4 files changed, 42 insertions(+) (limited to 'arm9/lib/include') diff --git a/arm9/lib/include/OS_entropy.h b/arm9/lib/include/OS_entropy.h index f4eef4b5..b4695a72 100644 --- a/arm9/lib/include/OS_entropy.h +++ b/arm9/lib/include/OS_entropy.h @@ -5,6 +5,23 @@ #ifndef POKEDIAMOND_OS_ENTROPY_H #define POKEDIAMOND_OS_ENTROPY_H +#include "consts.h" + void OS_GetLowEntropyData(u32 * arr); +typedef struct NVRAMConfig{ + u8 ncd[110]; // todo: typeof NVRAMConfigData + u16 saveCount; + u16 rc16; +} NVRAMConfig; + +extern vu64 OSi_TickCounter; + +extern u16 OS_GetTickLo(); + +static inline s32 GX_GetVCount() +{ + return reg_GX_VCOUNT; +} + #endif //POKEDIAMOND_OS_ENTROPY_H diff --git a/arm9/lib/include/consts.h b/arm9/lib/include/consts.h index 930f9af5..e07fe323 100644 --- a/arm9/lib/include/consts.h +++ b/arm9/lib/include/consts.h @@ -13,6 +13,19 @@ #define HW_PSR_DISABLE_IRQ 0x80 // Disable IRQ #define HW_PSR_DISABLE_IRQ_FIQ 0xc0 // Disable FIQ and IRQ +#define HW_REG_BASE 0x04000000 +#define REG_VCOUNT_OFFSET 0x006 +#define REG_VCOUNT_ADDR (HW_REG_BASE + REG_VCOUNT_OFFSET) +#define reg_GX_VCOUNT (*(REGType16v *)REG_VCOUNT_ADDR) + +#define REG_KEYINPUT_OFFSET 0x130 +#define REG_KEYINPUT_ADDR (HW_REG_BASE + REG_KEYINPUT_OFFSET) +#define reg_PAD_KEYINPUT (*(REGType16v *)REG_KEYINPUT_ADDR) + +#define REG_GXSTAT_OFFSET 0x600 +#define REG_GXSTAT_ADDR (HW_REG_BASE + REG_GXSTAT_OFFSET) +#define reg_G3X_GXSTAT (*(REGType32v *)REG_GXSTAT_ADDR) + #define HW_C6_PR_4KB 0x16 #define HW_C6_PR_8KB 0x18 #define HW_C6_PR_16KB 0x1a diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h index ddbd8883..d94df843 100644 --- a/arm9/lib/include/mmap.h +++ b/arm9/lib/include/mmap.h @@ -35,6 +35,8 @@ extern u32 SDK_AUTOLOAD_DTCM_START[]; #define HW_DTCM_SVC_STACK (HW_DTCM_SVC_STACK_END - HW_SVC_STACK_SIZE) #define HW_DTCM_IRQ_STACK_END (HW_DTCM_SVC_STACK) +#define HW_BUTTON_XY_BUF (HW_MAIN_MEM + 0x007fffa8) + #define OSi_MAIN_ARENA_HI_DEFAULT (HW_MAIN_MEM_MAIN_END) #define OSi_MAINEX_ARENA_HI_DEFAULT (HW_MAIN_MEM + HW_MAIN_MEM_DEBUGGER_OFFSET) #define HW_ITCM_ARENA_HI_DEFAULT (HW_ITCM + HW_ITCM_SIZE) diff --git a/arm9/lib/include/types.h b/arm9/lib/include/types.h index 5ad2c75e..40f8207d 100644 --- a/arm9/lib/include/types.h +++ b/arm9/lib/include/types.h @@ -25,6 +25,16 @@ typedef volatile s64 vs64; typedef float f32; typedef volatile f32 vf32; +typedef u8 REGType8; +typedef u16 REGType16; +typedef u32 REGType32; +typedef u64 REGType64; + +typedef vu8 REGType8v; +typedef vu16 REGType16v; +typedef vu32 REGType32v; +typedef vu64 REGType64v; + typedef int BOOL; #define TRUE 1 #define FALSE 0 -- cgit v1.2.3