OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:30 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: CPU Properties
PostPosted: Tue May 25, 2021 10:13 am 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
Hello again,
How would one detect things like the number of CPU cores, temperature, id, and frequency?

I currently have in my my main OS, CPUID and I can detect the manufacturer (on bare metal detects "AUTHENTICAMD" and "GENUINEINTEL"), but I want more information from my system to print to my terminal so I know that it works. What are the steps to take?

Thanks.


Attachments:
Capture.PNG
Capture.PNG [ 8.28 KiB | Viewed 4193 times ]
Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 10:24 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hi,

This is starting to enter non trivial territory here. CPU cores / ID's are obtained from the IOAPIC and per-CPU local APIC. Temperature sensor reading I believe is motherboard chipset specific: you aren't going to find any standard there. There is also ACPI but that is very, very far away.

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 10:30 am 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
neon wrote:
Hi,

This is starting to enter non trivial territory here. CPU cores / ID's are obtained from the IOAPIC and per-CPU local APIC. Temperature sensor reading I believe is motherboard chipset specific: you aren't going to find any standard there. There is also ACPI but that is very, very far away.


Well I did a quick google search before asking to no avail, but I will take a look at the terms you posted. As for CPU temp, I wanted that for performance reasons but I can do without for now. Thanks

Edit:
Yeah just realized I said cpu id as well. If I didn't already have that then I wouldn't be able to detect vendor string, lol.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 10:43 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
Hi,

Er, sorry, I should have realized you meant CPU thermal monitoring not motherboard sensors. That would be section 3B System Manual Part 2 of the Intel manuals - 14.8 discusses CPU thermal management. The APIC is also discussed in the manuals as local APIC's are a CPU feature and the IOAPIC for IPI's (used for multiprocessing.)

_________________
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 10:47 am 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
neon wrote:
Hi,

I'd also encourage reading through section 3B System Manual Part 2 of the Intel manuals - 14.8 discusses CPU thermal management.


Oh, well thank you. I'll definitely take a look at that.

Edit:
And no worries, I know I can be hard to understand sometimes :D


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 8:15 pm 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
Okay so all day I've been catching up on my reading and I've decided that I want to take a small break from it to catch up a bit on my code.
I can't remember the source exactly, but I found this example to check if CPUID is supported and I want to convert NASM assembly to GAS.
Here is what I don't know out of it:
Code:
xor dword [esp], 0x00200000


How would that be represented in GAS syntax?
An example or link please, and thank you.

Would I be wrong in assuming I'd just get rid of the "dword" and do something like this:
Code:
xor $0x00200000, (%esp)    // Or is this correct?


Okay I tried it and that failed. Anybody know? Or at least a good GAS assembly tutorial? I'm better in NASM assembly, but I want to switch over.
I get a page fault @0x200000.

Because google doesn't read symbols I can't find what I'm looking for.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 9:09 pm 
Offline
Member
Member
User avatar

Joined: Thu May 12, 2011 7:24 pm
Posts: 89
Code:
xor dword [esp], 0x00200000

Why is "dword" needed in this line? What is it telling the assembler that it can't determine from the operands?

Code:
xor $0x00200000, (%esp)    // Or is this correct?

How would you tell gas the same thing? The manual can help you.

_________________
Those who understand Unix are doomed to copy it, poorly.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 9:13 pm 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
Minoto wrote:
Code:
xor dword [esp], 0x00200000

Why is "dword" needed in this line? What is it telling the assembler that it can't determine from the operands?

Code:
xor $0x00200000, (%esp)    // Or is this correct?

How would you tell gas the same thing? The manual can help you.


Ah yes, the manual. I was on that page earlier. If you would, please point me to where I might find what I'm looking for. I don't see anything about converting NASM to GAS. Thanks.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Tue May 25, 2021 9:42 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
TheGameMaker90 wrote:
I can't remember the source exactly, but I found this example to check if CPUID is supported and I want to convert NASM assembly to GAS.

The code you're using won't detect CPUID on some obsolete CPUs.

TheGameMaker90 wrote:
Anybody know?

Try this part of the manual. But if you just want a quick summary, this might help.

TheGameMaker90 wrote:
I get a page fault @0x200000.

Is that really the faulting instruction? I don't see how it could be, since the only memory access is relative to the stack pointer, and surely you've accessed memory relative to the stack pointer before this point.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 12:49 pm 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
Octocontrabass wrote:
TheGameMaker90 wrote:
I can't remember the source exactly, but I found this example to check if CPUID is supported and I want to convert NASM assembly to GAS.

The code you're using won't detect CPUID on some obsolete CPUs.

TheGameMaker90 wrote:
Anybody know?

Try this part of the manual. But if you just want a quick summary, this might help.

TheGameMaker90 wrote:
I get a page fault @0x200000.

Is that really the faulting instruction? I don't see how it could be, since the only memory access is relative to the stack pointer, and surely you've accessed memory relative to the stack pointer before this point.


Is Pentium 4 one of them? I plan to have this OS run on an old Dell once I finish it. It'll be a complete system restoration since it's old.
I'll take a look.
And yes. See the screenshot.

Edit:
Okay, I scanned these documents and I'm sure they'll prove useful, but I just want to know what (if anything) is supposed to go in front of
Code:
xorl $0x00200000, (%eax)


I can't find anything on that and the only [close to useful] GAS assembly tutorial I could find was this: https://cs.lmu.edu/~ray/notes/gasexamples/
The other was a video tutorial series that ended at like episode 3, and most others are Linux specific and un-useful PDF's


Attachments:
Capture.PNG
Capture.PNG [ 8.57 KiB | Viewed 4003 times ]
Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 1:52 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
I think there is a fundamental flaw in your thinking process. On this thread and others I've noticed that you essentially want a step-by-step solution or something kinda like that. The problem is that in this line of work your not really going to find that anywhere. You might for some things, like multitasking, but typically for other things (e.g. PCI or NVMe) your going to need to invent your own way of doing things. As an example, the NVMe specification tells you how to initialize the controller, but in a very abstract manner. What it doesn't tell you is how to parallelize accesses to take full advantage of the power of the controller, for example. Other manuals follow a similar process -- they might give you a step-by-step for things but the majority of things is "This is the data layout of a network controller, figure out how to actually use it on your own". So, essentially what I'm trying to say is OSDev is very inference-based. There are tutorials and guides on some things, but on other things, you only have manuals/specs at your fingertips and you have to figure out a solution on your own. That isn't to say that we won't be able to help you on here, but I just thought I might provide a bit of help with that in case I'm right. But even if I'm wrong, I hope this helps anyway.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 2:15 pm 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
I can respect that, but I think you have it wrong. I just want the equivalent code for GAS. There are a few holes in my knowledge as I am all self taught. I'm asking for a translation or pseudo code of NASM to GAS. Not how to do anything per se.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 2:18 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
TheGameMaker90 wrote:
Is Pentium 4 one of them?

No. It's not an issue with any Intel or AMD CPUs, so if you're only using those then you don't have to worry about it.

TheGameMaker90 wrote:
See the screenshot.

Your screenshot shows the address of the access that caused the fault. It does not show the address of the instruction that caused the fault. You need the address of the instruction that caused the fault. (Here's a hint: it's one of the values the CPU automatically pushes onto the stack when an exception happens.)


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 4:42 pm 
Offline
Member
Member

Joined: Thu Jan 07, 2021 2:01 pm
Posts: 67
Octocontrabass wrote:
TheGameMaker90 wrote:
Is Pentium 4 one of them?

No. It's not an issue with any Intel or AMD CPUs, so if you're only using those then you don't have to worry about it.

TheGameMaker90 wrote:
See the screenshot.

Your screenshot shows the address of the access that caused the fault. It does not show the address of the instruction that caused the fault. You need the address of the instruction that caused the fault. (Here's a hint: it's one of the values the CPU automatically pushes onto the stack when an exception happens.)


Whew! Good, hopefully when I finish writing my bootloader I'll be able to run it (I think the Intel PC I have can't use GRUB. It was manufactured circa 2007).

Okay that I understand. So if it should be returning the address of the instruction then it's way off. Perhaps it's being done incorrectly, or maybe my paging system needs to be updated. It was a plan of mine to rewrite parts of my kernel (most of it is old/buggy/could be done better) anyway. I will switch back to the [working] NASM version for now.


Top
 Profile  
 
 Post subject: Re: CPU Properties
PostPosted: Wed May 26, 2021 5:13 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
TheGameMaker90 wrote:
So if it should be returning the address of the instruction then it's way off.

No, it should print a whole bunch of things, not just a single address. The information you need to debug your CPUID code is the address of the faulting instruction, but you will need different information to debug different issues.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 53 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group