From owner-freebsd-hackers@FreeBSD.ORG Tue Oct 23 06:20:44 2007 Return-Path: Delivered-To: FreeBSD-Hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2AC4716A468 for ; Tue, 23 Oct 2007 06:20:44 +0000 (UTC) (envelope-from issei.suzuki@gmail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.238]) by mx1.freebsd.org (Postfix) with ESMTP id B07D913C4B3 for ; Tue, 23 Oct 2007 06:20:43 +0000 (UTC) (envelope-from issei.suzuki@gmail.com) Received: by wx-out-0506.google.com with SMTP id i29so1442025wxd for ; Mon, 22 Oct 2007 23:20:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; bh=2RmW/2S85IAOk9PNaN1tW7D0nwrjPA2XI8zbOa9igig=; b=lL0d5t9LGqViEC5CLjHpSEAHrNezUi12++QQgDVrZPBoGK9KVJObU5oskB3Emitx1WtRBBj/FFvs82aa7X5VpnFzWfYgiN4b/uUcgZyE1/++iqhfGQGlRDoO4RqgtLoM/DBOOSzFP5RZ8kPpWyyasEyHBpKyklO45B7P2pO5Rdo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=V4L1MY9fZTO4mJI1kf+q+N+nSUiKqEVxELoAMAztwX7kR5GmYq/JBOr0oVFy+QEE92VerlipYE4Yk9Oa3mEAVf/qdvQEsb6li6YqN45HN4QuwZGbngRrDkKxxZWc5c9GQCuwoaS2iF/wsP+RpoiTPNk0E6+bmbHiAhNm030VYNY= Received: by 10.90.97.19 with SMTP id u19mr1820716agb.1193118761673; Mon, 22 Oct 2007 22:52:41 -0700 (PDT) Received: by 10.90.71.9 with HTTP; Mon, 22 Oct 2007 22:52:41 -0700 (PDT) Message-ID: <337dbc4d0710222252o1817e359k393a398de2315677@mail.gmail.com> Date: Tue, 23 Oct 2007 14:52:41 +0900 From: "Issei Suzuki" Sender: issei.suzuki@gmail.com To: FreeBSD-Hackers@freebsd.org In-Reply-To: <200710222211.51590.Danovitsch@vitsch.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <200710222211.51590.Danovitsch@vitsch.net> X-Google-Sender-Auth: 92c39ce98fa8fce0 Cc: Subject: Re: Floating point in interrupt handler X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Oct 2007 06:20:44 -0000 2007/10/23, Daan Vreeken [PA4DAN] : > So I've added asm inline functions to use the FPU's fsin and fcos operands. At > the start of my loop function I (try to) save the FPU state with the > following code : > td = curthread; > npxgetregs(td, &fpu_state); > At the end of the function I restore the FPU state with : > npxsetregs(td, &fpu_state); > > In between I currently have : > // create a 500Hz sine wave, modulate it with a 2Hz sine wave and > // let it have a 10.0 Volt amplitude > t += 0.0001; > set_dac_voltage(card, 0, > fp_sin(500 * 2 * M_PI * t) * fp_sin(2 * 2 * M_PI * t) * 10.0); > > As uggly as the code may seem, it works and the output of the acquisition > board shows the expected signal on a scope. While the code seems to do what > it should, the kernel floods the console with the following message : > kernel trap 22 with interrupts disabled In FreeBSD, FPU context switch is delayed until FPU is used for the first time after user thread is switched. To achieve this, T_DNA (FPU device not available trap) is used as follows. (Before switching thread) 1. Save FPU state and enable DNA trap (npxsave() @ /sys/i386/isa/npx.c). After this, DNA trap occurs when you access FPU. (Switch to another user thread) 2. User thread accesses FPU. 3. T_DNA trap occurs, and npxdna() @ /sys/i386/isa/npx.c is called. 4. Initialize FPU state (1st time) or restore FPU state (2nd times or later). 5. Return to user mode, and user thread access FPU again. So, to use FPU in kernel, you must clear T_DNA trap and initialize FPU registers first. Reading these functions may help you, I think. /sys/i386/isa/npx.c start_emulating() stop_emulating() npxdna() Regards, -- Issei Suzuki