diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-21 19:35:36 +0300 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2016-05-21 19:35:36 +0300 |
| commit | 695aa0b8c28a0069d0e999aa039a60951b440ea4 (patch) | |
| tree | 7a380df9f1e5b89eaec37512f799977faa31877b /manual tests | |
| parent | 0e469426dd799942376dd4ea96ea35ceae7f2cf8 (diff) | |
| download | meson-695aa0b8c28a0069d0e999aa039a60951b440ea4.tar.gz | |
Made cstdlib a subproject.
Diffstat (limited to 'manual tests')
| -rw-r--r-- | manual tests/9 nostdlib/meson.build | 14 | ||||
| -rw-r--r-- | manual tests/9 nostdlib/prog.c | 7 | ||||
| -rw-r--r-- | manual tests/9 nostdlib/subprojects/mylibc/libc.c | 35 | ||||
| -rw-r--r-- | manual tests/9 nostdlib/subprojects/mylibc/meson.build | 12 | ||||
| -rw-r--r-- | manual tests/9 nostdlib/subprojects/mylibc/stdio.h | 5 | ||||
| -rw-r--r-- | manual tests/9 nostdlib/subprojects/mylibc/stubstart.s | 8 |
6 files changed, 81 insertions, 0 deletions
diff --git a/manual tests/9 nostdlib/meson.build b/manual tests/9 nostdlib/meson.build new file mode 100644 index 000000000..ad5b7b9ba --- /dev/null +++ b/manual tests/9 nostdlib/meson.build @@ -0,0 +1,14 @@ +project('own libc', 'c') + +# A simple project that uses its own libc. + +libc_proj = subproject('mylibc') +libc_dep = libc_proj.get_variable('mylibc_dep') + +exe = executable('selfcontained', 'prog.c', + c_args : '-nostdlib', + link_args : '-nostdlib', + dependencies : libc_dep, +) + +test('standalone test', exe) diff --git a/manual tests/9 nostdlib/prog.c b/manual tests/9 nostdlib/prog.c new file mode 100644 index 000000000..9414bcea2 --- /dev/null +++ b/manual tests/9 nostdlib/prog.c @@ -0,0 +1,7 @@ + +#include<stdio.h> + +int main() { + const char *message = "Hello without stdlib.\n"; + return simple_print(message, simple_strlen(message)); +} diff --git a/manual tests/9 nostdlib/subprojects/mylibc/libc.c b/manual tests/9 nostdlib/subprojects/mylibc/libc.c new file mode 100644 index 000000000..67261cb1d --- /dev/null +++ b/manual tests/9 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/manual tests/9 nostdlib/subprojects/mylibc/meson.build b/manual tests/9 nostdlib/subprojects/mylibc/meson.build new file mode 100644 index 000000000..9d1fed8cf --- /dev/null +++ b/manual tests/9 nostdlib/subprojects/mylibc/meson.build @@ -0,0 +1,12 @@ +project('own libc', 'c') + +# A very simple libc implementation + +# Start with manual flags to compile, then add platform support. + +libc = static_library('c', 'libc.c', 'stubstart.s', +) + +mylibc_dep = declare_dependency(link_with : libc, + include_directories : include_directories('.') +) diff --git a/manual tests/9 nostdlib/subprojects/mylibc/stdio.h b/manual tests/9 nostdlib/subprojects/mylibc/stdio.h new file mode 100644 index 000000000..c3f8f56ca --- /dev/null +++ b/manual tests/9 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/manual tests/9 nostdlib/subprojects/mylibc/stubstart.s b/manual tests/9 nostdlib/subprojects/mylibc/stubstart.s new file mode 100644 index 000000000..0a6d9729a --- /dev/null +++ b/manual tests/9 nostdlib/subprojects/mylibc/stubstart.s @@ -0,0 +1,8 @@ +.globl _start + +_start: + + call main + movl %eax, %ebx + movl $1, %eax + int $0x80 |
