flat assembler
Message board for the users of flat assembler.

Index > OS Construction > [solved] CPUID trouble

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
OK, let us all assume were in p-mode. I have been trying to get the CPUID according to
wikipedia all I have to do is make eax = 0 use the 'cpuid' instruction and it stores the
return stuff into ebx, ecx, and edx. I then have to store all this somewhere. But I cant
get it to work.

Here is my CPUID code.
Code:
  Mov   ESI, msg
  Call   PrintString
  Call    Get_CPUID
  Mov    ESI, _CPUID
  Call    PrintString
  jmp     $
Get_CPUID:
   Push  EAX  ; Save regs we need to use later on.
   Push  ECX
   Push  EDX
   xor   eax, eax   ; get vendor ID
   cpuid          ; CPUID will now be saved into EBX, ECX, and EDX. So we need to
                  ; store that, should not be to hard. :-/
   Mov   ESI, _CPUID  ; This is were we store the CPU ID for now Wink
   mov   DWORD [ESI], EBX
   mov   DWORD [ESI+4], ECX
   mov   DWORD [ESI+8], EDX
; OK, so that is done! Lets restore what regs we saved and blow this joint!
   Pop   EDX
   Pop   ECX
   Pop   EDX
   ret
;;;;;;;;;;;;;;;;;;;Data;;;;;;;;;;;;;;;;;;;
msg  db "CPUID: ",0
_CPUID db 0,0,0,0,0,0,0,0,0,0,0,0     


I can't seem to find what I am doing wrong, many other examples seem to do it
close to the same way. Pointers would be appropriated Very Happy

PS: I am just assuming user has a Pentium+ for now.

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)


Last edited by Coddy41 on 30 Jan 2010, 17:01; edited 1 time in total
Post 29 Jan 2010, 01:33
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
this a prints cpuname and small vend name in pmode:
hope this helps!
Code:
pusha
mov   eax,0       ; eax=0

cpuid

    
mov   [cpuname+ 12],ebx
mov   [cpuname+ 16],edx
mov   [cpuname+ 20],ecx
mov   [smallvendor],ecx
 
popa
  
mov   esi,cpuname
call print_string
  
mov   esi,spacer
call print_string
   
mov   esi,smallvendor
call print_string

jmp $

cpuname: db 'CPU VENDOR:             ',0
spacer: db " ",0
smallvendor dd ?
    


Last edited by dosin on 29 Jan 2010, 14:46; edited 1 time in total
Post 29 Jan 2010, 04:35
View user's profile Send private message Reply with quote
roboman



Joined: 03 Dec 2006
Posts: 122
Location: USA
roboman
Don't know much about cpuid, but does your PrintString choke if it's not 0 terminated?
Post 29 Jan 2010, 05:53
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
Watch your pushes and pops too
Code:
   Push  EAX  ; Save regs we need to use later on. 
   Push  ECX 
   Push  EDX 
;...
   Pop   EDX 
   Pop   ECX 
   Pop   EDX 
    
Post 29 Jan 2010, 06:05
View user's profile Send private message Reply with quote
tom tobias



Joined: 09 Sep 2003
Posts: 1320
Location: usa
tom tobias
hmm. EDX, EAX, hmm. Now where have we had this discussion before????

Yup, that's right, a single letter change, leading to an error, which is difficult to identify....difficult to debug....hahaha...

Proof is in the pudding.....

Smile
Post 29 Jan 2010, 12:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
When I first saw that the first person I thought of was tom tobias.

tom, thanks for not letting me down. Smile

So what should be do about this "problem"? Clearly it is not acceptable that one single letter change is allowed to make a program crash (regardless of whether it is in and xor or a push). Should we rename all the registers and opcodes to ensure a minimum possible Hamming distance?
Post 29 Jan 2010, 12:41
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
the single letter change is like the single DNA change.
it gives unpredictable results.

a way to push:pop regs is preferable
do them on a single line, with the 4 general registers.(not only 3).
Code:
push eax ebx excx edx
pop edx ecx ebx eax 
    

then, you just have to compare the lines, the first in forward order, the second in reverse order.

and if you are very lazy, you can do it with a macro

Code:
macro pushg32{
push eax ebx ecx edx
}
macro popg32{
pop edx ecx ebx eax
}
    


push eax ebx ecx edx is better because if you want to add a new functionality in your code, you can do it with ALL registers.
after, you do the optimisation with a reduced pushing/poping.

and all with lowercase chars is better because faster to write. Smile
Post 29 Jan 2010, 13:47
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
edfed: Have you ever seen the 'proc' macro?
Post 29 Jan 2010, 13:50
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
i know 'proc', but i don't use it.
never, i don't understand it... Sad
like 'struct'...
Post 29 Jan 2010, 13:52
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
edfed wrote:
i know 'proc', but i don't use it.
Then that is why you have to type everything twice.
Post 29 Jan 2010, 13:55
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4237
Location: 2018
edfed
revolution wrote:
edfed wrote:
i know 'proc', but i don't use it.
Then that is why you have to type everything twice.

cool, i'll give it a try one day. Smile

but it is an abstraction layer, no?
Post 29 Jan 2010, 14:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
edfed wrote:
but it is an abstraction layer, no?
Yes. Much the same as your pushg32/popg32 macros above.
Post 29 Jan 2010, 14:53
View user's profile Send private message Visit poster's website Reply with quote
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
roboman wrote:
Don't know much about cpuid, but does your PrintString choke if it's not 0 terminated?

Nah, It would probably just print a bunch of ascii characters to the screen until a 0 comes along.

Hmm, I fixed that push pop problem, but it still does not seem to work Confused

I have decided to do a re-write with it based from dosin's example.

EDIT: Funny, even dosin's example would not work in my OS, I am wondering if it is the
GDT I am using, I am going to wright my own and see. I'll post back if it works Confused

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)
Post 29 Jan 2010, 17:05
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Also i made one for MM testing... (still not complete)
http://board.flatassembler.net/topic.php?t=10708
Post 29 Jan 2010, 17:21
View user's profile Send private message Reply with quote
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
Wow I did a search on the fasm board on 'CPUID' before making this thread and I do not
think I saw that one =/ Thanks I'll study it as I wanted to test for MMX Smile

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)
Post 29 Jan 2010, 17:28
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
What you could do - is make a dex os app that will display it..
since dex os is in pmode and have all the functions you need ...print string ect..

once you have it to print what you want - and working right.. transfer to your os.. then if its still not working.. look at the functions your using - your print text... gdt... pmode code... ect.
Post 29 Jan 2010, 19:30
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
Dex already have that program written (CPUID.DEX)
Maybe he would be kind enough to share the sources Smile
Post 29 Jan 2010, 19:51
View user's profile Send private message Reply with quote
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
@dosin: It works in DexOS wich is weird, Im going to check the rest of my code
and see if that works.

@bitshifter: Atually, the CPUID source is posted on the DexOS forums, do a search
of "CPUID not working" The code has a bug, but if you know what you are doing there
is a post that tells you the problem Wink

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)
Post 29 Jan 2010, 21:09
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin
if you have a print char function you can try that and see if it has the vender name stored - just print one char at a time..

if it works than there may be something in your printstring...

if still nothing .. it could be something with your GDT segment set up...
your data segs.. or something..


Code:
call get_cpuid_info

mov al,byte[cpuname+ 12]
call print_char
mov al,byte[cpuname+ 13]
call print_char
mov al,byte[cpuname+ 14]
call print_char
ect...
    
Post 29 Jan 2010, 23:40
View user's profile Send private message Reply with quote
Coddy41



Joined: 18 Jan 2009
Posts: 384
Location: Ohio, USA
Coddy41
My printstring works fine after dex pointed out the problem (see here http://dex.7.forumer.com/viewtopic.php?p=5812#5812)

But it does not hurt to try... I got my same result Sad
Image

_________________
Want hosting for free for your asm project? You can PM me. (*.fasm4u.net)
Post 30 Jan 2010, 00:28
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.