1

I am taking a course in Operating Systems. I am booting jos os on to qemu x86 PC emulator. I read that BIOS finds bootable devices and loads the bootloader from the first sector of the bootable device to 0x7c00 in the memory.

The first instruction in the bootloader is to disable the interrupts i.e cli.

I read about cli i.e it clears the enable interrupts flag in the eflags register. I read from Wikipedia that it is done to avoid a race condition between kernel code and interrupt handlers. please explain what a race condition is and what sort of race condition is present here.

I still don't understand why it's done? Can someone elaborate on this?

router
  • 582
  • 5
  • 16
  • There are more than one cause why to do this in a bootloader. Would you please share a link to the source code? – cadaniluk Aug 25 '15 at 17:12
  • The entire source code of the kernel, bootloader is in [this](http://pdos.csail.mit.edu/6.828/2014-jos.git) repo. – router Aug 25 '15 at 17:15
  • Look here: http://stackoverflow.com/questions/16536035/why-do-interrupts-need-to-be-disabled-before-switching-to-protected-mode-from-re – cadaniluk Aug 26 '15 at 05:53
  • Thank You @cad for referring to the answer written by Griwes. That was an awesome answer. I want to still know how racing is one of the cause for disabling the interrupts. – router Aug 26 '15 at 11:33
  • Well, the general and simple answer is that a process and an ISR may access common variables. If the read-write operations aren't atomic, race conditions occur. One concrete case is this one: http://stackoverflow.com/questions/20769768/why-disabling-interrupts-disables-kernel-preemption-and-how-spin-lock-disables-p – cadaniluk Aug 26 '15 at 11:56

1 Answers1

0

I am considering using JOS for my operating systems class, perhaps as early as Winter term 2016. The cli question, while interesting because of what it prevents, is a little less interesting, IMO, than this one:

When are interrupts enabled again?

One can use the directions on loading the git for the lab described at http://pdos.csail.mit.edu/6.828/2014/labs/lab1/ and then look through the boot and kern directories for the sequence.

PDX Mark
  • 31
  • 5