Page 1 of 1

Simple and naive OS, crashes after 10 seconds

Posted: Tue Feb 20, 2018 4:34 am
by nokimo33
I built an "OS", only a few lines, i.e 1)"cli" (for disabling interrupts), and 2) "while (1)" (for an infinite loop).

I expect this "os" to loop forever, but it crashes after 10 seconds. Why?


Other details:

No bootloader, just UEFI.

The Complete code is:

Code: Select all

mov     %rcx,   %rdi    # efi_handle_t
mov     %rdx,   %rsi    # efi_system_table_t
call    init
init() is defined:

Code: Select all

void init(efi_handle_t h, efi_system_table_t *t)
{
    unsigned long key;
	get_memory_map(&key);      /* Returns successfully, with @status=0. */
	exit_boot_services(key);   /* Returns successfully, with @status=0. */

	asm("cli"); /* So we don't hvae to install IDT for interrupt handlers. */
	while (1);  /* I expect here to loop forever.
	             * In practice, crashes after about 10 seconds. */
}

Re: Simple and naive OS, crashes after 10 seconds

Posted: Tue Feb 20, 2018 7:30 am
by zaval
This:
get_memory_map(&key); /* Returns successfully, with @status=0. */
exit_boot_services(key); /* Returns successfully, with @status=0. */
What is this? It's not UEFI functions, what they do? Is this a pseudo code? Show the code instead.

Re: Simple and naive OS, crashes after 10 seconds

Posted: Tue Feb 20, 2018 3:33 pm
by Brendan
Hi,
nokimo33 wrote:I built an "OS", only a few lines, i.e 1)"cli" (for disabling interrupts), and 2) "while (1)" (for an infinite loop).

I expect this "os" to loop forever, but it crashes after 10 seconds. Why?
Assuming the code actually does what you intend (and doesn't have bugs, etc); there's only 3 things that can interrupt a CPU after interrupts are disabled with "CLI" - NMI, SMI and machine check exception. Machine check exceptions need to be enabled by the OS and therefore can't be the cause; and SMI "should work" regardless of what the OS does (if it was a problem it'd probably be a problem with lots of OSs).

If we assume it's NMI; then (without more information) my best guess would be a watchdog timer - a timer deliberately intended to reboot the computer if the OS locks up during boot. Unfortunately 10 seconds is a bit too quick to make this theory "very believable" (typically watchdog timers are set for a longer amount of time - e.g. 5 minutes).


Cheers,

Brendan

Re: Simple and naive OS, crashes after 10 seconds

Posted: Tue Feb 20, 2018 3:46 pm
by zaval
just a note, on UEFI, watchdog timer is disabled (by the UEFI) on return from ExitBootServices().