summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <curtis.mcenroe@adgear.com>2016-10-07 11:27:44 -0400
committerJune McEnroe <curtis.mcenroe@adgear.com>2016-10-07 11:27:44 -0400
commitad468334dc96f3e2b019abded7777c54642d03a5 (patch)
treec0987ff2c33973650b3bcd0bceb45283b914d6ef
parentAdd OP_HIGH to jrp (diff)
downloadsrc-ad468334dc96f3e2b019abded7777c54642d03a5.tar.gz
src-ad468334dc96f3e2b019abded7777c54642d03a5.zip
Add runtime functions to jrp
The current JITed code causes a misaligned stack error when calling into
C code. Need to find a way to align the RPN stack to 16 bytes, or swap
back to the C stack before a CALL.
-rwxr-xr-x.bin/jrp.c55
1 files changed, 52 insertions, 3 deletions
diff --git a/.bin/jrp.c b/.bin/jrp.c
index daeb1477..b98f750d 100755
--- a/.bin/jrp.c
+++ b/.bin/jrp.c
@@ -10,6 +10,7 @@ exec cc -Wall -Wextra $@ -o $(dirname $0)/jrp $0
 
 typedef unsigned long long op;
 typedef long long value;
+typedef unsigned long long uvalue;
 typedef value *(*fptr)(value *);
 
 enum {
@@ -38,6 +39,44 @@ enum {
 #define IMMED_PUSH(x) ((op)(x) << 32)
 #define IMMED_HIGH(x) ((op)(x) & 0xffffffff00000000)
 
+static void rt_print_ascii(value val) {
+    printf("%c\n", (char)val);
+}
+
+static void rt_print_bin(value val) {
+    static char buf[sizeof(value) * 8 + 1];
+    uvalue uval = val;
+    int i = sizeof(buf);
+    do {
+        buf[--i] = '0' + (uval & 1);
+    } while (uval >>= 1);
+    printf("%s\n", &buf[i]);
+}
+
+static void rt_print_oct(value val) {
+    printf("%llo\n", val);
+}
+
+static void rt_print_dec(value val) {
+    printf("%lld\n", val);
+}
+
+static void rt_print_hex(value val) {
+    printf("%llx\n", val);
+}
+
+#define JIT_PUSH(p, val) { \
+    *p++ = OP_PUSH | IMMED_PUSH(val); \
+    if (IMMED_HIGH(val)) { \
+        *p++ = OP_HIGH | IMMED_HIGH(val); \
+    } \
+}
+
+#define JIT_CALL(p, fn) { \
+    JIT_PUSH(p, fn); \
+    *p++ = OP_CALL; \
+}
+
 int main() {
     int error;
     int page = getpagesize();
@@ -51,11 +90,21 @@ int main() {
 
     op *p = ops;
     *p++ = OP_PROL;
-    *p++ = OP_PUSH | IMMED_PUSH(1);
-    *p++ = OP_PUSH | IMMED_PUSH(2);
+    JIT_PUSH(p, 7);
+    JIT_PUSH(p, 10);
+    JIT_PUSH(p, 9);
+    *p++ = OP_MUL;
     *p++ = OP_ADD;
     *p++ = OP_DUP;
-    *p++ = OP_MUL;
+    *p++ = OP_DUP;
+    *p++ = OP_DUP;
+    *p++ = OP_DUP;
+    *p++ = OP_DUP;
+    JIT_CALL(p, rt_print_ascii);
+    JIT_CALL(p, rt_print_bin);
+    JIT_CALL(p, rt_print_oct);
+    JIT_CALL(p, rt_print_dec);
+    JIT_CALL(p, rt_print_hex);
     *p++ = OP_EPIL;
 
     error = mprotect(ops, page, PROT_READ | PROT_EXEC);
sing extraneous parameters on JOIN commands, but maybe not. invite-notify reuses the INVITE command where the invited user is not self. 2019-11-09Maintain stateCaps and offer them to clientsJune McEnroe 2019-11-09Parse capabilitiesJune McEnroe The list that I've defined are the ones that I expect to be able to enable probably without any clients breaking... And of course server-time which pounce implements itself. 2019-11-09Avoid the reserved _A names with BIT macroJune McEnroe 2019-11-09Define macro for bit flag enumsJune McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. 2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe