diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-03-06 14:11:28 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-03-06 14:11:28 +0100 |
| commit | 2b5c25ef17718bb0e324ea2febd5b76b829c309b (patch) | |
| tree | 808c3c4aed7dbc061b32b4e89639e2557743be8c /src | |
| parent | da34156267c483c3621e447ba78842aa37694751 (diff) | |
| download | box64-2b5c25ef17718bb0e324ea2febd5b76b829c309b.tar.gz box64-2b5c25ef17718bb0e324ea2febd5b76b829c309b.zip | |
Change branding of Cpu to refect Box64 and the cpu it's running on
Diffstat (limited to 'src')
| -rwxr-xr-x | src/main.c | 10 | ||||
| -rw-r--r-- | src/tools/my_cpuid.c | 62 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc.c | 40 |
3 files changed, 81 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c index 20e5bd35..21c8ed6a 100755 --- a/src/main.c +++ b/src/main.c @@ -204,8 +204,9 @@ void my_child_fork() } } -#ifdef DYNAREC +const char* getCpuName(); int getNCpu(); +#ifdef DYNAREC void GatherDynarecExtensions() { if(box64_dynarec==0) // no need to check if no dynarec @@ -347,9 +348,7 @@ HWCAP2_ECV printf_log(LOG_INFO, " PMULL"); if(arm64_atomics) printf_log(LOG_INFO, " ATOMICS"); - printf_log(LOG_INFO, " PageSize:%zd", box64_pagesize); - int ncpu = getNCpu(); - printf_log(LOG_INFO, " Cores:%d\n", ncpu); + printf_log(LOG_INFO, " PageSize:%zd\n", box64_pagesize); #elif defined(LA464) printf_log(LOG_INFO, "Dynarec for LoongArch"); printf_log(LOG_INFO, " PageSize:%zd\n", box64_pagesize); @@ -782,6 +781,9 @@ void LoadLogEnv() #ifdef DYNAREC GatherDynarecExtensions(); #endif + int ncpu = getNCpu(); + const char* cpuname = getCpuName(); + printf_log(LOG_INFO, "Running on %s with %d Cores\n", cpuname, ncpu); } EXPORTDYN diff --git a/src/tools/my_cpuid.c b/src/tools/my_cpuid.c index b08c214f..06b725aa 100644 --- a/src/tools/my_cpuid.c +++ b/src/tools/my_cpuid.c @@ -25,11 +25,33 @@ int get_cpuMhz() return MHz; } int getNCpu(); // defined in wrappedlibc.c +const char* getCpuName(); // same void my_cpuid(x64emu_t* emu, uint32_t tmp32u) { emu->regs[_AX].dword[1] = emu->regs[_DX].dword[1] = emu->regs[_CX].dword[1] = emu->regs[_BX].dword[1] = 0; int ncpu = getNCpu(); + static char branding[3*4*4+1] = ""; + static int done = 0; + if(!done) { + done = 1; + const char* name = getCpuName(); + if(strstr(name, "MHz") || strstr(name, "GHz")) { + // name already have the speed in it + snprintf(branding, 3*4*4, "Box64 on %s", name); + } else { + int MHz = get_cpuMhz(); + if(MHz>15000) { // swiches to GHz display... + snprintf(branding, 3*4*4, "Box64 on %s @%1.2f GHz", name, MHz/1000.); + } else { + snprintf(branding, 3*4*4, "Box64 on %s @%04d MHz", name, MHz); + } + } + while(strlen(branding)<3*4*4) { + memmove(branding+1, branding, strlen(branding)); + branding[0] = ' '; + } + } if(ncpu>255) ncpu = 255; if(!ncpu) ncpu = 1; switch(tmp32u) { @@ -157,37 +179,23 @@ void my_cpuid(x64emu_t* emu, uint32_t tmp32u) //AMD flags? //R_EDX = 1 | (1<<8) | (1<<11) | (1<<15) | (1<<23) | (1<<29); // fpu+cmov+cx8+syscall+mmx+lm (mmxext=22, 3dnow=31, 3dnowext=30) break; - case 0x80000002: // Brand part 1 (P4 signature) - R_EAX = 0x20202020; - R_EBX = 0x20202020; - R_ECX = 0x20202020; - R_EDX = 0x6E492020; + case 0x80000002: // Brand part 1 (branding signature) + R_EAX = ((uint32_t*)branding)[0]; + R_EBX = ((uint32_t*)branding)[1]; + R_ECX = ((uint32_t*)branding)[2]; + R_EDX = ((uint32_t*)branding)[3]; break; case 0x80000003: // Brand part 2 - R_EAX = 0x286C6574; - R_EBX = 0x50202952; - R_ECX = 0x69746E65; - R_EDX = 0x52286D75; + R_EAX = ((uint32_t*)branding)[4]; + R_EBX = ((uint32_t*)branding)[5]; + R_ECX = ((uint32_t*)branding)[6]; + R_EDX = ((uint32_t*)branding)[7]; break; case 0x80000004: // Brand part 3, with frequency - R_EAX = 0x20342029; - R_EBX = 0x20555043; - { - static int MHz = 0; - if(!MHz) - MHz = get_cpuMhz(); - if(MHz>15000) { // swiches to GHz display... - char tmp[11]; - sprintf(tmp, "%1.2f", MHz/1000.); - R_ECX = *(uint32_t*)tmp; - R_EDX = 0x007A4847; // GHz - } else { - char tmp[11]; - sprintf(tmp, "%04d", MHz); - R_ECX = *(uint32_t*)tmp; - R_EDX = 0x007A484D; // MHz - } - } + R_EAX = ((uint32_t*)branding)[8]; + R_EBX = ((uint32_t*)branding)[9]; + R_ECX = ((uint32_t*)branding)[10]; + R_EDX = ((uint32_t*)branding)[11]; break; case 0x80000005: R_EAX = 0; diff --git a/src/wrapped/wrappedlibc.c b/src/wrapped/wrappedlibc.c index 0f9ae4a5..b3f52353 100755 --- a/src/wrapped/wrappedlibc.c +++ b/src/wrapped/wrappedlibc.c @@ -1457,6 +1457,46 @@ int getNCpu() return nCPU; } +const char* getCpuName() +{ + static char name[200] = "Unknown"; + static int done = 0; + if(done) + return name; + done = 1; + FILE* f = popen("lscpu | grep \"Model name:\" | sed -r 's/Model name:\\s{1,}//g'", "r"); + if(f) { + char tmp[200] = ""; + ssize_t s = fread(tmp, 1, 200, f); + pclose(f); + if(s>0) { + // worked! + // trim ending + while(strlen(tmp) && tmp[strlen(tmp)-1]=='\n') + tmp[strlen(tmp)-1] = 0; + strncpy(name, tmp, 199); + return name; + } + } + // failled, try to get architecture at least + f = popen("lscpu | grep \"Architecture:\" | sed -r 's/Architecture:\\s{1,}//g'", "r"); + if(f) { + char tmp[200] = ""; + ssize_t s = fread(tmp, 1, 200, f); + pclose(f); + if(s>0) { + // worked! + // trim ending + while(strlen(tmp) && tmp[strlen(tmp)-1]=='\n') + tmp[strlen(tmp)-1] = 0; + snprintf(name, 199, "unknown %s cpu", tmp); + return name; + } + } + // Nope, bye + return name; +} + #ifndef NOALIGN void CreateCPUInfoFile(int fd) |