From 49d01a46fa02e7a6ae06dd652f8299529ae2c8c8 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 26 Nov 2017 18:45:10 +0100 Subject: [PATCH] mlibc: Mescc-tools support: chmod. * stage0/x86.M1 (SYS_chmod): New define. * lib/libc-gcc.c (chmod): New function. * lib/libc-mes.c (chmod): New function. --- lib/libc-gcc.c | 20 ++++++++++++++++++++ lib/libc-mes.c | 10 ++++++++++ stage0/x86.M1 | 1 + 3 files changed, 31 insertions(+) diff --git a/lib/libc-gcc.c b/lib/libc-gcc.c index 303d4e3e..f951433c 100644 --- a/lib/libc-gcc.c +++ b/lib/libc-gcc.c @@ -140,6 +140,26 @@ open (char const *s, int flags, ...) #endif } +int +chmod (char const *s, int mode) +{ +#if !__TINYC__ + int r; + //syscall (SYS_chmod, mode)); + asm ( + "mov %1,%%ebx\n\t" + "mov %2,%%ecx\n\t" + "mov $0x0f,%%eax\n\t" + "int $0x80\n\t" + "mov %%eax,%0\n\t" + : "=r" (r) + : "" (s), "" (mode) + : "eax", "ebx", "ecx" + ); + return r; +#endif +} + int access (char const *s, int mode) { diff --git a/lib/libc-mes.c b/lib/libc-mes.c index 3fbd68be..670eaca4 100644 --- a/lib/libc-mes.c +++ b/lib/libc-mes.c @@ -68,6 +68,16 @@ open () asm ("int____$0x80"); // int $0x80 } +void +chmod () +{ + asm ("mov____0x8(%ebp),%ebx !8"); // mov 0x8(%ebp),%ebx + asm ("mov____0x8(%ebp),%ecx !12"); // mov 0x8(%ebp),%ecx + + asm ("mov____$i32,%eax SYS_chmod"); // mov $0x0f,%eax + asm ("int____$0x80"); // int $0x80 +} + void access () { diff --git a/stage0/x86.M1 b/stage0/x86.M1 index cbac03e2..f1554a22 100644 --- a/stage0/x86.M1 +++ b/stage0/x86.M1 @@ -195,6 +195,7 @@ DEFINE SYS_write 04000000 DEFINE SYS_open 05000000 DEFINE SYS_close 06000000 DEFINE SYS_unlink 0a000000 +DEFINE SYS_chmod 0f000000 DEFINE SYS_lseek 13000000 DEFINE SYS_access 21000000 DEFINE SYS_brk 2d000000