aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-07-27 06:28:37 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-07-27 06:28:37 +0800
commit98b5c46141f1bd21570e14814ad64f228ce52720 (patch)
tree825f22ea8b49656da16d6f2ca9fb0de42e45f505
parenta46e058bce069922a67653cb50f31934c05cf543 (diff)
downloadpxelinux-98b5c46141f1bd21570e14814ad64f228ce52720.tar.gz
pxelinux-98b5c46141f1bd21570e14814ad64f228ce52720.tar.xz
pxelinux-98b5c46141f1bd21570e14814ad64f228ce52720.zip
Core:PXELINUX: trying to convert ack_packet function and make a C wrapper function fo pxenv
-rw-r--r--core/debug.c6
-rw-r--r--core/extern.inc2
-rw-r--r--core/include/pxe.h152
-rw-r--r--core/pxe.c88
-rw-r--r--core/pxelinux.asm50
5 files changed, 250 insertions, 48 deletions
diff --git a/core/debug.c b/core/debug.c
index 8cf132a2..eef453d0 100644
--- a/core/debug.c
+++ b/core/debug.c
@@ -27,10 +27,14 @@ void dump16(void *buf)
void print_reg(com32sys_t *regs)
{
+#if 0
printf(" DI: %p ", regs->edi.w[0]);
- //dump16(regs->edi.w[0]);
+ dump16(regs->edi.w[0]);
printf(" eax:%p ", regs->eax.l);
printf(" ZF %s ", (regs->eflags.l & EFLAGS_ZF) ? "SET" : "CLEAR");
+#endif
+
+ printf("searching file: %s\n", (char *)(MK_PTR(regs->ds,regs->edi.w[0]) + 4));
}
void dumpn(void *buf, int n)
diff --git a/core/extern.inc b/core/extern.inc
index 9c5cb129..9175c8a1 100644
--- a/core/extern.inc
+++ b/core/extern.inc
@@ -16,7 +16,7 @@
extern parse_dotquad, is_url, lchexbytes, uchexbytes, is_pxe, is_pxenv
extern memory_scan_for_pxe_struct, memory_scan_for_pxenv_struct
extern gendotquad, pxe_load_config, try_load, allocate_socket
- extern free_socket, ip_ok, mangle_name
+ extern free_socket, ip_ok, mangle_name, ack_packet
; debug.c
extern debug, print_reg
diff --git a/core/include/pxe.h b/core/include/pxe.h
index 502d7486..7f30f9a6 100644
--- a/core/include/pxe.h
+++ b/core/include/pxe.h
@@ -1,5 +1,157 @@
+
+/**
+* -----------------------------------------------------------------------
+*
+* Copyright 1999-2008 H. Peter Anvin - All Rights Reserved
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, Inc., 53 Temple Place Ste 330,
+* Boston MA 02111-1307, USA; either version 2 of the License, or
+* (at your option) any later version; incorporated herein by reference.
+*
+* -----------------------------------------------------------------------
+
+*
+* pxe.inc
+*
+* PXE opcodes
+*
+*/
#ifndef PXE_H
+#define PXE_H
+
+
+#define PXENV_TFTP_OPEN 0x0020
+#define PXENV_TFTP_CLOSE 0x0021
+#define PXENV_TFTP_READ 0x0022
+#define PXENV_TFTP_READ_FILE 0x0023
+#define PXENV_TFTP_READ_FILE_PMODE 0x0024
+#define PXENV_TFTP_GET_FSIZE 0x0025
+
+#define PXENV_UDP_OPEN 0x0030
+#define PXENV_UDP_CLOSE 0x0031
+#define PXENV_UDP_READ 0x0032
+#define PXENV_UDP_WRITE 0x0033
+
+#define PXENV_START_UNDI 0x0000
+#define PXENV_UNDI_STARTUP 0x0001
+#define PXENV_UNDI_CLEANUP 0x0002
+#define PXENV_UNDI_INITIALIZE 0x0003
+#define PXENV_UNDI_RESET_NIC 0x0004
+#define PXENV_UNDI_SHUTDOWN 0x0005
+#define PXENV_UNDI_OPEN 0x0006
+#define PXENV_UNDI_CLOSE 0x0007
+#define PXENV_UNDI_TRANSMIT 0x0008
+#define PXENV_UNDI_SET_MCAST_ADDR 0x0009
+#define PXENV_UNDI_SET_STATION_ADDR 0x000A
+#define PXENV_UNDI_SET_PACKET_FILTER 0x000B
+#define PXENV_UNDI_GET_INFORMATION 0x000C
+#define PXENV_UNDI_GET_STATISTICS 0x000D
+#define PXENV_UNDI_CLEAR_STATISTICS 0x000E
+#define PXENV_UNDI_INITIATE_DIAGS 0x000F
+#define PXENV_UNDI_FORCE_INTERRUPT 0x0010
+#define PXENV_UNDI_GET_MCAST_ADDR 0x0011
+#define PXENV_UNDI_GET_NIC_TYPE 0x0012
+#define PXENV_UNDI_GET_IFACE_INFO 0x0013
+#define PXENV_UNDI_ISR 0x0014
+#define PXENV_STOP_UNDI 0x0015
+#define PXENV_UNDI_GET_STATE 0x0015
+
+#define PXENV_UNLOAD_STACK 0x0070
+#define PXENV_GET_CACHED_INFO 0x0071
+#define PXENV_RESTART_DHCP 0x0072
+#define PXENV_RESTART_TFTP 0x0073
+#define PXENV_MODE_SWITCH 0x0074
+#define PXENV_START_BASE 0x0075
+#define PXENV_STOP_BASE 0x0076
+
+/* gPXE extensions... */
+#define PXENV_FILE_OPEN 0x00e0
+#define PXENV_FILE_CLOSE 0x00e1
+#define PXENV_FILE_SELECT 0x00e2
+#define PXENV_FILE_READ 0x00e3
+#define PXENV_GET_FILE_SIZE 0x00e4
+#define PXENV_FILE_EXEC 0x00e5
+#define PXENV_FILE_API_CHECK 0x00e6
+
+/* Exit codes */
+#define PXENV_EXIT_SUCCESS 0x0000
+#define PXENV_EXIT_FAILURE 0x0001
+/* Status codes */
+#define PXENV_STATUS_SUCCESS 0x00
+#define PXENV_STATUS_FAILURE 0x01
+#define PXENV_STATUS_BAD_FUNC 0x02
+#define PXENV_STATUS_UNSUPPORTED 0x03
+#define PXENV_STATUS_KEEP_UNDI 0x04
+#define PXENV_STATUS_KEEP_ALL 0x05
+#define PXENV_STATUS_OUT_OF_RESOURCES 0x06
+#define PXENV_STATUS_ARP_TIMEOUT 0x11
+#define PXENV_STATUS_UDP_CLOSED 0x18
+#define PXENV_STATUS_UDP_OPEN 0x19
+#define PXENV_STATUS_TFTP_CLOSED 0x1a
+#define PXENV_STATUS_TFTP_OPEN 0x1b
+#define PXENV_STATUS_MCOPY_PROBLEM 0x20
+#define PXENV_STATUS_BIS_INTEGRITY_FAILURE 0x21
+#define PXENV_STATUS_BIS_VALIDATE_FAILURE 0x22
+#define PXENV_STATUS_BIS_INIT_FAILURE 0x23
+#define PXENV_STATUS_BIS_SHUTDOWN_FAILURE 0x24
+#define PXENV_STATUS_BIS_GBOA_FAILURE 0x25
+#define PXENV_STATUS_BIS_FREE_FAILURE 0x26
+#define PXENV_STATUS_BIS_GSI_FAILURE 0x27
+#define PXENV_STATUS_BIS_BAD_CKSUM 0x28
+#define PXENV_STATUS_TFTP_CANNOT_ARP_ADDRESS 0x30
+#define PXENV_STATUS_TFTP_OPEN_TIMEOUT 0x32
+#define PXENV_STATUS_TFTP_UNKNOWN_OPCODE 0x33
+#define PXENV_STATUS_TFTP_READ_TIMEOUT 0x35
+#define PXENV_STATUS_TFTP_ERROR_OPCODE 0x36
+#define PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION 0x38
+#define PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION 0x39
+#define PXENV_STATUS_TFTP_TOO_MANY_PACKAGES 0x3a
+#define PXENV_STATUS_TFTP_FILE_NOT_FOUND 0x3b
+#define PXENV_STATUS_TFTP_ACCESS_VIOLATION 0x3c
+#define PXENV_STATUS_TFTP_NO_MCAST_ADDRESS 0x3d
+#define PXENV_STATUS_TFTP_NO_FILESIZE 0x3e
+#define PXENV_STATUS_TFTP_INVALID_PACKET_SIZE 0x3f
+#define PXENV_STATUS_DHCP_TIMEOUT 0x51
+#define PXENV_STATUS_DHCP_NO_IP_ADDRESS 0x52
+#define PXENV_STATUS_DHCP_NO_BOOTFILE_NAME 0x53
+#define PXENV_STATUS_DHCP_BAD_IP_ADDRESS 0x54
+#define PXENV_STATUS_UNDI_INVALID_FUNCTION 0x60
+#define PXENV_STATUS_UNDI_MEDIATEST_FAILED 0x61
+#define PXENV_STATUS_UNDI_CANNOT_INIT_NIC_FOR_MCAST 0x62
+#define PXENV_STATUS_UNDI_CANNOT_INITIALIZE_NIC 0x63
+#define PXENV_STATUS_UNDI_CANNOT_INITIALIZE_PHY 0x64
+#define PXENV_STATUS_UNDI_CANNOT_READ_CONFIG_DATA 0x65
+#define PXENV_STATUS_UNDI_CANNOT_READ_INIT_DATA 0x66
+#define PXENV_STATUS_UNDI_BAD_MAC_ADDRESS 0x67
+#define PXENV_STATUS_UNDI_BAD_EEPROM_CHECKSUM 0x68
+#define PXENV_STATUS_UNDI_ERROR_SETTING_ISR 0x69
+#define PXENV_STATUS_UNDI_INVALID_STATE 0x6a
+#define PXENV_STATUS_UNDI_TRANSMIT_ERROR 0x6b
+#define PXENV_STATUS_UNDI_INVALID_PARAMETER 0x6c
+#define PXENV_STATUS_BSTRAP_PROMPT_MENU 0x74
+#define PXENV_STATUS_BSTRAP_MCAST_ADDR 0x76
+#define PXENV_STATUS_BSTRAP_MISSING_LIST 0x77
+#define PXENV_STATUS_BSTRAP_NO_RESPONSE 0x78
+#define PXENV_STATUS_BSTRAP_FILE_TOO_BIG 0x79
+#define PXENV_STATUS_BINL_CANCELED_BY_KEYSTROKE 0xa0
+#define PXENV_STATUS_BINL_NO_PXE_SERVER 0xa1
+#define PXENV_STATUS_NOT_AVAILABLE_IN_PMODE 0xa2
+#define PXENV_STATUS_NOT_AVAILABLE_IN_RMODE 0xa3
+#define PXENV_STATUS_BUSD_DEVICE_NOT_SUPPORTED 0xb0
+#define PXENV_STATUS_LOADER_NO_FREE_BASE_MEMORY 0xc0
+#define PXENV_STATUS_LOADER_NO_BC_ROMID 0xc1
+#define PXENV_STATUS_LOADER_BAD_BC_ROMID 0xc2
+#define PXENV_STATUS_LOADER_BAD_BC_RUNTIME_IMAGE 0xc3
+#define PXENV_STATUS_LOADER_NO_UNDI_ROMID 0xc4
+#define PXENV_STATUS_LOADER_BAD_UNDI_ROMID 0xc5
+#define PXENV_STATUS_LOADER_BAD_UNDI_DRIVER_IMAGE 0xc6
+#define PXENV_STATUS_LOADER_NO_PXE_STRUCT 0xc8
+#define PXENV_STATUS_LOADER_NO_PXENV_STRUCT 0xc9
+#define PXENV_STATUS_LOADER_UNDI_START 0xca
+#define PXENV_STATUS_LOADER_BC_START 0xcb
#endif /* pxe.h */
diff --git a/core/pxe.c b/core/pxe.c
index f4b894e8..4f8d792f 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -28,10 +28,26 @@ struct open_file_t {
uint8_t tftp_unused[3]; /* Currently unused */
uint16_t tftp_pktbuf; /* Packet buffer offset */
};
-
extern char Files[];
+
+struct pxe_udp_write_pkt {
+ uint16_t status;
+ uint32_t sip;
+ uint32_t gip;
+ uint16_t lport;
+ uint16_t rport;
+ uint16_t buffersize;
+ uint16_t buffer[2];
+};
+extern char pxe_udp_write_pkt[];
+
extern uint32_t ServerIP;
+extern uint32_t MyIP;
+extern uint32_t Netmask;
+extern uint32_t Gateway;
+/* TFTP ACK packet */
+extern uint16_t ack_packet_buf[];
uint16_t NextSocket = 49152;
@@ -112,8 +128,7 @@ void mangle_name(com32sys_t *regs)
char *p = src;
uint32_t ip;
int i = 0;
- char *d = dst;
-
+
#if GPXE
is_url(regs);
if ((regs->eflags.l & EFLAGS_CF) == 0) {
@@ -140,6 +155,7 @@ void mangle_name(com32sys_t *regs)
if ((p = parse_dotquad(p, &ip)) && !strncmp(p, "::", 2))
goto gotprefix;
else {
+ extern void dns_resolv();
dns_resolv(regs);
p = (char *)MK_PTR(regs->ds, regs->esi.w[0]);
ip = regs->eax.l;
@@ -455,7 +471,6 @@ void pxe_load_config(com32sys_t *regs)
extern char UUID[];
extern char MACStr[];
extern uint8_t DHCPMagic;
- extern uint8_t MyIP[];
extern void no_config();
char *cfgprefix = "pxelinux.cfg/";
char *default_str = "default";
@@ -512,7 +527,7 @@ void pxe_load_config(com32sys_t *regs)
/* Nope, try hexadecimal IP prefixes... */
regs->ecx.w[0] = 4;
regs->edi.w[0] = OFFS_WRT(config_file, 0);
- regs->esi.w[0] = OFFS_WRT(MyIP, 0);
+ regs->esi.w[0] = OFFS_WRT(&MyIP, 0);
uchexbytes(regs); /* Convet to hex string */
last = (uint8_t *)MK_PTR(regs->ds, regs->edi.w[0]);
@@ -621,3 +636,66 @@ void ip_ok(com32sys_t *regs)
bad:
regs->eflags.l |= EFLAGS_ZF;
}
+
+int pxe_call(int opcode, void *data)
+{
+ extern void pxenv();
+ com32sys_t in_regs, out_regs;
+
+ memset(&in_regs, 0, sizeof in_regs);
+ memset(&out_regs, 0, sizeof out_regs);
+
+ in_regs.ebx.w[0] = opcode;
+ in_regs.es = SEG(data);
+ in_regs.edi.w[0] = OFFS(data);
+ call16(pxenv, &in_regs, &out_regs);
+
+ return out_regs.eflags.l & EFLAGS_CF; /* CF SET for fail */
+}
+
+/**
+ *
+ * Send ACK packet. This is a common operation and so is worth canning.
+ *
+ * Entry:
+ * SI = TFTP block
+ * AX = Packet # to ack (network byte order)
+ * Exit:
+ * All regiseters preserved
+ * This function uses the pxe_udp_write_pkt but not the packet_buf
+ *
+ */
+void ack_packet(com32sys_t *regs)
+{
+ extern void pxenv();
+ uint16_t bx, di;
+ struct pxe_udp_write_pkt *uw_pkt = (struct pxe_udp_write_pkt *)pxe_udp_write_pkt;;
+ struct open_file_t *file = (struct open_file_t *)MK_PTR(0, regs->esi.w[0]);
+
+#if 1
+ printf("Sending ack packet (%p)....\n", uw_pkt);
+#endif
+ /* Packet number to ack */
+ ack_packet_buf[1] = regs->eax.w[0];
+ uw_pkt->lport = file->tftp_localport;
+ uw_pkt->rport = file->tftp_remoteport;
+ uw_pkt->sip = file->tftp_remoteip;
+ uw_pkt->gip = ((uw_pkt->sip ^ MyIP) & Netmask) ? Gateway : 0;
+ uw_pkt->buffer[0] = OFFS(ack_packet_buf);
+ uw_pkt->buffer[1] = SEG(ack_packet_buf);
+ uw_pkt->buffersize = 4;
+
+#if 0
+ pxe_call(PXENV_UDP_WRITE, &uw_pkt);
+#else
+ bx = regs->ebx.w[0];
+ di = regs->edi.w[0];
+ regs->ebx.w[0] = PXENV_UDP_WRITE;
+ regs->edi.w[0] = (uint16_t)uw_pkt;
+ call16(pxenv, regs, NULL);
+ regs->ebx.w[0] = bx;
+ regs->edi.w[0] = di;
+#endif
+ printf("sent!\n");
+}
+
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 6e4e648d..e3f34922 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -804,7 +804,7 @@ searchdir:
mov si,di
push bp
mov bp,sp
-
+ pm_call print_reg
pm_call allocate_socket
jz .ret
@@ -1064,7 +1064,7 @@ searchdir:
push si
mov si,bx
; AX = htons(1) already
- call ack_packet
+ pm_call ack_packet
pop si
.not_eof:
mov [bx+tftp_bytesleft],cx
@@ -1238,6 +1238,7 @@ unmangle_name:
;
; While we're at it, save and restore all registers.
;
+ global pxenv
pxenv:
pushfd
pushad
@@ -1411,7 +1412,7 @@ fill_buffer:
movzx cx,byte [bx] ; Timeout
mov ax,[si+tftp_lastpkt]
- call ack_packet ; Send ACK
+ pm_call ack_packet ; Send ACK
; We used to test the error code here, but sometimes
; PXE would return negative status even though we really
@@ -1477,7 +1478,7 @@ fill_buffer:
; This is presumably because the ACK got lost,
; so the server just resent the previous packet
mov ax,[fs:bx+2]
- call ack_packet
+ pm_call ack_packet
jmp .send_ok ; Reset timeout
.right_packet: ; It's the packet we want. We're also EOF if the
@@ -1508,7 +1509,7 @@ fill_buffer:
.last_block: ; Last block - ACK packet immediately
mov ax,[fs:bx+2]
- call ack_packet
+ pm_call ack_packet
; Make sure we know we are at end of file
mov eax,[si+tftp_filepos]
@@ -1530,41 +1531,6 @@ TimeoutTable:
TimeoutTableEnd equ $
section .text16
-;
-; ack_packet:
-;
-; Send ACK packet. This is a common operation and so is worth canning.
-;
-; Entry:
-; SI = TFTP block
-; AX = Packet # to ack (network byte order)
-; Exit:
-; All registers preserved
-;
-; This function uses the pxe_udp_write_pkt but not the packet_buf.
-;
-ack_packet:
- pushad
- mov [ack_packet_buf+2],ax ; Packet number to ack
- mov ax,[si]
- mov [pxe_udp_write_pkt.lport],ax
- mov ax,[si+tftp_remoteport]
- mov [pxe_udp_write_pkt.rport],ax
- mov eax,[si+tftp_remoteip]
- mov [pxe_udp_write_pkt.sip],eax
- xor eax,[MyIP]
- and eax,[Netmask]
- jz .nogw
- mov eax,[Gateway]
-.nogw:
- mov [pxe_udp_write_pkt.gip],eax
- mov [pxe_udp_write_pkt.buffer],word ack_packet_buf
- mov [pxe_udp_write_pkt.buffersize], word 4
- mov di,pxe_udp_write_pkt
- mov bx,PXENV_UDP_WRITE
- call pxenv
- popad
- ret
%if GPXE
;
@@ -2154,6 +2120,7 @@ old_api_unload:
; PXE query packets partially filled in
;
section .bss16
+ global pxe_udp_write_pkt
pxe_bootp_query_pkt:
.status: resw 1 ; Status
.packettype: resw 1 ; Boot server packet type
@@ -2262,11 +2229,12 @@ tftp_proto_err dw TFTP_ERROR ; ERROR packet
tftp_proto_err_len equ ($-tftp_proto_err)
alignz 4
+ global ack_packet_buf
ack_packet_buf: dw TFTP_ACK, 0 ; TFTP ACK packet
;
; IP information (initialized to "unknown" values)
- global MyIP, ServerIP
+ global MyIP, ServerIP, Netmask, Gateway
MyIP dd 0 ; My IP address
ServerIP dd 0 ; IP address of boot server
Netmask dd 0 ; Netmask of this subnet