This was purely automatically massaged... some parts are still imperfect, but this is close enough to make it more readable/easy to work on. Unfortunately the vt/syscons/kdb situation slightly complicates changes to tty locking, so some work will need to be done to remediate that.