This (autonegotiation) is explained in various sections of the IEEE 802.3 specifications.
Auto-MDIX is mostly a function of gigabit interfaces being able to TX and RX on all four pairs. I don't recall this being part of 802.3, but the logic for it (looking for carrier signal, and/or link pulses) is simple enough that anything capable of gig will support it.