aboutsummaryrefslogtreecommitdiffstats
path: root/arch/frv/kernel/kernel_thread.S
blob: 4531c830d20b708b6dce2ce6bf736dabdf14c4de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* kernel_thread.S: kernel thread creation
 *
 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
 * Written by David Howells (dhowells@redhat.com)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
 */

#include <linux/linkage.h>
#include <asm/unistd.h>

#define CLONE_VM	0x00000100	/* set if VM shared between processes */
#define	KERN_ERR	"<3>"

	.section .rodata
kernel_thread_emsg:
	.asciz	KERN_ERR "failed to create kernel thread: error=%d\n"

	.text
	.balign		4

###############################################################################
#
# Create a kernel thread
#
# int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
#
###############################################################################
	.globl		kernel_thread
	.type		kernel_thread,@function
kernel_thread:
	or.p		gr8,gr0,gr4
	or		gr9,gr0,gr5

	# start by forking the current process, but with shared VM
	setlos.p	#__NR_clone,gr7		; syscall number
	ori		gr10,#CLONE_VM,gr8	; first syscall arg	[clone_flags]
	sethi.p		#0xe4e4,gr9		; second syscall arg	[newsp]
	setlo		#0xe4e4,gr9
	setlos.p	#0,gr10			; third syscall arg	[parent_tidptr]
	setlos		#0,gr11			; fourth syscall arg	[child_tidptr]
	tira		gr0,#0
	setlos.p	#4095,gr7
	andcc		gr8,gr8,gr0,icc0
	addcc.p		gr8,gr7,gr0,icc1
	bnelr		icc0,#2
	bc		icc1,#0,kernel_thread_error

	# now invoke the work function
	or		gr5,gr0,gr8
	calll		@(gr4,gr0)

	# and finally exit the thread
	setlos		#__NR_exit,gr7		; syscall number
	tira		gr0,#0

kernel_thread_error:
	subi		sp,#8,sp
	movsg		lr,gr4
	sti		gr8,@(sp,#0)
	sti.p		gr4,@(sp,#4)

	or		gr8,gr0,gr9
	sethi.p		%hi(kernel_thread_emsg),gr8
	setlo		%lo(kernel_thread_emsg),gr8

	call		printk

	ldi		@(sp,#4),gr4
	ldi		@(sp,#0),gr8
	subi		sp,#8,sp
	jmpl		@(gr4,gr0)

	.size		kernel_thread,.-kernel_thread