OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 4:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Simple and naive OS, crashes after 10 seconds
PostPosted: Tue Feb 20, 2018 4:34 am 
Offline

Joined: Tue Feb 20, 2018 4:27 am
Posts: 1
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:
mov     %rcx,   %rdi    # efi_handle_t
mov     %rdx,   %rsi    # efi_system_table_t
call    init


init() is defined:

Code:
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. */
}


Top
 Profile  
 
 Post subject: Re: Simple and naive OS, crashes after 10 seconds
PostPosted: Tue Feb 20, 2018 7:30 am 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
This:
Quote:
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.

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
 Post subject: Re: Simple and naive OS, crashes after 10 seconds
PostPosted: Tue Feb 20, 2018 3:33 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Simple and naive OS, crashes after 10 seconds
PostPosted: Tue Feb 20, 2018 3:46 pm 
Offline
Member
Member
User avatar

Joined: Fri Feb 17, 2017 4:01 pm
Posts: 642
Location: Ukraine, Bachmut
just a note, on UEFI, watchdog timer is disabled (by the UEFI) on return from ExitBootServices().

_________________
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 164 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group