66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
|
/* netboot
|
||
|
*
|
||
|
* $Log: packet.c,v $
|
||
|
* Revision 1.1 1993/07/08 16:04:06 brezak
|
||
|
* Diskless boot prom code from Jim McKim (mckim@lerc.nasa.gov)
|
||
|
*
|
||
|
* Revision 1.1.1.1 1993/05/28 11:41:07 mckim
|
||
|
* Initial version.
|
||
|
*
|
||
|
*
|
||
|
* source in this file came from
|
||
|
* the Mach ethernet boot written by Leendert van Doorn.
|
||
|
*
|
||
|
* Packet allocation and deallocation routines.
|
||
|
*
|
||
|
* Copyright (c) 1992 by Leendert van Doorn
|
||
|
*/
|
||
|
#include "proto.h"
|
||
|
#include "assert.h"
|
||
|
#include "param.h"
|
||
|
#include "packet.h"
|
||
|
|
||
|
static packet_t *pool = (packet_t *)0;
|
||
|
static packet_t *last;
|
||
|
|
||
|
void
|
||
|
PktInit(void) {
|
||
|
static packet_t s_pool[PKT_POOLSIZE];
|
||
|
pool = s_pool;
|
||
|
bzero((char *)pool, PKT_POOLSIZE * sizeof(packet_t));
|
||
|
last = pool;
|
||
|
}
|
||
|
|
||
|
packet_t *
|
||
|
PktAlloc(u_long offset) {
|
||
|
int i;
|
||
|
|
||
|
for (i = 0; i < PKT_POOLSIZE; i++) {
|
||
|
if (last->pkt_used == FALSE) {
|
||
|
bzero((char *)last->pkt_data, PKT_DATASIZE);
|
||
|
last->pkt_used = TRUE;
|
||
|
last->pkt_len = 0;
|
||
|
last->pkt_offset = last->pkt_data + offset;
|
||
|
#if 0
|
||
|
printf("PktAlloc: used %x\n", last);
|
||
|
#endif
|
||
|
return last;
|
||
|
}
|
||
|
if (++last == &pool[PKT_POOLSIZE])
|
||
|
last = pool;
|
||
|
}
|
||
|
printf("Pool out of free packets\n");
|
||
|
exit(1);
|
||
|
return 0; /* silence warnings */
|
||
|
}
|
||
|
|
||
|
void
|
||
|
PktRelease(packet_t *pkt) {
|
||
|
#if 0
|
||
|
printf("PktAlloc: freed %x\n", pkt);
|
||
|
#endif
|
||
|
assert(pkt >= &pool[0]);
|
||
|
assert(pkt < &pool[PKT_POOLSIZE]);
|
||
|
(last = pkt)->pkt_used = FALSE;
|
||
|
}
|