From a1747ac91621250d640d08136cc6b0730db3b955 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 10 Sep 2018 22:56:18 +0200 Subject: [PATCH] Add the .dataf4 and .dataf8 directives to the assembler --- manually converting floats and doubles to bytes is not fun. It might even work! --- mach/mips/libem/c_ud_i.s | 3 +-- mach/mips/libem/c_uf_i.s | 3 +-- mach/mips/libem/c_ui_d.s | 3 +-- mach/mips/libem/c_ui_f.s | 2 +- mach/pdp/as/mach0.c | 1 + mach/proto/as/build.lua | 1 + mach/proto/as/comm1.h | 1 + mach/proto/as/comm2.y | 15 +++++++++++++++ mach/proto/as/comm3.c | 2 ++ mach/proto/as/comm5.c | 24 ++++++++++++++++++++++-- mach/proto/as/comm7.c | 28 ++++++++++++++++++++++++++++ man/uni_ass.6 | 10 ++++++++++ 12 files changed, 84 insertions(+), 9 deletions(-) diff --git a/mach/mips/libem/c_ud_i.s b/mach/mips/libem/c_ud_i.s index ccd798e03..ed2c6479e 100644 --- a/mach/mips/libem/c_ud_i.s +++ b/mach/mips/libem/c_ud_i.s @@ -28,9 +28,8 @@ toobig: jr ra nop -/* 2147483648 as a double. */ .sect .rom .define .fd_80000000 .fd_80000000: - .data4 0, 0x41e00000 + .dataf8 2147483648.0 diff --git a/mach/mips/libem/c_uf_i.s b/mach/mips/libem/c_uf_i.s index 8bd840b40..8d7129cad 100644 --- a/mach/mips/libem/c_uf_i.s +++ b/mach/mips/libem/c_uf_i.s @@ -31,8 +31,7 @@ toobig: jr ra nop -/* 2147483648 as a float. */ .sect .rom .ff_80000000: - .data4 0x4f000000 + .dataf4 2147483648.0 diff --git a/mach/mips/libem/c_ui_d.s b/mach/mips/libem/c_ui_d.s index c46a2cf4a..0d339b702 100644 --- a/mach/mips/libem/c_ui_d.s +++ b/mach/mips/libem/c_ui_d.s @@ -20,7 +20,6 @@ nonnegative: jr ra nop -/* 4294967296 as a double. */ .sect .rom .fd_100000000: - .data4 0, 0x41f00000 + .dataf8 4294967296.0 diff --git a/mach/mips/libem/c_ui_f.s b/mach/mips/libem/c_ui_f.s index 46f9f0b62..7c1a05d6a 100644 --- a/mach/mips/libem/c_ui_f.s +++ b/mach/mips/libem/c_ui_f.s @@ -23,4 +23,4 @@ nonnegative: /* 4294967296 as a float. */ .sect .rom .fs_100000000: - .data4 0x4f800000 + .dataf4 4294967296.0 diff --git a/mach/pdp/as/mach0.c b/mach/pdp/as/mach0.c index c3e5c0a81..afede3407 100644 --- a/mach/pdp/as/mach0.c +++ b/mach/pdp/as/mach0.c @@ -12,6 +12,7 @@ #define WORDS_REVERSED #define LISTING #define RELOCATION +#define PDPFLOAT #undef ISALPHA #define ISALPHA(c) (isalpha(c) || c == '_' || c == '.' || c == '~') #undef ISALNUM diff --git a/mach/proto/as/build.lua b/mach/proto/as/build.lua index 52536cbbf..d9718e06f 100644 --- a/mach/proto/as/build.lua +++ b/mach/proto/as/build.lua @@ -44,6 +44,7 @@ definerule("build_as", deps = { "h+emheaders", "modules/src/object+lib", + "modules/src/flt_arith+lib", archlib, yaccfiles, e.deps diff --git a/mach/proto/as/comm1.h b/mach/proto/as/comm1.h index 7ea697015..47f4302b3 100644 --- a/mach/proto/as/comm1.h +++ b/mach/proto/as/comm1.h @@ -153,6 +153,7 @@ void emit1(int); void emit2(int); void emit4(long); void emitx(valu_t, int); +void emitf(int size); void emitstr(int); void ffreopen(char *, FILE *); FILE *ffcreat(char *); diff --git a/mach/proto/as/comm2.y b/mach/proto/as/comm2.y index 1b3e19917..0643928d8 100644 --- a/mach/proto/as/comm2.y +++ b/mach/proto/as/comm2.y @@ -43,9 +43,11 @@ static item_t *last_it, *o_it; %token NUMBER2 %token NUMBER3 %token NUMBER +%token NUMBERF %token DOT %token EXTERN %token DATA +%token DATAF %token ASCII %token SECTION %token COMMON @@ -249,6 +251,7 @@ operation DOTSCT->s_zero += $2; } | DATA datalist + | DATAF dataflist | ASCII STRING { emitstr($1);} ; @@ -276,6 +279,18 @@ datalist emitx($3.val, (int)$0); } ; + +dataflist + : NUMBERF + { + emitf((int)$0); + } + | dataflist ',' NUMBERF + { + emitf((int)$3); + } + ; + expr : error { serror("expr syntax err"); $$.val = 0; $$.typ = S_UND; diff --git a/mach/proto/as/comm3.c b/mach/proto/as/comm3.c index f35d1818c..2a24a0878 100644 --- a/mach/proto/as/comm3.c +++ b/mach/proto/as/comm3.c @@ -29,6 +29,8 @@ item_t keytab[] = { 0, DATA, RELO1, ".data1", 0, DATA, RELO2, ".data2", 0, DATA, RELO4, ".data4", + 0, DATAF, 4, ".dataf4", + 0, DATAF, 8, ".dataf8", 0, ASCII, 0, ".ascii", 0, ASCII, 1, ".asciz", 0, ALIGN, 0, ".align", diff --git a/mach/proto/as/comm5.c b/mach/proto/as/comm5.c index 0703f3bfb..b91ad3466 100644 --- a/mach/proto/as/comm5.c +++ b/mach/proto/as/comm5.c @@ -395,10 +395,12 @@ static int innumber(int c) { char* p; int radix; - static char num[20 + 1]; + static char num[40 + 1]; p = num; - radix = 20; + radix = 40; + if (c == '.') + goto floatconstant; do { if (--radix < 0) @@ -407,6 +409,8 @@ static int innumber(int c) c += ('a' - 'A'); *p++ = c; c = nextchar(); + if (c == '.') + goto floatconstant; } while (isalnum(c)); peekc = c; *p = '\0'; @@ -441,6 +445,22 @@ static int innumber(int c) yylval.y_valu = yylval.y_valu * radix + c; } return (NUMBER); + +floatconstant: + do + { + if (--radix < 0) + fatal("number too long"); + if (isupper(c)) + c += ('a' - 'A'); + *p++ = c; + c = nextchar(); + } while (isdigit(c) || (c == '.') || (c == 'E') || (c == '+') || (c == '-')); + + *p = '\0'; + stringbuf = strdup(num); + stringlen = p - num; + return NUMBERF; } static int instring(int termc) diff --git a/mach/proto/as/comm7.c b/mach/proto/as/comm7.c index 66147b130..c9e340191 100644 --- a/mach/proto/as/comm7.c +++ b/mach/proto/as/comm7.c @@ -346,6 +346,34 @@ void emitstr(int zero) emit1(0); } +#define CODE_EXPANDER + +#if !defined IEEEFLOAT && !defined PDPFLOAT + #define IEEEFLOAT +#endif + +#if defined WORDS_REVERSED + #define FL_MSL_AT_LOW_ADDRESS 1 + #define FL_MSW_AT_LOW_ADDRESS 1 +#else + #define FL_MSL_AT_LOW_ADDRESS 0 + #define FL_MSW_AT_LOW_ADDRESS 0 +#endif + +#if defined BYTES_REVERSED + #define FL_MSB_AT_LOW_ADDRESS 1 +#else + #define FL_MSB_AT_LOW_ADDRESS 0 +#endif + +#define gen1 emit1 +#include + +void emitf(int size) +{ + con_float(stringbuf, size); +} + /* ---------- Error checked file I/O ---------- */ void ffreopen(char* s, FILE* f) diff --git a/man/uni_ass.6 b/man/uni_ass.6 index 94b60a3cc..6d970621e 100644 --- a/man/uni_ass.6 +++ b/man/uni_ass.6 @@ -206,6 +206,16 @@ This is not followed by automatic alignment. .Pu ".data4 \fIexpression [, expression]*\fP" Initialize a sequence of longs (4-byte values). This is not followed by automatic alignment. +.Pu ".dataf4 \fIliteralfloat [, literalfloat]*\fP" +Initialize a sequence of floats (4-byte values). +The values must be literal floating point constants containing +a dot character. +This is not followed by automatic alignment. +.Pu ".dataf8 \fIliteralfloat [, literalfloat]*\fP" +Initialize a sequence of doubles (8-byte values). +The values must be literal floating point constants containing +a dot character. +This is not followed by automatic alignment. .Pu ".ascii \fIstring\fP" Initialize a sequence of bytes with the value of the bytes in the string.