feat: ajout GDT user, CPUID ajouts, noyaux 0x100000, syscall par sysenter préparation
This commit is contained in:
parent
93897a6cce
commit
a12ddfa03b
|
@ -1,8 +1,8 @@
|
||||||
target remote localhost:1234
|
target remote localhost:1234
|
||||||
set disassembly-flavor intel
|
set disassembly-flavor intel
|
||||||
set architecture i386
|
set architecture i386
|
||||||
break *0x50000
|
break *0x100000
|
||||||
cont
|
cont
|
||||||
symbol-file ./system/system.sys
|
symbol-file ./system/system.sys
|
||||||
clear *0x50000
|
clear *0x100000
|
||||||
display/20i $pc
|
display/20i $pc
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
|
|
||||||
#define sgdt(gdtr) asm ("sgdtl %0"::"m" (*gdtr))
|
#define sgdt(gdtr) asm ("sgdtl %0"::"m" (*gdtr))
|
||||||
|
|
||||||
|
#define wrmsr(reg,low,high) asm volatile ("wrmsr" :: "c" (reg), "a" (low), "d" (high))
|
||||||
|
|
||||||
|
#define rdmsr(reg,low,high) asm volatile ("rdmsr" :: "=a" (low), "=d" (high) : "c" (reg) )
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
#define outb(port,value) \
|
#define outb(port,value) \
|
||||||
|
|
|
@ -24,6 +24,14 @@ bool now3d;
|
||||||
bool now3d2;
|
bool now3d2;
|
||||||
bool htt;
|
bool htt;
|
||||||
bool apic;
|
bool apic;
|
||||||
|
bool bits64;
|
||||||
|
bool syscall;
|
||||||
|
bool msr;
|
||||||
|
bool sse4a;
|
||||||
|
bool vmx;
|
||||||
|
bool sse41;
|
||||||
|
bool sse42;
|
||||||
|
bool apic2;
|
||||||
} cpuinfo __attribute__ ((packed));
|
} cpuinfo __attribute__ ((packed));
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,16 @@
|
||||||
#include <types.h>
|
#include <types.h>
|
||||||
|
|
||||||
|
/* Ordre imposé par SYSENTER */
|
||||||
#define SEL_KERNEL_CODE 0x8 /* selecteur code du kernel */
|
#define SEL_KERNEL_CODE 0x8 /* selecteur code du kernel */
|
||||||
#define SEL_KERNEL_DATA 0x10 /* selecteur data du kernel */
|
#define SEL_KERNEL_STACK 0x10 /* selecteur pile du kernel */
|
||||||
#define SEL_KERNEL_STACK 0x18 /* selecteur pile du kernel */
|
#define SEL_USER_CODE 0x18 /* selecteur code utilisateur */
|
||||||
#define STACK_OFFSET 0x20000 /* adresse de la pile du kernel */
|
#define SEL_USER_STACK 0x20 /* selecteur pile utilisateur */
|
||||||
|
#define SEL_KERNEL_DATA 0x28 /* selecteur data du kernel */
|
||||||
|
#define SEL_USER_DATA 0x30 /* selecteur data utilisateur */
|
||||||
|
|
||||||
#define SIZEGDT 0x4 /* nombre de descripteurs */
|
#define STACK_OFFSET 0xFFFF /* adresse de la pile du kernel */
|
||||||
|
|
||||||
|
#define SIZEGDT 0x7 /* nombre de descripteurs */
|
||||||
#define BASEGDT 0x00000800 /* addr de la GDT */
|
#define BASEGDT 0x00000800 /* addr de la GDT */
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,5 +29,22 @@ struct gdtr {
|
||||||
u32 base;
|
u32 base;
|
||||||
} __attribute__ ((packed));
|
} __attribute__ ((packed));
|
||||||
|
|
||||||
|
struct tss {
|
||||||
|
u16 previous_task, __previous_task_unused;
|
||||||
|
u32 esp0;
|
||||||
|
u16 ss0, __ss0_unused;
|
||||||
|
u32 esp1;
|
||||||
|
u16 ss1, __ss1_unused;
|
||||||
|
u32 esp2;
|
||||||
|
u16 ss2, __ss2_unused;
|
||||||
|
u32 cr3;
|
||||||
|
u32 eip, eflags, eax, ecx, edx, ebx, esp, ebp, esi, edi;
|
||||||
|
u16 es, __es_unused;
|
||||||
|
u16 cs, __cs_unused;
|
||||||
|
u16 ss, __ss_unused;
|
||||||
|
u16 ds, __ds_unused;
|
||||||
|
u16 fs, __fs_unused;
|
||||||
|
u16 gs, __gs_unused;
|
||||||
|
u16 ldt_selector, __ldt_sel_unused;
|
||||||
|
u16 debug_flag, io_map;
|
||||||
|
} __attribute__ ((packed));
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
void initsyscall(void);
|
||||||
|
void sysenter_handler(void);
|
17
lib/cpu.c
17
lib/cpu.c
|
@ -18,6 +18,14 @@ static u8 *msg[] = {
|
||||||
"3dNow Extended!",
|
"3dNow Extended!",
|
||||||
"HyperThreading",
|
"HyperThreading",
|
||||||
"apic",
|
"apic",
|
||||||
|
"64bits",
|
||||||
|
"syscall",
|
||||||
|
"msr",
|
||||||
|
"sse4a",
|
||||||
|
"vmx",
|
||||||
|
"sse41",
|
||||||
|
"sse42",
|
||||||
|
"apic2"
|
||||||
};
|
};
|
||||||
|
|
||||||
static u8 space[] = " ";
|
static u8 space[] = " ";
|
||||||
|
@ -80,7 +88,10 @@ u8 getcpuinfos(cpuinfo * proc)
|
||||||
proc->sse3 = (regecx & 0x00000001);
|
proc->sse3 = (regecx & 0x00000001);
|
||||||
proc->fpu = (regedx & 0x00000001);
|
proc->fpu = (regedx & 0x00000001);
|
||||||
proc->htt = ((regedx >> 28) & 0x00000001);
|
proc->htt = ((regedx >> 28) & 0x00000001);
|
||||||
|
proc->vmx = ((regecx >> 5) & 0x00000001);
|
||||||
|
proc->sse41 = ((regecx >> 19) & 0x00000001);
|
||||||
|
proc->sse42 = ((regecx >> 20) & 0x00000001);
|
||||||
|
proc->apic2 = ((regecx >> 21) & 0x00000001);
|
||||||
}
|
}
|
||||||
if (maxextended >= 1) {
|
if (maxextended >= 1) {
|
||||||
cpuid(0x80000001, ®eax, ®ebx, ®ecx, ®edx);
|
cpuid(0x80000001, ®eax, ®ebx, ®ecx, ®edx);
|
||||||
|
@ -88,6 +99,10 @@ u8 getcpuinfos(cpuinfo * proc)
|
||||||
proc->apic = ((regedx >> 9) & 0x00000001);
|
proc->apic = ((regedx >> 9) & 0x00000001);
|
||||||
proc->now3d = ((regedx >> 30) & 0x00000001);
|
proc->now3d = ((regedx >> 30) & 0x00000001);
|
||||||
proc->now3d2 = ((regedx >> 31) & 0x00000001);
|
proc->now3d2 = ((regedx >> 31) & 0x00000001);
|
||||||
|
proc->bits64 = ((regedx >> 29) & 0x00000001);
|
||||||
|
proc->syscall = ((regedx >> 11) & 0x00000001);
|
||||||
|
proc->msr = ((regedx >> 5) & 0x00000001);
|
||||||
|
proc->sse4a = ((regecx >> 6) & 0x00000001);
|
||||||
}
|
}
|
||||||
if (maxextended >= 4) {
|
if (maxextended >= 4) {
|
||||||
int i;
|
int i;
|
||||||
|
|
10
lib/gdt.c
10
lib/gdt.c
|
@ -15,10 +15,14 @@ static gdtdes gdt[SIZEGDT];
|
||||||
|
|
||||||
void initgdt(u32 offset)
|
void initgdt(u32 offset)
|
||||||
{
|
{
|
||||||
makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* selecteur nulle */
|
makegdtdes(0x0, 0x00000, 0x00, 0x00, &gdt[0]); /* selecteur nul */
|
||||||
makegdtdes(0x0, 0xFFFFF, 0x9B, 0x0D, &gdt[1]); /* code -> SEL_KERNEL_CODE */
|
makegdtdes(0x0, 0xFFFFF, 0x9B, 0x0D, &gdt[1]); /* code -> SEL_KERNEL_CODE */
|
||||||
makegdtdes(0x0, 0xFFFFF, 0x93, 0x0D, &gdt[2]); /* data -> SEL_KERNEL_DATA */
|
makegdtdes(0x0, 0x00000, 0x97, 0x0D, &gdt[2]); /* pile -> SEL_KERNEL_STACK */
|
||||||
makegdtdes(0x0, 0x00000, 0x97, 0x0D, &gdt[3]); /* pile -> SEL_KERNEL_STACK */
|
makegdtdes(0x0, 0xFFFFF, 0xFF, 0x0D, &gdt[3]); /* code -> SEL_USER_CODE */
|
||||||
|
makegdtdes(0x0, 0x00000, 0xF7, 0x0D, &gdt[4]); /* pile -> SEL_USER_STACK */
|
||||||
|
makegdtdes(0x0, 0xFFFFF, 0x93, 0x0D, &gdt[5]); /* data -> SEL_KERNEL_DATA */
|
||||||
|
makegdtdes(0x0, 0xFFFFF, 0xF3, 0x0D, &gdt[6]); /* data -> SEL_USER_DATA */
|
||||||
|
|
||||||
/* initialise le registre gdt */
|
/* initialise le registre gdt */
|
||||||
gdtreg.limite = SIZEGDT * 8;
|
gdtreg.limite = SIZEGDT * 8;
|
||||||
gdtreg.base = BASEGDT;
|
gdtreg.base = BASEGDT;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include
|
CC=gcc -O0 -g -nostdinc -ffreestanding -fno-builtin -fomit-frame-pointer -Wall -w -m32 -F pe-i386 -I ../include
|
||||||
LINK=ld -m elf_i386 -r -o
|
LINK=ld -m elf_i386 -r -o
|
||||||
OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o gdt.o shell.o
|
OBJS=memory.o vga.o video.o mouse.o interrupts.o timer.o keyboard.o types.o string.o 2d.o 3d.o math.o cpu.o gdt.o shell.o syscall.o
|
||||||
|
|
||||||
all: makeall
|
all: makeall
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
#include <types.h>
|
||||||
|
#include <gdt.h>
|
||||||
|
#include <asm.h>
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
|
||||||
|
/* Entrée pour les appels système SYSENTER */
|
||||||
|
|
||||||
|
void sysenter_handler(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*******************************************************************************/
|
||||||
|
|
||||||
|
/* Initialise les appels système par SYSENTER/SYSEXIT */
|
||||||
|
|
||||||
|
void initsyscall(void)
|
||||||
|
{
|
||||||
|
wrmsr(0x174, SEL_KERNEL_CODE, 0x0);
|
||||||
|
wrmsr(0x175, STACK_OFFSET, 0x0);
|
||||||
|
wrmsr(0x176, &sysenter_handler, 0x0);
|
||||||
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ ENTRY(mymain)
|
||||||
|
|
||||||
SECTIONS
|
SECTIONS
|
||||||
{
|
{
|
||||||
. = 0x50000;
|
. = 0x100000;
|
||||||
.text ALIGN(16): {
|
.text ALIGN(16): {
|
||||||
*(.text)
|
*(.text)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "ansi.c"
|
#include "ansi.c"
|
||||||
#include "gdt.h"
|
#include "gdt.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
#include "syscall.h"
|
||||||
|
|
||||||
static u8 warnmsg[] =
|
static u8 warnmsg[] =
|
||||||
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
|
"\033[99C\033[8D\033[37m\033[1m[ \033[36mNON\033[37m ]\033[0m\000";
|
||||||
|
@ -79,5 +80,10 @@ next:
|
||||||
warning();
|
warning();
|
||||||
else
|
else
|
||||||
ok();
|
ok();
|
||||||
|
|
||||||
|
print(" -Installation des appels systemes utilisateur\000");
|
||||||
|
initsyscall();
|
||||||
|
ok();
|
||||||
|
|
||||||
shell();
|
shell();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue