head.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. .text
  20. .align 8
  21. .globl _start
  22. _start:
  23. /* we cannot use far-jmp in long mode. */
  24. /*
  25. * 'call' will push address of next code,
  26. * and 'ret' will pop it to %rip
  27. * so we can push address, 'ret' will
  28. * pop it and jump to it.
  29. */
  30. /* 64 bit code */
  31. /* return address */
  32. leaq init_done(%rip), %rax
  33. pushq %rax
  34. /* address will jump */
  35. leaq init(%rip), %rax
  36. pushq %rax
  37. retq
  38. init_done:
  39. /* andq %rax, %rax, but %rax won't change. */
  40. testq %rax, %rax
  41. jnz init_panic
  42. init_die:
  43. hlt
  44. jmp init_die
  45. init_panic:
  46. leaq panic_msg(%rip), %rdi
  47. callq printf
  48. jmp init_die
  49. .section .rodata
  50. .align 8
  51. message:
  52. .asciz "XNIX Kernel is starting..."
  53. panic_msg:
  54. .asciz "panic in init: halted"