| ▲ | Why is the x86 undefined instruction called ud2? Why 2?(devblogs.microsoft.com) |
| 84 points by ibobev 5 hours ago | 27 comments |
| |
|
| ▲ | hacker_homie 38 minutes ago | parent | next [-] |
| Thus finally the 0F FF believers were rewarded by being give the honor of op code UD0 making it the one and true original invalid opcode permanently disgracing the 0F B9 adherents with the shame of UD1. |
|
| ▲ | 349ru3h4f03 2 hours ago | parent | prev | next [-] |
| Nowadays UD0 UD1 UD2 are in the SDM and APM. We also got UDB (D6), the one-byte variant that arrived with x86-64 for 64-bit mode. And we have always had UDW (FF FF), aka group #5 (1st FF) with a modrm byte of mod=11b r/m=111b (/7) reg=111b (2nd FF) -- that one matters for memory with all bits set to 1, or for buses terminated to all 1 when no device claims an access. |
| |
|
| ▲ | ordu an hour ago | parent | prev | next [-] |
| > It’s called ud2 because the 0F FF variant was retroactively named ud0, and the 0F B9 variant was retroactively named ud1, leaving ud2 as the recommended undefined opcode. It was a surprise for me as a reader. When I came to this sentence I assumed that 0f ff would become #1 and 0fb9 -- #2. But no, Intel counts from zero, so there is a third ud. |
|
| ▲ | Neywiny 3 hours ago | parent | prev | next [-] |
| I'm not much of an x86 person but on other architectures you can raise software interrupts/exceptions. Does x86 not have this or did those facilities not cover enough use cases? |
| |
| ▲ | js8 2 hours ago | parent | next [-] | | It's basically a convention. The alternative is to raise interrupts of course, but that might be application specific, or use other invalid instructions than the designated one, but they might work differently on other processor types. | |
| ▲ | omoikane 2 hours ago | parent | prev | next [-] | | Maybe because if the code wants to call the invalid opcode interrupt handler (INT6), it needs extra code to populate the flags and registers expected by that handler, whereas actually triggering an invalid opcode exception will get all those parameters populated automatically. | |
| ▲ | 349ru3h4f03 2 hours ago | parent | prev [-] | | x86 has... INT Ib
INT1
INT3
INTO
BOUND |
|
|
| ▲ | qbane 2 hours ago | parent | prev | next [-] |
| It's like why the first (hard) drive letter is C. |
| |
| ▲ | cyanydeez 2 hours ago | parent [-] | | A: drive is 3.5; B: drive is 5.25; C: drive is hard disk | | |
| ▲ | dspillett an hour ago | parent | next [-] | | A: and B: were not specific to the type of drive. It was common to have two drives before fixed storage became common, often you would have the application disk in one and your data disk in the other though there were other common use patterns for two drives also (with the OS, or at least the core of it, resident in memory you can copy and otherwise manage data over two data disks, and so on). The first hard-drive in a system was made C: to reserve A: and B: in part because there was software out there that assumed A: and B: were floppy drives and could cause problems if something else was allocated to those signifiers. There are many things that are due to long forgotten compatibility issues like this (try naming file LPT1 under Windows to see another). Another reason is that the BIOS on many PCs was just hard-wired to assume two floppy drives so DOS would see that even if there were no drives really there. | | |
| ▲ | cesarb an hour ago | parent | next [-] | | From what I recall from the time I still used MS-DOS, even if you only have one floppy disk drive, it's accessible as both A: and B: and it prompts you to insert the other floppy disk when you change the drive letter. That is, it's "virtualizing" two floppy disk drives using a single physical one. That explains why the first hard disk drive was always C: even when you only had one floppy disk drive (and of course you had at least one floppy disk drive, how could you use a computer without one?) | | |
| ▲ | Sharlin 17 minutes ago | parent [-] | | Which is very convenient (and necessary for backwards compatibility) because programs could be (and were) written to assume they're in B: (and the DOS disk is in A:), or that they're in A: and the user's data is in B:, or a two-disk program is in both. All of that just worked (tm) even with a single drive, as long as the program didn't try to interleave accesses to both drives (I think it would still work because DOS was single-process, single-thread, it would just annoy the user!) |
| |
| ▲ | brewmarche an hour ago | parent | prev [-] | | I thought MS-DOS had special handling for A: and B: since it allowed you to copy from A: to B: even with just one floppy drive. | | |
| |
| ▲ | compiler-guy 2 hours ago | parent | prev | next [-] | | Even further back into time, before 3.5" disks, both A: and B: were 5.25" disks. And, although my memory is hazy, 3.5's were commonly slotted into B: at first, because no one had 3.5" boot disks until the drives became somewhat common. | | |
| ▲ | raldi 30 minutes ago | parent | next [-] | | The floppies got A and B because hard drives were expensive and for a time a lot of people got by without them, though everybody had at least one floppy. Even if you only had one floppy, it was both A and B, so you could say "copy a:DOC.TXT b:" and it would read the doc and then ask you to insert the floppy you're considering B (and depending on file size and available memory, sometimes switch back and forth a few more times) | |
| ▲ | gumby an hour ago | parent | prev [-] | | You are forgetting 8” floppies. IBM used only the soft sector ones (one hole punched close to the spindle to mark sector 0) but there were also hard sector ones (a ring of 32 holes close to the spindle hole). There was a lot of experimentation back in those days. The Wikipedia’s page on floppy disks is surprisingly long! | | |
| ▲ | jasomill 21 minutes ago | parent | next [-] | | Floppies, superfloppies, removable hard disks (platter-only, as opposed to modern external hard drives that incorporate the entire drive mechanism), magneto-optical disks, rewritable CD/DVD, even today magnetic tape is still used as removable storage in applications where large capacity is required and shelf life is more important than fast random access. | |
| ▲ | compiler-guy 25 minutes ago | parent | prev [-] | | Trust me, I will never forget 8" floppies. But in the context of drive lettering, although CP/M supported 8" floppies, MS-DOS never did. MS-DOS adopted the naming scheme, but not the boot style. |
|
| |
| ▲ | alightsoul 2 hours ago | parent | prev [-] | | Yeah it's a relic from when computers booted off floppy and hard disks were rare and expensive |
|
|
|
| ▲ | dataflow 2 hours ago | parent | prev | next [-] |
| Is this just his speculation? Or is there evidence for it? |
| |
| ▲ | dspillett an hour ago | parent [-] | | What the instruction does is well documented, and the history of other invalid instructions being used for the same purpose in the past I'm guessing there is also well known, though a quick search doesn't turn up any official Intel documentation on the matter. Given who this is and the overall quality of his output over the years, I'm willing to trust it isn't pure guesswork - and anyway, I'd trust his guesswork over many other people's absolute facts. |
|
|
| ▲ | zero-sharp an hour ago | parent | prev [-] |
| If you look at the intel instruction manual, you do see UD0 and UD1. This isn't specific to Microsoft. You would probably have to ask the cpu engineers who made the decision to add those instructions in? |
| |