| 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 | |
| 27 | /* |
| 28 | * Convert zero-based linear address to far pointer. |
| 29 | */ |
| 30 | #define GET_FP(x) ( (((x) & 0xffff0000) << (16 - 4)) | ((x) & 0xffff) ) |
| 31 | |
| 32 | /*========================================================================== |
| 33 | * Issue a command to the network loader. |
| 34 | * |
| 35 | * The 'cmd' command structure should be allocated on the stack to |
| 36 | * ensure that it resides within the addressable range for the |
| 37 | * network loader, which runs in real mode. |
| 38 | */ |
| 39 | static UInt32 nbp(nbpCommandCode_t code, nbpCommand_u * cmd) |
| 40 | { |
| 41 | loader(code, GET_FP((UInt32) cmd)); |
| 42 | |
| 43 | // Must re-enable the A20 address line, the PXE firmware will |
| 44 | // disable the A20 line control. |
| 45 | // |
| 46 | enableA20(); |
| 47 | |
| 48 | return cmd->header.status; |
| 49 | } |
| 50 | |
| 51 | /*========================================================================== |
| 52 | * Unload Base Code Stack command. |
| 53 | */ |
| 54 | UInt32 nbpUnloadBaseCode() |
| 55 | { |
| 56 | return nbp(nbpCommandUnloadBaseCode, (nbpCommand_u *) 0); |
| 57 | } |
| 58 | |
| 59 | /*========================================================================== |
| 60 | * TFTP Read File command. |
| 61 | */ |
| 62 | static long NBPLoadFile(CICell ih, char * filePath) |
| 63 | { |
| 64 | nbpCommandTFTPReadFile_s cmd; |
| 65 | UInt32 ret; |
| 66 | |
| 67 | strcpy((char *)cmd.filename, filePath); |
| 68 | cmd.status = nbpStatusFailed; |
| 69 | cmd.bufferSize = TFTP_LEN; |
| 70 | cmd.buffer = TFTP_ADDR; |
| 71 | |
| 72 | verbose("Loading file: %s\n", filePath); |
| 73 | |
| 74 | ret = nbp(nbpCommandTFTPReadFile, (nbpCommand_u *) &cmd); |
| 75 | |
| 76 | return (ret == nbpStatusSuccess) ? (long)cmd.bufferSize : -1; |
| 77 | } |
| 78 | |
| 79 | /*========================================================================== |
| 80 | * GetDirEntry is not supported. |
| 81 | */ |
| 82 | static long NBPGetDirEntry(CICell ih, char * dirPath, long * dirIndex, |
| 83 | char ** name, long * flags, long * time, |
| 84 | FinderInfo * finderInfo, long * infoValid) |
| 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 | } |