From aab29a31866124179745bc849416db478eec5c55 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Thu, 13 Jun 2024 12:08:35 +0000 Subject: [PATCH 01/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-01/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/exercise-01/Makefile b/src/exercise-01/Makefile index 43eebed..9c45b94 100644 --- a/src/exercise-01/Makefile +++ b/src/exercise-01/Makefile @@ -16,10 +16,10 @@ $(OUTPUT_DIR): $(TARGET): $(OBJS) # 在这里指定 TARGET 的构建命令 - + $(CC) $(LDFLAGS) -o $@ $^ %.o: %.c # 在这里指定 C 文件的编译命令 - + $(CC) $(CFLAGS) -c $< -o $@ clean: rm -f $(TARGET) $(OBJS) -- Gitee From 4889c7d76ef99fb0f8540ed1e398396b2f1ec91e Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Thu, 13 Jun 2024 12:12:55 +0000 Subject: [PATCH 02/22] update src/exercise-01/Makefile. Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-01/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/src/exercise-01/Makefile b/src/exercise-01/Makefile index 9c45b94..f739261 100644 --- a/src/exercise-01/Makefile +++ b/src/exercise-01/Makefile @@ -15,7 +15,6 @@ $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(TARGET): $(OBJS) - # 在这里指定 TARGET 的构建命令 $(CC) $(LDFLAGS) -o $@ $^ %.o: %.c -- Gitee From 36c0215134e8da27026aa0152b0a2608b7d2c077 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Thu, 13 Jun 2024 12:32:37 +0000 Subject: [PATCH 03/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-02/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exercise-02/Makefile b/src/exercise-02/Makefile index aabd450..cb2c62c 100644 --- a/src/exercise-02/Makefile +++ b/src/exercise-02/Makefile @@ -20,13 +20,13 @@ $(OUTPUT_DIR): $(TARGET): $(OBJS) # 在这里指定 TARGET 的构建命令 - + $(CC) $(LDFLAGS) -o $@ $^ $(TEST_TARGET): $(TEST_OBJS) # 在这里指定 TEST_TARGET 的构建命令 - + $(CC) $(LDFLAGS) -o $@ $^ %.o: %.c # 在这里指定所有 C 文件的编译命令 - + $(CC) $(CFLAGS) -c $< -o $@ test: $(TEST_TARGET) $(TEST_TARGET) -- Gitee From 0b21a67f06211529387bf494bd73f4cc04a9d4c0 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 11:51:25 +0000 Subject: [PATCH 04/22] junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-03/Makefile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/exercise-03/Makefile b/src/exercise-03/Makefile index 5ae6884..1eefc32 100644 --- a/src/exercise-03/Makefile +++ b/src/exercise-03/Makefile @@ -16,17 +16,23 @@ TEST_TARGET = $(OUTPUT_DIR)/exercise-03_test all: $(TARGET) -$(TARGET): $(OBJS) - # 在这里指定 TARGET 的构建命令 +$(OUTPUT_DIR): + mkdir -p $(OUTPUT_DIR) -$(TEST_TARGET): $(TEST_OBJS) - # 在这里指定 TEST_TARGET 的构建命令 +functions.a: functions.o + ar rcs $@ $^ + +$(TARGET): $(OBJS) functions.a + $(CC) $(LDFLAGS) -o $@ $^ + +$(TEST_TARGET): $(TEST_OBJS) functions.a + $(CC) $(LDFLAGS) -o $@ $^ %.o: %.c - # 在这里指定所有 C 文件的编译命令 + $(CC) $(CFLAGS) -c $< -o $@ test: $(TEST_TARGET) ./$(TEST_TARGET) clean: - rm -f $(TARGET) $(TEST_TARGET) $(OBJS) $(TEST_OBJS) + rm -f $(TARGET) $(TEST_TARGET) $(OBJS) $(TEST_OBJS) functions.a \ No newline at end of file -- Gitee From 2772316b2e4846dd5e25b4936143031d61de1d11 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 11:55:31 +0000 Subject: [PATCH 05/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-04/Makefile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/exercise-04/Makefile b/src/exercise-04/Makefile index 048c53a..4a5304c 100644 --- a/src/exercise-04/Makefile +++ b/src/exercise-04/Makefile @@ -1,45 +1,45 @@ CC ?= gcc -CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g +CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g LDFLAGS = -Wl,--as-needed -Wl,--no-undefined OUTPUT_DIR ?= . -SRCS = main.c -OBJS = $(SRCS:.c=.o) -TARGET = $(OUTPUT_DIR)/exercise-04 +SRCS = main.c +OBJS = $(SRCS:.c=.o) +TARGET = $(OUTPUT_DIR)/exercise-04 -LIB_NAME = libfunctions.a -LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) -LIB_SRC = functions.c -LIB_OBJ = $(LIB_SRC:.c=.o) +LIB_NAME = libfunctions.a +LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) +LIB_SRC = functions.c +LIB_OBJ = $(LIB_SRC:.c=.o) -TEST_SRCS = test.c functions.c -TEST_OBJS = $(TEST_SRCS:.c=.o) +TEST_SRCS = test.c functions.c +TEST_OBJS = $(TEST_SRCS:.c=.o) TEST_TARGET = $(OUTPUT_DIR)/exercise-04_test -all: $(TARGET) test +all: $(OUTPUT_DIR) $(TARGET) test $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(LIB_OBJ): $(LIB_SRC) - # 在这里指定如何编译 functions.o + $(CC) $(CFLAGS) -c -o $@ $< $(LIB_TARGET): $(LIB_OBJ) - # 在这里指定如何生成静态链接库 + ar rcs $@ $^ $(TARGET): $(OBJS) $(LIB_TARGET) - # 在这里指定如何链接 libfunctions.a 来生成 TARGET + $(CC) $(LDFLAGS) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions $(TEST_TARGET): $(TEST_OBJS) $(LIB_TARGET) - # 在这里指定如何链接 libfunctions.a 来生成 TEST_TARGET + $(CC) $(LDFLAGS) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions %.o: %.c - # 在这里指定所有 C 文件的编译命令 + $(CC) $(CFLAGS) -c -o $@ $< test: $(TEST_TARGET) - $(TEST_TARGET) + ./$(TEST_TARGET) clean: rm -f $(LIB_TARGET) $(TARGET) $(TEST_TARGET) $(OBJS) $(LIB_OBJ) $(TEST_OBJS) -- Gitee From 67bdc55cc040aa3127ae95c4dc94becd741e613f Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 11:58:00 +0000 Subject: [PATCH 06/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-05/Makefile | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/exercise-05/Makefile b/src/exercise-05/Makefile index 6c9c66d..c4ae208 100644 --- a/src/exercise-05/Makefile +++ b/src/exercise-05/Makefile @@ -1,46 +1,46 @@ CC ?= gcc -CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g +CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g LDFLAGS = -Wl,--as-needed -Wl,--no-undefined +RPATH = -Wl,-rpath,'$$ORIGIN' OUTPUT_DIR ?= . -SRCS = main.c -OBJS = $(SRCS:.c=.o) -TARGET = $(OUTPUT_DIR)/exercise-05 +SRCS = main.c +OBJS = $(SRCS:.c=.o) +TARGET = $(OUTPUT_DIR)/exercise-05 -LIB_NAME = libfunctions.so -LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) -LIB_SRC = functions.c -LIB_OBJ = $(LIB_SRC:.c=.o) -RPATH = -Wl,-rpath,'$$ORIGIN' +LIB_NAME = libfunctions.so +LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) +LIB_SRC = functions.c +LIB_OBJ = $(LIB_SRC:.c=.o) -TEST_SRCS = test.c functions.c -TEST_OBJS = $(TEST_SRCS:.c=.o) +TEST_SRCS = test.c functions.c +TEST_OBJS = $(TEST_SRCS:.c=.o) TEST_TARGET = $(OUTPUT_DIR)/exercise-05_test -all: $(TARGET) test +all: $(OUTPUT_DIR) $(TARGET) test $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(LIB_OBJ): $(LIB_SRC) - # 在这里指定如何编译 libfunctions.o + $(CC) $(CFLAGS) -fPIC -c -o $@ $< $(LIB_TARGET): $(LIB_OBJ) - # 在这里指定如何生成 libfunctions.so + $(CC) -shared -o $@ $^ $(TARGET): $(OBJS) $(LIB_TARGET) - # 在这里指定如何链接 libfunctions.so 来生成 TARGET + $(CC) $(LDFLAGS) $(RPATH) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions $(TEST_TARGET): $(TEST_OBJS) $(LIB_TARGET) - # 在这里指定如何链接 libfunctions.so 来生成 TEST_TARGET + $(CC) $(LDFLAGS) $(RPATH) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions %.o: %.c - # 在这里指定如何编译所有 C 文件 + $(CC) $(CFLAGS) -c -o $@ $< test: $(TEST_TARGET) - $(TEST_TARGET) + ./$(TEST_TARGET) clean: rm -f $(LIB_TARGET) $(TARGET) $(TEST_TARGET) $(OBJS) $(LIB_OBJ) $(TEST_OBJS) -- Gitee From 9a706f948bd15da9c31a7ab3db97c868ce72e2ed Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:01:25 +0000 Subject: [PATCH 07/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-11/memory_region.ld | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/exercise-11/memory_region.ld b/src/exercise-11/memory_region.ld index 74e3d4b..f019536 100644 --- a/src/exercise-11/memory_region.ld +++ b/src/exercise-11/memory_region.ld @@ -1,6 +1,6 @@ MEMORY { /* >>> 在这里定义内存区域,设置内存区域起始地址为 `0x8000000`,长度为 `0x2000`。 */ - + RAM (rwx) : ORIGIN = 0x8000000, LENGTH = 0x2000 /* <<< */ } @@ -37,4 +37,5 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; + } -- Gitee From d4d64f0185e3094c8ef16ee92e884b7c2c7c47d1 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:02:48 +0000 Subject: [PATCH 08/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-12/text_address.ld | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exercise-12/text_address.ld b/src/exercise-12/text_address.ld index bacc566..2de92fc 100644 --- a/src/exercise-12/text_address.ld +++ b/src/exercise-12/text_address.ld @@ -1,13 +1,13 @@ MEMORY { /* >>> 在这里定义内存区域,设置内存区域起始地址为 `0x8000000`,长度为 `0x2000`。 */ - + RAM (rwx) : ORIGIN = 0x8000000, LENGTH = 0x2000 /* <<< */ } SECTIONS { /* >>> 在这里指定 `.text` 的起始地址为 `0x1000` */ - .text : { + .text 0x1000 : { *(.text) /* 其他段的定义 */ } @@ -38,4 +38,4 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; -} +} \ No newline at end of file -- Gitee From 52b964e5b4a0e2addc7c394b37e9ac7a13e4c9ee Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:06:03 +0000 Subject: [PATCH 09/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-13/new_symbol.ld | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exercise-13/new_symbol.ld b/src/exercise-13/new_symbol.ld index 2ad387c..0f2b6fd 100644 --- a/src/exercise-13/new_symbol.ld +++ b/src/exercise-13/new_symbol.ld @@ -1,6 +1,6 @@ MEMORY { /* >>> 在这里定义内存区域,设置内存区域起始地址为 `0x8000000`,长度为 `0x2000`。 */ - + RAM (rwx) : ORIGIN = 0x8000000, LENGTH = 0x2000 /* <<< */ } @@ -11,7 +11,7 @@ SECTIONS { /* 其他段的定义 */ /* >>> 在这里添加 my_custom_symbol,地址设置 0x1111 。*/ - + my_custom_symbol = 0x1111; /* <<< */ } /* <<< */ @@ -42,4 +42,4 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; -} +} \ No newline at end of file -- Gitee From fe52efb6c75f657e76c4c5f013dfa46e7a5c014e Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:07:43 +0000 Subject: [PATCH 10/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-14/custom_section.ld | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/exercise-14/custom_section.ld b/src/exercise-14/custom_section.ld index e9718fd..42bd49c 100644 --- a/src/exercise-14/custom_section.ld +++ b/src/exercise-14/custom_section.ld @@ -1,6 +1,6 @@ MEMORY { /* >>> 在这里定义内存区域,设置内存区域起始地址为 `0x8000000`,长度为 `0x2000`。 */ - + RAM (rwx) : ORIGIN = 0x8000000, LENGTH = 0x2000 /* <<< */ } @@ -23,7 +23,9 @@ SECTIONS { } > RAM /* >>> 在这里添加 my_custom_sectoin,并在其内放置 `my_custom_data`,地址设置 0x1234 。*/ - + .my_custom_section : { + my_custom_data = 0x1234; + } /* <<< */ @@ -42,4 +44,4 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; -} +} \ No newline at end of file -- Gitee From 2ee19fc712842c166ec5d727504f7fdb265e392b Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:10:23 +0000 Subject: [PATCH 11/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-20/task_queue.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/exercise-20/task_queue.c b/src/exercise-20/task_queue.c index 3cad5b3..2935a60 100644 --- a/src/exercise-20/task_queue.c +++ b/src/exercise-20/task_queue.c @@ -26,17 +26,24 @@ merge_task_queues (TaskNode *a, TaskNode *b) TaskNode head, *tail = &head, *a_ptr = a, *b_ptr = b; - while (a_ptr && b_ptr) + while (a_ptr && b_ptr) { - /* - * 在这里比较 task_id 以调整合并后任务队列的顺序。 - * - */ + + + if(a_ptr->task_id < b_ptr->task_id) + { + tail->next = a_ptr; + a_ptr = a_ptr->next; + } + else + { + tail->next = b_ptr; + b_ptr = b_ptr->next; + } tail = tail->next; } tail->next = (a_ptr ? a_ptr : b_ptr); - return head.next; } -- Gitee From 2d252d1c075c32802ab450197907b6375dc247b1 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:14:16 +0000 Subject: [PATCH 12/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-21/task_queue.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/exercise-21/task_queue.c b/src/exercise-21/task_queue.c index 39dc2f6..e729d0e 100644 --- a/src/exercise-21/task_queue.c +++ b/src/exercise-21/task_queue.c @@ -30,13 +30,6 @@ reverse_task_queue_by_group (TaskNode *head, int k) while (head != NULL) { - /* - * TIP - * 按每 k 个节点一组翻转任务队列。可以利用一个指向头节点 head 的辅 - * 助节点 hair,用 pre 指向 hair。遍历链表,每次移动 k 个节点并翻 - * 转,翻转后的段首与 pre 相连,段尾与下一段相连。继续更新 pre 和 - * head,直到遍历完成。最后返回 hair 的下一个节点作为新头节点。 - */ TaskNode *tail = pre; for (int i = 0; i < k; ++i) @@ -44,7 +37,7 @@ reverse_task_queue_by_group (TaskNode *head, int k) tail = tail->next; if (tail == NULL) { - // 在这里填写代码 + return hair->next; } } @@ -55,13 +48,13 @@ reverse_task_queue_by_group (TaskNode *head, int k) while (prev != tail) { TaskNode *temp = p->next; - // 在这里填写代码 + p->next = prev; + prev = p; + p = temp; } pre->next = tail; - - // 在这里填写代码 - + pre = head; head = next; } @@ -92,3 +85,4 @@ print_task_queue (TaskNode *head) } printf ("\n"); } + -- Gitee From 8e4022aa18fa16917aef3a428cd61af6770481b0 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:17:55 +0000 Subject: [PATCH 13/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-30/hello.c | 7 +++--- src/exercise-31/factorial.c | 49 +++++++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/exercise-30/hello.c b/src/exercise-30/hello.c index 1a9625a..074dec6 100644 --- a/src/exercise-30/hello.c +++ b/src/exercise-30/hello.c @@ -1,4 +1,3 @@ - #include /* @@ -10,7 +9,7 @@ hello_init (void) { // >>> 在这里编写如何使用打印函数 输出 hello world! - + printk(KERN_INFO "hello world!\n"); // <<< return 0; @@ -26,7 +25,7 @@ hello_exit (void) { // >>> 在这里编写如何使用打印函数输出 exit world! - + printk(KERN_INFO "exit world!\n"); // <<< } @@ -35,4 +34,4 @@ module_init (hello_init); module_exit (hello_exit); // <<< -MODULE_LICENSE ("GPL"); +MODULE_LICENSE ("GPL"); \ No newline at end of file diff --git a/src/exercise-31/factorial.c b/src/exercise-31/factorial.c index 4894534..af14aac 100644 --- a/src/exercise-31/factorial.c +++ b/src/exercise-31/factorial.c @@ -3,38 +3,49 @@ #include static int factorial_input = 0; -module_param (factorial_input, int, S_IRUGO); -MODULE_PARM_DESC (factorial_input, "An integer input parameter"); +module_param(factorial_input, int, S_IRUGO); +MODULE_PARM_DESC(factorial_input, "An integer input parameter"); -static int -factorial (int n) -{ +static int factorial(int n) { /* >>> 实现 factorial 算法。*/ + int result = 1; + int i; + if (n < 0) { + printk(KERN_WARNING "Factorial is not defined for negative numbers\n"); + return -1; // 返回 -1 代表错误 + } + for (i = 1; i <= n; ++i) { + result *= i; + } + + return result; /* <<< */ } -static int __init -factorial_init (void) -{ +static int __init factorial_init(void) { int n = factorial_input; - int result = factorial (n); - printk (KERN_INFO "Factorial of %d is %d\n", n, result); + int result = factorial(n); + + if (result == -1) { + printk(KERN_WARNING "Invalid input for factorial: %d\n", n); + } else { + printk(KERN_INFO "Factorial of %d is %d\n", n, result); + } + return 0; } -static void __exit -factorial_exit (void) -{ - printk (KERN_INFO "Module unloaded\n"); +static void __exit factorial_exit(void) { + printk(KERN_INFO "Module unloaded\n"); } /* >>> 加载和卸载内核模块。*/ -module_init (factorial_init); -module_exit (factorial_exit); +module_init(factorial_init); +module_exit(factorial_exit); /* <<< */ -MODULE_LICENSE ("GPL"); -MODULE_AUTHOR ("Your Name"); -MODULE_DESCRIPTION ("Factorial Calculation Module"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Your Name"); +MODULE_DESCRIPTION("Factorial Calculation Module"); -- Gitee From 6832f35d2b68da3452455c1f795021ac4effee57 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:19:49 +0000 Subject: [PATCH 14/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-32/reverse_string.c | 45 ++++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/exercise-32/reverse_string.c b/src/exercise-32/reverse_string.c index 4f13d0b..207c04b 100644 --- a/src/exercise-32/reverse_string.c +++ b/src/exercise-32/reverse_string.c @@ -6,43 +6,42 @@ #define MAX_LEN 100 static char reverse_string_input[MAX_LEN] = "\0"; -module_param_string (reverse_string_input, reverse_string_input, MAX_LEN, - S_IRUGO); -MODULE_PARM_DESC (reverse_string_input, "A character string input parameter"); +module_param_string(reverse_string_input, reverse_string_input, MAX_LEN, S_IRUGO); +MODULE_PARM_DESC(reverse_string_input, "A character string input parameter"); -static void /* -> 我们原地对 reverse_string_input 进行处理。 */ -reverse_string (char *str) +static void +reverse_string(char *str) { - int len = strlen (str); + int len = strlen(str); int i; char temp; for (i = 0; i < len / 2; i++) - { - temp = str[i]; - // >>> 在这里编写调换的功能 - - // <<< - } + { + temp = str[i]; + str[i] = str[len - i - 1]; + str[len - i - 1] = temp; + } } static int __init -reverse_init (void) +reverse_init(void) { - printk (KERN_INFO "Original string: %s\n", reverse_string_input); - reverse_string (reverse_string_input); - printk (KERN_INFO "Reversed string: %s\n", reverse_string_input); + printk(KERN_INFO "Original string: %s\n", reverse_string_input); + reverse_string(reverse_string_input); + printk(KERN_INFO "Reversed string: %s\n", reverse_string_input); return 0; } static void __exit -reverse_exit (void) +reverse_exit(void) { - printk (KERN_INFO "Module unloaded\n"); + printk(KERN_INFO "Module unloaded\n"); } -module_init (reverse_init); -module_exit (reverse_exit); +module_init(reverse_init); +module_exit(reverse_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Your Name"); +MODULE_DESCRIPTION("String Reversal Module"); -MODULE_LICENSE ("GPL"); -MODULE_AUTHOR ("Your Name"); -MODULE_DESCRIPTION ("String Reversal Module"); -- Gitee From a1adc0091566470a93f7c5cae0afbf0d7c1f7ec0 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 12:58:30 +0000 Subject: [PATCH 15/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-04/Makefile | 36 +++++++++++++------------- src/exercise-33/average.c | 53 ++++++++++++++++++++++----------------- 2 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/exercise-04/Makefile b/src/exercise-04/Makefile index 4a5304c..7f741ba 100644 --- a/src/exercise-04/Makefile +++ b/src/exercise-04/Makefile @@ -1,45 +1,45 @@ CC ?= gcc -CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g -LDFLAGS = -Wl,--as-needed -Wl,--no-undefined +CFLAGS = -std=c11 -Wall -Wextra -Wpedantic -Werror -g +LDFLAGS = -Wl,--as-needed -Wl,--no-undefined # -fsanitize=address -fsanitize=undefined OUTPUT_DIR ?= . -SRCS = main.c -OBJS = $(SRCS:.c=.o) -TARGET = $(OUTPUT_DIR)/exercise-04 +SRCS = main.c +OBJS = $(SRCS:.c=.o) +TARGET = $(OUTPUT_DIR)/exercise-04 -LIB_NAME = libfunctions.a -LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) -LIB_SRC = functions.c -LIB_OBJ = $(LIB_SRC:.c=.o) +LIB_NAME = libfunctions.a +LIB_TARGET = $(OUTPUT_DIR)/$(LIB_NAME) +LIB_SRC = functions.c +LIB_OBJ = $(LIB_SRC:.c=.o) -TEST_SRCS = test.c functions.c -TEST_OBJS = $(TEST_SRCS:.c=.o) +TEST_SRCS = test.c functions.c +TEST_OBJS = $(TEST_SRCS:.c=.o) TEST_TARGET = $(OUTPUT_DIR)/exercise-04_test -all: $(OUTPUT_DIR) $(TARGET) test +all: $(TARGET) test $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(LIB_OBJ): $(LIB_SRC) - $(CC) $(CFLAGS) -c -o $@ $< + $(CC) $(CFLAGS) -c $< -o $@ $(LIB_TARGET): $(LIB_OBJ) - ar rcs $@ $^ + ar rcs $@ $< $(TARGET): $(OBJS) $(LIB_TARGET) - $(CC) $(LDFLAGS) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions + $(CC) $(LDFLAGS) -o $@ $(OBJS) -L$(OUTPUT_DIR) -lfunctions $(TEST_TARGET): $(TEST_OBJS) $(LIB_TARGET) - $(CC) $(LDFLAGS) -o $@ $^ -L$(OUTPUT_DIR) -lfunctions + $(CC) $(LDFLAGS) -o $@ $(TEST_OBJS) -L$(OUTPUT_DIR) -lfunctions %.o: %.c - $(CC) $(CFLAGS) -c -o $@ $< + $(CC) $(CFLAGS) -c $< -o $@ test: $(TEST_TARGET) - ./$(TEST_TARGET) + $(TEST_TARGET) clean: rm -f $(LIB_TARGET) $(TARGET) $(TEST_TARGET) $(OBJS) $(LIB_OBJ) $(TEST_OBJS) diff --git a/src/exercise-33/average.c b/src/exercise-33/average.c index 5b13922..772dccc 100644 --- a/src/exercise-33/average.c +++ b/src/exercise-33/average.c @@ -8,34 +8,41 @@ static int average_input[MAX_ARRAY_SIZE]; static int average_input_size = 0; /* 理解 module_param_array 是如何工作的 */ -module_param_array (average_input, int, &average_input_size, 0444); -MODULE_PARM_DESC (average_input, "An array of integers"); +module_param_array(average_input, int, &average_input_size, 0444); +MODULE_PARM_DESC(average_input, "An array of integers"); static int -average (int arr[], int size) +average(int arr[], int size) { - /* >>> 求并返回平均数 */ - - - /* <<< */ + int sum = 0; + int i; + + if (size == 0) { + return 0; + } + + for (i = 0; i < size; ++i) { + sum += arr[i]; + } + + return sum / size; } static int __init -average_init (void) +average_init(void) { /* 初始化 average.ko,注意:你需要检查 average_input_size < MAX_ARRAY_SIZE。 >>> */ if (average_input_size > MAX_ARRAY_SIZE) - { - printk (KERN_WARNING "Array size exceeds maximum limit of %d\n", - MAX_ARRAY_SIZE); - return -EINVAL; - } + { + printk(KERN_WARNING "Array size exceeds maximum limit of %d\n", MAX_ARRAY_SIZE); + return -EINVAL; + } - int avg = average (average_input, average_input_size); - printk (KERN_INFO "Average of the array: %d\n", avg); + int avg = average(average_input, average_input_size); + printk(KERN_INFO "Average of the array: %d\n", avg); /* <<< @@ -45,15 +52,15 @@ average_init (void) } static void __exit -average_exit (void) +average_exit(void) { - printk (KERN_INFO "Module unloaded\n"); + printk(KERN_INFO "Module unloaded\n"); } -module_init (average_init); -module_exit (average_exit); +module_init(average_init); +module_exit(average_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Your Name"); +MODULE_DESCRIPTION("Array Average Calculation Module using Kernel Parameters"); -MODULE_LICENSE ("GPL"); -MODULE_AUTHOR ("Your Name"); -MODULE_DESCRIPTION ( - "Array Average Calculation Module using Kernel Parameters"); -- Gitee From a57d4035a48995eec1df7eb3611572e8436264da Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 13:02:07 +0000 Subject: [PATCH 16/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-34/linear_search.c | 51 +++++++++++++++++---------------- src/exercise-35/delay.c | 16 ++++++----- 2 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/exercise-34/linear_search.c b/src/exercise-34/linear_search.c index c8f2e0c..d803af9 100644 --- a/src/exercise-34/linear_search.c +++ b/src/exercise-34/linear_search.c @@ -7,28 +7,30 @@ static int ls_array_input[MAX_ARRAY_SIZE]; static int ls_array_input_size = 0; -module_param_array (ls_array_input, int, &ls_array_input_size, 0444); -MODULE_PARM_DESC (ls_array_input, "An array of integers"); +module_param_array(ls_array_input, int, &ls_array_input_size, 0444); +MODULE_PARM_DESC(ls_array_input, "An array of integers"); static int ls_target = 0; -module_param (ls_target, int, S_IRUGO); -MODULE_PARM_DESC (ls_target, "An integer input parameter"); +module_param(ls_target, int, S_IRUGO); +MODULE_PARM_DESC(ls_target, "An integer input parameter"); static int -linear_search (int arr[], int size, int target) +linear_search(int arr[], int size, int target) { int i; + + for (i = 0; i < size; ++i) { + if (arr[i] == target) { + return i; + } + } - // >>> 在这里编写功能,返回匹配的索引 - - // <<< - - return -1; + return -1; // 表示未找到 } static int __init -search_init (void) +search_init(void) { /* 初始化 linear_search.ko,注意:你需要检查 ls_array_input_size 小于 @@ -36,14 +38,13 @@ search_init (void) >>> */ if (ls_array_input_size > MAX_ARRAY_SIZE) - { - printk (KERN_WARNING "Array size exceeds maximum limit of %d\n", - MAX_ARRAY_SIZE); - return -EINVAL; - } + { + printk(KERN_WARNING "Array size exceeds maximum limit of %d\n", MAX_ARRAY_SIZE); + return -EINVAL; + } - int result = linear_search (ls_array_input, ls_array_input_size, ls_target); - printk (KERN_INFO "Index of %d in the array: %d\n", ls_target, result); + int result = linear_search(ls_array_input, ls_array_input_size, ls_target); + printk(KERN_INFO "Index of %d in the array: %d\n", ls_target, result); /* <<< @@ -53,14 +54,14 @@ search_init (void) } static void __exit -search_exit (void) +search_exit(void) { - printk (KERN_INFO "Module unloaded\n"); + printk(KERN_INFO "Module unloaded\n"); } -module_init (search_init); -module_exit (search_exit); +module_init(search_init); +module_exit(search_exit); -MODULE_LICENSE ("GPL"); -MODULE_AUTHOR ("Your Name"); -MODULE_DESCRIPTION ("Linear Search Module"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Your Name"); +MODULE_DESCRIPTION("Linear Search Module"); diff --git a/src/exercise-35/delay.c b/src/exercise-35/delay.c index 305f269..6521d19 100644 --- a/src/exercise-35/delay.c +++ b/src/exercise-35/delay.c @@ -3,20 +3,22 @@ #include static int __init -delay_init (void) +delay_init(void) { // >>> 在这里编写延时功能,并打印 Delay 2s! - + msleep(2000); // 延时 2000 毫秒 (2 秒) + printk(KERN_INFO "Delay 2s!\n"); // <<< + return 0; } static void __exit -delay_exit (void) +delay_exit(void) { - printk (KERN_ALERT "exit kernel.\n"); + printk(KERN_ALERT "exit kernel.\n"); } -module_init (delay_init); -module_exit (delay_exit); -MODULE_LICENSE ("GPL"); +module_init(delay_init); +module_exit(delay_exit); +MODULE_LICENSE("GPL"); -- Gitee From 16b42cc4317f19b675f8ccf5cbafebb166671703 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 13:04:22 +0000 Subject: [PATCH 17/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-40/main.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/exercise-40/main.c b/src/exercise-40/main.c index b409d9d..c0bc630 100644 --- a/src/exercise-40/main.c +++ b/src/exercise-40/main.c @@ -20,19 +20,19 @@ conditional_jump (int a, int b) // 结束标签 // 输出操作数,result 用来存储返回值 - // >>> 替换 PLACEHOLDER 为合适的指令完成注释的功能 __asm__ volatile ( - // 实现 a >= b,跳转到 greater_equal - "PLACEHOLDER\n" - "mv %0, %2\n" - "j end\n" + // 实现 a >= b,跳转到 greater_equal + "cmp %1, %2\n" + "bge greater_equal\n" + "mov %0, %2\n" + "b end\n" "greater_equal:\n" - "mv %0, %1\n" + "mov %0, %1\n" "end:\n" : "=r"(result) - : "r"(a), "r"(b)); - - // <<< + : "r"(a), "r"(b) + : // 暂无需使用的寄存器 + ); return result; } -- Gitee From 8d939b70270c5cec200d1a0629a48b512c0066c4 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 13:08:33 +0000 Subject: [PATCH 18/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-41/main.c | 22 ++++++------- src/exercise-42/main.c | 73 ++++++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/exercise-41/main.c b/src/exercise-41/main.c index 77da77b..9c95b95 100644 --- a/src/exercise-41/main.c +++ b/src/exercise-41/main.c @@ -7,22 +7,21 @@ gcd (int a, int b) { int result; // 用于保存计算结果 - // >>> 替换 PLACEHOLDER 为合适的指令完成注释的功能 - __asm__ volatile ( // 用于循环条件判断的标签 "loop:\n\t" // 判断 a 和 b 是否相等,如果相等,则跳出循环 - "PLACEHOLDER\n\t" - // 判断 b 是否小于 a,跳到 a_greater - "PLACEHOLDER\n\t" - // 如果 a 小于 b,则执行 b = b - a - "sub %2, %2, %1\n\t" - "jal x0, loop\n\t" - // 如果b小于a,则执行 a = a - b - "a_greater:\n\t" + "beq %1, %2, end\n\t" + // 判断 b 是否小于 a,如果是,则跳转到 a_greater + "blt %2, %1, a_greater\n\t" + // 如果 a 大于等于 b,则执行 a = a - b "sub %1, %1, %2\n\t" - "jal x0, loop\n\t" + "j loop\n\t" + // b < a 的情况 + "a_greater:\n\t" + // 如果 b 小于 a,则执行 b = b - a + "sub %2, %2, %1\n\t" + "j loop\n\t" // 循环结束标签 "end:\n\t" // 最终结果存储在 %0 中 @@ -31,7 +30,6 @@ gcd (int a, int b) : "r"(a), "r"(b) // 输入寄存器 ); - // <<< return result; } diff --git a/src/exercise-42/main.c b/src/exercise-42/main.c index e076d5f..2ccf21e 100644 --- a/src/exercise-42/main.c +++ b/src/exercise-42/main.c @@ -8,47 +8,56 @@ find_value (int *arr, int n, int target, int start_index) { int index = -1; // 默认为目标值未找到或起始索引超出数组范围 - // >>> 替换 PLACEHOLDER 为合适的指令完成注释的功能 __asm__ volatile ( // 检查起始索引是否超出数组范围 - "PLACEHOLDER\n\t" // 如果起始索引 start_index >= n,则跳转到 - // out_of_range 标签 - "blt %4, x0, out_of_range\n\t" // 如果起始索引 start_index < 0,则跳转到 - // out_of_range 标签 - // 用于循环计数的寄存器 - "li t0, 0\n\t" - "sub t3,%2,%4\n\t" - // 将 start_index 乘以 4(整数大小)保存到t2寄存器 - "PLACEHOLDER\n\t" - "add %1, %1, t2\n\t" // 将计算的偏移量添加到数组指针中 + "blt %4, x0, out_of_range\n\t" // 如果起始索引 start_index < 0,则跳转到 out_of_range 标签 + "bge %4, %2, out_of_range\n\t" // 如果起始索引 start_index >= n,则跳转到 out_of_range 标签 + + // 计算起始索引的偏移量(索引乘以 4,因为每个整数占用 4 字节) + "slli t2, %4, 2\n\t" // t2 = start_index * 4 + + // 将偏移量加到数组指针中,得到起始位置的指针 + "add %1, %1, t2\n\t" // arr = arr + start_index * 4 + + // 初始化循环计数器 t0 和循环结束条件 t3 + "li t0, 0\n\t" // t0 = 0 + "li t3, %2\n\t" // t3 = n + + // 循环开始标签 "loop:\n\t" - // 使用 load 指令将 arr[i] 加载到 t1 寄存器 - "lw t1, 0(%1)\n\t" - // 比较 arr[i] 和目标值 - "PLACEHOLDER\n\t" // 如果 arr[i] == target,则跳转到 found 标签 - "bne t0, t3, next\n\t" // 如果循环计数 t0 != n,则跳转到 next 标签 - "jal x0, out_of_range\n\t" // 否则跳转到 out_of_range 标签 - "found:\n\t" + // 加载 arr[t0] 到寄存器 t1 + "lw t1, 0(%1)\n\t" // t1 = *arr + + // 比较 t1 和目标值 target + "bne t1, %3, next\n\t" // 如果 t1 != target,则跳转到 next 标签 + // 如果找到目标值,保存索引并跳转到 end 标签 - "mv %0, t0\n\t" - "jal x0, end\n\t" + "mv %0, t0\n\t" // index = t0 + "jal x0, end\n\t" // 跳转到 end 标签 + + // 下一个元素标签 "next:\n\t" - // 指针增加 4,指向下一个元素 - "addi %1, %1, 4\n\t" - // 循环计数加 1 - "addi t0, t0, 1\n\t" + // 指针移动到下一个元素位置 + "addi %1, %1, 4\n\t" // arr++ + // 循环计数器加 1 + "addi t0, t0, 1\n\t" // t0++ + // 判断是否达到循环结束条件 - "blt t0, t3, loop\n\t" - "jal x0, out_of_range\n\t" + "blt t0, t3, loop\n\t" // 如果 t0 < t3,则跳转到 loop 标签 + "jal x0, out_of_range\n\t" // 否则跳转到 out_of_range 标签 + + // 超出范围标签 "out_of_range:\n\t" - // 如果起始索引超出数组范围,返回 -1 - "li %0, -1\n\t" + // 返回 -1 + "li %0, -1\n\t" // index = -1 + + // 结束标签 "end:\n\t" - : "=r"(index) - : "r"(arr), "r"(n), "r"(target), "r"(start_index) - : "t0", "t1", "t2", "t3"); + : "=r"(index) // 输出寄存器 + : "r"(arr), "r"(n), "r"(target), "r"(start_index) // 输入寄存器 + : "t0", "t1", "t2", "t3" // 破坏寄存器 + ); -#<<< return index; } -- Gitee From 2c27e21878e6522a0e69743a0ea00adcd4bf5040 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 13:15:07 +0000 Subject: [PATCH 19/22] Junyi Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-12/text_address.ld | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/exercise-12/text_address.ld b/src/exercise-12/text_address.ld index 2de92fc..65bb203 100644 --- a/src/exercise-12/text_address.ld +++ b/src/exercise-12/text_address.ld @@ -4,13 +4,14 @@ MEMORY { /* <<< */ } - SECTIONS { /* >>> 在这里指定 `.text` 的起始地址为 `0x1000` */ .text 0x1000 : { *(.text) - /* 其他段的定义 */ - } + *(.rodata) + *(.data) + *(.bss) + } > RAM /* <<< */ /* 定义只读数据段,包含常量数据 */ @@ -38,4 +39,4 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; -} \ No newline at end of file +} -- Gitee From 6ce5655820f0f7e33c7817e6d8354968440c3f8e Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Fri, 14 Jun 2024 14:22:54 +0000 Subject: [PATCH 20/22] test Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-12/text_address.ld | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/exercise-12/text_address.ld b/src/exercise-12/text_address.ld index 65bb203..4931949 100644 --- a/src/exercise-12/text_address.ld +++ b/src/exercise-12/text_address.ld @@ -4,14 +4,13 @@ MEMORY { /* <<< */ } + SECTIONS { /* >>> 在这里指定 `.text` 的起始地址为 `0x1000` */ - .text 0x1000 : { + .text 0x1000 : { *(.text) - *(.rodata) - *(.data) - *(.bss) - } > RAM + /* 其他段的定义 */ + } /* <<< */ /* 定义只读数据段,包含常量数据 */ @@ -39,4 +38,4 @@ SECTIONS { .eh_frame : { *(.eh_frame) } . = ALIGN(8); . = . + SIZEOF_HEADERS; -} +} \ No newline at end of file -- Gitee From 8f1407ca324276a42b3f0874bba5f73842631d42 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Sat, 15 Jun 2024 04:06:51 +0000 Subject: [PATCH 21/22] TEST Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-01/Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/exercise-01/Makefile b/src/exercise-01/Makefile index f739261..0e45c07 100644 --- a/src/exercise-01/Makefile +++ b/src/exercise-01/Makefile @@ -15,10 +15,11 @@ $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(TARGET): $(OBJS) - $(CC) $(LDFLAGS) -o $@ $^ + $(CC) $(LDFLAGS) -o $@ $(OBJS) + %.o: %.c - # 在这里指定 C 文件的编译命令 - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ + clean: rm -f $(TARGET) $(OBJS) -- Gitee From 4b56dd33cb252e79afbe85d07bf08e4aa9eadcb4 Mon Sep 17 00:00:00 2001 From: Ruby_Facetious_a005 <1621059562@qq.com> Date: Sat, 15 Jun 2024 04:07:58 +0000 Subject: [PATCH 22/22] test Signed-off-by: Ruby_Facetious_a005 <1621059562@qq.com> --- src/exercise-02/Makefile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/exercise-02/Makefile b/src/exercise-02/Makefile index cb2c62c..ad0b06e 100644 --- a/src/exercise-02/Makefile +++ b/src/exercise-02/Makefile @@ -19,16 +19,16 @@ $(OUTPUT_DIR): mkdir -p $(OUTPUT_DIR) $(TARGET): $(OBJS) - # 在这里指定 TARGET 的构建命令 - $(CC) $(LDFLAGS) -o $@ $^ + $(CC) $(LDFLAGS) -o $@ $(OBJS) + $(TEST_TARGET): $(TEST_OBJS) - # 在这里指定 TEST_TARGET 的构建命令 - $(CC) $(LDFLAGS) -o $@ $^ + $(CC) $(LDFLAGS) -o $@ $(TEST_OBJS) + %.o: %.c - # 在这里指定所有 C 文件的编译命令 - $(CC) $(CFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) -c $< -o $@ + test: $(TEST_TARGET) $(TEST_TARGET) clean: - rm -f $(TARGET) $(TEST_TARGET) $(OBJS) $(TEST_OBJS) + rm -f $(TARGET) $(TEST_TARGET) $(OBJS) $(TEST_OBJS) \ No newline at end of file -- Gitee