aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-07-26 14:39:12 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-07-26 14:39:12 +0800
commita46e058bce069922a67653cb50f31934c05cf543 (patch)
treeada0f0889324959f7014abe545d8def0fdc65a85
parent8092b5ba226dfd890e687041cc0f3f368bc5ee22 (diff)
downloadpxelinux-a46e058bce069922a67653cb50f31934c05cf543.tar.gz
pxelinux-a46e058bce069922a67653cb50f31934c05cf543.tar.xz
pxelinux-a46e058bce069922a67653cb50f31934c05cf543.zip
Core:PXELINUX: mangle_name converted
-rw-r--r--core/comboot.inc6
-rw-r--r--core/conio.inc2
-rw-r--r--core/debug.c15
-rw-r--r--core/dnsresolv.inc1
-rw-r--r--core/extern.inc2
-rw-r--r--core/parseconfig.inc10
-rw-r--r--core/pxe.c144
-rw-r--r--core/pxelinux.asm85
-rw-r--r--core/runkernel.inc2
-rw-r--r--core/ui.inc2
10 files changed, 143 insertions, 126 deletions
diff --git a/core/comboot.inc b/core/comboot.inc
index ab5e33fe..5c9ffc87 100644
--- a/core/comboot.inc
+++ b/core/comboot.inc
@@ -517,7 +517,7 @@ comapi_open:
mov ds,P_ES
mov si,P_SI
mov di,InitRD
- call mangle_name
+ pm_call mangle_name
pop ds
call searchdir
jz comapi_err
@@ -748,7 +748,7 @@ comapi_runkernel:
mov ds,P_DS
mov si,P_SI
mov di,KernelName
- call mangle_name
+ pm_call mangle_name
pop ds
call searchdir
jz comapi_err
@@ -904,7 +904,7 @@ comapi_opendir:
mov ds,P_ES
mov si,P_SI
mov di,InitRD
- call mangle_name
+ pm_call mangle_name
pop ds
call searchdir
jnz comapi_err ; Didn't find a directory
diff --git a/core/conio.inc b/core/conio.inc
index 5209af1c..4fcc8546 100644
--- a/core/conio.inc
+++ b/core/conio.inc
@@ -207,7 +207,7 @@ msg_viewimage:
mov byte [si],0 ; Zero-terminate filename
mov si,VGAFileBuf
mov di,VGAFileMBuf
- call mangle_name
+ pm_call mangle_name
call open
jz msg_putcharnext ; Not there
call vgadisplayfile
diff --git a/core/debug.c b/core/debug.c
index 10571128..8cf132a2 100644
--- a/core/debug.c
+++ b/core/debug.c
@@ -32,3 +32,18 @@ void print_reg(com32sys_t *regs)
printf(" eax:%p ", regs->eax.l);
printf(" ZF %s ", (regs->eflags.l & EFLAGS_ZF) ? "SET" : "CLEAR");
}
+
+void dumpn(void *buf, int n)
+{
+ uint8_t *p = (uint8_t *)buf;
+ int i = 0;
+
+ for (; i < n; i++)
+ printf("%02x ", *p++);
+
+ p = (uint8_t *)buf;
+ printf(" ");
+ for (i = 0; i < n; i++)
+ printf("%c", *p++);
+ printf("\n");
+}
diff --git a/core/dnsresolv.inc b/core/dnsresolv.inc
index 7b632378..7105f791 100644
--- a/core/dnsresolv.inc
+++ b/core/dnsresolv.inc
@@ -186,6 +186,7 @@ LastDNSServer dw DNSServers
; No segment assumptions permitted.
;
section .text16
+ global dns_resolv
dns_resolv:
push ds
push es
diff --git a/core/extern.inc b/core/extern.inc
index 2aa25e23..9c5cb129 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
+ extern free_socket, ip_ok, mangle_name
; debug.c
extern debug, print_reg
diff --git a/core/parseconfig.inc b/core/parseconfig.inc
index 02bc4bf8..8447446e 100644
--- a/core/parseconfig.inc
+++ b/core/parseconfig.inc
@@ -104,7 +104,7 @@ pc_kernel: cmp byte [VKernel],0
mov [VKernelBuf+vk_type],al
call pc_getline
mov di,VKernelBuf+vk_rname
- call mangle_name
+ pm_call mangle_name
.err: ret
;
@@ -147,7 +147,7 @@ pc_setint16:
pc_filecmd: push ax ; Function to tailcall
call pc_getline
mov di,MNameBuf
- call mangle_name
+ pm_call mangle_name
call searchdir
jnz .ok
pop ax ; Drop the successor function
@@ -160,7 +160,7 @@ pc_filecmd: push ax ; Function to tailcall
pc_opencmd: push ax ; Function to tailcall
call pc_getline
mov di,MNameBuf
- call mangle_name
+ pm_call mangle_name
call open
jnz .ok
pop ax ; Drop the successor function
@@ -289,7 +289,7 @@ pc_serial: call getint
pc_filename: push ax
call pc_getline
pop di
- call mangle_name ; Mangle file name
+ pm_call mangle_name ; Mangle file name
ret
;
@@ -314,7 +314,7 @@ pc_label: call commit_vk ; Commit any current vkernel
mov byte [VKernel],1 ; We've seen a "label" statement
mov si,VKernelBuf+vk_vname ; By default, rname == mangled vname
mov di,VKernelBuf+vk_rname
- call mangle_name
+ pm_call mangle_name
mov si,AppendBuf ; Default append==global append
mov di,VKernelBuf+vk_append
mov cx,[AppendLen]
diff --git a/core/pxe.c b/core/pxe.c
index 206105f6..f4b894e8 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -30,38 +30,31 @@ struct open_file_t {
};
extern char Files[];
+extern uint32_t ServerIP;
+
uint16_t NextSocket = 49152;
-/*********************************************************************
-;
-; parse_dotquad:
-; Read a dot-quad pathname in DS:SI and output an IP
-; address in EAX, with SI pointing to the first
-; nonmatching character.
-;
-; Return CF=1 on error.
-;
-; No segment assumptions permitted.
-;
-*********************************************************************/
-void parse_dotquad(com32sys_t *regs)
+
+/*
+ * parse the ip_str and return the ip address with *res.
+ * return the the string address after the ip string
+ *
+ */
+char *parse_dotquad(char *ip_str, uint32_t *res)
{
- char *pathname = (char *)MK_PTR(regs->ds, regs->esi.w[0]);
- char *p = pathname;
+ char *p = ip_str;
int i = 0;
uint8_t part = 0;
uint32_t ip = 0;
-
+
for (; i < 4; i++) {
while (is_digit(*p)) {
part = part * 10 + *p - '0';
p++;
}
- if (i != 3 && *p != '.') {
- regs->eflags.l |= EFLAGS_CF;
- return;
- }
+ if (i != 3 && *p != '.')
+ return NULL;
ip = (ip << 8) | part;
part = 0;
@@ -69,8 +62,8 @@ void parse_dotquad(com32sys_t *regs)
}
p --;
- regs->eax.l = ip;
- regs->esi.w[0] = OFFS_WRT(p, 0);
+ *res = ip;
+ return p;
}
@@ -96,6 +89,99 @@ void is_url(com32sys_t *regs)
}
#endif /* GPXE */
+/*
+ ; mangle a filename pointed to by DS:SI into a buffer pointed
+ ; to by ES:DI; ends on encountering any whitespace.
+ ; DI is preserved.
+ ;
+ ; This verifies that a filename is < FILENAME_MAX characters
+ ; and doesn't contain whitespace, and zero-pads the output buffer,
+ ; so "repe cmpsb" can do a compare.
+ ;
+ ; The first four bytes of the manged name is the IP address of
+ ; the download host, 0 for no host, or -1 for a gPXE URL.
+ ;
+ ; No segment assumptions permitted.
+ ;
+*********************************************************************/
+void mangle_name(com32sys_t *regs)
+{
+ char *dst = (char *)MK_PTR(regs->es, regs->edi.w[0]);
+ char *src = (char *)MK_PTR(regs->ds, regs->esi.w[0]);
+
+ char *p = src;
+ uint32_t ip;
+ int i = 0;
+ char *d = dst;
+
+#if GPXE
+ is_url(regs);
+ if ((regs->eflags.l & EFLAGS_CF) == 0) {
+ ip |= -1;
+ goto prefix_done;
+ }
+#endif
+
+ ip = ServerIP;
+ if (*p == 0)
+ goto noip;
+ if (! strncmp(p, "::", 2))
+ goto gotprefix;
+ else {
+ while (*p && strncmp(p, "::", 2))
+ p ++;
+ if (! *p)
+ goto noip;
+ /*
+ * we have a :: prefix of ip sort, it could be either a DNS
+ * name or dot-quad IP address. Try the dot-quad first.
+ */
+ p = src;
+ if ((p = parse_dotquad(p, &ip)) && !strncmp(p, "::", 2))
+ goto gotprefix;
+ else {
+ dns_resolv(regs);
+ p = (char *)MK_PTR(regs->ds, regs->esi.w[0]);
+ ip = regs->eax.l;
+ if (! strncmp(p, "::", 2))
+ if (ip)
+ goto gotprefix;
+ }
+ }
+ noip:
+ p = src;
+ ip = 0;
+ goto prefix_done;
+
+ gotprefix:
+ p += 2; /* skip double colon */
+
+ prefix_done:
+ *(uint32_t *)dst = ip;
+ dst += 4;
+ i = FILENAME_MAX - 5;
+
+ do {
+ if (*p <= ' ')
+ break;
+ *dst++ = *p++;
+ }while (i--);
+
+ i ++;
+ while (i) {
+ *dst++ = 0;
+ i --;
+ }
+
+#if 0
+ printf("the name before mangling: ");
+ dump16(src);
+ printf("the name after mangling: ");
+ dump16(d);
+#endif
+}
+
+
/**
* Take a nubmer of bytes in memory and convert to lower-case hxeadecimal
@@ -337,18 +423,17 @@ void genipopt(com32sys_t *regs)
*/
int try_load(com32sys_t *regs)
{
- extern void mangle_name();
extern void open();
- extern void try();
extern char KernelName[];
- char *config_name = (char *)(regs->edi.w[0]);
+ char *config_name = (char *)MK_PTR(regs->ds, regs->edi.w[0]);
char *trying_msg = "Trying to load: ";
printf("%s%s ", trying_msg, config_name);
+ regs->edi.w[0] = OFFS_WRT(KernelName, 0);
regs->esi.w[0] = OFFS_WRT(config_name, 0);
+ mangle_name(regs);
regs->edi.w[0] = OFFS_WRT(KernelName, 0);
- call16(mangle_name, regs, regs);
call16(open, regs, regs);
if (regs->eflags.l & EFLAGS_ZF) {
printf(" [FAILED]\n");
@@ -404,7 +489,7 @@ void pxe_load_config(com32sys_t *regs)
regs->esi.w[0] = OFFS_WRT(UUID, 0);
lchexbytes(regs);
uuid_ptr++;
- *(char *)(regs->edi.w[0]) = '-';
+ *(char *)MK_PTR(regs->ds, regs->edi.w[0]) = '-';
regs->edi.w[0] ++;
}
/* Remove last dash and zero-terminate */
@@ -430,7 +515,7 @@ void pxe_load_config(com32sys_t *regs)
regs->esi.w[0] = OFFS_WRT(MyIP, 0);
uchexbytes(regs); /* Convet to hex string */
- last = (uint8_t *)(regs->edi.w[0]);
+ last = (uint8_t *)MK_PTR(regs->ds, regs->edi.w[0]);
while (tries) {
*last = '\0'; /* Zero-terminate string */
regs->edi.w[0] = OFFS_WRT(ConfigName, 0);
@@ -505,7 +590,7 @@ void allocate_socket(com32sys_t *regs)
void free_socket(com32sys_t *regs)
{
/* tftp_pktbuf is not cleared */
- memset(regs->esi.w[0], 0, sizeof(struct open_file_t) - 2);
+ memset((void *)(int)(regs->esi.w[0]), 0, sizeof(struct open_file_t) - 2);
regs->esi.w[0] = 0;
regs->eflags.l |= EFLAGS_ZF;
}
@@ -536,4 +621,3 @@ void ip_ok(com32sys_t *regs)
bad:
regs->eflags.l |= EFLAGS_ZF;
}
-
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 9b18702e..6e4e648d 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -1196,89 +1196,6 @@ HasGPXE db -1 ; Unknown
%endif
-;
-; mangle_name: Mangle a filename pointed to by DS:SI into a buffer pointed
-; to by ES:DI; ends on encountering any whitespace.
-; DI is preserved.
-;
-; This verifies that a filename is < FILENAME_MAX characters
-; and doesn't contain whitespace, and zero-pads the output buffer,
-; so "repe cmpsb" can do a compare.
-;
-; The first four bytes of the manged name is the IP address of
-; the download host, 0 for no host, or -1 for a gPXE URL.
-;
-; No segment assumptions permitted.
-;
- global mangle_name
-mangle_name:
- push di
-%if GPXE
- pm_call is_url
- jc .not_url
- or eax,-1 ; It's a URL
- jmp .prefix_done
-.not_url:
-%endif ; GPXE
- push si
- mov eax,[cs:ServerIP]
- cmp byte [si],0
- je .noip ; Null filename?!?!
- cmp word [si],'::' ; Leading ::?
- je .gotprefix
-
-.more:
- inc si
- cmp byte [si],0
- je .noip
- cmp word [si],'::'
- jne .more
-
- ; We have a :: prefix of some sort, it could be either
- ; a DNS name or a dot-quad IP address. Try the dot-quad
- ; first...
-.here:
- pop si
- push si
- pm_call parse_dotquad
- jc .notdq
- cmp word [si],'::'
- je .gotprefix
-.notdq:
- pop si
- push si
- call dns_resolv
- cmp word [si],'::'
- jne .noip
- and eax,eax
- jnz .gotprefix
-
-.noip:
- pop si
- xor eax,eax
- jmp .prefix_done
-
-.gotprefix:
- pop cx ; Adjust stack
- inc si ; Skip double colon
- inc si
-
-.prefix_done:
- stosd ; Save IP address prefix
- mov cx,FILENAME_MAX-5
-
-.mn_loop:
- lodsb
- cmp al,' ' ; If control or space, end
- jna .mn_end
- stosb
- loop .mn_loop
-.mn_end:
- inc cx ; At least one null byte
- xor ax,ax ; Zero-fill name
- rep stosb ; Doesn't do anything if CX=0
- pop di
- ret ; Done
;
; unmangle_name: Does the opposite of mangle_name; converts a DOS-mangled
@@ -2349,7 +2266,7 @@ ack_packet_buf: dw TFTP_ACK, 0 ; TFTP ACK packet
;
; IP information (initialized to "unknown" values)
- global MyIP
+ global MyIP, ServerIP
MyIP dd 0 ; My IP address
ServerIP dd 0 ; IP address of boot server
Netmask dd 0 ; Netmask of this subnet
diff --git a/core/runkernel.inc b/core/runkernel.inc
index 8d0f2968..ecaaceb0 100644
--- a/core/runkernel.inc
+++ b/core/runkernel.inc
@@ -538,7 +538,7 @@ parse_load_initrd:
push di
mov di,InitRD ; Target buffer for mangled name
- call mangle_name
+ pm_call mangle_name
pop di
call loadinitrd
diff --git a/core/ui.inc b/core/ui.inc
index 3e42a97d..249074ef 100644
--- a/core/ui.inc
+++ b/core/ui.inc
@@ -318,7 +318,7 @@ load_kernel: ; Load the kernel now
mov si,command_line
mov di,KernelName
push si
- call mangle_name
+ pm_call mangle_name
pop si
;
; Fast-forward to first option (we start over from the beginning, since