We present calculated second-harmonic-generation (SHG) spectra of the Si(001) surface based on a first-principles description of eigenvalues and eigenvectors using ab initio pseudopotentials. We also present SHG spectra for Ge-covered Si(001). The theoretical results explain all essential features of recent experimental SHG spectra of the $\mathrm{Si}(001)\ensuremath{-}(2\ifmmode\times\else\texttimes\fi{}1)$ surface with low coverages of hydrogen and/or germanium, which alter the ${E}_{1}$ resonance in contrasting ways. The strong adatom specificity of the spectra results from redistribution of the adatom-related electronic states on the surface.