From d847394a7663df1593625507b9a0d26acf0c814b Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Tue, 13 Dec 2022 14:46:34 +0800 Subject: [PATCH] 1, delete some unused code, 2, print usage when start scf, 3, mov test code to dir examples. --- examples/hello.c | 9 +++++++ {parse => examples}/mat.c | 15 ++---------- parse/qsort.test => examples/qsort.c | 13 +++++----- lib/Makefile | 3 --- lib/scf_linux_api.c | 35 --------------------------- lib/scf_linux_api.o | Bin 5374 -> 0 bytes lib/scf_syscall.o | Bin 872 -> 728 bytes lib/scf_syscall.s | 12 ++------- parse/main.c | 6 ++--- 9 files changed, 22 insertions(+), 71 deletions(-) create mode 100644 examples/hello.c rename {parse => examples}/mat.c (91%) rename parse/qsort.test => examples/qsort.c (58%) delete mode 100644 lib/scf_linux_api.o 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 5048c4a1d0a6d225f0aac61c97951c8793be28ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5374 zcmb`JUu;`f9mmhTcH)#YS?jX36%X^Ybn6&)+O@P1Wu0$gw>O&|r*4uah1PYPo5YL% zVPBVYY_O_S)QS)-JPc__OyYq*Pi%Wwkw7g1p%z}sc&T`*gpj5&#CVw|fmD9qbAHEm zP8-I6pLFl}ozMCGIsfiC_iM@25!WC)n4Dwx4tSuRENJ|CJvhc+0XQUfc-fgTZy*+?KV-0>Hi@68)o7mbd02`iuT*| zf0SD8H{Tc8|LaD_O#k5x{5SQhlrOY1E5-Cbw1NKx_P_QK{zs@iNKf3b8{MqHW#$Nn zaq9d#m>;9^e*SN>zqW%vmelm0-@yM}_P@iE3;&+`_&11|dxwzt?I7Ni51k`HxJ~q! z`M*NUSRx`qyd9Q>_`b2YMpaxOv-|mf>66O;o2qEPP5)`P^=J3|d#hw{+?jHwof+pu z>!lCfR`Y$gHT{memZoR={k7(YZs7yBy_)V-9r0Lp<{jv#PtLimp4wLWPNJ2(ood~1e|8r~ z2!cLxgC;!HO5buXUPm~8vwQX3yGs7z(<1GG)!Iw9+}4XjBC(dfoi5x=tR?TH3)its zg_~F@7sGFn(KT#0NT;`MD>c;Twx))*xGjHZN2-+=ilm6`mMiF<|21~!+{x35zz7&+H5gey;ye|M)h* z_>NabcUs%%^BofX{fGMl)Q8}H5$IDUHl18O4^YcEne=Y60)zd%Xn{v)plvpSDS4UZ zOLe7B_GI%>g0p&zRCeEjz0VWaLXY(*EJFU-T*E5}YgZXn5|D~SkG(=w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b#9IQUr)dvsp(==|i-`Oo9{aVDUS7a(1S!CG+;%vfz^U|BP@%aU*c?=BNP<0@egKYWp9|9QkiYs$V5|e;*NfCt3 zfU$~Fa}xDRQY%Ur^imQ_5*hT8ii^>$BbToL)Clq$8=3(QP`&}0I8t5$R7@1 z9)gg7DwKcxt35C@bG6IX+ZqsK%6R2@2nZodvt0mw{p^@Gd<#RWQm**^g)0SX_G lKhfRK2^2%O8>|KDP;oE^L7=-|5QlyPs6s=8Rxk@)KLGO+Jgxu$ 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; } -- 2.25.1