From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC510C433E2 for ; Fri, 4 Sep 2020 08:21:22 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 989152074D for ; Fri, 4 Sep 2020 08:21:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YgxS4rAr"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MB+YqWZ0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 989152074D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nZyeWCuYrOA9ZXxfvfjU56qmw+rpcCEk8cslrVQSoKQ=; b=YgxS4rAri2k1o0gwkvjDz62Tv etJKY/JTz2A6QhHj1vYvZjiazVg946IO6r8CCIsFdWHYqosD4Nc+ArsdvDJhq+syKgeRYrz2DfcHu /kLo3tr2/6IxYWYoEwZc/MROYMcfqWcz9fqXk+lWRftgFPaoeTkxn/a1fRIOyg0LdCKl3OpFdJV+W h4rn5+h+8XBj4TY+EzNxpzPWOJLePxjwJIsWj+t4nIPdjQVx9BgAPZos9aggTeljRqQSYdqZ9k159 Ag+BsmVeL2uMYaM1otPL27m5/4qsEv7PyAXkinyJXcSYrIUhSduh+cRV8VFJMIEEcX5IqeV2dsJLv pPXvS2XPg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kE6x8-0007FL-0w; Fri, 04 Sep 2020 08:20:10 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kE6wy-0007CB-Ob for linux-arm-kernel@lists.infradead.org; Fri, 04 Sep 2020 08:20:01 +0000 Received: by mail-lj1-x243.google.com with SMTP id e11so6938552ljn.6 for ; Fri, 04 Sep 2020 01:20:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MIT5oeyPm9oK5nW97TMG5UDzH/VjYQna/z8fF2xJ/KQ=; b=MB+YqWZ0goPsjl+jCKgQLeHpQ0MgEYIH/FtvRLYhBz5i7fP69YGLTYJgbFfYGMR1Pg dOo827INWp95xtfj3+qug+oP08bOoQQv7YLgWdsOQpfeTcZc5X1dt3NCf5GlBuBlsEdu G4fF1sY7WWOKFBoi+vbkVdKyNlyR7z/Gx7U8wKdiHrqLyqCZImVrcsqzO5thJasjggrm EJn+lj6T9z503/hdPM0PTPg0qe1IBhsP7N0AAbvII+NHhDQ1rUThH7ACpxjdpGWiBufF ruCXNcM6tRVY51YYcG1AbkuyKk/Pi3b6MSe82Qw7PdbGKVXY4F+4RMmzk/OWNHuXjcbn 8kLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MIT5oeyPm9oK5nW97TMG5UDzH/VjYQna/z8fF2xJ/KQ=; b=A5c8i1LvDr5bf46Z/+XhRBfT0DC9CTZNLdmiGESMvF5rhmkS9/Mcfbl1H106SQ6a9q ZdJ0F2DFIcOSPZzZReMEdE/I7xX9O8wRX71hL8uylaM7i3S1+uCfjltSbdauc5dbqPls lmVSH185vNNqfMUgR0uDOZ+67YcjaN6EA/suT6znJ6I/SJcX2WbFx1E+XH+YjpW/Xhff FWPWy0TlMyExCZBNAKLudlVPPvRbtHtmxQxFFzyj93EPXfUM9EBrjsfeG82L62+bNKeE 4p+FZ3+reYGlYljvyVfJr2gmtp5m92q3W8tc01cHl0sl6OMBLplu5CRQfnty1dEpexRT HTwA== X-Gm-Message-State: AOAM533sJG2MvdB8nOK7ra8JEvXecwPoWg9jzHmdjpSpV/o9XaJVhJis iRslj0dxeQmqJNrTQs2vkGDPfg== X-Google-Smtp-Source: ABdhPJyxwSWbbR7mVGVZH3IS4Y7TaA0DRyrXFXjJ1ItWiRnY81fx19Ls48rggr8PgmKiFF9tdc/ToQ== X-Received: by 2002:a2e:92cd:: with SMTP id k13mr3329383ljh.441.1599207599187; Fri, 04 Sep 2020 01:19:59 -0700 (PDT) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id v5sm1131054ljh.73.2020.09.04.01.19.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Sep 2020 01:19:58 -0700 (PDT) From: Linus Walleij To: Russell King Subject: [PATCH 3/3] RFC: ARM: head: Debug prints for section mappings Date: Fri, 4 Sep 2020 10:19:49 +0200 Message-Id: <20200904081949.5594-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200904081949.5594-1-linus.walleij@linaro.org> References: <20200904081949.5594-1-linus.walleij@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200904_042000_847225_3BAA3152 X-CRM114-Status: GOOD ( 23.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Geert Uytterhoeven , Arnd Bergmann , Nicolas Pitre , Linus Walleij , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This creates a facility to print the early 1MB section mappings of the kernel. By selecting the symbol CONFIG_DEBUG_EARLY_MAPPINGS we can get a printout of some of the early mappings as they are written into the swapper_pg_dir page table during very early boot. Currently I introduced hooks for printing the MMU enable 1:1 mappings, the kernel RAM mappings and the "r2" (ATAGs or DTB) mappings. The debug prints will show the physical address base and the virtual address base map, something like this for example: Uncompressing Linux... done, booting the kernel. MMU enable: 0x40300000->0x40300000 Kernel RAM: 0x40000000->0xc0000000 Kernel RAM: 0x40100000->0xc0100000 Kernel RAM: 0x40200000->0xc0200000 (...) Kernel RAM: 0x42500000->0xc2500000 Kernel RAM: 0x42600000->0xc2600000 ATAG/DTB : 0x43000000->0xc3000000 ATAG/DTB : 0x43100000->0xc3100000 This code does not try to be clever and shuffle registers around like some puzzle, instead we just store out r1 thru r6 into memory while printing and read them back afterwards. It is debug code anyway, so optimizations are not any concern here. Signed-off-by: Linus Walleij --- arch/arm/Kconfig.debug | 13 ++++- arch/arm/kernel/head.S | 109 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 120 insertions(+), 2 deletions(-) diff --git a/arch/arm/Kconfig.debug b/arch/arm/Kconfig.debug index 87912e5c2256..a1620f2d0963 100644 --- a/arch/arm/Kconfig.debug +++ b/arch/arm/Kconfig.debug @@ -1919,7 +1919,18 @@ config DEBUG_UNCOMPRESS When this option is set, the selected DEBUG_LL output method will be re-used for normal decompressor output on multiplatform kernels. - + +config DEBUG_EARLY_MAPPINGS + bool "Enable early section mapping debugging via DEBUG_LL output" + depends on DEBUG_LL + help + This option enables the kernel to print a list of all the 1 MB + section mappings used to map physical to virtual mempory + during the early boot. These mappings are used until the + kernel sets up the proper page table. + + The selected DEBUG_LL output method will be used for these debug + messages. config UNCOMPRESS_INCLUDE string diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S index 8b089c4c0d17..5758a99f6f0f 100644 --- a/arch/arm/kernel/head.S +++ b/arch/arm/kernel/head.S @@ -163,6 +163,109 @@ ENDPROC(stext) .long PAGE_OFFSET #endif +#ifdef CONFIG_DEBUG_EARLY_MAPPINGS +__debug_tmp: + .align + .long 0, 0, 0, 0, 0, 0 /* r1 thru r6 */ +__en_mmu_debug_txt: + .asciz "MMU enable: " + .align +__ram_debug_txt: + .asciz "Kernel RAM: " + .align +__r2_debug_txt: + .asciz "ATAG/DTB : " + .align + /* + * This macro prints one physical to virtual section map using + * a section descriptor and a section table address + */ + .macro dbg_pr, secd, vindex + /* Only the physical address in secd please */ + bic \secd, \secd, #0x000ff000 + bic \secd, \secd, #0x00000ff0 + bic \secd, \secd, #0x0000000f + /* Convert the section index to a virtual address */ + bic \vindex, \vindex, #0xff000000 + bic \vindex, \vindex, #0x00ff0000 + bic \vindex, \vindex, #0x0000c000 + lsr \vindex, \vindex, #PMD_ORDER /* Convert to index */ + lsl \vindex, \vindex, #SECTION_SHIFT /* Convert to virtual address */ + mov r0, #'0' + bl printch + mov r0, #'x' + bl printch + mov r0, \secd + bl printhex8 + mov r0, #'-' + bl printch + mov r0, #'>' + bl printch + mov r0, #'0' + bl printch + mov r0, #'x' + bl printch + mov r0, \vindex + bl printhex8 + mov r0, #'\n' + bl printch + .endm + + /* + * r3 = current section descriptor, bits 31-20 is the physical address + * r5 = section table index + */ + .macro dbg_pr_mmu + adr r0, __debug_tmp + stmia r0, {r1-r6} + mov r6, r3 /* Save r3 to r6 (print corrupts r3) */ + adr r0, __en_mmu_debug_txt + bl printascii + /* Print helper wants physical offset index */ + lsl r5, r5, #PMD_ORDER + dbg_pr r6, r5 + adr r0, __debug_tmp + ldmia r0, {r1-r6} + .endm + + /* + * r0 = section table index absolute address in physical memory + * r3 = current section descriptor, bits 31-20 is the physical address + */ + .macro dbg_pr_ram + mov r5, r0 /* Save r0 in r5 */ + adr r0, __debug_tmp + stmia r0, {r1-r6} + mov r6, r3 /* Save r3 to r6 (print corrupts r3) */ + adr r0, __ram_debug_txt + bl printascii + dbg_pr r6, r5 + adr r0, __debug_tmp + ldmia r0, {r1-r6} + mov r0, r5 /* Restore r0 from r5 */ + .endm + + /* Debug text for "what is in r2" either ATAGs or a DTB */ + .macro dbg_pr_r2 + adr r0, __debug_tmp + stmia r0, {r1-r6} + mov r5, r3 /* Save r3 to r5 (print corrupts r3) */ + adr r0, __r2_debug_txt + bl printascii + dbg_pr r6, r5 + adr r0, __debug_tmp + ldmia r0, {r1-r6} + .endm +#else + /* Dummy stubs when not debugging */ + .macro dbg_pr_mmu + .endm + .macro dbg_pr_ram + .endm + .macro dbg_pr_r2 + .endm +#endif /* CONFIG_DEBUG_EARLY_MAPPINGS */ + /* * Setup the initial page tables. We only setup the barest * amount which are required to get the kernel running, which @@ -234,6 +337,7 @@ __create_page_tables: mov r6, r6, lsr #SECTION_SHIFT 1: orr r3, r7, r5, lsl #SECTION_SHIFT @ flags + kernel base + dbg_pr_mmu str r3, [r4, r5, lsl #PMD_ORDER] @ identity mapping cmp r5, r6 addlo r5, r5, #1 @ next section @@ -246,7 +350,8 @@ __create_page_tables: ldr r6, =(_end - 1) orr r3, r8, r7 add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER) -1: str r3, [r0], #1 << PMD_ORDER +1: dbg_pr_ram + str r3, [r0], #1 << PMD_ORDER add r3, r3, #1 << SECTION_SHIFT cmp r0, r6 bls 1b @@ -281,8 +386,10 @@ __create_page_tables: add r3, r3, #PAGE_OFFSET add r3, r4, r3, lsr #(SECTION_SHIFT - PMD_ORDER) orr r6, r7, r0 + dbg_pr_r2 str r6, [r3], #1 << PMD_ORDER add r6, r6, #1 << SECTION_SHIFT + dbg_pr_r2 str r6, [r3] 1: -- 2.26.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel