Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Trunk/i386/libsaio/nbp.c

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

Archive Download this file

Revision: 2062