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

mem.c File Reference

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

#include <const.h>
#include <arch/i386.h>
#include <arch/paging.h>
#include <kernel/console.h>
#include <kernel/kernel.h>
#include <kernel/task.h>
#include <arch/mem.h>

Go to the source code of this file.

Functions

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.


Variables

volatile gdt_entry_t gdt [GDT_DIM]
 Global Descriptor Table (GDT).

gdt_reg gdt_ptr
 GDT pointer.


Detailed Description

Low level (i386) memory manager.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2004-01-20
Note:
Copyright (©) 2003 Andrea Righi

For a complete documentation about GDT and descriptors you can see the "IA-32 Intel® Architecture Software Developer's Manual - Volume 3: System Programming Guide" (http://www.intel.com/design/pentium4/manuals).
For an intalian documentation you can download the "Minirighi32 - Documentazione Ufficiale" (http://sourceforge.net/project/showfiles.php?group_id=80923&release_id=180542).

Definition in file mem.c.


Function Documentation

void install_GDT  
 

Initialize the Global Descriptor Table with the default selectors and update the segment registers.

Definition at line 93 of file mem.c.

00094 {
00095         // First of all reset all entries in the GDT //
00096         memset(&gdt, 0, sizeof(gdt));
00097 
00098         // ------------- Reserved entries in the GDT ------------------ //
00099 
00100         // Dummy descriptor//
00101         setup_GDT_entry(0, 0, 0, 0);
00102         // KERNEL_DATA descriptor 0x08 //
00103         setup_GDT_entry(0xFFFF, 0, DATA_SEG, (ATTR_GRANUL | ATTR_32BIT | 0xF));
00104         // KERNEL_CODE descriptor 0x10 //
00105         setup_GDT_entry(0xFFFF, 0, CODE_SEG, (ATTR_GRANUL | ATTR_32BIT | 0xF));
00106         // USER_DATA descriptor 0x18 //
00107         setup_GDT_entry(0xFFFF, 0, (DATA_SEG | DPL_3), (ATTR_GRANUL | ATTR_32BIT | 0xF));
00108         // USER_CODE descriptor 0x20 //
00109         setup_GDT_entry(0xFFFF, 0, (CODE_SEG | DPL_3), (ATTR_GRANUL | ATTR_32BIT | 0xF));
00110 
00111         // --------- End of reserved entries in the GDT --------------- //
00112 
00113         // Set up the GDT pointer //
00114         gdt_ptr.limit = (uint16_t)(GDT_DIM * GDT_ENTRY_DIM - 1);
00115         gdt_ptr.base = (size_t)gdt;
00116 
00117         // Load info into GDTR //
00118         __asm__ __volatile__ ("lgdtl (%0)" : : "r"(&gdt_ptr));
00119 
00120         // Update segment registers //
00121         k_update_segment_regs();
00122 }

void remove_GDT_entry word    sel
 

Remove a GDT entry.

Parameters:
sel  The selector to remove from the GDT.

Definition at line 74 of file mem.c.

00075 {
00076         dword IF = GET_IF();
00077 
00078         disable();
00079 
00080         gdt[sel/GDT_ENTRY_DIM].limit = 0;
00081         gdt[sel/GDT_ENTRY_DIM].base0_15 = 0;
00082         gdt[sel/GDT_ENTRY_DIM].base16_23 = 0;
00083         gdt[sel/GDT_ENTRY_DIM].base24_31 = 0;
00084         gdt[sel/GDT_ENTRY_DIM].attribs0_7 = 0;
00085         gdt[sel/GDT_ENTRY_DIM].attribs8_15 = 0;
00086 
00087         SET_IF(IF);
00088 }

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.

Definition at line 44 of file mem.c.

00045 {
00046         // Skip the dummy entry (#0).
00047         register unsigned short i=1;
00048         dword IF = GET_IF();
00049 
00050         disable();
00051         for (; i<GDT_DIM; i++)
00052         {
00053                 if (!(gdt[i].limit))
00054                 {
00055                         gdt[i].limit = limit;
00056                         gdt[i].base0_15 = base & 0xFFFF;
00057                         gdt[i].base16_23 = (base >> 16) & 0xFF;
00058                         gdt[i].base24_31 = (base >> 24) & 0xFF;
00059                         gdt[i].attribs0_7 = attribs0_7;
00060                         gdt[i].attribs8_15 = attribs8_15;
00061 
00062                         SET_IF(IF);
00063 
00064                         // Return the selector.
00065                         return(i * GDT_ENTRY_DIM);
00066                 }
00067         }
00068         error("Out of GDT entries!");
00069         return( NULL );
00070 }


Variable Documentation

volatile gdt_entry_t gdt[GDT_DIM]
 

Global Descriptor Table (GDT).

Definition at line 31 of file mem.c.

gdt_reg gdt_ptr [static]
 

GDT pointer.

Definition at line 33 of file mem.c.


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