There is a story about a worm. David is not sure it's true, but he's heard the story, and a poet knows that stories are powerful even if they're untrue. Sometimes they're also true even if they're untrue. The Shamir is a unique worm, a one of a kind wonder of creation like the Leviathan David has sung so many songs about. If you have the worm, all you need to do is place it on a stone and the stone splits in half.
The Temple to the Lord in the City of David is to be a House of Peace, the Lord God has told him through his servant Nathan. A Warrior-King is not fit to build it. He has blood on his hands, has made his living my the sword, and the Temple's walls must not even know the caress of iron in their construction.
But a poet is alert to nuance, and though he is not destined to be the Builder of God's House in Jerusalem, he can still support his son's achievement. The King orders his masons and his metalworkers to begin assembling the materials, declaring "Solomon, my son, is young and tender. The House that will be built for the Lord must be immensely great, its fame and glory known through all the lands, so I will start the preparations for him."
And then he leaves his palace of cedarwood and makes his way to a certain well in the wilderness, a place he had known in his hiding. The King casts a piece of gold into the well and proclaims, "Ashmedai, I summon thee to me." Lo, the demon Ashmedai appeared before him.
"What do you want, my Lord?" the demon asked, grinning satyrically.
"You owe me a favor, demon, for the services I rendered unto you. But I have no need of your demonic favors, for the Lord God is with me. So I will pass your favor down to my son, Solomon. Though he is young and tender, yet he is wise and just, and will use it properly. When he is ready, you will tell him how to find the Shamir, Ashmedai. Then, my hold on you will be released."
The Earth shook and the skies thundered and darkness and light shifted places before David's eyes. Then, it was calm, and David was appeased.