CPU Properties

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

CPU Properties

Post by TheGameMaker90 »

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 5872 times
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: CPU Properties

Post by neon »

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();}
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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.
User avatar
neon
Member
Member
Posts: 1568
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: CPU Properties

Post by neon »

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();}
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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: Select all

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: Select all

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.
User avatar
Minoto
Member
Member
Posts: 89
Joined: Thu May 12, 2011 7:24 pm

Re: CPU Properties

Post by Minoto »

Code: Select all

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: Select all

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.
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

Minoto wrote:

Code: Select all

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: Select all

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.
Octocontrabass
Member
Member
Posts: 5758
Joined: Mon Mar 25, 2013 7:01 pm

Re: CPU Properties

Post by Octocontrabass »

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.
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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: Select all

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 5682 times
Ethin
Member
Member
Posts: 625
Joined: Sun Jun 23, 2019 5:36 pm
Location: North Dakota, United States

Re: CPU Properties

Post by Ethin »

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.
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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.
Octocontrabass
Member
Member
Posts: 5758
Joined: Mon Mar 25, 2013 7:01 pm

Re: CPU Properties

Post by Octocontrabass »

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.)
TheGameMaker90
Member
Member
Posts: 83
Joined: Thu Jan 07, 2021 2:01 pm

Re: CPU Properties

Post by TheGameMaker90 »

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.
Octocontrabass
Member
Member
Posts: 5758
Joined: Mon Mar 25, 2013 7:01 pm

Re: CPU Properties

Post by Octocontrabass »

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.
Post Reply