Swearing has a long and illustrious history. I believe however that its prehistory is much much longer.
Swearing at its purest is monosyllabic and entirely emotional. Its context is now.
People swear from pain, during sex, before battle, when disgusted or exhilarated.
At its most general the function of swearing is to communicate, and thereby relieve, stress.
The need for this function exists in all social animals. Any animal that vocalizes is, essentially, swearing.
I believe that human language evolved from swearing when humans developed a longer perspective on time than just the immediate, and consequently learned to modify the meaning of swearing across time. No longer was it just "Fuck!"; now it could be "was fucked" and "will be fucked".
(with acknowledgments to Will Self: Great Apes)