Skip to content

Commit 89b9d8c

Browse files
committed
cleanup: use macro for gp register get/set
1 parent 57d60f4 commit 89b9d8c

5 files changed

Lines changed: 18 additions & 17 deletions

File tree

iop/kernel/include/defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ extern "C" {
2626
#define NULL ((void *)0)
2727
#endif
2828

29+
#ifndef ALIGN
2930
#define ALIGN(x, align) (((x)+((align)-1))&~((align)-1))
31+
#endif
3032

3133
#define PHYSADDR(a) (((u32)(a)) & 0x1fffffff)
3234

iop/system/loadcore/src/loadcore.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "irx_imports.h"
1313
#include "kerr.h"
1414
#include "xloadcore.h"
15+
#include <defs.h>
1516

1617
extern struct irx_export_table _exp_loadcore;
1718

@@ -432,7 +433,7 @@ void loadcore_init(boot_params *in_params)
432433
next.callback = (void *)*stack_reboot_handlers;
433434
if ( i == 3 )
434435
next.callback = (void *)*reboot_handler_ptr;
435-
__asm__ __volatile__("\tmove $gp, %0\n" : : "r"(reboot_handler_ptr[1]));
436+
SetGP((void *)reboot_handler_ptr[1]);
436437
((BootupCallback_t)(*reboot_handler_ptr & (~3)))(&next, 1);
437438
}
438439
reboot_handler_ptr += 2;
@@ -565,12 +566,11 @@ int *QueryBootMode(int mode)
565566

566567
int AddRebootNotifyHandler(BootupCallback_t func, int priority, int *stat)
567568
{
568-
u32 gp_val;
569+
void *gp_val;
569570
iop_init_entry_t next;
570571

571572
next.callback = (void *)1;
572-
gp_val = 0;
573-
__asm__ __volatile__("\tmove %0, $gp\n" : "=r"(gp_val) :);
573+
gp_val = GetGP();
574574

575575
if ( !reboot_handlers )
576576
{
@@ -583,7 +583,7 @@ int AddRebootNotifyHandler(BootupCallback_t func, int priority, int *stat)
583583
}
584584

585585
reboot_handlers[0] = (u32)func + (priority & 3);
586-
reboot_handlers[1] = gp_val;
586+
reboot_handlers[1] = (u32)gp_val;
587587
reboot_handlers += 2;
588588
reboot_handlers[0] = 0;
589589
return 1;

iop/system/threadman/src/include/thcommon.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#define HANDLE_VERIFY(handle, t) (((struct heaptag *)(HANDLE_PTR(handle)))->tag == (t) && \
2525
HANDLE_ID(handle) == ((struct heaptag *)(HANDLE_PTR(handle)))->id)
2626

27+
#ifdef ALIGN
28+
#undef ALIGN
29+
#endif
2730
#define ALIGN(i) (((i) + 3) & (~3))
2831
#define ALIGN_256(i) (((i) + 0xff) & (~0xff))
2932

@@ -164,7 +167,7 @@ struct thread
164167
void *entry;
165168
void *stack_top;
166169
u32 stack_size;
167-
u32 gp;
170+
void *gp;
168171
u32 attr;
169172
u32 option;
170173
// nothing seems to use wait_return, would be $ra

iop/system/threadman/src/thbase.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "thsemap.h"
88
#include "xthbase.h"
99
#include "xtimrman.h"
10+
#include <defs.h>
1011

1112
#include "thcommon.h"
1213

@@ -73,9 +74,7 @@ int CreateThread(iop_thread_t *thparam)
7374
thread->attr = thparam->attr;
7475
thread->option = thparam->option;
7576
thread->status = THS_DORMANT;
76-
77-
__asm__ __volatile__("sw $gp, %0\n"
78-
: "=m"(thread->gp)::);
77+
thread->gp = GetGP();
7978

8079
list_insert(&thctx.thread_list, &thread->thread_list);
8180

iop/system/threadman/src/thcommon.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "loadcore.h"
99
#include "sysclib.h"
1010
#include "stdio.h"
11+
#include <defs.h>
1112

1213
#include <limits.h>
1314

@@ -205,7 +206,7 @@ int thread_init_and_start(struct thread *thread, int intr_state)
205206
thread->saved_regs->sp = (u32)&thread->saved_regs[1];
206207
thread->saved_regs->fp = thread->saved_regs->sp;
207208
thread->saved_regs->ra = (u32)ExitThread;
208-
thread->saved_regs->gp = thread->gp;
209+
thread->saved_regs->gp = (u32)thread->gp;
209210
thread->saved_regs->sr = 0x404;
210211
thread->saved_regs->sr |= thread->attr & 8;
211212
thread->saved_regs->pc = (u32)thread->entry;
@@ -650,13 +651,11 @@ int _start(int argc, char **argv)
650651
idle->entry = idle_thread;
651652
idle->saved_regs = idle->stack_top + (((idle->stack_size << 2) >> 2) - RESERVED_REGCTX_SIZE);
652653
memset(idle->saved_regs, 0, RESERVED_REGCTX_SIZE);
653-
654-
__asm__ __volatile__("sw $gp, %0\n"
655-
: "=m"(idle->gp)::);
654+
idle->gp = GetGP();
656655

657656
idle->saved_regs->unk = -2;
658657
idle->saved_regs->sp = (u32)&idle->saved_regs[1];
659-
idle->saved_regs->gp = idle->gp;
658+
idle->saved_regs->gp = (u32)idle->gp;
660659
idle->saved_regs->fp = idle->saved_regs->sp;
661660
idle->saved_regs->ra = (u32)ExitThread;
662661
idle->saved_regs->sr = (idle->attr & 0xF0000000) | 0x404;
@@ -679,9 +678,7 @@ int _start(int argc, char **argv)
679678
current->priority = 1;
680679
current->attr = TH_C;
681680
current->status = THS_RUN;
682-
683-
__asm__ __volatile__("sw $gp, %0\n"
684-
: "=m"(current->gp)::);
681+
current->gp = GetGP();
685682

686683
list_insert(&thctx.thread_list, &current->thread_list);
687684
thctx.current_thread = current;

0 commit comments

Comments
 (0)