1

I have a TLB miss on load error when I run the fork test , I understand this is due to passing wrong stackptr to mips_usermode , my implementation seems to revolve around few suggestions over here, would be grateful if I get corrected her. My code below is provided as entry point function in thread_fork. Am i missin any thing ?

void
enter_forked_process(void *junk,unsigned long num)
{

        kprintf("\n entered enter_fork_process");
        struct trapframe tf = (*((struct trapframe *) junk));


        (void) num;


        kprintf("\n copied tf from from parent to child");
        tf.tf_v0 = 0;
        tf.tf_a3 = 0;
        tf.tf_epc += 4;
        kprintf("abt to enter mips_ usermode");
        mips_usermode(&tf);
}
VividD
  • 10,456
  • 6
  • 64
  • 111
gsb
  • 41
  • 1
  • 5

1 Answers1

2

You have to copy parent thread's address space before you call thread_fork, and pass the address space pointer as the second parameter of enter_forked_process. And in enter_forked_process, you have to fill the address space into curthread->t_addrspace. Otherwise, you'll get the TLB miss on load error, since current thread (the child)'s address space is not initialized.

For more details about OS161 fork system call, please refer to this blog. And child_forkentry there is more or less the same as your enter_forked_process. http://jhshi.me/2012/03/11/os161-fork-system-call/index.html

tvdias
  • 821
  • 2
  • 10
  • 25
Jinghao Shi
  • 1,077
  • 2
  • 10
  • 15