Skip to content

Commit

Permalink
Add AT_ADDRESS macro
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Jul 12, 2024
1 parent 33c6922 commit 1cd3788
Show file tree
Hide file tree
Showing 24 changed files with 85 additions and 50 deletions.
5 changes: 3 additions & 2 deletions include/dolphin/dsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

#include "dolphin/os/OS.h"
#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

volatile u16 __DSPRegs[32] : 0xCC005000;
volatile u32 __AIRegs[8] : 0xCC006C00;
volatile u16 __DSPRegs[32] AT_ADDRESS(0xCC005000);
volatile u32 __AIRegs[8] AT_ADDRESS(0xCC006C00);

#ifdef __cplusplus
extern "C" {
Expand Down
3 changes: 2 additions & 1 deletion include/dolphin/dvd/dvdlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#define DVDLOW_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

typedef void (*DVDLowCallback)(u32 intType);
vu32 __DIRegs[16] : 0xCC006000;
vu32 __DIRegs[16] AT_ADDRESS(0xCC006000);

#endif /* DVDLOW_H */
3 changes: 2 additions & 1 deletion include/dolphin/exi/EXIBios.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#define EXIBIOS_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct OSContext OSContext;

vu32 __EXIRegs[16] : 0xCC006800;
vu32 __EXIRegs[16] AT_ADDRESS(0xCC006800);

#define EXI_MEMORY_CARD_59 0x00000004
#define EXI_MEMORY_CARD_123 0x00000008
Expand Down
3 changes: 2 additions & 1 deletion include/dolphin/gx/GX.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "dolphin/gx/GXTev.h"
#include "dolphin/gx/GXTexture.h"
#include "dolphin/gx/GXTransform.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -41,7 +42,7 @@ typedef union {
f64 f64;
} PPCWGPipe;

volatile PPCWGPipe GXFIFO : 0xCC008000;
volatile PPCWGPipe GXFIFO AT_ADDRESS(0xCC008000);

// Direct
inline void GXPosition2f32(f32 x, f32 z) {
Expand Down
23 changes: 12 additions & 11 deletions include/dolphin/os/OS.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "dolphin/os/OSSync.h"
#include "dolphin/os/OSThread.h"
#include "dolphin/os/OSTime.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -59,19 +60,19 @@ extern "C" {
#define OS_CONSOLE_PC_EMULATOR 0x10000001
#define OS_CONSOLE_EMULATOR 0x10000000

volatile u16 __OSDeviceCode : 0x800030E6;
volatile u16 __OSDeviceCode AT_ADDRESS(0x800030E6);

volatile u32 OS_PI_INTR_CAUSE : 0xCC003000;
volatile u32 OS_PI_INTR_MASK : 0xCC003004;
volatile u32 OS_PI_INTR_CAUSE AT_ADDRESS(0xCC003000);
volatile u32 OS_PI_INTR_MASK AT_ADDRESS(0xCC003004);

volatile u16 OS_MI_INTR_MASK : 0xCC00401C;
volatile u16 OS_MI_INTR_MASK AT_ADDRESS(0xCC00401C);

volatile u16 OS_DSP_DMA_ADDR_HI : 0xCC005030;
volatile u16 OS_DSP_DMA_ADDR_LO : 0xCC005032;
volatile u16 OS_DSP_INTR_MASK : 0xCC00500A;
volatile u16 OS_DSP_DMA_ADDR_HI AT_ADDRESS(0xCC005030);
volatile u16 OS_DSP_DMA_ADDR_LO AT_ADDRESS(0xCC005032);
volatile u16 OS_DSP_INTR_MASK AT_ADDRESS(0xCC00500A);

volatile u16 OS_ARAM_DMA_ADDR_HI : 0xCC005020;
volatile u16 OS_ARAM_DMA_ADDR_LO : 0xCC005022;
volatile u16 OS_ARAM_DMA_ADDR_HI AT_ADDRESS(0xCC005020);
volatile u16 OS_ARAM_DMA_ADDR_LO AT_ADDRESS(0xCC005022);

BOOL OSIsThreadSuspended(OSThread* thread);

Expand All @@ -89,8 +90,8 @@ extern u8 __OSReport_enable;

extern BOOL __OSIsGcam;

extern u32 BOOT_REGION_START : 0x812FDFF0;
extern u32 BOOT_REGION_END : 0x812FDFEC;
extern u32 BOOT_REGION_START AT_ADDRESS(0x812FDFF0);
extern u32 BOOT_REGION_END AT_ADDRESS(0x812FDFEC);

void OSReportInit__Fv(void); // needed for inline asm

Expand Down
5 changes: 3 additions & 2 deletions include/dolphin/os/OSContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OSCONTEXT_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -151,8 +152,8 @@ typedef struct OSContext {
/* 0x1C4 */ f64 ps[32];
} OSContext;

OSContext* OS_CURRENT_CONTEXT : 0x800000D4;
OSContext* OS_CURRENT_FPU_CONTEXT : 0x800000D8;
OSContext* OS_CURRENT_CONTEXT AT_ADDRESS(0x800000D4);
OSContext* OS_CURRENT_FPU_CONTEXT AT_ADDRESS(0x800000D8);

void __OSLoadFPUContext(void);
void __OSSaveFPUContext(s32 unused0, s32 unused1, OSContext* context);
Expand Down
5 changes: 3 additions & 2 deletions include/dolphin/os/OSLink.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef OSLINK_H
#define OSLINK_H

#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -18,8 +19,8 @@ typedef struct OSSectionInfo OSSectionInfo;
typedef struct OSImportInfo OSImportInfo;
typedef struct OSRel OSRel;

OSModuleQueue __OSModuleList : 0x800030C8;
void* __OSStringTable : 0x800030D0;
OSModuleQueue __OSModuleList AT_ADDRESS(0x800030C8);
void* __OSStringTable AT_ADDRESS(0x800030D0);

struct OSModuleQueue {
OSModuleInfo* head;
Expand Down
3 changes: 2 additions & 1 deletion include/dolphin/os/OSReset.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#define OSRESET_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
#endif

vu32 __PIRegs[12] : 0xCC003000;
vu32 __PIRegs[12] AT_ADDRESS(0xCC003000);

#define OS_RESETCODE_RESTART 0x80000000
#define OS_RESETCODE_SYSTEM 0x40000000
Expand Down
5 changes: 3 additions & 2 deletions include/dolphin/os/OSThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OSTHREAD_H

#include "dolphin/os/OSContext.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -75,8 +76,8 @@ struct OSThread {

typedef void (*OSSwitchThreadCallback)(OSThread* from, OSThread* to);

OSThreadQueue OS_THREAD_QUEUE : 0x800000DC;
OSThread* OS_CURRENT_THREAD : 0x800000E4;
OSThreadQueue OS_THREAD_QUEUE AT_ADDRESS(0x800000DC);
OSThread* OS_CURRENT_THREAD AT_ADDRESS(0x800000E4);

static void DefaultSwitchThreadCallback(OSThread* from, OSThread* to);
OSSwitchThreadCallback OSSetSwitchThreadCallback(OSSwitchThreadCallback func);
Expand Down
5 changes: 3 additions & 2 deletions include/dolphin/os/OSTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OSTIME_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -10,7 +11,7 @@ extern "C" {
typedef s64 OSTime;
typedef u32 OSTick;

OSTime OS_SYSTEM_TIME : 0x800030D8;
OSTime OS_SYSTEM_TIME AT_ADDRESS(0x800030D8);

typedef struct OSCalendarTime {
/* 0x00 */ s32 seconds;
Expand All @@ -32,7 +33,7 @@ OSTime __OSTimeToSystemTime(OSTime time);
void GetDates(s32 days, OSCalendarTime* ct);
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* ct);

extern u32 __OSBusClock : 0x800000F8;
extern u32 __OSBusClock AT_ADDRESS(0x800000F8);

#define OS_BUS_CLOCK (__OSBusClock)
#define OS_CORE_CLOCK (*(u32*)0x800000FC)
Expand Down
21 changes: 21 additions & 0 deletions include/dolphin/os/OSUtil.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _DOLPHIN_OS_OSUTIL_H
#define _DOLPHIN_OS_OSUTIL_H

#include "dolphin/types.h"

#ifdef __cplusplus
extern "C" {
#endif // ifdef __cplusplus

// Macro to make it more clear when something is an address, and to prevent intellisense errors.
#ifdef __MWERKS__
#define AT_ADDRESS(addr) : (addr)
#else
#define AT_ADDRESS(addr)
#endif

#ifdef __cplusplus
};
#endif // ifdef __cplusplus

#endif
3 changes: 2 additions & 1 deletion include/dolphin/os/__start.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __START_H

#include "global.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -21,7 +22,7 @@ extern "C" {

extern void InitMetroTRK();

u16 Pad3Button : PAD3_BUTTON_ADDR;
u16 Pad3Button AT_ADDRESS(PAD3_BUTTON_ADDR);

extern int main(int argc, char* argv[]);
extern void exit(int);
Expand Down
3 changes: 2 additions & 1 deletion include/dolphin/si/SIBios.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "dolphin/os/OSInterrupt.h"
#include "dolphin/os/OSTime.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -121,7 +122,7 @@ u32 SIGetType(s32 chan);
u32 SIGetTypeAsync(s32 chan, SITypeAndStatusCallback callback);
u32 SIProbe(s32 chan);

vu32 __SIRegs[64] : 0xCC006400;
vu32 __SIRegs[64] AT_ADDRESS(0xCC006400);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion include/dolphin/vi/vi.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define VI_H

#include "dolphin/types.h"
#include "dolphin/os/OSUtil.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -54,7 +55,7 @@ void VISetBlack(BOOL);
u32 VIGetRetraceCount();
u32 VIGetDTVStatus();

vu16 __VIRegs[59] : 0xCC002000;
vu16 __VIRegs[59] AT_ADDRESS(0xCC002000);

#ifdef __cplusplus
};
Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/os/OS.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ asm void __OSPSInit(void){
// clang-format on
}

vu32 __DIRegs[16] : 0xCC006000;
vu32 __DIRegs[16] AT_ADDRESS(0xCC006000);
#define DI_CONFIG_IDX 0x9
#define DI_CONFIG_CONFIG_MASK 0xFF

Expand Down
5 changes: 3 additions & 2 deletions src/dolphin/os/OSContext.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "dolphin/os/OSContext.h"
#include "dolphin/db/db.h"
#include "dolphin/os/OS.h"
#include "dolphin/os/OSUtil.h"

volatile OSContext* __OSCurrentContext : (OS_BASE_CACHED | 0x00D4);
volatile OSContext* __OSFPUContext : (OS_BASE_CACHED | 0x00D8);
volatile OSContext* __OSCurrentContext AT_ADDRESS(OS_BASE_CACHED | 0x00D4);
volatile OSContext* __OSFPUContext AT_ADDRESS(OS_BASE_CACHED | 0x00D8);

asm void __OSLoadFPUContext(void) {
// clang-format off
Expand Down
6 changes: 3 additions & 3 deletions src/dolphin/os/OSError.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "dolphin/dvd/dvdlow.h"
#include "dolphin/os/OS.h"

OSThread* __OSCurrentThread : (OS_BASE_CACHED | 0x00E4);
OSThreadQueue __OSActiveThreadQueue : (OS_BASE_CACHED | 0x00DC);
volatile OSContext* __OSFPUContext : (OS_BASE_CACHED | 0x00D8);
OSThread* __OSCurrentThread AT_ADDRESS(OS_BASE_CACHED | 0x00E4);
OSThreadQueue __OSActiveThreadQueue AT_ADDRESS(OS_BASE_CACHED | 0x00DC);
volatile OSContext* __OSFPUContext AT_ADDRESS(OS_BASE_CACHED | 0x00D8);

extern volatile u32 __OSLastInterruptSrr0;
extern volatile s16 __OSLastInterrupt;
Expand Down
4 changes: 2 additions & 2 deletions src/dolphin/os/OSInterrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "dolphin/exi/EXIBios.h"
#include "dolphin/os/OS.h"

vu32 __PIRegs[12] : 0xCC003000;
vu16 __MEMRegs[64] : 0xCC004000;
vu32 __PIRegs[12] AT_ADDRESS(0xCC003000);
vu16 __MEMRegs[64] AT_ADDRESS(0xCC004000);

asm BOOL OSDisableInterrupts(void) {
// clang-format off
Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/os/OSLink.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
__prev->link.next = __next; \
} while (0)

OSModuleQueue __OSModuleInfoList : (OS_BASE_CACHED | 0x30C8);
OSModuleQueue __OSModuleInfoList AT_ADDRESS(OS_BASE_CACHED | 0x30C8);

#pragma dont_inline on

Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/os/OSMemory.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define TRUNC(n, a) (((u32)(n)) & ~((a)-1))
#define ROUND(n, a) (((u32)(n) + (a)-1) & ~((a)-1))

vu16 __MEMRegs[64] : 0xCC004000;
vu16 __MEMRegs[64] AT_ADDRESS(0xCC004000);

extern OSErrorHandlerEx __OSErrorTable[16];

Expand Down
10 changes: 5 additions & 5 deletions src/dolphin/os/OSReboot.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "dolphin/os/Os.h"
#include "dolphin/os/OS.h"
#include "dolphin/os/OSReboot.h"

static void* SaveStart = NULL;
static void* SaveEnd = NULL;
static volatile BOOL Prepared;

extern u32 OS_RESET_CODE : 0x800030F0;
extern u8 OS_REBOOT_BOOL : 0x800030E2; // unknown function, set to true by __OSReboot
extern u32 UNK_817FFFF8 : 0x817FFFF8;
extern u32 UNK_817FFFFC : 0x817FFFFC;
extern u32 OS_RESET_CODE AT_ADDRESS(0x800030F0);
extern u8 OS_REBOOT_BOOL AT_ADDRESS(0x800030E2); // unknown function, set to true by __OSReboot
extern u32 UNK_817FFFF8 AT_ADDRESS(0x817FFFF8);
extern u32 UNK_817FFFFC AT_ADDRESS(0x817FFFFC);

#define OS_BOOTROM_ADDR 0x81300000

Expand Down
4 changes: 2 additions & 2 deletions src/dolphin/os/OSReset.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "dolphin/os/OSReset.h"
#include "dolphin/os/OS.h"

vu16 __VIRegs[59] : 0xCC002000;
OSThreadQueue __OSActiveThreadQueue : (OS_BASE_CACHED | 0x00DC);
vu16 __VIRegs[59] AT_ADDRESS(0xCC002000);
OSThreadQueue __OSActiveThreadQueue AT_ADDRESS(OS_BASE_CACHED | 0x00DC);

static OSResetQueue ResetFunctionQueue;

Expand Down
2 changes: 1 addition & 1 deletion src/dolphin/os/OSResetSW.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "dolphin/os/OS.h"
#include "dolphin/os/OSReset.h"

u8 GameChoice : (OS_BASE_CACHED | 0x30E3);
u8 GameChoice AT_ADDRESS(OS_BASE_CACHED | 0x30E3);

void __OSResetSWInterruptHandler(__OSInterrupt interrupt, OSContext* context);

Expand Down
8 changes: 4 additions & 4 deletions src/dolphin/os/OSThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include "dolphin/os/OSThread.h"
#include "dolphin/os/OS.h"

OSThread* __OSCurrentThread : OS_BASE_CACHED + 0x00E4;
OSThreadQueue __OSActiveThreadQueue : OS_BASE_CACHED + 0x00DC;
volatile OSContext __OSCurrentContext : OS_BASE_CACHED + 0x00D4;
volatile OSContext* __OSFPUContext : OS_BASE_CACHED + 0x00D8;
OSThread* __OSCurrentThread AT_ADDRESS(OS_BASE_CACHED + 0x00E4);
OSThreadQueue __OSActiveThreadQueue AT_ADDRESS(OS_BASE_CACHED + 0x00DC);
volatile OSContext __OSCurrentContext AT_ADDRESS(OS_BASE_CACHED + 0x00D4);
volatile OSContext* __OSFPUContext AT_ADDRESS(OS_BASE_CACHED + 0x00D8);

#define AddTail(queue, thread, link) \
do { \
Expand Down

0 comments on commit 1cd3788

Please sign in to comment.