Senior Member
Iscritto dal: Jan 2002
Città: Germania
Messaggi: 26110
|
Quote:
Originariamente inviato da cionci
Quindi davvero secondo te conviene partire da Python e non da C# se una persona si pone l'obiettivo di scrivere programmi che interagiscono a basso livello con l'hardware ? Secondo me è un'assurdità.
Nota bene che io non dico che sia un'assurdità imparare a programmare con Python, tutt'altro, dico che è assurdo in questo caso.
|
Codice:
from ctypes import *
hw = windll.WinRing0
def c_intToStr(Value):
return ''.join(chr((Value >> Shift) & 255) for Shift in (0, 8, 16, 24))
def c_intToNibbles(Value):
return tuple((Value >> Shift) & 15 for Shift in(0, 4, 8, 12, 16, 20, 24, 28))
def BitSetToStringList(Value, Names):
List = []
for Name in Names:
if Name and (Value & 1):
List.append(Name)
Value >>= 1
return List
def CPUID(Function):
eax = c_int(); ebx = c_int(); ecx = c_int(); edx = c_int()
hw.Cpuid(Function, byref(eax), byref(ebx), byref(ecx), byref(edx))
return eax.value, ebx.value, ecx.value, edx.value
EDXFeatures = ('Floating-point unit on-Chip',
'Virtual Mode Extension',
'Debugging Extension',
'Page Size Extension',
'Time-Stamp Counter',
'Model Specific Registers',
'Physical Address Extension',
'Machine Check Exception',
'CMPXCHG8 Instruction Supported',
'On-chip APIC Hardware Supported',
'',
'Fast System Call',
'Memory Type Range Registers',
'Page Global Enable',
'Machine Check Architecture',
'Conditional Move Instruction Supported',
'Page Attribute Table',
'36-bit Page Size Extension',
'Processor serial number is present and enabled',
'CLFLUSH Instruction supported',
'',
'Debug Store',
'Thermal Monitor and Software Controlled Clock Facilities supported',
'Intel Architecture MMX technology supported',
'Fast floating point save and restore',
'Streaming SIMD Extensions supported',
'Streaming SIMD Extensions 2',
'Self-Snoop',
'Multi-Threading',
'Thermal Monitor supported',
'IA64 Capabilities',
'Pending Break Enable')
ECXFeatures = ('Streaming SIMD Extensions 3',
'',
'64-Bit Debug Store',
'MONITOR/MWAIT',
'CPL Qualified Debug Store',
'Virtual Machine Extensions',
'Safer Mode Extensions',
'Enhanced Intel SpeedStep Technology',
'Thermal Monitor 2',
'Supplemental Streaming SIMD Extensions 3',
'Context ID',
'',
'',
'CMPXCHG16B',
'Send Task Priority Messages',
'Performance Capabilities MSR',
'',
'',
'Direct Cache Access',
'Streaming SIMD Extensions 4.1',
'Streaming SIMD Extensions 4.2',
'',
'',
'POPCNT instruction',
'',
'',
'',
'',
'',
'',
'',
'RAZ')
try:
hw.InitializeDll()
eax, ebx, ecx, edx = CPUID(0)
print 'CPU VendorID is:', c_intToStr(ebx) + c_intToStr(edx) + c_intToStr(ecx)
eax, ebx, ecx, edx = CPUID(0x80000002)
Brand = c_intToStr(eax) + c_intToStr(ebx) + c_intToStr(ecx) + c_intToStr(edx)
eax, ebx, ecx, edx = CPUID(0x80000003)
Brand += c_intToStr(eax) + c_intToStr(ebx) + c_intToStr(ecx) + c_intToStr(edx)
eax, ebx, ecx, edx = CPUID(0x80000004)
Brand += c_intToStr(eax) + c_intToStr(ebx) + c_intToStr(ecx) + c_intToStr(edx)
print 'CPU Brand is:', ''.join(Ch for Ch in Brand if Ch != '\x00')
eax, ebx, ecx, edx = CPUID(1)
print 'CPU Stepping: %s, Model: %s, Family: %s, Processor Type: %s' % c_intToNibbles(eax)[ : 4]
print 'CPU Features:'
for Feature in BitSetToStringList(edx, EDXFeatures) + BitSetToStringList(ecx, ECXFeatures):
print ' ', Feature
finally:
hw.DeinitializeDll()
OUTPUT:
Codice:
CPU VendorID is: AuthenticAMD
CPU Brand is: AMD Athlon(tm) 64 Processor 2800+
CPU Stepping: 0, Model: 12, Family: 15, Processor Type: 0
CPU Features:
Floating-point unit on-Chip
Virtual Mode Extension
Debugging Extension
Page Size Extension
Time-Stamp Counter
Model Specific Registers
Physical Address Extension
Machine Check Exception
CMPXCHG8 Instruction Supported
On-chip APIC Hardware Supported
Fast System Call
Memory Type Range Registers
Page Global Enable
Machine Check Architecture
Conditional Move Instruction Supported
Page Attribute Table
36-bit Page Size Extension
CLFLUSH Instruction supported
Intel Architecture MMX technology supported
Fast floating point save and restore
Streaming SIMD Extensions supported
Streaming SIMD Extensions 2
E' abbastanza assurdo per te?
P.S. Il programma ha bisogno che i file WinRing0.dll e WinRing0.sys della cartella "release" del progetto http://openlibsys.org/ siano presenti nella cartella da cui verrà lanciato (oppure che si trovino nel path).
|