Magnetohydrodynamic equilibrium and the stability of tokamak and reversed- field pinch systems with 3D helical cores