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

mem.h File Reference

Low level (i386) memory manager header. More...

#include <kernel/kernel_map.h>

Go to the source code of this file.

Data Structures

struct  gdt_entry
 GDT structure. More...

struct  gdt_register
 The GDT register format. More...


Defines

#define GDT_DIM   8192
 Number of entries in the GDT (Global Descriptor Table).

#define GDT_ENTRY_DIM   sizeof(gdt_entry_t)
 GDT entry dimension in bytes.

#define PRESENT   0x80
 The segment is present.

#define CODE   0x18
 A code segment type.

#define DATA   0x10
 A data segment type.

#define EXP_DOWN   0x04
 The segment grows downward.

#define CONFORMING   0x04
 A conforming code segment.

#define READABLE   0x02
 A readable segment.

#define WRITEABLE   0x02
 A writeable segment.

#define CODE_SEG   (CODE | PRESENT | READABLE)
 A standard code segment.

#define DATA_SEG   (DATA | PRESENT | WRITEABLE)
 A standard data segment.

#define STACK_SEG   DATA_SEG
 A standard stack segment.

#define TSS_SEG   (PRESENT | 0x09)
 A standard TSS segment.

#define REAL_SEG   (CODE | PRESENT | READABLE)
 A real-mode area segment.

#define INT_GATE   (PRESENT | 0x0E)
 32-bit Interrupt Gate.

#define TASK_GATE   (PRESENT | 0x05)
 Task Gate.

#define TRAP_GATE   (PRESENT | 0x0F)
 32-bit Trap Gate.

#define DPL_0   0x00
 Descriptor Privilege Level 0 (maximum privilege).

#define DPL_1   0x20
 Descriptor Privilege Level 1.

#define DPL_2   0x40
 Descriptor Privilege Level 2.

#define DPL_3   0x60
 Descriptor Privilege Level 3 (minimum privilege).

#define BUSY_FLAG   0x02
 The busy bit of the TSS descriptor (to avoid recursive tasks).

#define ATTR_32BIT   0x40
 Default size of the istructions (for a code segment) or the stack alignment (for a stack segment).

#define ATTR_GRANUL   0x80
 The granularity of the segment size (limit field):
  • 0 => byte granularity;
  • 1 => page granularity (4096 bytes).


#define KERNEL_DATA   0x08
 This is the data selector for the kernel. REMEBER!!! It is defined also into irq.S!

#define KERNEL_STACK   0x08
 This is the stack selector for the kernel.

#define KERNEL_CODE   0x10
 This is the code selector for the kernel.

#define USER_DATA   0x18
 This is the selector for the user data segment.

#define USER_STACK   0x18
 This is the selector for the user stack segment.

#define USER_CODE   0x20
 This is the selector for the user code segment.

#define SEGMENT(linear)   ( (word)(((dword)(linear) & 0xFFFF0000) >> 4) )
 (real-mode) Extract the segment part of a linear address.

#define OFFSET(linear)   ( (word)((dword)(linear) & 0xFFFF) )
 (real-mode) Extract the offset part of a linear address.

#define LINEAR(seg, off)   ( (dword)(((word)(seg) << 4) + (word)(off)) )
 (real-mode) Make a linear address from a segment:offset address.

#define MK_FP(seg, off)   ((FARPTR) (((uint32_t) (seg) << 16) | (uint16_t) (off)))
 (i386) Make a far pointer from seg segment and off offset.
Note:
In this case a segment is considered as 65536(0x10000) bytes.


#define FP_SEG(fp)   (((FARPTR) fp) >> 16)
 (i386) Get the segment from the far pointer fp.

#define FP_OFF(fp)   (((FARPTR) fp) & 0xffff)
 (i386) Get the offset from the far pointer fp.

#define FP_TO_LINEAR(seg, off)   ((void*) ((((uint16_t) (seg)) << 4) + ((uint16_t) (off))))
 Translate a real-mode segment:offset address to the linear address. This macro is equivalent to LINEAR(seg, off) macro.


Typedefs

typedef uint32_t FARPTR
 (i386) far pointer.

typedef uint32_t far
 (i386) far pointer.

typedef gdt_entry gdt_entry_t
 GDT structure.

typedef gdt_register gdt_reg
 The GDT register format.


Functions

__inline__ void memsetb (void *dest_ptr, int val, dword count)
 Sets count bytes to val.
Parameters:
dest_ptr  The destination pointer.
val  The value to set.
count  How many bytes to set.


__inline__ void memsetw (void *dest_ptr, word val, dword count)
 Sets count words to val.
Parameters:
dest_ptr  The destination pointer.
val  The value to set.
count  How many words to set.


__inline__ void memsetl (void *dest_ptr, dword val, dword count)
 Sets count double words to val.
Parameters:
dest_ptr  The destination pointer.
val  The value to set.
count  How many double words to set.


__inline__ void * memset (void *s, unsigned long c, size_t count)
 Optimized version of memset.
Parameters:
s  The destination pointer.
c  The value to set.
count  How many bytes to set.
Returns:
The destination pointer.


__inline__ void memcpyb (void *dest_ptr, const void *org_ptr, dword count)
 Copy count bytes from org_ptr to dest_ptr.
Parameters:
dest_ptr  The destination pointer.
org_ptr  The source pointer.
count  How many bytes to copy.


__inline__ void memcpyw (void *dest_ptr, const void *org_ptr, dword count)
 Copy count words from org_ptr to dest_ptr.
Parameters:
dest_ptr  The destination pointer.
org_ptr  The source pointer.
count  How many words to copy.


__inline__ void memcpyl (void *dest_ptr, const void *org_ptr, dword count)
 Copy count double words from org_ptr to dest_ptr.
Parameters:
dest_ptr  The destination pointer.
org_ptr  The source pointer.
count  How many double words to copy.


__inline__ void * memcpy (void *to, const void *from, size_t n)
 Optimized version of memcpy.
Parameters:
to  The destination pointer.
from  The source pointer.
n  How many bytes to copy.
Returns:
The destination pointer.


__inline__ int memcmp (const void *s1, const void *s2, size_t n)
 Compares the first n bytes of memory areas s1 and s2. It returns an integer less than, equal to, or greater than zero if s1 is found, respectively, to be less than, to match, or be greater than s2.
Parameters:
s1  The first memory pointer of the area to compare.
s2  The second memory pointer of the area to compare.
n  How many words to compare.


__inline__ void * memchr (const void *cs, int c, size_t count)
 Find a byte into a memory area.
Parameters:
cs  The pointer of the memory area.
c  The character to find.
count  The size of the memory area.
Returns:
The address of the first occurrence or 0 if the char has not been found.


__inline__ void k_update_segment_regs ()
 Update segment registers with kernel selectors.

word setup_GDT_entry (word limit, dword base, byte attribs0_7, byte attribs8_15)
 Initialize a GDT entry.
Parameters:
limit  The size of the memory segment.
base  The starting linear address of the memory segment.
attribs0_7  The first 8-bit of the segment descriptor attributes.
attribs8_15  The last 8-bit of the segment descriptor attributes.
Returns:
The selector of the new GDT entry.


void remove_GDT_entry (word sel)
 Remove a GDT entry.
Parameters:
sel  The selector to remove from the GDT.


void install_GDT ()
 Initialize the Global Descriptor Table with the default selectors and update the segment registers.


Detailed Description

Low level (i386) memory manager header.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update:
2004-01-04 Andrea Righi: Improved assembler routies.
Note:
Copyright (C) 2003 Andrea Righi

Definition in file mem.h.


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