Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a few changes : boot.h , bit.h ,crc32 #103

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions arch/x86/boot/boot.h
Original file line number Diff line number Diff line change
@@ -39,43 +39,54 @@ extern struct boot_params boot_params;

#define cpu_relax() asm volatile("rep; nop")


/*
* unsigned short-u16 port_t
* perhaps, be defined in linux/types.h
*/
typedef u16 port_t;
typedef u8 byte_t;
typedef u16 word_t;
typedef u32 dword_t;


/* Basic port I/O */
static inline void outb(u8 v, u16 port)
static inline void outb(byte_t value, port_t port)
{
asm volatile("outb %0,%1" : : "a" (v), "dN" (port));
asm volatile("outb %0,%1" : : "a" (value), "dN" (port));
}
static inline u8 inb(u16 port)
static inline byte_t inb(port_t port)
{
u8 v;
asm volatile("inb %1,%0" : "=a" (v) : "dN" (port));
return v;
byte_t ret_val;
asm volatile("inb %1,%0" : "=a" (ret_val) : "dN" (port));
return ret_val;
}

static inline void outw(u16 v, u16 port)
static inline void outw(word_t value, port_t port)
{
asm volatile("outw %0,%1" : : "a" (v), "dN" (port));
asm volatile("outw %0,%1" : : "a" (value), "dN" (port));
}
static inline u16 inw(u16 port)
static inline word_t inw(port_t port)
{
u16 v;
asm volatile("inw %1,%0" : "=a" (v) : "dN" (port));
return v;
word_t ret_val;
asm volatile("inw %1,%0" : "=a" (ret_val) : "dN" (port));
return ret_val;
}

static inline void outl(u32 v, u16 port)
static inline void outl(dword_t value, port_t port)
{
asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
asm volatile("outl %0,%1" : : "a" (value), "dN" (port));
}
static inline u32 inl(u16 port)
static inline dword_t inl(port_t port)
{
u32 v;
asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
return v;
dword ret_val;
asm volatile("inl %1,%0" : "=a" (ret_val) : "dN" (port));
return ret_val;
}

static inline void io_delay(void)
{
const u16 DELAY_PORT = 0x80;
const port_t DELAY_PORT = 0x80;
asm volatile("outb %%al,%0" : : "dN" (DELAY_PORT));
}

40 changes: 40 additions & 0 deletions include/linux/bit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*
* Copyright (C) 2014 Burak Köken - colcsky@gmail.com
*
* Get & set bit macro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/

#ifndef __LINUX_BIT_H__
#define __LINUX_BIT_H__

#include <linux/types.h>

/* get bit */
#define getbit8_high(x) x >> 4
#define getbit8_low(x) x & 0x0f

#define getbit16_high(x) x >> 8
#define getbit16_low(x) x & 0xff

#define getbit32_high(x) x >> 16
#define getbit32_low(x) x & 0xffff

#define getbit64_high(x) x >> 32
#define getbit64_low(x) x & 0xffffffff

/* set bit */
#define setbit8(high_4bit,low_4bit) ((u8) high_4bit << 4 | low_4bit)
#define setbit16(high_8bit,low_8bit) ((u16) high_8bit << 8 | low_8bit)
#define setbit32(high_16bit,low_16bit) ((u32) high_16bit << 16 | low_16bit)
#define setbit64(high_32bit,low_32bit) ((u64) high_32bit << 32 | low_32bit)



#endif /* __LINUX_BIT_H__ */
19 changes: 19 additions & 0 deletions include/linux/crc32.h
Original file line number Diff line number Diff line change
@@ -8,9 +8,28 @@
#include <linux/types.h>
#include <linux/bitrev.h>

#ifndef __CRC32DEFS
#define __CRC32DEFS
#define CRCBIG_ENDIAN (1)
#define CRCLITTLE_ENDIAN (0)

#define CRCPOLY32_BIGEND 0x04C11DB7 /* big endian poly. */
#define CRCPOLY32_LITEND 0xEDB88320 /* little endian poly.*/
#define CRC_TENTRY 256 /* crc32 table entries */
#endif

extern u32 crc32_le(u32 crc, unsigned char const *p, size_t len);
extern u32 crc32_be(u32 crc, unsigned char const *p, size_t len);

/*
* crc32 endian select
*
* endian type : CRCBIG_ENDIAN , CRCLITTLE_ENDIAN
*
*/
extern u32 crc32_sel(u32 crc,unsigned char const *p,size_t len,u8 endian_type);


/**
* crc32_le_combine - Combine two crc32 check values into one. For two
* sequences of bytes, seq1 and seq2 with lengths len1
14 changes: 14 additions & 0 deletions lib/crc32.c
Original file line number Diff line number Diff line change
@@ -155,6 +155,20 @@ crc32_body(u32 crc, unsigned char const *buf, size_t len, const u32 (*tab)[256])
}
#endif

/*
* crc32 select endian
*
*/

u32 crc32_sel(u32 crc,unsigned char const *p,size_t len,u8 endian_type){

/*
* (endian_type) ? big endian : little endian
*/
return (endian_type) ? crc32_be(crc,p,len) : crc_le(crc,p,len);

}

/* For conditions of distribution and use, see copyright notice in zlib.h */
static u32 crc32_generic_combine(u32 crc1, u32 crc2, size_t len2,
u32 polynomial)