Skip to content

Commit 9268738

Browse files
committed
rtcfx_exclude property is read as string from RTC provider's properties
1 parent 58cc42f commit 9268738

File tree

3 files changed

+90
-62
lines changed

3 files changed

+90
-62
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ RTCMemoryFixup Changelog
33
#### v1.0.3
44
- Fixed compiling and loading on older OS
55
- Fixed loading from /Library/Extensions
6+
- rtcfx_exclude property is read as string from RTC provider's properties
67

78
#### v1.0.2
89
- Wrong range start value in debug message has been fixed (thanks to nms42)

RTCMemoryFixup/RTCMemoryFixup.cpp

Lines changed: 88 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -78,71 +78,12 @@ bool RTCMemoryFixup::init(OSDictionary *propTable)
7878
return false;
7979
}
8080

81-
char rtcfx_exclude[200] {};
81+
char rtcfx_exclude[512] {};
8282
if (PE_parse_boot_argn("rtcfx_exclude", rtcfx_exclude, sizeof(rtcfx_exclude)))
8383
{
84-
DBGLOG("RTCFX", "boot-arg rtcfx_exclude specified, value = %s", rtcfx_exclude);
85-
86-
char *tok = rtcfx_exclude, *end = rtcfx_exclude;
87-
char *dash = nullptr;
88-
while (tok != nullptr)
89-
{
90-
strsep(&end, ",");
91-
DBGLOG("RTCFX", "rtc offset token = %s", tok);
92-
if ((dash = strchr(tok, '-')) == nullptr)
93-
{
94-
unsigned int offset = RTC_SIZE;
95-
if (sscanf(tok, "%02X", &offset) != 1)
96-
break;
97-
if (offset >= RTC_SIZE)
98-
{
99-
DBGLOG("RTCFX", "rtc offset %02X is not valid", offset);
100-
break;
101-
}
102-
emulated_flag[offset] = true;
103-
DBGLOG("RTCFX", "rtc offset %02X is marked as emulated", offset);
104-
}
105-
else
106-
{
107-
unsigned int soffset = RTC_SIZE, eoffset = RTC_SIZE;
108-
char *rstart = tok, *rend = dash+1;
109-
*dash = '\0';
110-
if (sscanf(rstart, "%02X", &soffset) == 1 && sscanf(rend, "%02X", &eoffset) == 1)
111-
{
112-
if (soffset >= RTC_SIZE)
113-
{
114-
DBGLOG("RTCFX", "rtc start offset %02X is not valid", soffset);
115-
break;
116-
}
117-
118-
if (eoffset >= RTC_SIZE)
119-
{
120-
DBGLOG("RTCFX", "rtc end offset %02X is not valid", eoffset);
121-
break;
122-
}
123-
124-
if (soffset >= eoffset)
125-
{
126-
DBGLOG("RTCFX", "rtc start offset %02X must be less than end offset %02X", soffset, eoffset);
127-
break;
128-
}
129-
130-
for (unsigned int i = soffset; i <= eoffset; ++i)
131-
emulated_flag[i] = true;
132-
DBGLOG("RTCFX", "rtc range from offset %02X to offset %02X is marked as emulated", soffset, eoffset);
133-
}
134-
else
135-
{
136-
DBGLOG("RTCFX", "boot-arg rtcfx_exclude can't be parsed properly");
137-
break;
138-
}
139-
}
140-
141-
tok = end;
142-
}
84+
DBGLOG("RTCFX", "boot-arg rtcfx_exclude specified, value = %s", rtcfx_exclude);
85+
excludeAddresses(rtcfx_exclude);
14386
}
144-
else
145-
DBGLOG("RTCFX", "boot-arg rtcfx_exclude is not specified, RTCMemoryFixup is in test mode");
14687

14788
return true;
14889
}
@@ -280,8 +221,93 @@ void RTCMemoryFixup::ioWrite8(IOService * that, UInt16 offset, UInt8 value, IOMe
280221

281222
//==============================================================================
282223

224+
void RTCMemoryFixup::excludeAddresses(char* rtcfx_exclude)
225+
{
226+
memset(emulated_rtc_mem, 0, sizeof(emulated_rtc_mem));
227+
memset(emulated_flag, 0, sizeof(emulated_flag));
228+
229+
char *tok = rtcfx_exclude, *end = rtcfx_exclude;
230+
char *dash = nullptr;
231+
while (tok != nullptr)
232+
{
233+
strsep(&end, ",");
234+
DBGLOG("RTCFX", "rtc offset token = %s", tok);
235+
if ((dash = strchr(tok, '-')) == nullptr)
236+
{
237+
unsigned int offset = RTC_SIZE;
238+
if (sscanf(tok, "%02X", &offset) != 1)
239+
break;
240+
if (offset >= RTC_SIZE)
241+
{
242+
DBGLOG("RTCFX", "rtc offset %02X is not valid", offset);
243+
break;
244+
}
245+
emulated_flag[offset] = true;
246+
DBGLOG("RTCFX", "rtc offset %02X is marked as emulated", offset);
247+
}
248+
else
249+
{
250+
unsigned int soffset = RTC_SIZE, eoffset = RTC_SIZE;
251+
char *rstart = tok, *rend = dash+1;
252+
*dash = '\0';
253+
if (sscanf(rstart, "%02X", &soffset) == 1 && sscanf(rend, "%02X", &eoffset) == 1)
254+
{
255+
if (soffset >= RTC_SIZE)
256+
{
257+
DBGLOG("RTCFX", "rtc start offset %02X is not valid", soffset);
258+
break;
259+
}
260+
261+
if (eoffset >= RTC_SIZE)
262+
{
263+
DBGLOG("RTCFX", "rtc end offset %02X is not valid", eoffset);
264+
break;
265+
}
266+
267+
if (soffset >= eoffset)
268+
{
269+
DBGLOG("RTCFX", "rtc start offset %02X must be less than end offset %02X", soffset, eoffset);
270+
break;
271+
}
272+
273+
for (unsigned int i = soffset; i <= eoffset; ++i)
274+
emulated_flag[i] = true;
275+
DBGLOG("RTCFX", "rtc range from offset %02X to offset %02X is marked as emulated", soffset, eoffset);
276+
}
277+
else
278+
{
279+
DBGLOG("RTCFX", "boot-arg rtcfx_exclude can't be parsed properly");
280+
break;
281+
}
282+
}
283+
284+
tok = end;
285+
}
286+
}
287+
288+
//==============================================================================
289+
283290
void RTCMemoryFixup::hookProvider(IOService *provider)
284291
{
292+
if (orgIoRead8 == nullptr || orgIoWrite8 == nullptr)
293+
{
294+
auto data = OSDynamicCast(OSData, provider->getProperty("rtcfx_exclude"));
295+
if (data)
296+
{
297+
char rtcfx_exclude[512] {};
298+
if (data->getLength() < sizeof(rtcfx_exclude))
299+
{
300+
lilu_os_strncpy(rtcfx_exclude, reinterpret_cast<const char*>(data->getBytesNoCopy()), data->getLength());
301+
DBGLOG("RTCFX", "property rtcfx_exclude specified, value = %s", rtcfx_exclude);
302+
excludeAddresses(rtcfx_exclude);
303+
}
304+
else
305+
{
306+
SYSLOG("RTCFX", "RTCMemoryFixup::hookProvider: length of rtcfx_exclude cannot excceed 512 bytes");
307+
}
308+
}
309+
}
310+
285311
if (orgIoRead8 == nullptr)
286312
{
287313
if (KernelPatcher::routeVirtual(provider, IOPortAccessOffset::ioRead8, ioRead8, &orgIoRead8))

RTCMemoryFixup/RTCMemoryFixup.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class EXPORT RTCMemoryFixup : public IOService
2727
virtual void free() override;
2828

2929
private:
30+
static void excludeAddresses(char* rtcfx_exclude);
3031
static void hookProvider(IOService* provider);
3132

3233
using t_io_read8 = UInt8 (*)(IOService * that, UInt16 offset, IOMemoryMap * map);

0 commit comments

Comments
 (0)