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____%eax,%ebx");
|
||||||
asm ("mov____$i32,%eax SYS_exit");
|
asm ("mov____$i32,%eax SYS_exit");
|
||||||
asm ("int____$0x80");
|
asm ("int____$0x80");
|
||||||
#else // !__MESC__
|
#elif __GNUC__
|
||||||
asm ("mov %0,%%ebx"
|
asm ("mov %0,%%ebx"
|
||||||
: // no outputs
|
: // no outputs
|
||||||
: "" (r));
|
: "" (r));
|
||||||
asm ("mov $1,%eax");
|
asm ("mov $1,%eax");
|
||||||
asm ("int $0x80");
|
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
|
int
|
||||||
close (int fd)
|
close (int fd)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
asm (
|
asm (
|
||||||
"mov %0,%%ebx\n\t"
|
"mov %0,%%ebx\n\t"
|
||||||
|
@ -53,11 +54,13 @@ close (int fd)
|
||||||
: "" (fd)
|
: "" (fd)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
unlink (char const *file_name)
|
unlink (char const *file_name)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
asm (
|
asm (
|
||||||
"mov %0,%%ebx\n\t"
|
"mov %0,%%ebx\n\t"
|
||||||
|
@ -67,11 +70,13 @@ unlink (char const *file_name)
|
||||||
: "" (file_name)
|
: "" (file_name)
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t
|
off_t
|
||||||
lseek (int fd, off_t offset, int whence)
|
lseek (int fd, off_t offset, int whence)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
asm (
|
asm (
|
||||||
"mov %1,%%ebx\n\t"
|
"mov %1,%%ebx\n\t"
|
||||||
|
@ -87,11 +92,13 @@ lseek (int fd, off_t offset, int whence)
|
||||||
: "eax", "ebx", "ecx", "edx"
|
: "eax", "ebx", "ecx", "edx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
getcwd (char *buf, size_t size)
|
getcwd (char *buf, size_t size)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
asm (
|
asm (
|
||||||
"mov %1,%%ebx\n\t"
|
"mov %1,%%ebx\n\t"
|
||||||
|
@ -106,6 +113,7 @@ getcwd (char *buf, size_t size)
|
||||||
: "eax", "ebx", "ecx"
|
: "eax", "ebx", "ecx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -18,8 +18,6 @@
|
||||||
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int g_stdin = 0;
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <mlibc.h>
|
#include <mlibc.h>
|
||||||
|
|
||||||
|
@ -27,18 +25,28 @@ int g_stdin = 0;
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __GNUC__ && !POSIX
|
#if (__GNUC__ || __TINYC__) && !POSIX
|
||||||
|
|
||||||
void
|
void
|
||||||
exit (int code)
|
exit (int code)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
asm (
|
asm (
|
||||||
"mov %0,%%ebx\n\t"
|
"mov %0,%%ebx\n\t"
|
||||||
"mov $1,%%eax\n\t"
|
"mov $1,%%eax\n\t"
|
||||||
"int $0x80"
|
"int $0x80\n\t"
|
||||||
: // no outputs "=" (r)
|
: // no outputs "=" (r)
|
||||||
: "" (code)
|
: "" (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
|
// not reached
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
@ -46,6 +54,7 @@ exit (int code)
|
||||||
int
|
int
|
||||||
read (int fd, void* buf, size_t n)
|
read (int fd, void* buf, size_t n)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
//syscall (SYS_write, fd, s, n));
|
//syscall (SYS_write, fd, s, n));
|
||||||
asm (
|
asm (
|
||||||
|
@ -62,31 +71,49 @@ read (int fd, void* buf, size_t n)
|
||||||
: "eax", "ebx", "ecx", "edx"
|
: "eax", "ebx", "ecx", "edx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
write (int fd, char const* s, int n)
|
write (int fd, char const* s, int n)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
//syscall (SYS_write, fd, s, n));
|
#if __GNUC__
|
||||||
asm (
|
asm (
|
||||||
"mov %1,%%ebx\n\t"
|
"mov %1,%%ebx\n\t"
|
||||||
"mov %2,%%ecx\n\t"
|
"mov %2,%%ecx\n\t"
|
||||||
"mov %3,%%edx\n\t"
|
"mov %3,%%edx\n\t"
|
||||||
|
|
||||||
"mov $0x4, %%eax\n\t"
|
"mov $0x04,%%eax\n\t"
|
||||||
"int $0x80\n\t"
|
"int $0x80\n\t"
|
||||||
"mov %%eax,%0\n\t"
|
"mov %%eax,%0\n\t"
|
||||||
: "=r" (r)
|
: "=r" (r)
|
||||||
: "" (fd), "" (s), "" (n)
|
: "" (fd), "" (s), "" (n)
|
||||||
: "eax", "ebx", "ecx", "edx"
|
: "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;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
open (char const *s, int flags, ...)
|
open (char const *s, int flags, ...)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int mode;
|
int mode;
|
||||||
asm (
|
asm (
|
||||||
"mov %%ebp,%%eax\n\t"
|
"mov %%ebp,%%eax\n\t"
|
||||||
|
@ -110,11 +137,13 @@ open (char const *s, int flags, ...)
|
||||||
: "eax", "ebx", "ecx", "edx"
|
: "eax", "ebx", "ecx", "edx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
access (char const *s, int mode)
|
access (char const *s, int mode)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
//syscall (SYS_access, mode));
|
//syscall (SYS_access, mode));
|
||||||
asm (
|
asm (
|
||||||
|
@ -128,11 +157,13 @@ access (char const *s, int mode)
|
||||||
: "eax", "ebx", "ecx"
|
: "eax", "ebx", "ecx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
brk (void *p)
|
brk (void *p)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
void *r;
|
void *r;
|
||||||
asm (
|
asm (
|
||||||
"mov %1,%%ebx\n\t"
|
"mov %1,%%ebx\n\t"
|
||||||
|
@ -146,11 +177,13 @@ brk (void *p)
|
||||||
: "eax", "ebx"
|
: "eax", "ebx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
fsync (int fd)
|
fsync (int fd)
|
||||||
{
|
{
|
||||||
|
#if !__TINYC__
|
||||||
int r;
|
int r;
|
||||||
//syscall (SYS_fsync, fd));
|
//syscall (SYS_fsync, fd));
|
||||||
asm (
|
asm (
|
||||||
|
@ -164,6 +197,7 @@ fsync (int fd)
|
||||||
: "eax", "ebx"
|
: "eax", "ebx"
|
||||||
);
|
);
|
||||||
return r;
|
return r;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#if !__GNUC__
|
#if !__GNUC__ && !__TINYC__
|
||||||
#include <libc-mes.c>
|
#include <libc-mes.c>
|
||||||
|
|
||||||
int errno;
|
int errno;
|
||||||
|
|
Loading…
Reference in New Issue