Detecting 186 CPUs
Detecting 186 CPUs
As a part of our CPU detection unit, I am writing a series of CPU detection units that deal with pre-386 CPUs. I am detecting 8088/8086/80286/386+ but the problem is that there doesn't seem to be much official documentation about how 186 CPUs have to be detected. I read somewhere that in 186, if you push SP and then pop it into a 16-bit register such as AX, the value of AX with the new value of SP will not be the same. In other words, when SP is pushed onto the stack, the value of [SP]-2 is pushed onto the stack so when it is popped onto, say, AX, AX will be equal to the current SP-2. Is this true? Does anybody have any official document (dis)proving this?
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
Hi,
Best way to distinguish between 8086 and 80286 is to use FLAGS register bits 12 through 15.
on 8086, FLAGS[12..15] are always set.
on 80286, FLAGS[12..15] are always clear in real-mode.
80186 is mostly same with 8086 with embedded market in mind. it has on-chip peripherals so that everything comes in one package ( dma, interrupt controller, timer etc... ) , no ALE pin ( address latch enable, 8086 users hate that CPU pin ) and following new instructions. AFAIK 80186 were not used much on personal computers.
some sources are:
Wiki:
http://en.wikipedia.org/wiki/Intel_80186
Intel:
http://www.intel.com/design/intarch/prodbref/272222.htm
Best way to distinguish between 8086 and 80286 is to use FLAGS register bits 12 through 15.
on 8086, FLAGS[12..15] are always set.
on 80286, FLAGS[12..15] are always clear in real-mode.
That is true, when pushing the SP register, 8086 uses the decremented value, 80186 uses the value before decrementing SP. but as I know, it cannot be used for clear distinguishing, since non-intel vendors are not clear about this. all vendors for 80286+ will do it the same way anyway but the SP issue exists for 80186.I read somewhere that in 186, if you push SP and then pop it into a 16-bit register such as AX, the value of AX with the new value of SP will not be the same. In other words, when SP is pushed onto the stack, the value of [SP]-2 is pushed onto the stack so when it is popped onto, say, AX, AX will be equal to the current SP-2. Is this true?
80186 is mostly same with 8086 with embedded market in mind. it has on-chip peripherals so that everything comes in one package ( dma, interrupt controller, timer etc... ) , no ALE pin ( address latch enable, 8086 users hate that CPU pin ) and following new instructions. AFAIK 80186 were not used much on personal computers.
so by your detection method, if you conclude that cpu is not 286, you might simply try using those new instructions and check for an error by using CPU unknown-opcode interrupt handler to determine if it is a 8086 or 80186.Wikipedia wrote: ENTER Make stack frame for procedure parameters
LEAVE High-level procedure exit
PUSHA Push all general registers
POPA Pop all general registers
BOUND Check array index against bounds
UD2 Generate invalid opcode exception
INS Input from port to string
OUTS Output string to port
some sources are:
Wiki:
http://en.wikipedia.org/wiki/Intel_80186
Intel:
http://www.intel.com/design/intarch/prodbref/272222.htm
Last edited by Cemre on Tue Feb 05, 2008 4:14 pm, edited 2 times in total.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
There are many sources for CPU detection, and many tests that can be done. Among them is indeed the SP test, but there are more tests that can tell cpu's apart without going for an exception.
But yes, I still have to come across this in an intel-signed documentThe 8086/88 and 80186/188 had a bug in the PUSH SP microcode. The 8086 and 80186 stored the value of SP on the stack after it was decremented, instead of decrementing SP first and storing the resultant value on the stack. Any program that executed PUSH SP and a subsequent POP SP would not receive the same value for the PUSH/POP combination. Therefore, this well-documented difference is exploited to detect the difference in these families of processors.
I really don't understand the reason to do detection for pre-386 cpus.
I cannot even find pre-Pentium cpus.
They exists only in museums.
I cannot even find pre-Pentium cpus.
They exists only in museums.
Keep coding...
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
I hear ya.. I own quite a few pre-Pentium systems myself... the oldest being a 286.Combuster wrote:That'd make my room a large museum. Great.Jef wrote:I really don't understand the reason to do detection for pre-386 cpus.
I cannot even find pre-Pentium cpus.
They exists only in museums.
Now I can charge my folks for entering my room
They're quite common here.. junk stores, garage sales.. etc..
It is your problem if you deny a known fact and says it is misinformation,Combuster wrote:It seems to me that you're actively trying to provoke flamewars.
To kick down the dungeon door: Don't post intential misinformation. Its the second time in a few days you posted something that goes directly against facts/consensus. Dont insult people. You have the right to remain silent.
If there is anyone here doing anything for giving intentional misinformation, that is you, not me. Which word of anything I posted here has misinformation?
Seriously, what do you carry in that vase of yours that you carry over your shoulders? Learn to respect someone if they know better than you...
Hahahahahahahahahahahahahahahahahahahahahahaha (breathes)... hahahahahahahahahahahahahaha, aww man, if it's not enough that you are blatently attempting to flame an admin in the most stuck up way, you're actually completely ignorant of your own stupidity. Just drop it.Cemre wrote:It is your problem if you deny a known fact and says it is misinformation,Combuster wrote:It seems to me that you're actively trying to provoke flamewars.
To kick down the dungeon door: Don't post intential misinformation. Its the second time in a few days you posted something that goes directly against facts/consensus. Dont insult people. You have the right to remain silent.
If there is anyone here doing anything for giving intentional misinformation, that is you, not me. Which word of anything I posted here has misinformation?
Seriously, what do you carry in that vase of yours that you carry over your shoulders? Learn to respect someone if they know better than you...
As for Pre-386 detection, the Flags method mentioned above is what i use in My bootloader, i have an old Compaq with a 8086 and it works fine. I'm pretty sure 80186 is basically the same processor.
EDIT: Actually, it might be an 8088... but still, the detection method is the same, external details (data bus size) shouldn't effect you.
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
I have a Vegas 8088 WITH hand drive and WITH color monitor,Brynet-Inc wrote:I hear ya.. I own quite a few pre-Pentium systems myself... the oldest being a 286.Combuster wrote:That'd make my room a large museum. Great.Jef wrote:I really don't understand the reason to do detection for pre-386 cpus.
I cannot even find pre-Pentium cpus.
They exists only in museums.
Now I can charge my folks for entering my room
They're quite common here.. junk stores, garage sales.. etc..
but i will never use it in the future. It just exists.
Keep coding...
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
...the sky is the limit
AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
I really don't think trying to throw an exception by using instructions that are introduced on new processors is a good way since I am going to use this code in the MBR and I will not have enough space for code to handle the interrupts and exceptions.
Intel's website doesn't seem to be much of help since their manuals are updated according to changes in their most recent CPUs and chipsets so no dice yet in finding a manual written for 186.
I found this source that also states the method of using SP to detect 186! I think this is the most prominent way of detecting 186 CPUs since nobody seems to have official documentations stating how 186 CPUs have to be detected
How did it crash? Didn't you just PUSH SP into the stack and POP it into a 16-bit register? How could it crash?Mathematician wrote:I well remember push sp/pop sp being the source of a bug in one of my programs. It worked fine on my AT, but crashed when somebody tested it on their XT.
Intel's website doesn't seem to be much of help since their manuals are updated according to changes in their most recent CPUs and chipsets so no dice yet in finding a manual written for 186.
I found this source that also states the method of using SP to detect 186! I think this is the most prominent way of detecting 186 CPUs since nobody seems to have official documentations stating how 186 CPUs have to be detected
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
Hi,
Cheers,
Brendan
Everybody here *should* have official Intel documentation that mentions that "PUSH SP" behaves differently on older CPUs...XCHG wrote:I think this is the most prominent way of detecting 186 CPUs since nobody seems to have official documentations stating how 186 CPUs have to be detected
Some web pages you might like: Note: Be careful - code that is meant to distinguish between different Intel CPUs normally stuffs up when it's run on a "non-Intel" clone...Intel's System Programming Guide wrote:18.14.1. PUSH SP
The P6 family, Pentium, Intel486, Intel386, and Intel 286 processors push a different value on the stack for a PUSH SP instruction than the 8086 processor. The 32-bit processors push the value of the SP register before it is decremented as part of the push operation; the 8086 processor pushes the value of the SP register after it is decremented. If the value is important, replace PUSH SP with the following three instructions:This code functions as the 8086 processor PUSH SP instruction on the P6 family, Pentium, Intel486, Intel386 and Intel 286 processors.Code: Select all
PUSH BP MOV BP,SP XCHG BP, [BP]
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.