refactor: keep in mind the stack layout is crucial. Move context switching & signal...
[lunaix-os.git] / lunaix-os / kernel / proc0.c
index dac1b55597c7400c783efcbca659ac72b6a7a390..6e941b0218506c79ce07fa275fa70eddca712256 100644 (file)
@@ -24,6 +24,8 @@ init_platform();
 void
 lock_reserved_memory();
 
+// #define ENABLE_USER_MODE
+
 /**
  * @brief LunaixOS的零号进程,该进程永远为可执行。
  *
@@ -36,6 +38,22 @@ void
 __proc0()
 {
     init_platform();
+#ifdef ENABLE_USER_MODE
+    asm volatile("movw %0, %%ax\n"
+                 "movw %%ax, %%es\n"
+                 "movw %%ax, %%ds\n"
+                 "movw %%ax, %%fs\n"
+                 "movw %%ax, %%gs\n"
+                 "pushl %0\n"
+                 "pushl %1\n"
+                 "pushl %2\n"
+                 "pushl %3\n"
+                 "retf" ::"i"(UDATA_SEG),
+                 "i"(USTACK_TOP & ~0xf),
+                 "i"(UCODE_SEG),
+                 "r"(&&usr));
+#endif
+usr:
     if (!fork()) {
         asm("jmp _lxinit_main");
     }