working on TSS

This commit is contained in:
Adrien Bourmault 2019-05-13 18:07:45 +02:00
parent 3a42a811d2
commit cf86c19096
7 changed files with 88 additions and 19 deletions

View File

@ -162,6 +162,15 @@ $(KOBJDIR)/kernel/cpu/idt.o: $(KALEIDDIR)/kernel/cpu/idt.c \
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/mm/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c \
$(KALEIDDIR)/kernel/mm/gdt.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)
@$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/mm/gdt.asm -o $@.1
@$(KCC) $< -o $@.2
@$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@
@rm -f $@.1 $@.2
@echo ${CL2}[$@] ${CL}Compiled.${CL3}
$(KOBJDIR)/kernel/cpu/cpuid.o: $(KALEIDDIR)/kernel/cpu/cpuid.c \
$(KALEIDDIR)/kernel/cpu/cpuf.asm | $(KOBJDIR)
@mkdir -p $(shell dirname $@)

View File

@ -58,6 +58,8 @@ typedef struct MemoryMap_t MemoryMap_t;
typedef struct MapEntry_t MapEntry_t;
typedef struct GdtEntry_t GdtEntry_t;
typedef struct GdtPtr_t GdtPtr_t;
typedef struct TssEntry_t TssEntry_t;
typedef struct TssDescriptor_t TssDescriptor_t;
//----------------------------------------------------------------------------//

View File

@ -60,14 +60,40 @@ struct MemoryMap_t {
// The gdt
struct GdtEntry_t
{
ushort lowLimit; // lower 16 bits
ushort lowBase; // lower 16 bits
uchar middleBase; // next 8 bits
uchar access; // determine what ring this segment can be used in
uchar granularity;
uchar highBase; // last 8 bits
ushort lowLimit; // lower 16 bits
ushort lowBase; // lower 16 bits
uchar middleBase; // next 8 bits
uchar access; // determine what ring this segment can be used in
uchar granularity;
uchar highBase; // last 8 bits
} __attribute__((__packed__));
struct TssDescriptor_t
{
ushort limitLow;
ushort base00;
uchar base16;
uchar access;
uchar size;
uchar base24;
uint base32;
uint reserved;
} __attribute__ ((packed));
struct TssEntry_t
{
uint reserved0;
ulong privStackPointer[3]; // stack pointers for CPL 0-2
ulong intStackTable[8]; // /!\ [0] is reserved
ulong reserved1;
ushort reserved2;
ushort ioMapOffset;
} __attribute__ ((packed));
// The gdt pointer
struct GdtPtr_t
{
@ -106,7 +132,13 @@ void MmInitGdt(void);
//
// Loads the descriptor table
//
extern void MmLoadGdt(GdtPtr_t *GdtPtr);
extern void MmLoadGdt(ulong ds, ulong cs, ulong tr);
//
// Stores the descriptor table
//
extern void MmStoreGdt(void);
//----------------------------------------------------------------------------//

View File

@ -22,5 +22,7 @@
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
[BITS 64]
%include "kaleid/kernel/cpu/cpuf.inc"

View File

@ -22,6 +22,8 @@
; along with OS/K. If not, see <https://www.gnu.org/licenses/>. ;
;=----------------------------------------------------------------------------=;
[BITS 64]
%include "kaleid/kernel/cpu/cpuf.inc"
global IdtInit

View File

@ -44,7 +44,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
// Sanity checks
BtDoSanityChecks(mbMagic);
// Memory & scheduler
// Memory
MmInitMemoryMap();
// Interrupts launching

View File

@ -24,13 +24,11 @@
#include <kernel/mm.h>
// The Gdt
GdtEntry_t gdtEntries[5];
GdtEntry_t gdtEntries[5] = { 0 };
TssEntry_t tssEntry = { 0 };
GdtPtr_t gdtPtr;
#if 0
static void SetGdtEntry(int index, uint base, uint limit, uchar access,
uchar granularity)
static void SetGdtEntry(int index, uint base, uint limit, uchar access)
{
gdtEntries[index].lowBase = (base & 0xFFFF);
gdtEntries[index].middleBase = (base >> 16) & 0xFF;
@ -39,10 +37,30 @@ static void SetGdtEntry(int index, uint base, uint limit, uchar access,
gdtEntries[index].lowLimit = (limit & 0xFFFF);
gdtEntries[index].granularity = (limit >> 16) & 0x0F;
gdtEntries[index].granularity |= granularity & 0xF0;
gdtEntries[index].access = access;
gdtEntries[index].granularity |= 0xA0;
// 0x10 is system
// 0x80 is present
gdtEntries[index].access = access | 0x10 | 0x80;
}
static void SetTssEntry(uchar index, ulong base, ulong limit)
{
TssDescriptor_t tssDesc = { 0 };
tssDesc.limitLow = limit & 0xffff;
tssDesc.size = (limit >> 16) & 0xf;
tssDesc.base00 = base & 0xffff;
tssDesc.base16 = (base >> 16) & 0xff;
tssDesc.base24 = (base >> 24) & 0xff;
tssDesc.base32 = (base >> 32) & 0xffffffff;
tssDesc.reserved = 0;
tssDesc.access = 0x01 | 0x08 | 0x10 | 0x80;
memmove(&gdtEntries[index], &tssDesc, sizeof(TssDescriptor_t));
}
#endif
void MmInitGdt(void)
@ -50,11 +68,15 @@ void MmInitGdt(void)
gdtPtr.limit = (sizeof(GdtEntry_t) * 5) - 1;
gdtPtr.base = (uint)(ullong)&gdtEntries;
//SetGdtEntry(0,0,0,0,0);
MmStoreGdt();
/* XXX set TSS register */
/* SetGdtEntry(1, 0x0, 0xfffff, 0x02 | 0x08); */
//MmLoadGdt(&gdtPtr);
/* tssEntry.ioMapOffset = sizeof(TssEntry_t); */
/* SetTssEntry(2, (ulong)&tssEntry, sizeof(TssEntry_t)); */
/* MmLoadGdt(0x8, 0x0, 2 << 3); */
}