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/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 + 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/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; 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 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++) {