Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Inline ASM Funktion erweitern (https://www.delphipraxis.net/169230-inline-asm-funktion-erweitern.html)

Horst0815 5. Jul 2012 18:53

Inline ASM Funktion erweitern
 
Könnte mir bitte jemand folgende Funktion dahingehend anpassen das auch Aktuelle Prozessoren erkannt werden ich habe leider keine Ahnung von Assembler


Delphi-Quellcode:
procedure GetCPUtype; stdcall;
asm
  push   ebx
  push   esi
  push   edi



//  _get_cpu_type: Identifies processor type in _cpu_type:
//; 0=8086/8088 processor
//; 2=Intel 286 processor
//; 3=Intel386(TM) family processor
//; 4=Intel486(TM) family processor
//; 5=Pentium(R) family processor
//; 6=P6 family of processors
//; F=Pentium 4 family of processors

  // Intel386 processor check
  pushfd                     // push original EFLAGS
  pop      eax           // get original EFLAGS
  mov      ecx, eax         // save original EFLAGS
  xor      eax, 40000h  // flip AC bit in EFLAGS
  push   eax                  // save new EFLAGS value on stack
  popfd
  pushfd
  pop      eax
  xor      eax, ecx
  mov      [cpu_type], 3
  jz      @end_cpuid_type
  push   ecx
  popfd

  // Intel486 processor check
  mov      [cpu_type], 4
  mov      eax, ecx
  xor      eax, 200000h
  push   eax
  popfd
  pushfd
  pop      eax
  xor      eax, ecx
  je      @end_cpuid_type

  mov      [cpuid_flag], 1

  // ***************************************************************************
  //
  // Execute CPUID instruction to determine vendor, family/model, stepping
  // and features
  //
  // ***************************************************************************

  mov      eax, 0
  call   CPU_ID

  mov      [dword ptr vendor_id], ebx
  mov      [dword ptr vendor_id+4], edx
  mov      [dword ptr vendor_id+8], ecx

  cmp      [dword ptr intel_id], ebx
  jne      @end_cpuid_type
  cmp      [dword ptr intel_id+4], edx
  jne      @end_cpuid_type
  cmp      [dword ptr intel_id+8], ecx
  jne      @end_cpuid_type

  mov      [intel_CPU], 1
  cmp      eax, 1
  jl      @end_cpuid_type

  mov      eax, 1               // get family/model/stepping/features
  call   CPU_ID

  mov      [cpu_signature], eax
  mov      [features_ebx], ebx
  mov      [features_edx], edx
  mov      [features_ecx], ecx

  // set cpu_type
  mov      eax, [dword ptr cpu_signature]
  shr      eax, 12
  and      eax, 3
  mov      [dword ptr cpu_type], eax

  // set family
  mov      eax, [dword ptr cpu_signature]
  shr      eax, 8
  and      eax, 0fh
  mov      [dword ptr cpu_family], eax

  // set extended family
  mov      eax, [dword ptr cpu_signature]
  shr      eax, 20
  and      eax, 0ffh
  mov      [dword ptr cpu_ext_family], eax

  // set model
  mov      eax, [dword ptr cpu_signature]
  shr      eax, 4
  and      eax, 0fh
  mov      [dword ptr cpu_model], eax

  // set extended model
  mov      eax, [dword ptr cpu_signature]
  shr      eax, 16
  and      eax, 0fh
  mov      [dword ptr cpu_ext_model], eax

  // set stepping
  mov      eax, [cpu_signature]
  and      eax, 0fh
  mov      [dword ptr cpu_stepping], eax

  // set brand_index
  mov      eax, [features_ebx]
  and      eax, 0ffh
  mov      [dword ptr cpu_brand_index], eax

  // set CLFLUSH line size
  mov      eax, [features_ebx]
  and      eax, 0ff00h
  shr      eax, 8
  mov      [dword ptr cpu_CLFLUSH_lsize], eax

  // ***************************************************************************
  //
  // Execute CPUID intruction to determine the cache descriptor information
  //
  // ***************************************************************************

  mov      eax, 0
  call   CPU_ID
  cmp      eax, 2                  // Are cache descriptors supported?
  jl      @end_cpuid_type

  mov      eax, 2                  // setup to read cache descriptor
  call   CPU_ID
  cmp      al, 1                     // is one iteration enough to obtain
  jne      @end_cpuid_type         // cache information?
  // This code supports one iteration
  // only, for now!
  mov      [cache_eax], eax // store cache information
  mov      [cache_ebx], ebx   // for the future processors CPUID instruction
  mov      [cache_ecx], ecx   // may need to run more than once to get full
  mov      [cache_edx], edx   // cache information

  mov      eax, 0
  call   CPU_ID
  cmp      eax, 4                  // Are determistic cache parameters supported?
  jl      @end_cpuid_type

  mov      eax, 4
  mov      ecx, 0
  call   CPU_ID
  push   eax
  and      al, 1fh                  // determine if valid cache parameters read
  cmp      al, 00h                  // EAX[4:0] = 0 indicates invalid cache

  pop      eax
  je      @end_cpuid_type

  mov      [dcp_cache_eax], eax   // store deterministic cache information
  mov      [dcp_cache_ebx], ebx
  mov      [dcp_cache_ecx], ecx
  mov      [dcp_cache_edx], edx

  // ***************************************************************************
  //
  // Execute CPUID intruction to determine the MONITOR/MWAIT functions information
  //
  // ***************************************************************************

  mov      eax, 0
  call   CPU_ID
  cmp      eax, 5
  jl      @checkBrand

  // TODO:??? get information about MONITOR/MWAIT functions

  // ***************************************************************************
  //
  // Execute CPUID intruction to determine the Power Mangement Feature
  // Enumeration information
  //
  // ***************************************************************************

  mov      eax, 0
  call   CPU_ID
  cmp      eax, 6
  jl      @checkBrand

  // TODO:??? get more information about PMFE


  // ***************************************************************************
  //
  // Execute CPUID intruction to determine the Extended Feature information
  //
  // ***************************************************************************

@checkBrand:
  mov      eax, EXT_VAL_0    // check if brand string supported
  call   CPU_ID
  cmp      eax, EXT_VAL_4
  jbe      @end_cpuid_type

  mov      eax, EXT_VAL_1      // get the extended feature flags
  call   CPU_ID

  mov      [ext_funct_1_eax], eax
  mov      [ext_funct_1_ebx], ebx
  mov      [ext_funct_1_ecx], ecx
  mov      [ext_funct_1_edx], edx

  mov      edi, offset cpu_proc_string

  mov      eax, EXT_VAL_2       // get first 16 bytes of brand string
  call   CPU_ID
  mov      [edi], eax             // save bytes 0..15
  mov      [edi+4], ebx
  mov      [edi+8], ecx
  mov      [edi+12], edx
  add      edi, 16

  mov      eax, EXT_VAL_3
  call   CPU_ID
  mov      [edi], eax             // save bytes 16..31
  mov      [edi+4], ebx
  mov      [edi+8], ecx
  mov      [edi+12], edx
  add      edi, 16

  mov      eax, EXT_VAL_4
  call   CPU_ID
  mov      [edi], eax             // save bytes 32..47
  mov      [edi+4], ebx
  mov      [edi+8], ecx
  mov      [edi+12], edx

  mov      eax, EXT_VAL_0      // check if L2 cache features supported
  call   CPU_ID
  cmp      eax, EXT_VAL_6
  jbe      @end_cpuid_type

  mov      [ext_funct_6_eax], eax
  mov      [ext_funct_6_ebx], ebx
  mov      [ext_funct_6_ecx], ecx
  mov      [ext_funct_6_edx], edx

  mov      eax, EXT_VAL_0      // check if Address Size function supported
  call   CPU_ID
  cmp      eax, EXT_VAL_8
  jbe      @end_cpuid_type

  mov      [ext_funct_8_eax], eax
  mov      [ext_funct_8_ebx], ebx
  mov      [ext_funct_8_ecx], ecx
  mov      [ext_funct_8_edx], edx

@end_cpuid_type:
  pop      edi         // restore registers
  pop      esi
  pop      ebx

end; // get_cpu_type

himitsu 5. Jul 2012 19:36

AW: Inline ASM Funktion erweitern
 
Tipp: Ab zu den Jedi ... da gibt es ganze Klassensammlungen dazu und es kümmern sich Andere (die sich hoffentlich auskennen) um die Aktualität. :stupid:


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:35 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz