@@ -78,71 +78,12 @@ bool RTCMemoryFixup::init(OSDictionary *propTable)
78
78
return false ;
79
79
}
80
80
81
- char rtcfx_exclude[200 ] {};
81
+ char rtcfx_exclude[512 ] {};
82
82
if (PE_parse_boot_argn (" rtcfx_exclude" , rtcfx_exclude, sizeof (rtcfx_exclude)))
83
83
{
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);
143
86
}
144
- else
145
- DBGLOG (" RTCFX" , " boot-arg rtcfx_exclude is not specified, RTCMemoryFixup is in test mode" );
146
87
147
88
return true ;
148
89
}
@@ -280,8 +221,93 @@ void RTCMemoryFixup::ioWrite8(IOService * that, UInt16 offset, UInt8 value, IOMe
280
221
281
222
// ==============================================================================
282
223
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
+
283
290
void RTCMemoryFixup::hookProvider (IOService *provider)
284
291
{
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
+
285
311
if (orgIoRead8 == nullptr )
286
312
{
287
313
if (KernelPatcher::routeVirtual (provider, IOPortAccessOffset::ioRead8, ioRead8, &orgIoRead8))
0 commit comments