summaryrefslogtreecommitdiff
path: root/kernel/usermode.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/usermode.c')
-rw-r--r--kernel/usermode.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/kernel/usermode.c b/kernel/usermode.c
new file mode 100644
index 0000000..afad9df
--- /dev/null
+++ b/kernel/usermode.c
@@ -0,0 +1,32 @@
+#include "usermode.h"
+
+
+void install_tss(int cpu_no){
+ // now fill each value
+ // set values necessary
+ sys_tss.ss0 = 0x10;
+ // now set the IO bitmap (not necessary, so set above limit)
+ sys_tss.iomap = ( unsigned short ) sizeof( tss_struct );
+}
+
+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; \
+ mov $0x200, %eax; \
+ push %eax; \
+ pushl $0x1B; \
+ push $1f; \
+ iret; \ 1: \
+ ");
+}