aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/unit/78 nostdlib/subprojects/mylibc
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/unit/78 nostdlib/subprojects/mylibc')
-rw-r--r--meson/test cases/unit/78 nostdlib/subprojects/mylibc/libc.c35
-rw-r--r--meson/test cases/unit/78 nostdlib/subprojects/mylibc/meson.build13
-rw-r--r--meson/test cases/unit/78 nostdlib/subprojects/mylibc/stdio.h5
-rw-r--r--meson/test cases/unit/78 nostdlib/subprojects/mylibc/stubstart.s8
4 files changed, 61 insertions, 0 deletions
diff --git a/meson/test cases/unit/78 nostdlib/subprojects/mylibc/libc.c b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/libc.c
new file mode 100644
index 000000000..67261cb1d
--- /dev/null
+++ b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/libc.c
@@ -0,0 +1,35 @@
+/* Do not use this as the basis of your own libc.
+ * The code is probably unoptimal or wonky, as I
+ * had no prior experience with this, but instead
+ * just fiddled with the code until it worked.
+ */
+
+#include<stdio.h>
+
+#define STDOUT 1
+#define SYS_WRITE 4
+
+int simple_print(const char *msg, const long bufsize) {
+ int count;
+ long total_written = 0;
+ while(total_written < bufsize) {
+ asm(
+ "int $0x80\n\t"
+ : "=a"(count)
+ : "0"(SYS_WRITE), "b"(STDOUT), "c"(msg+total_written), "d"(bufsize-total_written)
+ :);
+ if(count == 0) {
+ return 1;
+ }
+ total_written += count;
+ }
+ return 0;
+}
+
+int simple_strlen(const char *str) {
+ int len = 0;
+ while(str[len] != '\0') {
+ len++;
+ }
+ return len;
+}
diff --git a/meson/test cases/unit/78 nostdlib/subprojects/mylibc/meson.build b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/meson.build
new file mode 100644
index 000000000..ff4bdb20f
--- /dev/null
+++ b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/meson.build
@@ -0,0 +1,13 @@
+project('own libc', 'c')
+
+# A very simple libc implementation
+
+# Do not specify -nostdlib & co. They come from cross specifications.
+
+libc = static_library('c', 'libc.c', 'stubstart.s')
+
+mylibc_dep = declare_dependency(link_with : libc,
+ include_directories : include_directories('.')
+)
+
+meson.override_dependency('c_stdlib', mylibc_dep)
diff --git a/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stdio.h b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stdio.h
new file mode 100644
index 000000000..c3f8f56ca
--- /dev/null
+++ b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stdio.h
@@ -0,0 +1,5 @@
+#pragma once
+
+int simple_print(const char *msg, const long bufsize);
+
+int simple_strlen(const char *str);
diff --git a/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stubstart.s b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stubstart.s
new file mode 100644
index 000000000..0a6d9729a
--- /dev/null
+++ b/meson/test cases/unit/78 nostdlib/subprojects/mylibc/stubstart.s
@@ -0,0 +1,8 @@
+.globl _start
+
+_start:
+
+ call main
+ movl %eax, %ebx
+ movl $1, %eax
+ int $0x80