songziming wrote:
Interrupts also fire under user mode, as long as you set rflags.IF=1 before iret.
When process tries to read from an empty file, the process will change to pending state. And that process will be removed from ready queue. When other process or ISR write to the file, making that file not empty, the pending process can be wake up.
So when process calls getchar() while the stdin is empty, the process is actually pending, i.e. not running on CPU. When stdin becomes not empty, the process resumes and function getchar() returns.
So when I have this code in c which move me to user mode:
Code:
void switch_to_user_mode()
{
// Set up a stack structure for switching to user mode.
asm volatile(" \
cli; \
mov $0x23, %ax; \
mov %ax, %ds; \
mov %ax, %es; \
mov %ax, %fs; \
mov %ax, %gs; \
\
mov %esp, %eax; \
pushl $0x23; \
pushl %eax; \
pushf; \
pushl $0x1B; \
push $1f; \
iret; \
1: \
");
}
How do I set IF=1 So I still have interrupts in user mode and the system won't crash when I access the cpu?