The core i386 NLKD adjustments to pre-existing code. Signed-Off-By: Jan Beulich Index: 2.6.14-nlkd/arch/i386/Kconfig =================================================================== --- 2.6.14-nlkd.orig/arch/i386/Kconfig 2005-11-04 16:19:32.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/Kconfig 2005-11-04 16:19:32.000000000 +0100 @@ -425,6 +425,11 @@ config X86_CMPXCHG64 depends on !M386 && !M486 default y +config X86_CMOVE + bool + depends on !M386 && !M486 && !MCYRIXIII && !M586 && !M586TSC && !M586MMX && !MWINCHIPC6 && !MWINCHIP2 && !MWINCHIP3D && !MGEODEGX1 + default y + config X86_ALIGNMENT_16 bool depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1 Index: 2.6.14-nlkd/arch/i386/Kconfig.debug =================================================================== --- 2.6.14-nlkd.orig/arch/i386/Kconfig.debug 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/Kconfig.debug 2005-11-04 16:19:32.000000000 +0100 @@ -54,7 +54,7 @@ config DEBUG_PAGEALLOC config 4KSTACKS bool "Use 4Kb for kernel stacks instead of 8Kb" - depends on DEBUG_KERNEL + depends on DEBUG_KERNEL && !NLKD help If you say Y here the kernel will use a 4Kb stacksize for the kernel stack attached to each process/thread. This facilitates Index: 2.6.14-nlkd/arch/i386/kernel/cpu/common.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/cpu/common.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/cpu/common.c 2005-11-04 16:19:32.000000000 +0100 @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include Index: 2.6.14-nlkd/arch/i386/kernel/process.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/process.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/process.c 2005-11-04 16:48:57.000000000 +0100 @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_MATH_EMULATION @@ -393,6 +394,10 @@ void exit_thread(void) tss->io_bitmap_base = INVALID_IO_BITMAP_OFFSET; put_cpu(); } + if (tsk->thread.debugreg[7]) { + enable_debugreg(tsk, 7, 0); + tsk->thread.debugreg[7] = 0; + } } void flush_thread(void) @@ -406,6 +411,8 @@ void flush_thread(void) */ kprobe_flush_task(tsk); + if (tsk->thread.debugreg[7]) + enable_debugreg(tsk, 7, 0); memset(tsk->thread.debugreg, 0, sizeof(unsigned long)*8); memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array)); /* @@ -507,6 +514,12 @@ int copy_thread(int nr, unsigned long cl desc->b = LDT_entry_b(&info); } + if (tsk->thread.debugreg[7]) { + p->thread.debugreg[7] = 0; + enable_debugreg(p, 7, tsk->thread.debugreg[7]); + p->thread.debugreg[7] = tsk->thread.debugreg[7]; + } + err = 0; out: if (err && p->thread.io_bitmap_ptr) { Index: 2.6.14-nlkd/arch/i386/kernel/ptrace.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/ptrace.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/ptrace.c 2005-11-04 16:19:32.000000000 +0100 @@ -493,7 +493,7 @@ asmlinkage int sys_ptrace(long request, * * Note that LENi == 0x10 is defined on x86_64 in long * mode (i.e. even for 32-bit userspace software, but - * 64-bit kernel), so the x86_64 mask value is 0x5454. + * 64-bit kernel), so the x86_64 mask value is 0x5554. * See the AMD manual no. 24593 (AMD64 System * Programming)*/ @@ -506,6 +506,11 @@ asmlinkage int sys_ptrace(long request, addr -= (long) &dummy->u_debugreg; addr = addr >> 2; + + if (enable_debugreg(child, addr, data) < 0) { + ret = -EBUSY; + break; + } child->thread.debugreg[addr] = data; ret = 0; } Index: 2.6.14-nlkd/arch/i386/kernel/signal.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/signal.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/signal.c 2005-11-04 16:19:33.000000000 +0100 @@ -25,6 +25,7 @@ #include #include #include +#include #include "sigframe.h" #define DEBUG_SIG 0 @@ -629,7 +630,7 @@ int fastcall do_signal(struct pt_regs *r * inside the kernel. */ if (unlikely(current->thread.debugreg[7])) { - set_debugreg(current->thread.debugreg[7], 7); + restore_debugreg(); } /* Whee! Actually deliver the signal. */ Index: 2.6.14-nlkd/arch/i386/kernel/traps.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/traps.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/traps.c 2005-11-04 17:00:47.000000000 +0100 @@ -774,7 +774,7 @@ fastcall void __kprobes do_debug(struct * the signal is delivered. */ clear_dr7: - set_debugreg(0, 7); + disable_debugreg(regs, 7); return; debug_vm86: Index: 2.6.14-nlkd/arch/i386/kernel/vmlinux.lds.S =================================================================== --- 2.6.14-nlkd.orig/arch/i386/kernel/vmlinux.lds.S 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/kernel/vmlinux.lds.S 2005-11-07 11:58:12.000000000 +0100 @@ -82,6 +82,12 @@ SECTIONS __setup_start = .; .init.setup : AT(ADDR(.init.setup) - LOAD_OFFSET) { *(.init.setup) } __setup_end = .; +#ifdef CONFIG_NLKD + . = ALIGN(4); + __start_nlkd_ext = .; + .nlkd.ext : AT(ADDR(.nlkd.ext) - LOAD_OFFSET) { *(.nlkd.ext) } + __stop_nlkd_ext = .; +#endif __initcall_start = .; .initcall.init : AT(ADDR(.initcall.init) - LOAD_OFFSET) { *(.initcall1.init) Index: 2.6.14-nlkd/arch/i386/power/cpu.c =================================================================== --- 2.6.14-nlkd.orig/arch/i386/power/cpu.c 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/arch/i386/power/cpu.c 2005-11-04 17:05:42.000000000 +0100 @@ -10,6 +10,7 @@ #include #include #include +#include static struct saved_context saved_context; Index: 2.6.14-nlkd/include/asm-i386/debugreg.h =================================================================== --- 2.6.14-nlkd.orig/include/asm-i386/debugreg.h 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/include/asm-i386/debugreg.h 2005-11-04 16:19:34.000000000 +0100 @@ -61,4 +61,54 @@ #define DR_LOCAL_SLOWDOWN (0x100) /* Local slow the pipeline */ #define DR_GLOBAL_SLOWDOWN (0x200) /* Global slow the pipeline */ +#ifdef CONFIG_NLKD + +# include + +struct pt_regs; +struct task_struct; + +# ifdef CONFIG_CDE +# define MAYBE_INDIR(x) x +# define set_debugreg(val, reg) ((void)(val), (void)(reg)) +# else +# define MAYBE_INDIR(x) (*x) +extern void (*set_debugreg)(uintptr_t value, nuint_t regnum); +# endif + +extern int MAYBE_INDIR(enable_debugreg)(struct task_struct *, nuint_t regnum, uintptr_t value); +extern int MAYBE_INDIR(disable_debugreg)(struct pt_regs *, nuint_t regnum); +extern int MAYBE_INDIR(restore_debugreg)(void); + +# undef MAYBE_INDIR + +#else + +# define set_debugreg(value, register) \ + __asm__("movl %0,%%db" #register \ + : /* no output */ \ + :"r" (value)) +# define enable_debugreg(task, regnum, value) ({ \ + (void)(task); \ + (void)(regnum); \ + (void)(value); \ + 0; \ + }) +# define disable_debugreg(regs, regnum) ({ \ + (void)(regs); \ + (void)(regnum); \ + set_debugreg(0, 7); \ + 0; \ + }) +# define restore_debugreg() ({ \ + set_debugreg(current->thread.debugreg[7], 7); \ + 0; \ + }) + +#endif /* CONFIG_NLKD */ + +#define get_debugreg(var, register) \ + __asm__("movl %%db" #register ", %0" \ + :"=r" (var)) + #endif Index: 2.6.14-nlkd/include/asm-i386/processor.h =================================================================== --- 2.6.14-nlkd.orig/include/asm-i386/processor.h 2005-11-09 10:39:46.000000000 +0100 +++ 2.6.14-nlkd/include/asm-i386/processor.h 2005-11-07 10:20:43.000000000 +0100 @@ -461,6 +461,7 @@ struct thread_struct { #define INIT_THREAD { \ .vm86_info = NULL, \ + .esp0 = sizeof(init_stack) + (long)&init_stack, \ .sysenter_cs = __KERNEL_CS, \ .io_bitmap_ptr = NULL, \ } @@ -507,17 +508,6 @@ static inline void load_esp0(struct tss_ } while (0) /* - * These special macros can be used to get or set a debugging register - */ -#define get_debugreg(var, register) \ - __asm__("movl %%db" #register ", %0" \ - :"=r" (var)) -#define set_debugreg(value, register) \ - __asm__("movl %0,%%db" #register \ - : /* no output */ \ - :"r" (value)) - -/* * Set IOPL bits in EFLAGS from given mask */ static inline void set_iopl_mask(unsigned mask)