Hi,
devsau wrote:I read through the wiki entries and I just had a few questions that I don't think were covered anywhere.
First is, upon execution of loader at 7c00, the IF flag is clear correct? I would assume so based upon the fact that we need to setup stack segment, but just to be clear.
The IF flag should actually be set (IRQs enabled); and there should be a stack. The problem is that you don't know how large the stack is or where the stack is. For a (deliberately "worst case") example; the BIOS might use exactly 1234 bytes for its IRQ handlers and might have a 1234 byte stack just above your boot code, so if you push anything on the stack your code gets trashed as soon as an IRQ occurs. Of course a far more likely problem is that your boot code wants to load something (e.g. a kernel) from disk and trashes its own stack.
To fix the "unknown stack" problem you have to setup a known stack.
Yoda wrote:You don't need to disable interrupts to setup stack. Just load SS, then SP. Every loading of SS automatically disables interrupts for the next instruction.
For 8086 the CPU doesn't disable IRQs for the instruction following a load of SS (only later CPUs do that). My normal approach is to assume the CPU might be an ancient 8086 (and explicitly disable IRQs when setting up a known stack); then (later) check if the CPU is too old for the OS (and display an error and refuse to boot if it is). Of course this may be considered "excessively cautious".
devsau wrote:3rd and final

I am familiar with APIC programming due to several past projects I worked on, one thing I didn't find covered with the 8259 PIC is interrupt priority. Obviously interrupts are masked until we write to EOI, but is there a priority level based upon the vector number?
The IRQ priority is based on "PIC input number", and is fixed/hard-wired; and due to the way the slave PIC is connected to the master PIC (via. "PIC input number 2") it's a little strange. The priority of IRQs (from highest priority IRQ to lowest priority IRQ) is: IRQ 0, 1, 8, 9, 10, 11, 12, 13, 14, 15, 3, 4, 5, 6, 7.
Cheers,
Brendan