CPU Properties
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
CPU Properties
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.
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 (8.28 KiB) Viewed 5865 times
Re: CPU Properties
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.
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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. Thanksneon 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.
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.
Re: CPU Properties
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.)
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();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
Oh, well thank you. I'll definitely take a look at that.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.
Edit:
And no worries, I know I can be hard to understand sometimes

-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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:
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:
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.
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
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?
I get a page fault @0x200000.
Because google doesn't read symbols I can't find what I'm looking for.
Re: CPU Properties
Code: Select all
xor dword [esp], 0x00200000
Code: Select all
xor $0x00200000, (%esp) // Or is this correct?
Those who understand Unix are doomed to copy it, poorly.
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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.Minoto wrote: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 dword [esp], 0x00200000
How would you tell gas the same thing? The manual can help you.Code: Select all
xor $0x00200000, (%esp) // Or is this correct?
-
- Member
- Posts: 5758
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Properties
The code you're using won't detect CPUID on some obsolete CPUs.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.
Try this part of the manual. But if you just want a quick summary, this might help.TheGameMaker90 wrote:Anybody know?
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 wrote:I get a page fault @0x200000.
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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.Octocontrabass wrote:The code you're using won't detect CPUID on some obsolete CPUs.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.
Try this part of the manual. But if you just want a quick summary, this might help.TheGameMaker90 wrote:Anybody know?
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 wrote:I get a page fault @0x200000.
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)
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 (8.57 KiB) Viewed 5675 times
Re: CPU Properties
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.
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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.
-
- Member
- Posts: 5758
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Properties
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:Is Pentium 4 one of them?
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 wrote:See the screenshot.
-
- Member
- Posts: 83
- Joined: Thu Jan 07, 2021 2:01 pm
Re: CPU Properties
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).Octocontrabass wrote: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:Is Pentium 4 one of them?
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 wrote:See the screenshot.
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.
-
- Member
- Posts: 5758
- Joined: Mon Mar 25, 2013 7:01 pm
Re: CPU Properties
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.TheGameMaker90 wrote:So if it should be returning the address of the instruction then it's way off.