Under the mild assumption of sign-controllability, a closed-form expression parametrizing all the solutions of the Hamiltonian system over a finite time interval is presented in terms of a strongly unmixed solution of a continuous algebraic Riccati equation and of the solution of an algebraic Lyapunov equation. This result can be employed for the solution of a generalized version of the finite-horizon LQ problem, encompassing the case of fixed end-point