mlibc: Tinycc support: support, most syscalls stubbed.
* mlibc/libc-gcc.c (exit, write)[__TINYC__]: tcc-compatible gcc-style asm implementation. (read,open,access,brk,fsync)[__TINYC__]: Stub body. * mlibc/libc-gcc+tcc.c (close,unlink, lseek, getcwd)[__TINYC__]: Stub body. * mlibc/libc-mes+tcc.c: Support tinycc. * mlibc/include/00-test.i (main) [__TINYC__]: Support tcc.
This commit is contained in:
parent
67afa2a397
commit
26e9dd14e3
|
@ -28,11 +28,17 @@ main ()
|
|||
asm ("mov____%eax,%ebx");
|
||||
asm ("mov____$i32,%eax SYS_exit");
|
||||
asm ("int____$0x80");
|
||||
#else // !__MESC__
|
||||
#elif __GNUC__
|
||||
asm ("mov %0,%%ebx"
|
||||
: // no outputs
|
||||
: "" (r));
|
||||
asm ("mov $1,%eax");
|
||||
asm ("int $0x80");
|
||||
#endif
|
||||
#elif __TINYC__
|
||||
asm ("mov %0,%%ebx"
|
||||
: // no outputs
|
||||
: "Ir" (r));
|
||||
asm ("mov $1,%eax");
|
||||
asm ("int $0x80");
|
||||
#endif // __GNUC__
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ int errno;
|
|||
int
|
||||
close (int fd)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
asm (
|
||||
"mov %0,%%ebx\n\t"
|
||||
|
@ -53,11 +54,13 @@ close (int fd)
|
|||
: "" (fd)
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
unlink (char const *file_name)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
asm (
|
||||
"mov %0,%%ebx\n\t"
|
||||
|
@ -67,11 +70,13 @@ unlink (char const *file_name)
|
|||
: "" (file_name)
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
off_t
|
||||
lseek (int fd, off_t offset, int whence)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
|
@ -87,11 +92,13 @@ lseek (int fd, off_t offset, int whence)
|
|||
: "eax", "ebx", "ecx", "edx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
char *
|
||||
getcwd (char *buf, size_t size)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
|
@ -106,6 +113,7 @@ getcwd (char *buf, size_t size)
|
|||
: "eax", "ebx", "ecx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
int g_stdin = 0;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <mlibc.h>
|
||||
|
||||
|
@ -27,18 +25,28 @@ int g_stdin = 0;
|
|||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if __GNUC__ && !POSIX
|
||||
#if (__GNUC__ || __TINYC__) && !POSIX
|
||||
|
||||
void
|
||||
exit (int code)
|
||||
{
|
||||
#if !__TINYC__
|
||||
asm (
|
||||
"mov %0,%%ebx\n\t"
|
||||
"mov $1,%%eax\n\t"
|
||||
"int $0x80"
|
||||
"int $0x80\n\t"
|
||||
: // no outputs "=" (r)
|
||||
: "" (code)
|
||||
);
|
||||
#else // __TINYC__
|
||||
asm (
|
||||
"mov %0,%%ebx\n\t"
|
||||
"mov $1,%%eax\n\t"
|
||||
"int $128\n\t"
|
||||
: // no outputs "=" (r)
|
||||
: "Ir" (code)
|
||||
);
|
||||
#endif // __TINYC__
|
||||
// not reached
|
||||
exit (0);
|
||||
}
|
||||
|
@ -46,6 +54,7 @@ exit (int code)
|
|||
int
|
||||
read (int fd, void* buf, size_t n)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
//syscall (SYS_write, fd, s, n));
|
||||
asm (
|
||||
|
@ -62,31 +71,49 @@ read (int fd, void* buf, size_t n)
|
|||
: "eax", "ebx", "ecx", "edx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
write (int fd, char const* s, int n)
|
||||
{
|
||||
int r;
|
||||
//syscall (SYS_write, fd, s, n));
|
||||
#if __GNUC__
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
"mov %2,%%ecx\n\t"
|
||||
"mov %3,%%edx\n\t"
|
||||
|
||||
"mov $0x4, %%eax\n\t"
|
||||
"mov $0x04,%%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "" (fd), "" (s), "" (n)
|
||||
: "eax", "ebx", "ecx", "edx"
|
||||
);
|
||||
|
||||
//syscall (SYS_write, fd, s, n));
|
||||
#elif __TINYC__
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
"mov %2,%%ecx\n\t"
|
||||
"mov %3,%%edx\n\t"
|
||||
|
||||
"mov $4, %%eax\n\t"
|
||||
"int $128\n\t"
|
||||
"mov %%eax,%0\n\t"
|
||||
: "=r" (r)
|
||||
: "Ir" (fd), "Ir" (s), "Ir" (n)
|
||||
: "eax", "ebx", "ecx"//, "edx"
|
||||
);
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
open (char const *s, int flags, ...)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int mode;
|
||||
asm (
|
||||
"mov %%ebp,%%eax\n\t"
|
||||
|
@ -110,11 +137,13 @@ open (char const *s, int flags, ...)
|
|||
: "eax", "ebx", "ecx", "edx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
access (char const *s, int mode)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
//syscall (SYS_access, mode));
|
||||
asm (
|
||||
|
@ -128,11 +157,13 @@ access (char const *s, int mode)
|
|||
: "eax", "ebx", "ecx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
void *
|
||||
brk (void *p)
|
||||
{
|
||||
#if !__TINYC__
|
||||
void *r;
|
||||
asm (
|
||||
"mov %1,%%ebx\n\t"
|
||||
|
@ -146,11 +177,13 @@ brk (void *p)
|
|||
: "eax", "ebx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
fsync (int fd)
|
||||
{
|
||||
#if !__TINYC__
|
||||
int r;
|
||||
//syscall (SYS_fsync, fd));
|
||||
asm (
|
||||
|
@ -164,6 +197,7 @@ fsync (int fd)
|
|||
: "eax", "ebx"
|
||||
);
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if !__GNUC__
|
||||
#if !__GNUC__ && !__TINYC__
|
||||
#include <libc-mes.c>
|
||||
|
||||
int errno;
|
||||
|
|
Loading…
Reference in a new issue