2N/A/*
2N/A * GRUB -- GRand Unified Bootloader
2N/A * Copyright (C) 2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#define MODE_RDRW 2
2N/A#define FLAGS_NONE 0
2N/A#define SYSCALL_OPEN 5
2N/A#define SYSCALL_WRITE 4
2N/A#ifdef TARGET_NETBSD
2N/A#define SYSCALL_RESET 208
2N/A#elif defined (TARGET_OPENBSD)
2N/A#define SYSCALL_RESET 55
2N/A#else
2N/A#error unknown target
2N/A#endif
2N/A#define SYSCALL_EXIT 1
2N/A#define SYSCALL_ARCH 165
2N/A#define SYSCALL_INT 0x80
2N/A#define SYSCALL_ARCH_IOPL 2
2N/A
2N/A#define RESET_NOSYNC 0x4
2N/A#define RESET_HALT 0x8
2N/A#define RESET_POWEROFF 0x800
2N/A#define SHUTDOWN_PORT 0x8900
2N/A
2N/A .section ".init", "ax"
2N/A .global start,_start
2N/Astart:
2N/A_start:
2N/A /* open. */
2N/A movq $SYSCALL_OPEN, %rax
2N/A leaq device, %rdi
2N/A movq $MODE_RDRW, %rsi
2N/A movq $FLAGS_NONE, %rdx
2N/A syscall
2N/A movq %rax, %rdi
2N/A
2N/A /* write. */
2N/A movq $SYSCALL_WRITE, %rax
2N/A movq $(messageend-message), %rdx
2N/A leaq message, %rsi
2N/A syscall
2N/A
2N/A /* IOPL. */
2N/A movq $SYSCALL_ARCH, %rax
2N/A movq $SYSCALL_ARCH_IOPL, %rdi
2N/A leaq iopl_arg, %rsi
2N/A syscall
2N/A
2N/A movw $SHUTDOWN_PORT, %dx
2N/A movb $'S', %al
2N/A outb %al, %dx
2N/A movb $'h', %al
2N/A outb %al, %dx
2N/A movb $'u', %al
2N/A outb %al, %dx
2N/A movb $'t', %al
2N/A outb %al, %dx
2N/A movb $'d', %al
2N/A outb %al, %dx
2N/A movb $'o', %al
2N/A outb %al, %dx
2N/A movb $'w', %al
2N/A outb %al, %dx
2N/A movb $'n', %al
2N/A outb %al, %dx
2N/A
2N/A /* shutdown. */
2N/A movq $SYSCALL_RESET, %rax
2N/A movq $(RESET_POWEROFF|RESET_HALT|RESET_NOSYNC), %rdi
2N/A movq $0, %rsi
2N/A syscall
2N/A
2N/A /* exit (1). Shouldn't be reached. */
2N/A movq $SYSCALL_EXIT, %rax
2N/A movq $1, %rdi
2N/A syscall
2N/A .section ".fini", "ax"
2N/A1: jmp 1b
2N/A .section ".text", "ax"
2N/A1: jmp 1b
2N/A /* This section is needed for NetBSD to identify the binary. */
2N/A .section ".note.netbsd.ident", "a"
2N/A .long 0x7
2N/A .long 0x4
2N/A .long 0x1
2N/A .ascii "NetBSD"
2N/A .byte 0
2N/A .data
2N/Adevice:
2N/A .ascii "/dev/console"
2N/A .byte 0
2N/Amessage:
2N/A .ascii "Boot Test Passed Successfully\n" SUCCESSFUL_BOOT_STRING "\n"
2N/Amessageend:
2N/Aiopl_arg:
2N/A .long 3