What is the exact mathematical relationship between the p-values and t-stat/degrees of freedom? Let's say, for whatever ungodly reason, I want to precisely calculate p-values by hand, without looking up tables for approximate values.
What is the exact specific formula for arriving at a p-value, given a t-stat and degrees of freedom?

Accurate p-values for t-tests are not really feasible "by hand"; note that you can work out p-values from the cdf, so I will focus on that.
At very low, integer degrees of freedom, the cdf can be computed -- you can obtain the cdf via integration by parts, whence you can descend 2 d.f. each time but the length of the expression grows each time, ending up with a finite series of terms ending either at the 2 d.f  case or the 1 d.f. case, which are integrable.
Explicit expressions are given for the first few degrees of freedom in the t-distribution page at Wikipedia (see the link below).
Outside that - non-integer d.f. or large d.f. - there's no practical, simple expression for it (in the sense of something you can expect to easily write down as a short closed form expression or do on a cheap calculator; there are some calculator-type approximations but typically not of great accuracy).
More generally you need to be able to evaluate something equivalent to the regularized incomplete beta function, which mathematical libraries for a variety of computer languages will have built in, or the hypergeometric function $_2F_1$.
See https://en.wikipedia.org/wiki/Student%27s_t-distribution#Cumulative_distribution_function
Alternatively, you can use some function specifically designed to numerically approximate the t-cdf. Computer functions may use a variety of methods to approximate the cdf of the t at almost any required degrees of freedom, typically for d.f.s up to many thousands at least (and beyond which the normal approximation will usually be easily sufficient), and will usually give quite a few figures of accuracy for almost all of the range (e.g. 6-8 decimal digits, say), aside for the most extreme tails.
There's some mention of specific examples of such approximations here:  Mathematically, how are the critical t values calculated?
Per the above Wikipedia links, the cdf for the $t_\nu$ can be written as:
$$\int_{-\infty}^t f(u)\,du = \tfrac{1}{2} + t\frac{\Gamma \left( \tfrac{1}{2}(\nu+1) \right)} {\sqrt{\pi\nu}\,\Gamma \left(\tfrac{\nu}{2}\right)} \, {}_2F_1 \left( \tfrac{1}{2}, \tfrac{1}{2}(\nu+1); \tfrac{3}{2}; -\tfrac{t^2}{\nu} \right),$$
where
$${}_2F_1(a,b;c;z) = 1 + \frac{ab}{c}\frac{z}{1!} + \frac{a(a+1)b(b+1)}{c(c+1)}\frac{z^2}{2!} + \cdots.$$
