If you want to do this before the bootloder, you will need a hardware watchdog timer. Many embedded operating systems have these, and you configure them in the system's hardware set up (or BIOS setup if it's a normal PC).
These will reboot the system if the watchdog has not been "tickled" within a certain number of seconds, which stops happening after a kernel panic or even an unrecoverable hardware error like corrupted RAM that completely freezes the machine.
Note that with hardware watchdogs like this, you have to be sure to set the timeout to longer than it takes to boot into Linux and load the watchdog driver, to start tickling the watchdog. Otherwise the system will reset every time the time expires, even if everything is working fine and it's just taking a long time to boot the kernel.