fix: execution du setup en mode reel fonctionnel, erreur sur A20

This commit is contained in:
Nicolas Hordé 2019-01-14 14:54:50 +01:00
parent d3abee6a74
commit b565d073c7
3 changed files with 89 additions and 56 deletions

View File

@ -2,6 +2,7 @@
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "types.h" #include "types.h"
#include "gdt.h"
#define E820_MAX_ENTRIES 128 #define E820_MAX_ENTRIES 128
@ -34,10 +35,68 @@ typedef struct miniregs {
u16 flags, hflags; u16 flags, hflags;
}; };
struct { struct {
u8 bl, bh, hbx2, hbx3;
u8 dl, dh, hdx2, hdx3;
u8 cl, ch, hcx2, hcx3;
u8 al, ah, hax2, hax3; u8 al, ah, hax2, hax3;
u8 bl, bh, hbx2, hbx3;
u8 cl, ch, hcx2, hcx3;
u8 dl, dh, hdx2, hdx3;
}; };
}; };
} miniregs __attribute__ ((packed)); } miniregs __attribute__ ((packed));
#define STRINGIFY(x) #x
#define MACRO(x) STRINGIFY(x)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
#define EFLAGS_CF 0x00000001
#define LOOPS_8042 100000
#define FF_8042 32
#define LOOPS_A20_ENABLE 255
#define LOOPS_DELAY 32768
#define SMAP 0x534d4150
#define interrupt(num, regs) ({\
asm("mov %[eflagsregs],%%eax\n\
pushl %%eax\n\
popfl\n\
mov %[eaxregs],%%eax\n\
mov %[ebxregs],%%ebx\n\
mov %[ecxregs],%%ecx\n\
mov %[edxregs],%%edx\n\
mov %[esiregs],%%esi\n\
mov %[ediregs],%%edi\n\
int %[numregs]\n\
pushfl\n\
popl %%eax\n\
mov %%eax,%[eflagsregs]\n\
mov %%eax,%[eaxregs]\n\
mov %%ebx,%[ebxregs]\n\
mov %%ecx,%[ecxregs]\n\
mov %%edx,%[edxregs]\n\
mov %%esi,%[esiregs]\n\
mov %%edi,%[ediregs]":[eaxregs] "+m" (regs.eax),[ebxregs] "+m" (regs.ebx),[ecxregs] "+m" (regs.ecx),[edxregs] "+m" (regs.edx),[esiregs] "+m" (regs.esi),[ediregs] "+m" (regs.edi),[eflagsregs] "+m" (regs.eflags):[numregs] "i" (num):"%eax","%ebx","%ecx","%edx","%esi","%edi");})
void cleanreg(miniregs *reg);
u8 initmemory(void);
void showchar(u8 achar);
void showstr(u8 *str);
u8 gettime(void);
u8 waitchar(void);
void initkeyboard(void);
u8 empty8042(void);
void iodelay(void);
u8 testA20(void);
void enableA20kbc(void);
void enableA20fast(void);
u8 enableA20(void);
void memset(void *dst, u8 val, u32 count, u32 size);
void memcpy(void *src, void *dst, u32 count, u32 size);
void initselectors(u32 executingoffset);
void makegdtdes(u32 base, u32 limite, u8 acces, u8 flags, gdtdes * desc);
void initgdt();
void maskinterrupts(void);
void initcoprocessor(void);
void initpmode(u32 offset);
void main(void);

View File

@ -1,5 +1,5 @@
GCC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -Wall -w -I ../../include -march=i386 -m16 -fomit-frame-pointer -fno-pie -no-pie -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387 -c GCC=gcc -O0 -g -nostdinc -ffreestanding -Wall -Wstrict-prototypes -fno-stack-protector -march=i386 -m16 -mpreferred-stack-boundary=2 -mregparm=3 -fno-pic -fno-strict-aliasing -mno-mmx -mno-sse -w -I ../../include -c
ASM=gcc -m16 -march=i386 -fomit-frame-pointer -fno-pie -no-pie -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387 -D__ASSEMBLY__ -I ../ -I ../../include -c -o ASM=gcc -O0 -m16 -march=i386 -fno-pic -D__ASSEMBLY__ -I ../ -I ../../include -c -o
LINK=ld -m elf_i386 -n LINK=ld -m elf_i386 -n
CONVERT=dos2unix CONVERT=dos2unix
INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl INDENT=indent -nhnl -l75 -ppi3 -ts8 -bls -nbc -di8 -nbad -nbap -nsob -i8 -bl -bli0 -ncdw -nce -cli8 -cbi0 -npcs -cs -saf -sai -saw -nprs -lp -npsl

View File

@ -1,10 +1,9 @@
/*******************************************************************************/ //*******************************************************************************/
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */ /* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
/* */ /* */
#include "types.h" #include "types.h"
#include "asm.h" #include "asm.h"
#include "setup.h" #include "setup.h"
#include "gdt.h"
#include "memory.h" #include "memory.h"
struct params { struct params {
@ -19,52 +18,13 @@ static struct gdtr gdtreg;
/* table de GDT */ /* table de GDT */
static gdtdes gdt[GDT_SIZE]; static gdtdes gdt[GDT_SIZE];
#define STRINGIFY(x) #x
#define MACRO(x) STRINGIFY(x)
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
#define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
u8 kernel_version[] = "COS2000 Version " MACRO(VERSION) "- compiled " __DATE__ ; u8 kernel_version[] = "COS2000 Version " MACRO(VERSION) "- compiled " __DATE__ ;
#define EFLAGS_CF 0x00000001
#define LOOPS_8042 100000
#define FF_8042 32
#define LOOPS_A20_ENABLE 255
#define LOOPS_DELAY 32768
#define SMAP 0x534d4150
#define interrupt(num, regs) ({\
asm("pushal\n\
mov %[eflagsregs],%%eax\n\
pushl %%eax\n\
popfl\n\
mov %[eaxregs],%%eax\n\
mov %[ebxregs],%%ebx\n\
mov %[ecxregs],%%ecx\n\
mov %[edxregs],%%edx\n\
mov %[esiregs],%%esi\n\
mov %[ediregs],%%edi\n\
mov %[ebpregs],%%ebp\n\
int %[numregs]\n\
pushfl\n\
popl %%eax\n\
mov %%eax,%[eflagsregs]\n\
mov %%eax,%[eaxregs]\n\
mov %%ebx,%[ebxregs]\n\
mov %%ecx,%[ecxregs]\n\
mov %%edx,%[edxregs]\n\
mov %%esi,%[esiregs]\n\
mov %%edi,%[ediregs]\n\
mov %%ebp,%[ebpregs]\n\
popal":[eaxregs] "+m" (regs.eax),[ebxregs] "+m" (regs.ebx),[ecxregs] "+m" (regs.ecx),[edxregs] "+m" (regs.edx),[esiregs] "+m" (regs.esi),[ediregs] "+m" (regs.edi),[ebpregs] "+m" (regs.ebp),[eflagsregs] "+m" (regs.eflags):[numregs] "i" (num):);})
u8 initmemory(void) u8 initmemory(void)
{ {
u32 count = 0; u32 count = 0;
miniregs reg; miniregs reg;
cleanreg(&reg);
entrye820 *desc = params.e820_table; entrye820 *desc = params.e820_table;
static struct entrye820 buf; static struct entrye820 buf;
do { do {
@ -86,9 +46,22 @@ u8 initmemory(void)
return params.e820_numbers= count; return params.e820_numbers= count;
} }
void showstr(u8 *str)
{
while (*str!='\000')
showchar(*str++);
}
void cleanreg(miniregs *reg)
{
for (u8 i;i<sizeof(miniregs);i++)
*((u8 *)reg+i)=0;
}
void showchar(u8 achar) void showchar(u8 achar)
{ {
miniregs reg; miniregs reg;
cleanreg(&reg);
reg.bx = 0x0007; reg.bx = 0x0007;
reg.cx = 0x0001; reg.cx = 0x0001;
reg.ah = 0x0e; reg.ah = 0x0e;
@ -96,15 +69,10 @@ void showchar(u8 achar)
interrupt(0x10, reg); /* INT 10 - VIDEO - TELETYPE OUTPUT */ interrupt(0x10, reg); /* INT 10 - VIDEO - TELETYPE OUTPUT */
} }
void showstr(u8 *str)
{
while (*str!='\000')
showchar(*str++);
}
u8 gettime(void) u8 gettime(void)
{ {
miniregs reg; miniregs reg;
cleanreg(&reg);
reg.ah = 0x02; reg.ah = 0x02;
interrupt(0x1a, reg); /* TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS) */ interrupt(0x1a, reg); /* TIME - GET REAL-TIME CLOCK TIME (AT,XT286,PS) */
return reg.dh; return reg.dh;
@ -113,6 +81,7 @@ u8 gettime(void)
u8 waitchar(void) u8 waitchar(void)
{ {
miniregs reg; miniregs reg;
cleanreg(&reg);
reg.ah = 0x00; reg.ah = 0x00;
interrupt(0x16, reg); /* INT 16 - KEYBOARD - GET KEYSTROKE */ interrupt(0x16, reg); /* INT 16 - KEYBOARD - GET KEYSTROKE */
return reg.al; return reg.al;
@ -121,6 +90,7 @@ u8 waitchar(void)
void initkeyboard(void) void initkeyboard(void)
{ {
miniregs reg; miniregs reg;
cleanreg(&reg);
reg.ah = 0x02; reg.ah = 0x02;
interrupt(0x16, reg); /* INT 16 - KEYBOARD - GET SHIFT FLAGS */ interrupt(0x16, reg); /* INT 16 - KEYBOARD - GET SHIFT FLAGS */
params.kbflag=reg.al; params.kbflag=reg.al;
@ -281,7 +251,8 @@ void initselectors(u32 executingoffset)
xor %%esi,%%esi\n\ xor %%esi,%%esi\n\
xor %%edi,%%edi\n\ xor %%edi,%%edi\n\
xor %%ebp,%%ebp\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)); jmp %%ebx\n\
.code16gcc"::[data] "i"(SEL_KERNEL_DATA),[code] "i"(SEL_KERNEL_CODE),[stack] "i"(SEL_KERNEL_STACK),[stackoff] "i"(KERNEL_STACK_ADDR),[offset] "m"(executingoffset));
} }
/*******************************************************************************/ /*******************************************************************************/
@ -353,12 +324,15 @@ void initpmode(u32 offset)
void main(void) void main(void)
{ {
showstr("Chargement de COS2000 - mode reel"); showstr("*** Chargement de COS2000 - mode reel ***\r\n");
waitchar();
/* initparams(); */ /* initparams(); */
showstr(" -Initialisation de la memoire\r\n");
initmemory(); initmemory();
showstr(" -Initialisation du clavier\r\n");
initkeyboard(); initkeyboard();
/* initvideo(); */ /* initvideo(); */
showstr(" -Initialisation du coprocesseur\r\n");
initcoprocessor(); initcoprocessor();
showstr(" -Passage en mode protege\r\n");
initpmode(0x10000); initpmode(0x10000);
} }