From: Lawrence S. <ljs...@us...> - 2015-12-24 03:47:35
|
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 4fafabbed82481771967c8439d2220c0a67793df (commit) from 3b548217d8a33be76d01c86621bc7b32da923930 (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 4fafabbed82481771967c8439d2220c0a67793df Author: Lawrence Sebald <ljs...@us...> Date: Wed Dec 23 22:47:16 2015 -0500 Add <arch/byteorder.h>. ----------------------------------------------------------------------- Summary of changes: include/kos.h | 1 + kernel/arch/dreamcast/include/arch/byteorder.h | 118 ++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 0 deletions(-) create mode 100644 kernel/arch/dreamcast/include/arch/byteorder.h diff --git a/include/kos.h b/include/kos.h index 4129df3..55c7b1c 100644 --- a/include/kos.h +++ b/include/kos.h @@ -64,6 +64,7 @@ __BEGIN_DECLS #include <arch/types.h> #include <arch/exec.h> #include <arch/stack.h> +#include <arch/byteorder.h> #ifdef _arch_dreamcast # include <arch/gdb.h> diff --git a/kernel/arch/dreamcast/include/arch/byteorder.h b/kernel/arch/dreamcast/include/arch/byteorder.h new file mode 100644 index 0000000..9b5ffea --- /dev/null +++ b/kernel/arch/dreamcast/include/arch/byteorder.h @@ -0,0 +1,118 @@ +/* KallistiOS ##version## + + arch/dreamcast/include/arch/byteorder.h + Copyright (C) 2015 Lawrence Sebald + +*/ + +/** \file arch/byteorder.h + \brief Byte-order related macros. + + This file contains architecture-specific byte-order related macros and/or + functions. Each platform should define six macros/functions in this file: + arch_swap16, arch_swap32, arch_ntohs, arch_ntohl, arch_htons, and + arch_htonl. The first two of these swap the byte order of 16-bit and 32-bit + integers, respectively. The other four macros will be used by the kernel to + implement the network-related byte order functions. + + \author Lawrence Sebald +*/ + +#ifndef __ARCH_BYTEORDER_H +#define __ARCH_BYTEORDER_H + +#include <sys/cdefs.h> +__BEGIN_DECLS + +#include <sys/_types.h> + +/** \brief Define the byte-order of the platform in use. */ +#define BYTE_ORDER LITTLE_ENDIAN + +/** \brief Swap the byte order of a 16-bit integer. + + This macro swaps the byte order of a 16-bit integer in an architecture- + defined manner. + + \param x The value to be byte-swapped. This should be a uint16, + or equivalent. + \return The swapped value. +*/ +#define arch_swap16(x) ({ \ + uint16 __x = (x); \ + __asm__ __volatile__("swap.b %0, %0" : "=r" (__x) : "0" (__x)); \ + __x; \ +}) + +/** \brief Swap the byte order of a 32-bit integer. + + This macro swaps the byte order of a 32-bit integer in an architecture- + defined manner. + + \param x The value to be byte-swapped. This should be a uint32, + or equivalent. + \return The swapped value. +*/ +#define arch_swap32(x) ({ \ + uint32 __x = (x); \ + __asm__ __volatile__("swap.b %0, %0\n\t" \ + "swap.w %0, %0\n\t" \ + "swap.b %0, %0\n\t" : "=r"(__x) : "0" (__x)); \ + __x; \ +}) + +/** \brief Convert network-to-host short. + + This macro converts a network byte order (big endian) value to the host's + native byte order. On a little endian system (like the Dreamcast), this + should just call arch_swap16(). On a big endian system, this should be a + no-op. + + \param x The value to be converted. This should be a uint16, + or equivalent. + \return The converted value. +*/ +#define arch_ntohs(x) arch_swap16(x) + +/** \brief Convert network-to-host long. + + This macro converts a network byte order (big endian) value to the host's + native byte order. On a little endian system (like the Dreamcast), this + should just call arch_swap32(). On a big endian system, this should be a + no-op. + + \param x The value to be converted. This should be a uint32, + or equivalent. + \return The converted value. +*/ +#define arch_ntohl(x) arch_swap32(x) + +/** \brief Convert host-to-network short. + + This macro converts a value in the host's native byte order to network byte + order (big endian). On a little endian system (like the Dreamcast), this + should just call arch_swap16(). On a big endian system, this should be a + no-op. + + \param x The value to be converted. This should be a uint16, + or equivalent. + \return The converted value. +*/ +#define arch_htons(x) arch_swap16(x) + +/** \brief Convert host-to-network long. + + This macro converts a value in the host's native byte order to network byte + order (big endian). On a little endian system (like the Dreamcast), this + should just call arch_swap32(). On a big endian system, this should be a + no-op. + + \param x The value to be converted. This should be a uint32, + or equivalent. + \return The converted value. +*/ +#define arch_htonl(x) arch_swap32(x) + +__END_DECLS + +#endif /* !__ARCH_BYTEORDER_H */ hooks/post-receive -- A pseudo Operating System for the Dreamcast. |