From owner-freebsd-hackers@freebsd.org Thu Aug 6 10:24:39 2015 Return-Path: Delivered-To: freebsd-hackers@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 63A5A9B5CE0 for ; Thu, 6 Aug 2015 10:24:39 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EBB9E1659 for ; Thu, 6 Aug 2015 10:24:38 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id t76AOYXT096861 (version=TLSv1 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 6 Aug 2015 13:24:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t76AOYXT096861 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id t76AOYTs096860; Thu, 6 Aug 2015 13:24:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 6 Aug 2015 13:24:34 +0300 From: Konstantin Belousov To: TJ Lee Cc: freebsd-hackers@freebsd.org Subject: Re: Trying to understand kernel trap code Message-ID: <20150806102434.GH2072@kib.kiev.ua> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Aug 2015 10:24:39 -0000 On Thu, Aug 06, 2015 at 12:09:05PM +0200, TJ Lee wrote: > Hi, > > I just started looking at FreeBSD kernel code in more detail and > want to understand the low-level entry points into the kernel on a > x86-64 CPU. What I'd like to know is precisely what happens when I > execute a "syscall" instruction in user-land. More specifically, what > instruction in what assembly source file is RIP/CS loaded with on > executing syscall? Also where in the source code do we load the MSRs > with these values? > Read the sys/amd64/amd64/exception.S, fast_syscall entry point. Grep for MSR_*STAR msr names to see how syscall MSRs are configured, in particular, on BSP in hammer_time(), on AP in init_secondary(). You need to read the IA32 manual about syscall instruction to understand how it all plays together.