summaryrefslogtreecommitdiff
path: root/scripts/stdincludes/stdarg.h
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2023-07-25 14:58:33 -0700
committerMatthew Sotoudeh <matthew@masot.net>2023-07-25 14:58:33 -0700
commit1d943da0cf9154e7ce78ce867cdbb91531c5d78e (patch)
tree40c5c6c3ba7fafa6567aa5b5aa216caecf3935fc /scripts/stdincludes/stdarg.h
initial dietc commit
Diffstat (limited to 'scripts/stdincludes/stdarg.h')
-rw-r--r--scripts/stdincludes/stdarg.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/stdincludes/stdarg.h b/scripts/stdincludes/stdarg.h
new file mode 100644
index 0000000..73563b4
--- /dev/null
+++ b/scripts/stdincludes/stdarg.h
@@ -0,0 +1,46 @@
+#ifndef _STDARG_H
+#define _STDARG_H
+
+typedef struct {
+ unsigned int gp_offset; unsigned int fp_offset;
+ void *overflow_arg_area; void *reg_save_area;
+} __va_elem;
+typedef __va_elem va_list;
+typedef va_list __builtin_va_list;
+typedef va_list __gnuc_va_list;
+
+extern void __builtin_va_start(void *ap, void *last);
+#define va_start(ap, last) do { void *_ap = &ap; __builtin_va_start(_ap, last); } while (0)
+#define va_end(ap)
+static void *__va_arg_mem(__va_elem *ap, int sz, int align) {
+ unsigned long p = ap->overflow_arg_area;
+ if (align > 8)
+ p = (p + 15) / 16 * 16;
+ ap->overflow_arg_area = ((unsigned long)p + sz + 7) / 8 * 8;
+ return (void*)p;
+}
+static void *__va_arg_gp(__va_elem *ap, int sz, int align) {
+ if (ap->gp_offset >= 48)
+ return __va_arg_mem(ap, sz, align);
+
+ void *r = ap->reg_save_area + ap->gp_offset;
+ ap->gp_offset += 8;
+ return r;
+}
+static void *__va_arg_fp(__va_elem *ap, int sz, int align) {
+ if (ap->fp_offset >= 112)
+ return __va_arg_mem(ap, sz, align);
+
+ void *r = ap->reg_save_area + ap->fp_offset;
+ ap->fp_offset += 8;
+ return r;
+}
+#define va_arg(ap, ty) \
+ ({ \
+ int klass = __builtin_reg_class(ty); \
+ *(ty *)(klass == 0 ? __va_arg_gp(&ap, sizeof(ty), _Alignof(ty)) : \
+ klass == 1 ? __va_arg_fp(&ap, sizeof(ty), _Alignof(ty)) : \
+ __va_arg_mem(&ap, sizeof(ty), _Alignof(ty))); \
+ })
+
+#endif
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback