//linux kernel 源代码
1 #
2 # Makefile for the linux kernel.
3 #
4 # Note! Dependencies are done automagically by 'make dep', which also
5 # removes any old dependencies. DON'T put your own dependencies here
6 # unless it's something special (ie not a .c file).
7 #
8 # Note 2! The CFLAGS definitions are now in the main makefile...
9
10 .S.s:
11 $(CPP) -traditional $< -o $*.s
12 .c.s:
13 $(CC) $(CFLAGS) -S $<
14 .s.o:
15 $(AS) -c -o $*.o $<
16 .c.o:
17 $(CC) $(CFLAGS) -c $<
18
19 OBJS = sched.o sys_call.o traps.o irq.o dma.o fork.o \
20 panic.o printk.o vsprintf.o sys.o module.o ksyms.o exit.o \
21 signal.o mktime.o ptrace.o ioport.o itimer.o \
22 info.o ldt.o time.o
23
24 all: kernel.o
25
26 kernel.o: $(OBJS)
27 $(LD) -r -o kernel.o $(OBJS)
28 sync
29
30 sys_call.s: sys_call.S
31
32 sys_call.o: sys_call.s
33
34 sched.o: sched.c
35 $(CC) $(CFLAGS) $(PROFILING) -fno-omit-frame-pointer -c $<
36
37 ksyms.lst: ksyms.S ../include/linux/autoconf.h
38 $(CPP) $(CFLAGS) $< > $@
39
40 ksyms.s: ksyms.sh ksyms.lst
41 sh $< > $@
42
43 ksyms.o: ksyms.s
44
45 dep:
46 $(CPP) -M *.c > .depend
47
48 dummy:
49
50 #
51 # include a dependency file if one exists
52 #
53 ifeq (.depend,$(wildcard .depend))
54 include .depend
55 endif
56
--------------------------
1 /* $Id: dma.c,v 1.5 1992/11/18 02:49:05 root Exp root $
2 * linux/kernel/dma.c: A DMA channel allocator. Inspired by linux/kernel/irq.c.
3 * Written by Hennus Bergman, 1992.
4 */
5
6 #include <linux/kernel.h>
7 #include <linux/errno.h>
8 #include <asm/dma.h>
9
10
11 /* A note on resource allocation:
12 *
13 * All drivers needing DMA channels, should allocate and release them
14 * through the public routines `request_dma()' and `free_dma()'.
15 *
16 * In order to avoid problems, all processes should allocate resources in
17 * the same sequence and release them in the reverse order.
18 *
19 * So, when allocating DMAs and IRQs, first allocate the IRQ, then the DMA.
20 * When releasing them, first release the DMA, then release the IRQ.
21 * If you don't, you may cause allocation requests to fail unnecessarily.
22 * This doesn't really matter now, but it will once we get real semaphores
23 * in the kernel.
24 */
25
26
27
28 /* Channel n is busy iff dma_chan_busy[n] != 0.
29 * DMA0 is reserved for DRAM refresh, I think.
30 * DMA4 is reserved for cascading (?).
31 */
32 static volatile unsigned int dma_chan_busy[MAX_DMA_CHANNELS] = {
33 1, 0, 0, 0, 1, 0, 0, 0
34 };
35
36
37
38 /* Atomically swap memory location [32 bits] with `newval'.
39 * This avoid the cli()/sti() junk and related problems.
40 * [And it's faster too :-)]
41 * Maybe this should be in include/asm/mutex.h and be used for
42 * implementing kernel-semaphores as well.
43 */
44 static __inline__ unsigned int mutex_atomic_swap(volatile unsigned int * p, unsigned int newval)
45 {
46 unsigned int semval = newval;
47
48 /* If one of the operands for the XCHG instructions is a memory ref,
49 * it makes the swap an uninterruptible RMW cycle.
50 *
51 * One operand must be in memory, the other in a register, otherwise
52 * the swap may not be atomic.
53 */
54
55 asm __volatile__ ("xchgl %2, %0\n"
56 : /* outputs: semval */ "=r" (semval)
57 : /* inputs: newval, p */ "" (semval), "m" (*p)
58 ); /* p is a var, containing an address */
59 return semval;
60 } /* mutex_atomic_swap */
61
62
63
64 int request_dma(unsigned int dmanr)
65 {
66 if (dmanr >= MAX_DMA_CHANNELS)
67 return -EINVAL;
68
69 if (mutex_atomic_swap(&dma_chan_busy[dmanr], 1) != 0)
70 return -EBUSY;
71 else
72 /* old flag was 0, now contains 1 to indicate busy */
73 return 0;
74 } /* request_dma */
75
76
77 void free_dma(unsigned int dmanr)
78 {
79 if (dmanr >= MAX_DMA_CHANNELS) {
80 printk("Trying to free DMA%d\n", dmanr);
81 return;
82 }
83
84 if (mutex_atomic_swap(&dma_chan_busy[dmanr], 0) == 0)
85 printk("Trying to free free DMA%d\n", dmanr);
86 } /* free_dma */
87
88
------------------------------
1 /*
2 * linux/kernel/exit.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7 #define DEBUG_PROC_TREE
8
9 #include <linux/wait.h>
10 #include <linux/errno.h>
11 #include <linux/signal.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/resource.h>
15 #include <linux/mm.h>
16 #include <linux/tty.h>
17 #include <linux/malloc.h>
18
19 #include <asm/segment.h>
20 extern void shm_exit (void);
21 extern void sem_exit (void);
22
23 int getrusage(struct task_struct *, int, struct rusage *);
24
25 static int generate(unsigned long sig, struct task_struct * p)
26 {
27 unsigned long mask = 1 << (sig-1);
28 struct sigaction * sa = sig + p->sigaction - 1;
29
30 /* always generate signals for traced processes ??? */
31 if (p->flags & PF_PTRACED) {
32 p->signal |= mask;
33 return 1;
34 }
35 /* don't bother with ignored signals (but SIGCHLD is special) */
36 if (sa->sa_handler == SIG_IGN && sig != SIGCHLD)
37 return 0;
38 /* some signals are ignored by default.. (but SIGCONT already did its deed) */
39 if ((sa->sa_handler == SIG_DFL) &&
40 (sig == SIGCONT || sig == SIGCHLD || sig == SIGWINCH))
41 return 0;
42 p->signal |= mask;
43 return 1;
44 }
45
46 int send_sig(unsigned long sig,struct task_struct * p,int priv)
47 {
48 if (!p || sig > 32)
49 return -EINVAL;
50 if (!priv && ((sig != SIGCONT) || (current->session != p->session)) &&
51 (current->euid != p->euid) && (current->uid != p->uid) && !suser())
52 return -EPERM;
53 if (!sig)
54 return 0;
55 if ((sig == SIGKILL) || (sig == SIGCONT)) {
56 if (p->state == TASK_STOPPED)
57 p->state = TASK_RUNNING;
58 p->exit_code = 0;
59 p->signal &= ~( (1<<(SIGSTOP-1)) | (1<<(SIGTSTP-1)) |
60 (1<<(SIGTTIN-1)) | (1<<(SIGTTOU-1)) );
61 }
62 /* Depends on order SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU */
63 if ((sig >= SIGSTOP) && (sig <= SIGTTOU))
64 p->signal &= ~(1<<(SIGCONT-1));
65 /* Actually generate the signal */
66 generate(sig,p);
67 return 0;
68 }
69
70 void notify_parent(struct task_struct * tsk)
71 {
72 if (tsk->p_pptr == task[1])
73 tsk->exit_signal = SIGCHLD;
74 send_sig(tsk->exit_signal, tsk->p_pptr, 1);
75 wake_up_interruptible(&tsk->p_pptr->wait_chldexit);
76 }
77
78 void release(struct task_struct * p)
79 {
80 int i;
81
82 if (!p)
83 return;
84 if (p == current) {
85 printk("task releasing itself\n");
86 return;
87 }
88 for (i=1 ; i<NR_TASKS ; i++)
89 if (task[i] == p) {
90 task[i] = NULL;
91 REMOVE_LINKS(p);
92 if (STACK_MAGIC != *(unsigned long *)p->kernel_stack_page)
93 printk(KERN_ALERT "release: %s kernel stack corruption. Aiee\n", p->comm);
94 free_page(p->kernel_st