I-Nex/I-Nex/i-nex/.src/CPU/MLibcpuid14.module

356 lines
13 KiB
Plaintext

' Gambas module file
' The module was written by vuott from http://www.gambas-it.org/
' http://www.gambas-it.org/smf/index.php?action=profile;u=402
Library "libcpuid:14.0.0"
Public Struct cpu_raw_data_t
basic_cpuid[32, 4] As Integer
ext_cpuid[32, 4] As Integer
intel_fn4[8, 4] As Integer
intel_fn11[4, 4] As Integer
intel_fn12h[4, 4] As Integer
intel_fn14h[4, 4] As Integer
End Struct
Public Struct cpu_mark_t
tsc As Long
sys_clock As Long
End Struct
' int cpuid_present(void)
' Checks if the CPUID instruction is supported.
Private Extern cpuid_present() As Integer
' int cpuid_get_raw_data(struct cpu_raw_data_t* data)
' Obtains the raw CPUID data from the current CPU.
Private Extern cpuid_get_raw_data(data As Cpu_raw_data_t) As Integer
' const char* cpuid_error(void)
' Returns textual description of the last error.
Private Extern cpuid_error() As String
' int cpu_identify(struct cpu_raw_data_t* raw, struct cpu_id_t* data)
' Identifies the CPU.
Private Extern cpu_identify(raw As Cpu_raw_data_t, data As Pointer) As Integer
' void cpu_tsc_mark(struct cpu_mark_t* mark)
' Store TSC and timing info.
Private Extern cpu_tsc_mark(mark As Cpu_mark_t)
' void cpu_tsc_unmark(struct cpu_mark_t* mark)
' Calculate TSC and timing difference.
Private Extern cpu_tsc_unmark(mark As Cpu_mark_t)
' int cpu_clock(void)
' Get the CPU clock frequency (all-in-one method).
Private Extern cpu_clock() As Integer
' int cpu_clock_by_os(void)
' Returns the CPU clock, as reported by the OS.
Private Extern cpu_clock_by_os() As Integer
' int cpu_clock_by_ic(int millis, int runs)
' Measure the CPU clock frequency using instruction-counting.
Private Extern cpu_clock_by_ic(millis As Integer, runs As Integer) As Integer
' int cpu_clock_measure(int millis, int quad_check)
' Measure the CPU clock frequency.
Private Extern cpu_clock_measure(millis As Integer, quad_check As Integer) As Integer
' const char * cpu_feature_str(cpu_feature_t feature)
' Returns the short textual representation Of a CPU flag.
Private Extern cpu_feature_str(feature As Integer) As String
Private sa As ScrollArea
Public Sub Main()
Dim obs As Observer
Dim TextBox As TextBox
Dim TextArea As TextArea
Dim raw As New Cpu_raw_data_t
Dim data As Pointer
Dim mark As New Cpu_mark_t
Dim au As String
Dim cpu_vendor As String[]
Dim i As Integer
cpu_vendor = ["Intel CPU", "AMD CPU", "Cyrix CPU", "NexGen CPU", "Transmeta CPU", "x86 CPU by UMC", "x86 CPU by IDT",
"x86 CPU by Rise Technology", "x86 CPU by SiS", "x86 CPU by National Semiconductor", ""]
If Not cpuid_present() Then Error.Raise("La CPUID non è supportata !")
If cpuid_get_raw_data(raw) < 0 Then
Error.Raise("Impossibile ottenere dati grezzi CPUID !\nError: " & cpuid_error())
Endif
data = Alloc(SizeOf(gb.Byte), 432)
If cpu_identify(raw, data) < 0 Then
Error.Raise("Impossibile identificare la CPU !\nError: " & cpuid_error())
Endif
cpu_tsc_mark(mark)
cpu_tsc_unmark(mark)
sa = Finfosys.GridView4.Children[0]
obs = New Observer(sa) As "Scroll"
With Finfosys.GridView4
.Columns.Count = 1
.Rows.Count = 20
End With
Finfosys.GridView4.Columns[0].W = 400
With TextBox = New TextBox(sa) As "CPU_VENDOR"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[0].Y
.W = Finfosys.GridView4[0, 0].W
.H = Finfosys.GridView4[0, 0].H
.Text = "CPU Vendor: " & String@(data)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "CPU_CODENAME"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[1].Y
.W = Finfosys.GridView4[1, 0].W
.H = Finfosys.GridView4[1, 0].H
.Text = "CPU Codename: " & String@(data + 296)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "CPU_BRAND"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[2].Y
.W = Finfosys.GridView4[2, 0].W
.H = Finfosys.GridView4[2, 0].H
.Text = "CPU Brand: " & String@(data + 16)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "VENDOR"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[3].Y
.W = Finfosys.GridView4[3, 0].W
.H = Finfosys.GridView4[3, 0].H
.Text = "CPU Vendor: " & IIf(Int@(data + 80) = -1, "Not found", cpu_vendor[Int@(data + 80)])
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "FAMILY"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[4].Y
.W = Finfosys.GridView4[4, 0].W
.H = Finfosys.GridView4[4, 0].H
.Text = "CPU Family: " & Int@(data + 212)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "MODEL"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[5].Y
.W = Finfosys.GridView4[5, 0].W
.H = Finfosys.GridView4[5, 0].H
.Text = "CPU Model: " & Int@(data + 216)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "STEPPING"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[6].Y
.W = Finfosys.GridView4[6, 0].W
.H = Finfosys.GridView4[6, 0].H
.Text = "CPU Stepping: " & Int@(data + 220)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "EXT_FAMILY"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[7].Y
.W = Finfosys.GridView4[7, 0].W
.H = Finfosys.GridView4[7, 0].H
.Text = "CPU Ext family: " & Int@(data + 224)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "EXT_MODEL"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[8].Y
.W = Finfosys.GridView4[8, 0].W
.H = Finfosys.GridView4[8, 0].H
.Text = "CPU Ext model: " & Int@(data + 228)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "NUM_CORES"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[9].Y
.W = Finfosys.GridView4[9, 0].W
.H = Finfosys.GridView4[9, 0].H
.Text = "CPU Num cores: " & Int@(data + 232)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "NUM_LOGICAL_CPUS"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[10].Y
.W = Finfosys.GridView4[10, 0].W
.H = Finfosys.GridView4[10, 0].H
.Text = "CPU Num logical cpus: " & Int@(data + 236)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "TOTAL_LOGICAL_CPUS"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[11].Y
.W = Finfosys.GridView4[11, 0].W
.H = Finfosys.GridView4[11, 0].H
.Text = "CPU Total logical cpus: " & Int@(data + 240)
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "L1_DATA_CACHE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[12].Y
.W = Finfosys.GridView4[12, 0].W
.H = Finfosys.GridView4[12, 0].H
.Text = "L1 Data Cache: " & Int@(data + 244) & " KB" &
", Assoc: " & IIf(Int@(data + 264) > 0, Int@(data + 264) & "-way", "intedeterminato") &
", Cacheline: " & IIf(Int@(data + 280) > 0, Int@(data + 280) & " byte", "intedeterminato")
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "L1_INSTRUCTION_CACHE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[13].Y
.W = Finfosys.GridView4[13, 0].W
.H = Finfosys.GridView4[13, 0].H
.Text = "L1 Instruction Cache: " & Int@(data + 248) & " KB"
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "L2_CACHE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[14].Y
.W = Finfosys.GridView4[14, 0].W
.H = Finfosys.GridView4[14, 0].H
.Text = "L2 Cache: " & Int@(data + 252) & " KB" &
", Assoc: " & IIf(Int@(data + 268) > 0, Int@(data + 268) & "-way", "undetermined") &
", Cacheline: " & IIf(Int@(data + 284) > 0, Int@(data + 280) & " byte", "undetermined")
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "L3_CACHE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[15].Y
.W = Finfosys.GridView4[15, 0].W
.H = Finfosys.GridView4[15, 0].H
.Text = "L3 Cache: " & Int@(data + 256) & " KB" &
", Assoc: " & IIf(Int@(data + 272) > 0, Int@(data + 272) & "-way", "undetermined") &
", Cacheline: " & IIf(Int@(data + 288) > 0, Int@(data + 288) & " byte", "undetermined")
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "L4_CACHE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[16].Y
.W = Finfosys.GridView4[16, 0].W
.H = Finfosys.GridView4[16, 0].H
.Text = "L4 Cache: " & Int@(data + 260) & " KB" &
", Assoc: " & IIf(Int@(data + 276) > 0, Int@(data + 276) & "-way", "undetermined") &
", Cacheline: " & IIf(Int@(data + 292) > 0, Int@(data + 292) & " byte", "undetermined")
.Border = False
.ReadOnly = True
End With
au = IIf(Byte@(data + 364), "(authoritative)", "(non-authoritative)")
With TextBox = New TextBox(sa) As "SSE_SIZE"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[17].Y
.W = Finfosys.GridView4[17, 0].W
.H = Finfosys.GridView4[17, 0].H
.Text = "SSE Size: " & Int@(data + 360) & " bit " & au
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "CPU_CLOCK"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[18].Y
.W = Finfosys.GridView4[18, 0].W
.H = Finfosys.GridView4[18, 0].H
.Text = "CPU Clock: " & cpu_clock() & " Mhz" &
", By OS:" & cpu_clock_by_os() & " Mhz" &
", By IC:" & cpu_clock_by_ic(25, 16) & " Mhz" &
", Measure:" & cpu_clock_measure(400, 1) & " Mhz"
.Border = False
.ReadOnly = True
End With
With TextBox = New TextBox(sa) As "CPU_MARK_TSC"
.X = Finfosys.GridView4.Columns[0].X
.Y = Finfosys.GridView4.Rows[19].Y
.W = Finfosys.GridView4[19, 0].W
.H = Finfosys.GridView4[19, 0].H
.Text = "CPU Mark TSC: " & mark.tsc &
", Sys Clock:" & "µs " & mark.sys_clock
.Border = False
.ReadOnly = True
End With
'
'
' Print " \"VENDOR_STR\": "; String@(data)
' Print " \"CPU_CODENAME\": "; String@(data + 296)
' Print " \"BRAND_STR\": "; String@(data + 16)
' Print " \"VENDOR\": "; IIf(Int@(data + 80) = -1, "Not found", cpu_vendor[Int@(data + 80)])
' Print " \"FAMILY\": "; Int@(data + 212)
' Print " \"MODEL\": "; Int@(data + 216)
' Print " \"STEPPING\": "; Int@(data + 220)
' Print " \"EXT_FAMILY\": "; Int@(data + 224)
' Print " \"EXT_MODEL\": "; Int@(data + 228)
' Print " \"NUM_CORES\": "; Int@(data + 232)
' Print " \"NUM_LOGICAL_CPUS\": "; Int@(data + 236)
' Print " \"TOTAL_LOGICAL_CPUS\": "; Int@(data + 240)
' Print " \"L1_DATA_CACHE\": "; Int@(data + 244); " KB"
' Print " \"L1_INSTRUCTION_CACHE\": "; Int@(data + 248); " KB"
' Print " \"L2_CACHE\": "; Int@(data + 252); " KB"
' Print " \"L3_CACHE\": "; Int@(data + 256); " KB"
' Print " \"L4_CACHE\": "; Int@(data + 260); " KB"
' Print " \"L1_ASSOC\": "; IIf(Int@(data + 264) > 0, Int@(data + 264) & "-way", "intedeterminato")
' Print " \"L2_ASSOC\": "; IIf(Int@(data + 268) > 0, Int@(data + 268) & "-way", "intedeterminato")
' Print " \"L3_ASSOC\": "; IIf(Int@(data + 272) > 0, Int@(data + 272) & "-way", "intedeterminato")
' Print " \"L4_ASSOC\": "; IIf(Int@(data + 276) > 0, Int@(data + 276) & "-way", "intedeterminato")
' Print " \"L1_CACHELINE\": "; IIf(Int@(data + 280) > 0, Int@(data + 280) & " byte", "intedeterminato")
' Print " \"L2_CACHELINE\": "; IIf(Int@(data + 284) > 0, Int@(data + 284) & " byte", "intedeterminato")
' Print " \"L3_CACHELINE\": "; IIf(Int@(data + 288) > 0, Int@(data + 288) & " byte", "intedeterminato")
' Print " \"L4_CACHELINE\": "; IIf(Int@(data + 292) > 0, Int@(data + 292) & " byte", "intedeterminato")
'
' Print " \"SSE_SIZE\": "; Int@(data + 360); " bit "; au
' Print " \"CPU_CLOCK\": "; cpu_clock(); " Mhz"
' Print " \"CPU_CLOCK_BY_OS\": "; cpu_clock_by_os(); " Mhz"
' Print " \"CPU_CLOCK_BY_IC\": "; cpu_clock_by_ic(25, 16); " Mhz"
' Print " \"CPU_CLOCK_MEASURE\": "; cpu_clock_measure(400, 1); " Mhz"
' Print " \"MARK_TSC\": "; mark.tsc
' Print " \"MARK_SYS_CLOCK\": "; "µs "; mark.sys_clock
For i = 0 To 109
Finfosys.ListBox2.Add("FEATURE: " & cpu_feature_str(i) & IIf(Byte@(data + (i + 84)), " Present", " Absent"))
Next
Free(data)
End