From bfb54c50f9babd4c4cfc20597b274e80f881ec2f Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 30 Nov 2014 20:57:29 +0000 Subject: [PATCH] utils: Allow for wrong endian file systems --- Standalone/fuzix_fs.h | 5 +++-- Standalone/mkfs.c | 2 +- Standalone/ucp.c | 1 + Standalone/util.c | 22 ++++++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Standalone/fuzix_fs.h b/Standalone/fuzix_fs.h index a65b7823..3c48bf51 100644 --- a/Standalone/fuzix_fs.h +++ b/Standalone/fuzix_fs.h @@ -40,8 +40,9 @@ void bufsync (void); char *zerobuf (void); int super(void); -#define swizzle16(x) (x) -#define swizzle32(x) (x) +extern uint16_t swizzle16(uint32_t v); +extern uint32_t swizzle32(uint32_t v); +extern int swizzling; typedef struct s_queue { char *q_base; /* Pointer to data */ diff --git a/Standalone/mkfs.c b/Standalone/mkfs.c index 8fcb8410..0d9d69a8 100644 --- a/Standalone/mkfs.c +++ b/Standalone/mkfs.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) argc--; } if (argc != 4) { - printf("Usage: mkfs device isize fsize\n"); + printf("Usage: mkfs [-X] device isize fsize\n"); return -1; } diff --git a/Standalone/ucp.c b/Standalone/ucp.c index f8f7f713..ba4c8b7d 100644 --- a/Standalone/ucp.c +++ b/Standalone/ucp.c @@ -25,6 +25,7 @@ char *month[] = "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +int swizzling = 0; int match(char *cmd); void usage(void); diff --git a/Standalone/util.c b/Standalone/util.c index 895bb9b1..9d1beed5 100644 --- a/Standalone/util.c +++ b/Standalone/util.c @@ -13,6 +13,8 @@ int dev_fd; int dev_offset; struct u_data udata; +extern int swizzling; + int fd_open(char *name) { char *namecopy, *sd; @@ -43,3 +45,23 @@ void panic(char *s) fprintf(stderr, "panic: %s\n", s); exit(1); } + +uint16_t swizzle16(uint32_t v) +{ + if (v & 0xFFFF0000UL) { + fprintf(stderr, "swizzle16 given a 32bit input\n"); + exit(1); + } + if (swizzling) + return (v & 0xFF) << 8 | ((v & 0xFF00) >> 8); + else return v; +} + +uint32_t swizzle32(uint32_t v) +{ + if (!swizzling) + return v; + + return (v & 0xFF) << 24 | (v & 0xFF00) << 8 | (v & 0xFF0000) >> 8 | + (v & 0xFF000000) >> 24; +} -- 2.34.1