aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxetc
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2023-05-11 23:42:43 +0200
committerGitHub <noreply@github.com>2023-05-11 23:42:43 +0200
commit04d7728350cbd04dd86cd894e906c98673e3f9a7 (patch)
tree08e8c7dd495d1c4c6fcf5f7ba6b4b10693dc42f6 /libpsn00b/psxetc
parenteaec942f56ceec9c14de5c4185a02602abadd50a (diff)
parent58a8306d24fe29d965aa8b40ddc37c3163c0a2f9 (diff)
downloadpsn00bsdk-04d7728350cbd04dd86cd894e906c98673e3f9a7.tar.gz
Merge pull request #70 from Lameguy64/v0.23-wip
Header cleanups, PCDRV, more safety checks, libc and mkpsxiso fixes (v0.23)
Diffstat (limited to 'libpsn00b/psxetc')
-rw-r--r--libpsn00b/psxetc/dl.c13
-rw-r--r--libpsn00b/psxetc/interrupts.c40
2 files changed, 41 insertions, 12 deletions
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c
index ff712eb..06302e2 100644
--- a/libpsn00b/psxetc/dl.c
+++ b/libpsn00b/psxetc/dl.c
@@ -112,6 +112,8 @@ static uint32_t _elf_hash(const char *str) {
/* Symbol map loading/introspection API */
int DL_InitSymbolMap(int num_entries) {
+ _sdk_validate_args(num_entries, -1);
+
if (_symbol_map.entries)
DL_UnloadSymbolMap();
@@ -151,6 +153,8 @@ void DL_UnloadSymbolMap(void) {
}
void DL_AddMapSymbol(const char *name, void *ptr) {
+ _sdk_validate_args_void(name);
+
uint32_t hash = _elf_hash(name);
int index = _symbol_map.index;
_symbol_map.index = index + 1;
@@ -168,6 +172,8 @@ void DL_AddMapSymbol(const char *name, void *ptr) {
}
int DL_ParseSymbolMap(const char *ptr, size_t size) {
+ _sdk_validate_args(ptr && size, 0);
+
int entries = 0;
// Perform a quick scan over the entire map text and count the number of
@@ -232,6 +238,8 @@ int DL_ParseSymbolMap(const char *ptr, size_t size) {
}
void *DL_GetMapSymbol(const char *name) {
+ _sdk_validate_args(name, 0);
+
if (!_symbol_map.entries) {
_sdk_log("DL_GetMapSymbol() with no map loaded\n");
return 0;
@@ -275,8 +283,7 @@ void *DL_SetResolveCallback(void *(*callback)(DLL *, const char *)) {
/* Library loading and linking API */
DLL *DL_CreateDLL(DLL *dll, void *ptr, size_t size, DL_ResolveMode mode) {
- if (!dll || !ptr)
- return 0;
+ _sdk_validate_args(dll && ptr && size, 0);
dll->ptr = ptr;
dll->malloc_ptr = (mode & DL_FREE_ON_DESTROY) ? ptr : 0;
@@ -463,6 +470,8 @@ void DL_DestroyDLL(DLL *dll) {
}
void *DL_GetDLLSymbol(const DLL *dll, const char *name) {
+ _sdk_validate_args(name, 0);
+
if (!dll)
return DL_GetMapSymbol(name);
//return _dl_resolve_callback(0, name);
diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c
index f2a273c..8bd11fc 100644
--- a/libpsn00b/psxetc/interrupts.c
+++ b/libpsn00b/psxetc/interrupts.c
@@ -4,6 +4,7 @@
*/
#include <stdint.h>
+#include <assert.h>
#include <psxapi.h>
#include <psxetc.h>
#include <hwregs_c.h>
@@ -99,8 +100,7 @@ static void _global_dma_handler(void) {
/* IRQ and DMA handler API */
void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) {
- if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS))
- return 0;
+ _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0);
void *old_callback = _irq_handlers[irq];
_irq_handlers[irq] = func;
@@ -116,15 +116,13 @@ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) {
}
void *GetInterruptCallback(IRQ_Channel irq) {
- if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS))
- return 0;
+ _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0);
return _irq_handlers[irq];
}
void *DMACallback(DMA_Channel dma, void (*func)(void)) {
- if ((dma < 0) || (dma >= NUM_DMA_CHANNELS))
- return 0;
+ _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0);
void *old_callback = _dma_handlers[dma];
_dma_handlers[dma] = func;
@@ -151,12 +149,34 @@ void *DMACallback(DMA_Channel dma, void (*func)(void)) {
}
void *GetDMACallback(DMA_Channel dma) {
- if ((dma < 0) || (dma >= NUM_DMA_CHANNELS))
- return 0;
+ _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0);
return _dma_handlers[dma];
}
+/* DMA channel priority API */
+
+int SetDMAPriority(DMA_Channel dma, int priority) {
+ _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1);
+
+ uint32_t dpcr = DMA_DPCR;
+ uint32_t channel = dpcr >> (dma * 4);
+
+ dpcr &= ~(0xf << (dma * 4));
+ if (priority >= 0)
+ dpcr |= ((priority & 7) | 8) << (dma * 4);
+
+ DMA_DPCR = dpcr;
+ return (channel & 8) ? (channel & 7) : -1;
+}
+
+int GetDMAPriority(DMA_Channel dma) {
+ _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1);
+
+ uint32_t channel = DMA_DPCR >> (dma * 4);
+ return (channel & 8) ? (channel & 7) : -1;
+}
+
/* Hook installation/removal API */
int ResetCallback(void) {
@@ -190,7 +210,7 @@ void RestartCallback(void) {
// Install the ISR hook and prevent the kernel's internal handlers from
// automatically acknowledging SPI and timer IRQs.
- SetCustomExitFromException(&_isr_jmp_buf);
+ HookEntryInt(&_isr_jmp_buf);
ChangeClearPAD(0);
ChangeClearRCnt(0, 0);
ChangeClearRCnt(1, 0);
@@ -217,7 +237,7 @@ void StopCallback(void) {
DMA_DPCR = _saved_dma_dpcr & 0x07777777;
DMA_DICR = 0;
- SetDefaultExitFromException();
+ ResetEntryInt();
ChangeClearPAD(1);
ChangeClearRCnt(0, 1);
ChangeClearRCnt(1, 1);