Ring 3 query
Posted: Wed Apr 01, 2009 8:50 pm
Hi,
I am currently in ring 0. the code I use to jump to ring 3 is shown below...
The problem here is that everything works fine without any triple faults! Actually, the "print()" function is a function in the kernel to print data on the screen. So typically if I jump from Ring 0 to Ring 3 this function should not be available unless accessed using some kind of system call, rite? But "hello world" is printed out on the screen in this case? What could be wrong?
Just to add, the system call i implemented works. But I guess that does not tell me anything, since "sysenter" can be called from ring 0 and ring 3. The switch_to_user_mode() function is the same from JamesM's kernel development tutorials. I could use some insight from you guys here. I'm pretty sure, I'm doing something wrong. Please also tell me if I need to give more details about my implementation. Thanks.
I am currently in ring 0. the code I use to jump to ring 3 is shown below...
Code: Select all
void switch_to_user_mode()
{
print("\nJumping to ring 3");
// 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; \
pop %eax;\
orl $0x200, %eax;\
push %eax;\
pushl $0x1B;\
push $1f;\
iret; \
1: \
");
}
void user_task()
{
switch_to_user_mode();
print("hello world");
asm volatile("sysenter");
}
Just to add, the system call i implemented works. But I guess that does not tell me anything, since "sysenter" can be called from ring 0 and ring 3. The switch_to_user_mode() function is the same from JamesM's kernel development tutorials. I could use some insight from you guys here. I'm pretty sure, I'm doing something wrong. Please also tell me if I need to give more details about my implementation. Thanks.