1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
| #include <sextant/String.h>
#include <hal/multiboot.h>
#include <hal/memoire.h>
#include <hal/irq.h>
#include <hal/idt.h>
#include <hal/gdt.h>
#include <hal/thread.h>
#include <hal/physmem.h>
#include <hal/paging.h>
#include <hal/kmalloc.h>
#include <drivers/Ecran.h>
#include <drivers/ide.h>
#include <drivers/Clavier.h>
#include <drivers/fs_fat.h>
#include <Applications/Horloge/Horloge.h>
#include <Applications/CasseBrique/CasseBrique.h>
#include <Applications/Fibo/fibo.h>
//Gestion des threads cooperatifs ou preemptifs
#define COOP true
extern int i;//pour test de new
extern struct ide_controller ide_controllers[MAX_IDE_CONTROLLERS];
extern char __e_kernel;
/* The address of the stack of the bootstrap thread */
extern vaddr_t bootstrap_stack_bottom;
extern size_t bootstrap_stack_size;
extern "C" void Sextant_main(unsigned long magic, unsigned long addr){
char tab1[1024];
Ecran ecran;
Clavier clavier;
paddr_t kernel_core_base,kernel_core_top;
/** Phase d'initialisation **/
//Initialisation de l'écran
ecran.initier();
//Initialisation des interruptions
idt_setup();
//Initialisation de la mémoire
gdt_setup();
irq_setup();
//Initialisation de la fréquence de l'horloge
i8254_set_frequency(1000);
multiboot_info_t* mbi;
mbi = (multiboot_info_t*) addr;
// mem_setup(& __e_kernel,(mbi->mem_upper<<10) + (1<<20));
//Initialisation des adresses virtuelles
physmem_setup((mbi->mem_upper<<10) + (1<<20),&kernel_core_base,&kernel_core_top);
paging_setup(kernel_core_base,kernel_core_top);
kmem_vmm_setup(kernel_core_base,kernel_core_top,bootstrap_stack_bottom,
bootstrap_stack_bottom + bootstrap_stack_size);
//Initialisation des threads
thread_subsystem_setup(tab1[1024],1024);
//Initialisation de l'ordonnanceur
sched_subsystem_setup();
//Initialisation du driver IDE
ide_subsystem_setup(&ecran);
//Un ecran propre
ecran.effacerEcran(NOIR);
ecran.afficherBase(bootstrap_stack_bottom);
ecran.afficherMot(" jusqu'a ");
ecran.afficherBase(bootstrap_stack_size + bootstrap_stack_bottom);
ecran.afficherMot("\n");
/***
* Test lecture/ecriture sur le disque IDE
* ATTENTION : Ce test écrase le secteur contenant les informations de la FAT.
***/
/* char toto[512];
char titi[512];
toto[0]='T';
toto[1]='I';
toto[2]='T';
toto[3]='I';
toto[4]='\n';
toto[5]='\0';
int lg = 512;
ide_write_device(&ide_controllers[0].devices[1],(vaddr_t)toto,(luoffset_t)2,lg);
ide_read_device(&ide_controllers[0].devices[1],(vaddr_t)titi,(luoffset_t)2,lg);
ecran.afficherMot("Allez titi !\n");
ecran.afficherMot(titi);
/*** Test d'allocation/liberation de memoire ***/
int *d = (int*)malloc(sizeof(int));
*d = 3;
ecran.afficherBase(*d);
ecran.afficherMot(" et ");
struct stock_tab* toto = (struct stock_tab*)malloc(sizeof(struct stock_tab));
toto->tab[10] = 98;
ecran.afficherBase(toto->tab[10]);
ecran.afficherMot("\n");
kfree((vaddr_t)d);
kfree((vaddr_t)toto);
/*** Test de la structure Fat ***/
fat_clear(&ecran);//Aucune structure Fat n'est en place
bool* formate = (bool*)malloc(sizeof(bool));//Indicateur de formatage du disque
struct stock_tab* milou = (struct stock_tab*)malloc(sizeof(struct stock_tab));//Permet la récupération de la table (bricolage)
int secteur = 0;
ide_read_device(&ide_controllers[0].devices[1],(vaddr_t)formate,secteur,512);
secteur++;
struct fat_data_structure *data_struct = (struct fat_data_structure*)malloc(sizeof(struct fat_data_structure));
if(!*formate)//Pas de formatage, on initialise la Fat
fat_mount(&ecran,data_struct,formate);
else {//On recupere les infos de la Fat
ide_read_device(&ide_controllers[0].devices[1],(vaddr_t)data_struct,secteur,sizeof(struct fat_data_structure));
secteur++;
ui32_t taille = sizeof(ui32_t)*data_struct->CountOfClusters;
data_struct->fat_table = (ui32_t*)malloc(taille);
secteur = 3;//En 2 ca ne marche pas ???
for(ui32_t offset = 0;offset < taille;offset+=512,secteur++) {
ide_read_device(&ide_controllers[0].devices[1],(vaddr_t)milou,secteur,512);
for(int i=0;i<128 && data_struct->CountOfClusters > (offset/4 + i);i++) {
data_struct->fat_table[offset/4 + i] = milou->tab[i];
}
}
}
//Creation de fichiers
char chien[512];
struct fat_directory* fic = (struct fat_directory*)malloc(sizeof(struct fat_directory));
//Creation du fichier chien
create_file(data_struct,"chien");
fic = fopen("chien");
fwrite(data_struct,fic,"Le chien et le chat jouent.\n",String::strlen("Le chien et le chat jouent.\n")+1);
fread(data_struct,fic,chien,512);
fclose(fic);
//Creation du fichier info
fic = (struct fat_directory*)malloc(sizeof(struct fat_directory));
char info[512];
create_file(data_struct,"info");
fic = fopen("info");
fwrite(data_struct,fic,"L informatique c est genial !\n",String::strlen("L informatique c est genial !\n")+1);
fread(data_struct,fic,info,512);
fclose(fic);
fic = (struct fat_directory*)malloc(sizeof(struct fat_directory));
char marche[512];
create_file(data_struct,"marche");
fic = fopen("marche");
fwrite(data_struct,fic,"Quand ca marche.\n",String::strlen("Quand ca marche.\n")+1);
fread(data_struct,fic,marche,512);
fclose(fic);
//Lecture des fichiers crees
ecran.afficherMot(chien);
ecran.afficherMot(marche);
ecran.afficherMot(info);
/*** Test de l'allocation mémoire ***/
Ecran* ec = new Ecran;
ecran.afficherMot("\n");
ecran.afficherBase(paging_get_paddr((vaddr_t)ec));
ec->afficherCaractere(10,10,BLANC,NOIR,i+48);
ec->afficherMot("un ecran qui marche bien !");
kfree((vaddr_t)ec);
/** Test de l'affichage **/
/*** Affichage de chaines testant la prise en compte du défilement et '\n' ***/
ecran.afficherMot("Bienvenue a toi, petit terrien !\n",JAUNE);
ecran.afficherMot("Bienvenue a toi, petit terrien !\n",JAUNE);
ecran.afficherMot("Bienvenue a toi, petit terrien !\n",JAUNE);
ecran.afficherMot("Bienvenue a toi, petit terrien !\n",JAUNE);
ecran.afficherCaractere(24,72,BLEU,NOIR,'S');
ecran.afficherCaractere(24,73,VERT,NOIR,'E');
ecran.afficherCaractere(24,74,CYAN,NOIR,'X');
ecran.afficherCaractere(24,75,ROUGE,NOIR,'T');
ecran.afficherCaractere(24,76,MAGENTA,NOIR,'A');
ecran.afficherCaractere(24,77,MARRON,NOIR,'N');
ecran.afficherCaractere(24,78,GRIS_LEGER,NOIR,'T');
ecran.afficherMot("tra\nlala\n");
/*** Initialisation des routines d'interruption du clavier et de l'horloge ***/
irq_set_routine(IRQ_KEYBOARD, keyboard_handler);
irq_set_routine(IRQ_TIMER, ticTac);
asm volatile("sti\n");//Autorise les interruptions
/** Test des interruptions **/
/* Horloge h(&ecran,&clavier);
/*** Test du clavier ***/
char buffer[256];
int curseur = 0;
while(!String::strcmp(buffer,"jeu\n"))
if(clavier.testChar()) {
char mot[256];
String::strcpy(mot,clavier.getString(),256);
ecran.afficherMot(mot);
if(mot[0]=='\n') {
buffer[curseur]=mot[0];
curseur++;
buffer[curseur]='\0';
curseur=0;
}
else {
buffer[curseur]=mot[0];
curseur++;
buffer[curseur]='\0';
}
}
/*** Test des threads ***/
if(COOP) {
//cooperatifs
irq_set_routine(IRQ_TIMER, sched_clk);
fibo_print(&ecran);
}
//debut du Jeu : casse brique
else {
CasseBrique monJeu;
monJeu.start(&ecran,&clavier);
}
/** The End **/
while(true);
} |
Partager