Bona Fide OS Developer
View unanswered posts | View active topics It is currently Mon Jun 18, 2018 12:20 pm



Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
 is there a way to determine the cpu architecture in 16bit 
Author Message

Joined: Thu Jan 27, 2011 6:28 pm
Posts: 8
Post is there a way to determine the cpu architecture in 16bit
Hi I'm new to OS development but not new to programming, I'm building a hobby OS entirely in assembly and I was wondering if there's a way to determine whether the installed cpu is x86 or x64.
I am not sure if this is the correct topic category to post this in so I apologize if this needs to be moved.

Anyway my reason for needing to detect the cpu architecture is because my os is designed to dynamically run x86 or x64 code, but it needs to know which to run, and for that it needs to know the cpu architecture. I know I could do this by compiling a hardcoded list of cpu architectures but that would be time consuming compared to just getting on with coding the OS. Is there a specific code or bit I can check to see if the cpu is x86 or x64.

I appreciate any and all help anyone can provide, thanks in advance!

p.s. I've looked all over the internet via google & bing and I am either not educated enough or I genuinely can't find the related documentation for such information. I would also appreciate being pointer in the correct direction if I may have overlooked something, thanks.

p.p.s I am also sorry if this topic has already been covered I have not had time to check and would appreciate a link, thanks.


Thu Jan 27, 2011 6:34 pm
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post Re: is there a way to determine the cpu architecture in 16bi
You probably want the x86 CPUID http://www.intel.com/assets/pdf/manual/253666.pdf instruction.

be careful not to confuse people with Itaniums.

If you are worried about really old computers, you have to check if the CPUID instruction exists. My operating system is exclusively 64-bit, so people would have to be silly to try it on a 386 or earlier. I don't remember which CPU saw the introduction of the CPUID instruction but it was early.

You are insane to worry about computers with no CPUID instruction. You are insane to worry about an actual 8086 or 80286 or even 80386.


Fri Jan 28, 2011 2:22 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: is there a way to determine the cpu architecture in 16bi
The CPU that saw the introduction of the CPUID value, if I am not mistaken, was 8086. It tells you in Chapter 1 of Volume 1 of the Intel Architecture manuals. There is a brief history of changes to the Intel Architecture.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Fri Jan 28, 2011 11:19 am
Profile WWW

Joined: Thu Jan 27, 2011 6:28 pm
Posts: 8
Post Re: is there a way to determine the cpu architecture in 16bi
Thank you for your replies I am not actually entirely bothered about supporting old CPUs, only real mode architecture.

[EDIT]
P.S. does the cpuid instruction also work for AMD CPUs?
[/EDIT]


Fri Jan 28, 2011 11:51 am
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post Re: is there a way to determine the cpu architecture in 16bi
I think 386 or better has CPUID.

People on OSDev often sabotages people with bad advice. I think you are a victim or an abuser. For example, limiting real mode to 16-bit only instructions is absurd because every machine since 386s (1992 or so) has allowed 32-bit instructions in real mode.

On detecting 64-bit mode with the CPUID instruction, you have to detect if that bit exists, first. I don't bother because OSDev has copyrighted the code. My OS is 64-bit or better, so it's foolish to attempt to run it on that old of a machine, anyway.

(Copyrighted about 3 instructions. If you use them they want credit, even though you could figure-it-out-yourself. OSDev is as bad as GPL. Stay away.)

I'm not worried about any machine that doesn't have 64-bit mode. (2004 or so)


Sat Jan 29, 2011 10:34 pm
Profile

Joined: Thu Jan 27, 2011 6:28 pm
Posts: 8
Post Re: is there a way to determine the cpu architecture in 16bi
I've not been fooled by anyone, I am meerly using 16bit real mode as a safemode or for debugging, nothing else, I might not even include it it's just for reference.

Also there's always a way to code things differently than that which is copyrighted! ;)

Also my OS is meant to be a protected mode OS. And if you'd read my post in the project category you'd know why I need 32bit/64bit cross support. it's just easier to create a dynamic system than a static one in my experience.

Oh and as for something as petty as copyrighting assembly instructions it's illegal since they are owned by the respective CPU developer, not the programmers.


Sun Jan 30, 2011 4:43 am
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post Re: is there a way to determine the cpu architecture in 16bi
"16 bit real mode" allows 32-bit instructions, but uses a segmented memory model, not flat. This is true of all machines after 286.

The OSdev CPUID issue...

They were criticizing me because I didn't check for processors without extended CPUID bits. So, I put it in. They wanted credit, so I took it out, cause I don't need it. It won't run on ancient computers, anyway, so the difference is stupid people won't get an error message when it won't run.


In general, the way OSDev sabotages is by making you worry about the past instead of the future. They'll get you bogged down in details you don't need to worry about.

CHS disk blocks instead of LBA is an example. They will tell you to support both. CHS might be needed for floppies, but you shouldn't be worried about floppies.

They will give dreadful advice making you worry about ancient hardware.

I think their bootloader advice is dreadful. If you start with an OS like LoseThos to launch from, you can patch your bootloader with the LBA address of your 2nd stage module and its size.

I can't believe they tell people to do FAT12 or FAT16 instead of FAT32.

They suggest you boot with Grub already in 32-bit or 64-bit mode. You should change modes yourself. If you start in real mode, you can call BIOS routines for memory and Video mode.

on and on, I disagree with them.


Sun Jan 30, 2011 5:51 am
Profile
Site Admin

Joined: Fri Jul 24, 2009 10:02 pm
Posts: 247
Location: Las Vegas, NV, US
Post Re: is there a way to determine the cpu architecture in 16bi
losethos wrote:
I think 386 or better has CPUID.

People on OSDev often sabotages people with bad advice. I think you are a victim or an abuser. For example, limiting real mode to 16-bit only instructions is absurd because every machine since 386s (1992 or so) has allowed 32-bit instructions in real mode.

On detecting 64-bit mode with the CPUID instruction, you have to detect if that bit exists, first. I don't bother because OSDev has copyrighted the code. My OS is 64-bit or better, so it's foolish to attempt to run it on that old of a machine, anyway.

(Copyrighted about 3 instructions. If you use them they want credit, even though you could figure-it-out-yourself. OSDev is as bad as GPL. Stay away.)

I'm not worried about any machine that doesn't have 64-bit mode. (2004 or so)


Who is this 'OSDev' you are talking about? Copyrighting a small set of computer instructions is not possible. That sounds just absurd!


Sun Jan 30, 2011 10:26 pm
Profile

Joined: Fri Aug 20, 2010 10:04 pm
Posts: 41
Post Re: is there a way to determine the cpu architecture in 16bi
Umm... it's kind-of a delusional thing where I do stuff and they write about it as though they're watching. :oops:

Look at this horrible advice:

http://forum.osdev.org/viewtopic.php?f=1&t=23062

There is a size bit in page table entries which select between 2Meg and 4K. IA32e is long mode and it has nothing to do with PAE. There is one more level of heirarchy in IA32e mode. 2Meg instead of 4K is when you eliminate a level in the heirarchy. He was trying to eliminate two levels and use 1Gig size, I think... which is not allowed. (If it doesn't work.)

I cannot comprehend how you could do an operating system and not an editor!
http://forum.osdev.org/viewtopic.php?f=13&t=23057


Mon Jan 31, 2011 6:09 am
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post Re: is there a way to determine the cpu architecture in 16bi
Did they file for a copyright through the United States Copyright office? People think you can just slap on "Copyright <year> <name>" and that doesn't actually work in the US. It will keep people off of your stuff, but it's not copyright, especially since a copyright fee on code is somewhere in the hundreds (I know, I looked). Also I know for a FACT that you can't copyright anything in a single programming language. You copyright methods, datastructs, or algorithms in pseudo code, you don't copyright it in C or ASM, because the (c) will only protect the development of the code in that language. You want to be as abstract as possible when submitting a copyright. (I know, I have been there. I have attempted to copyright several works in the past under my company, and unfortunately all copyrights were denied for reasons of, "design too simple/common [considered public domain]", "abstraction required", etc.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Wed Feb 02, 2011 1:08 am
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.