From: yu.dongliang <18588496441@163.com> Date: Tue, 13 Dec 2022 06:46:34 +0000 (+0800) Subject: 1, delete some unused code, X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=d847394a7663df1593625507b9a0d26acf0c814b;p=scf.git 1, delete some unused code, 2, print usage when start scf, 3, mov test code to dir examples. --- diff --git a/examples/hello.c b/examples/hello.c new file mode 100644 index 0000000..4ce1a4c --- /dev/null +++ b/examples/hello.c @@ -0,0 +1,9 @@ + +int printf(const char* fmt, ...); + +int main() +{ + printf("hello world\n"); + return 0; +} + diff --git a/parse/mat.c b/examples/mat.c similarity index 91% rename from parse/mat.c rename to examples/mat.c index 200faca..4c5241c 100644 --- a/parse/mat.c +++ b/examples/mat.c @@ -1,16 +1,5 @@ -void scf__release_pt (void* objdata); - -void* scf__auto_malloc(uintptr_t size); -void scf__auto_ref(void* data); - -void scf__auto_freep (void** pp, scf__release_pt* release); -void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release); -void scf__auto_free_array (void** pp, int size, int nb_pointers, scf__release_pt* release); - -int memcpy(void* dst, const void* src, uintptr_t n); - -int scf_printf(const char* fmt, ...); +include "../lib/scf_capi.c"; const int MAT_TYPE_NONE = 0; const int MAT_TYPE_U8 = 1; @@ -234,7 +223,7 @@ int main() int i; for (i = 0; i < 4; i++) - scf_printf("m3: %lf\n", dd[i]); + printf("m3: %lf\n", dd[i]); // scf_printf("m1: %lf\n", *(double*)(m1->data + i * sizeof(double))); return 0; diff --git a/parse/qsort.test b/examples/qsort.c similarity index 58% rename from parse/qsort.test rename to examples/qsort.c index 1e8fc6d..1a45e31 100644 --- a/parse/qsort.test +++ b/examples/qsort.c @@ -1,4 +1,4 @@ -int printf(char* fmt, int a); +int printf(const char* fmt, ...); int sort(int* a, int m, int n) { @@ -12,12 +12,12 @@ int sort(int* a, int m, int n) t = a[i]; while (i < j) { - while (i < j && t < a[j]) + while (i < j && t <= a[j]) j--; a[i] = a[j]; a[j] = t; - while (i < j && a[i] < t) + while (i < j && a[i] <= t) i++; a[j] = a[i]; a[i] = t; @@ -30,12 +30,13 @@ int sort(int* a, int m, int n) int main() { - int a[10] = {1, 3, 5, 7, 9, 8, 6, 4, 2, 0}; + int a[20] = {1, 3, 5, 7, 9, 8, 4, 2, 6, 0, + 11, 13, 15, 17, 19, 18, 16, 14, 12, 10}; - sort(a, 0, 9); + sort(a, 0, 19); int i; - for (i = 0; i < 10; i++) + for (i = 0; i < 20; i++) printf("%d\n", a[i]); return 0; diff --git a/lib/Makefile b/lib/Makefile index e3e4628..e044053 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,9 +1,6 @@ all: as _start.s -o _start.o as scf_syscall.s -o scf_syscall.o - as scf_memcpy.s -o scf_memcpy.o - as scf_memcmp.s -o scf_memcmp.o - as scf_memset.s -o scf_memset.o clean: rm *.o diff --git a/lib/scf_linux_api.c b/lib/scf_linux_api.c index 8087146..3995bd8 100644 --- a/lib/scf_linux_api.c +++ b/lib/scf_linux_api.c @@ -56,38 +56,3 @@ struct stat struct timespec st_ctim; /* Time of last status change */ }; -int scf__read(int fd, uint8_t* buf, uint64_t size) -{ - return scf_syscall(SCF_read, fd, buf, size); -} - -int scf__write(int fd, uint8_t* buf, uint64_t size) -{ - return scf_syscall(SCF_write, fd, buf, size); -} - -int scf__open(const char *pathname, int flags, ...); - -int scf__close(int fd) -{ - return scf_syscall(SCF_close, fd); -} - -int scf__fstat(int fd, stat *statbuf) -{ - return scf_syscall(SCF_fstat, fd, statbuf); -} - -intptr_t scf__mmap(void* addr, uint64_t len, int prot, int flags, int fd, uint64_t offset) -{ - if (offset & 0xfff) - return -EINVAL; - - return scf_syscall(SCF_mmap, addr, len, prot, flags, fd, offset); -} - -int scf__munmap(void* addr, uint64_t len) -{ - return scf_syscall(SCF_munmap, addr, len); -} - diff --git a/lib/scf_linux_api.o b/lib/scf_linux_api.o deleted file mode 100644 index 5048c4a..0000000 Binary files a/lib/scf_linux_api.o and /dev/null differ diff --git a/lib/scf_syscall.o b/lib/scf_syscall.o index 447574d..0f6c879 100644 Binary files a/lib/scf_syscall.o and b/lib/scf_syscall.o differ diff --git a/lib/scf_syscall.s b/lib/scf_syscall.s index 533bda9..357a5de 100644 --- a/lib/scf_syscall.s +++ b/lib/scf_syscall.s @@ -1,5 +1,5 @@ .text -.global scf_syscall, scf__open +.global scf_syscall scf_syscall: @@ -17,12 +17,4 @@ scf_syscall: syscall ret - -scf__open: - movq %rdx, %rcx - movq %rsi, %rdx - movq %rdi, %rsi - movq $2, %rdi - call scf_syscall - ret -.fill 0, 1, 0 +.fill 6, 1, 0 diff --git a/parse/main.c b/parse/main.c index a36886f..1724de4 100644 --- a/parse/main.c +++ b/parse/main.c @@ -5,8 +5,6 @@ static char* __objs[] = { "../lib/_start.o", - "../lib/scf_syscall.o", - "../lib/scf_linux_api.o", "../lib/scf_object.o", "../lib/scf_atomic.o", }; @@ -37,7 +35,8 @@ int main(int argc, char* argv[]) } if (optind >= argc) { - fprintf(stderr, "Expected argument after options\n"); + fprintf(stderr, "Usage: %s src0 [src1] [-o out]\n", argv[0]); + fprintf(stderr, "Usage: %s -c src0 [-o out]\n", argv[0]); return -1; } @@ -143,7 +142,6 @@ int main(int argc, char* argv[]) return -1; } - printf("%s(),%d, main ok\n", __func__, __LINE__); return 0; }