1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

add missing data segemnet for 32bit applications

This commit is contained in:
Stefan Lankes 2015-08-17 17:07:34 +02:00
parent 462c6c4a24
commit bf3c9258b9
3 changed files with 17 additions and 16 deletions

View file

@ -656,7 +656,7 @@ void udelay(uint32_t usecs);
/// Register a task's TSS at GDT
static inline void register_task(void)
{
uint16_t sel = (CORE_ID*2+6) << 3;
uint16_t sel = (CORE_ID*2+7) << 3;
asm volatile ("ltr %%ax" : : "a"(sel));
}

View file

@ -71,7 +71,7 @@ int create_default_frame(task_t* task, entry_point_t ep, void* arg);
static inline int jump_to_user_code(size_t ep, size_t stack)
{
// Create a pseudo interrupt on the stack and return to user function
asm volatile ("push %0; push %1; push $0x1202; push %2; push %3; iretq" :: "r"(0x23ULL), "r"(stack), "r"(0x2bULL), "r"(ep) : "memory");
asm volatile ("push %0; push %1; push $0x1202; push %2; push %3; iretq" :: "r"(0x33ULL), "r"(stack), "r"(0x2bULL), "r"(ep) : "memory");
return 0;
}

View file

@ -81,15 +81,10 @@ void configure_gdt_entry(gdt_entry_t *dest_entry, unsigned long base, unsigned l
*/
void gdt_install(void)
{
unsigned long gran_ds, gran_cs, limit;
int i, num = 0;
memset(task_state_segments, 0x00, MAX_CORES*sizeof(tss_t));
gran_cs = GDT_FLAG_64_BIT;
gran_ds = 0;
limit = 0;
/* Setup the GDT pointer and limit */
gp.limit = (sizeof(gdt_entry_t) * GDT_ENTRIES) - 1;
gp.base = (size_t) &gdt;
@ -102,16 +97,16 @@ void gdt_install(void)
* is 0, the limit is 4 GByte, it uses 4KByte granularity,
* and is a Code Segment descriptor.
*/
gdt_set_gate(num++, 0, limit,
GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, gran_cs);
gdt_set_gate(num++, 0, 0,
GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, GDT_FLAG_64_BIT);
/*
* 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_gate(num++, 0, limit,
GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, gran_ds);
gdt_set_gate(num++, 0, 0,
GDT_FLAG_RING0 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, 0);
/*
* Create code segment for 32bit user-space applications (ring 3)
@ -122,14 +117,20 @@ void gdt_install(void)
/*
* Create data segment for user-space applications (ring 3)
*/
gdt_set_gate(num++, 0, limit,
GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, gran_ds);
gdt_set_gate(num++, 0, 0xFFFFFFFF,
GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN);
/*
* Create code segment for 64bit user-space applications (ring 3)
*/
gdt_set_gate(num++, 0, limit,
GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, gran_cs);
gdt_set_gate(num++, 0, 0,
GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, GDT_FLAG_64_BIT);
/*
* Create data segment for 64bit user-space applications (ring 3)
*/
gdt_set_gate(num++, 0, 0,
GDT_FLAG_RING3 | GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, 0);
/*
* Create TSS for each core (we use these segments for task switching)
@ -137,7 +138,7 @@ void gdt_install(void)
for(i=0; i<MAX_CORES; i++) {
task_state_segments[i].rsp0 = (size_t) &boot_stack + i * KERNEL_STACK_SIZE - 0x10;
gdt_set_gate(num+i*2, (unsigned long) (task_state_segments+i), sizeof(tss_t)-1,
GDT_FLAG_PRESENT | GDT_FLAG_TSS | GDT_FLAG_RING0, gran_ds);
GDT_FLAG_PRESENT | GDT_FLAG_TSS | GDT_FLAG_RING0, 0);
}
/* Flush out the old GDT and install the new changes! */