Esempio n. 1
0
File: gdt.c Progetto: neal024/Okusha
/*
 * Initialize The Global Descriptor Table
 * Should be called by kernel_main. This will setup the special GDT
 * pointer, set up the first 3 entries in our GDT, and then
 * finally call gdt_flush() in our assembler file in order
 * to tell the processor where the new GDT is and update the
 * new segment registers
 */
void gdt_install(void)
{
    /* Setup the GDT pointer and limit */
    gdt_p.limit = (sizeof(struct gdt_entry) * 3) - 1;
    gdt_p.base  = (uint32_t)&gdt;

    /* Our NULL descriptor */
	gdt_set_entry(SEG_NULL, 0, 0, 0, 0);

    /* The second entry is our Code Segment. The base address
    *  is 0, the limit is 4GBytes, it uses 4KByte granularity,
    *  uses 32-bit opcodes, and is a Code Segment descriptor.
    *  Please check the table above in the tutorial in order
    *  to see exactly what each value means */
	//gdt_set_entry(SEG_CODE, 0, 64*1024*1024, 0x9A, 0xCF);	/* Kernel Code Segment */
	gdt_set_entry(SEG_CODE, 0, 0xFFFFFFFF, 0x9A, 0xCF);	/* Kernel Code Segment */

    /* The third entry is our Data Segment. It's EXACTLY the
    *  same as our code segment, but the descriptor type in
    *  this entry's access byte says it's a Data Segment */
	//gdt_set_entry(SEG_DATA, 0, 64*1024*1024, 0x92, 0xCF);	/* Kernel Data Segment */
	gdt_set_entry(SEG_DATA, 0, 0xFFFFFFFF, 0x92, 0xCF);	/* Kernel Data Segment */

	//gdt_set_entry(SEG_USR1, 0, 64*1024*1024, 0xFA, 0xCF);	/* User-Mode Segment 1 */
	//gdt_set_entry(SEG_USR2, 0, 64*1024*1024, 0xF2, 0xCF);	/* User-Mode Segment 2 */
	//gdt_set_entry(SEG_TSS, 0, 0, 0, 0);

    /* Flush out the old GDT and install the new changes! */
    gdt_flush();
}
Esempio n. 2
0
/* Set up and install our three segments */
void gdt_install()
{
	gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
	gp.base = (unsigned long)&gdt;

	gdt_set_entry(0, 0, 0, 0, 0);
	gdt_set_entry(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
	gdt_set_entry(2, 0, 0xFFFFFFFF, 0x92, 0xCF);

	gdt_set();
}
Esempio n. 3
0
void gdt_init() {
    gdt_set_entry(0, 0, 0, 0);
    gdt_set_entry(1, 0, 0xFFFFFFFF, 0x9A);
    gdt_set_entry(2, 0, 0xFFFFFFFF, 0x92);
    gdt_set_entry(3, 0, 0xFFFFFFFF, 0xFA);
    gdt_set_entry(4, 0, 0xFFFFFFFF, 0xF2);
    
    ptr.base = (uint32_t) &gdt_tab;
    ptr.limit = (sizeof(struct gdt_info) * GDT_LEN) - 1;
    
    gdt_set(&ptr);
}
Esempio n. 4
0
bool gdt_setup(void)
{
	bool status;
	gdt_location.limit = (sizeof(struct gdt_entry) * BERMUDOS_GDT_NB_ENTRY) - 1;
	gdt_location.base = (uint32_t)&kernel_GDT;

	status = gdt_set_entry(0, (uint32_t)(NULL), 0, 0, 0)  /* The GDT MUST start with a NULL entry */
		&& gdt_set_entry(1, (uint32_t)(NULL), 0xFFFFFFFF, GDT_ENTRY_DATA_SEGMENT, GDT_GRANULARITY_4KiB | GDT_PROTECTED_32_BIT)
		&& gdt_set_entry(2, (uint32_t)(NULL), 0xFFFFFFFF, GDT_ENTRY_CODE_SEGMENT, GDT_GRANULARITY_4KiB | GDT_PROTECTED_32_BIT);
	gdt_flush();
	return status;
}
Esempio n. 5
0
File: gdt.c Progetto: mmalecki/cOS
void gdt_init() {
  gdt_pointer.limit = (sizeof(gdt_entry_t) * 5) - 1;
  gdt_pointer.base  = (uint32) &gdt_entries;
  gdt_set_entry(0, 0, 0, 0, 0);
  gdt_fill_entry(1, 0, 0xFFFFFFFF, GDT_RING_0, GDT_CODE_SEGMENT);
  gdt_fill_entry(2, 0, 0xFFFFFFFF, GDT_RING_0, GDT_DATA_SEGMENT);
  gdt_fill_entry(3, 0, 0xFFFFFFFF, GDT_RING_3, GDT_CODE_SEGMENT);
  gdt_fill_entry(4, 0, 0xFFFFFFFF, GDT_RING_3, GDT_DATA_SEGMENT);
  gdt_flush((uint32) &gdt_pointer);
}
Esempio n. 6
0
void gdt_init()
{
    gdtPointer.limit = (sizeof(gdt_entry_t) * 6) - 1;
    gdtPointer.base = (unsigned) &gdt;

    // Null Selector
    gdt_set_entry(0, 0, 0, 0, 0);

    // SYSENTER Code Segment
    gdt_set_entry(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);

    // SYSENTER Data Segment (Stack)
    gdt_set_entry(2, 0, 0xFFFFFFFF, 0x92, 0xCF);

    // SYSEXIT Code Segment
    gdt_set_entry(3, 0, 0xFFFFFFFF, 0xFA, 0xCF);

    // SYSEXIT Data Segment (User-mode Stack)
    gdt_set_entry(4, 0, 0xFFFFFFFF, 0xF2, 0xCF);

    // TSS Segment (Multitasking)
    gdt_set_entry(5, 0, 0xFFFFFFFF, 0x90, 0xCF);

    gdt_flush((unsigned) &gdtPointer);
}
Esempio n. 7
0
File: gdt.c Progetto: regina/jonix
/*  ----------------------------------------------------
 *  Function:       gdt_init
 *  --------------------------------------------------*/
void gdt_init(){
    /* Setup the GDT pointer and limit */
    gdt_ptr.limit = (sizeof(gdt_entry_t) * 5) - 1;
    gdt_ptr.base = (uint32_t) &gdt;

    /* Our NULL descriptor */
    gdt_set_entry(0, 0, 0, 0, 0);

    /* The second entry is our Code Segment. The base address
    *  is 0, the limit is 4GBytes, it uses 4KByte granularity,
    *  uses 32-bit opcodes, and is a Code Segment descriptor.
    *  Please check the table above in the tutorial in order
    *  to see exactly what each value means */
    gdt_set_entry(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);

    /* The third entry is our Data Segment. It's EXACTLY the
    *  same as our code segment, but the descriptor type in
    *  this entry's access byte says it's a Data Segment */
    gdt_set_entry(2, 0, 0xFFFFFFFF, 0x92, 0xCF);

    /* The fourth entry is a TSS descriptor (for ring 0)*/
    gdt_set_entry(3, (uint32_t) &tss_0, sizeof(tss_0)-1, 0x89, 0x00);

    /* Initialise the ring 0 TSS to zeros */
    memset(&tss_0, 0, sizeof(tss_0));

    /* Set stack info in the ring 0 TSS */

    tss_0.ss0    = 0x10;        // The descriptor used for the stack segment.

    tss_0.esp0   = (uint32_t) kmem_stack;   // The base of the kernel stack.
                                // This will be used as the stack pointer - 
                                // once we start multitasking this should be
                                // fine (I hope).

    /* Flush out the old GDT and install the new changes! */
    gdt_flush();

}
Esempio n. 8
0
void install_tss() {
    uint32_t base = (uint32_t) &tss;
    gdt_set_entry(5, base, base + sizeof(tss_t), 0xE9);
    memset((void *) base, 0, sizeof(tss_t));

    tss.esp0 = 0;
    tss.ss0 = 0x10;
    tss.cs = 0x0B;
    tss.ss = 0x13;
    tss.es = 0x13;
    tss.ds = 0x13;
    tss.fs = 0x13;
    tss.gs = 0x13;
    
    flush_tss();
}
Esempio n. 9
0
/* initialize the GDT */
void gdt_init(void)
{
    /* null segment */
    gdt_set_entry(0, 0, 0, 0, 0);
    /* 32 bit code, ring 0 */
    gdt_set_entry(1, GDT_BASE_NULL, GDT_LIMIT_FULL, GDT_PRESENT | GDT_RING_0 | GDT_SEGMENT | GDT_EXECUTABLE | GDT_READABLE, GDT_GRANULAR | GDT_PROTECTED_MODE);
    /* 32 bit data, ring 0 */
    gdt_set_entry(2, GDT_BASE_NULL, GDT_LIMIT_FULL, GDT_PRESENT | GDT_RING_0 | GDT_SEGMENT | GDT_WRITABLE | GDT_DIRECTION_UP, GDT_GRANULAR | GDT_PROTECTED_MODE);
    /* 32 bit code, ring 3 */
    gdt_set_entry(3, GDT_BASE_NULL, GDT_LIMIT_FULL, GDT_PRESENT | GDT_RING_3 | GDT_SEGMENT | GDT_EXECUTABLE | GDT_READABLE, GDT_GRANULAR | GDT_PROTECTED_MODE);
    /* 32 bit data, ring 3 */
    gdt_set_entry(4, GDT_BASE_NULL, GDT_LIMIT_FULL, GDT_PRESENT | GDT_RING_3 | GDT_SEGMENT | GDT_WRITABLE | GDT_DIRECTION_UP, GDT_GRANULAR | GDT_PROTECTED_MODE);
    /* 32 bit tss */
    gdt_set_entry(5, (uintptr_t)&tss, sizeof(tss_t) - 1, GDT_PRESENT | GDT_RING_0 | GDT_TSS, GDT_NULL);
}