Per spec:
Upon reset, the MDT field is set to 1. When the MDT bit is set to 1 by an explicit CSR write, the MIE bit is cleared to 0. For RV64, this clearing occurs regardless of the value written, if any, to the MIE bit by the same write. The MIE bit can only be set to 1 by an explicit CSR write if the MDT bit is already 0 or, for RV64, is being set to 0 by the same write (For RV32, the MDT bit is in mstatush and the MIE bit in mstatus register).
Most of that will be fairly straightforward.
Difficult is "clearing [MIE] occurs regardless of the value written to the MIE bit ... by the same write".
Per spec:
Most of that will be fairly straightforward.
Difficult is "clearing [MIE] occurs regardless of the value written to the MIE bit ... by the same write".