Formation, history and energetics of cores in the terrestrial planets