The earth we live on has three usual outer layers.
The atmosphere in gas phase, the oceans etc in liquid phase and the crust in solid mineral phase or as ice and snow.
It has an inbuilt source of heat which is important.
The vast majority of the heat present at the surface comes externally from the sun.
The minerals making up the earth are the original source of the atmosphere and the oceans.*
* some people claim meteorites are an additional source of water.
The earth is basically a hot meteorite slightly cooling down.
If we could imagine it a lot further away from the sun in orbit we would find it to have very little atmosphere as most of the oxygen and nitrogen would be frozen as a layer on the surface with the oceans as solid ice.*
* different scenarios exist.
The first and most important comment is that the earth, and meteorites have a pH depending on their mineral composition which for the earth is around pH 8.1.
When the temperature increases ( planet closer to the sun in our case) water becomes liquid on top of the solid mineral surface and engages in chemical reactions which lead to it equilibrating with the pH of the surface of the earth in general.*
*pH varies according to the minerals and compounds both in the water and in contact with the water..
The second comment is that when water is present a third gaseous layer develops from the large amount of gases given off by the warming water.
This is far greater than any trace gas atmosphere on a water less solid planetoid such as on the surface of the moon.
The gases in the atmosphere are present as per Boyle’s law each by how much is dissolved in the water at that temperature and pressure from the solids presented by the earth..
Oxygen has a special place as it would normally be in mineral or part of water only on a cold lifeless planet.
The formulae for determining the amount of CO2 in the air are quite clear.
CO2 in the air is present in minuscule amounts compared to CO2/H2CO3 various forms and CaCO3 in water.
In turn the earth has massive amounts of CaCO3 and other Carbonates not only in its surface layer but also deeper.
The earth pH 8.1 is in equilibrium with the water pH 8.1 overall.*
*obviously pH is constantly varying depending on temperature and depth. Being in equilibrium overall does not mean it is the same everywhere at the same time.
The CO2 in the atmosphere has been there for over the last two billion years. It comes from the water dissolving carbonates when it is warm enough to do so.
The water then keeps an average 400 ppm in the atmosphere
At a yearly average surface temperature of 14.9 C at 1 atmosphere of pressure.