the question how exactly molluscs and other calcifying organisms, such as foraminifera form their shells is still an ongoing research question. What has become clear though is that the formation of Calcite, Aragonite or Vaterite is highly biologically controlled. One classical theory is that the organisms create a spece enclosed by membranes where they change the chemistry of the enclosed solute (e.g. seawater) in such a way that CaCO3 precipitation occurs. But there are a number of things that remain to be clarified. Nacre, for example, cosists of CaCO3 crystals with a lot or organics around them and it is not clear how that is built. A good starting point for reading is the following article:
Cuif, J. P. , Dauphin, Y. , Nehrke, G. , Nouet, J. and Perez-Huerta, A. (2012): Layered Growth and Crystallization in Calcareous Biominerals: Impact of Structural and Chemical Evidence on Two Major Concepts in Invertebrate Biomineralization Studies , Minerals, 2 (1), pp. 11-39 . doi: 10.3390/min2010011
The carbon comes from the carbon dioxide gas dissolved in the sea water, so is calcium ion. The animals take advantage of a chemical reaction to combine the two to form bicarbonate first, then finally carbonate of calcium, I was told by some expert (sorry forgot name).