help please...i am in a very bad situation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
aks

help please...i am in a very bad situation

Post by aks »

hi

i am developing an os as a college project..i have 25 days 2 submission....
this is what i have done.....
switched to pmode
set up gdt,idt,etc...
init apic
completed mem mngmt
i have also setup a basic task using ltr..
file system is in progress...my teammate is doing it...

now i am trouble with multitasking....
i am using the TSS based MT...now the problem is i do not know how to switch from ring0 to ring 3...i have tried the IRET method as well as the call gate return method...in both cases i think there is a problem regarding SS....i am using VMWARE which generates an error(Stack Error or something) when i try switching as above...also i tried switching from ring 0 to ring 2...this works somewhat in the sense that the transition is made but it also gives the same error after sometime....i have checked out the example in myexecpc...without much success....please help...if anyone could plz gimme a code written in nasm for which can boot(basic os)....which also jumps from ring0 to ring3 would be very helpful......

i have another problem...
i have init the apic...now the clock interrupt no 32 is being generated but the interrupt no. 33 is not being generate when i press a key on the keyboard...plz help...

thnx
aks
knicos

RE:help please...i am in a very bad situation

Post by knicos »

Hi

I had exactly the same problem, and it took me hours to find. But... i cant remember what exactly i did to fix it.

Here is my C code that switches between ring 0 and ring 3, and vice versa, with the timer interrupt.

#define SAVECORE asm( \
"push %ebx\n" \
"push %eax\n" \
"push %ecx\n" \
"push %edx\n" \
"push %ds\n" \
"push %es\n" \
"push %fs\n" \
"push %gs\n" \
"push %ebp\n" \
"push %esi\n" \
"push %edi\n" \
"push %eax\n" \
"mov $16, %ax\n" \
"mov %ax, %ds\n" \
"mov %ax, %es\n" \
"mov %ax, %fs\n" \
"mov %ax, %gs\n" \
"pop %eax\n")

#define RESTORECORE asm( \
"pop %edi\n" \
"pop %esi\n" \
"pop %ebp\n" \
"pop %gs\n" \
"pop %fs\n" \
"pop %es\n" \
"pop %ds\n" \
"pop %edx\n" \
"pop %ecx\n" \
"pop %eax\n" \
"pop %ebx\n" \
)

#define RESCOREEAX asm( \
"pop %edi\n" \
"pop %esi\n" \
"pop %ebp\n" \
"pop %gs\n" \
"pop %fs\n" \
"pop %es\n" \
"pop %ds\n" \
"pop %edx\n" \
"pop %ecx\n" \
"pop %ebx\n" \
"pop %ebx\n" \
)

#define IRET asm("leave\n\tiret")

#define SAVEESP(i) asm("mov %%esp,%0" : "=a" (i))
#define LOADESP(i) asm("mov %0, %%esp" : : "a" (i))
#define LTR(i) asm("ltr %%ax" :: "a" (i))

#define CHANGECR3(i) asm("movl %0, %%cr3\nnop\nnop" : : "a" (i))

void do_timer()
{
SAVECORE; //Push all registers onto the stack
SAVEESP(cpus[0].current->esp);

clear_ints();

jiffies++; //Add to timer counter.
wakeup();
select_task(&cpus[0]); //Select next task.
outb(0x20,0x20); //Tell pic that we have finished
LOADESP(cpus[0].current->esp);
CHANGECR3(cpus[0].current->pdir);
cpus[0].tss.esp0 = cpus[0].current->kstack;

set_ints();

RESTORECORE; //Pop all registers off of the stack
IRET; //Special return as this is an interrupt handler
}

Its works, hope u can use it somehow. Make sure the SS descripter has the correct priviledge level (3). If u need any more of the code, just ask.
Post Reply