Posted: Tue Jan 22, 2008 5:50 pm
Lukem, I used dir->tablesPhysical (Thats whats in his paging code)
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
void start_task(void (*func)(void*), void *arg)
{
if (fork() == 0)
{
func(arg);
kill_task();
for(;;);
}
}
Code: Select all
printf("cloning directory:\n");
#endif
current_directory = clone_directory(kernel_directory);
#ifdef DEBUG
printf("cloning directory...ok!\n");
printf("switching to current_directory...");
#endif
#ifdef DEBUG
printf("updating cr3...");
#endif
/* This line is where it hangs */
__asm__ __volatile__("mov %0, %%cr3":: "r"(current_directory->tablesPhysical));
#ifdef DEBUG
printf("ok!\n");
#endif
unsigned int cr0;
__asm__ __volatile__("mov %%cr0, %0": "=r"(cr0));
cr0 |= 0x80000000; // Enable paging!
__asm__ __volatile__("mov %0, %%cr0":: "r"(cr0));
#ifdef DEBUG
printf("ok!\n");
#endif
Code: Select all
00026255628i[CPU0 ] protected mode
00026255628i[CPU0 ] CS.d_b = 32 bit
00026255628i[CPU0 ] SS.d_b = 32 bit
00026255628i[CPU0 ] | EAX=c0083000 EBX=00245000 ECX=000003d4 EDX=000003d5
00026255628i[CPU0 ] | ESP=00138e68 EBP=00101fbe ESI=00000012 EDI=0013f000
00026255628i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df IF tf SF zf af PF cf
00026255628i[CPU0 ] | SEG selector base limit G D
00026255628i[CPU0 ] | SEG sltr(index|ti|rpl) base limit G D
00026255628i[CPU0 ] | CS:0008( 0001| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | DS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | SS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | ES:0010( 0002| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | FS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | GS:0010( 0002| 0| 0) 00000000 000fffff 1 1
00026255628i[CPU0 ] | EIP=001024a9 (001024a9)
00026255628i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x0013a070
00026255628i[CPU0 ] | CR3=0xc0083000 CR4=0x00000000
00026255628i[CPU0 ] >> push 0x0000000f : 6A0F
00026255628e[CPU0 ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00026255628i[SYS ] bx_pc_system_c::Reset(SOFTWARE) called
00026255628i[APIC0] local apic in CPU 0 initializing
00026255628e[CPU0 ] CPU_LOOP bx_guard.interrupt_requested=1
Code: Select all
// Get the offset of tablesPhysical from the start of the page_directory_t structure.
unsigned int offset = (unsigned int)dir->tablesPhysical - (unsigned int)dir;
// Then the physical address of dir->tablesPhysical is:
dir->physicalAddr = phys + offset;
#ifdef DEBUG
printf("Physical address: 0x%x\n",dir->physicalAddr);
#endif
Code: Select all
unsigned int offset = (unsigned int)current_directory->tablesPhysical - (unsigned int)current_directory;
That would be processor ring levels. Load your apps in Ring 3 and you won't have that problemlukem_95 wrote:Also, on a slightly different note, how do people stop user programs accessing hardwear directly, or stop it executing say CLI, as then my multitasking would die.
Both of those would be useful!I don't have my code here, right now, nor the actual error, but I'll post it as soon as I get home.
Code: Select all
void switch_task()
{
k_puts("Switching");
if (!current_task)
return;
unsigned int esp, ebp, eip;
asm volatile("mov %%esp, %0" : "=r" (esp));
asm volatile("mov %%ebp, %0" : "=r" (ebp));
eip = read_eip();
if (eip == 0x12345)
{
return;
}
current_task->eip = eip;
current_task->esp = esp;
current_task->ebp = ebp;
current_task = current_task->next;
if (!current_task) current_task = ready_queue;
eip = current_task->eip;
esp = current_task->esp;
ebp = current_task->ebp;
current_directory = current_task->page_directory;
asm volatile("cli");
asm volatile(" \
mov %0, %%ecx; \
mov %1, %%esp; \
mov %2, %%ebp; \
mov $0x12345, %%eax; \
jmp *%%ecx; " : : "r" (eip), "r"(esp), "r"(ebp));
switch_page_directory(current_directory);
asm volatile("sti");
/**/
}
int fork()
{
asm volatile("cli");
task_t *parent_task = (task_t*)current_task;
page_directory_t *directory = clone_directory(current_directory);
task_t *new_task = (task_t*)kmalloc(sizeof(task_t));
new_task->id = next_pid++;
new_task->esp = new_task->ebp = 0;
new_task->eip = 0;
new_task->page_directory = directory;
new_task->next = 0;
task_t *tmp_task = (task_t*)ready_queue;
while(tmp_task->next)
tmp_task = tmp_task->next;
tmp_task->next = new_task;
unsigned int eip = read_eip();
unsigned int esp; asm volatile("mov %%esp, %0" : "=r" (esp));
unsigned int ebp; asm volatile("mov %%ebp, %0" : "=r" (ebp));
if (current_task == parent_task)
{
new_task->esp = esp;
new_task->ebp = ebp;
new_task->eip = eip;
asm volatile("sti");
return new_task->id;
} else {
k_printf("!-returning!",cursor_y, cursor_x);
return 0;
}
}
Code: Select all
if (fork()== 0)
{
k_puts("FORKED!");
for(;;);
}