Consider an intrinsic semiconductor, which means that there are valence and conduction bands that are energetically separated by a band gap of forbidden electronic energy levels of width $E_g$.
In groundstate, so $T=0 \mathrm{K}$, you correctly said that the valence band edge is the highest occupied energetic state. The electron distribution function takes the look of a heaviside function with values $1$ for the valence band and $0$ for the conduction band. Here the position of the Fermi energy, which is basically the point where the heavyside function has it's step, is ambigously positioned somewhere in the band gap region.
If we now consider a more realistic environment for the semiconductor, like room temperature at $300$ K, we have to closer look at the electron distribution function. As electrons are fermions they follow Fermi-Dirac statistics and the electron distribution function is thus given by
$f(E,\mu, T) = \frac{1}{\exp^{\left[\frac{E-\mu}{k_\mathrm{B} T}\right]} + 1}$
, where $k_\mathrm{B}$ is the Boltzmann constant and $\mu$ the Fermi energy. For finite temperatures this function is not step-like, but a rather smoothly varying from $1$ to zero if energy increases with a turning point at $\mu$. Furthermore this function is asymmetric with respect to $\mu$.
The position of the Fermi energy is now determined by the underlying bandstructure. In the simplest case, so two parabolic bands with same effective mass (e.g. curvature), the position of the Fermi energy lies exactly in the middle of the bandgap. This is due to the fact that the room-temperature Fermi-Dirac function depopulates the valence band (VB) edge states and populates conduction band (CB) edge states. As the number of particles must be conserved, the depopulated valence electrons must be equal to the populated conduction band electrons. For the same effective mass of these bands (same density of states for the VB and CB) this scenario is valid, if $\mu$ lies directly in the middle of the gap.
If the valence and conduction bands show different effective masses, they also have a different density of states and thus we need to change the Fermi energy in such a way that the particle states that are thermally depopulated and populated are equal.
This is ensured by the following equation:
$E_{\mathrm{F}} = \mu = \frac{E_{\mathrm{CB}} - E_{\mathrm{VB}}}{2} + \frac{3}{4} k_\mathrm{B} T \ln(\frac{m_{\mathrm{CB}}^*}{m_{\mathrm{VB}}^*})$.
The choice of the Fermi energy in the middle of the bandgap at $T=0$ K is, as far as I know, ambigious but it kind of makes sense, if you follow the formula from above to $T \rightarrow 0$.