summaryrefslogtreecommitdiff
path: root/com32/lib/syslinux/shuffle.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-03-12 13:17:35 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-03-12 13:17:35 -0700
commit9a0509cffdb22cd647b4b9bea266c2ea68a7341e (patch)
tree28f82b1087c3859ec8164964fe64d7f87ca7da34 /com32/lib/syslinux/shuffle.c
parent66950a7c945cbb4c378c6185490a0d7d773e20d1 (diff)
downloadsyslinux-9a0509cffdb22cd647b4b9bea266c2ea68a7341e.tar.gz
Wrapper infrastructure for "shuffle and boot"
Initial checkin of a wrapper infrastructure for the "shuffle and boot" interface, both real and protected mode. This code automatically will figure out the necessary sequence of moves, taking into account swaps and overlaps as necessary.
Diffstat (limited to 'com32/lib/syslinux/shuffle.c')
-rw-r--r--com32/lib/syslinux/shuffle.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c
new file mode 100644
index 00000000..ad6e7d06
--- /dev/null
+++ b/com32/lib/syslinux/shuffle.c
@@ -0,0 +1,82 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007 H. Peter Anvin - All Rights Reserved
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall
+ * be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * shuffle.c
+ *
+ * Common code for "shuffle and boot" operation; generates a shuffle list
+ * and puts it in the bounce buffer. Returns the number of shuffle
+ * descriptors.
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+#include <com32.h>
+#include <syslinux/movebits.h>
+
+struct shuffle_descriptor {
+ uint32_t dst, src, len;
+};
+
+int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist)
+{
+ struct syslinux_movelist *moves = NULL, *freelist = NULL, *mp;
+ int n;
+ struct shuffle_descriptor *dp;
+ int np, rv = -1;
+
+ freelist = syslinux_memory_map();
+ if (!freelist)
+ goto bail;
+
+ if (syslinux_compute_movelist(&moves, fraglist, freelist))
+ goto bail;
+
+ dp = __com32.cs_bounce;
+ np = 0;
+
+ for (mp = moves; mp; mp = mp->next) {
+ if (np >= 65536/12)
+ goto bail; /* Way too many descriptors... */
+
+ dp->dst = mp->dst;
+ dp->src = mp->src;
+ dp->len = mp->len;
+ np++;
+ }
+
+ rv = np;
+
+ bail:
+ if (freelist)
+ syslinux_free_movelist(freelist);
+ if (moves)
+ syslinux_free_movelist(moves);
+
+ return rv;
+}
+