]> git.saurik.com Git - apple/boot.git/blob - i386/libsaio/nbp.c
boot-111.tar.gz
[apple/boot.git] / i386 / libsaio / nbp.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
26 #include "libsaio.h"
27
28 /*
29 * Convert zero-based linear address to far pointer.
30 */
31 #define GET_FP(x) ( (((x) & 0xffff0000) << (16 - 4)) | ((x) & 0xffff) )
32
33 /*==========================================================================
34 * Issue a command to the network loader.
35 *
36 * The 'cmd' command structure should be allocated on the stack to
37 * ensure that it resides within the addressable range for the
38 * network loader, which runs in real mode.
39 */
40 static UInt32 nbp(nbpCommandCode_t code, nbpCommand_u * cmd)
41 {
42 loader(code, GET_FP((UInt32) cmd));
43
44 // Must re-enable the A20 address line, the PXE firmware will
45 // disable the A20 line control.
46 //
47 enableA20();
48
49 return cmd->header.status;
50 }
51
52 /*==========================================================================
53 * Unload Base Code Stack command.
54 */
55 UInt32 nbpUnloadBaseCode()
56 {
57 return nbp(nbpCommandUnloadBaseCode, (nbpCommand_u *) 0);
58 }
59
60 /*==========================================================================
61 * TFTP Read File command.
62 */
63 static long NBPLoadFile(CICell ih, char * filePath)
64 {
65 nbpCommandTFTPReadFile_s cmd;
66 UInt32 ret;
67
68 strcpy(cmd.filename, filePath);
69 cmd.status = nbpStatusFailed;
70 cmd.bufferSize = TFTP_LEN;
71 cmd.buffer = TFTP_ADDR;
72
73 verbose("Loading file: %s\n", filePath);
74
75 ret = nbp(nbpCommandTFTPReadFile, (nbpCommand_u *) &cmd);
76
77 return (ret == nbpStatusSuccess) ? (long)cmd.bufferSize : -1;
78 }
79
80 /*==========================================================================
81 * GetDirEntry is not supported.
82 */
83 static long NBPGetDirEntry(CICell ih, char * dirPath, long * dirIndex,
84 char ** name, long * flags, long * time)
85 {
86 return -1;
87 }
88
89 //==========================================================================
90
91 static void NBPGetDescription(CICell ih, char * str, long strMaxLen)
92 {
93 sprintf( str, "Ethernet PXE Client" );
94 }
95
96 //==========================================================================
97
98 BVRef nbpScanBootVolumes( int biosdev, int * countPtr )
99 {
100 static BVRef gNetBVR = NULL;
101
102 if ( countPtr ) *countPtr = 1;
103
104 if ( !gNetBVR )
105 {
106 gNetBVR = malloc( sizeof(*gNetBVR) );
107 if ( gNetBVR )
108 {
109 bzero(gNetBVR, sizeof(*gNetBVR));
110 gNetBVR->biosdev = biosdev;
111 gNetBVR->flags = kBVFlagPrimary | kBVFlagNativeBoot;
112 gNetBVR->description = NBPGetDescription;
113 gNetBVR->fs_loadfile = NBPLoadFile;
114 gNetBVR->fs_getdirentry = NBPGetDirEntry;
115 }
116 }
117 return gNetBVR;
118 }