feat: ajustement des fonctions multiboot

This commit is contained in:
Nicolas Hordé 2018-11-14 22:23:10 +01:00
parent 8b2fa6ae68
commit 812e3c0bed
6 changed files with 114 additions and 154 deletions

View File

@ -7,8 +7,8 @@ typedef struct cpuinfo
{
u8 vendor[13];
u8 names[32];
u8 detectedname[48];
u8 techs[48];
u8 detectedname[256];
u8 techs[256];
u8 stepping;
u8 models;
u8 family;

View File

@ -4,7 +4,7 @@
#include "types.h"
#ifndef MULTIBOOT
# define ALLTYMULTIBOOTPES
#define MULTIBOOT
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 32768
@ -389,8 +389,12 @@
u32 load_base_addr;
};
void getbootinfo(void);
u32 getblockinfo(void);
u32 getgrubinfo(u8 type);
u8 *getgrubinfo_cmdline(void);
u32 getgrubinfo_ram(void);
struct multiboot_memory_map_t *getgrubinfo_mem(void);
struct multiboot_tag_framebuffer *getgrubinfo_fb(void);
void getgrubinfo_all(void);
void initmultiboot(const u32 addr);
#endif

View File

@ -758,8 +758,9 @@ void initidt(void)
void inittimer(void)
{
u32 divisor = TIMER_FREQ / HZ;
outb(TIMER_MODE, RATE_GENERATOR);
outb(TIMER0, (u8) (TIMER_FREQ / HZ));
outb(TIMER0, (u8) ((TIMER_FREQ / HZ) >> 8));
outb(TIMER0, (u8) divisor);
outb(TIMER0, (u8) (divisor >> 8));
}
/*******************************************************************************/

View File

@ -15,24 +15,64 @@ void initmultiboot(const u32 addr)
}
/*******************************************************************************/
/* Renvoie l'adresse du bloc multiboot2 */
/* Renvoie les informations souhaitées multiboot2 */
u32 getblockinfo(void)
u32 getgrubinfo(u8 type)
{
return infobloc;
struct multiboot_tag *tag;
unsigned size = *(unsigned *) infobloc;
for (tag = (struct multiboot_tag *) (infobloc + 8);
tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *) ((u8 *) tag + ((tag->size + 7) & ~7)))
if (tag->type==type) return tag;
}
/*******************************************************************************/
/* Affiche les informations multiboot2 */
/* Renvoie la ligne de commande */
void getbootinfo(void)
u8 *getgrubinfo_cmdline(void)
{
struct multiboot_tag_string *tag=getgrubinfo(MULTIBOOT_TAG_TYPE_CMDLINE);
return tag->string;
}
/*******************************************************************************/
/* Renvoie la quantité de mémoire */
u32 getgrubinfo_ram(void)
{
struct multiboot_tag_basic_meminfo *tag=getgrubinfo(MULTIBOOT_TAG_TYPE_BASIC_MEMINFO);
return tag->mem_upper;
}
/*******************************************************************************/
/* Renvoie le plan de la mémoire */
struct multiboot_memory_map_t *getgrubinfo_mem(void)
{
struct multiboot_memory_map_t *tag=getgrubinfo(MULTIBOOT_TAG_TYPE_MMAP);
return tag;
}
/*******************************************************************************/
/* Renvoie les information sur le framebuffer */
struct multiboot_tag_framebuffer *getgrubinfo_fb(void)
{
struct multiboot_tag_framebuffer *tag=getgrubinfo(MULTIBOOT_TAG_TYPE_FRAMEBUFFER);
return tag;
}
/*******************************************************************************/
/* Affiche les informations multiboot2 ;*/
void getgrubinfo_all(void)
{
u32 addr=infobloc;
struct multiboot_tag *tag;
unsigned size = *(unsigned *) addr;
if (addr & 7) print("Non aligne...");
u32 size = *(unsigned *) infobloc;
if (infobloc & 7) print("Attention : Bloc non aligne...");
printf(" Taille :% 4u\r\n", (u32)size);
for (tag = (struct multiboot_tag *) (addr + 8);
for (tag = (struct multiboot_tag *) (infobloc + 8);
tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *) ((u8 *) tag + ((tag->size + 7) & ~7)))
{
@ -40,132 +80,66 @@ for (tag = (struct multiboot_tag *) (addr + 8);
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_CMDLINE:
printf ("line de lancement : %s\r\n",
printf (" Ligne de lancement : %s\r\n",
((struct multiboot_tag_string *) tag)->string);
break;
case MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME:
printf ("Chargeur de boot : %s\r\n",
printf (" Chargeur de boot : %s\r\n",
((struct multiboot_tag_string *) tag)->string);
break;
case MULTIBOOT_TAG_TYPE_MODULE:
printf ("Module %X-%X. Command line %s\r\n",
printf (" Module %X-%X. Command line %s\r\n",
((struct multiboot_tag_module *) tag)->mod_start,
((struct multiboot_tag_module *) tag)->mod_end,
((struct multiboot_tag_module *) tag)->cmdline);
break;
case MULTIBOOT_TAG_TYPE_BASIC_MEMINFO:
printf ("Memoire basse : %H, memoire haute = %lH\r\n",
printf (" Memoire basse : %H, memoire haute = %lH\r\n",
((struct multiboot_tag_basic_meminfo *) tag)->mem_lower<<10,
((u64)((struct multiboot_tag_basic_meminfo *) tag)->mem_upper)<<10);
break;
case MULTIBOOT_TAG_TYPE_BOOTDEV:
printf ("Peripherique de demarrage : %X,%u,%u\r\n\r\n",
printf (" Peripherique de demarrage : %Y,%u,%u\r\n\r\n",
((struct multiboot_tag_bootdev *) tag)->biosdev,
((struct multiboot_tag_bootdev *) tag)->slice,
((struct multiboot_tag_bootdev *) tag)->part);
break;
case MULTIBOOT_TAG_TYPE_MMAP:
{
{
multiboot_memory_map_t *mmap;
printf ("*** Plan de memoire ***\r\n");
for (mmap = ((struct multiboot_tag_mmap *) tag)->entries;(u8 *) mmap < (u8 *) tag + tag->size; mmap = (multiboot_memory_map_t *)
((unsigned long) mmap + ((struct multiboot_tag_mmap *) tag)->entry_size))
printf (" adresse: %lX,"" taille:%lX, type:%X\r\n",
printf (" adresse: %lY, taille:%lY, type:%Y\r\n",
(u64) (mmap->addr),
(u64) (mmap->len),
(u32) (mmap->type));
}
break;
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
{
u32 color;
unsigned i;
struct multiboot_tag_framebuffer *tagfb
= (struct multiboot_tag_framebuffer *) tag;
void *fb = (void *) (unsigned long) tagfb->common.framebuffer_addr;
switch (tagfb->common.framebuffer_type)
{
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
{
unsigned best_distance, distance;
struct multiboot_color *palette;
palette = tagfb->framebuffer_palette;
color = 0;
best_distance = 4*256*256;
for (i = 0; i < tagfb->framebuffer_palette_num_colors; i++)
{
distance = (0xff - palette[i].blue)
* (0xff - palette[i].blue)
+ palette[i].red * palette[i].red
+ palette[i].green * palette[i].green;
if (distance < best_distance)
{
color = i;
best_distance = distance;
}
}
}
break;
case MULTIBOOT_FRAMEBUFFER_TYPE_RGB:
color = ((1 << tagfb->framebuffer_blue_mask_size) - 1)
<< tagfb->framebuffer_blue_field_position;
break;
case MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT:
color = '\\' | 0x0100;
break;
default:
color = 0xffffffff;
break;
}
for (i = 0; i < tagfb->common.framebuffer_width
&& i < tagfb->common.framebuffer_height; i++)
{
switch (tagfb->common.framebuffer_bpp)
{
case 8:
{
u8 *pixel = fb
+ tagfb->common.framebuffer_pitch * i + i;
*pixel = color;
}
break;
case 15:
case 16:
{
u16 *pixel
= fb + tagfb->common.framebuffer_pitch * i + 2 * i;
*pixel = color;
}
break;
case 24:
{
u32 *pixel
= fb + tagfb->common.framebuffer_pitch * i + 3 * i;
*pixel = (color & 0xffffff) | (*pixel & 0xff000000);
}
break;
case 32:
{
u32 *pixel
= fb + tagfb->common.framebuffer_pitch * i + 4 * i;
*pixel = color;
}
break;
}
}
break;
}
}
}
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
{
struct multiboot_tag_framebuffer *tagfb = (struct multiboot_tag_framebuffer *) tag;
printf (" Framebuffer, resolution %d*%d*%d adresse: %X, ",tagfb->common.framebuffer_width,tagfb->common.framebuffer_height,tagfb->common.framebuffer_bpp,tagfb->common.framebuffer_addr);
switch (tagfb->common.framebuffer_type)
{
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
printf ("mode graphique indexé\r\n");
break;
case MULTIBOOT_FRAMEBUFFER_TYPE_RGB:
printf ("mode graphique RGB\r\n");
break;
case MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT:
printf ("mode texte EGA\r\n");
break;
}
break;
}
case MULTIBOOT_TAG_TYPE_VBE:
{
struct multiboot_tag_vbe *tagvbe = (struct multiboot_tag_framebuffer *) tag;
printf (" VBE 2.0, mode %Y, adresse %hY:%hY-%hY\r\n", tagvbe->vbe_mode,tagvbe->vbe_interface_seg,tagvbe->vbe_interface_off,tagvbe->vbe_interface_len);
}
}
}
}
/*******************************************************************************/

View File

@ -375,7 +375,7 @@ int err(u8* commandline)
/* Information sur le démarrage */
int info()
{
getbootinfo();
getgrubinfo_all();
return 0;
}

View File

@ -18,45 +18,26 @@ static capabilities vesacapabilities[] = {
/*******************************************************************************/
/* Detecte si le hardware est disponible, return NULL ou pointeur sur le type de pilote */
u8 *VESA_detect_hardware(void) {
u32 addr=getblockinfo();
struct multiboot_tag *tag;
unsigned size = *(unsigned *) addr;
for (tag = (struct multiboot_tag *) (addr + 8);
tag->type != MULTIBOOT_TAG_TYPE_END;
tag = (struct multiboot_tag *) ((u8 *) tag + ((tag->size + 7) & ~7)))
{
switch (tag->type)
{
case MULTIBOOT_TAG_TYPE_FRAMEBUFFER:
{
struct multiboot_tag_framebuffer *tagfb = (struct multiboot_tag_framebuffer *) tag;
switch (tagfb->common.framebuffer_type)
{
case MULTIBOOT_FRAMEBUFFER_TYPE_RGB:
vesacapabilities[0].modenumber=0x0;
vesacapabilities[0].width=tagfb->common.framebuffer_width;
vesacapabilities[0].height=tagfb->common.framebuffer_height;
vesacapabilities[0].graphic=true;
vesacapabilities[0].depth=tagfb->common.framebuffer_bpp;
vesacapabilities[0].refresh=0x0;
infos.baseaddress=tagfb->common.framebuffer_addr;
infos.currentpitch=tagfb->common.framebuffer_pitch;
return "LEGACY";
break;
default:
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
case MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT:
return NULL;
break;
}
break;
}
}
}
struct multiboot_tag_framebuffer *tagfb = getgrubinfo_fb();
switch (tagfb->common.framebuffer_type)
{
case MULTIBOOT_FRAMEBUFFER_TYPE_RGB:
vesacapabilities[0].modenumber=0x0;
vesacapabilities[0].width=tagfb->common.framebuffer_width;
vesacapabilities[0].height=tagfb->common.framebuffer_height;
vesacapabilities[0].graphic=true;
vesacapabilities[0].depth=tagfb->common.framebuffer_bpp;
vesacapabilities[0].refresh=0x0;
infos.baseaddress=tagfb->common.framebuffer_addr;
infos.currentpitch=tagfb->common.framebuffer_pitch;
return "LEGACY";
break;
default:
case MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED:
case MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT:
return NULL;
break;
}
}
/*******************************************************************************/