iPXE
bios_reboot.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 /** @file
00027  *
00028  * Standard PC-BIOS reboot mechanism
00029  *
00030  */
00031 
00032 #include <ipxe/reboot.h>
00033 #include <realmode.h>
00034 #include <bios.h>
00035 #include <ipxe/apm.h>
00036 #include <ipxe/acpipwr.h>
00037 
00038 /**
00039  * Reboot system
00040  *
00041  * @v warm              Perform a warm reboot
00042  */
00043 static void bios_reboot ( int warm ) {
00044         uint16_t flag;
00045 
00046         /* Configure BIOS for cold/warm reboot */
00047         flag = ( warm ? BDA_REBOOT_WARM : 0 );
00048         put_real ( flag, BDA_SEG, BDA_REBOOT );
00049 
00050         /* Jump to system reset vector */
00051         __asm__ __volatile__ ( REAL_CODE ( "ljmp $0xf000, $0xfff0" ) : );
00052 }
00053 
00054 /**
00055  * Power off system
00056  *
00057  * @ret rc              Return status code
00058  */
00059 static int bios_poweroff ( void ) {
00060         int rc;
00061 
00062         /* Try APM */
00063         if ( ( rc = apm_poweroff() ) != 0 )
00064                 DBG ( "APM power off failed: %s\n", strerror ( rc ) );
00065 
00066         /* Try ACPI */
00067         if ( ( rc = acpi_poweroff() ) != 0 )
00068                 DBG ( "ACPI power off failed: %s\n", strerror ( rc ) );
00069 
00070         return rc;
00071 }
00072 
00073 PROVIDE_REBOOT ( pcbios, reboot, bios_reboot );
00074 PROVIDE_REBOOT ( pcbios, poweroff, bios_poweroff );