feat: menage dans fichiers inutiles

This commit is contained in:
Nicolas Hordé 2018-08-28 15:22:43 +02:00
parent 647050d22e
commit e3c09a2191
11 changed files with 143 additions and 660 deletions

View File

@ -1,26 +0,0 @@
/***********************************/
/* Librairie Kmemory.h */
/* 20 Mars 2007 */
/***********************************/
#ifndef JREKCED_KERNEL_MEMORY
# define JREKCED_KERNEL_MEMORY
# include "type.h"
# define MEMORY_BLOC_SIZE (1024L) /* Taille des blocs */
// Initialise les gestionnaire de memoire.
void Kernel_InitMemory (void *DataMemory, // DataMemory pointe vers la zone de memoire disponible.
UDWORD TotalMemorySize); // TotalMemorySize est la quantite total de memoire disponible.
void * Kernel_mballoc(UDWORD Size); // Alloue SIZE blocs de memoire et retourne un pointeur sur la zone.
// Retourne un pointeur nul si l'allocation est impossible.
int Kernel_mbfree (void *Adresse); // Libere le bloc memoire alloue a l'adresse ADRESSE.
// Retourne -1 si adresse incorrecte et 0 si tout s'est bien deroule.
void * Kernel_mbrealloc (void *Adresse, UDWORD Size); // Redimensionne un bloc, retourne NULL si le bloc
// n'est pas redimensionne.
#endif

View File

@ -1,85 +0,0 @@
/***********************************/
/* Librairie LDT.h */
/* 23 Mars 2007 */
/***********************************/
#ifndef JREKCED_LDT
# define JREKCED_LDT
# include "type.h"
# define LDT_BLOC_SIZE (128) /* Nombre de descripteur LDT dans un bloc */
// Types d'acces
# define GLT_ACCESSED (0x1)
# define LDT_DATA (0x0)
# define LDT_DATA_WRITE (0x2)
# define LDT_DATA_EXPAND (0x4)
# define LDT_CODE (0x8)
# define LDT_CODE_READ (0xA)
# define LDT_CODE_CONFORMING (0xD)
// Granularite
# define LDT_BYTE (0x0)
# define LDT_4KB (0x1)
// Mode du CPU
# define LDT_16BIT (0x0)
# define LDT_32BIT (0x1)
typedef struct
{
UWORD Limite_0_15; // Bit 00-15 : Limite (0-15)
UWORD Adresse_0_15; // Bit 16-31 : Adresse (0-15)
UBYTE Adresse_16_23; // Bit 32-39 : Adresse (16-23)
UBYTE Acces : 1; // 0 = System
// 1 = Code ou data
UBYTE Type : 4; // Bit 41-44 : Type
UBYTE DPL : 2; // Spécifie le niveau de privilège du segment
UBYTE Present : 1; // Indique si le segment est en mémoire (bit a 1) ou non (bit a 0)
UBYTE Limite_16_19 : 4; // Bit 48-51 : Limite (16-19)
UBYTE UserDefine : 1; // Bit 52 : Utilisation libre
UBYTE Unused : 1; // Bit 53 : Non utilise (toujours = 0)
UBYTE CPUMode : 1; // Bit 54 : = 0 -> 16-Bit
// = 1 -> 32-Bit
UBYTE Granularite : 1; // Si = 0 : Limite = 1 octet -> 1 Mo
// Si = 1 : Limite = 4 Ko -> 4 Go
UBYTE Adresse_24_31; // Bit 56-63 : Adresse (24-31)
} T_LDT;
typedef struct
{
UWORD Size; // Taille de la GDT
void * Adresse; // Adresse phisique de la GDT;
UWORD Empty;
} T_LDT_reg;
// T_LDT *GDT_BASE = ((T_LDT*)0x0800L); /* Addresse physique ou reside la GDT, le 1e element est toujours null */
T_LDT * LDT_balloc (UWORD Size); // Alloue un bloc de Size LDT
int LDT_bfree (void * Adresse); // Libere un bloc LDT
T_LDT * LDT_brealloc (T_LDT * OldLDT, UWORD NewSize); // Redimensionne un bloc LDT, retourne NULL en cas d'erreur.
T_LDT * LDT_AllocLDT (T_LDT *BaseLDT); // Cherche un LDT libre dans un bloc precedement
// alloue avec LDT_balloc.
// Retourne NULL si aucun bloc disponible.
// Si un bloc libre est trouve, il est marque comme
// utilise et un pointeur sur ce LDT est retourne.
int LDT_FreeLDT (T_LDT *LDT); // Marque le LDT comme non utilise et le met a NULL.
int LDT_MapMemory (T_LDT *LDT, void * Linear, // Met des donnees dans un LDT.
UDWORD Size, // Cette fonction est a tester.
UBYTE Granularite,
UBYTE DPL, UBYTE Type,
UBYTE CPUMode);
#endif

View File

@ -1,42 +0,0 @@
#ifndef __TL_CTYPE_H
#define __TL_CTYPE_H
#ifdef __cplusplus
extern "C"
{
#endif
extern char g_ctype[];
#define CT_UP 0x01 /* upper case */
#define CT_LOW 0x02 /* lower case */
#define CT_DIG 0x04 /* digit */
#define CT_CTL 0x08 /* control */
#define CT_PUN 0x10 /* punctuation */
#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */
#define CT_HEX 0x40 /* hex digit */
#define CT_SP 0x80 /* hard space (0x20) */
/* without the cast to unsigned, DJGPP complains (using -Wall) */
#define isalnum(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG))
#define isalpha(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW))
#define iscntrl(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_CTL))
#define isdigit(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_DIG))
#define isgraph(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG))
#define islower(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_LOW))
#define isprint(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP))
#define ispunct(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_PUN))
#define isspace(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_WHT))
#define isupper(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_UP))
#define isxdigit(c) ((g_ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX))
#define isascii(c) ((unsigned)(c) <= 0x7F)
#define toascii(c) ((unsigned)(c) & 0x7F)
#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c)
#define toupper(c) (islower(c) ? c + 'A' - 'a' : c)
#ifdef __cplusplus
}
#endif
#endif

19
include/gdt.h Executable file
View File

@ -0,0 +1,19 @@
#include <type.h>
struct gdtdesc {
u16 lim0_15;
u16 base0_15;
u8 base16_23;
u8 acces;
u8 lim16_19 : 4;
u8 flags : 4;
u8 base24_31;
} __attribute__ ((packed));
struct gdtr {
u16 limite;
u32 base;
} __attribute__ ((packed));

View File

@ -1,6 +1,21 @@
#include "types.h" #include "types.h"
#define PIC1_CMD 0x20 /*PIC 8259A Commandes n°1 */
#define PIC1_DATA 0x21 /*PIC 8259A Données n°1 */
#define PIC2_CMD 0xa0 /*PIC 8259A Commandes n°2 */
#define PIC2_DATA 0xa1 /*PIC 8259A Données n°1 */
#define ICW1_ICW4 0x01 /* ICW4 ou pas*/
#define ICW1_SINGLE 0x02 /* mode seul ou cascadé */
#define ICW1_INTERVAL4 0x04 /* adresses appel d'interval 4 ou 8 */
#define ICW1_LEVEL 0x08 /* déclenchement sur niveau ou sur front */
#define ICW1_INIT 0x10 /* Initialization */
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
#define ICW4_AUTO 0x02 /* Auto EOI ou normal */
#define ICW4_BUF_SLAVE 0x08 /* mode/slave avec tampon*/
#define ICW4_BUF_MASTER 0x0C /* mode/master avec tampon*/
#define ICW4_SFNM 0x10 /* Complètement lié ou non */
#define INTGATE 0x8E00 /* utilise pour gerer les interruptions */ #define INTGATE 0x8E00 /* utilise pour gerer les interruptions */
#define TRAPGATE 0x8F00 /* utilise pour faire des appels systemes */ #define TRAPGATE 0x8F00 /* utilise pour faire des appels systemes */
@ -8,6 +23,15 @@
#define CALLGATE 0x8C00 /* utilise pour appeler du code */ #define CALLGATE 0x8C00 /* utilise pour appeler du code */
#define LDTDES 0x8200 /* utilise pour pointer une LDT */ #define LDTDES 0x8200 /* utilise pour pointer une LDT */
/* 00-11-010-0 : Compteur 0 - LSB puis MSB - generateur taux - binaire */
#define TIMER0 0x40 /* port E/S pour le timer canal 0 */
#define TIMER_MODE 0x43 /* port E/S pour le mode controle du timer */
#define RATE_GENERATOR 0x34 /* générateur de fréquence */
#define SQUARE_WAVE 0x36 /* générateur d'onde carrée */
#define TIMER_FREQ 1193180 /* fréquence pour timer dans un PC ou AT */
#define HZ 100 /* Fréquence d'horloge (ajutste logiciellement sur IBM-PC) */
/* descripteur de segment */ /* descripteur de segment */
typedef struct idtdes { typedef struct idtdes {
u16 offset0_15; u16 offset0_15;
@ -17,6 +41,10 @@ typedef struct idtdes {
} idtdes __attribute__ ((packed)); } idtdes __attribute__ ((packed));
struct dtr {
u16 limite;
u32 base;
} __attribute__ ((packed));
void initidt(void); void initidt(void);
void setidt(u32 offset, u16 select, u16 type,u16 index); void setidt(u32 offset, u16 select, u16 type,u16 index);

View File

@ -1,31 +0,0 @@
/***********************************/
/* Librairie Type.h */
/* 20 Mars 2007 */
/***********************************/
#ifndef JREKCED_TYPE
# define JREKCED_TYPE
# define NULL (0x0LL)
typedef char int8;
typedef short int16;
typedef int int32;
typedef long long int64;
typedef char BYTE;
typedef short WORD;
typedef long DWORD;
typedef long long QWORD;
typedef signed char SBYTE;
typedef signed short SWORD;
typedef signed long SDWORD;
typedef signed long long SQWORD;
typedef unsigned char UBYTE;
typedef unsigned short UWORD;
typedef unsigned long UDWORD;
typedef unsigned long long UQWORD;
#endif

View File

@ -1,66 +1,66 @@
#ifndef I386_TYPE #ifndef ALLTYPES
#define I386_TYPE # define ALLTYPES
typedef unsigned char u8;
typedef unsigned short u16; typedef char int8;
typedef unsigned int u32; typedef short int16;
typedef char s8; typedef int int32;
typedef short s16; typedef long long int64;
typedef int s32;
typedef int bool; typedef char BYTE;
typedef short WORD;
typedef long DWORD;
#define true 1 typedef long long QWORD;
#define false 0
#define NULL 0x0000 typedef signed char SBYTE;
typedef signed short SWORD;
struct dtr { typedef signed long SDWORD;
typedef signed long long SQWORD;
u16 limite;
typedef unsigned char UBYTE;
u32 base; typedef unsigned short UWORD;
typedef unsigned long UDWORD;
} __attribute__ ((packed)); typedef unsigned long long UQWORD;
#ifdef __cplusplus typedef unsigned char u8;
extern "C" typedef unsigned short u16;
{ typedef unsigned int u32;
#endif typedef char s8;
typedef short s16;
extern char ctype[]; typedef int s32;
typedef int bool;
#define CT_UP 0x01 /* upper case */
#define CT_LOW 0x02 /* lower case */ extern char ctype[];
#define CT_DIG 0x04 /* digit */
#define CT_CTL 0x08 /* control */ #define true 1
#define CT_PUN 0x10 /* punctuation */ #define false 0
#define CT_WHT 0x20 /* white space (space/cr/lf/tab) */ #define NULL 0x0000
#define CT_HEX 0x40 /* hex digit */
#define CT_SP 0x80 /* hard space (0x20) */ #define CT_UP 0x01 /* upper case */
#define CT_LOW 0x02 /* lower case */
/* without the cast to unsigned, DJGPP complains (using -Wall) */ #define CT_DIG 0x04 /* digit */
#define isalnum(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG)) #define CT_CTL 0x08 /* control */
#define isalpha(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW)) #define CT_PUN 0x10 /* punctuation */
#define iscntrl(c) ((ctype + 1)[(unsigned)(c)] & (CT_CTL)) #define CT_WHT 0x20 /* white space (space/cr/lf/tab) */
#define isdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG)) #define CT_HEX 0x40 /* hex digit */
#define isgraph(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG)) #define CT_SP 0x80 /* hard space (0x20) */
#define islower(c) ((ctype + 1)[(unsigned)(c)] & (CT_LOW))
#define isprint(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP)) /* without the cast to unsigned, DJGPP complains (using -Wall) */
#define ispunct(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN)) #define isalnum(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW | CT_DIG))
#define isspace(c) ((ctype + 1)[(unsigned)(c)] & (CT_WHT)) #define isalpha(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP | CT_LOW))
#define isupper(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP)) #define iscntrl(c) ((ctype + 1)[(unsigned)(c)] & (CT_CTL))
#define isxdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX)) #define isdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG))
#define isascii(c) ((unsigned)(c) <= 0x7F) #define isgraph(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG))
#define toascii(c) ((unsigned)(c) & 0x7F) #define islower(c) ((ctype + 1)[(unsigned)(c)] & (CT_LOW))
#define isprint(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN | CT_UP | CT_LOW | CT_DIG | CT_SP))
#define tolower(c) (isupper(c) ? c + 'a' - 'A' : c) #define ispunct(c) ((ctype + 1)[(unsigned)(c)] & (CT_PUN))
#define toupper(c) (islower(c) ? c + 'A' - 'a' : c) #define isspace(c) ((ctype + 1)[(unsigned)(c)] & (CT_WHT))
#define isupper(c) ((ctype + 1)[(unsigned)(c)] & (CT_UP))
#ifdef __cplusplus #define isxdigit(c) ((ctype + 1)[(unsigned)(c)] & (CT_DIG | CT_HEX))
} #define isascii(c) ((unsigned)(c) <= 0x7F)
#endif #define toascii(c) ((unsigned)(c) & 0x7F)
#endif #define tolower(c) (isupper(c) ? c + 'a' - 'A' : c)
#define toupper(c) (islower(c) ? c + 'A' - 'a' : c)
#endif

View File

@ -1,156 +0,0 @@
/***********************************/
/* Librairie Kmemory.c */
/* 20 Mars 2007 */
/***********************************/
#include <type.h>
#include <Kmemory.h>
/* Structure table d'allocation memoire */
typedef struct
{
UBYTE Used : 1; // = 0 -> La zone memoire est libre.
// = 1 -> La zone memoire est utilisee.
UBYTE Expand : 1; // = 0 -> Fin du bloc.
// = 1 -> Le bloc se prolonge sur le bloc suivant.
UBYTE UnUsed : 6; // Zone libre.
} T_KernelMemoryMap;
T_KernelMemoryMap * BlocAllocate = NULL; // Table d'allocation des blocs memoire.
void * BaseDynAlloc = NULL; // Pointeur sur la zone memoire allouable.
UDWORD MaxMemoryBlocs;
// Initialisation du gestionnaire de memoire.
void Kernel_InitMemory (void *DataMemory, UDWORD TotalMemorySize)
{
UDWORD Boucle;
UDWORD TableBlocs;
UDWORD TotalBlocs;
// Alignement des bloc de memoire a un multiple de MEMORY_BLOC_SIZE
if ( (UDWORD)DataMemory % MEMORY_BLOC_SIZE != 0)
{ DataMemory = ((void*) ((((UDWORD)DataMemory) / MEMORY_BLOC_SIZE) * MEMORY_BLOC_SIZE) + MEMORY_BLOC_SIZE ); };
TotalBlocs = (((void*)TotalMemorySize) - DataMemory) / MEMORY_BLOC_SIZE;
TableBlocs = TotalBlocs / MEMORY_BLOC_SIZE;
MaxMemoryBlocs = TotalBlocs - TableBlocs;
BlocAllocate = (T_KernelMemoryMap *)DataMemory;
BaseDynAlloc = DataMemory + (TableBlocs * MEMORY_BLOC_SIZE);
for (Boucle = 0; Boucle < MaxMemoryBlocs; Boucle++)
{
BlocAllocate [Boucle].Used = 0;
BlocAllocate [Boucle].Expand = 0;
}
}
// Alloue SIZE blocs de memoire
void * Kernel_mballoc(UDWORD Size)
{
UDWORD Counter = 0;
UDWORD Base = 0;
UDWORD Boucle, Boucle2;
if (Size == 0) return NULL;
for (Boucle = 0; Boucle < MaxMemoryBlocs; Boucle++)
{
if (BlocAllocate[Boucle].Used == 0) { Counter++; }
else { Counter = 0; Base = Boucle + 1; }
if (Counter >= Size)
{
if (Base+Size > MaxMemoryBlocs) return NULL;
for (Boucle2=Base; Boucle2 < (Base+Size); Boucle2++)
{
BlocAllocate[Boucle2].Used = 1;
if (Boucle2+1 < (Base+Size) ) { BlocAllocate[Boucle2].Expand = 1; }
else { BlocAllocate[Boucle2].Expand = 0; }
}
return ((void*) (BaseDynAlloc + (Base * MEMORY_BLOC_SIZE) ));
}
}
return NULL;
}
// Libere un bloc memoire
int Kernel_mbfree (void *Adresse)
{
UDWORD Bloc;
if (((Adresse - BaseDynAlloc) % MEMORY_BLOC_SIZE) != 0) return -1;
if ((((UDWORD)Adresse) % MEMORY_BLOC_SIZE) != 0) return -1;
Bloc = (Adresse - BaseDynAlloc) / MEMORY_BLOC_SIZE;
for (; BlocAllocate[Bloc].Expand == 1; Bloc++)
{
BlocAllocate[Bloc].Used = 0;
BlocAllocate[Bloc].Expand = 0;
}
BlocAllocate[Bloc].Used = 0;
BlocAllocate[Bloc].Expand = 0;
return 0;
};
void * Kernel_mbrealloc (void *Adresse, UDWORD Size)
{
UDWORD Bloc, Boucle, OldSize, CopySize;
void * NewAdresse;
if (((Adresse - BaseDynAlloc) % MEMORY_BLOC_SIZE) != 0) return NULL;
Bloc = (Adresse - BaseDynAlloc) / MEMORY_BLOC_SIZE;
if (BlocAllocate[Bloc].Used == 0) return NULL;
for (Boucle = Bloc; BlocAllocate[Boucle].Expand == 1; Boucle++)
{ if (Boucle >= MaxMemoryBlocs) break; };
OldSize = Boucle - Bloc + 1;
// Si pas de changement de taille de bloc, ...
if ( Size == OldSize) return Adresse;
// Si on reduit le nombre de bloc, ...
if ( Size < OldSize)
{
for (Boucle = (Bloc + Size); Boucle < (Bloc + OldSize) ; Boucle++)
{
BlocAllocate[Boucle].Used = 0;
BlocAllocate[Boucle].Expand = 0;
}
BlocAllocate[Size-1].Expand = 0;
return Adresse;
}
// Si on augmente le nombre de bloc
for (Boucle = (Bloc + OldSize); Boucle < (Bloc + Size) ; Boucle++)
{
// Si le bloc ne peut etre simplement agrandit, ...
if ( BlocAllocate[Boucle].Used == 1 )
{
NewAdresse = Kernel_mballoc (Size);
if (NewAdresse == NULL) return NULL;
CopySize = (OldSize * MEMORY_BLOC_SIZE) / sizeof (int64);
for (Boucle = 0; Boucle < CopySize; Boucle++)
{ ((int64*) NewAdresse)[Boucle] = ((int64*) Adresse)[Boucle]; };
Kernel_mbfree (Adresse);
return NewAdresse;
}
}
// Le bloc est simplement agrandit
for (Boucle = (Bloc + OldSize - 1); Boucle < (Bloc + Size) ; Boucle++)
{
BlocAllocate[Boucle].Used = 1;
BlocAllocate[Boucle].Expand = 1;
}
BlocAllocate[Size-1].Expand = 0;
return Adresse;
}
#undef MAX_MEMORY_BLOCS

236
lib/LDT.c
View File

@ -1,236 +0,0 @@
/***********************************/
/* Librairie LDT.c */
/* 23 Mars 2007 */
/***********************************/
#include "LDT.h"
#include "Kmemory.h"
# define LDT_MANAGER_SIZE (127)
typedef struct // Structure de gestion des bloc LDT
{
void * Next; // Pointeur de chainage
UDWORD Empty;
T_LDT_reg LDTdesc [LDT_MANAGER_SIZE]; // Nombre de blocs LDT
} T_LDT_Manager;
void LDT_initalloc (void *AllocTable, UDWORD Index, UDWORD SetSize, UDWORD TotalSize);
T_LDT_Manager * LDT_mballoc (UWORD Size);
/////////////////////////////////////////////////////////////////////////
T_LDT_Manager * LDT_Manager = NULL;
/////////////////////////////////////////////////////////////////////////
T_LDT * LDT_balloc (UWORD Size) // Alloue un bloc de Size LDT
{
UWORD Boucle;
UDWORD Blocs, Boucle2;
T_LDT_Manager * * ptr_Manager = &LDT_Manager;
T_LDT_Manager * Manager = LDT_Manager;
do
{
if (* ptr_Manager == NULL)
{
* ptr_Manager = Kernel_mballoc (1);
Manager = * ptr_Manager;
Manager->Next = NULL;
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
Manager->LDTdesc [Boucle].Adresse = NULL;
Manager->LDTdesc [Boucle].Size = NULL;
}
}
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
if (Manager->LDTdesc [Boucle].Adresse == NULL)
{
Blocs = Size * sizeof(T_LDT);
if (Blocs % MEMORY_BLOC_SIZE == 0)
{ Blocs /= MEMORY_BLOC_SIZE; } else { Blocs = (Blocs / MEMORY_BLOC_SIZE) + 1; }
Manager->LDTdesc [Boucle].Adresse = Kernel_mballoc (Blocs);
if (Manager->LDTdesc [Boucle].Adresse == NULL) return NULL;
Manager->LDTdesc [Boucle].Size = (Blocs * MEMORY_BLOC_SIZE) / sizeof(T_LDT);
// Mise a zero de la LDT
for (Boucle2 = 0; Boucle2 < Manager->LDTdesc [Boucle].Size; Boucle2++)
{ ((int64*) Manager->LDTdesc [Boucle].Adresse)[Boucle2] = NULL; }
return Manager->LDTdesc [Boucle].Adresse;
}
}
*ptr_Manager = Manager;
Manager = Manager->Next;
} while (1);
}
int LDT_bfree (void * Adresse) // Libere un bloc LDT
{
UWORD Boucle, Boucle2;
int RetVal;
T_LDT_Manager * * ptr_Manager = &LDT_Manager;
T_LDT_Manager * Manager = LDT_Manager;
do
{
if (*ptr_Manager == NULL) { return -1; }
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
if (Manager->LDTdesc [Boucle].Adresse == Adresse)
{
RetVal = Kernel_mbfree(Manager->LDTdesc [Boucle].Adresse);
if (Boucle == 0)
{
Kernel_mbfree (*ptr_Manager);
*ptr_Manager = NULL;
return RetVal;
}
else
{
for (Boucle2 = Boucle; Boucle2 < LDT_MANAGER_SIZE-1; Boucle2++)
{ Manager->LDTdesc [Boucle2] = Manager->LDTdesc [Boucle2+1]; }
Manager->LDTdesc [Boucle2+1].Size = NULL;
Manager->LDTdesc [Boucle2+1].Adresse = NULL;
}
Manager->LDTdesc [LDT_MANAGER_SIZE-1].Size = NULL;
Manager->LDTdesc [LDT_MANAGER_SIZE-1].Adresse = NULL;
return RetVal;
}
}
*ptr_Manager = Manager;
Manager = Manager->Next;
} while (1);
}
T_LDT * LDT_brealloc (T_LDT * OldLDT, UWORD NewSize)
{
T_LDT * NewLDT;
UDWORD Blocs;
UWORD Boucle;
T_LDT_Manager * * ptr_Manager = &LDT_Manager;
T_LDT_Manager * Manager = LDT_Manager;
Blocs = NewSize * sizeof(T_LDT);
if (Blocs % MEMORY_BLOC_SIZE == 0)
{ Blocs /= MEMORY_BLOC_SIZE; } else { Blocs = (Blocs / MEMORY_BLOC_SIZE) + 1; }
do
{
if (*ptr_Manager == NULL) { return NULL; }
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
if (Manager->LDTdesc [Boucle].Adresse == OldLDT)
{
NewLDT = Kernel_mbrealloc (OldLDT, Blocs);
if (NewLDT == NULL) return NULL;
Manager->LDTdesc [Boucle].Adresse = NewLDT;
Manager->LDTdesc [Boucle].Size = NewSize;
return NewLDT;
}
}
*ptr_Manager = Manager;
Manager = Manager->Next;
} while (1);
}
///////////////////////////////////////////////////////////////////////
T_LDT * LDT_AllocLDT (T_LDT *BaseLDT)
{
UWORD Boucle;
UDWORD Boucle2;
UDWORD Size;
T_LDT_Manager * Manager = LDT_Manager;
if (BaseLDT == NULL) return NULL;
do
{
if (Manager == NULL) { return NULL; }
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
Size = Manager->LDTdesc [Boucle].Size;
if (Manager->LDTdesc [Boucle].Adresse == ((void*)BaseLDT) )
{
for (Boucle2 = 1; Boucle2 < Size; Boucle2++) // Le 1e LDT reste null
{
if ( BaseLDT[Boucle2].UserDefine == 0 )
{
BaseLDT[Boucle2].UserDefine = 1;
return BaseLDT+Boucle2;
};
}
return NULL;
}
}
Manager = Manager->Next;
} while (1);
}
int LDT_FreeLDT (T_LDT *LDT) // Marque le LDT comme non utilise et le met a NULL
{
if ( ((UDWORD)LDT & 0x07L) != NULL) { return -2; }
if (LDT->UserDefine == 0) { return -1; }
*((int64*)LDT) = NULL;
return 0;
}
///////////////////////////////////////////////////////////////////////
int LDT_MapMemory (T_LDT *LDT, void * Linear, UDWORD Size, UBYTE Granularite, UBYTE DPL, UBYTE Type, UBYTE CPUMode)
{
if ( ((UDWORD)LDT & 0x07L) != NULL) { return -2; }
LDT->Adresse_0_15 = (DWORD)Linear & 0x0000FFFFL;
LDT->Adresse_16_23 = ((DWORD)Linear >> 16) & 0x000000FFL;
LDT->Adresse_24_31 = ((DWORD)Linear >> 24) & 0x000000FFL;
LDT->Limite_0_15 = Size & 0x0000FFFFL;
LDT->Limite_16_19 = (Size >> 16) & 0x0000000FL;
LDT->Granularite = Granularite;
LDT->Type = Type;
LDT->DPL = DPL;
LDT->CPUMode = CPUMode;
LDT->Present = 1;
LDT->UserDefine = 1;
return 0;
}
int LDT_load (T_LDT *LDT)
{
UWORD Boucle;
T_LDT_Manager * * ptr_Manager = &LDT_Manager;
T_LDT_Manager * Manager = LDT_Manager;
do
{
if (*ptr_Manager == NULL) { return -1; }
for (Boucle = 0; Boucle < LDT_MANAGER_SIZE; Boucle++)
{
if (Manager->LDTdesc [Boucle].Adresse == LDT)
{
asm("lgdt %0\n" : : "m" (Manager->LDTdesc [Boucle]));
return 0;
}
}
*ptr_Manager = Manager;
Manager = Manager->Next;
} while (1);
}

View File

@ -18,38 +18,38 @@ void initpic(void)
{ {
/* MASTER */ /* MASTER */
/* Initialisation de ICW1 */ /* Initialisation de ICW1 */
outb(0x20, 0x11); outb(PIC1_CMD, ICW1_INIT + ICW1_ICW4);
nop(); nop();
/* Initialisation de ICW2 - vecteur de depart = 32 */ /* Initialisation de ICW2 - vecteur de depart = 32 */
outb(0x21, 0x20); outb(PIC1_DATA, 0x20);
nop(); nop();
/* Initialisation de ICW3 */ /* Initialisation de ICW3 */
outb(0x21, 0x04); outb(PIC1_DATA, 0x04);
nop(); nop();
/* Initialisation de ICW4 */ /* Initialisation de ICW4 */
outb(0x21, 0x01); outb(PIC1_DATA, ICW4_8086);
nop(); nop();
/* masquage des interruptions */ /* masquage des interruptions */
outb(0x21, 0xFF); outb(PIC1_DATA, 0xFF);
nop(); nop();
/* SLAVE */ /* SLAVE */
/* Initialisation de ICW1 */ /* Initialisation de ICW1 */
outb(0xA0, 0x11); outb(PIC2_CMD, ICW1_INIT + ICW1_ICW4);
nop(); nop();
/* Initialisation de ICW2 - vecteur de depart = 96 */ /* Initialisation de ICW2 - vecteur de depart = 96 */
outb(0xA1, 0x60); outb(PIC2_DATA, 0x60);
nop(); nop();
/* Initialisation de ICW3 */ /* Initialisation de ICW3 */
outb(0xA1, 0x02); outb(PIC2_DATA, 0x02);
nop(); nop();
/* Initialisation de ICW4 */ /* Initialisation de ICW4 */
outb(0xA1, 0x01); outb(PIC2_DATA, ICW4_8086);
nop(); nop();
/* masquage des interruptions */ /* masquage des interruptions */
outb(0xA1, 0xFF); outb(PIC2_DATA, 0xFF);
nop(); nop();
/* Demasquage des irqs sauf clavier /* Demasquage des irqs sauf clavier
outb(0x21,0xFD); outb(PIC1_DATA,0xFD);
nop(); nop();
*/ */
} }
@ -62,7 +62,7 @@ void enableirq(u8 irq)
{ {
u16 port; u16 port;
cli(); cli();
port = (((irq & 0x08) << 4) + 0x21); port = (((irq & 0x08) << 4) + PIC1_DATA);
outb(port, inb(port) & ~(1 << (irq & 7))); outb(port, inb(port) & ~(1 << (irq & 7)));
sti(); sti();
} }
@ -75,7 +75,7 @@ void disableirq(u8 irq)
{ {
u16 port; u16 port;
cli(); cli();
port = (((irq & 0x08) << 4) + 0x21); port = (((irq & 0x08) << 4) + PIC1_DATA);
outb(port, inb(port) | (1 << (irq & 7))); outb(port, inb(port) | (1 << (irq & 7)));
sti(); sti();
} }
@ -129,7 +129,7 @@ void cpuerror(const u8 * src)
print("\033[31m***** ERREUR CPU ****\r\n -"); print("\033[31m***** ERREUR CPU ****\r\n -");
print(src); print(src);
dump_regs(); dump_regs();
while (1) { while (true) {
nop(); nop();
} }
} }
@ -514,7 +514,7 @@ void initidt(void)
putidt((u32) exception17, 0x20, INTGATE, 17); putidt((u32) exception17, 0x20, INTGATE, 17);
putidt((u32) exception18, 0x20, INTGATE, 18); putidt((u32) exception18, 0x20, INTGATE, 18);
for (i = 19; i < 32; i++) { for (i = 19; i < 32; i++) {
putidt((u32) interruption, 0x20, INTGATE, i); putidt((u32) interruption, 0x20, TRAPGATE, i);
} }
putidt((u32) irq0, 0x20, INTGATE, 32); putidt((u32) irq0, 0x20, INTGATE, 32);
putidt((u32) irq1, 0x20, INTGATE, 33); putidt((u32) irq1, 0x20, INTGATE, 33);
@ -525,7 +525,7 @@ void initidt(void)
putidt((u32) irq6, 0x20, INTGATE, 38); putidt((u32) irq6, 0x20, INTGATE, 38);
putidt((u32) irq7, 0x20, INTGATE, 39); putidt((u32) irq7, 0x20, INTGATE, 39);
for (i = 40; i < 96; i++) { for (i = 40; i < 96; i++) {
putidt((u32) interruption, 0x20, INTGATE, i); putidt((u32) interruption, 0x20, TRAPGATE, i);
} }
putidt((u32) irq8, 0x20, INTGATE, 96); putidt((u32) irq8, 0x20, INTGATE, 96);
putidt((u32) irq9, 0x20, INTGATE, 97); putidt((u32) irq9, 0x20, INTGATE, 97);
@ -536,7 +536,7 @@ void initidt(void)
putidt((u32) irq14, 0x20, INTGATE, 102); putidt((u32) irq14, 0x20, INTGATE, 102);
putidt((u32) irq15, 0x20, INTGATE, 103); putidt((u32) irq15, 0x20, INTGATE, 103);
for (i = 104; i < 255; i++) { for (i = 104; i < 255; i++) {
putidt((u32) interruption, 0x20, INTGATE, i); putidt((u32) interruption, 0x20, TRAPGATE, i);
} }
/* initialise le registre idt */ /* initialise le registre idt */
idtreg.limite = 256 * 8; idtreg.limite = 256 * 8;
@ -547,3 +547,15 @@ void initidt(void)
lidt(&idtreg); lidt(&idtreg);
} }
/******************************************************************************/
/* 8253/8254 PIT (Programmable Interval Timer) Timer ajustable */
void inittimer()
{
outb(TIMER_MODE, RATE_GENERATOR);
outb(TIMER0, (u8) (TIMER_FREQ/HZ) );
outb(TIMER0, (u8) ((TIMER_FREQ/HZ) >> 8));
}

View File

@ -91,7 +91,7 @@ int main(void)
} }
void test2d() { void test2d() {
setvmode(0x84); setvmode(0x89);
fill(0x00); fill(0x00);
struct vertex2d a,b,c; struct vertex2d a,b,c;
randomize(); randomize();