1
/* halt.c - command to halt the computer. */
3
* GRUB -- GRand Unified Bootloader
4
* Copyright (C) 2005,2007,2009 Free Software Foundation, Inc.
6
* GRUB is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
11
* GRUB is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21
#include <grub/misc.h>
22
#include <grub/extcmd.h>
23
#include <grub/i18n.h>
24
#include <grub/machine/int.h>
25
#include <grub/acpi.h>
27
GRUB_MOD_LICENSE ("GPLv3+");
29
static const struct grub_arg_option options[] =
31
{"no-apm", 'n', 0, N_("Do not use APM to halt the computer."), 0, 0},
35
static inline void __attribute__ ((noreturn))
44
* Halt the system, using APM if possible. If NO_APM is true, don't use
45
* APM even if it is available.
47
void __attribute__ ((noreturn))
48
grub_halt (int no_apm)
50
struct grub_bios_int_registers regs;
60
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
61
grub_bios_interrupt (0x15, ®s);
63
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
66
/* disconnect APM first */
69
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
70
grub_bios_interrupt (0x15, ®s);
75
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
76
grub_bios_interrupt (0x15, ®s);
77
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
80
/* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
84
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
85
grub_bios_interrupt (0x15, ®s);
86
if (regs.flags & GRUB_CPU_INT_FLAGS_CARRY)
89
/* set the power state to off */
93
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
94
grub_bios_interrupt (0x15, ®s);
96
/* shouldn't reach here */
100
static grub_err_t __attribute__ ((noreturn))
101
grub_cmd_halt (grub_extcmd_context_t ctxt,
102
int argc __attribute__ ((unused)),
103
char **args __attribute__ ((unused)))
106
struct grub_arg_list *state = ctxt->state;
114
static grub_extcmd_t cmd;
118
cmd = grub_register_extcmd ("halt", grub_cmd_halt, 0, "[-n]",
119
N_("Halt the system, if possible using APM."),
125
grub_unregister_extcmd (cmd);