Guest User

Untitled

a guest
Aug 10th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .text
  2.  
  3. .extern SYSCALLS
  4.  
  5.  
  6. loader_run: // void (*)(void* main)
  7.    
  8.     // Get argument
  9.     mov %eax, 8(%esp)
  10.    
  11.     // Save kernel stack
  12.     mov %esp, ($kernel_stack_save)
  13.    
  14.     // Setup user stack
  15.     mov $user_stack, %esp
  16.    
  17.     // Call main
  18.     push $SYSCALLS
  19.     call *eax
  20.     add %esp, 4 // bullshit!
  21.  
  22. // jump here from userspace to restore kernel stack and functionality
  23. userspace_exit:
  24.     mov ($kernel_stack_save), %esp
  25.    
  26.     ret
  27.  
  28. .section .data
  29. // Storage of the current kernel stack pointer
  30. kernel_stack_save:
  31. .int 0
  32.  
  33. // 8 kB user space stack
  34. .section .bss
  35. .space 8192
  36. user_stack:
  37.  
  38.  
  39. .global loader_run
  40. .global userspace_exit
Advertisement
Add Comment
Please, Sign In to add comment