Old English hwæt, referring to things in abstraction; also "why, wherefore; indeed, surely, truly," from Proto-Germanic pronoun *hwat (source also of Old Saxon hwat, Old Norse hvat, Danish hvad, Old Frisian hwet, Dutch wat, Old High German hwaz, German was, Gothic hva "what"), from PIE *kwod, neuter singular of *kwos "who," from PIE root *kwo-, stem of relative and interrogative pronouns. Corresponding to Latin quid.
Meaning "what did you say?" is recorded from c. 1300. As an adjective and adverb, in Old English. As a conjunction in late Old English. Exclamatory use was in Old English. What the _____ (devil, etc.) as an exclamation of surprise is from late 14c. As an interrogative expletive at the end of sentences from 1891; common in affected British speech. Or what as an alternative end to a question is first attested 1766. What have you "anything else one can think of" is from 1925. What's up? "what is happening?" first recorded 1881.
"To give one what for is to respond to his remonstrant what for? by further assault" [Weekley]. The phrase is attested from 1873; what for? as introducing a question is from 1760. To know what is what is from c. 1400; I'll tell you what to emphasize what is about to be said is in Shakespeare.