/* kernel_thread.S: kernel thread creation1*2* Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.3* Written by David Howells ([email protected])4*5* This program is free software; you can redistribute it and/or6* modify it under the terms of the GNU General Public License7* as published by the Free Software Foundation; either version8* 2 of the License, or (at your option) any later version.9*/1011#include <linux/linkage.h>12#include <asm/unistd.h>1314#define CLONE_VM 0x00000100 /* set if VM shared between processes */15#define KERN_ERR "<3>"1617.section .rodata18kernel_thread_emsg:19.asciz KERN_ERR "failed to create kernel thread: error=%d\n"2021.text22.balign 42324###############################################################################25#26# Create a kernel thread27#28# int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)29#30###############################################################################31.globl kernel_thread32.type kernel_thread,@function33kernel_thread:34or.p gr8,gr0,gr435or gr9,gr0,gr53637# start by forking the current process, but with shared VM38setlos.p #__NR_clone,gr7 ; syscall number39ori gr10,#CLONE_VM,gr8 ; first syscall arg [clone_flags]40sethi.p #0xe4e4,gr9 ; second syscall arg [newsp]41setlo #0xe4e4,gr942setlos.p #0,gr10 ; third syscall arg [parent_tidptr]43setlos #0,gr11 ; fourth syscall arg [child_tidptr]44tira gr0,#045setlos.p #4095,gr746andcc gr8,gr8,gr0,icc047addcc.p gr8,gr7,gr0,icc148bnelr icc0,#249bc icc1,#0,kernel_thread_error5051# now invoke the work function52or gr5,gr0,gr853calll @(gr4,gr0)5455# and finally exit the thread56setlos #__NR_exit,gr7 ; syscall number57tira gr0,#05859kernel_thread_error:60subi sp,#8,sp61movsg lr,gr462sti gr8,@(sp,#0)63sti.p gr4,@(sp,#4)6465or gr8,gr0,gr966sethi.p %hi(kernel_thread_emsg),gr867setlo %lo(kernel_thread_emsg),gr86869call printk7071ldi @(sp,#4),gr472ldi @(sp,#0),gr873subi sp,#8,sp74jmpl @(gr4,gr0)7576.size kernel_thread,.-kernel_thread777879