Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

Generic (IA-32) Routines
[Kernel]


Data Structures

struct  atomic
 The atomic variable structure. More...


Defines

#define rdtsc(low, high)   __asm__ __volatile__( "rdtsc" : "=a"(low), "=d"(high) )
 Read the timestamp counter from the model-specific register and put it into two 32-bit registers.

#define rdtscll(val)   __asm__ __volatile__( "rdtsc" : "=A"(val) )
 Read the timestamp counter from the model-specific register and put it into eax:edx registers. This is a 64-bit value.

#define wmb()   mb()
 A macro equivalent to the function mb().

#define get_eip()   ({ void *eip; __asm__("movl $1f,%0\n1:" : "=g" (eip)); eip; })
 A macro that returns current instruction pointer.

#define in   inportb
 A macro equivalent to the inportb(word port) function.

#define in16   inportw
 A macro equivalent to the inportw(word port) function.

#define in32   inportl
 A macro equivalent to the inportl(word port) function.

#define out   outportb
 A macro equivalent to the outportb(word port, byte val) function.

#define out16   outportw
 A macro equivalent to the outportw(word port, word val) function.

#define out32   outportl
 A macro equivalent to the outportl(word port, dword val) function.

#define inportbm   insb
 A macro equivalent to the insb(unsigned short port, void * addr, unsigned long count) function.

#define inportwm   insw
 A macro equivalent to the insw(unsigned short port, void * addr, unsigned long count) function.

#define inportlm   insl
 A macro equivalent to the insl(unsigned short port, void * addr, unsigned long count) function.

#define outportbm   outsb
 A macro equivalent to the outsb(unsigned short port, void * addr, unsigned long count) function.

#define outportwm   outsw
 A macro equivalent to the outsw(unsigned short port, void * addr, unsigned long count) function.

#define outportlm   outsl
 A macro equivalent to the outsl(unsigned short port, void * addr, unsigned long count) function.

#define atomic_set(v, i)   (((v)->counter) = (i))
 Set the atomic value of v to i (guaranteed only 24 bits)
Parameters:
v  The atomic variable.
i  The value to assign.


#define atomic_read(v)   ((v)->counter)
 Read the atomic value of v (guaranteed only 24 bits)
Parameters:
v  The atomic variable.



Typedefs

typedef atomic atomic_t
 The atomic variable structure.


Functions

__inline__ void mb ()
 Force strict CPU ordering (required for all out-of-order Intel CPUs to preserve the order of execution).

__inline__ void enable ()
 Enable all interrupts.

__inline__ void disable ()
 Disable all interrupts.

__inline__ dword GET_IF ()
 Get the IF (interrupt enable flag) value from the EFLAGS register.
Returns:
The interrupt enable flag (IF).


__inline__ void SET_IF (dword IF)
 Set the IF (interrupt enable flag) value into the EFLAGS register.
Parameters:
IF  The interrupt flag:
  • 1 = ON
  • 0 = OFF.


__inline__ byte inportb (word port)
 Get a byte from an I/O port.
Parameters:
port  The I/O port.
Returns:
The value of the byte.


__inline__ word inportw (word port)
 Get a word from an I/O port.
Parameters:
port  The I/O port.
Returns:
The value of the word.


__inline__ dword inportl (word port)
 Get a dword from an I/O port.
Parameters:
port  The I/O port.
Returns:
The value of the double word.


__inline__ void outportb (word port, byte val)
 Put a byte to an I/O port.
Parameters:
port  The I/O port.
val  The value you want to put.


__inline__ void outportw (word port, word val)
 Put a word to an I/O port.
Parameters:
port  The I/O port.
val  The value you want to put.


__inline__ void outportl (word port, dword val)
 Put a dword to an I/O port.
Parameters:
port  The I/O port.
val  The value you want to put.


void insb (unsigned short port, void *addr, unsigned long count)
 The string version of in().
Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many bytes we want to read from the port.


void insw (unsigned short port, void *addr, unsigned long count)
 The string version of in16().
Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many words we want to read from the port.


void insl (unsigned short port, void *addr, unsigned long count)
 The string version of in32().
Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many double words we want to read from the port.


void outsb (unsigned short port, void *addr, unsigned long count)
 The string version of out().
Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many bytes we want to write to the port.


void outsw (unsigned short port, void *addr, unsigned long count)
 The string version of out16().
Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many words we want to write to the port.


void outsl (unsigned short port, void *addr, unsigned long count)
 The string version of out32().
Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many double words we want to write to the port.


__inline__ void cpuid (int op, int *eax, int *ebx, int *ecx, int *edx)
 Get the CPUID information.
Parameters:
op  The operation code to perform.
eax  EAX register value after the CPUID execution.
ebx  EBX register value after the CPUID execution.
ecx  ECX register value after the CPUID execution.
edx  EDX register value after the CPUID execution.
Warning:
Not all the Intel CPUs support the CPUID instruction!!! Only some Intel486 family and subsequent Intel processors provide this method for determinig the architecture flags. Execution of CPUID on a processor that does not support this instruction will result in an invalid opcode exception.

To determine if it is possible to use this instruction we can use bit 21 of the EFLAGS register. If software can change the value of this flag, the CPUID instruction is executable.


__inline__ void atomic_inc (atomic_t *v)
 Perform an atomic increment.
Parameters:
v  The atomic value to increment.
Warning:
Guaranteed only 24 bits.


__inline__ void atomic_dec (atomic_t *v)
 Perform an atomic decrement.
Parameters:
v  The atomic value to decrement.
Warning:
Guaranteed only 24 bits.


__inline__ void halt ()
 Halt the system by disabling the CPU.
Warning:
This is truly the end. You have to reboot the system after this...


__inline__ void breakpoint ()
 Perform a breakpoint exeception.


Detailed Description

Some useful asm routines for the IA-32 architecture.

Define Documentation

#define atomic_read      ((v)->counter)
 

Read the atomic value of v (guaranteed only 24 bits)

Parameters:
v  The atomic variable.

Definition at line 326 of file i386.h.

#define atomic_set v,
i       (((v)->counter) = (i))
 

Set the atomic value of v to i (guaranteed only 24 bits)

Parameters:
v  The atomic variable.
i  The value to assign.

Definition at line 323 of file i386.h.

 
#define get_eip      ({ void *eip; __asm__("movl $1f,%0\n1:" : "=g" (eip)); eip; })
 

A macro that returns current instruction pointer.

Definition at line 49 of file i386.h.

#define in   inportb
 

A macro equivalent to the inportb(word port) function.

Definition at line 100 of file i386.h.

#define in16   inportw
 

A macro equivalent to the inportw(word port) function.

Definition at line 102 of file i386.h.

#define in32   inportl
 

A macro equivalent to the inportl(word port) function.

Definition at line 104 of file i386.h.

#define inportbm   insb
 

A macro equivalent to the insb(unsigned short port, void * addr, unsigned long count) function.

Definition at line 219 of file i386.h.

#define inportlm   insl
 

A macro equivalent to the insl(unsigned short port, void * addr, unsigned long count) function.

Definition at line 225 of file i386.h.

#define inportwm   insw
 

A macro equivalent to the insw(unsigned short port, void * addr, unsigned long count) function.

Definition at line 222 of file i386.h.

#define out   outportb
 

A macro equivalent to the outportb(word port, byte val) function.

Definition at line 143 of file i386.h.

#define out16   outportw
 

A macro equivalent to the outportw(word port, word val) function.

Definition at line 145 of file i386.h.

#define out32   outportl
 

A macro equivalent to the outportl(word port, dword val) function.

Definition at line 147 of file i386.h.

#define outportbm   outsb
 

A macro equivalent to the outsb(unsigned short port, void * addr, unsigned long count) function.

Definition at line 270 of file i386.h.

#define outportlm   outsl
 

A macro equivalent to the outsl(unsigned short port, void * addr, unsigned long count) function.

Definition at line 276 of file i386.h.

#define outportwm   outsw
 

A macro equivalent to the outsw(unsigned short port, void * addr, unsigned long count) function.

Definition at line 273 of file i386.h.

#define rdtsc low,
high       __asm__ __volatile__( "rdtsc" : "=a"(low), "=d"(high) )
 

Read the timestamp counter from the model-specific register and put it into two 32-bit registers.

Definition at line 26 of file i386.h.

#define rdtscll val       __asm__ __volatile__( "rdtsc" : "=A"(val) )
 

Read the timestamp counter from the model-specific register and put it into eax:edx registers. This is a 64-bit value.

Definition at line 32 of file i386.h.

 
#define wmb      mb()
 

A macro equivalent to the function mb().

Definition at line 45 of file i386.h.


Typedef Documentation

typedef struct atomic atomic_t
 

The atomic variable structure.


Function Documentation

__inline__ void atomic_dec atomic_t   v [static]
 

Perform an atomic decrement.

Parameters:
v  The atomic value to decrement.
Warning:
Guaranteed only 24 bits.

Definition at line 340 of file i386.h.

00341 {
00342         __asm__ __volatile__ (  "lock; decl %0"
00343                                 : "=m"(v->counter) : "m"(v->counter));
00344 }

__inline__ void atomic_inc atomic_t   v [static]
 

Perform an atomic increment.

Parameters:
v  The atomic value to increment.
Warning:
Guaranteed only 24 bits.

Definition at line 331 of file i386.h.

00332 {
00333         __asm__ __volatile__ (  "lock; incl %0"
00334                                 : "=m"(v->counter) : "m"(v->counter));
00335 }

__inline__ void breakpoint   [static]
 

Perform a breakpoint exeception.

Definition at line 358 of file i386.h.

00359 {
00360         __asm__ __volatile__ ("int3" : : : "memory");
00361 }

__inline__ void cpuid int    op,
int *    eax,
int *    ebx,
int *    ecx,
int *    edx
[static]
 

Get the CPUID information.

Parameters:
op  The operation code to perform.
eax  EAX register value after the CPUID execution.
ebx  EBX register value after the CPUID execution.
ecx  ECX register value after the CPUID execution.
edx  EDX register value after the CPUID execution.
Warning:
Not all the Intel CPUs support the CPUID instruction!!! Only some Intel486 family and subsequent Intel processors provide this method for determinig the architecture flags. Execution of CPUID on a processor that does not support this instruction will result in an invalid opcode exception.

To determine if it is possible to use this instruction we can use bit 21 of the EFLAGS register. If software can change the value of this flag, the CPUID instruction is executable.

Definition at line 297 of file i386.h.

00298 {
00299         __asm__ __volatile__(
00300                 "cpuid"
00301                 :
00302                 "=a" (*eax),
00303                 "=b" (*ebx),
00304                 "=c" (*ecx),
00305                 "=d" (*edx)
00306                 :
00307                 "0" (op)
00308         );
00309         __asm__ __volatile__ ("" : : : "eax", "ebx", "ecx", "edx");
00310 }

__inline__ void disable   [static]
 

Disable all interrupts.

Definition at line 60 of file i386.h.

00061 {
00062         __asm__ __volatile__ ("cli" : : : "memory");
00063 }

__inline__ void enable   [static]
 

Enable all interrupts.

Definition at line 53 of file i386.h.

00054 {
00055         __asm__ ("sti" : : : "memory");
00056 }

__inline__ dword GET_IF   [static]
 

Get the IF (interrupt enable flag) value from the EFLAGS register.

Returns:
The interrupt enable flag (IF).

Definition at line 68 of file i386.h.

00069 {
00070         register uint32_t IF;
00071         __asm__ __volatile__ (
00072                 "pushfl                 \n"
00073                 "popl   %%eax           \n"
00074                 "shrl   $9, %%eax       \n"
00075                 "andl   $1, %%eax       \n" : "=a" (IF) : );
00076         __asm__ __volatile__("" : : : "eax");
00077         return( IF );
00078 }

__inline__ void halt   [static]
 

Halt the system by disabling the CPU.

Warning:
This is truly the end. You have to reboot the system after this...

Definition at line 350 of file i386.h.

00351 {
00352         __asm__ __volatile__ ("cli\n hlt");
00353 }

__inline__ byte inportb word    port [static]
 

Get a byte from an I/O port.

Parameters:
port  The I/O port.
Returns:
The value of the byte.

Definition at line 110 of file i386.h.

00111 {
00112         // Get a byte from I/O port                                             //
00113         register uint8_t val;
00114         __asm__ __volatile__ ("inb %%dx, %%al" : "=a" (val) : "d" (port));
00115         return( val );
00116 }

__inline__ dword inportl word    port [static]
 

Get a dword from an I/O port.

Parameters:
port  The I/O port.
Returns:
The value of the double word.

Definition at line 133 of file i386.h.

00134 {
00135         register uint32_t val;
00136         __asm__ __volatile__ ("inl %%dx, %%eax" : "=a" (val) : "d" (port));
00137         return( val );
00138 }

__inline__ word inportw word    port [static]
 

Get a word from an I/O port.

Parameters:
port  The I/O port.
Returns:
The value of the word.

Definition at line 122 of file i386.h.

00123 {
00124         register uint16_t val;
00125         __asm__ __volatile__ ("inw %%dx, %%ax" : "=a" (val) : "d" (port));
00126         return( val );
00127 }

void insb unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of in().

Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many bytes we want to read from the port.

Copy a sequence of count bytes to the buffer addr from the port port.

Definition at line 186 of file i386.h.

00187 {
00188         __asm__ __volatile__ ("rep ; insb": "=D"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00189 }

void insl unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of in32().

Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many double words we want to read from the port.

Copy a sequence of count double words to the buffer addr from the port port.

Definition at line 212 of file i386.h.

00213 {
00214         __asm__ __volatile__ ("rep ; insl": "=D"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00215 }

void insw unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of in16().

Parameters:
port  The I/O port.
addr  A memory buffer where the values will be copied.
count  How many words we want to read from the port.

Copy a sequence of count words to the buffer addr from the port port.

Definition at line 199 of file i386.h.

00200 {
00201         __asm__ __volatile__ ("rep ; insw": "=D"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00202 }

__inline__ void mb   [static]
 

Force strict CPU ordering (required for all out-of-order Intel CPUs to preserve the order of execution).

Definition at line 38 of file i386.h.

00039 {
00040         __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory");
00041 }

__inline__ void outportb word    port,
byte    val
[static]
 

Put a byte to an I/O port.

Parameters:
port  The I/O port.
val  The value you want to put.

Definition at line 153 of file i386.h.

00154 {
00155         __asm__ __volatile__ ("outb %%al, %%dx" : : "d" (port), "a" (val));
00156 }

__inline__ void outportl word    port,
dword    val
[static]
 

Put a dword to an I/O port.

Parameters:
port  The I/O port.
val  The value you want to put.

Definition at line 171 of file i386.h.

00172 {
00173         __asm__ __volatile__ ("outl %%eax, %%dx" : : "d" (port), "a" (val));
00174 }

__inline__ void outportw word    port,
word    val
[static]
 

Put a word to an I/O port.

Parameters:
port  The I/O port.
val  The value you want to put.

Definition at line 162 of file i386.h.

00163 {
00164         __asm__ __volatile__ ("outw %%ax, %%dx" : : "d" (port), "a" (val));
00165 }

void outsb unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of out().

Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many bytes we want to write to the port.

Copy a sequence of count bytes to the port port from the buffer addr.

Definition at line 237 of file i386.h.

00238 {
00239         __asm__ __volatile__ ("rep ; outsb": "=S"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00240 }

void outsl unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of out32().

Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many double words we want to write to the port.

Copy a sequence of count double words to the port port from the buffer addr.

Definition at line 263 of file i386.h.

00264 {
00265         __asm__ __volatile__ ("rep ; outsl": "=S"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00266 }

void outsw unsigned short    port,
void *    addr,
unsigned long    count
[inline, static]
 

The string version of out16().

Parameters:
port  The I/O port.
addr  A memory buffer that contains the values to be copied.
count  How many words we want to write to the port.

Copy a sequence of count words to the port port from the buffer addr.

Definition at line 250 of file i386.h.

00251 {
00252         __asm__ __volatile__ ("rep ; outsw": "=S"(addr), "=c"(count) : "d"(port), "0"(addr), "1"(count));
00253 }

__inline__ void SET_IF dword    IF [static]
 

Set the IF (interrupt enable flag) value into the EFLAGS register.

Parameters:
IF  The interrupt flag:
  • 1 = ON
  • 0 = OFF.

Definition at line 85 of file i386.h.

00086 {
00087         __asm__ __volatile__ (
00088                 "pushfl                 \n"
00089                 "popl   %%eax           \n"
00090                 "orl    $(1 << 9), %%eax\n"
00091                 "andl   %0, %%eax       \n"
00092                 "pushl  %%eax           \n"
00093                 "popfl                  \n" : : "d" ((IF & 0x01) << 9) );
00094         __asm__ __volatile__("" : : : "eax", "edx");
00095 }


Generated on Fri Feb 20 15:32:21 2004 for Minirighi by doxygen1.2.18