kbsd.init-x86_64.S 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB 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. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define MODE_RDRW 2
  19. #define FLAGS_NONE 0
  20. #define SYSCALL_OPEN 5
  21. #define SYSCALL_WRITE 4
  22. #ifdef TARGET_NETBSD
  23. #define SYSCALL_RESET 208
  24. #elif defined (TARGET_OPENBSD)
  25. #define SYSCALL_RESET 55
  26. #else
  27. #error unknown target
  28. #endif
  29. #define SYSCALL_EXIT 1
  30. #define SYSCALL_ARCH 165
  31. #define SYSCALL_INT 0x80
  32. #define SYSCALL_ARCH_IOPL 2
  33. #define RESET_NOSYNC 0x4
  34. #define RESET_HALT 0x8
  35. #define RESET_POWEROFF 0x800
  36. .section ".init", "ax"
  37. .global start,_start
  38. start:
  39. _start:
  40. /* open. */
  41. movq $SYSCALL_OPEN, %rax
  42. leaq device, %rdi
  43. movq $MODE_RDRW, %rsi
  44. movq $FLAGS_NONE, %rdx
  45. syscall
  46. movq %rax, %rdi
  47. /* write. */
  48. movq $SYSCALL_WRITE, %rax
  49. movq $(messageend-message), %rdx
  50. leaq message, %rsi
  51. syscall
  52. /* IOPL. */
  53. movq $SYSCALL_ARCH, %rax
  54. movq $SYSCALL_ARCH_IOPL, %rdi
  55. leaq iopl_arg, %rsi
  56. syscall
  57. #include "qemu-shutdown-x86.S"
  58. /* shutdown. */
  59. movq $SYSCALL_RESET, %rax
  60. movq $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC), %rdi
  61. movq $0, %rsi
  62. syscall
  63. /* exit (1). Shouldn't be reached. */
  64. movq $SYSCALL_EXIT, %rax
  65. movq $1, %rdi
  66. syscall
  67. .section ".fini", "ax"
  68. 1: jmp 1b
  69. .section ".text", "ax"
  70. 1: jmp 1b
  71. /* This section is needed for NetBSD to identify the binary. */
  72. .section ".note.netbsd.ident", "a"
  73. .long 0x7
  74. .long 0x4
  75. .long 0x1
  76. .ascii "NetBSD"
  77. .byte 0
  78. .data
  79. device:
  80. .ascii "/dev/console"
  81. .byte 0
  82. message:
  83. .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n"
  84. messageend:
  85. iopl_arg:
  86. .long 3