[Prev][Next][Index][Thread]
Problems coding a scheduler
/*
* Hello,
* We are trying to make an operating system and we are using
* the Oskit tool. We are just starting and we have some problems related
* to the IDT table.
* We are trying to code an scheduler using the timer to interrupt
* processes as you can see in the code below. It does not work
* at all.
* The timer interrupt seems to occur just once and no more. The
* first task switch to the scheduler happens but after that the
* main function is not interrupted again. We think that the problem
* is related to how the PIC has been programmed and we believe that it should
* be programmed in the AUTO_EOI mode but OSKIT initialization seems
* to program it in other mode.
* We think that the IDT and the TSS have been filled correctly.
* What have we done wrong??
* Thank you.
* Jose Fresnadillo
* La Laguna University
* La Laguna, Tenerife. Spain. */
#include <stdio.h>
#include <oskit/machine/base_cpu.h>
#include <oskit/x86/pmode.h>
#include <oskit/x86/base_gdt.h>
#include <oskit/machine/base_vm.h>
#include <oskit/x86/tss.h>
#include <oskit/x86/base_tss.h>
#include <oskit/dev/dev.h>
#include <oskit/x86/proc_reg.h>
#include <oskit/x86/base_idt.h>
#include <oskit/debug.h>
#include <oskit/x86/pio.h>
#include <oskit/x86/pc/pit.h>
#include <oskit/x86/pc/base_irq.h>
#include <oskit/x86/base_trap.h>
#define USER_TSS1 0x58
CODE32
struct x86_tss user_base_tss1;
long dataseg[100];
/*
* SCHEDULER.-
*
*/
void scheduler(void){
printf("Scheduling...\n");
asm("iret");
}
/*
* MAIN PROGRAM.-
*
*/
void main(void) {
/* Make sure we're not already in protected mode. */
if (i16_get_msw() & CR0_PE)
printf("The processor is in protected mode environment.\n");
base_gdt_init();
base_gdt_load();
base_tss_init();
base_tss_load();
fill_descriptor(&base_gdt[USER_TSS1 / 8],
&user_base_tss1, sizeof(user_base_tss1) - 1,
ACC_PL_K | ACC_TSS | ACC_P, 0);
base_tss.eflags = base_tss.eflags | 0x202;
user_base_tss1.eip = (long)&scheduler;
user_base_tss1.cs = KERNEL_CS;
user_base_tss1.es = KERNEL_DS;
user_base_tss1.ds = KERNEL_DS;
user_base_tss1.ss = KERNEL_DS;
user_base_tss1.fs = KERNEL_DS;
user_base_tss1.gs = KERNEL_DS;
user_base_tss1.ss0 = KERNEL_DS;
user_base_tss1.ss1 = KERNEL_DS;
user_base_tss1.ss2 = KERNEL_DS;
user_base_tss1.esp = sizeof(dataseg) * 100 + (long)dataseg;
user_base_tss1.esp0 = sizeof(dataseg) * 100 + (long)dataseg;
user_base_tss1.esp1 = sizeof(dataseg) * 100 + (long)dataseg;
user_base_tss1.esp2 = sizeof(dataseg) * 100 + (long)dataseg;
user_base_tss1.io_bit_map_offset = sizeof(user_base_tss1);
user_base_tss1.ldt = 0;
user_base_tss1.eflags = 0x202;
base_gdt[USER_TSS1 / 8].access &= ~ACC_TSS_BUSY;
osenv_intr_disable();
fill_gate(&base_idt[irq_master_base + 0], 0, USER_TSS1,
ACC_TASK_GATE | ACC_PL_K, 0);
pit_init(100);
osenv_irq_enable(0);
osenv_intr_enable();
while (1)
;
printf("Just in case...\n");
return;
}
Follow-Ups: