1 /* 2 * GRUB -- GRand Unified Bootloader 3 * Copyright (C) 2001,2002 Free Software Foundation, Inc. 4 * 5 * This program 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 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program 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 this program; if not, write to the Free Software 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 */ 19 /* 20 * Copyright 2016 Nexenta Systems, Inc. 21 */ 22 23 #include "shared.h" 24 25 static unsigned long long saved_sector = (unsigned long long)-1; 26 27 static void 28 disk_read_savesect_func (unsigned long long sector, int offset, int length) 29 { 30 saved_sector = sector; 31 } 32 33 void 34 cmain (void) 35 { 36 grub_printf ("\n\nGRUB loading, please wait...\n"); 37 38 /* 39 * Here load the true second-stage boot-loader. 40 */ 41 42 if (grub_open (config_file)) 43 { 44 int ret; 45 46 disk_read_hook = disk_read_savesect_func; 47 grub_read ((char *) 0x8000, SECTOR_SIZE * 2); 48 disk_read_hook = NULL; 49 50 /* Sanity check: catch an internal error. */ 51 if (saved_sector == (unsigned int)-1) 52 { 53 grub_printf ("internal error: the second sector of Stage 2 is unknown."); 54 stop (); 55 } 56 57 ret = grub_read ((char *) 0x8000 + SECTOR_SIZE * 2, -1); 58 59 grub_close (); 60 61 if (ret) 62 chain_stage2 (0, 0x8200, saved_sector); 63 } 64 65 /* 66 * If not, then print error message and die. 67 */ 68 69 print_error (); 70 71 stop (); 72 } 73