aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 18:28:12 +0800
committerLiu Aleaxander <Aleaxander@gmail.com>2009-08-05 18:28:12 +0800
commitac317a87826518afad5e2492c4cd81db5cb72650 (patch)
treeee84caf9ea239572322427470c39d54eb3fadeb5
parent8c937d26bdc76959f8490718aa4ab3a26263b727 (diff)
downloadpxelinux-ac317a87826518afad5e2492c4cd81db5cb72650.tar.gz
pxelinux-ac317a87826518afad5e2492c4cd81db5cb72650.tar.xz
pxelinux-ac317a87826518afad5e2492c4cd81db5cb72650.zip
Core:PXELINUX: code clean -- 6
drop the pxe packet struct defined in asm file, define them in C in a __lowmem style
-rw-r--r--core/pxe.c170
1 files changed, 86 insertions, 84 deletions
diff --git a/core/pxe.c b/core/pxe.c
index 9f32ae36..67079aec 100644
--- a/core/pxe.c
+++ b/core/pxe.c
@@ -815,19 +815,19 @@ int pxe_call(int opcode, void *data)
void ack_packet(struct open_file_t *file, uint16_t ack_num)
{
int err;
- struct pxe_udp_write_pkt *uw_pkt = (struct pxe_udp_write_pkt *)pxe_udp_write_pkt;;
+ static __lowmem struct pxe_udp_write_pkt uw_pkt;
/* Packet number to ack */
ack_packet_buf[1] = ack_num;
- 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_WRT(ack_packet_buf, 0);
- uw_pkt->buffer[1] = 0; /* seems SEG and OFFS stuff doesn't work here */
- uw_pkt->buffersize = 4;
-
- err = pxe_call(PXENV_UDP_WRITE, uw_pkt);
+ 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_WRT(ack_packet_buf, 0);
+ uw_pkt.buffer[1] = 0; /* seems SEG and OFFS stuff doesn't work here */
+ uw_pkt.buffersize = 4;
+
+ err = pxe_call(PXENV_UDP_WRITE, &uw_pkt);
#if 0
printf("sent %s\n", err ? "FAILED" : "OK");
#endif
@@ -844,22 +844,22 @@ void ack_packet(struct open_file_t *file, uint16_t ack_num)
int pxe_get_cached_info(int type)
{
int err;
- struct pxe_bootp_query_pkt *bq_pkt = (struct pxe_bootp_query_pkt *)pxe_bootp_query_pkt;
+ static __lowmem struct pxe_bootp_query_pkt bq_pkt;
printf(" %02x", type);
- bq_pkt->status = 0;
- bq_pkt->packettype = type;
- bq_pkt->buffersize = 8192;
- bq_pkt->buffer[0] = OFFS_WRT(trackbuf, 0);
- bq_pkt->buffer[1] = 0;
+ bq_pkt.status = 0;
+ bq_pkt.packettype = type;
+ bq_pkt.buffersize = 8192;
+ bq_pkt.buffer[0] = OFFS_WRT(trackbuf, 0);
+ bq_pkt.buffer[1] = 0;
- err = pxe_call(PXENV_GET_CACHED_INFO, bq_pkt);
+ err = pxe_call(PXENV_GET_CACHED_INFO, &bq_pkt);
if (err) {
printf("%s %04x\n", err_pxefailed, err);
call16(kaboom, NULL, NULL);
}
- return bq_pkt->buffersize;
+ return bq_pkt.buffersize;
}
/*
@@ -869,12 +869,12 @@ int pxe_get_cached_info(int type)
void udp_init(void)
{
int err;
- struct pxe_udp_open_pkt *uo_pkt = (struct pxe_udp_open_pkt *)pxe_udp_open_pkt;
- uo_pkt->sip = MyIP;
- err = pxe_call(PXENV_UDP_OPEN, uo_pkt);
- if (err || uo_pkt->status) {
+ static __lowmem struct pxe_udp_open_pkt uo_pkt;
+ uo_pkt.sip = MyIP;
+ err = pxe_call(PXENV_UDP_OPEN, &uo_pkt);
+ if (err || uo_pkt.status) {
printf("%s", err_udpinit);
- printf("%d\n", uo_pkt->status);
+ printf("%d\n", uo_pkt.status);
call16(kaboom, NULL, NULL);
}
}
@@ -1186,19 +1186,21 @@ void parse_dhcp(int pkt_len)
int is_gpxe(char *url)
{
int err;
- struct gpxe_file_api_check *ac = (struct gpxe_file_api_check *)gpxe_file_api_check;
+ static __lowmem struct gpxe_file_api_check ac;
char *gpxe_warning_msg = "URL syntax, but gPXE extensions not detected, tring plain TFTP...\n";
-
+
if (! is_url(url))
return 0;
+ ac.size = 20;
+ ac.magic = 0x91d447b2;
/* If has_gpxe is greater than one, means the gpxe status is unknow */
while (has_gpxe > 1) {
- err = pxe_call(PXENV_FILE_API_CHECK, gpxe_file_api_check);
- if (err || ac->magic != 0xe9c17b20)
+ err = pxe_call(PXENV_FILE_API_CHECK, &ac);
+ if (err || ac.magic != 0xe9c17b20)
printf("%s\n", gpxe_warning_msg);
else
- has_gpxe = (~ac->provider & 0xffff) & 0x4b ? 0 : 1;
+ has_gpxe = (~ac.provider & 0xffff) & 0x4b ? 0 : 1;
if (!has_gpxe)
printf("%s\n", gpxe_warning_msg);
@@ -1217,25 +1219,25 @@ int is_gpxe(char *url)
*/
void get_packet_gpxe(struct open_file_t *file)
{
- struct gpxe_file_read *fr = (struct gpxe_file_read *)gpxe_file_read;
+ static __lowmem struct gpxe_file_read fr;
int err;
while (1) {
- fr->filehandle = file->tftp_remoteport;
- fr->buffer[0] = file->tftp_pktbuf;
- fr->buffer[1] = PKTBUF_SEG;
- fr->buffersize = PKTBUF_SIZE;
- err = pxe_call(PXENV_FILE_READ, fr);
+ fr.filehandle = file->tftp_remoteport;
+ fr.buffer[0] = file->tftp_pktbuf;
+ fr.buffer[1] = PKTBUF_SEG;
+ fr.buffersize = PKTBUF_SIZE;
+ err = pxe_call(PXENV_FILE_READ, &fr);
if (!err) /* successed */
break;
- if (fr->status == PXENV_STATUS_TFTP_OPEN)
+ if (fr.status == PXENV_STATUS_TFTP_OPEN)
continue;
call16(kaboom, NULL, NULL);
}
- file->tftp_bytesleft = fr->buffersize;
- file->tftp_filepos += fr->buffersize;
+ file->tftp_bytesleft = fr.buffersize;
+ file->tftp_filepos += fr.buffersize;
if (file->tftp_bytesleft == 0)
file->tftp_filesize = file->tftp_filepos;
@@ -1246,7 +1248,7 @@ void get_packet_gpxe(struct open_file_t *file)
/* Got EOF, close it */
file->tftp_goteof = 1;
- pxe_call(PXENV_FILE_CLOSE, fr);
+ pxe_call(PXENV_FILE_CLOSE, &fr);
}
#endif /* GPXE */
@@ -1268,7 +1270,7 @@ void fill_buffer(struct open_file_t *file)
uint16_t buffersize;
uint16_t old_time;
void *data = NULL;
- struct pxe_udp_read_pkt *pkt = (struct pxe_udp_read_pkt *)pxe_udp_read_pkt;
+ static __lowmem struct pxe_udp_read_pkt pkt;
if (file->tftp_bytesleft || file->tftp_goteof)
return;
@@ -1292,14 +1294,14 @@ void fill_buffer(struct open_file_t *file)
timeout = *timeout_ptr++;
old_time = BIOS_timer;
while (timeout) {
- pkt->buffer[0] = file->tftp_pktbuf;
- pkt->buffer[1] = PKTBUF_SEG;
- pkt->buffersize = PKTBUF_SIZE;
- pkt->sip = file->tftp_remoteip;
- pkt->dip = MyIP;
- pkt->rport = file->tftp_remoteport;
- pkt->lport = file->tftp_localport;
- err = pxe_call(PXENV_UDP_READ, pkt);
+ pkt.buffer[0] = file->tftp_pktbuf;
+ pkt.buffer[1] = PKTBUF_SEG;
+ pkt.buffersize = PKTBUF_SIZE;
+ pkt.sip = file->tftp_remoteip;
+ pkt.dip = MyIP;
+ pkt.rport = file->tftp_remoteport;
+ pkt.lport = file->tftp_localport;
+ err = pxe_call(PXENV_UDP_READ, &pkt);
if (err) {
if (BIOS_timer == old_time) {
printf(".");
@@ -1316,7 +1318,7 @@ void fill_buffer(struct open_file_t *file)
continue;
}
- if (pkt->buffersize < 4) /* Bad size for a DATA packet */
+ if (pkt.buffersize < 4) /* Bad size for a DATA packet */
continue;
data = MK_PTR(PKTBUF_SEG, file->tftp_pktbuf);
@@ -1349,7 +1351,7 @@ void fill_buffer(struct open_file_t *file)
/* It's the packet we want. We're also EOF if the size < blocksize */
file->tftp_lastpkt = last_pkt; /* Update last packet number */
- buffersize = pkt->buffersize - 4; /* Skip TFTP header */
+ buffersize = pkt.buffersize - 4; /* Skip TFTP header */
file->tftp_dataptr = file->tftp_pktbuf + 4;
file->tftp_filepos += buffersize;
file->tftp_bytesleft = buffersize;
@@ -1706,10 +1708,10 @@ void searchdir_c(com32sys_t *regs)
char *src, *dst;
char *data;
struct open_file_t *file;
- struct pxe_udp_write_pkt *uw_pkt = (struct pxe_udp_write_pkt *)pxe_udp_write_pkt;
- struct pxe_udp_read_pkt *ur_pkt = (struct pxe_udp_read_pkt *)pxe_udp_read_pkt;
- struct gpxe_file_open *fo = (struct gpxe_file_open *)gpxe_file_open;
- struct gpxe_get_file_size *gs = (struct gpxe_get_file_size *)gpxe_get_file_size;
+ static __lowmem struct pxe_udp_write_pkt uw_pkt;
+ static __lowmem struct pxe_udp_read_pkt ur_pkt;
+ static __lowmem struct gpxe_file_open fo;
+ static __lowmem struct gpxe_get_file_size gs;
struct tftp_options *tftp_opt = tftp_options;
int i = 0;
int tftp_opts = sizeof tftp_options / sizeof tftp_options[0];
@@ -1735,8 +1737,8 @@ void searchdir_c(com32sys_t *regs)
timeout_ptr = TimeoutTable; /* Reset timeout */
sendreq:
- uw_pkt->buffer[0] = OFFS_WRT(buf, 0);
- uw_pkt->buffer[1] = 0;
+ uw_pkt.buffer[0] = OFFS_WRT(buf, 0);
+ uw_pkt.buffer[1] = 0;
*(uint16_t *)buf = TFTP_RRQ; /* TFTP opcode */
buf += 2;
@@ -1754,10 +1756,10 @@ void searchdir_c(com32sys_t *regs)
#if GPXE
if (is_gpxe(packet_buf + 2)) {
- fo->status = PXENV_STATUS_BAD_FUNC;
- fo->filename[0] = OFFS_WRT(packet_buf + 2, 0);
- fo->filename[1] = regs->ds;
- err = pxe_call(PXENV_FILE_OPEN, fo);
+ fo.status = PXENV_STATUS_BAD_FUNC;
+ fo.filename[0] = OFFS_WRT(packet_buf + 2, 0);
+ fo.filename[1] = regs->ds;
+ err = pxe_call(PXENV_FILE_OPEN, &fo);
if (err) {
free_socket(file);
regs->esi.w[0] = 0;
@@ -1766,13 +1768,13 @@ void searchdir_c(com32sys_t *regs)
}
file->tftp_localport = -1;
- file->tftp_remoteport = fo->filehandle;
- gs->filehandle = fo->filehandle;
+ file->tftp_remoteport = fo.filehandle;
+ gs.filehandle = fo.filehandle;
#if 0
- err = pxe_call(PXENV_GET_FILE_SIZE, gs);
+ err = pxe_call(PXENV_GET_FILE_SIZE, &gs);
if (!err)
- filesize = gs->filesize;
+ filesize = gs.filesize;
else
#endif
filesize = -1;
@@ -1783,14 +1785,14 @@ void searchdir_c(com32sys_t *regs)
file->tftp_remoteip = ip;
tid = file->tftp_localport; /* TID(local port No) */
- uw_pkt->sip = ip;
- uw_pkt->gip = ((uw_pkt->sip ^ MyIP) & Netmask) ? Gateway : 0;
- uw_pkt->lport = tid;
- uw_pkt->rport = ServerPort;
+ uw_pkt.sip = ip;
+ uw_pkt.gip = ((uw_pkt.sip ^ MyIP) & Netmask) ? Gateway : 0;
+ uw_pkt.lport = tid;
+ uw_pkt.rport = ServerPort;
buf += fill_tail(buf);
- uw_pkt->buffersize = buf - packet_buf;
- err = pxe_call(PXENV_UDP_WRITE, uw_pkt);
- if (err || uw_pkt->status != 0)
+ uw_pkt.buffersize = buf - packet_buf;
+ err = pxe_call(PXENV_UDP_WRITE, &uw_pkt);
+ if (err || uw_pkt.status != 0)
goto failure; /* In fact, the 'failure' target will not do a failure thing;
it will move on to the next timeout, then tries again until
_real_ time out */
@@ -1805,12 +1807,12 @@ void searchdir_c(com32sys_t *regs)
oldtime = BIOS_timer;
while (timeout) {
buf = packet_buf;
- ur_pkt->buffer[0] = OFFS_WRT(buf, 0);
- ur_pkt->buffer[1] = regs->ds;
- ur_pkt->buffersize = 2048;
- ur_pkt->dip = MyIP;
- ur_pkt->lport = tid;
- err = pxe_call(PXENV_UDP_READ, ur_pkt);
+ ur_pkt.buffer[0] = OFFS_WRT(buf, 0);
+ ur_pkt.buffer[1] = regs->ds;
+ ur_pkt.buffersize = 2048;
+ ur_pkt.dip = MyIP;
+ ur_pkt.lport = tid;
+ err = pxe_call(PXENV_UDP_READ, &ur_pkt);
if (err) {
if (oldtime == BIOS_timer)
continue;
@@ -1820,19 +1822,19 @@ void searchdir_c(com32sys_t *regs)
}
/* Make sure the packet actually came from the server */
- if (ur_pkt->sip == file->tftp_remoteip)
+ if (ur_pkt.sip == file->tftp_remoteip)
break;
}
/* Got packet; reset timeout */
timeout_ptr = TimeoutTable;
- file->tftp_remoteport = ur_pkt->rport;
+ file->tftp_remoteport = ur_pkt.rport;
/* filesize <- -1 == unknow */
file->tftp_filesize = -1;
/* Default blksize unless blksize option negotiated */
file->tftp_blksize = TFTP_BLOCKSIZE;
- buffersize = ur_pkt->buffersize - 2; /* bytes after opcode */
+ buffersize = ur_pkt.buffersize - 2; /* bytes after opcode */
if (buffersize < 0)
goto failure; /* Garbled reply */
@@ -1944,11 +1946,11 @@ void searchdir_c(com32sys_t *regs)
extern char tftp_proto_err[];
err_reply:
- uw_pkt->rport = file->tftp_remoteport;
- uw_pkt->buffer[0] = OFFS_WRT(tftp_proto_err, 0);
- uw_pkt->buffer[1] = 0;
- uw_pkt->buffersize = 24;
- pxe_call(PXENV_UDP_WRITE, uw_pkt);
+ uw_pkt.rport = file->tftp_remoteport;
+ uw_pkt.buffer[0] = OFFS_WRT(tftp_proto_err, 0);
+ uw_pkt.buffer[1] = 0;
+ uw_pkt.buffersize = 24;
+ pxe_call(PXENV_UDP_WRITE, &uw_pkt);
printf("TFTP server sent an incomprehesible reply\n");
call16(kaboom, NULL, NULL);
}