From: quzar <qu...@us...> - 2025-01-05 20:12:23
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 99b18e3a864c4f591f73dad893b10d0f4920de81 (commit) via 01a695b8afba0b44cc8e672ca693ea5285201d3e (commit) via 2e52944bb98e951a6f39a531e95c92ccbb2c1830 (commit) via 9809b9d5ff3a24777341d16570b70f8f868ddca8 (commit) via 19ce9ecad9136f36c1f3d170a0eedde22218eeb7 (commit) from c27605764db8ce5fa1a0dcb97042f581f6489483 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 99b18e3a864c4f591f73dad893b10d0f4920de81 Merge: c2760576 01a695b8 Author: Donald Haase <qu...@ya...> Date: Sun Jan 5 15:04:15 2025 -0500 Merge pull request #877 from pcercuei/fck-macros Convert some macros to inline functions and improve inline ASM commit 01a695b8afba0b44cc8e672ca693ea5285201d3e Author: Paul Cercueil <pa...@cr...> Date: Thu Jan 2 15:44:33 2025 +0100 arch.h: Simplify inline ASM The arch_get_ret_addr() used the weird "=&z" output modifier. The '&' means the register is an "early clobber", which makes no sense for a single-instruction ASM code. The 'z' means (AFAIK) that the destination register is r0, which we don't really need here. The output modifier can therefore be replaced by the much more normal "=r" token. Besides, given that the STS opcode called does not modify memory in any way, the "memory" clobber specifier can go. For arch_get_fptr(), there is no need for any inline ASM - we can just return the content of the r14 register. Signed-off-by: Paul Cercueil <pa...@cr...> commit 2e52944bb98e951a6f39a531e95c92ccbb2c1830 Author: Paul Cercueil <pa...@cr...> Date: Thu Jan 2 15:43:16 2025 +0100 arch.h: Transform macros into inline functions There is no valid reason to have the arch API has macros. Convert it to static inline functions to benefit from type checking. Signed-off-by: Paul Cercueil <pa...@cr...> commit 9809b9d5ff3a24777341d16570b70f8f868ddca8 Author: Paul Cercueil <pa...@cr...> Date: Sun Jan 5 17:10:51 2025 +0100 cache: Improve dcache_alloc_block() Instead of using the "memory" clobber, instruct the compiler that the 32 bytes located at the address passed as parameter have been written. The compiler then knows that anything read or written to that memory area prior to the dcache_alloc_block() call is dead code, and anything read or written outside this area is still valid after the call. The "volatile" specifier has been dropped as well, given that the compiler has now all the information it needs, and can freely reorganize the instructions as needed. Signed-off-by: Paul Cercueil <pa...@cr...> commit 19ce9ecad9136f36c1f3d170a0eedde22218eeb7 Author: Paul Cercueil <pa...@cr...> Date: Thu Jan 2 15:39:32 2025 +0100 cache: PREF instruction does not clobber memory From the compiler point of view, the PREF instruction does not modify the content of the memory; therefore the "memory" clobber is not useful here. The compiler then knows that it does not have to reload all the variables from memory after a call to dcache_pref_block(). Signed-off-by: Paul Cercueil <pa...@cr...> ----------------------------------------------------------------------- Summary of changes: kernel/arch/dreamcast/include/arch/arch.h | 55 +++++++++++++++++------------- kernel/arch/dreamcast/include/arch/cache.h | 24 ++++++++----- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/kernel/arch/dreamcast/include/arch/arch.h b/kernel/arch/dreamcast/include/arch/arch.h index e944762b..3bdc06c3 100644 --- a/kernel/arch/dreamcast/include/arch/arch.h +++ b/kernel/arch/dreamcast/include/arch/arch.h @@ -22,6 +22,8 @@ #include <kos/cdefs.h> __BEGIN_DECLS +#include <stdbool.h> + #include <arch/types.h> /** \defgroup arch Architecture @@ -352,12 +354,12 @@ const char *kos_get_license(void); */ const char *kos_get_authors(void); -/** \brief Dreamcast specific sleep mode "function". - \ingroup arch +/** \brief Dreamcast specific sleep mode function. + \ingroup arch */ -#define arch_sleep() do { \ - __asm__ __volatile__("sleep"); \ - } while(0) +static inline void arch_sleep(void) { + __asm__ __volatile__("sleep\n"); +} /** \brief DC specific "function" to get the return address from the current function. @@ -365,13 +367,13 @@ const char *kos_get_authors(void); \return The return address of the current function. */ -#define arch_get_ret_addr() ({ \ - uint32 pr; \ - __asm__ __volatile__("sts pr,%0\n" \ - : "=&z" (pr) \ - : /* no inputs */ \ - : "memory" ); \ - pr; }) +static inline uintptr_t arch_get_ret_addr(void) { + uintptr_t pr; + + __asm__ __volatile__("sts pr,%0\n" : "=r"(pr)); + + return pr; +} /* Please note that all of the following frame pointer macros are ONLY valid if you have compiled your code WITHOUT -fomit-frame-pointer. These @@ -384,13 +386,11 @@ const char *kos_get_authors(void); \return The frame pointer from the current function. \note This only works if you don't disable frame pointers. */ -#define arch_get_fptr() ({ \ - uint32 fp; \ - __asm__ __volatile__("mov r14,%0\n" \ - : "=&z" (fp) \ - : /* no inputs */ \ - : "memory" ); \ - fp; }) +static inline uintptr_t arch_get_fptr(void) { + register uintptr_t fp asm("r14"); + + return fp; +} /** \brief Pass in a frame pointer value to get the return address for the given frame. @@ -399,7 +399,9 @@ const char *kos_get_authors(void); \param fptr The frame pointer to look at. \return The return address of the pointer. */ -#define arch_fptr_ret_addr(fptr) (*((uint32*)(fptr))) +static inline uintptr_t arch_fptr_ret_addr(uintptr_t fptr) { + return *(uintptr_t *)fptr; +} /** \brief Pass in a frame pointer value to get the previous frame pointer for the given frame. @@ -408,7 +410,9 @@ const char *kos_get_authors(void); \param fptr The frame pointer to look at. \return The previous frame pointer. */ -#define arch_fptr_next(fptr) (*((uint32*)((fptr)+4))) +static inline uintptr_t arch_fptr_next(uintptr_t fptr) { + return arch_fptr_ret_addr(fptr + 4); +} /** \brief Returns true if the passed address is likely to be valid. Doesn't have to be exact, just a sort of general idea. @@ -417,7 +421,9 @@ const char *kos_get_authors(void); \return Whether the address is valid or not for normal memory access. */ -#define arch_valid_address(ptr) ((ptr_t)(ptr) >= 0x8c010000 && (ptr_t)(ptr) < _arch_mem_top) +static inline bool arch_valid_address(uintptr_t ptr) { + return ptr >= 0x8c010000 && ptr < _arch_mem_top; +} /** \brief Returns true if the passed address is in the text section of your program. @@ -426,8 +432,9 @@ const char *kos_get_authors(void); \return Whether the address is valid or not for text memory access. */ -#define arch_valid_text_address(ptr) \ - ((uintptr_t)(ptr) >= (uintptr_t)&_executable_start && (uintptr_t)(ptr) < (uintptr_t)&_etext) +static inline bool arch_valid_text_address(uintptr_t ptr) { + return ptr >= (uintptr_t)&_executable_start && ptr < (uintptr_t)&_etext; +} __END_DECLS diff --git a/kernel/arch/dreamcast/include/arch/cache.h b/kernel/arch/dreamcast/include/arch/cache.h index 2dca15cd..0581b27a 100644 --- a/kernel/arch/dreamcast/include/arch/cache.h +++ b/kernel/arch/dreamcast/include/arch/cache.h @@ -139,9 +139,9 @@ void dcache_purge_all_with_buffer(uintptr_t start, size_t count); */ static __always_inline void dcache_pref_block(const void *src) { __asm__ __volatile__("pref @%0\n" - : + : /* No outputs */ : "r" (src) - : "memory" + : /* No clobbers */ ); } @@ -157,14 +157,22 @@ static __always_inline void dcache_pref_block(const void *src) { This function allocate a block of the data/operand cache. - \param src The physical address to allocate. + \param src The address to allocate (32-byte aligned) \param value The value written to first 4-byte. */ -static __always_inline void dcache_alloc_block(const void *src, uint32_t value) { - __asm__ __volatile__ ("movca.l r0, @%0\n\t" - : - : "r" (src), "z" (value) - : "memory" +static __always_inline void dcache_alloc_block(void *src, uint32_t value) { + uint32_t *src32 = (uint32_t *)src; + + __asm__ ("movca.l r0, @%8\n\t" + : "=m"(src32[0]), + "=m"(src32[1]), + "=m"(src32[2]), + "=m"(src32[3]), + "=m"(src32[4]), + "=m"(src32[5]), + "=m"(src32[6]), + "=m"(src32[7]) + : "r" (src32), "z" (value) ); } hooks/post-receive -- A pseudo Operating System for the Dreamcast. |