kbsd.init-i386.S 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. #ifdef TARGET_NETBSD
  19. #define SYSCALL_RESET 208
  20. #elif defined (TARGET_OPENBSD)
  21. #define SYSCALL_RESET 55
  22. #else
  23. #error unknown target
  24. #endif
  25. #define MODE_RDRW 2
  26. #define FLAGS_NONE 0
  27. #define SYSCALL_OPEN 5
  28. #define SYSCALL_WRITE 4
  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. movl $SYSCALL_OPEN, %eax
  42. pushl $FLAGS_NONE
  43. pushl $MODE_RDRW
  44. leal device, %ebx
  45. pushl %ebx
  46. pushl $0
  47. int $SYSCALL_INT
  48. addl $16, %esp
  49. movl %eax, %ecx
  50. /* write. */
  51. movl $SYSCALL_WRITE, %eax
  52. pushl $(messageend-message)
  53. leal message, %ebx
  54. pushl %ebx
  55. pushl %ecx
  56. pushl $0
  57. int $SYSCALL_INT
  58. addl $16, %esp
  59. /* IOPL. */
  60. movl $SYSCALL_ARCH, %eax
  61. pushl $iopl_arg
  62. pushl $SYSCALL_ARCH_IOPL
  63. pushl $0
  64. int $SYSCALL_INT
  65. addl $12, %esp
  66. #include "qemu-shutdown-x86.S"
  67. /* shutdown. */
  68. movl $SYSCALL_RESET, %eax
  69. pushl $0
  70. pushl $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC)
  71. pushl $0
  72. int $SYSCALL_INT
  73. addl $8, %esp
  74. /* exit (1). Shouldn't be reached. */
  75. movl $SYSCALL_EXIT, %eax
  76. pushl $1
  77. pushl $0
  78. int $SYSCALL_INT
  79. .section ".fini", "ax"
  80. 1: jmp 1b
  81. .section ".text", "ax"
  82. 1: jmp 1b
  83. /* This section is needed for NetBSD to identify the binary. */
  84. .section ".note.netbsd.ident", "a"
  85. .long 0x7
  86. .long 0x4
  87. .long 0x1
  88. .ascii "NetBSD"
  89. .byte 0
  90. .data
  91. device:
  92. .ascii "/dev/console"
  93. .byte 0
  94. message:
  95. .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n"
  96. messageend:
  97. iopl_arg:
  98. .long 3