Why is the x86 undefined instruction called ud2? Why 2?

(devblogs.microsoft.com)

55 points | by ibobev 4 hours ago

4 comments

  • 349ru3h4f03 1 hour ago
    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.

  • Neywiny 1 hour ago
    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?
    • omoikane 31 minutes ago
      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.
    • js8 1 hour ago
      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.
    • 349ru3h4f03 1 hour ago
      x86 has...

      INT Ib INT1 INT3 INTO BOUND

  • qbane 42 minutes ago
    It's like why the first (hard) drive letter is C.
    • cyanydeez 39 minutes ago
      A: drive is 3.5; B: drive is 5.25; C: drive is hard disk
      • dspillett 14 minutes ago
        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 1 minute ago
          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?)
        • brewmarche 7 minutes ago
          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 32 minutes ago
        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.
        • gumby 5 minutes ago
          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!

      • alightsoul 37 minutes ago
        Yeah it's a relic from when computers booted off floppy and hard disks were rare and expensive
  • dataflow 53 minutes ago
    Is this just his speculation? Or is there evidence for it?
    • dspillett 27 minutes ago
      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.