You are probably working at too low of a level, and you are
also tackling a task that has already been done. (Linux systems have been shutting themselves down when power dies, for many ye ...
)
The port (a serial port?) is simply a
device, and you should have (and BTW there already exists...) a daemon that can start an
asynchronous read upon the port (uses a mechanism like
poll() ...) and be woken up when the read completes.
IRQs and such are the lowest-level glue when talking to a
device, and "a port is a device ... a power-supply is not ... and we already know how to talk to a port."
When the daemon decides that power has been lost, it notifies the kernel to switch to a different runlevel, thereby bringing the system to a stop.