aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-07-26 13:02:36 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-07-26 13:02:36 +0800
commitc7595667e3620aea55648a1dbb386bc74cf5ae57 (patch)
treea468b5d6301df9b6637eae64754c21e3a7499d23
parentf2cf077ea8b0c10427fc1342f0de797b3075be1c (diff)
downloadpxelinux-c7595667e3620aea55648a1dbb386bc74cf5ae57.tar.gz
pxelinux-c7595667e3620aea55648a1dbb386bc74cf5ae57.tar.xz
pxelinux-c7595667e3620aea55648a1dbb386bc74cf5ae57.zip
Core:PXELINUX: allocate_socket converted
-rw-r--r--core/extern.inc2
-rw-r--r--core/pxe.c76
-rw-r--r--core/pxelinux.asm47
3 files changed, 75 insertions, 50 deletions
diff --git a/core/extern.inc b/core/extern.inc
index b13aef39..7c5b487d 100644
--- a/core/extern.inc
+++ b/core/extern.inc
@@ -15,7 +15,7 @@
; pxe.c
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
+ extern gendotquad, pxe_load_config, try_load, allocate_socket
; debug.c
extern debug, print_reg
diff --git a/core/pxe.c b/core/pxe.c
index a691cc6e..a3b5dde0 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -3,13 +3,35 @@
#include <core.h>
#include <pxe.h>
-
+#define MAX_OPEN_LG2 5
+#define MAX_OPEN (1 << MAX_OPEN_LG2)
#define FILENAME_MAX_LG2 7
#define FILENAME_MAX (1 << FILENAME_MAX_LG2)
#define GPXE 1
-#define is_digit(c) ((c >= '0') && (c <= '9'))
+#define is_digit(c) (((c) >= '0') && ((c) <= '9'))
+#define htons(x) ( ( ((x) & 0xff) << 8) + ( ((x) &0xff00) >> 8) )
+#define ntohs(x) htons(x)
+
+struct open_file_t {
+ uint16_t tftp_localport; /* Local port number (0=not in us)*/
+ uint16_t tftp_remoteport; /* Remote port number */
+ uint32_t tftp_remoteip; /* Remote IP address */
+ uint32_t tftp_filepos; /* bytes downloaded (includeing buffer) */
+ uint32_t tftp_filesize; /* Total file size(*) */
+ uint32_t tftp_blksize; /* Block size for this connection(*) */
+ uint16_t tftp_bytesleft; /* Unclaimed data bytes */
+ uint16_t tftp_lastpkt; /* Sequence number of last packet (NBO) */
+ uint16_t tftp_dataptr; /* Pointer to available data */
+ uint8_t tftp_goteof; /* 1 if the EOF packet received */
+ uint8_t tftp_unused[3]; /* Currently unused */
+ uint16_t tftp_pktbuf; /* Packet buffer offset */
+};
+
+extern char Files[];
+
+uint16_t NextSocket = 49152;
/*********************************************************************
;
@@ -285,7 +307,7 @@ void gendotquad(com32sys_t *regs)
regs->edi.w[0] = OFFS_WRT(str, 0);
}
-/********************************
+/*
void genipopt(com32sys_t *regs)
{
extern char IPOption[];
@@ -428,5 +450,51 @@ void pxe_load_config(com32sys_t *regs)
}
-
+/******************************************************************
+; Allocate a local UDP port structure
+;
+; If successful:
+; ZF clear
+; BX = socket pointer
+; If unsuccessful:
+; ZF set
+;
+******************************************************************/
+void allocate_socket(com32sys_t *regs)
+{
+ extern uint16_t NextSocket;
+ uint16_t i = MAX_OPEN;
+ struct open_file_t *socket = (struct open_file_t *)&Files;
+
+ for (; i > 0; i--) {
+ if (*(uint16_t*)socket == 0)
+ break;
+ socket ++;
+ }
+
+ /* Not found */
+ if (i == 0) {
+ regs->eflags.l |= EFLAGS_ZF;
+ return;
+ }
+
+ /*
+ * Allocate a socket number. Socket numbers are made guaranteed unique
+ * by including the socket slot number(inverted, because we use the loop
+ * counter cx; add a counter value to keep the numbers from being likely
+ * to get immediately reused.
+ *
+ * The NextSocket variable also contains the top two bits set. This
+ * generates a value in the range 49152 to 57343.
+ *
+ */
+ i--;
+ NextSocket = ((NextSocket + 1) & ((1 << (13-MAX_OPEN_LG2))-1)) | 0xc000;
+ i <<= 13-MAX_OPEN_LG2;
+ i += NextSocket;
+ i = ntohs(i) ; /* convet to network byte order, little to big */
+ *(uint16_t*)socket = i; /* socket in use */
+ regs->ebx.w[0] = OFFS_WRT(socket, 0);
+ regs->eflags.l &= ~EFLAGS_ZF;
+}
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 792c7c61..5911501f 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -166,6 +166,7 @@ trackbuf resb trackbufsize ; Track buffer goes here
; ends at 2800h
section .bss16
+ global Files
alignb open_file_t_size
Files resb MAX_OPEN*open_file_t_size
@@ -804,7 +805,7 @@ searchdir:
push bp
mov bp,sp
- call allocate_socket
+ pm_call allocate_socket
jz .ret
mov ax,TimeoutTable ; Reset timeout
@@ -1144,49 +1145,6 @@ searchdir:
jmp .got_file
%endif ; GPXE
-;
-; allocate_socket: Allocate a local UDP port structure
-;
-; If successful:
-; ZF set
-; BX = socket pointer
-; If unsuccessful:
-; ZF clear
-;
-allocate_socket:
- push cx
- mov bx,Files
- mov cx,MAX_OPEN
-.check: cmp word [bx], byte 0
- je .found
- add bx,open_file_t_size
- loop .check
- xor cx,cx ; ZF = 1
- pop cx
- ret
- ; Allocate a socket number. Socket numbers are made
- ; guaranteed unique by including the socket slot number
- ; (inverted, because we use the loop counter cx); add a
- ; counter value to keep the numbers from being likely to
- ; get immediately reused.
- ;
- ; The NextSocket variable also contains the top two bits
- ; set. This generates a value in the range 49152 to
- ; 57343.
-.found:
- dec cx
- push ax
- mov ax,[NextSocket]
- inc ax
- and ax,((1 << (13-MAX_OPEN_LG2))-1) | 0xC000
- mov [NextSocket],ax
- shl cx,13-MAX_OPEN_LG2
- add cx,ax ; ZF = 0
- xchg ch,cl ; Convert to network byte order
- mov [bx],cx ; Socket in use
- pop ax
- pop cx
- ret
;
; Free socket: socket in SI; return SI = 0, ZF = 1 for convenience
@@ -2389,7 +2347,6 @@ gpxe_file_read:
alignz 4
BaseStack dd StackTop ; ESP of base stack
dw 0 ; SS of base stack
-NextSocket dw 49152 ; Counter for allocating socket numbers
KeepPXE db 0 ; Should PXE be kept around?
;