1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | #include "libsaio.h"␊ |
25 | #include "nbp_cmd.h"␊ |
26 | ␊ |
27 | /* This NBP code is pretty useless because it just blindly calls INT 2B.␊ |
28 | Presumably INT 2B was implemented by some first-stage bootloader that␊ |
29 | is long gone.␊ |
30 | ␊ |
31 | One good reason to disable this is that nbpScanBootVolumes always␊ |
32 | succeeds. The scanBootVolumes function thus never fails because␊ |
33 | it always falls back to NBP. This is a problem because there is␊ |
34 | other code in the booter (for example, in open) which needs to␊ |
35 | fail instead of attempting to use this NBP which will often␊ |
36 | hang the machine.␊ |
37 | */␊ |
38 | ␊ |
39 | ␊ |
40 | /*␊ |
41 | * Convert zero-based linear address to far pointer.␊ |
42 | */␊ |
43 | #define GET_FP(x) ( (((x) & 0xffff0000) << (16 - 4)) | ((x) & 0xffff) )␊ |
44 | ␊ |
45 | /*==========================================================================␊ |
46 | * Issue a command to the network loader.␊ |
47 | *␊ |
48 | * The 'cmd' command structure should be allocated on the stack to␊ |
49 | * ensure that it resides within the addressable range for the␊ |
50 | * network loader, which runs in real mode.␊ |
51 | */␊ |
52 | static UInt32 nbp(nbpCommandCode_t code, nbpCommand_u * cmd)␊ |
53 | {␊ |
54 | ␉loader(code, GET_FP((UInt32) cmd));␊ |
55 | ␊ |
56 | ␉// Must re-enable the A20 address line, the PXE firmware will␊ |
57 | ␉// disable the A20 line control.␊ |
58 | ␉//␊ |
59 | ␉enableA20();␊ |
60 | ␊ |
61 | ␉return cmd->header.status;␊ |
62 | }␊ |
63 | ␊ |
64 | /*==========================================================================␊ |
65 | * Unload Base Code Stack command.␊ |
66 | */␊ |
67 | UInt32 nbpUnloadBaseCode()␊ |
68 | {␊ |
69 | return nbp(nbpCommandUnloadBaseCode, (nbpCommand_u *) 0);␊ |
70 | }␊ |
71 | ␊ |
72 | /*==========================================================================␊ |
73 | * TFTP Read File command.␊ |
74 | */␊ |
75 | static long NBPLoadFile(CICell ih, char * filePath)␊ |
76 | {␊ |
77 | nbpCommandTFTPReadFile_s cmd;␊ |
78 | ␉UInt32 ret;␊ |
79 | ␊ |
80 | ␉strcpy((char *)cmd.filename, filePath);␊ |
81 | ␉cmd.status = nbpStatusFailed;␊ |
82 | ␉cmd.bufferSize = TFTP_LEN;␊ |
83 | ␉cmd.buffer = TFTP_ADDR;␊ |
84 | ␊ |
85 | ␉verbose("Loading file: %s\n", filePath);␊ |
86 | ␊ |
87 | ␉ret = nbp(nbpCommandTFTPReadFile, (nbpCommand_u *) &cmd);␊ |
88 | ␊ |
89 | return (ret == nbpStatusSuccess) ? (long)cmd.bufferSize : -1;␊ |
90 | }␊ |
91 | ␊ |
92 | /*==========================================================================␊ |
93 | * GetDirEntry is not supported.␊ |
94 | */␊ |
95 | static long NBPGetDirEntry(CICell ih, char * dirPath, long long * dirIndex,␊ |
96 | char ** name, long * flags, long * time,␊ |
97 | FinderInfo * finderInfo, long * infoValid)␊ |
98 | {␊ |
99 | return -1;␊ |
100 | }␊ |
101 | ␊ |
102 | //==========================================================================␊ |
103 | ␊ |
104 | static void NBPGetDescription(CICell ih, char * str, long strMaxLen)␊ |
105 | {␊ |
106 | snprintf( str, strMaxLen,"Ethernet PXE Client" );␊ |
107 | }␊ |
108 | ␊ |
109 | //==========================================================================␊ |
110 | ␊ |
111 | BVRef nbpScanBootVolumes( int biosdev, int * countPtr )␊ |
112 | {␊ |
113 | static BVRef gNetBVR = NULL;␊ |
114 | ␊ |
115 | if ( countPtr ) *countPtr = 1;␊ |
116 | ␊ |
117 | if ( !gNetBVR )␊ |
118 | {␊ |
119 | gNetBVR = malloc( sizeof(*gNetBVR) );␊ |
120 | if ( gNetBVR )␊ |
121 | {␊ |
122 | bzero(gNetBVR, sizeof(*gNetBVR));␊ |
123 | gNetBVR->biosdev = biosdev;␊ |
124 | gNetBVR->flags = kBVFlagPrimary | kBVFlagNativeBoot;␊ |
125 | gNetBVR->description = NBPGetDescription;␊ |
126 | gNetBVR->fs_loadfile = NBPLoadFile;␊ |
127 | gNetBVR->fs_getdirentry = NBPGetDirEntry;␊ |
128 | }␊ |
129 | }␊ |
130 | return gNetBVR;␊ |
131 | } |