Introducce TimebaseSpeed which represents exact timebase-frequency instead

of supposing it to be (BusClockSpeed/4), which is no longer true on G5 et al.
This commit is contained in:
gbeauche 2004-07-03 10:39:07 +00:00
parent ddd6402a16
commit 0669b02e5f
6 changed files with 35 additions and 5 deletions

View File

@ -219,6 +219,7 @@ uint32 DREmulatorAddr; // Address of DR Emulator
uint32 PVR; // Theoretical PVR
int64 CPUClockSpeed; // Processor clock speed (Hz)
int64 BusClockSpeed; // Bus clock speed (Hz)
int64 TimebaseSpeed; // Timebase clock speed (Hz)
system_info SysInfo; // System information
static void *sig_stack = NULL; // Stack for signal handlers
@ -299,6 +300,7 @@ void SheepShaver::ReadyToRun(void)
}
CPUClockSpeed = SysInfo.cpu_clock_speed;
BusClockSpeed = SysInfo.bus_clock_speed;
TimebaseSpeed = BusClockSpeed / 4;
// Delete old areas
area_id old_kernel_area = find_area(KERNEL_AREA_NAME);

View File

@ -224,7 +224,7 @@ AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(mach/vm_map.h mach/mach_init.h sys/mman.h)
AC_CHECK_HEADERS(sys/time.h sys/times.h sys/socket.h)
AC_CHECK_HEADERS(unistd.h fcntl.h byteswap.h)
AC_CHECK_HEADERS(unistd.h fcntl.h byteswap.h dirent.h)
AC_CHECK_HEADERS(linux/if.h, [], [], [
#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>

View File

@ -127,6 +127,10 @@
#include "debug.h"
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif
#ifdef USE_SDL
#include <SDL.h>
#endif
@ -275,6 +279,7 @@ uint32 DRCacheAddr; // Address of DR Cache
uint32 PVR; // Theoretical PVR
int64 CPUClockSpeed; // Processor clock speed (Hz)
int64 BusClockSpeed; // Bus clock speed (Hz)
int64 TimebaseSpeed; // Timebase clock speed (Hz)
// Global variables
@ -566,6 +571,7 @@ int main(int argc, char **argv)
PVR = 0x00040000; // Default: 604
CPUClockSpeed = 100000000; // Default: 100MHz
BusClockSpeed = 100000000; // Default: 100MHz
TimebaseSpeed = 25000000; // Default: 25MHz
#if EMULATED_PPC
PVR = 0x000c0000; // Default: 7400 (with AltiVec)
#elif defined(__APPLE__) && defined(__MACH__)
@ -670,6 +676,27 @@ int main(int argc, char **argv)
BusClockSpeed = value.l;
fclose(proc_file);
}
// Get actual timebase frequency
TimebaseSpeed = BusClockSpeed / 4;
DIR *cpus_dir;
if ((cpus_dir = opendir("/proc/device-tree/cpus")) != NULL) {
struct dirent *cpu_entry;
while ((cpu_entry = readdir(cpus_dir)) != NULL) {
if (strstr(cpu_entry->d_name, "PowerPC,") == cpu_entry->d_name) {
char timebase_freq_node[256];
sprintf(timebase_freq_node, "/proc/device-tree/cpus/%s/timebase-frequency", cpu_entry->d_name);
proc_file = fopen(timebase_freq_node, "r");
if (proc_file) {
union { uint8 b[4]; uint32 l; } value;
if (fread(value.b, sizeof(value), 1, proc_file) == 1)
TimebaseSpeed = value.l;
fclose(proc_file);
}
}
}
closedir(cpus_dir);
}
#endif
D(bug("PVR: %08x (assumed)\n", PVR));
@ -954,7 +981,7 @@ int main(int argc, char **argv)
kernel_data->v[0xf60 >> 2] = htonl(PVR);
kernel_data->v[0xf64 >> 2] = htonl(CPUClockSpeed); // clock-frequency
kernel_data->v[0xf68 >> 2] = htonl(BusClockSpeed); // bus-frequency
kernel_data->v[0xf6c >> 2] = htonl(BusClockSpeed / 4); // timebase-frequency
kernel_data->v[0xf6c >> 2] = htonl(TimebaseSpeed); // timebase-frequency
} else {
kernel_data->v[0xc80 >> 2] = htonl(RAMSize);
kernel_data->v[0xc84 >> 2] = htonl(RAMSize);
@ -968,7 +995,7 @@ int main(int argc, char **argv)
kernel_data->v[0xf80 >> 2] = htonl(PVR);
kernel_data->v[0xf84 >> 2] = htonl(CPUClockSpeed); // clock-frequency
kernel_data->v[0xf88 >> 2] = htonl(BusClockSpeed); // bus-frequency
kernel_data->v[0xf8c >> 2] = htonl(BusClockSpeed / 4); // timebase-frequency
kernel_data->v[0xf8c >> 2] = htonl(TimebaseSpeed); // timebase-frequency
}
// Initialize extra low memory

View File

@ -28,6 +28,7 @@ extern uint32 BootGlobsAddr; // Address of BootGlobs structure at top of Mac RAM
extern uint32 PVR; // Theoretical PVR
extern int64 CPUClockSpeed; // Processor clock speed (Hz)
extern int64 BusClockSpeed; // Bus clock speed (Hz)
extern int64 TimebaseSpeed; // Timebase clock speed (Hz)
#ifdef __BEOS__
extern system_info SysInfo; // System information

View File

@ -1145,7 +1145,7 @@ static inline uint64 get_tb_ticks(void)
{
uint64 ticks;
#ifdef SHEEPSHAVER
const uint32 TBFreq = BusClockSpeed / 4;
const uint32 TBFreq = TimebaseSpeed;
ticks = muldiv64(GetTicks_usec(), TBFreq, 1000000);
#else
const uint32 TBFreq = 25 * 1000 * 1000; // 25 MHz

View File

@ -138,7 +138,7 @@ void DoPatchNameRegistry(void)
RegistryPropertyCreate(power_pc.ptr(), "clock-frequency", u32.ptr(), 4);
u32.set_value(BusClockSpeed);
RegistryPropertyCreate(power_pc.ptr(), "bus-frequency", u32.ptr(), 4);
u32.set_value(BusClockSpeed / 4);
u32.set_value(TimebaseSpeed);
RegistryPropertyCreate(power_pc.ptr(), "timebase-frequency", u32.ptr(), 4);
u32.set_value(PVR);
RegistryPropertyCreate(power_pc.ptr(), "cpu-version", u32.ptr(), 4);