]> git.saurik.com Git - apple/boot.git/blob - i386/boot1/gonext.c
4fa31aadd04495eb57837e60e348f002b672c65e
[apple/boot.git] / i386 / boot1 / gonext.c
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 #include <bios.h>
26 #include <dos.h>
27 #include <stdio.h>
28
29 char bufold[512];
30
31 int main(int argc, char *argv[])
32 {
33 void far (*reset)();
34 #define CMD 2
35 #define DRIVE 0x80
36 #define HEAD 0
37 #define TRACK 0
38 #define SECT 1
39 #define NSECT 1
40 int result, i;
41 int found;
42 unsigned char *p1, *p2, key;
43 int softReboot=0;
44 int dontAsk=0;
45
46 for (i=1; i<argc; i++)
47 {
48 if (!strcmp(argv[i],"-dontask")) dontAsk=1;
49 else if (!strcmp(argv[i],"-soft")) softReboot=1;
50 }
51
52 if (!dontAsk)
53 {
54 printf("Do you want to reboot into NEXTSTEP?\n");
55 printf(" (This will immediately terminate all processes!)\n");
56 key = bioskey(0);
57 if (!(key=='y' || key=='Y'))
58 {
59 printf("Cancelled\n");
60 exit(0);
61 }
62 }
63
64 result = biosdisk(CMD,DRIVE,HEAD,TRACK,SECT,NSECT,bufold);
65 if (result != 0)
66 { printf("Couldn't read bootsectorread\n");
67 exit(0);
68 }
69
70 p1 = bufold + 445;
71
72 if (*p1 != 0xa7)
73 {
74 printf("GONEXT can only work if NeXT's BOOT0 bootsector"
75 " is installed.\n");
76 exit(0);
77 }
78
79 found = 0;
80 p1=bufold + 446;
81 for (i=0; i<4; i++)
82 { p2 = p1 + (i*16) + 4;
83 if (*p2 == 0xa7)
84 { found=1;
85 break;
86 }
87 }
88
89 if (!found)
90 { printf("No NEXTSTEP partition installed\n");
91 exit(0);
92 }
93
94 /* now do the proper CMOS write! */
95
96
97 outportb(0x70,6); /* select */
98 key = inportb(0x71);
99 key |= 0x10;
100 outportb(0x70,6); /* select */
101 outportb(0x71,key);
102
103 if (softReboot) geninterrupt(0x19);
104 else
105 {
106 printf("'Scuse me while I kiss the sky!\n");
107 reset = MK_FP(0xf000,0xfff0);
108 reset();
109 geninterrupt(0x19); /* try again - shouldn't get here */
110 }
111
112 printf("Reboot failed\n");
113 return -1; /* you never get here */
114 }