OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sim/] [verilator/] [byteswap.h] - Blame information for rev 204

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 204 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    byteswap.h
4
//
5
// Project:     Zip CPU -- a small, lightweight, RISC CPU soft core
6
//
7
// Purpose:     To convert between little endian and big endian byte orders,
8
//              and to handle conversions between character strings and
9
//      bit-endian words made from those characters.
10
//
11
//
12
// Creator:     Dan Gisselquist, Ph.D.
13
//              Gisselquist Technology, LLC
14
//
15
////////////////////////////////////////////////////////////////////////////////
16
//
17
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
18
//
19
// This program is free software (firmware): you can redistribute it and/or
20
// modify it under the terms of  the GNU General Public License as published
21
// by the Free Software Foundation, either version 3 of the License, or (at
22
// your option) any later version.
23
//
24
// This program is distributed in the hope that it will be useful, but WITHOUT
25
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
26
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
// for more details.
28
//
29
// You should have received a copy of the GNU General Public License along
30
// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
31
// target there if the PDF file isn't present.)  If not, see
32
// <http://www.gnu.org/licenses/> for a copy.
33
//
34
// License:     GPL, v3, as defined and found on www.gnu.org,
35
//              http://www.gnu.org/licenses/gpl.html
36
//
37
//
38
////////////////////////////////////////////////////////////////////////////////
39
//
40
//
41
#ifndef BYTESWAP_H
42
#define BYTESWAP_H
43
 
44
#include <stdint.h>
45
 
46
/*
47
 * The byte swapping routines below are designed to support conversions from a little endian
48
 * machine/host (such as my PC) to the big endian byte order used on the ZipCPU.  If the current
49
 * machine is already little endian, no byte swapping is required.
50
 */
51
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
52
/*
53
 * byteswap
54
 *
55
 * Given a big (or little) endian word, return a little (or big) endian word.
56
 */
57
extern  uint32_t
58
byteswap(uint32_t v);
59
 
60
/*
61
 * byteswapbuf
62
 *
63
 * To swap from the byte order of every 32-bit word in the given buffer.
64
 */
65
extern  void    byteswapbuf(int ln, uint32_t *buf);
66
 
67
#else
68
#define byteswap(A)              (A)
69
#define byteswapbuf(A, B)
70
#endif
71
 
72
/*
73
 * buildword
74
 *
75
 * Given a pointer within an array of characters, build a 32-bit big-endian
76
 * word from those characters.  Does not require the character pointer to be
77
 * aligned.
78
 */
79
extern  uint32_t buildword(const unsigned char *p);
80
 
81
/*
82
 * buildswap
83
 *
84
 * Same as buildword, except that we build a little endian word from the
85
 * characters given to us.  Hence the first character is the low order octet
86
 * of the word.
87
 */
88
extern  uint32_t buildswap(const unsigned char *p);
89
 
90
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.