Huhu,
Bin dabei Multitasking einzubauen, teilweise nach dem Tutorial aus dem Wiki.
Jetzt bekomm ich dauernd ne General protection Fault und Bochs sagt
Der GDT Code hatte davor ohne Probleme funktioniert, ich denk den kann man als fehlqerquelle ausschliessen...
GDT-Setup:
IRQ-handling:
irq_handler:
uund die tasks mit scheduler
kann mir wer weiterhelfen? =)
Greetz, livinskull
Bin dabei Multitasking einzubauen, teilweise nach dem Tutorial aus dem Wiki.
Jetzt bekomm ich dauernd ne General protection Fault und Bochs sagt
Zitat
00189211808e[CPU0 ] check_cs(0x001b): not a valid code segment !
Der GDT Code hatte davor ohne Probleme funktioniert, ich denk den kann man als fehlqerquelle ausschliessen...
GDT-Setup:
Code: [Auswählen]
void gdt_install() {
gp.limit = (sizeof(struct gdt_entry) * 6) - 1;
gp.base = (uint32_t) &gdt;
gdt_set_gate(0, 0, 0, 0, 0);
// kernel code segment
gdt_set_gate(1, 0, 0xFFFFFFFF, GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN);
// kernel data segment
gdt_set_gate(2, 0, 0xFFFFFFFF, GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN);
//user segments
gdt_set_gate(3, 0, 0xFFFFFFFF, GDT_FLAG_SEGMENT | GDT_FLAG_CODESEG | GDT_FLAG_PRESENT | GDT_FLAG_RING3, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN);
gdt_set_gate(4, 0, 0xFFFFFFFF, GDT_FLAG_SEGMENT | GDT_FLAG_DATASEG | GDT_FLAG_PRESENT | GDT_FLAG_RING3, GDT_FLAG_32_BIT | GDT_FLAG_4K_GRAN);
//TSS
gdt_set_gate(5, (uint32_t) tss, sizeof(tss), GDT_FLAG_TSS | GDT_FLAG_PRESENT | GDT_FLAG_RING3, 0);
gdt_flush();
__asm__ __volatile__("ltr %%ax" : : "a" (5 << 3));
}IRQ-handling:
Code: [Auswählen]
irq0:
cli
push byte 0
push byte 32
jmp irq_common_stub
irq_common_stub:
pusha
push ds
push es
push fs
push gs
;load kernel segments
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
mov eax, irq_handler
call eax
mov esp, eax
;mov ax, 0x23
;mov ds, ax
;mov es, ax
;mov gs, ax
;mov fs, ax
pop gs
pop fs
pop es
pop ds
popa
add esp, 8
sti
iretirq_handler:
Code: [Auswählen]
regs *irq_handler(regs *r) {
void (*handler)(regs *r);
regs *new_regs = r;
handler = irq_routines[r->int_no - 32];
if (handler)
handler(r);
if (r->int_no == 0x20) { // INT 0x20, IRQ0, timer interrupt
new_regs = schedule(r);
tss[1] = (uint32_t) (new_regs + 1);
}
// EOI to slave controller
if (r->int_no >= 40)
outb(0xA0, 0x20);
// EOI to master
outb(0x20, 0x20);
return new_regs;
}uund die tasks mit scheduler
Code: [Auswählen]
regs *schedule(regs *r) {
current_task->cpu_state = r;
if (current_task->time_left > 0) {
current_task->time_left -= TASK_TIMESLICE;
} else {
current_task->time_left = TASK_TIMESLICE * current_task->priority;
current_task->state = READY;
do {
current_task = current_task->next?current_task->next:first_task;
} while (current_task->state == BLOCKED);
current_task->state = RUNNING;
}
return current_task->cpu_state;
}
task *init_task(void *entrypoint, char *name, uint8_t priority) {
uint8_t *user_stack = (uint8_t *) pmm_alloc();
uint8_t *stack = (uint8_t *) pmm_alloc();
regs new_state = {
.eax = 0, .ebx = 0, .ecx = 0, .edx = 0, .esi = 0, .edi = 0,
.ebp = 0, .esp = (uint32_t) user_stack + 4096,
.eip = (uint32_t) entrypoint,
.cs = (0x03<<3) | 0x03, //ring 3 segments
.ss = (0x04<<3) | 0x03,
.es = (0x04<<3) | 0x03,
.fs = (0x04<<3) | 0x03,
.gs = (0x04<<3) | 0x03,
.ds = (0x04<<3) | 0x03,
.eflags = 0x200 //interrupts on
};
regs *state = (void *) (stack + 4096 - sizeof(new_state));
*state = new_state;
task* new_task = pmm_alloc();
new_task->cpu_state = state;
new_task->name = name;
new_task->priority = priority;
new_task->time_left = TASK_TIMESLICE + priority;
new_task->pid = next_pid++;
new_task->state = CREATED;
new_task->next = first_task;
first_task = new_task;
return new_task;
}kann mir wer weiterhelfen? =)
Greetz, livinskull

Übersicht
Wiki
Hilfe
Suche
Einloggen
Registrieren
Drucken


Gespeichert


