xref: /titanic_44/usr/src/grub/grub-0.97/stage2/stage1_5.c (revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809)
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 #include "shared.h"
21 
22 static unsigned int saved_sector = (unsigned int)-1;
23 
24 static void
disk_read_savesect_func(unsigned int sector,int offset,int length)25 disk_read_savesect_func (unsigned int sector, int offset, int length)
26 {
27   saved_sector = sector;
28 }
29 
30 void
cmain(void)31 cmain (void)
32 {
33   grub_printf ("\n\nGRUB loading, please wait...\n");
34 
35   /*
36    *  Here load the true second-stage boot-loader.
37    */
38 
39   if (grub_open (config_file))
40     {
41       int ret;
42 
43       disk_read_hook = disk_read_savesect_func;
44       grub_read ((char *) 0x8000, SECTOR_SIZE * 2);
45       disk_read_hook = NULL;
46 
47       /* Sanity check: catch an internal error.  */
48       if (saved_sector == (unsigned int)-1)
49 	{
50 	  grub_printf ("internal error: the second sector of Stage 2 is unknown.");
51 	  stop ();
52 	}
53 
54       ret = grub_read ((char *) 0x8000 + SECTOR_SIZE * 2, -1);
55 
56       grub_close ();
57 
58       if (ret)
59 	chain_stage2 (0, 0x8200, saved_sector);
60     }
61 
62   /*
63    *  If not, then print error message and die.
64    */
65 
66   print_error ();
67 
68   stop ();
69 }
70