From 726500bd77e22abc92961dce6c0eff07eb2b86a6 Mon Sep 17 00:00:00 2001 From: Flower Black Date: Wed, 4 Dec 2024 11:07:55 +0800 Subject: [PATCH 1/4] Optimize .gitignore to get rid of annoying intermediate product commit reminders. --- Ubiquitous/XiZi_AIoT/.gitignore | 1 + Ubiquitous/XiZi_AIoT/services/app/.gitignore | 3 +++ Ubiquitous/XiZi_AIoT/services/tools/mkfs/.gitignore | 1 + 3 files changed, 5 insertions(+) create mode 100644 Ubiquitous/XiZi_AIoT/.gitignore create mode 100644 Ubiquitous/XiZi_AIoT/services/app/.gitignore create mode 100644 Ubiquitous/XiZi_AIoT/services/tools/mkfs/.gitignore diff --git a/Ubiquitous/XiZi_AIoT/.gitignore b/Ubiquitous/XiZi_AIoT/.gitignore new file mode 100644 index 000000000..c795b054e --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/app/.gitignore b/Ubiquitous/XiZi_AIoT/services/app/.gitignore new file mode 100644 index 000000000..46078f320 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/app/.gitignore @@ -0,0 +1,3 @@ +bin +fs.img +user.map \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/tools/mkfs/.gitignore b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/.gitignore new file mode 100644 index 000000000..3337b041d --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/tools/mkfs/.gitignore @@ -0,0 +1 @@ +mkfs \ No newline at end of file From 157c622d1fe95eac29c3320ee28e8ddc84e1d823 Mon Sep 17 00:00:00 2001 From: Flower Black Date: Wed, 4 Dec 2024 11:09:10 +0800 Subject: [PATCH 2/4] Run QEMU with default config with just one-click. --- Ubiquitous/XiZi_AIoT/Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Ubiquitous/XiZi_AIoT/Makefile b/Ubiquitous/XiZi_AIoT/Makefile index ddd3dab82..3697be3ed 100755 --- a/Ubiquitous/XiZi_AIoT/Makefile +++ b/Ubiquitous/XiZi_AIoT/Makefile @@ -140,3 +140,12 @@ distclean: @rm -f .config* @rm -f $(KERNEL_ROOT)/lib/musllib/libmusl.a @rm -f $(KERNEL_ROOT)/board/*/.config + + +# Run qemu with config discribed in README.md. +.PHONY: qemu-default +qemu-default: + qemu-system-arm -M sabrelite -m 1G -smp 4 -cpu cortex-a9 \ + -display none -serial null -serial stdio \ + -kernel ./build/XiZi-imx6q-sabrelite.elf + From 5f47b922559f4df3837a8d0b94a5a04b24ea8c72 Mon Sep 17 00:00:00 2001 From: Flower Black Date: Wed, 4 Dec 2024 11:16:36 +0800 Subject: [PATCH 3/4] Find order faster in KBuddyPagesAlloc when using GCC. --- Ubiquitous/XiZi_AIoT/softkernel/memory/buddy.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Ubiquitous/XiZi_AIoT/softkernel/memory/buddy.c b/Ubiquitous/XiZi_AIoT/softkernel/memory/buddy.c index 97817851a..ffebd5ea5 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/memory/buddy.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/memory/buddy.c @@ -77,8 +77,13 @@ static struct KPage* KBuddyPagesAlloc(struct KBuddy* pbuddy, int nPages) int i = 0, order = 0; // find order +#if defined(__GNUC__) + // see: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html + order = nPages ? (sizeof(int) * 8 - __builtin_clz(nPages) - 1) + !!(__builtin_popcount(nPages) != 1) : 0; +#else for (order = 0; (FREE_LIST_INDEX(order)) < nPages; order++) ; +#endif // find the free page list for (i = order; i < MAX_BUDDY_ORDER; i++) { From 3ef1f5570c5a992eaee6628c4fba062916349390 Mon Sep 17 00:00:00 2001 From: Flower Black Date: Wed, 4 Dec 2024 12:20:01 +0800 Subject: [PATCH 4/4] Repair the out-of-bounds error of the semaphore. --- .../services/semaphore/semaphore_server.c | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/semaphore/semaphore_server.c b/Ubiquitous/XiZi_AIoT/services/semaphore/semaphore_server.c index a835ff8e9..ad4d9978b 100644 --- a/Ubiquitous/XiZi_AIoT/services/semaphore/semaphore_server.c +++ b/Ubiquitous/XiZi_AIoT/services/semaphore/semaphore_server.c @@ -41,15 +41,28 @@ int IPC_DO_SERVE_FUNC(Ipc_sem_create)(sem_t* sem, int* count) return SEMAPHORE_SUC; } + +#define CHECK_SEM_RANGE(sem) \ + do { \ + if (*sem < 0 || *sem >= MAX_SUPPORT_SEMAPHORES) { \ + return SEMAPHORE_ERR; \ + } \ + } while (0) + + +#define CHECK_SEM_RANGE_AND_VALID(sem) \ + do { \ + CHECK_SEM_RANGE(sem); \ + \ + if (!sem_pool[*sem].valid) { \ + return SEMAPHORE_ERR; \ + } \ + } while (0) + + int IPC_DO_SERVE_FUNC(Ipc_sem_delete)(sem_t* sem) { - if (*sem < 0 || *sem > MAX_SUPPORT_SEMAPHORES) { - return SEMAPHORE_ERR; - } - - if (!sem_pool[*sem].valid) { - return SEMAPHORE_ERR; - } + CHECK_SEM_RANGE_AND_VALID(sem); sem_pool[*sem].valid = false; return SEMAPHORE_SUC; @@ -57,9 +70,7 @@ int IPC_DO_SERVE_FUNC(Ipc_sem_delete)(sem_t* sem) int IPC_DO_SERVE_FUNC(Ipc_sem_wait)(sem_t* sem, int* timeout) { - if (*sem < 0 || *sem > MAX_SUPPORT_SEMAPHORES) { - return SEMAPHORE_ERR; - } + CHECK_SEM_RANGE(sem); /// @todo support timeout // return if sem is freed(no valid) or sem count is sufficient @@ -72,13 +83,7 @@ int IPC_DO_SERVE_FUNC(Ipc_sem_wait)(sem_t* sem, int* timeout) int IPC_DO_SERVE_FUNC(Ipc_sem_signal)(sem_t* sem) { - if (*sem < 0 || *sem >= MAX_SUPPORT_SEMAPHORES) { - return SEMAPHORE_ERR; - } - - if (!sem_pool[*sem].valid) { - return SEMAPHORE_ERR; - } + CHECK_SEM_RANGE_AND_VALID(sem); sem_pool[*sem].count++; return SEMAPHORE_SUC;