feat: premier boot opérationnel avec la commande linux16 de GRUB, reste la gestion VESA
This commit is contained in:
parent
63f7e530cc
commit
4f7aae792e
|
@ -6,5 +6,5 @@ break *0x90200
|
|||
cont
|
||||
clear *0x90200
|
||||
break main
|
||||
cont
|
||||
###cont
|
||||
clear main
|
||||
|
|
|
@ -3,6 +3,9 @@ set disassembly-flavor att
|
|||
set architecture i386
|
||||
symbol-file ./system/system.sym
|
||||
break start
|
||||
break system.c:50
|
||||
break *0x100000
|
||||
cont
|
||||
clear *0x100000
|
||||
si
|
||||
break *0x100000
|
||||
cont
|
||||
clear system.c:50
|
||||
|
|
Binary file not shown.
|
@ -22,7 +22,7 @@ set timeout=4\n\
|
|||
set default=0\n\
|
||||
menuentry "cos2000" {\n\
|
||||
set root=(hd0,1)\n\
|
||||
linux16 /boot/system.sys\n
|
||||
linux16 /boot/system.sys root=hd0,2\n
|
||||
boot\n\
|
||||
}" > /mnt/boot/grub/grub.cfg
|
||||
umount /mnt
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
/* Sources modifiées du noyau Linux linux-source-4.15.0/arch/x86/include/uapi/asm/bootparam.h
|
||||
/* Sources modifiées du noyau Linux linux-source-4.15.0/arch/x86/include/asm/e820/type.h
|
||||
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
|
||||
#ifndef _BOOT
|
||||
#define _BOOT
|
||||
|
||||
#include "types.h"
|
||||
#include "gdt.h"
|
||||
|
||||
#define E820_MAX_ENTRIES 128
|
||||
|
||||
typedef struct entrye820 {
|
||||
u64 addr;
|
||||
u64 size;
|
||||
u32 type;
|
||||
} entrye820 __attribute__((packed));
|
||||
|
||||
typedef struct bootparams {
|
||||
entrye820 e820_table[E820_MAX_ENTRIES];
|
||||
u32 e820_numbers;
|
||||
u8* cmdline;
|
||||
u8 kbflag;
|
||||
} bootparams;
|
||||
|
||||
|
||||
enum e820_type {
|
||||
E820_TYPE_RAM = 1,
|
||||
E820_TYPE_RESERVED = 2,
|
||||
E820_TYPE_ACPI = 3,
|
||||
E820_TYPE_NVS = 4,
|
||||
E820_TYPE_UNUSABLE = 5,
|
||||
E820_TYPE_PMEM = 7,
|
||||
E820_TYPE_PRAM = 12,
|
||||
E820_TYPE_RESERVED_KERN = 128,
|
||||
};
|
||||
|
||||
typedef struct header {
|
||||
u8 setup_sects;
|
||||
u16 root_flags;
|
||||
u32 syssize;
|
||||
u16 ram_size;
|
||||
u16 vid_mode;
|
||||
u16 root_dev;
|
||||
u16 boot_flag;
|
||||
u16 jump;
|
||||
u32 header;
|
||||
u16 version;
|
||||
u32 realmode_swtch;
|
||||
u16 start_sys_seg;
|
||||
u16 kernel_version;
|
||||
u8 type_of_loader;
|
||||
u8 loadflags;
|
||||
u16 setup_move_size;
|
||||
u32 code32_start;
|
||||
u32 ramdisk_image;
|
||||
u32 ramdisk_size;
|
||||
u32 bootsect_kludge;
|
||||
u16 heap_end_ptr;
|
||||
u8 ext_loader_ver;
|
||||
u8 ext_loader_type;
|
||||
u32 cmd_line_ptr;
|
||||
u32 initrd_addr_max;
|
||||
u32 kernel_alignment;
|
||||
u8 relocatable_kernel;
|
||||
u8 min_alignment;
|
||||
u16 xloadflags;
|
||||
u32 cmdline_size;
|
||||
u32 hardware_subarch;
|
||||
u64 hardware_subarch_data;
|
||||
u32 payload_offset;
|
||||
u32 payload_length;
|
||||
u64 setup_data;
|
||||
u64 pref_address;
|
||||
u32 init_size;
|
||||
u32 handover_offset;
|
||||
} __attribute__((packed)) header;
|
||||
|
||||
#endif
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef _GDT
|
||||
#define _GDT
|
||||
|
||||
/* Ordre imposé par SYSENTER */
|
||||
#define SEL_KERNEL_CODE 0x8 /* Selecteur code du kernel */
|
||||
#define SEL_KERNEL_STACK 0x10 /* Selecteur pile du kernel */
|
||||
|
@ -93,3 +96,4 @@ u16 getdesalign(u16 sel);
|
|||
void setTSS(u32 ss, u32 sp);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
|
||||
#include "types.h"
|
||||
#include "queue.h"
|
||||
#include "boot.h"
|
||||
|
||||
/* Malloc, pour l'attribution de mémoire en heap */
|
||||
typedef struct tmalloc
|
||||
|
@ -114,8 +115,8 @@ typedef TAILQ_HEAD(page_s, page) page_t;
|
|||
void physical_range_use(u64 addr, u64 len);
|
||||
void physical_range_free(u64 addr, u64 len);
|
||||
u8 *physical_page_getfree(void);
|
||||
void physical_init(void);
|
||||
void initpaging(void);
|
||||
void physical_init();
|
||||
void initpaging();
|
||||
void virtual_init(void);
|
||||
tmalloc *mallocpage(u64 size);
|
||||
void *vmalloc(u32 size);
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
/* Sources modifiées du noyau Linux linux-source-4.15.0/arch/x86/include/uapi/asm/bootparam.h
|
||||
/* Sources modifiées du noyau Linux linux-source-4.15.0/arch/x86/include/asm/e820/type.h
|
||||
|
||||
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
|
||||
|
||||
#include "types.h"
|
||||
#include "gdt.h"
|
||||
|
||||
#define E820_MAX_ENTRIES 128
|
||||
|
||||
typedef struct entrye820 {
|
||||
u64 addr;
|
||||
u64 size;
|
||||
u32 type;
|
||||
} entrye820 __attribute__((packed));
|
||||
#include "boot.h"
|
||||
|
||||
typedef struct miniregs {
|
||||
union {
|
||||
|
@ -70,8 +68,7 @@ typedef struct miniregs {
|
|||
mov %[ediregs],%%edi\n\
|
||||
int %[numregs]\n\
|
||||
pushfl\n\
|
||||
popl %%eax\n\
|
||||
mov %%eax,%[eflagsregs]\n\
|
||||
popl %[eflagsregs]\n\
|
||||
mov %%eax,%[eaxregs]\n\
|
||||
mov %%ebx,%[ebxregs]\n\
|
||||
mov %%ecx,%[ecxregs]\n\
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
/*******************************************************************************/
|
||||
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
||||
/* */
|
||||
|
||||
#include "boot.h";
|
||||
|
||||
extern restart;
|
||||
int main(u8* info);
|
||||
|
|
|
@ -71,10 +71,13 @@ void initselectors(u32 executingoffset)
|
|||
movw %%ax, %%es \n \
|
||||
movw %%ax, %%fs \n \
|
||||
movw %%ax, %%gs \n \
|
||||
movl %[offset], %%ebx \n \
|
||||
movw %[stack], %%ax \n \
|
||||
movl %[offset], %%ebx \n \
|
||||
movw %%ax, %%ss \n \
|
||||
movl %[stackoff], %%esp \n \
|
||||
pushl %%ebx \n \
|
||||
ljmp %[code],$raz \n \
|
||||
raz:\n \
|
||||
xor %%eax,%%eax\n\
|
||||
xor %%ebx,%%ebx\n\
|
||||
xor %%ecx,%%ecx\n\
|
||||
|
@ -82,7 +85,7 @@ void initselectors(u32 executingoffset)
|
|||
xor %%esi,%%esi\n\
|
||||
xor %%edi,%%edi\n\
|
||||
xor %%ebp,%%ebp\n\
|
||||
jmp %%ebx"::[data] "i"(SEL_KERNEL_DATA),[code] "i"(SEL_KERNEL_CODE),[stack] "i"(SEL_KERNEL_STACK),[stackoff] "i"(KERNEL_STACK_ADDR),[offset] "m"(executingoffset));
|
||||
ret"::[data] "i"(SEL_KERNEL_DATA),[code] "i"(SEL_KERNEL_CODE),[stack] "i"(SEL_KERNEL_STACK),[stackoff] "i"(KERNEL_STACK_ADDR),[offset] "m"(executingoffset));
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
|
49
lib/memory.c
49
lib/memory.c
|
@ -5,10 +5,14 @@
|
|||
#include "memory.h"
|
||||
#include "queue.h"
|
||||
#include "asm.h"
|
||||
#include "boot.h"
|
||||
|
||||
static u8 *kernelcurrentheap = NULL; /* pointeur vers le heap noyau */
|
||||
static u8 bitmap[MAXMEMPAGE / 8]; /* bitmap */
|
||||
static vrange_t vrange_head;
|
||||
static u64 memorysize=0;
|
||||
|
||||
extern bootparams* allparams;
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Erreur fatale */
|
||||
|
@ -154,20 +158,7 @@ void vfree(void *vaddr)
|
|||
|
||||
u64 physical_getmemorysize()
|
||||
{
|
||||
/*u64 maxaddr = 0;
|
||||
struct multiboot_tag_mmap *tag = getgrubinfo_mem();
|
||||
multiboot_memory_map_t *mmap;
|
||||
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))
|
||||
if ((mmap->addr + mmap->len > maxaddr) && mmap->type == 1)
|
||||
maxaddr = mmap->addr + mmap->len;
|
||||
if (maxaddr >= MAXMEMSIZE)
|
||||
maxaddr = MAXMEMSIZE - 1;
|
||||
return maxaddr;*/
|
||||
return memorysize;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
@ -258,24 +249,22 @@ u64 getmemoryfree(void)
|
|||
/*******************************************************************************/
|
||||
/* Initialisation du bitmap pour la gestion physique de la mémoire */
|
||||
|
||||
void physical_init(void)
|
||||
void physical_init()
|
||||
{
|
||||
/*u64 page;
|
||||
for (page = 0; page < sizeof(bitmap); page++)
|
||||
for (u64 page = 0; page < sizeof(bitmap); page++)
|
||||
bitmap[page] = 0xFF;
|
||||
struct multiboot_tag_mmap *tag = getgrubinfo_mem();
|
||||
multiboot_memory_map_t *mmap;
|
||||
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))
|
||||
if (mmap->type == 1)
|
||||
physical_range_free(mmap->addr, mmap->len);
|
||||
for (u8 i=0;i<allparams->e820_numbers;i++)
|
||||
{
|
||||
if (allparams->e820_table[i].type == E820_TYPE_RAM)
|
||||
physical_range_free(allparams->e820_table[i].addr, allparams->e820_table[i].size);
|
||||
else
|
||||
physical_range_use(mmap->addr, mmap->len);
|
||||
physical_range_use(0x0, KERNELSIZE);*/
|
||||
physical_range_use(allparams->e820_table[i].addr, allparams->e820_table[i].size);
|
||||
if ((allparams->e820_table[i].addr + allparams->e820_table[i].size > memorysize) && allparams->e820_table[i].type == E820_TYPE_RAM)
|
||||
memorysize = allparams->e820_table[i].addr + allparams->e820_table[i].size;
|
||||
if (memorysize >= MAXMEMSIZE)
|
||||
memorysize = MAXMEMSIZE - 1;
|
||||
}
|
||||
physical_range_use(0x0, KERNELSIZE);
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
@ -668,7 +657,7 @@ void registry_init(void)
|
|||
/*******************************************************************************/
|
||||
/* Initialisation de la mémoire paginée */
|
||||
|
||||
void initpaging(void)
|
||||
void initpaging()
|
||||
{
|
||||
identity_init();
|
||||
registry_init();
|
||||
|
|
2
makefile
2
makefile
|
@ -139,7 +139,7 @@ qemu64: killer
|
|||
qemu-system-x86_64 -m 5G -drive format=raw,file=./final/harddiskuefi.img.final --bios /usr/share/qemu/OVMF.fd --enable-kvm -cpu host -s &
|
||||
|
||||
system/system.sys:
|
||||
make -C system VESA=$(VESA)
|
||||
make -C system
|
||||
|
||||
final/harddisk.img.final:
|
||||
make -C final harddisk.img.final
|
||||
|
|
|
@ -35,7 +35,7 @@ piggy.o: piggy.S
|
|||
$(ASM) $@ $^
|
||||
|
||||
system: system.o system_asm.o ../lib/libs.o
|
||||
$(LINK) -T system.ld system.o ../lib/libs.o
|
||||
$(LINK) -T system.ld system.o system_asm.o ../lib/libs.o
|
||||
$(OBJDEBUG) system system.sym
|
||||
$(NM) system > system.map
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
#include "setup.h"
|
||||
#include "memory.h"
|
||||
|
||||
struct params {
|
||||
entrye820 e820_table[E820_MAX_ENTRIES];
|
||||
u32 e820_numbers;
|
||||
u8 kbflag;
|
||||
} params;
|
||||
extern hdr;
|
||||
|
||||
/* paramètres de démarrage */
|
||||
static bootparams params;
|
||||
|
||||
/* registre gdt */
|
||||
static struct gdtr gdtreg;
|
||||
|
@ -273,17 +272,31 @@ void initpmode()
|
|||
gotopmode();
|
||||
}
|
||||
|
||||
void initparams()
|
||||
{
|
||||
//params.cmdline=((header*)hdr)->cmd_line_ptr;
|
||||
asm("xorl %%eax,%%eax\n \
|
||||
movw %%ds,%%ax\n \
|
||||
shl $4,%%eax\n \
|
||||
addw %[bootparams],%%ax \n \
|
||||
movl %%eax,%%cr3"::[bootparams] "i" (¶ms));
|
||||
}
|
||||
|
||||
void initvideo()
|
||||
{
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
showstr("*** Chargement de COS2000 - mode reel ***\r\n");
|
||||
/* initparams(); */
|
||||
initparams();
|
||||
showstr(" -Initialisation de la memoire\r\n");
|
||||
initmemory();
|
||||
showstr(" -Initialisation du clavier\r\n");
|
||||
initkeyboard();
|
||||
/* initvideo(); */
|
||||
showstr(" -Initialisation du coprocesseur\r\n");
|
||||
initcoprocessor();
|
||||
showstr(" -Passage en mode protege\r\n");
|
||||
showstr(" -Initialisation video & passage en mode protege\r\n");
|
||||
initvideo();
|
||||
initpmode();
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "syscall.h"
|
||||
#include "memory.h"
|
||||
#include "system.h"
|
||||
#include "boot.h"
|
||||
|
||||
static u8 warnmsg[] =
|
||||
"\033[150C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m";
|
||||
|
@ -28,6 +29,8 @@ static u8 key = 0;
|
|||
extern wrapper_timer;
|
||||
extern wrapper_interruption20;
|
||||
|
||||
bootparams* allparams;
|
||||
|
||||
void ok()
|
||||
{
|
||||
print(okmsg);
|
||||
|
@ -46,9 +49,10 @@ void error()
|
|||
return;
|
||||
}
|
||||
|
||||
int main(u8* info)
|
||||
void main(bootparams** params)
|
||||
{
|
||||
cli();
|
||||
allparams=params;
|
||||
initdriver();
|
||||
registerdriver(&vgafonctions);
|
||||
registerdriver(&vesafonctions);
|
||||
|
@ -62,7 +66,7 @@ int main(u8* info)
|
|||
print("\033[37m\033[0m -Initilisation de la memoire virtuelle");
|
||||
initgdt(&&next);
|
||||
next:
|
||||
initpaging();
|
||||
initpaging(*allparams);
|
||||
remap_memory(VESA_FBMEM);
|
||||
ok();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ SECTIONS
|
|||
. = 0x100000;
|
||||
.text ALIGN(16): {
|
||||
_text = .;
|
||||
*(.inittext)
|
||||
*(.text)
|
||||
}
|
||||
.data ALIGN(16): {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include "gdt.h"
|
||||
|
||||
.code32
|
||||
.section ".text"
|
||||
.section ".inittext"
|
||||
.global start
|
||||
.extern main
|
||||
start:
|
||||
|
@ -17,7 +17,9 @@ start:
|
|||
movw %ax, %gs
|
||||
movw $SEL_KERNEL_STACK, %ax
|
||||
movw %ax, %ss
|
||||
movl $KERNEL_STACK_ADDR, %esp
|
||||
movl %cr3, %eax
|
||||
mov $KERNEL_STACK_ADDR,%esp
|
||||
pushl %eax
|
||||
xor %eax,%eax
|
||||
xor %ebx,%ebx
|
||||
xor %ecx,%ecx
|
||||
|
@ -25,4 +27,4 @@ start:
|
|||
xor %esi,%esi
|
||||
xor %edi,%edi
|
||||
xor %ebp,%ebp
|
||||
call main
|
||||
calll main
|
||||
|
|
Loading…
Reference in New Issue