LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2005, 02:28 AM   #1
arunka
Member
 
Registered: Mar 2005
Posts: 60

Rep: Reputation: 15
CPU register test


hI ALL
can any one sugest how to verify that CPU registers are working properly in C under linux..
like i need to check and make sure the the registers of my CPU are working fine??

Thanks in advance..

Arun
 
Old 10-03-2005, 03:56 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Under C? No. You would need to write assembly code for that. C does provide a "register" storage class for variables. However, it does not allow the programmer to specify which register, and it does not guarantee the register request will be granted. Even if C allowed that, it would only be able to test general purpose registers. There would be no direct tests for the program counter, error status, or other special purpose registers.

If you're just worried that something might be wrong, don't. If a register in the processor was broken or misbehaving, I seriously doubt your computer would boot at all. I mean, we're talking near-impossible to have a functional computer with a bad register.
 
Old 10-03-2005, 09:09 AM   #3
Brian Knoblauch
Member
 
Registered: Jan 2005
Distribution: OpenSuse Tumbleweed
Posts: 288

Rep: Reputation: 39
If you had a bad register, you would not be able to get anywhere at all. If you still feel the need to test them, the best way (simplest) is to write some assembly code for real mode, boot into DOS and do it that way. You won't be able to test all of them.
 
Old 10-03-2005, 10:03 AM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Quote:
In an email from arunka
i think that we can embeded the assembly and C using asm() function...
Through this can we have our register test performed..
Do u have any idea of how we can use the asm().
Maybe the point I was trying to make isn't completely clear. The entire functional code would need to be in assembly to do this test. Not some, not most, but all of it. It doesn't make any sense to wrap it in C. It would be the same thing as using C with nothing but system() calls to implement a shell script. It just doesn't make sense to use C. If you have the knowledge to write the assembly, then just do it in assembly... forget about C.

And to reiterate the other point, if you have a broken register, you will not have a functional computer, which implies you wouldn't be able to compile the program in the first place.

Trust me, you would have serious problems with a broken register.

Lastly, according to the reference book I have (Programmer's Reference: C/C++ Second Edition), the asm keyword is supported only by C++. The book includes the C99 standard, so that leads me to believe it's still current. If gcc supports the asm keyword in standard C, and you are absolutely intent on doing this, then you'll need to find some documentation on what format gcc requires for assembly instructions.
 
Old 10-03-2005, 10:27 AM   #5
Brian Knoblauch
Member
 
Registered: Jan 2005
Distribution: OpenSuse Tumbleweed
Posts: 288

Rep: Reputation: 39
If I was going to do it in C, I'd just create an executable string which would have the machine code in it. Pretty silly though. C is just the wrong tool, like using a screwdriver to drill a hole in the wall (yeah, I've done that)
 
Old 10-03-2005, 11:47 PM   #6
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Here's some code I wrote in 1999. You may do anything with it.

I still don't know what you're trying to do. It would be easy to make a function that returns the value of any register. It wouldn't be portable though. The asm keyword may be used too. Just browse some crypto code, ie openssl, gnupg, libgcrypt, mcrypt, libmcrypt, et cetera

compile with "gcc showreg.s"

Code:
#
# showreg
#   Shows the contents of 32-bit registers
#
# (!c) 1999
#

        .section        .rodata
EAX:
        .string "EAX = %0.8X\n"
EBX:
        .string "EBX = %0.8X\n"
ECX:
        .string "ECX = %0.8X\n"
EDX:
        .string "EDX = %0.8X\n"
ESI:
        .string "ESI = %0.8X\n"
EDI:
        .string "EDI = %0.8X\n"
EBP:
        .string "EBP = %0.8X\n"
ESP:
        .string "ESP = %0.8X\n"
EIP:
        .string "EIP = %0.8X\n"
CS:
        .string " CS = %0.4X\n"
DS:
        .string " DS = %0.4X\n"
ES:
        .string " ES = %0.4X\n"
FS:
        .string " FS = %0.4X\n"
GS:
        .string " GS = %0.4X\n"
SS:
        .string " SS = %0.4X\n"

        .text
        .align 4

.globl main
        .type    main,@function
main:
        pushl %eax
        pushl $EAX
        call printf

        pushl %ebx
        pushl $EBX
        call printf

        pushl %ecx
        pushl $ECX
        call printf

        pushl %edx
        pushl $EDX
        call printf

        pushl %esi
        pushl $ESI
        call printf

        pushl %edi
        pushl $EDI
        call printf

        pushl %ebp
        pushl $EBP
        call printf

        addl $56, %esp  # Resetear %esp por 14 pushl's

        pushl %esp
        pushl $ESP
        call printf

        xorl %eax, %eax # movl $0, %eax
        movw %cs, %ax
        pushl %eax
        pushl $CS
        call printf

        xorl %eax, %eax
        movw %ds, %ax
        pushl %eax
        pushl $DS
        call printf

        xorl %eax, %eax
        movw %es, %ax
        pushl %eax
        pushl $ES
        call printf

        xorl %eax, %eax
        movw %fs, %ax
        pushl %eax
        pushl $FS
        call printf

        xorl %eax, %eax
        movw %gs, %ax
        pushl %eax
        pushl $GS
        call printf

        xorl %eax, %eax
        movw %ss, %ax
        pushl %eax
        pushl $SS
        call printf

        addl $56, %esp  # Resetear %esp

        call dummy      # pushl %eip
 dummy: pushl $EIP
        call printf
        addl $8, %esp

        xorl %eax, %eax
        ret

Last edited by primo; 10-03-2005 at 11:55 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU/Memory stress test twantrd Programming 2 11-12-2005 08:49 PM
Test tool of CPU in linux.... do any one has any idea.. rajsun Programming 4 04-03-2005 06:47 AM
FC4 Test 1 CD Test failes every DISC Jimbo99 Linux - Software 1 03-18-2005 03:16 PM
CPU stress test CTRLBREAK Linux - Hardware 2 02-24-2005 07:21 PM
Writing a CPU Consume Program to Test a Distributed System russelh Programming 4 11-30-2004 02:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration