push %ebx
push %esi
push %edi
+ pushf /* Save EFLAGS (including IF) */
/* 2. Save the old ESP */
- /* Get the location of old_esp_ptr.
- Stack is: [RetAddr] [old_esp_ptr] [new_esp]
- ESP points to EDI (last push) */
+ /* Stack is: [RetAddr] [old_esp_ptr] [new_esp] + 5 pushes (20 bytes)
+ ESP points to EFLAGS (last push) */
- mov 20(%esp), %eax /* EAX = old_esp_ptr */
+ mov 24(%esp), %eax /* EAX = old_esp_ptr */
mov %esp, (%eax) /* *old_esp_ptr = ESP */
/* 3. Switch to the NEW process stack */
- mov 24(%esp), %esp /* ESP = new_esp */
+ mov 28(%esp), %esp /* ESP = new_esp */
/* 4. Restore state of the NEW process */
+ popf /* Restore EFLAGS (including IF) from saved context */
pop %edi
pop %esi
pop %ebx
*--sp = 0;
*--sp = (uint32_t)thread_wrapper;
*--sp = 0; *--sp = 0; *--sp = 0; *--sp = 0;
+ *--sp = 0x202; /* EFLAGS: IF=1, reserved bit 1 */
proc->sp = (uintptr_t)sp;
proc->next = ready_queue_head;
*--sp = 0;
*--sp = (uint32_t)thread_wrapper;
*--sp = 0; *--sp = 0; *--sp = 0; *--sp = 0;
+ *--sp = 0x202; /* EFLAGS: IF=1, reserved bit 1 */
proc->sp = (uintptr_t)sp;
/* Insert into process list */
*--sp = 0;
*--sp = (uint32_t)thread_wrapper;
*--sp = 0; *--sp = 0; *--sp = 0; *--sp = 0;
+ *--sp = 0x202; /* EFLAGS: IF=1, reserved bit 1 */
proc->sp = (uintptr_t)sp;
context_switch(&prev->sp, current_process->sp);
- hal_cpu_enable_interrupts();
+ /* EFLAGS (including IF) is now restored by context_switch via popf,
+ * so we no longer force-enable interrupts here. */
}
void process_sleep(uint32_t ticks) {