All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Alpha Beta" <abbashake007@lycos.com>
To: linux-kernel@vger.kernel.org
Subject: Qn: kernel_thread() and init
Date: Sun, 03 Feb 2002 13:52:08 +0530	[thread overview]
Message-ID: <BNBIFONAELMBOAAA@mailcity.com> (raw)

In the code of 
int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
in arch/i386/kernel/process.c

as can be seen in the code here, a system call is made by trigerring the 0x80 interrupt.
this function kernel_thread() is used to launch the init process during booting by
start_kernel()	//in init/main.c
But at that time, the process 0 which calls kernel_thread is executing in Kernel mode, so why should some process in kernel mode make a system call??


ANOTHER BIG DOUBT IS THAT process 0 executes in Kernel mode, it then creates the init process ( process 1)- this process according to BACH ends up running in User mode while process 0 runs in kernel mode.
so why should then we have a kernel thread invoked for init when it is to run in User mode ??




int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
{
	long retval, d0;

	__asm__ __volatile__(
		"movl %%esp,%%esi\n\t"
		"int $0x80\n\t"		/* Linux/i386 system call */
		"cmpl %%esp,%%esi\n\t"	/* child or parent? */
		"je 1f\n\t"		/* parent - jump */
		/* Load the argument into eax, and push it.  That way, it does
		 * not matter whether the called function is compiled with
		 * -mregparm or not.  */
		"movl %4,%%eax\n\t"
		"pushl %%eax\n\t"		
		"call *%5\n\t"		/* call fn */
		"movl %3,%0\n\t"	/* exit */
		"int $0x80\n"
		"1:\t"
		:"=&a" (retval), "=&S" (d0)
		:"0" (__NR_clone), "i" (__NR_exit),
		 "r" (arg), "r" (fn),
		 "b" (flags | CLONE_VM)
		: "memory");
	return retval;
}




             reply	other threads:[~2002-02-03  8:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-03  8:22 Alpha Beta [this message]
2002-02-03 14:54 ` Qn: kernel_thread() and init Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BNBIFONAELMBOAAA@mailcity.com \
    --to=abbashake007@lycos.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.