Theory of shallow acceptor states in Si and Ge