Author Topic: Solutions to save 1/2 CPU registers inside a procedure  (Read 918 times)

jj2007

  • Member
  • *****
  • Posts: 8845
  • Assembler is fun ;-)
    • MasmBasic
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #15 on: June 05, 2018, 04:01:08 AM »
zedd151 say that it doesnt identify the frequency of his CPU
The PrintCpu macro shows the brand string supplied by the CPU through cpuid. The real frequency may differ from that (although it shouldn't...).

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #16 on: June 05, 2018, 06:04:56 AM »
Quote from: RuiLoureiro
but zedd151 say that it doesnt identify the frequency of his CPU (AMD ?)


Yup, if you notice what it does say about my cpu, notice how long the description is...

Quote
AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (SSE4)


 A little "over-the-top" description if I say so myself.
They could have done without the "5 COMPUTE CORES 2C+3G" part. My cpu has 2 cores, no matter how they try to inflate the description to make it sound better, even magical.   8)

Quote from: jj2007
The PrintCpu macro shows the brand string supplied by the CPU through cpuid. The real frequency may differ from that (although it shouldn't...).

The specs list my cpu speed as 1.60 Ghz. It fluctuates a little, but nothing to write home about. It IS a little netbook after all.
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

RuiLoureiro

  • Member
  • ****
  • Posts: 819
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #17 on: June 05, 2018, 07:15:12 AM »
Hi zedd151,
                 As you are seeing i am trying to solve the CPU identification  problem and i am sure that Jochen may solve it, he is the author of the that code and i trust him.
Thanks for your work.         

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #18 on: June 05, 2018, 07:38:22 AM »
Quote from: RuiLoureiro
As you are seeing i am trying to solve the CPU identification  problem and i am sure that Jochen may solve it

Quote from: JJ
The PrintCpu macro shows the brand string supplied by the CPU through cupid

Therefore he may not be able to solve my case. The string for my cpu apparently is longer than anticipated by cupid. Still there may be a work around for these special cases. I'm always a special case it seems.   :P

This is what is displayed in 'System' info...
« Last Edit: July 19, 2018, 04:42:34 PM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

felipe

  • Member
  • ****
  • Posts: 971
  • Eagles are just great!
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #19 on: June 05, 2018, 08:00:49 AM »
I know there's an option in the bios configurations regarding a max number used with the cpuid instruction, but i don't know now (i don't want to reboot now  :biggrin:) if it has something to do with the "big string identification" issue... :idea:
Felipe.

RuiLoureiro

  • Member
  • ****
  • Posts: 819
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #20 on: June 05, 2018, 08:31:58 AM »
 :biggrin:
zedd151,
          If you say "he may not be able to solve my case" the case seems to be solved.
          What can we do ?
Regards
 :icon14:

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #21 on: June 05, 2018, 08:34:25 AM »
 :biggrin:

Rui

LOL


 :P

Next time I'll trade this one in for one with a cpu with a short name.   (i286)  lol
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

jj2007

  • Member
  • *****
  • Posts: 8845
  • Assembler is fun ;-)
    • MasmBasic
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #22 on: June 05, 2018, 08:52:57 AM »
The string for my cpu apparently is longer than anticipated by cupid.

The PrintCpu macro has a 124 byte buffer, your string is only about 50 bytes long. I'd love to see in a debugger what's actually happening there...

From the manuals: The brand string is architecturally defined to be 48 byte long: the first 47 bytes contain ASCII characters and the 48th byte is defined to be null (0).

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #23 on: June 05, 2018, 09:05:38 AM »
Aha! Maybe.

"AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (SSE4)" is 54 bytes long.
Possibly the cpu speed is overwritten by "(SSE4)" ???

anyway I'll run the testbed through xdbg to see what's happening there, when I get a few minutes to spare.

***** a little while later ******


I used a testbed with smaller code and found that "AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   " is written first. Did not find 1.60 Ghz get written anywhere. The (SSE4) was appended later in the console window. the reason I did not use the testbed from this thread is because it takes an eternity to run in a debugger.

JJ could you write a small piece that only displays my cpu info, as in the testbed in this thread?

Would make debugging a lot easier with less code to wade through.  I will post those results from x32dbg as well as screen shots of the debugging.

« Last Edit: June 05, 2018, 11:03:13 AM by zedd151 »
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

jj2007

  • Member
  • *****
  • Posts: 8845
  • Assembler is fun ;-)
    • MasmBasic
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #24 on: June 05, 2018, 04:49:59 PM »
JJ could you write a small piece that only displays my cpu info, as in the testbed in this thread?

I suspect that your CPU doesn't follow the specs saying the brand string is up to 48 bytes long, including the zero delimiter. In fact, the PrintCpu macro is designed to yield 48 characters. The attached variant allows up to 112 bytes, but I wonder if it works with old CPUs.

Here is the relevant part:
Code: [Select]
sub esp, 124 ; create a buffer for the brand string
mov edi, esp ; point edi to it
xor ebp, ebp
.Repeat
lea eax, [ebp+80000002h]
db 0Fh, 0A2h ; cpuid 80000002h-80000004h
stosd
mov eax, ebx
stosd
mov eax, ecx
stosd
mov eax, edx
stosd
inc ebp
.Until ebp>=3+pcup

pcup is for testing your case. The first string (pcup=0) is obtained with 3x4xstosd, i.e. 48 bytes, the second (pcup=2) with 5*4*stosd, 80 bytes. We'll see how that changes the output. Note that when I wrote "from the manual" above, it was probably an Intel manual 8)

sinsi

  • Member
  • *****
  • Posts: 1085
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #25 on: June 05, 2018, 05:16:28 PM »
From the AMD manual
Quote
The three extended functions from Fn8000_0002 to Fn8000_0004 are initialized to and return a null terminated
ASCII string up to 48 characters in length corresponding to the processor name. (The 48 character maximum
includes the null character.)

Quote
The processor name string must be programmed by the BIOS during system initialization.

Anyway, how can you get more than 48 bytes from 3 CPUID calls returning 16 bytes each?
I can walk on water but stagger on beer.

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #26 on: June 05, 2018, 05:39:12 PM »
Thanks jochen.

Here is my results with the test piece you posted:

Code: [Select]
AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX)
AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AVX)
AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G

Then the program hangs until a key is pressed (enter) then disappears.
Is that what was supposed to happen, or was there more if I waited?

*---------------------------

I will look into this a little more later. I am getting ready for work at the moment.
I'll give another crack to try and determine if there's anything I can do on my end.

ps. sorry for the hijack, Rui
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

jj2007

  • Member
  • *****
  • Posts: 8845
  • Assembler is fun ;-)
    • MasmBasic
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #27 on: June 05, 2018, 05:54:46 PM »
"AMD A6-9220e RADEON R4, 5 COMPUTE CORES 2C+3G   (SSE4)" is 54 bytes long.
Possibly the cpu speed is overwritten by "(SSE4)" ???

OK, now I understand the problem: Your brand string is actually 45 bytes long. You didn't find the frequency, and the reason is simply that your cpu doesn't list it in the brand string. Some do, others don't 8)

The SSExx stuff is added later and has nothing to do with the brand string.

@sinsi: See above, .Until ebp>=3+pcup was just a test if the AMD has additional bits & pieces. It doesn't.

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #28 on: June 05, 2018, 05:55:41 PM »
I just looked at the source snippet

Code: [Select]
  Inkey Str$("\n\nYour puter has run %3f hours since the last boot, give it a break!", Timer/3600000

LMAO! I can't wait for that at the present time.   :biggrin:
I'm not always the sharpest knife in the drawer, but I have my moments.  :P

zedd151

  • Member
  • ****
  • Posts: 850
Re: Solutions to save 1/2 CPU registers inside a procedure
« Reply #29 on: June 05, 2018, 05:58:10 PM »
Quote from: jj2007
... your cpu doesn't list it in the brand string. Some do, others don't 8)

Wtf. I'm always coming up short in one way or another.   :P
Well for the price I paid for this humble box, I can't complain too much.  8)

I have a notion to write a strongly worded letter to Dell Computers.   :badgrin:


edit to add:
Quote from: jochen
The SSExx stuff is added later and has nothing to do with the brand string.

as verified by my initial debugging
I'm not always the sharpest knife in the drawer, but I have my moments.  :P