S&P 500, Nasdaq gain as investors await Nvidia earnings, Jackson Hole meet