iPXE
bios_reboot.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * Standard PC-BIOS reboot mechanism
29 *
30 */
31
32#include <string.h>
33#include <ipxe/reboot.h>
34#include <realmode.h>
35#include <bios.h>
36#include <ipxe/apm.h>
37#include <ipxe/acpipwr.h>
38
39/**
40 * Reboot system
41 *
42 * @v flags Reboot flags
43 */
44static void bios_reboot ( int flags ) {
46
47 /* Configure BIOS for cold/warm reboot */
48 type = ( ( flags & REBOOT_WARM ) ? BDA_REBOOT_WARM : 0 );
50
51 /* Jump to system reset vector */
52 __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : );
53}
54
55/**
56 * Power off system
57 *
58 * @ret rc Return status code
59 */
60static int bios_poweroff ( void ) {
61 int rc;
62
63 /* Try APM */
64 if ( ( rc = apm_poweroff() ) != 0 )
65 DBG ( "APM power off failed: %s\n", strerror ( rc ) );
66
67 /* Try ACPI */
68 if ( ( rc = acpi_poweroff() ) != 0 )
69 DBG ( "ACPI power off failed: %s\n", strerror ( rc ) );
70
71 return rc;
72}
73
int acpi_poweroff(void)
Power off the computer using ACPI.
Definition acpipwr.c:115
ACPI power off.
int apm_poweroff(void)
Power off the computer using APM.
Definition apm.c:42
Advanced Power Management.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned short uint16_t
Definition stdint.h:11
#define BDA_REBOOT_WARM
Definition bios.h:18
#define BDA_SEG
Definition bios.h:6
#define BDA_REBOOT
Definition bios.h:17
static void bios_reboot(int flags)
Reboot system.
Definition bios_reboot.c:44
static int bios_poweroff(void)
Power off system.
Definition bios_reboot.c:60
uint32_t type
Operating system type.
Definition ena.h:1
uint8_t flags
Flags.
Definition ena.h:7
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
iPXE reboot API
#define PROVIDE_REBOOT(_subsys, _api_func, _func)
Provide an reboot API implementation.
Definition reboot.h:33
int poweroff(void)
Power off system.
void reboot(int flags)
Reboot system.
#define REBOOT_WARM
Perform a warm reboot.
Definition reboot.h:59
String functions.
#define put_real
Definition libkir.h:150
#define REAL_CODE(asm_code_str)
Definition libkir.h:226
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79