📄 io.h
字号:
/***************************************************************************
** File name : io.h
** Author : x.cheng
** Create date :
**
** Comments:
** 定义了端口IO和寄存器IO...
**
** Revisions:
** $Log: io.h,v $
** Revision 1.2 2005/08/02 15:35:11 x.cheng
** 当使用宏ReadPortString从硬盘读数据时,
** 在中断处理中对地址指针的处理有很大的麻烦,及其诡异,不得以,换成了函数
** WritePortString也同理
**
** Revision 1.1.1.1 2005/07/27 06:53:15 x.cheng
** add into repositories
**
**
***************************************************************************/
#ifndef __JCINX_INC_IO_H__
#define __JCINX_INC_IO_H__
/* ports io */
#define ucInPort(_uiPort) ({ \
unsigned char ucResult; \
__asm__ __volatile__("inb %w1, %b0" : "=a"(ucResult) : "d"(_uiPort)); \
ucResult; \
})
#define vOutPort(_uiPort, _ucData) \
__asm__ __volatile__("outb %b0, %w1" : :"a"(_ucData), "d"(_uiPort));
/* 带延迟的硬件端口输出输入函数 */
/* 标号是数字 */
#define ucInPortDelay(_uiPort) ({ \
unsigned char ucResult; \
__asm__ __volatile__("inb %w1, %b0\n" \
"\tjmp 1f\n" \
"1:\tjmp 1f\n" \
"1:" : "=a" (ucResult) : "d" (_uiPort)); \
ucResult; \
})
#define vOutPortDelay(_uiPort, _ucData) \
__asm__ __volatile__("outb %b0, %w1\n" \
"\tjmp 1f\n" \
"1:\tjmp 1f\n" \
"1:" : : "a" (_ucData), "d"(_uiPort));
#ifdef __IDE_HD_SRC__
/*ReadPortString,WritePortString,主要是给硬盘用的*/
/*从端口读入一串数据*/
//note: 当我用下面这个宏的时候,内存地址的问题搞得我焦头烂额,没办法只能换函数,还不能
// 是inline函数,shit!
//#define ReadPortString(_uiPort,_pucBuffer,_uiBytes)
// __asm__ __volatile__("cld;rep;insw"::"d" (_uiPort),"D" (_pucBuffer),"c" (_uiBytes))
static void ReadPortString(unsigned short uiPort, unsigned char* pucBuffer, unsigned short uiLen)
{
__asm__ __volatile__("cld;rep;insw"::"d" (uiPort),"D" (pucBuffer),"c" (uiLen/2));
}
/*向端口写入一串数据*/
// 同理
//#define WritePortString(_uiPort,_pucBuffer,_uiBytes)
// __asm__ __volatile__("cld;rep;outsw"::"d" (_uiPort),"S" (_pucBuffer),"c" (_uiBytes))
static void WritePortString(unsigned short uiPort, unsigned char* pucBuffer, unsigned short uiLen)
{
// HexDump(pucBuffer, 12);
__asm__ __volatile__("cld;rep;outsw"::"d" (uiPort),"S" (pucBuffer),"c" (uiLen/2));
}
#endif
/*register io*/
#define _CS() ({ \
unsigned short uiResult; \
__asm__ __volatile__("mov %0, %%cs\n" "mov %1, %0\n" "shr %1, 8" \
: "a" : "=d"(uiResult)); \
uiResult; \
})
#define _DS() ({ \
unsigned short uiResult; \
__asm__ __volatile__("mov %0, %%ds\n" "mov %1, %0\n" "shr %1, 8" \
: "a" : "=d"(uiResult)); \
uiResult; \
})
#define _SS() ({ \
unsigned short uiResult; \
__asm__ __volatile__("mov %0, %%ss\n" "mov %1, %0\n" "shr %1, 8" \
: "a" : "=d"(uiResult)); \
uiResult; \
})
#define _FS() ({ \
unsigned short uiResult; \
__asm__ __volatile__("mov %%fs, %%ax" : "=a"(uiResult) : ); \
uiResult; \
})
#define dwReadCR0() ({ \
unsigned long dwResult; \
__asm__ __volatile__("mov %0, CR0" : "=a"(dwResult) : ); \
dwResult; \
})
//! \brief Clear task switch flag.
static inline void vClearTaskSwitchFlag() {
__asm__ __volatile__ ("clts");
}
//! \brief Set task switch flag.
static inline void vSetTaskSwitchFlag() {
unsigned int __cr0;
__asm__ __volatile__ (
"movl %%cr0, %0\n"
"or $8, %0\n"
"movl %0, %%cr0" : "=r"(__cr0));
}
/***************************************
*为了读cmos中存储的信息, 下面定义的是
*CMOS地址读函数
***************************************/
#define CMOS_Read(Addr) ({ \
vOutPortDelay(0x70, Addr); \
ucInPortDelay(0x71); \
})
/*
void vWriteCR0(DWORD dwValue);
void vLGDT (ts_GDTR *pstGDTR);
void vUpdateCS (WORD uiNewCS);
_vWriteCR0:
push bp
mov bp, sp
mov eax, [ss:bp+4] ; eax = 32-bit parameter
mov CR0, eax
pop bp
retn
_vLGDT:
push bp
mov bp, sp
push bx
mov bx, [ss:bp+4] ; ds:bx = pointer to GDTR struct
lgdt [ds:bx] ; load GDTR
pop bx
pop bp
retn
_vUpdateCS:
push bp
mov bp, sp
mov ax, [ss:bp+4] ; ax = new CS
push ax ; push segment
;-------------------------------------------
; error: COFF format does not support non-32-bit relocations
; push word .1 ; push offset
retf ; we have a new cs now
.1:
pop bp
retn
*/
#endif /* end of __JCINX_INC_IO_H__ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -