start.S 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Symbol from main.rs
  2. .extern rust_entry
  3. .code32
  4. .section .multiboot_header, "a", @progbits
  5. /*
  6. * Multiboot v1 Header.
  7. * Required so that we can be booted by QEMU via the "-kernel" parameter.
  8. */
  9. .align 8
  10. .global multiboot_header
  11. multiboot_header:
  12. .long 0x1badb002
  13. .long 0x0
  14. .long -0x1badb002
  15. .section .text
  16. .global start
  17. start:
  18. # Prepare Multiboot2-handoff parameters for Rust
  19. mov %eax, %edi
  20. mov %ebx, %esi
  21. # Prepare stack + align it to 16 byte (for SSE registers)
  22. mov $stack_end, %eax
  23. sub $16, %eax
  24. # x86 quirk: stack is n-aligned at address x when %esp+$8 is n-aligned
  25. add $8, %eax
  26. # Set stack
  27. mov %eax, %esp
  28. mov %eax, %ebp
  29. # Enable SSE.
  30. # Strictly speaking, this is not necessary, but I activated SSE in the
  31. # compiler spec json file. Rustc/LLVM produces SSE coe for example from the
  32. # core::fmt code.
  33. mov %cr0, %eax
  34. and $0xFFFB, %ax # clear coprocessor emulation CR0.EM
  35. or $0x2, %ax # set coprocessor monitoring CR0.MP
  36. mov %eax, %cr0
  37. mov %cr4, %eax
  38. or $(3 << 9), %ax # set CR4.OSFXSR and CR4.OSXMMEXCPT
  39. mov %eax, %cr4
  40. push %ebp
  41. mov %esp, %ebp
  42. # x86 SystemV calling convention: Push arguments in reverse order to stack
  43. push %esi
  44. push %edi
  45. call rust_entry
  46. ud2
  47. .section .data
  48. # 16K natural-aligned stack.
  49. .align 16384
  50. stack_begin:
  51. .zero 16384
  52. stack_end: