Move $_MIDGARD emulation to the compat layer