summaryrefslogtreecommitdiff
path: root/com32/lib/syslinux/shuffle.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:27 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-29 15:10:27 -0700
commit0ac639579f37898e0f1e165bd8fcca8bc70b449e (patch)
tree40b359e1c2c39f266a1c330a241b299e6c342a01 /com32/lib/syslinux/shuffle.c
parentdfc6a45461f2f5c8aad79e825f2f10036f6584d4 (diff)
downloadsyslinux-0ac639579f37898e0f1e165bd8fcca8bc70b449e.tar.gz
Run Nindent on com32/lib/syslinux/shuffle.c
Automatically reformat com32/lib/syslinux/shuffle.c using Nindent. Do this for all files except HDT, gPXE and externally maintained libraries (zlib, tinyjpeg, libpng). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'com32/lib/syslinux/shuffle.c')
-rw-r--r--com32/lib/syslinux/shuffle.c317
1 files changed, 160 insertions, 157 deletions
diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c
index 6c33d0a5..6b5a601f 100644
--- a/com32/lib/syslinux/shuffle.c
+++ b/com32/lib/syslinux/shuffle.c
@@ -60,19 +60,19 @@
#endif
struct shuffle_descriptor {
- uint32_t dst, src, len;
+ uint32_t dst, src, len;
};
static int shuffler_size;
static void __constructor __syslinux_get_shuffer_size(void)
{
- static com32sys_t reg;
+ static com32sys_t reg;
- reg.eax.w[0] = 0x0023;
- __intcall(0x22, &reg, &reg);
+ reg.eax.w[0] = 0x0023;
+ __intcall(0x22, &reg, &reg);
- shuffler_size = (reg.eflags.l & EFLAGS_CF) ? 2048 : reg.ecx.w[0];
+ shuffler_size = (reg.eflags.l & EFLAGS_CF) ? 2048 : reg.ecx.w[0];
}
/*
@@ -86,187 +86,190 @@ int syslinux_do_shuffle(struct syslinux_movelist *fraglist,
addr_t entry_point, addr_t entry_type,
uint16_t bootflags)
{
- int rv = -1;
- struct syslinux_movelist *moves = NULL, *mp;
- struct syslinux_memmap *rxmap = NULL, *ml;
- struct shuffle_descriptor *dp, *dbuf;
- int np;
- int desc_blocks, need_blocks;
- int need_ptrs;
- addr_t desczone, descfree, descaddr, descoffs;
- int nmoves, nzero;
- com32sys_t ireg;
-
- descaddr = 0;
- dp = dbuf = NULL;
-
- /* Count the number of zero operations */
- nzero = 0;
- for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
- if (ml->type == SMT_ZERO)
- nzero++;
- }
-
- /* Find the largest contiguous region unused by input *and* output;
- this is where we put the move descriptor list and safe area */
-
- rxmap = syslinux_dup_memmap(memmap);
- if (!rxmap)
- goto bail;
- /* Avoid using the low 1 MB for the shuffle area -- this avoids
- possible interference with the real mode code or stack */
- if (syslinux_add_memmap(&rxmap, 0, 1024*1024, SMT_RESERVED))
- goto bail;
- for (mp = fraglist; mp; mp = mp->next) {
- if (syslinux_add_memmap(&rxmap, mp->src, mp->len, SMT_ALLOC) ||
- syslinux_add_memmap(&rxmap, mp->dst, mp->len, SMT_ALLOC))
- goto bail;
- }
- if (syslinux_memmap_largest(rxmap, SMT_FREE, &desczone, &descfree))
- goto bail;
-
- syslinux_free_memmap(rxmap);
-
- dprintf("desczone = 0x%08x, descfree = 0x%08x\n", desczone, descfree);
-
- rxmap = syslinux_dup_memmap(memmap);
- if (!rxmap)
- goto bail;
-
- desc_blocks = (nzero+DESC_BLOCK_SIZE-1)/DESC_BLOCK_SIZE;
- for (;;) {
- /* We want (desc_blocks) allocation blocks, plus the terminating
- descriptor, plus the shuffler safe area. */
- addr_t descmem = desc_blocks*
- sizeof(struct shuffle_descriptor)*DESC_BLOCK_SIZE
- + sizeof(struct shuffle_descriptor) + shuffler_size;
-
- descaddr = (desczone + descfree - descmem) & ~3;
-
- if (descaddr < desczone)
- goto bail; /* No memory block large enough */
-
- /* Mark memory used by shuffle descriptors as reserved */
- if (syslinux_add_memmap(&rxmap, descaddr, descmem, SMT_RESERVED))
- goto bail;
+ int rv = -1;
+ struct syslinux_movelist *moves = NULL, *mp;
+ struct syslinux_memmap *rxmap = NULL, *ml;
+ struct shuffle_descriptor *dp, *dbuf;
+ int np;
+ int desc_blocks, need_blocks;
+ int need_ptrs;
+ addr_t desczone, descfree, descaddr, descoffs;
+ int nmoves, nzero;
+ com32sys_t ireg;
+
+ descaddr = 0;
+ dp = dbuf = NULL;
+
+ /* Count the number of zero operations */
+ nzero = 0;
+ for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
+ if (ml->type == SMT_ZERO)
+ nzero++;
+ }
+
+ /* Find the largest contiguous region unused by input *and* output;
+ this is where we put the move descriptor list and safe area */
+
+ rxmap = syslinux_dup_memmap(memmap);
+ if (!rxmap)
+ goto bail;
+ /* Avoid using the low 1 MB for the shuffle area -- this avoids
+ possible interference with the real mode code or stack */
+ if (syslinux_add_memmap(&rxmap, 0, 1024 * 1024, SMT_RESERVED))
+ goto bail;
+ for (mp = fraglist; mp; mp = mp->next) {
+ if (syslinux_add_memmap(&rxmap, mp->src, mp->len, SMT_ALLOC) ||
+ syslinux_add_memmap(&rxmap, mp->dst, mp->len, SMT_ALLOC))
+ goto bail;
+ }
+ if (syslinux_memmap_largest(rxmap, SMT_FREE, &desczone, &descfree))
+ goto bail;
+
+ syslinux_free_memmap(rxmap);
+
+ dprintf("desczone = 0x%08x, descfree = 0x%08x\n", desczone, descfree);
+
+ rxmap = syslinux_dup_memmap(memmap);
+ if (!rxmap)
+ goto bail;
+
+ desc_blocks = (nzero + DESC_BLOCK_SIZE - 1) / DESC_BLOCK_SIZE;
+ for (;;) {
+ /* We want (desc_blocks) allocation blocks, plus the terminating
+ descriptor, plus the shuffler safe area. */
+ addr_t descmem = desc_blocks *
+ sizeof(struct shuffle_descriptor) * DESC_BLOCK_SIZE
+ + sizeof(struct shuffle_descriptor) + shuffler_size;
+
+ descaddr = (desczone + descfree - descmem) & ~3;
+
+ if (descaddr < desczone)
+ goto bail; /* No memory block large enough */
+
+ /* Mark memory used by shuffle descriptors as reserved */
+ if (syslinux_add_memmap(&rxmap, descaddr, descmem, SMT_RESERVED))
+ goto bail;
#if DEBUG > 1
- syslinux_dump_movelist(stdout, fraglist);
+ syslinux_dump_movelist(stdout, fraglist);
#endif
- if (syslinux_compute_movelist(&moves, fraglist, rxmap))
- goto bail;
+ if (syslinux_compute_movelist(&moves, fraglist, rxmap))
+ goto bail;
- nmoves = 0;
- for (mp = moves; mp; mp = mp->next)
- nmoves++;
+ nmoves = 0;
+ for (mp = moves; mp; mp = mp->next)
+ nmoves++;
- need_blocks = (nmoves+nzero+DESC_BLOCK_SIZE-1)/DESC_BLOCK_SIZE;
+ need_blocks = (nmoves + nzero + DESC_BLOCK_SIZE - 1) / DESC_BLOCK_SIZE;
- if (desc_blocks >= need_blocks)
- break; /* Sufficient memory, yay */
+ if (desc_blocks >= need_blocks)
+ break; /* Sufficient memory, yay */
- desc_blocks = need_blocks; /* Try again... */
- }
+ desc_blocks = need_blocks; /* Try again... */
+ }
#if DEBUG > 1
- dprintf("Final movelist:\n");
- syslinux_dump_movelist(stdout, moves);
+ dprintf("Final movelist:\n");
+ syslinux_dump_movelist(stdout, moves);
#endif
- syslinux_free_memmap(rxmap);
- rxmap = NULL;
+ syslinux_free_memmap(rxmap);
+ rxmap = NULL;
- need_ptrs = nmoves+nzero+1;
- dbuf = malloc(need_ptrs*sizeof(struct shuffle_descriptor));
- if (!dbuf)
- goto bail;
+ need_ptrs = nmoves + nzero + 1;
+ dbuf = malloc(need_ptrs * sizeof(struct shuffle_descriptor));
+ if (!dbuf)
+ goto bail;
- descoffs = descaddr - (addr_t)dbuf;
+ descoffs = descaddr - (addr_t) dbuf;
#if DEBUG
- dprintf("nmoves = %d, nzero = %d, dbuf = %p, offs = 0x%08x\n",
- nmoves, nzero, dbuf, descoffs);
+ dprintf("nmoves = %d, nzero = %d, dbuf = %p, offs = 0x%08x\n",
+ nmoves, nzero, dbuf, descoffs);
#endif
- /* Copy the move sequence into the descriptor buffer */
- np = 0;
- dp = dbuf;
- for (mp = moves; mp; mp = mp->next) {
- dp->dst = mp->dst;
- dp->src = mp->src;
- dp->len = mp->len;
- dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
- dp++; np++;
- }
-
- /* Copy bzero operations into the descriptor buffer */
- for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
- if (ml->type == SMT_ZERO) {
- dp->dst = ml->start;
- dp->src = (addr_t)-1; /* bzero region */
- dp->len = ml->next->start - ml->start;
- dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
- dp++; np++;
+ /* Copy the move sequence into the descriptor buffer */
+ np = 0;
+ dp = dbuf;
+ for (mp = moves; mp; mp = mp->next) {
+ dp->dst = mp->dst;
+ dp->src = mp->src;
+ dp->len = mp->len;
+ dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
+ dp++;
+ np++;
}
- }
-
- /* Finally, record the termination entry */
- dp->dst = entry_point;
- dp->src = entry_type;
- dp->len = 0;
- dp++; np++;
-
- if (np != need_ptrs) {
- dprintf("!!! np = %d : nmoves = %d, nzero = %d, desc_blocks = %d\n",
- np, nmoves, nzero, desc_blocks);
- }
-
- rv = 0;
-
- bail:
- /* This is safe only because free() doesn't use the bounce buffer!!!! */
- if (moves)
- syslinux_free_movelist(moves);
- if (rxmap)
- syslinux_free_memmap(rxmap);
- if (rv)
- return rv;
+ /* Copy bzero operations into the descriptor buffer */
+ for (ml = memmap; ml->type != SMT_END; ml = ml->next) {
+ if (ml->type == SMT_ZERO) {
+ dp->dst = ml->start;
+ dp->src = (addr_t) - 1; /* bzero region */
+ dp->len = ml->next->start - ml->start;
+ dprintf2("[ %08x %08x %08x ]\n", dp->dst, dp->src, dp->len);
+ dp++;
+ np++;
+ }
+ }
+
+ /* Finally, record the termination entry */
+ dp->dst = entry_point;
+ dp->src = entry_type;
+ dp->len = 0;
+ dp++;
+ np++;
+
+ if (np != need_ptrs) {
+ dprintf("!!! np = %d : nmoves = %d, nzero = %d, desc_blocks = %d\n",
+ np, nmoves, nzero, desc_blocks);
+ }
- /* Actually do it... */
- memset(&ireg, 0, sizeof ireg);
- ireg.edi.l = descaddr;
- ireg.esi.l = (addr_t)dbuf;
- ireg.ecx.l = (addr_t)dp-(addr_t)dbuf;
- ireg.edx.w[0] = bootflags;
- ireg.eax.w[0] = 0x0024;
- __intcall(0x22, &ireg, NULL);
+ rv = 0;
- return -1; /* Shouldn't have returned! */
+bail:
+ /* This is safe only because free() doesn't use the bounce buffer!!!! */
+ if (moves)
+ syslinux_free_movelist(moves);
+ if (rxmap)
+ syslinux_free_memmap(rxmap);
+
+ if (rv)
+ return rv;
+
+ /* Actually do it... */
+ memset(&ireg, 0, sizeof ireg);
+ ireg.edi.l = descaddr;
+ ireg.esi.l = (addr_t) dbuf;
+ ireg.ecx.l = (addr_t) dp - (addr_t) dbuf;
+ ireg.edx.w[0] = bootflags;
+ ireg.eax.w[0] = 0x0024;
+ __intcall(0x22, &ireg, NULL);
+
+ return -1; /* Shouldn't have returned! */
}
/*
* Common helper routine: takes a memory map and blots out the
* zones which are used in the destination of a fraglist
*/
-struct syslinux_memmap *
-syslinux_target_memmap(struct syslinux_movelist *fraglist,
- struct syslinux_memmap *memmap)
+struct syslinux_memmap *syslinux_target_memmap(struct syslinux_movelist
+ *fraglist,
+ struct syslinux_memmap *memmap)
{
- struct syslinux_memmap *tmap;
- struct syslinux_movelist *mp;
-
- tmap = syslinux_dup_memmap(memmap);
- if (!tmap)
- return NULL;
-
- for (mp = fraglist; mp; mp = mp->next) {
- if (syslinux_add_memmap(&tmap, mp->dst, mp->len, SMT_ALLOC)) {
- syslinux_free_memmap(tmap);
- return NULL;
+ struct syslinux_memmap *tmap;
+ struct syslinux_movelist *mp;
+
+ tmap = syslinux_dup_memmap(memmap);
+ if (!tmap)
+ return NULL;
+
+ for (mp = fraglist; mp; mp = mp->next) {
+ if (syslinux_add_memmap(&tmap, mp->dst, mp->len, SMT_ALLOC)) {
+ syslinux_free_memmap(tmap);
+ return NULL;
+ }
}
- }
- return tmap;
+ return tmap;
}