Skip to content

Commit ed95521

Browse files
authored
Merge pull request #723 from uyjulian/rtc_timezone_link_if_used
Link timer, timezone, and RTC functions only if they are used
2 parents 16cae0e + 9241d6f commit ed95521

File tree

10 files changed

+105
-16
lines changed

10 files changed

+105
-16
lines changed

ee/kernel/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ EXIT_OBJS += _exit_internals.o SetArg.o Exit.o ExecPS2.o LoadExecPS2.o ExecOSD.o
125125

126126
TIMER_OBJS = \
127127
timer_data.o \
128+
_ps2sdk_init_timer.o \
129+
_ps2sdk_deinit_timer.o \
128130
SetT2.o \
129131
SetT2_COUNT.o \
130132
SetT2_MODE.o \

ee/kernel/include/kernel.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,8 @@ extern void *GetEntryAddress(int syscall);
575575
void ExecOSD(int num_args, char *args[]) { _ExecOSD(num_args, args); }
576576

577577
#define DISABLE_TimerSystemTime() \
578-
s32 InitTimer(s32 in_mode) {(void)in_mode; return 0;} \
579-
s32 EndTimer(void) {return 0;} \
580-
s32 StartTimerSystemTime(void) {return 0;} \
581-
s32 StopTimerSystemTime(void) {return 0;}
578+
void _ps2sdk_init_timer() {} \
579+
void _ps2sdk_deinit_timer() {}
582580

583581
#define DISABLE_TimerAlarm() \
584582
void ForTimer_InitAlarm(void) {}

ee/kernel/include/timer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ typedef u64 (*timer_alarm_handler_t)(s32 id, u64 scheduled_time, u64 actual_time
6666
extern "C" {
6767
#endif
6868

69+
extern void _ps2sdk_init_timer_impl(void);
70+
extern void _ps2sdk_init_timer(void);
71+
extern void _ps2sdk_deinit_timer_impl(void);
72+
extern void _ps2sdk_deinit_timer(void);
73+
6974
extern s32 InitTimer(s32 in_mode);
7075
extern s32 EndTimer(void);
7176
extern s32 GetTimerPreScaleFactor(void);

ee/kernel/src/initsys.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
void _InitSys(void)
2222
{
2323
InitAlarm();
24-
InitTimer(2);
25-
StartTimerSystemTime();
24+
_ps2sdk_init_timer();
2625
InitThread();
2726
InitExecPS2();
2827
InitTLBFunctions();
@@ -32,8 +31,7 @@ void _InitSys(void)
3231
#ifdef F_TerminateLibrary
3332
void TerminateLibrary(void)
3433
{
35-
StopTimerSystemTime();
36-
EndTimer();
34+
_ps2sdk_deinit_timer();
3735
InitTLB();
3836
}
3937
#endif

ee/kernel/src/timer.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ extern timer_ee_global_struct g_Timer;
7979
extern counter_struct_t g_CounterBuf[COUNTER_COUNT] __attribute__((aligned(64)));
8080
#endif
8181

82+
#ifdef F__ps2sdk_init_timer
83+
void __attribute__((weak)) _ps2sdk_init_timer_impl(void);
84+
__attribute__((weak)) void _ps2sdk_init_timer(void)
85+
{
86+
// cppcheck-suppress knownConditionTrueFalse
87+
if (&_ps2sdk_init_timer_impl)
88+
{
89+
_ps2sdk_init_timer_impl();
90+
}
91+
}
92+
#endif
93+
94+
#ifdef F__ps2sdk_deinit_timer
95+
void __attribute__((weak)) _ps2sdk_deinit_timer_impl(void);
96+
__attribute__((weak)) void _ps2sdk_deinit_timer(void)
97+
{
98+
// cppcheck-suppress knownConditionTrueFalse
99+
if (&_ps2sdk_deinit_timer_impl)
100+
{
101+
_ps2sdk_deinit_timer_impl();
102+
}
103+
}
104+
#endif
105+
82106
#ifdef F_SetT2
83107
void SetT2(volatile void *ptr, u32 val)
84108
{
@@ -478,6 +502,18 @@ u64 iGetTimerSystemTime(void)
478502
timer_system_time_now = timer_system_time_now << ((mode & 3) << 2);
479503
return timer_system_time_now;
480504
}
505+
506+
void _ps2sdk_init_timer_impl(void)
507+
{
508+
InitTimer(2);
509+
StartTimerSystemTime();
510+
}
511+
512+
void _ps2sdk_deinit_timer_impl(void)
513+
{
514+
StopTimerSystemTime();
515+
EndTimer();
516+
}
481517
#endif
482518

483519
#ifdef F_GetTimerSystemTime

ee/libcglue/Makefile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@
88

99
EE_LIB = libcglue.a
1010

11-
CORE_OBJS = rtc.o
11+
RTC_OBJS = \
12+
_libcglue_rtc_data.o \
13+
_libcglue_rtc_get_offset_from_busclk.o \
14+
_libcglue_rtc_update.o
1215

13-
TIMEZONE_OBJS = _libcglue_timezone_update.o ps2sdk_setTimezone.o ps2sdk_setDaylightSaving.o
16+
TIMEZONE_OBJS = \
17+
_libcglue_timezone_update_impl.o \
18+
_libcglue_timezone_update.o \
19+
ps2sdk_setTimezone.o \
20+
ps2sdk_setDaylightSaving.o
1421

1522
FDMAN_OBJS = \
1623
__fdman_sema.o \
@@ -229,6 +236,7 @@ SOCKET_OBJS = \
229236

230237
EE_OBJS = \
231238
$(CORE_OBJS) \
239+
$(RTC_OBJS) \
232240
$(TIMEZONE_OBJS) \
233241
$(SJIS_OBJS) \
234242
$(TIME_OBJS) \
@@ -249,6 +257,10 @@ include $(PS2SDKSRC)/ee/Rules.lib.make
249257
include $(PS2SDKSRC)/ee/Rules.make
250258
include $(PS2SDKSRC)/ee/Rules.release
251259

260+
$(RTC_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)rtc.c
261+
$(DIR_GUARD)
262+
$(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@
263+
252264
$(TIMEZONE_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)timezone.c
253265
$(DIR_GUARD)
254266
$(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@

ee/libcglue/include/ps2sdkapi.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static inline ps2_clock_t ps2_clock(void) {
175175
}
176176

177177
extern s64 _ps2sdk_rtc_offset_from_busclk;
178+
s64 _libcglue_rtc_get_offset_from_busclk(void);
179+
extern void _libcglue_rtc_update_impl();
178180
extern void _libcglue_rtc_update();
179181

180182
// The newlib port does not support 64bit
@@ -183,6 +185,7 @@ typedef int64_t off64_t;
183185
extern off64_t lseek64(int fd, off64_t offset, int whence);
184186

185187
// Functions to be used related to timezone
188+
extern void _libcglue_timezone_update_impl();
186189
extern void _libcglue_timezone_update();
187190

188191
extern void ps2sdk_setTimezone(int timezone);

ee/libcglue/src/glue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ int _gettimeofday(struct timeval *tv, struct timezone *tz)
788788
u32 busclock_usec;
789789

790790
TimerBusClock2USec(GetTimerSystemTime(), &busclock_sec, &busclock_usec);
791-
tv->tv_sec = (time_t)(_ps2sdk_rtc_offset_from_busclk + ((s64)busclock_sec));
791+
tv->tv_sec = (time_t)(_libcglue_rtc_get_offset_from_busclk() + ((s64)busclock_sec));
792792
tv->tv_usec = busclock_usec;
793793
}
794794

ee/libcglue/src/rtc.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@
2424
// The definition for this function is located in ee/rpc/cdvd/src/scmd.c
2525
extern time_t ps2time(time_t *t);
2626

27+
#ifdef F__libcglue_rtc_data
2728
s64 _ps2sdk_rtc_offset_from_busclk = 0;
29+
#endif
2830

29-
__attribute__((weak))
30-
void _libcglue_rtc_update()
31+
#ifdef F__libcglue_rtc_get_offset_from_busclk
32+
s64 _libcglue_rtc_get_offset_from_busclk(void)
33+
{
34+
return _ps2sdk_rtc_offset_from_busclk;
35+
}
36+
37+
void _libcglue_rtc_update_impl()
3138
{
3239
time_t rtc_sec;
3340
u32 busclock_sec;
@@ -38,3 +45,17 @@ void _libcglue_rtc_update()
3845

3946
_ps2sdk_rtc_offset_from_busclk = ((s64)rtc_sec) - ((s64)busclock_sec);
4047
}
48+
#endif
49+
50+
#ifdef F__libcglue_rtc_update
51+
void __attribute__((weak)) _libcglue_rtc_update_impl();
52+
__attribute__((weak))
53+
void _libcglue_rtc_update()
54+
{
55+
// cppcheck-suppress knownConditionTrueFalse
56+
if (&_libcglue_rtc_update_impl)
57+
{
58+
_libcglue_rtc_update_impl();
59+
}
60+
}
61+
#endif

ee/libcglue/src/timezone.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
#include <stdlib.h>
1919
#include <unistd.h>
2020
#include <fcntl.h>
21+
#include <reent.h>
2122

2223
#include <ps2sdkapi.h>
2324
#define OSD_CONFIG_NO_LIBCDVD
2425
#include "osd_config.h"
2526

2627
#define posixIODriver { open, close, (int (*)(int, void *, int))read, O_RDONLY }
2728

28-
#ifdef F__libcglue_timezone_update
29-
__attribute__((weak))
30-
void _libcglue_timezone_update()
29+
#ifdef F__libcglue_timezone_update_impl
30+
void _libcglue_timezone_update_impl()
3131
{
3232
/* Initialize timezone from PS2 OSD configuration */
3333
_io_driver driver = posixIODriver;
@@ -45,6 +45,20 @@ void _libcglue_timezone_update()
4545
}
4646
#endif
4747

48+
#ifdef F__libcglue_timezone_update
49+
// Defined in newlib: newlib/libc/time/tzset_r.c
50+
void __attribute((weak)) _tzset_unlocked_r(struct _reent *reent_ptr);
51+
__attribute__((weak))
52+
void _libcglue_timezone_update()
53+
{
54+
// cppcheck-suppress knownConditionTrueFalse
55+
if (&_tzset_unlocked_r)
56+
{
57+
_libcglue_timezone_update_impl();
58+
}
59+
}
60+
#endif
61+
4862
#ifdef F_ps2sdk_setTimezone
4963
void ps2sdk_setTimezone(int timezone) {
5064
_io_driver driver = posixIODriver;

0 commit comments

Comments
 (0)