diff options
author | H. Peter Anvin <hpa@zytor.com> | 2009-03-10 14:54:45 -0700 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2009-03-10 14:54:45 -0700 |
commit | 0921ae9c9014dcf6f7319567f52e9a1923bba708 (patch) | |
tree | 4b5cc886fe0df91051821da1eebb04c30845c3f0 /com32/lib/syslinux/shuffle.c | |
parent | 86981dec7307fd10f98410561107bde5bff7e10b (diff) | |
download | syslinux-0921ae9c9014dcf6f7319567f52e9a1923bba708.tar.gz |
shuffler: more corrections to shuffle buffer assignment
We really need to be able to allocate the shuffle buffer itself...
Diffstat (limited to 'com32/lib/syslinux/shuffle.c')
-rw-r--r-- | com32/lib/syslinux/shuffle.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c index edba4209..b891722d 100644 --- a/com32/lib/syslinux/shuffle.c +++ b/com32/lib/syslinux/shuffle.c @@ -44,11 +44,18 @@ #ifndef DEBUG # define DEBUG 0 #endif + +#define dprintf(f, ...) ((void)0) +#define dprintf2(f, ...) ((void)0) + #if DEBUG # include <stdio.h> +# undef dprintf # define dprintf printf -#else -# define dprintf(f, ...) ((void)0) +# if DEBUG > 1 +# undef dprintf2 +# define dprintf2 printf +# endif #endif struct shuffle_descriptor { @@ -78,6 +85,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, struct shuffle_descriptor *dp, *dbuf; int np, nb, nl, rv = -1; int desc_blocks, need_blocks; + int need_ptrs; addr_t desczone, descfree, descaddr, descoffs; int nmoves, nzero; struct shuffle_descriptor primaries[2]; @@ -111,7 +119,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, if (!rxmap) goto bail; - desc_blocks = (nzero+DESC_BLOCK_SIZE)/(DESC_BLOCK_SIZE-1); + desc_blocks = (nzero+DESC_BLOCK_SIZE-1)/(DESC_BLOCK_SIZE-1); for (;;) { addr_t descmem = desc_blocks* sizeof(struct shuffle_descriptor)*DESC_BLOCK_SIZE; @@ -124,7 +132,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, if (syslinux_add_memmap(&rxmap, descaddr, descmem, SMT_RESERVED)) goto bail; -#if DEBUG +#if DEBUG > 1 syslinux_dump_movelist(stdout, fraglist); #endif @@ -135,7 +143,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, for (mp = moves; mp; mp = mp->next) nmoves++; - need_blocks = (nmoves+nzero)/(DESC_BLOCK_SIZE-1); + need_blocks = (nmoves+nzero+DESC_BLOCK_SIZE-1)/(DESC_BLOCK_SIZE-1); if (desc_blocks >= need_blocks) break; /* Sufficient memory, yay */ @@ -143,7 +151,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, desc_blocks = need_blocks; /* Try again... */ } -#if DEBUG +#if DEBUG > 1 dprintf("Final movelist:\n"); syslinux_dump_movelist(stdout, moves); #endif @@ -151,7 +159,8 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, syslinux_free_memmap(rxmap); rxmap = NULL; - dbuf = malloc((nmoves+nzero+desc_blocks)*sizeof(struct shuffle_descriptor)); + need_ptrs = nmoves+nzero+desc_blocks-1; + dbuf = malloc(need_ptrs*sizeof(struct shuffle_descriptor)); if (!dbuf) goto bail; @@ -180,7 +189,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, dp->dst = mp->dst; dp->src = mp->src; dp->len = mp->len; - dprintf("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len); + dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len); dp++; np++; nb++; nl--; } @@ -199,17 +208,15 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, dp->dst = ml->start; dp->src = (addr_t)-1; /* bzero region */ dp->len = ml->next->start - ml->start; - dprintf("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len); + dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len); dp++; np++; nb++; nl--; } } -#if DEBUG - if (np != nmoves+nzero+desc_blocks) { + if (np != need_ptrs) { dprintf("!!! np = %d : nmoves = %d, nzero = %d, desc_blocks = %d\n", np, nmoves, nzero, desc_blocks); } -#endif /* Set up the primary descriptors in the bounce buffer. The first one moves the descriptor list into its designated safe |