Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/libsaio/nbp.c

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
25//#include "libsaio.h"
26#include "saio_types.h"
27
28/* This NBP code is pretty useless because it just blindly calls INT 2B.
29 Presumably INT 2B was implemented by some first-stage bootloader that
30 is long gone.
31
32 One good reason to disable this is that nbpScanBootVolumes always
33 succeeds. The scanBootVolumes function thus never fails because
34 it always falls back to NBP. This is a problem because there is
35 other code in the booter (for example, in open) which needs to
36 fail instead of attempting to use this NBP which will often
37 hang the machine.
38 */
39#ifndef NBP_SUPPORT
40#define NBP_SUPPORT 0
41#endif
42
43#if NBP_SUPPORT
44
45/*
46 * Convert zero-based linear address to far pointer.
47 */
48#define GET_FP(x) ( (((x) & 0xffff0000) << (16 - 4)) | ((x) & 0xffff) )
49
50/*==========================================================================
51 * Issue a command to the network loader.
52 *
53 * The 'cmd' command structure should be allocated on the stack to
54 * ensure that it resides within the addressable range for the
55 * network loader, which runs in real mode.
56 */
57static UInt32 nbp(nbpCommandCode_t code, nbpCommand_u * cmd)
58{
59loader(code, GET_FP((UInt32) cmd));
60
61// Must re-enable the A20 address line, the PXE firmware will
62// disable the A20 line control.
63//
64enableA20();
65
66return cmd->header.status;
67}
68
69/*==========================================================================
70 * Unload Base Code Stack command.
71 */
72UInt32 nbpUnloadBaseCode()
73{
74 return nbp(nbpCommandUnloadBaseCode, (nbpCommand_u *) 0);
75}
76
77/*==========================================================================
78 * TFTP Read File command.
79 */
80static long NBPLoadFile(CICell ih, char * filePath)
81{
82 nbpCommandTFTPReadFile_s cmd;
83UInt32 ret;
84
85strcpy((char *)cmd.filename, filePath);
86cmd.status = nbpStatusFailed;
87cmd.bufferSize = TFTP_LEN;
88cmd.buffer = TFTP_ADDR;
89
90verbose("Loading file: %s\n", filePath);
91
92ret = nbp(nbpCommandTFTPReadFile, (nbpCommand_u *) &cmd);
93
94 return (ret == nbpStatusSuccess) ? (long)cmd.bufferSize : -1;
95}
96
97/*==========================================================================
98 * GetDirEntry is not supported.
99 */
100static long NBPGetDirEntry(CICell ih, char * dirPath, long long * dirIndex,
101 char ** name, long * flags, long * time,
102 FinderInfo * finderInfo, long * infoValid)
103{
104 return -1;
105}
106
107//==========================================================================
108
109static void NBPGetDescription(CICell ih, char * str, long strMaxLen)
110{
111 sprintf( str, "Ethernet PXE Client" );
112}
113
114//==========================================================================
115
116BVRef nbpScanBootVolumes( int biosdev, int * countPtr )
117{
118 static BVRef gNetBVR = NULL;
119
120 if ( countPtr ) *countPtr = 1;
121
122 if ( !gNetBVR )
123 {
124 gNetBVR = malloc( sizeof(*gNetBVR) );
125 if ( gNetBVR )
126 {
127 bzero(gNetBVR, sizeof(*gNetBVR));
128 gNetBVR->biosdev = biosdev;
129 gNetBVR->flags = kBVFlagPrimary | kBVFlagNativeBoot;
130 gNetBVR->description = NBPGetDescription;
131 gNetBVR->fs_loadfile = NBPLoadFile;
132 gNetBVR->fs_getdirentry = NBPGetDirEntry;
133 }
134 }
135 return gNetBVR;
136}
137#else
138BVRef nbpScanBootVolumes( int biosdev, int * countPtr )
139{
140 return NULL;
141}
142UInt32 nbpUnloadBaseCode()
143{
144 return 0;
145}
146#endif
147

Archive Download this file

Revision: 495