summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-08-30 07:05:58 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-08-30 07:05:58 +0800
commite2d252347b046b157a65cbcb82d5909a494b6682 (patch)
tree75706c5ea28cabe0d238966cca0a4fd283a60466
parentb17a78c59d28b06b77b3a9af636664a7299adbc9 (diff)
downloadsyslinux-e2d252347b046b157a65cbcb82d5909a494b6682.tar.gz
Core:pxelinux: code clean
Two main things: 1. Redeclare the varibales that are't needed by any asm files in C file. 2. Move the extern statements of PXELINUX into pxe.h, instead of in core.h Signed-off-by: Liu Aleaxander <Aleaxander@gmail.com>
-rw-r--r--core/fs/pxe/dhcp_option.c57
-rw-r--r--core/fs/pxe/dnsresolv.c2
-rw-r--r--core/fs/pxe/pxe.c98
-rw-r--r--core/fs/pxe/pxe.h47
-rw-r--r--core/include/core.h46
-rw-r--r--core/pxelinux.asm36
6 files changed, 135 insertions, 151 deletions
diff --git a/core/fs/pxe/dhcp_option.c b/core/fs/pxe/dhcp_option.c
index 9bd20b07..ebe8eb49 100644
--- a/core/fs/pxe/dhcp_option.c
+++ b/core/fs/pxe/dhcp_option.c
@@ -4,20 +4,23 @@
#include <sys/cpu.h>
#include "pxe.h"
+int over_load;
+uint8_t uuid_type;
+char uuid[17];
void parse_dhcp_options(void *, int, int);
static void subnet_mask(void *data, int opt_len)
{
if (opt_len != 4)
return;
- Netmask = *(uint32_t *)data;
+ net_mask = *(uint32_t *)data;
}
static void router(void *data, int opt_len)
{
if (opt_len != 4)
return;
- Gateway = *(uint32_t *)data;
+ gate_way = *(uint32_t *)data;
}
static void dns_servers(void *data, int opt_len)
@@ -66,7 +69,7 @@ static void option_overload(void *data, int opt_len)
{
if (opt_len != 1)
return;
- OverLoad = *(uint8_t *)data;
+ over_load = *(uint8_t *)data;
}
@@ -77,44 +80,44 @@ static void server(void *data, int opt_len)
if (opt_len != 4)
return;
- if (ServerIP)
+ if (server_ip)
return;
ip = *(uint32_t *)data;
if (ip_ok(ip))
- ServerIP = ip;
+ server_ip = ip;
}
static void client_identifier(void *data, int opt_len)
{
if (opt_len > MAC_MAX || opt_len < 2 ||
- MACLen != (opt_len >> 8) ||
- *(uint8_t *)data != MACType)
+ MAC_len != (opt_len >> 8) ||
+ *(uint8_t *)data != MAC_type)
return;
opt_len --;
- MACLen = opt_len & 0xff;
+ MAC_len = opt_len & 0xff;
memcpy(MAC, data+1, opt_len);
MAC[opt_len] = 0;
}
static void bootfile_name(void *data, int opt_len)
{
- strncpy(BootFile, data, opt_len);
- BootFile[opt_len] = 0;
+ strncpy(boot_file, data, opt_len);
+ boot_file[opt_len] = 0;
}
static void uuid_client_identifier(void *data, int opt_len)
{
int type = *(uint8_t *)data;
if (opt_len != 17 ||
- (type | HaveUUID))
+ (type | have_uuid))
return;
- HaveUUID = 1;
- UUIDType = type;
- memcpy(UUID, data+1, 16);
- UUID[16] = 0;
+ have_uuid = 1;
+ uuid_type = type;
+ memcpy(uuid, data+1, 16);
+ uuid[16] = 0;
}
static void pxelinux_configfile(void *data, int opt_len)
@@ -127,8 +130,8 @@ static void pxelinux_configfile(void *data, int opt_len)
static void pxelinux_pathprefix(void *data,int opt_len)
{
DHCPMagic |= 4;
- strncpy(PathPrefix, data, opt_len);
- PathPrefix[opt_len] = 0;
+ strncpy(path_prefix, data, opt_len);
+ path_prefix[opt_len] = 0;
}
static void pxelinux_reboottime(void *data, int opt_len)
@@ -229,13 +232,13 @@ void parse_dhcp_options(void *option, int size, int filter)
; information is present:
;
; MyIP - client IP address
- ; ServerIP - boot server IP address
- ; Netmask - network mask
- ; Gateway - default gateway router IP
- ; BootFile - boot file name
+ ; server_ip - boot server IP address
+ ; net_mask - network mask
+ ; gate_way - default gateway router IP
+ ; boot_file - boot file name
; DNSServers - DNS server IPs
; LocalDomain - Local domain name
- ; MACLen, MAC - Client identifier, if MACLen == 0
+ ; MAC_len, MAC - Client identifier, if MAC_len == 0
;
; This assumes the DHCP packet is in "trackbuf".
;
@@ -245,22 +248,22 @@ void parse_dhcp(int pkt_len)
struct bootp_t *dhcp = (struct bootp_t *)trackbuf;
int opt_len;
- OverLoad = 0;
+ over_load = 0;
if (ip_ok(dhcp->yip))
MyIP = dhcp->yip;
if (ip_ok(dhcp->sip))
- ServerIP = dhcp->sip;
+ server_ip = dhcp->sip;
opt_len = (char *)dhcp + pkt_len - (char *)&dhcp->options;
if (opt_len && (dhcp->option_magic == BOOTP_OPTION_MAGIC))
parse_dhcp_options(&dhcp->options, opt_len, 0);
- if (OverLoad & 1)
+ if (over_load & 1)
parse_dhcp_options(&dhcp->bootfile, 128, 0);
else if (dhcp->bootfile[0])
- strcpy(BootFile, dhcp->bootfile);
+ strcpy(boot_file, dhcp->bootfile);
- if (OverLoad & 2)
+ if (over_load & 2)
parse_dhcp_options(dhcp->sname, 64, 0);
}
diff --git a/core/fs/pxe/dnsresolv.c b/core/fs/pxe/dnsresolv.c
index 8fccd372..dbabbb62 100644
--- a/core/fs/pxe/dnsresolv.c
+++ b/core/fs/pxe/dnsresolv.c
@@ -221,7 +221,7 @@ uint32_t dns_resolv(const char *name)
continue; /* just move on before runing the time out */
udp_write.status = 0;
udp_write.ip = srv;
- udp_write.gw = ((srv ^ MyIP) & Netmask) ? Gateway : 0;
+ udp_write.gw = ((srv ^ MyIP) & net_mask) ? gate_way : 0;
udp_write.src_port = DNS_LOCAL_PORT;
udp_write.dst_port = DNS_PORT;
udp_write.buffer_size = p - DNSSendBuf;
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index a4537855..e73211c5 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -8,15 +8,25 @@
#define GPXE 1
-uint32_t ServerIP = 0; /* IP address of boot server */
-uint32_t Netmask = 0; /* Netmask of this subnet */
-uint32_t Gateway = 0; /* Default router */
-uint16_t ServerPort = TFTP_PORT; /* TFTP server port */
+uint32_t server_ip = 0; /* IP address of boot server */
+uint32_t net_mask = 0; /* net_mask of this subnet */
+uint32_t gate_way = 0; /* Default router */
+uint16_t server_port = TFTP_PORT; /* TFTP server port */
+uint16_t real_base_mem; /* Amount of DOS memory after freeing */
+
+char MAC_str[3 * (MAC_MAX + 1)]; /* MAC address as a string */
+char MAC[MAC_MAX + 1]; /* Actual MAC address */
+uint8_t MAC_len; /* MAC address len */
+uint8_t MAC_type; /* MAC address type */
+
+char boot_file[256];
+char path_prefix[256];
+char dot_quad_buf[16];
static struct open_file_t Files[MAX_OPEN];
static int has_gpxe;
static uint8_t uuid_dashes[] = {4, 2, 2, 2, 6, 0};
-int HaveUUID = 0;
+int have_uuid = 0;
const uint8_t TimeoutTable[] = {
2, 2, 3, 3, 4, 5, 6, 7, 9, 10, 12, 15, 18, 21, 26, 31, 37, 44, 53, 64, 77,
@@ -279,7 +289,7 @@ static void ack_packet(struct open_file_t *file, uint16_t ack_num)
udp_write.src_port = file->tftp_localport;
udp_write.dst_port = file->tftp_remoteport;
udp_write.ip = file->tftp_remoteip;
- udp_write.gw = ((udp_write.ip ^ MyIP) & Netmask) ? Gateway : 0;
+ udp_write.gw = ((udp_write.ip ^ MyIP) & net_mask) ? gate_way : 0;
udp_write.buffer.offs = OFFS(ack_packet_buf);
udp_write.buffer.seg = SEG(ack_packet_buf);
udp_write.buffer_size = 4;
@@ -422,7 +432,7 @@ static void get_packet_gpxe(struct open_file_t *file)
static void pxe_mangle_name(char *dst, const char *src)
{
const char *p = src;
- uint32_t ip = ServerIP;
+ uint32_t ip = server_ip;
int i = 0;
#if GPXE
@@ -723,9 +733,9 @@ static void pxe_searchdir(char *filename, struct file *file)
p += 4;
if (ip == 0) {
/* Have prefix */
- strcpy(buf, PathPrefix);
- buf += strlen(PathPrefix);
- ip = ServerIP; /* Get the default server */
+ strcpy(buf, path_prefix);
+ buf += strlen(path_prefix);
+ ip = server_ip; /* Get the default server */
}
strcpy(buf, p); /* Copy the filename */
@@ -758,9 +768,9 @@ static void pxe_searchdir(char *filename, struct file *file)
open_file->tftp_remoteip = ip;
tid = open_file->tftp_localport; /* TID(local port No) */
udp_write.ip = ip;
- udp_write.gw = ((udp_write.ip ^ MyIP) & Netmask) ? Gateway : 0;
+ udp_write.gw = ((udp_write.ip ^ MyIP) & net_mask) ? gate_way : 0;
udp_write.src_port = tid;
- udp_write.dst_port = ServerPort;
+ udp_write.dst_port = server_port;
buf += fill_tail(buf);
udp_write.buffer_size = buf - packet_buf;
err = pxe_call(PXENV_UDP_WRITE, &udp_write);
@@ -983,9 +993,9 @@ static void get_prefix(void)
if (DHCPMagic & 0x04) /* Did we get a path prefix option */
goto got_prefix;
- strcpy(PathPrefix, BootFile);
- len = strlen(PathPrefix);
- p = &PathPrefix[len - 1];
+ strcpy(path_prefix, boot_file);
+ len = strlen(path_prefix);
+ p = &path_prefix[len - 1];
while (len--) {
c = *p--;
@@ -1004,8 +1014,8 @@ static void get_prefix(void)
*(p + 2) = 0; /* Zero-terminate after delimiter */
got_prefix:
- printf("TFTP prefix: %s\n", PathPrefix);
- strcpy(CurrentDirName, PathPrefix);
+ printf("TFTP prefix: %s\n", path_prefix);
+ strcpy(CurrentDirName, path_prefix);
}
/*
@@ -1062,12 +1072,12 @@ static void pxe_load_config(com32sys_t *regs)
*/
/* Try loading by UUID */
- if (HaveUUID) {
+ if (have_uuid) {
uuid_ptr = uuid_dashes;
p = config_file;
while (*uuid_ptr) {
int len = *uuid_ptr;
- char *src = UUID;
+ char *src = uuid;
lchexbytes(p, src, len);
p += len * 2;
@@ -1083,7 +1093,7 @@ static void pxe_load_config(com32sys_t *regs)
}
/* Try loading by MAC address */
- strcpy(config_file, MACStr);
+ strcpy(config_file, MAC_str);
regs->edi.w[0] = OFFS_WRT(ConfigName, 0);
if (try_load(regs))
return;
@@ -1121,13 +1131,14 @@ static void pxe_load_config(com32sys_t *regs)
*/
static void make_bootif_string(void)
{
- char *bootif_str = "BOOTIF=";
- uint8_t *src = &MACType; /* MACType just followed by MAC */
- char *dst;
- int i = MACLen + 1; /* MACType included */
-
- strcpy(BOOTIFStr, bootif_str);
- dst = strchr(BOOTIFStr, '\0');
+ char mac[18];
+ char *src = mac;
+ char *dst = MAC_str;
+ int i = MAC_len + 1;
+
+ *(uint8_t *)src++ = MAC_type;
+ memcpy(src, MAC, MAC_len);
+ src = mac;
for (; i > 0; i--) {
lchexbytes(dst, src, 1);
dst += 2;
@@ -1135,6 +1146,8 @@ static void make_bootif_string(void)
*dst++ = '-';
}
*(dst - 1) = 0; /* Drop the last '-' and null-terminate string */
+ strcat(BOOTIFStr, "BOOTIF=");
+ strcat(BOOTIFStr, MAC_str);
#if 0
printf("%s\n", BOOTIFStr);
@@ -1157,31 +1170,28 @@ static void genipopt(void)
p += ip_len;
*p++ = ':';
- ip_len = gendotquad(p, ServerIP);
+ ip_len = gendotquad(p, server_ip);
p += ip_len;
*p++ = ':';
- ip_len = gendotquad(p, Gateway);
+ ip_len = gendotquad(p, gate_way);
p += ip_len;
*p++ = ':';
- ip_len = gendotquad(p, Netmask);
+ ip_len = gendotquad(p, net_mask);
}
/* Generate ip= option and print the ip adress */
static void ip_init(void)
{
- int ip = MyIP;
- char *myipaddr_msg = "My IP address seems to be ";
-
+ uint32_t ip = MyIP;
+
genipopt();
-
- gendotquad(DotQuadBuf, ip);
+ gendotquad(dot_quad_buf, ip);
ip = ntohl(ip);
- printf("%s %08X %s\n", myipaddr_msg, ip, DotQuadBuf);
-
+ printf("My IP address seems to be %08X %s\n", ip, dot_quad_buf);
printf("%s\n", IPOption);
}
@@ -1381,7 +1391,7 @@ static void pxe_init(void)
code_seg = code_seg + ((code_len + 15) >> 4);
data_seg = data_seg + ((data_len + 15) >> 4);
- RealBaseMem = max(code_seg,data_seg) >> 6; /* Convert to kilobytes */
+ real_base_mem = max(code_seg,data_seg) >> 6; /* Convert to kilobytes */
}
/*
@@ -1440,9 +1450,9 @@ static void network_init(void)
* turns out to be problematic it might be better getting it from
* the query info 1 packet
*/
- MACLen = bp->hardlen > 16 ? 0 : bp->hardlen;
- MACType = bp->hardware;
- memcpy(MAC, bp->macaddr, MACLen);
+ MAC_len = bp->hardlen > 16 ? 0 : bp->hardlen;
+ MAC_type = bp->hardware;
+ memcpy(MAC, bp->macaddr, MAC_len);
/*
* Get the boot file and other info. This lives in the CACHED_REPLY
@@ -1522,15 +1532,15 @@ void unload_pxe(void)
}
flag = 0xff00;
- if (RealBaseMem <= BIOS_fbm) /* Santiy check */
+ if (real_base_mem <= BIOS_fbm) /* Santiy check */
goto cant_free;
flag ++;
/* Check that PXE actually unhooked the INT 0x1A chain */
int_addr = (int)MK_PTR(*(uint16_t *)(4*0x1a+2), *(uint16_t *)(4*0x1a));
int_addr >>= 10;
- if (int_addr >= RealBaseMem || int_addr < BIOS_fbm) {
- BIOS_fbm = RealBaseMem;
+ if (int_addr >= real_base_mem || int_addr < BIOS_fbm) {
+ BIOS_fbm = real_base_mem;
return;
}
diff --git a/core/fs/pxe/pxe.h b/core/fs/pxe/pxe.h
index 7c30d66e..224b8a26 100644
--- a/core/fs/pxe/pxe.h
+++ b/core/fs/pxe/pxe.h
@@ -157,6 +157,53 @@ struct open_file_t {
} __attribute__ ((packed));
/*
+ * Variable externs
+ */
+extern uint32_t server_ip;
+extern uint32_t MyIP;
+extern uint32_t net_mask;
+extern uint32_t gate_way;
+extern uint16_t server_port;
+
+extern char MAC_str[];
+extern char MAC[];
+extern char BOOTIFStr[];
+extern uint8_t MAC_len;
+extern uint8_t MAC_type;
+
+extern uint8_t DHCPMagic;
+extern uint32_t RebootTime;
+
+extern char boot_file[];
+extern char path_prefix[];
+extern char LocalDomain[];
+
+extern char packet_buf[];
+
+extern char IPOption[];
+extern char dot_quad_buf[];
+
+extern uint32_t dns_server[];
+extern char DNSSendBuf[];
+extern char DNSRecvBuf[];
+
+extern uint16_t real_base_mem;
+extern uint16_t APIVer;
+extern far_ptr_t PXEEntry;
+extern uint8_t KeepPXE;
+
+extern far_ptr_t InitStack;
+
+extern int have_uuid;
+extern uint8_t uuid_type;
+extern char uuid[];
+
+extern volatile uint16_t BIOS_timer;
+extern uint16_t BIOS_fbm;
+extern const uint8_t TimeoutTable[];
+
+
+/*
* functions
*/
diff --git a/core/include/core.h b/core/include/core.h
index 61097a63..9ab03517 100644
--- a/core/include/core.h
+++ b/core/include/core.h
@@ -41,51 +41,5 @@ void call16(void (*)(void), const com32sys_t *, com32sys_t *);
__noreturn _kaboom(void);
#define kaboom() _kaboom()
-/*
- * externs for pxelinux
- */
-extern uint32_t ServerIP;
-extern uint32_t MyIP;
-extern uint32_t Netmask;
-extern uint32_t Gateway;
-extern uint16_t ServerPort;
-
-extern char MACStr[]; /* MAC address as a string */
-extern char MAC[]; /* Actual MAC address */
-extern char BOOTIFStr[]; /* Space for "BOOTIF=" */
-extern uint8_t MACLen; /* MAC address len */
-extern uint8_t MACType; /* MAC address type */
-
-extern uint8_t DHCPMagic;
-extern uint8_t OverLoad;
-extern uint32_t RebootTime;
-
-extern char BootFile[];
-extern char PathPrefix[];
-extern char LocalDomain[];
-
-extern char packet_buf[];
-
-extern char IPOption[];
-extern char DotQuadBuf[];
-
-extern uint32_t dns_server[];
-extern char DNSSendBuf[];
-extern char DNSRecvBuf[];
-
-extern uint16_t RealBaseMem;
-extern uint16_t APIVer;
-extern far_ptr_t PXEEntry;
-extern uint8_t KeepPXE;
-
-extern far_ptr_t InitStack;
-
-extern int HaveUUID;
-extern uint8_t UUIDType;
-extern char UUID[];
-
-extern volatile uint16_t BIOS_timer;
-extern uint16_t BIOS_fbm;
-extern const uint8_t TimeoutTable[];
#endif /* CORE_H */
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 7643d009..e8c81301 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -45,17 +45,6 @@ SECTOR_SHIFT equ TFTP_BLOCKSIZE_LG2
SECTOR_SIZE equ TFTP_BLOCKSIZE
;
-; TFTP operation codes
-;
-TFTP_ACK equ htons(4) ; ACK packet
-TFTP_ERROR equ htons(5) ; ERROR packet
-
-;
-; TFTP error codes
-;
-TFTP_EOPTNEG equ htons(8) ; Option negotiation failure
-
-;
; The following structure is used for "virtual kernels"; i.e. LILO-style
; option labels. The options we permit here are `kernel' and `append
; Since there is no room in the bottom 64K for all of these, we
@@ -94,39 +83,21 @@ InitStack resd 1
section .bss16
alignb FILENAME_MAX
- global BootFile, PathPrefix, DotQuadBuf, IPOption
-BootFile resb 256 ; Boot file from DHCP packet
-PathPrefix resb 256 ; Path prefix derived from boot file
-DotQuadBuf resb 16 ; Buffer for dotted-quad IP address
+ global IPOption
IPOption resb 80 ; ip= option buffer
PXEStack resd 1 ; Saved stack during PXE call
alignb 4
- global DHCPMagic, OverLoad, RebootTime, APIVer, RealBaseMem
- global StructPtr
+ global DHCPMagic, RebootTime, APIVer
RebootTime resd 1 ; Reboot timeout, if set by option
StrucPtr resw 2 ; Pointer to PXENV+ or !PXE structure
APIVer resw 1 ; PXE API version found
LocalBootType resw 1 ; Local boot return code
-RealBaseMem resw 1 ; Amount of DOS memory after freeing
-OverLoad resb 1 ; Set if DHCP packet uses "overloading"
DHCPMagic resb 1 ; PXELINUX magic flags
; The relative position of these fields matter!
- global MACStr, MACLen, MACType, MAC, BOOTIFStr
-MAC_MAX equ 32 ; Handle hardware addresses this long
-MACLen resb 1 ; MAC address len
-MACType resb 1 ; MAC address type
-MAC resb MAC_MAX+1 ; Actual MAC address
+ global BOOTIFStr
BOOTIFStr resb 7 ; Space for "BOOTIF="
-MACStr resb 3*(MAC_MAX+1) ; MAC address as a string
-
-; The relative position of these fields matter!
- global UUID, UUIDType
-UUIDType resb 1 ; Type byte from DHCP option
-UUID resb 16 ; UUID, from the PXE stack
-UUIDNull resb 1 ; dhcp_copyoption zero-terminates
-
section .bss16
global packet_buf
@@ -410,7 +381,6 @@ copyright_str db ' Copyright (C) 1994-'
db ' H. Peter Anvin et al', CR, LF, 0
err_bootfailed db CR, LF, 'Boot failed: press a key to retry, or wait for reset...', CR, LF, 0
bailmsg equ err_bootfailed
-cant_free_msg db 'Failed to free base memory, error ', 0
localboot_msg db 'Booting from local disk...', CR, LF, 0
syslinux_banner db CR, LF, 'PXELINUX ', VERSION_STR, ' ', DATE_STR, ' ', 0