#define ALIGNDOWN(v) (v)
#endif
+/* These work fine for most compilers but can be overriden for those where the
+ resulting code generation is foul */
+#ifndef LOWORD
+#define LOWORD(x) ((uint16_t)(x))
+#endif
+#ifndef HIBYTE32
+#define HIBYTE32(x) ((uint8_t)((x) >> 24))
+#endif
+
#ifdef CONFIG_LEVEL_2
#include "level2.h"
#else
#define BLKSIZE 512
#define BLKSHIFT 9
#define BLKMASK 511
-#define BLKOVERSIZE 25 /* Bits 25+ mean we exceeded the file size */
+#define BLKOVERSIZE32 0xFE /* Bits 25+ mean we exceeded the file size */
/* Help the 8bit compilers out by preventing any 32bit promotions */
#define BLKOFF(x) (((uint16_t)(x)) & BLKMASK)
return 0;
}
}
- udata.u_count = min(udata.u_count, (uint16_t)ino->c_node.i_size);
+ udata.u_count = min(udata.u_count, LOWORD(ino->c_node.i_size));
return 1;
}
gcc_miscompile_workaround();
#endif
umove(amount);
- if (ispipe && (uint16_t)udata.u_offset >= 18 * BLKSIZE)
+ if (ispipe && LOWORD(udata.u_offset) >= 18 * BLKSIZE)
udata.u_offset = 0;
if (ispipe) {
ino->c_node.i_size -= amount;
/* FIXME: this will hang if you ever write > 16 * BLKSIZE
in one go - needs merging into the loop */
while (udata.u_count > (16 * BLKSIZE) -
- (uint16_t)ino->c_node.i_size) {
+ LOWORD(ino->c_node.i_size)) {
if (ino->c_readers == 0) { /* No readers */
udata.u_done = (usize_t)-1;
udata.u_error = EPIPE;
while (udata.u_count) {
pblk = mapcalc(ino, &amount, 0);
- if (udata.u_offset >> BLKOVERSIZE) {
+ if (HIBYTE32(udata.u_offset) & BLKOVERSIZE32) {
udata.u_error = EFBIG;
ssig(udata.u_ptab, SIGXFSZ);
break;
umove(amount);
if (ispipe) {
- if ((uint16_t)udata.u_offset >= 18 * 512)
+ if (LOWORD(udata.u_offset) >= 18 * 512)
udata.u_offset = 0;
ino->c_node.i_size += amount;
/* Wake up any readers */