start.S 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Symbol from main.rs
  2. .extern rust_entry
  3. .code32
  4. .align 8
  5. .section .text
  6. .global start
  7. start:
  8. # Prepare Multiboot2-handoff parameters for Rust
  9. mov %eax, %edi
  10. mov %ebx, %esi
  11. # Prepare stack + align it to 16 byte (for SSE registers)
  12. mov $stack_end, %eax
  13. sub $16, %eax
  14. # x86 quirk: stack is n-aligned at address x when %esp+$8 is n-aligned
  15. add $8, %eax
  16. # Set stack
  17. mov %eax, %esp
  18. mov %eax, %ebp
  19. # Enable SSE.
  20. # Strictly speaking, this is not necessary, but I activated SSE in the
  21. # compiler spec json file. Rustc/LLVM produces SSE coe for example from the
  22. # core::fmt code.
  23. mov %cr0, %eax
  24. and $0xFFFB, %ax # clear coprocessor emulation CR0.EM
  25. or $0x2, %ax # set coprocessor monitoring CR0.MP
  26. mov %eax, %cr0
  27. mov %cr4, %eax
  28. or $(3 << 9), %ax # set CR4.OSFXSR and CR4.OSXMMEXCPT
  29. mov %eax, %cr4
  30. # x86 (i386) calling convention:
  31. # 1. prepare stackframe pointer
  32. # 2. push arguments on stack in reverse order
  33. push %ebp
  34. mov %esp , %ebp
  35. push %esi
  36. push %edi
  37. call rust_entry
  38. ud2
  39. .section .data
  40. # 16K natural-aligned stack.
  41. .align 16384
  42. stack_begin:
  43. .zero 16384
  44. stack_end: