mirror of
https://github.com/n64dev/cen64.git
synced 2024-06-21 13:32:40 -04:00
core: add cpuid fetching code from 4996031
This commit is contained in:
parent
dcefa18582
commit
abca698a75
|
@ -275,6 +275,7 @@ set(OS_SOURCES
|
|||
|
||||
set(OS_POSIX_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/os/posix/alloc.c
|
||||
${PROJECT_SOURCE_DIR}/os/posix/cpuid.c
|
||||
${PROJECT_SOURCE_DIR}/os/posix/local_time.c
|
||||
${PROJECT_SOURCE_DIR}/os/posix/main.c
|
||||
${PROJECT_SOURCE_DIR}/os/posix/rom_file.c
|
||||
|
@ -284,6 +285,7 @@ set(OS_POSIX_SOURCES
|
|||
|
||||
set(OS_WINAPI_SOURCES
|
||||
${PROJECT_SOURCE_DIR}/os/winapi/alloc.c
|
||||
${PROJECT_SOURCE_DIR}/os/winapi/cpuid.c
|
||||
${PROJECT_SOURCE_DIR}/os/winapi/gl_config.c
|
||||
${PROJECT_SOURCE_DIR}/os/winapi/gl_window.c
|
||||
${PROJECT_SOURCE_DIR}/os/winapi/local_time.c
|
||||
|
|
25
os/cpuid.h
Normal file
25
os/cpuid.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
//
|
||||
// os/cpuid.h
|
||||
//
|
||||
// Functions for calling cpuid on x86.
|
||||
//
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#ifndef __os_cpuid_h__
|
||||
#define __os_cpuid_h__
|
||||
#include "common.h"
|
||||
|
||||
struct cen64_cpuid_t {
|
||||
uint32_t eax;
|
||||
uint32_t ebx;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
};
|
||||
|
||||
void cen64_cpuid(uint32_t eax, uint32_t ecx, struct cen64_cpuid_t *cpuid);
|
||||
void cen64_cpuid_get_vendor(char vendor[13]);
|
||||
|
||||
#endif
|
||||
|
31
os/posix/cpuid.c
Normal file
31
os/posix/cpuid.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
//
|
||||
// os/posix/cpuid.c
|
||||
//
|
||||
// Functions for calling cpuid on x86.
|
||||
//
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#include "os/cpuid.h"
|
||||
|
||||
void cen64_cpuid(uint32_t eax, uint32_t ecx, struct cen64_cpuid_t *cpuid) {
|
||||
__asm__ __volatile__(
|
||||
"cpuid\n\t"
|
||||
|
||||
: "=a"(cpuid->eax), "=b"(cpuid->ebx), "=c"(cpuid->ecx), "=d"(cpuid->edx)
|
||||
: "0"(eax), "2"(ecx)
|
||||
);
|
||||
}
|
||||
|
||||
void cen64_cpuid_get_vendor(char vendor[13]) {
|
||||
struct cen64_cpuid_t my_cpuid;
|
||||
|
||||
cen64_cpuid(0, 0, &my_cpuid);
|
||||
|
||||
memcpy(vendor + 0, &my_cpuid.ebx, sizeof(my_cpuid.ebx));
|
||||
memcpy(vendor + 4, &my_cpuid.edx, sizeof(my_cpuid.edx));
|
||||
memcpy(vendor + 8, &my_cpuid.ecx, sizeof(my_cpuid.ecx));
|
||||
vendor[12] = '\0';
|
||||
}
|
||||
|
35
os/winapi/cpuid.c
Normal file
35
os/winapi/cpuid.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// os/winapi/cpuid.c
|
||||
//
|
||||
// Functions for calling cpuid on x86.
|
||||
//
|
||||
// This file is subject to the terms and conditions defined in
|
||||
// 'LICENSE', which is part of this source code package.
|
||||
//
|
||||
|
||||
#include "os/cpuid.h"
|
||||
#include <intrin.h>
|
||||
|
||||
|
||||
void cen64_cpuid(uint32_t eax, uint32_t ecx, struct cen64_cpuid_t *cpuid) {
|
||||
int cpuInfo[4];
|
||||
|
||||
__cpuidex(cpuInfo, eax, ecx);
|
||||
|
||||
cpuid->eax = cpuInfo[0];
|
||||
cpuid->ebx = cpuInfo[1];
|
||||
cpuid->ecx = cpuInfo[2];
|
||||
cpuid->edx = cpuInfo[3];
|
||||
}
|
||||
|
||||
void cen64_cpuid_get_vendor(char vendor[13]) {
|
||||
int cpuInfo[4];
|
||||
|
||||
__cpuidex(cpuInfo, 0, 0);
|
||||
|
||||
memcpy(vendor + 0, cpuInfo + 1, sizeof(*cpuInfo));
|
||||
memcpy(vendor + 4, cpuInfo + 3, sizeof(*cpuInfo));
|
||||
memcpy(vendor + 8, cpuInfo + 2, sizeof(*cpuInfo));
|
||||
vendor[sizeof(vendor) - 1] = '\0';
|
||||
}
|
||||
|
Loading…
Reference in a new issue