tag:blogger.com,1999:blog-36940421777425146652024-03-05T16:39:28.309-08:00What? Notes!一個極度健忘的資工宅貓,持續努力喵的coding吧!ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.comBlogger20125tag:blogger.com,1999:blog-3694042177742514665.post-11093450969472483262016-12-01T00:26:00.002-08:002016-12-01T00:26:53.815-08:00setup_arch(4) - PSCI partial 看完local_async_enable, 繼續 trace setup_arch()囉<br />
<span style="color: red;">[cpu_uninstall_idmap]</span><br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L252" name="L252" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">252</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L253" name="L253" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">253</a> <b><i> * TTBR0 is only used for the identity mapping at this stage. Make it</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L254" name="L254" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">254</a> <b><i> * point to zero page to avoid speculatively fetching new entries.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L255" name="L255" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">255</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L256" name="L256" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">256</a> <a href="http://lxr.free-electrons.com/ident?i=cpu_uninstall_idmap" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpu_uninstall_idmap</a>();</pre>
<div>
<br /></div>
看到TTBR0了, 先來看看這個register在幹嘛? Programmers Guide的定義如下<br />
<div>
<div>
<div>
<span style="color: #3d85c6;"><b>TTBR0_ELn (Translation Table Base Register 0)</b></span></div>
<div>
Holds the base address of translation table 0, and information</div>
<div>
about the memory it occupies. This is one of the translation</div>
<div>
tables for the stage 1 translation of memory accesses at ELn.</div>
</div>
</div>
<div>
TTBR0儲存PGD的address, 因此現階段一律將TTBR0指到zero page<br />
detail以後有空再trace<br />
<br />
[keep going]<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L258" name="L258" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">258</a> <a href="http://lxr.free-electrons.com/ident?i=xen_early_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">xen_early_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L259" name="L259" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">259</a> <a href="http://lxr.free-electrons.com/ident?i=efi_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">efi_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L260" name="L260" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">260</a> <a href="http://lxr.free-electrons.com/ident?i=arm64_memblock_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm64_memblock_init</a>();</pre>
<div>
xen_early_init():</div>
處理hypervisor的device tree (more see Documentation/devicetree/bindings/arm/xen.txt for the <a href="http://lxr.free-electrons.com/source/arch/arm/xen/enlighten.c#L258">258</a> * documentation of the Xen Device Tree format.)</div>
<div>
<br /></div>
<div>
efi_init():</div>
<div>
跟UEFI related 的operations --> skip</div>
<div>
<br /></div>
<div>
arm64_memblock_init():</div>
<div>
在系統初始化階段, Linux 的memory 機制尚未啟動(buddy), 因此系統init初期是使用memblock 機制來分配physical memory 給大家使用</div>
<div>
more can see reference as follows</div>
<div>
(1) http://www.maxwellxxx.com/linuxmemblock</div>
<div>
(2) http://blog.jobbole.com/88452/</div>
<div>
(3) http://lib.csdn.net/article/linux/45665</div>
<div>
<br /></div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L262" name="L262" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">262</a> <a href="http://lxr.free-electrons.com/ident?i=paging_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">paging_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L263" name="L263" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">263</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L264" name="L264" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">264</a> <a href="http://lxr.free-electrons.com/ident?i=acpi_table_upgrade" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">acpi_table_upgrade</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L265" name="L265" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">265</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L266" name="L266" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">266</a> <b><i>/* Parse the ACPI tables for possible boot-time configuration */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L267" name="L267" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">267</a> <a href="http://lxr.free-electrons.com/ident?i=acpi_boot_table_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">acpi_boot_table_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L268" name="L268" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">268</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L269" name="L269" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">269</a> if (<a href="http://lxr.free-electrons.com/ident?i=acpi_disabled" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">acpi_disabled</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L270" name="L270" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">270</a> <a href="http://lxr.free-electrons.com/ident?i=unflatten_device_tree" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">unflatten_device_tree</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L271" name="L271" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">271</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L272" name="L272" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">272</a> <a href="http://lxr.free-electrons.com/ident?i=bootmem_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">bootmem_init</a>();</pre>
</div>
<div>
<br /></div>
<div>
paging_init():</div>
<div>
set up page tables (initialize paging mechanism)</div>
<div>
<br /></div>
<div>
acpi_table_upgrade():</div>
<div>
acpi_boot_table_init():</div>
<div>
skip</div>
<div>
<br /></div>
<div>
bootmem_init():</div>
<div>
initialize memory management.</div>
<div>
more can see reference as follows</div>
<div>
(1) http://www.voidcn.com/blog/gatieme/article/p-6183366.html</div>
<div>
<br /></div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L274" name="L274" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">274</a> <a href="http://lxr.free-electrons.com/ident?i=kasan_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">kasan_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L275" name="L275" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">275</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L276" name="L276" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">276</a> <a href="http://lxr.free-electrons.com/ident?i=request_standard_resources" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">request_standard_resources</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L277" name="L277" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">277</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L278" name="L278" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">278</a> <a href="http://lxr.free-electrons.com/ident?i=early_ioremap_reset" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_ioremap_reset</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L279" name="L279" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">279</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L280" name="L280" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">280</a> if (<a href="http://lxr.free-electrons.com/ident?i=acpi_disabled" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">acpi_disabled</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L281" name="L281" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">281</a> <a href="http://lxr.free-electrons.com/ident?i=psci_dt_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_dt_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L282" name="L282" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">282</a> else
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L283" name="L283" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">283</a> <a href="http://lxr.free-electrons.com/ident?i=psci_acpi_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_acpi_init</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L284" name="L284" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">284</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L285" name="L285" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">285</a> <a href="http://lxr.free-electrons.com/ident?i=cpu_read_bootcpu_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpu_read_bootcpu_ops</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L286" name="L286" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">286</a> <a href="http://lxr.free-electrons.com/ident?i=smp_init_cpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">smp_init_cpus</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L287" name="L287" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">287</a> <a href="http://lxr.free-electrons.com/ident?i=smp_build_mpidr_hash" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">smp_build_mpidr_hash</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L288" name="L288" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">288</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L289" name="L289" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">289</a> #ifdef CONFIG_VT
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L290" name="L290" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">290</a> #if defined(CONFIG_VGA_CONSOLE)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L291" name="L291" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">291</a> <a href="http://lxr.free-electrons.com/ident?i=conswitchp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">conswitchp</a> = &<a href="http://lxr.free-electrons.com/ident?i=vga_con" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">vga_con</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L292" name="L292" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">292</a> #elif defined(CONFIG_DUMMY_CONSOLE)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L293" name="L293" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">293</a> <a href="http://lxr.free-electrons.com/ident?i=conswitchp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">conswitchp</a> = &<a href="http://lxr.free-electrons.com/ident?i=dummy_con" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">dummy_con</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L294" name="L294" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">294</a> #endif
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L295" name="L295" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">295</a> #endif
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L296" name="L296" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">296</a> if (<a href="http://lxr.free-electrons.com/ident?i=boot_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[1] || <a href="http://lxr.free-electrons.com/ident?i=boot_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[2] || <a href="http://lxr.free-electrons.com/ident?i=boot_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[3]) {
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L297" name="L297" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">297</a> <a href="http://lxr.free-electrons.com/ident?i=pr_err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_err</a>(<i>"WARNING: x1-x3 nonzero in violation of boot protocol:\n"</i>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L298" name="L298" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">298</a> <i>"\tx1: %016llx\n\tx2: %016llx\n\tx3: %016llx\n"</i>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L299" name="L299" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">299</a> <i>"This indicates a broken bootloader or old kernel\n"</i>,
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L300" name="L300" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">300</a> <a href="http://lxr.free-electrons.com/ident?i=boot_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[1], <a href="http://lxr.free-electrons.com/ident?i=boot_args" style="background-attachment: initial; background-clip: initial; background-image: none; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[2], <a href="http://lxr.free-electrons.com/ident?i=boot_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_args</a>[3]);
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L301" name="L301" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">301</a> }</pre>
</div>
<div>
kasan_init():</div>
<div>
kernel address sanitizer</div>
<div>
是一個可以dynamic memory error detector</div>
<div>
more can see the reference as follows </div>
<div>
(1) http://www.ibm.com/developerworks/cn/linux/1608_tengr_kasan/index.html</div>
<div>
(2) http://lxr.free-electrons.com/source/Documentation/kasan.txt</div>
<div>
<br /></div>
<div>
request_standard_resource():</div>
<div>
每一個cpu上掛的device 會用一個struct resource 記錄這個device需要使用的physical address(iomem)的info (eg. 起始位置)</div>
<div>
more can see the reference as follows</div>
<div>
(1) http://blog.csdn.net/boarmy/article/details/8652763</div>
<div>
<br /></div>
<div>
early_ioremap_reset():</div>
<div>
set after_paging_init = 1</div>
<div>
<br /></div>
<div>
psci_dt_init():</div>
<div>
acpi_disabled =1 被define在 arch/arm64/kernel/acpi.c, line 38</div>
<div>
grep .config 也沒有發現CONFIG_PSCI</div>
<div>
因此會走psci_dt_init()</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L618" name="L618" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">618</a> static const struct <a href="http://lxr.free-electrons.com/ident?i=of_device_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_device_id</a> psci_of_match[] <a href="http://lxr.free-electrons.com/ident?i=__initconst" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__initconst</a> = {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L619" name="L619" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">619</a> { .compatible = <i>"arm,psci"</i>, .<a href="http://lxr.free-electrons.com/ident?i=data" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">data</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_0_1_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_1_init</a>},
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L620" name="L620" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">620</a> { .compatible = <i>"arm,psci-0.2"</i>, .<a href="http://lxr.free-electrons.com/ident?i=data" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">data</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_0_2_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_2_init</a>},
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L621" name="L621" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">621</a> { .compatible = <i>"arm,psci-1.0"</i>, .<a href="http://lxr.free-electrons.com/ident?i=data" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">data</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_0_2_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_2_init</a>},
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L622" name="L622" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">622</a> {},
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L623" name="L623" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">623</a> };</pre>
</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L625" name="L625" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">625</a> int <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_dt_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_dt_init</a>(void)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L626" name="L626" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">626</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L627" name="L627" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">627</a> struct <a href="http://lxr.free-electrons.com/ident?i=device_node" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">device_node</a> *<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L628" name="L628" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">628</a> const struct <a href="http://lxr.free-electrons.com/ident?i=of_device_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_device_id</a> *matched_np;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L629" name="L629" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">629</a> <a href="http://lxr.free-electrons.com/ident?i=psci_initcall_t" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_initcall_t</a> init_fn;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L630" name="L630" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">630</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L631" name="L631" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">631</a> <a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a> = <a href="http://lxr.free-electrons.com/ident?i=of_find_matching_node_and_match" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_find_matching_node_and_match</a>(<a href="http://lxr.free-electrons.com/ident?i=NULL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NULL</a>, psci_of_match, &matched_np);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L632" name="L632" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">632</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L633" name="L633" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">633</a> if (!<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L634" name="L634" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">634</a> return -<a href="http://lxr.free-electrons.com/ident?i=ENODEV" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">ENODEV</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L635" name="L635" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">635</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L636" name="L636" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">636</a> init_fn = (<a href="http://lxr.free-electrons.com/ident?i=psci_initcall_t" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_initcall_t</a>)matched_np-><a href="http://lxr.free-electrons.com/ident?i=data" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">data</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L637" name="L637" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">637</a> return init_fn(<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L638" name="L638" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">638</a> }</pre>
</div>
<div>
<br /></div>
<div>
of_find_matching_node_and_match() 會到device tree中search 有無與 psci_of_match[] 中定義的element 一樣的node (根據compatible), 若有找到, 將 matched_np 指向psci_of_match[]中的element</div>
<div>
for example, we got compatible="arm,psci-0.2" in our device tree, 因此match_np指向psci_of_match[1], 代表目前使用的是psci 0.2 版</div>
<div>
接著將matched_np->data 轉成function pointer</div>
<div>
然後執行psci_0_2_init, 同時帶入參數np</div>
<div>
<br /></div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L549" name="L549" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">549</a> typedef int (*<a href="http://lxr.free-electrons.com/ident?i=psci_initcall_t" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_initcall_t</a>)(const struct <a href="http://lxr.free-electrons.com/ident?i=device_node" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">device_node</a> *);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L550" name="L550" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">550</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L551" name="L551" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">551</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L552" name="L552" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">552</a> <b><i> * PSCI init function for PSCI versions >=0.2</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L553" name="L553" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">553</a> <b><i> *</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L554" name="L554" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">554</a> <b><i> * Probe based on PSCI PSCI_VERSION function</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L555" name="L555" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">555</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L556" name="L556" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">556</a> static int <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_0_2_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_2_init</a>(struct <a href="http://lxr.free-electrons.com/ident?i=device_node" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">device_node</a> *<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L557" name="L557" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">557</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L558" name="L558" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">558</a> int <a href="http://lxr.free-electrons.com/ident?i=err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">err</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L559" name="L559" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">559</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L560" name="L560" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">560</a> <a href="http://lxr.free-electrons.com/ident?i=err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">err</a> = <a href="http://lxr.free-electrons.com/ident?i=get_set_conduit_method" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">get_set_conduit_method</a>(<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L561" name="L561" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">561</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L562" name="L562" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">562</a> if (<a href="http://lxr.free-electrons.com/ident?i=err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">err</a>)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L563" name="L563" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">563</a> goto out_put_node;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L564" name="L564" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">564</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L565" name="L565" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">565</a> <b><i> * Starting with v0.2, the PSCI specification introduced a call</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L566" name="L566" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">566</a> <b><i> * (PSCI_VERSION) that allows probing the firmware version, so</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L567" name="L567" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">567</a> <b><i> * that PSCI function IDs and version specific initialization</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L568" name="L568" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">568</a> <b><i> * can be carried out according to the specific version reported</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L569" name="L569" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">569</a> <b><i> * by firmware</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L570" name="L570" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">570</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L571" name="L571" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">571</a> <a href="http://lxr.free-electrons.com/ident?i=err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">err</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_probe" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_probe</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L572" name="L572" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">572</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L573" name="L573" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">573</a> out_put_node:
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L574" name="L574" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">574</a> <a href="http://lxr.free-electrons.com/ident?i=of_node_put" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_node_put</a>(<a href="http://lxr.free-electrons.com/ident?i=np" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">np</a>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L575" name="L575" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">575</a> return <a href="http://lxr.free-electrons.com/ident?i=err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">err</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L576" name="L576" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">576</a> }</pre>
</div>
<div>
<br />
device tree will define psci node like this<br />
<span style="color: red;">psci {</span><br />
<span style="color: red;"> compatible = "arm, psci-0.2";</span><br />
<span style="color: red;"> method = "smc";</span><br />
<span style="color: red;">}</span><br />
<span style="font-size: xx-small;">(http://lxr.free-electrons.com/source/arch/arm64/boot/dts/mediatek/mt6795.dtsi)</span></div>
<div>
get_set_conduit_method() 會到device tree找這個node<br />
用<span style="color: black;"><a href="http://lxr.free-electrons.com/ident?i=of_property_read_string">of_property_read_string</a>(<a href="http://lxr.free-electrons.com/ident?i=np">np</a>, "method", &method)</span>找 method</div>
<div>
由node可知, psci在這邊是用smc的方式進入ATF, 因此會將invoke_psci_fn設定為 __invoke_psci_fn_smc</div>
<div>
<br /></div>
<div>
部分的get_set_conduit_method() code如下</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;">if (!<a href="http://lxr.free-electrons.com/ident?i=strcmp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">strcmp</a>(<i>"hvc"</i>, method)) {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L225" name="L225" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">225</a> <a href="http://lxr.free-electrons.com/ident?i=invoke_psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">invoke_psci_fn</a> = <a href="http://lxr.free-electrons.com/ident?i=__invoke_psci_fn_hvc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__invoke_psci_fn_hvc</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L226" name="L226" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">226</a> } else if (!<a href="http://lxr.free-electrons.com/ident?i=strcmp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">strcmp</a>(<i>"smc"</i>, method)) {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L227" name="L227" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">227</a> <a href="http://lxr.free-electrons.com/ident?i=invoke_psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">invoke_psci_fn</a> = <a href="http://lxr.free-electrons.com/ident?i=__invoke_psci_fn_smc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__invoke_psci_fn_smc</a>;</pre>
invoke_psci_fn是一個function pointer定義如下</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"> <a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L64" name="L64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">64</a> typedef unsigned long (<a href="http://lxr.free-electrons.com/ident?i=psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_fn</a>)(unsigned long, unsigned long,
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L65" name="L65" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">65</a> unsigned long, unsigned long);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L66" name="L66" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">66</a> static <a href="http://lxr.free-electrons.com/ident?i=psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_fn</a> *<a href="http://lxr.free-electrons.com/ident?i=invoke_psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">invoke_psci_fn</a>;</pre>
回到psci_0_2_init()</div>
<div>
接著執行psci_probe()</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L524" name="L524" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">524</a> static int <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_probe" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_probe</a>(void)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L525" name="L525" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">525</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L526" name="L526" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">526</a> <a href="http://lxr.free-electrons.com/ident?i=u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">u32</a> ver = <a href="http://lxr.free-electrons.com/ident?i=psci_get_version" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_get_version</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L527" name="L527" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">527</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L528" name="L528" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">528</a> <a href="http://lxr.free-electrons.com/ident?i=pr_info" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_info</a>(<i>"PSCIv%d.%d detected in firmware.\n"</i>,
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L529" name="L529" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">529</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_VERSION_MAJOR" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_VERSION_MAJOR</a>(ver),
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L530" name="L530" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">530</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_VERSION_MINOR" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_VERSION_MINOR</a>(ver));
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L531" name="L531" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">531</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L532" name="L532" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">532</a> if (<a href="http://lxr.free-electrons.com/ident?i=PSCI_VERSION_MAJOR" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_VERSION_MAJOR</a>(ver) == 0 && <a href="http://lxr.free-electrons.com/ident?i=PSCI_VERSION_MINOR" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_VERSION_MINOR</a>(ver) < 2) {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L533" name="L533" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">533</a> <a href="http://lxr.free-electrons.com/ident?i=pr_err" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_err</a>(<i>"Conflicting PSCI version detected.\n"</i>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L534" name="L534" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">534</a> return -<a href="http://lxr.free-electrons.com/ident?i=EINVAL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">EINVAL</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L535" name="L535" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">535</a> }
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L536" name="L536" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">536</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L537" name="L537" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">537</a> <a href="http://lxr.free-electrons.com/ident?i=psci_0_2_set_functions" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_2_set_functions</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L538" name="L538" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">538</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L539" name="L539" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">539</a> <a href="http://lxr.free-electrons.com/ident?i=psci_init_migrate" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_init_migrate</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L540" name="L540" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">540</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L541" name="L541" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">541</a> if (<a href="http://lxr.free-electrons.com/ident?i=PSCI_VERSION_MAJOR" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_VERSION_MAJOR</a>(ver) >= 1) {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L542" name="L542" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">542</a> <a href="http://lxr.free-electrons.com/ident?i=psci_init_cpu_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_init_cpu_suspend</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L543" name="L543" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">543</a> <a href="http://lxr.free-electrons.com/ident?i=psci_init_system_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_init_system_suspend</a>();
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L544" name="L544" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">544</a> }
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L545" name="L545" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">545</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L546" name="L546" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">546</a> return 0;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L547" name="L547" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">547</a> }</pre>
</div>
<div>
(1) psci_get_version()</div>
<div>
call invoke_psci_fn (也就是__invoke_psci_fn_smc()) get firmware version</div>
<div>
(2) psci_0_2_set_functions()</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L496" name="L496" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">496</a> static void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_0_2_set_functions" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_0_2_set_functions</a>(void)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L497" name="L497" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">497</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L498" name="L498" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">498</a> <a href="http://lxr.free-electrons.com/ident?i=pr_info" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_info</a>(<i>"Using standard PSCI v0.2 function IDs\n"</i>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L499" name="L499" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">499</a> <a href="http://lxr.free-electrons.com/ident?i=psci_function_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_function_id</a>[PSCI_FN_CPU_SUSPEND] =
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L500" name="L500" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">500</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_FN_NATIVE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_FN_NATIVE</a>(0_2, CPU_SUSPEND);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L501" name="L501" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">501</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.<a href="http://lxr.free-electrons.com/ident?i=cpu_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpu_suspend</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_cpu_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_cpu_suspend</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L502" name="L502" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">502</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L503" name="L503" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">503</a> <a href="http://lxr.free-electrons.com/ident?i=psci_function_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_function_id</a>[PSCI_FN_CPU_OFF] = <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_CPU_OFF" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_CPU_OFF</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L504" name="L504" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">504</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.cpu_off = <a href="http://lxr.free-electrons.com/ident?i=psci_cpu_off" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_cpu_off</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L505" name="L505" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">505</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L506" name="L506" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">506</a> <a href="http://lxr.free-electrons.com/ident?i=psci_function_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_function_id</a>[PSCI_FN_CPU_ON] = <a href="http://lxr.free-electrons.com/ident?i=PSCI_FN_NATIVE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_FN_NATIVE</a>(0_2, CPU_ON);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L507" name="L507" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">507</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.cpu_on = <a href="http://lxr.free-electrons.com/ident?i=psci_cpu_on" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_cpu_on</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L508" name="L508" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">508</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L509" name="L509" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">509</a> <a href="http://lxr.free-electrons.com/ident?i=psci_function_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_function_id</a>[PSCI_FN_MIGRATE] = <a href="http://lxr.free-electrons.com/ident?i=PSCI_FN_NATIVE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_FN_NATIVE</a>(0_2, MIGRATE);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L510" name="L510" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">510</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.migrate = <a href="http://lxr.free-electrons.com/ident?i=psci_migrate" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_migrate</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L511" name="L511" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">511</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L512" name="L512" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">512</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.affinity_info = <a href="http://lxr.free-electrons.com/ident?i=psci_affinity_info" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_affinity_info</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L513" name="L513" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">513</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L514" name="L514" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">514</a> <a href="http://lxr.free-electrons.com/ident?i=psci_ops" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_ops</a>.migrate_info_type = <a href="http://lxr.free-electrons.com/ident?i=psci_migrate_info_type" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_migrate_info_type</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L515" name="L515" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">515</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L516" name="L516" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">516</a> <a href="http://lxr.free-electrons.com/ident?i=arm_pm_restart" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_pm_restart</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_sys_reset" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_sys_reset</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L517" name="L517" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">517</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L518" name="L518" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">518</a> <a href="http://lxr.free-electrons.com/ident?i=pm_power_off" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pm_power_off</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_sys_poweroff" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_sys_poweroff</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L519" name="L519" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">519</a> }</pre>
</div>
<div>
<br /></div>
<div>
首先psci.c裡面有define</div>
enum <a href="http://lxr.free-electrons.com/ident?v=4.4;i=psci_function">psci_function</a> { <br />
PSCI_FN_CPU_SUSPEND, <br />
PSCI_FN_CPU_ON, <br />
PSCI_FN_CPU_OFF, <br />
PSCI_FN_MIGRATE, <br />
PSCI_FN_MAX,<br />
};<br />
static <a href="http://lxr.free-electrons.com/ident?v=4.4;i=u32">u32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=psci_function_id">psci_function_id</a>[PSCI_FN_MAX];<br />
<div>
<div>
<br /></div>
</div>
<div>
psci有四種function, 這些function各有id define在上面的enum裡<br />
另外還有 PSCI_FN_NATIVE 這個macro, </div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L32" name="L32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">32</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L33" name="L33" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">33</a> <b><i> * While a 64-bit OS can make calls with SMC32 calling conventions, for some</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L34" name="L34" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">34</a> <b><i> * calls it is necessary to use SMC64 to pass or return 64-bit values.</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L35" name="L35" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">35</a> <b><i> * For such calls PSCI_FN_NATIVE(version, name) will choose the appropriate</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L36" name="L36" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">36</a> <b><i> * (native-width) function ID.</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L37" name="L37" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">37</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L38" name="L38" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">38</a> #ifdef <a href="http://lxr.free-electrons.com/ident?v=4.4;i=CONFIG_64BIT" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">CONFIG_64BIT</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L39" name="L39" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">39</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=PSCI_FN_NATIVE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_FN_NATIVE</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=version" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">version</a>, <a href="http://lxr.free-electrons.com/ident?v=4.4;i=name" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">name</a>) PSCI_##version##_FN64_##name
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L40" name="L40" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">40</a> #else
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L41" name="L41" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">41</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=PSCI_FN_NATIVE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_FN_NATIVE</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=version" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">version</a>, <a href="http://lxr.free-electrons.com/ident?v=4.4;i=name" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">name</a>) PSCI_##version##_FN_##name
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c?v=4.4#L42" name="L42" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">42</a> #endif</pre>
</div>
<div>
我們有define CONFIG_64BIT<br />
因此macro 炸開會變成 PSCI_0_2_FN64_[NAME]<br />
<br />
另外還有一個重要的params<br />
<span style="color: red;">struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=psci_operations">psci_operations</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=psci_ops">psci_ops</a>;</span></div>
<div>
這是一個psci_operations, struct定義如下<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L27" name="L27" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">27</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=psci_operations" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_operations</a> {
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L28" name="L28" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">28</a> int (*<a href="http://lxr.free-electrons.com/ident?v=4.4;i=cpu_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpu_suspend</a>)(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">u32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=state" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">state</a>, unsigned long entry_point);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L29" name="L29" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">29</a> int (*cpu_off)(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">u32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=state" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">state</a>);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L30" name="L30" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">30</a> int (*cpu_on)(unsigned long <a href="http://lxr.free-electrons.com/ident?v=4.4;i=cpuid" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpuid</a>, unsigned long entry_point);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L31" name="L31" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">31</a> int (*migrate)(unsigned long <a href="http://lxr.free-electrons.com/ident?v=4.4;i=cpuid" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpuid</a>);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L32" name="L32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">32</a> int (*affinity_info)(unsigned long target_affinity,
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L33" name="L33" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">33</a> unsigned long lowest_affinity_level);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L34" name="L34" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">34</a> int (*migrate_info_type)(void);
<a href="http://lxr.free-electrons.com/source/include/linux/psci.h?v=4.4#L35" name="L35" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">35</a> };</pre>
<br />
回到psci_0_2_set_functions()會發現這個function一開始會設定大家的suspend/on/off/migrate 的function id, 以及掛上callback functions<br />
深入進去看<br />
<div>
psci_function_id[PSCI_FN_CPU_SUSPEND] =PSCI_0_2_CPU_SUSPEND</div>
<div>
psci_ops.cpu_suspend = psci_cpu_suspend;</div>
<div>
(WHERE defines) PSCI_0_2_CPU_SUSPEND ??</div>
<div>
<br /></div>
<div>
psci_function_id[PSCI_FN_CPU_OFF] = PSCI_0_2_FN_CPU_OFF</div>
<div>
psci_ops.cpu_off = psci_cpu_off;</div>
<div>
<br /></div>
<div>
psci_function_id[PSCI_FN_CPU_ON] = PSCI_FN_0_2,_CPU_ON</div>
<div>
psci_ops.cpu_on = psci_cpu_on;</div>
<div>
<br /></div>
<div>
psci_function_id[PSCI_FN_MIGRATE] = PSCI_FN_0_2_MIGRATE</div>
<div>
psci_ops.migrate = psci_migrate;</div>
<div>
<br /></div>
<div>
psci_ops.affinity_info = psci_affinity_info;</div>
<div>
psci_ops.migrate_info_type = psci_migrate_info_type;</div>
<div>
<br />
關於function id 定義在http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L34<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L24" name="L24" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">24</a> <b><i>/* PSCI v0.2 interface */</i></b>
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L25" name="L25" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">25</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_BASE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_BASE</a> 0x84000000
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L26" name="L26" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">26</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(<a href="http://lxr.free-electrons.com/ident?i=n" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">n</a>) (<a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_BASE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_BASE</a> + (<a href="http://lxr.free-electrons.com/ident?i=n" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">n</a>))
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L27" name="L27" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">27</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_64BIT" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_64BIT</a> 0x40000000
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L28" name="L28" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">28</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_BASE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_BASE</a> \
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L29" name="L29" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">29</a> (<a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_BASE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_BASE</a> + <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_64BIT" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_64BIT</a>)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L30" name="L30" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">30</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(<a href="http://lxr.free-electrons.com/ident?i=n" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">n</a>) (<a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_BASE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_BASE</a> + (<a href="http://lxr.free-electrons.com/ident?i=n" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">n</a>))
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L31" name="L31" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">31</a>
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L32" name="L32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">32</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_PSCI_VERSION" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_PSCI_VERSION</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(0)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L33" name="L33" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">33</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_CPU_SUSPEND" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_CPU_SUSPEND</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(1)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L34" name="L34" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">34</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_CPU_OFF" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_CPU_OFF</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(2)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L35" name="L35" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">35</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_CPU_ON" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_CPU_ON</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(3)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L36" name="L36" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">36</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_AFFINITY_INFO" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_AFFINITY_INFO</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(4)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L37" name="L37" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">37</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_MIGRATE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_MIGRATE</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(5)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L38" name="L38" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">38</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_MIGRATE_INFO_TYPE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_MIGRATE_INFO_TYPE</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(6)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L39" name="L39" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">39</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_MIGRATE_INFO_UP_CPU" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_MIGRATE_INFO_UP_CPU</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(7)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L40" name="L40" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">40</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_SYSTEM_OFF" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_SYSTEM_OFF</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(8)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L41" name="L41" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">41</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN_SYSTEM_RESET" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN_SYSTEM_RESET</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(9)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L42" name="L42" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">42</a>
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L43" name="L43" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">43</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_CPU_SUSPEND" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_CPU_SUSPEND</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(1)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L44" name="L44" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">44</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_CPU_ON" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_CPU_ON</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(3)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L45" name="L45" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">45</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_AFFINITY_INFO" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_AFFINITY_INFO</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(4)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L46" name="L46" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">46</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_MIGRATE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_MIGRATE</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(5)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L47" name="L47" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">47</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(7)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L48" name="L48" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">48</a>
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L49" name="L49" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">49</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_1_0_FN_PSCI_FEATURES" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_1_0_FN_PSCI_FEATURES</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(10)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L50" name="L50" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">50</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_1_0_FN_SYSTEM_SUSPEND" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_1_0_FN_SYSTEM_SUSPEND</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN</a>(14)
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L51" name="L51" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">51</a>
<a href="http://lxr.free-electrons.com/source/include/uapi/linux/psci.h#L52" name="L52" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">52</a> #define <a href="http://lxr.free-electrons.com/ident?i=PSCI_1_0_FN64_SYSTEM_SUSPEND" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_1_0_FN64_SYSTEM_SUSPEND</a> <a href="http://lxr.free-electrons.com/ident?i=PSCI_0_2_FN64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_0_2_FN64</a>(14)</pre>
</div>
<div>
所有的function id 都是psci base + idx<br />
我看的是64bit的case<br />
因此 psci base = PSCI_0_2_FN64_BASE = 0xC4000000<br />
psci version id = base + 0<br />
cpu_suspend = base + 1<br />
依此類推<br />
<br />
另外還有兩個function pointers: arm_pm_restart, pm_power_off</div>
<div>
分別hook 上psci_sys_reset, psci_sys_poweroff</div>
<div>
指定reset & poweroff時要做什麼事</div>
<div>
arm_pm_restart = psci_sys_reset;</div>
<div>
pm_power_off = psci_sys_poweroff;</div>
</div>
<div>
<div>
<br /></div>
<div>
(3) psci_init_migrate()</div>
<div>
skip<br />
<br />
(4) psci_init_cpu_suspend()<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L448" name="L448" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">448</a> static void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_init_cpu_suspend" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_init_cpu_suspend</a>(void)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L449" name="L449" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">449</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L450" name="L450" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">450</a> int <a href="http://lxr.free-electrons.com/ident?i=feature" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">feature</a> = <a href="http://lxr.free-electrons.com/ident?i=psci_features" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_features</a>(<a href="http://lxr.free-electrons.com/ident?i=psci_function_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_function_id</a>[PSCI_FN_CPU_SUSPEND]);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L451" name="L451" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">451</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L452" name="L452" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">452</a> if (<a href="http://lxr.free-electrons.com/ident?i=feature" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">feature</a> != <a href="http://lxr.free-electrons.com/ident?i=PSCI_RET_NOT_SUPPORTED" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_RET_NOT_SUPPORTED</a>)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L453" name="L453" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">453</a> <a href="http://lxr.free-electrons.com/ident?i=psci_cpu_suspend_feature" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_cpu_suspend_feature</a> = <a href="http://lxr.free-electrons.com/ident?i=feature" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">feature</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L454" name="L454" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">454</a> }</pre>
主要是將 cpu suspend 的function id 帶入 psci features function, 檢查cpu suspend 的function handler 是否存在<br />
而要看cpu_suspend是否存在, 要看psci_features return的64bit value<br />
return value 的format 如下<br />
<br />
if Func ID 是 0x84000001(SMC32)/0xC4000001 (SMC64) for CPU_SUSPEND<br />
Bits[31:2] : 若存在, must be 0<br />
Bits[1:1]: 0 if the implementation uses original format for the power_state parameter<br />
1 if the implementation uses the new extended StateID format for the power_state param<br />
Bits[0:0]: 0 if not support os initiated mode<br />
1 if support os initiated mode<br />
else<br />
its[31:0] : 若存在, must be 0<br />
<br />
return value 會跟 PSCI_RET_NOT_SUPPORTET(-1)比對, 若不為-1代表存在就將 feature assign 給 psci_cpu_suspend 這個variable<br />
<br />
進一步看一下psci_features (第一個參數是psci_feature本身的function id, 第二個參數是欲查詢的function id<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L245" name="L245" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">245</a> static int <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=psci_features" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">psci_features</a>(<a href="http://lxr.free-electrons.com/ident?i=u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">u32</a> psci_func_id)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L246" name="L246" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">246</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L247" name="L247" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">247</a> return <a href="http://lxr.free-electrons.com/ident?i=invoke_psci_fn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">invoke_psci_fn</a>(<a href="http://lxr.free-electrons.com/ident?i=PSCI_1_0_FN_PSCI_FEATURES" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PSCI_1_0_FN_PSCI_FEATURES</a>,
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L248" name="L248" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">248</a> psci_func_id, 0, 0);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L249" name="L249" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">249</a> }</pre>
psci_features 裡面其實是個smc call, invoke_psci_fn相當於<a href="http://lxr.free-electrons.com/ident?i=__invoke_psci_fn_smc">__invoke_psci_fn_smc</a></div>
<div>
如下, __invoke_psci_fn_smc裡面call arm_smccc_smc才會真正做一次smc call 到EL3, 第一個參數為function id, 後面有三個arg 可以將info帶入到smc call</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L123" name="L123" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">123</a> static unsigned long <a href="http://lxr.free-electrons.com/ident?i=__invoke_psci_fn_smc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__invoke_psci_fn_smc</a>(unsigned long function_id,
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L124" name="L124" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">124</a> unsigned long arg0, unsigned long <a href="http://lxr.free-electrons.com/ident?i=arg1" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arg1</a>,
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L125" name="L125" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">125</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=arg2" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arg2</a>)
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L126" name="L126" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">126</a> {
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L127" name="L127" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">127</a> struct <a href="http://lxr.free-electrons.com/ident?i=arm_smccc_res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_smccc_res</a> <a href="http://lxr.free-electrons.com/ident?i=res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">res</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L128" name="L128" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">128</a>
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L129" name="L129" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">129</a> <a href="http://lxr.free-electrons.com/ident?i=arm_smccc_smc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_smccc_smc</a>(function_id, arg0, <a href="http://lxr.free-electrons.com/ident?i=arg1" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arg1</a>, <a href="http://lxr.free-electrons.com/ident?i=arg2" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arg2</a>, 0, 0, 0, 0, &<a href="http://lxr.free-electrons.com/ident?i=res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">res</a>);
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L130" name="L130" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">130</a> return <a href="http://lxr.free-electrons.com/ident?i=res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">res</a>.<a href="http://lxr.free-electrons.com/ident?i=a0" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a0</a>;
<a href="http://lxr.free-electrons.com/source/drivers/firmware/psci.c#L131" name="L131" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">131</a> }</pre>
<br />
arm_smccc_smc() 定義在http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L84<br />
底層的EL3 應該是assembly code, 因此這裡加上gcc compile conigs <b>asmlinkage</b><br />
並且將要傳遞的參數存入register 0-7<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L74" name="L74" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">74</a> <b><i>/**</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L75" name="L75" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">75</a> <b><i> * arm_smccc_smc() - make SMC calls</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L76" name="L76" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">76</a> <b><i> * @a0-a7: arguments passed in registers 0 to 7</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L77" name="L77" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">77</a> <b><i> * @res: result values from registers 0 to 3</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L78" name="L78" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">78</a> <b><i> *</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L79" name="L79" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">79</a> <b><i> * This function is used to make SMC calls following SMC Calling Convention.</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L80" name="L80" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">80</a> <b><i> * The content of the supplied param are copied to registers 0 to 7 prior</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L81" name="L81" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">81</a> <b><i> * to the SMC instruction. The return values are updated with the content</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L82" name="L82" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">82</a> <b><i> * from register 0 to 3 on return from the SMC instruction.</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L83" name="L83" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">83</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L84" name="L84" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">84</a> <a href="http://lxr.free-electrons.com/ident?i=asmlinkage" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">asmlinkage</a> void <a href="http://lxr.free-electrons.com/ident?i=arm_smccc_smc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_smccc_smc</a>(unsigned long <a href="http://lxr.free-electrons.com/ident?i=a0" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a0</a>, unsigned long <a href="http://lxr.free-electrons.com/ident?i=a1" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a1</a>,
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L85" name="L85" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">85</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a2" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a2</a>, unsigned long <a href="http://lxr.free-electrons.com/ident?i=a3" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a3</a>, unsigned long <a href="http://lxr.free-electrons.com/ident?i=a4" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a4</a>,
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L86" name="L86" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">86</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a5" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a5</a>, unsigned long <a href="http://lxr.free-electrons.com/ident?i=a6" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a6</a>, unsigned long <a href="http://lxr.free-electrons.com/ident?i=a7" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a7</a>,
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L87" name="L87" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">87</a> struct <a href="http://lxr.free-electrons.com/ident?i=arm_smccc_res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_smccc_res</a> *<a href="http://lxr.free-electrons.com/ident?i=res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">res</a>);</pre>
<br />
另外smc call 的results會被存在 res 裡<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"> <a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L63" name="L63" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">63</a> <b><i>/**</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L64" name="L64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">64</a> <b><i> * struct arm_smccc_res - Result from SMC/HVC call</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L65" name="L65" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">65</a> <b><i> * @a0-a3 result values from registers 0 to 3</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L66" name="L66" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">66</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L67" name="L67" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">67</a> struct <a href="http://lxr.free-electrons.com/ident?i=arm_smccc_res" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arm_smccc_res</a> {
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L68" name="L68" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">68</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a0" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a0</a>;
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L69" name="L69" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">69</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a1" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a1</a>;
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L70" name="L70" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">70</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a2" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a2</a>;
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L71" name="L71" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">71</a> unsigned long <a href="http://lxr.free-electrons.com/ident?i=a3" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">a3</a>;
<a href="http://lxr.free-electrons.com/source/include/linux/arm-smccc.h#L72" name="L72" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">72</a> };</pre>
(5) psci_init_system_suspend()<br />
跟cpu suspend init做一樣的動作<br />
<br />
到這裡psci_probe 結束<br />
回到psci_0_2_init<br />
再回到 psci_dt_init結束<br />
最後終於回到setup_arch....</div>
<div>
<br /></div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-89090682838139722212016-11-08T03:33:00.000-08:002016-11-08T03:48:53.985-08:00setup_arch(3) - local_async_enable()看完boot arguments之後繼續往下看setup_arch() 的code<br />
<br />
<span style="color: red;">[local_async_enable]</span><br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L246" name="L246" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">246</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L247" name="L247" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">247</a> <b><i> * Unmask asynchronous aborts after bringing up possible earlycon.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L248" name="L248" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">248</a> <b><i> * (Report possible System Errors once we can report this occurred)</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L249" name="L249" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">249</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L250" name="L250" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">250</a> <a href="http://lxr.free-electrons.com/ident?i=local_async_enable" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">local_async_enable</a>();</pre>
<br />
local_async_enable 的code 在 arch/arm64/include/asm/irqflags.h#L59<br />
<pre style="overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/irqflags.h#L59" name="L59" style="background-color: white; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; text-decoration: none;">59</a><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b> #define </b></span></span><a href="http://lxr.free-electrons.com/ident?i=local_async_enable" style="background-color: white; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; text-decoration: none;">local_async_enable</a><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b>() asm(</b></span></span><i style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold;">"msr daifclr, #4"</i><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b> : : : </b></span></span><i style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold;">"memory"</i><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b>)
</b></span></span><a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/irqflags.h#L60" name="L60" style="background-color: white; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; text-decoration: none;">60</a><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b> #define </b></span></span><a href="http://lxr.free-electrons.com/ident?i=local_async_disable" style="background-color: white; border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; text-decoration: none;">local_async_disable</a><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b>() asm(</b></span></span><i style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold;">"msr daifset, #4"</i><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b> : : : </b></span></span><i style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold;">"memory"</i><span style="color: #787878; font-family: "monaco" , "courier new" , "courier" , monospace;"><span style="background-color: white; font-size: 0.95em;"><b>)</b></span></span></pre>
<div>
<br /></div>
這邊是將 SPSR中的的A bit設定起來<br />
<div>
對於SPSR 等system register只能透過msr or mrs 來存取</div>
<div>
而 這些register中某些特定的欄位可以直接指定要 set 還是 clear</div>
<div>
<div>
• MSR DAIFClr, #imm4 : clear any or all of DAIF to 1</div>
<div>
• MSR DAIFSet, #imm4 : set any or all of DAIF to 0<br />
• MSR SPSel, #imm4 : select stack pointer between EL0 to ELn<br />
<br />
DAIF指得就是如下圖SPSR中的DAIF 四個field</div>
</div>
<div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOZr7njmLoiiteORkbnh7TvGoPjjg4MlGDcLgSfeHguqngpexBj8xhF-tSHx6MWKEBPJTzocHd9_5ihApY1J_9bmx71Rvt4olNnggLCIAXt4RZNDpzylihaJgreyGZkJ7Ihvg7ui9BpCPB/s1600/spsr.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="80" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOZr7njmLoiiteORkbnh7TvGoPjjg4MlGDcLgSfeHguqngpexBj8xhF-tSHx6MWKEBPJTzocHd9_5ihApY1J_9bmx71Rvt4olNnggLCIAXt4RZNDpzylihaJgreyGZkJ7Ihvg7ui9BpCPB/s400/spsr.PNG" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
According to ARM Programmers Guide for ARMv8<br />
----------------------------------------------------------------------------------------------------<br />
D: Process state Debug mask. Indicates whether debug exceptions from watchpoint,<br />
breakpoint, and software step debug events that are targeted at the Exception level<br />
the exception occurred in were masked or not<br />
若mask, 代表發生exception時core會知道<br />
----------------------------------------------------------------------------------------------------<br />
A: SError (System Error) mask bit.<br />
若mask, 代表發生system error時, core 會知道<br />
----------------------------------------------------------------------------------------------------<br />
I: IRQ mask bit.<br />
若mask, 代表IRQ不會被core 知道(IRQ不會打進來)<br />
----------------------------------------------------------------------------------------------------<br />
F: FIQ mask bit.<br />
若mask, 代表FIQ不會被core 知道(FIQ不會打進來)<br />
----------------------------------------------------------------------------------------------------<br />
<br />
<span style="color: red;">[History]</span><br />
這一篇mailing list [3]說明了為什麼要加這個function<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: medium;"><b>subject</b></span><br />
<b style="font-family: "courier new", courier, monospace; font-size: 16px;">[arm64: Unmask asynchronous aborts when in kernel mode]</b><br />
The asynchronous aborts are generally fatal for the kernel but they can be masked via the pstate A bit. If a system error happens while in kernel mode, it won't be visible until returning to user space. This patch enables this kind of abort early to help identifying the cause.</div>
<div>
作者提到當系統在kernel mode發生error時, 必須要等到return 到user space才會被看見</div>
<div>
因此為了讓 abort 提早被發現, 他在 setup.c的setup_arch() 與 smp.c 的 secondary_start_kernel()中加入這個patch, 將可以看到system error的bit enable起來</div>
<div>
<br /></div>
<div>
<span style="color: red;">[Asynchronous\Synchronous Exception]</span></div>
<div>
個別說明兩種exception的差別</div>
<span style="color: #3d85c6;"><b>An exception</b></span> is described as synchronous if it is generated as a result of execution or attempted execution of the instruction stream, and where the return address provides details of the instruction that caused it.<br />
<div>
<span style="background-color: white; font-family: "verdana" , "tahoma" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span></div>
Synchronous exception 發生的原因如下<br />
<div>
<ul style="background-color: white; font-family: Verdana, Tahoma, Arial, Helvetica, sans-serif; font-size: small; margin-bottom: 0.2em; margin-top: 0.8em;" type="disc">
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>Instruction aborts</b> from the MMU. For example, by reading an instruction from a memory location marked as Execute Never.</div>
</li>
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>Data Aborts </b>from the MMU. For example, Permission failure or alignment checking.</div>
</li>
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>SP and PC alignment checking</b>.</div>
</li>
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>Synchronous external aborts</b>. For example, an abort when reading translation table.</div>
</li>
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>Unallocated instructions</b>.</div>
</li>
<li style="margin-bottom: 0.2em; margin-top: 0.6em;"><div style="margin-bottom: 0.2em; margin-top: 0.4em;">
<b>Debug exceptions</b>.</div>
</li>
</ul>
<span style="font-family: "verdana" , "tahoma" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><br /></span></div>
<b><span style="color: #3d85c6;">An asynchronous exception</span></b> is not generated by executing instructions, while the return address might not always provide details of what caused the exception.<br />
非同步例外: 是由 IRQ (normal priority interrupt), FIQ (fast interrupt) or SError (System Error)所引起. For example, an abort triggered by writeback of dirty data from a cache line to external memory<br />
<div>
<span style="background-color: white; font-family: "verdana" , "tahoma" , "arial" , "helvetica" , sans-serif; font-size: x-small;"><span style="color: red;"><br /></span></span></div>
<span style="color: red;">[reference]</span><br />
1. http://www.voidcn.com/blog/longwang155069/article/p-6147749.html<br />
2. http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.den0024a/CHDDJBAB.html<br />
3. http://marc.info/?l=git-commits-head&m=138574902028026&w=2ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-61187585249480994612016-10-25T00:04:00.003-07:002016-11-08T03:49:04.497-08:00setup_arch (2) - Kernel boot arguments_parse_early_param()<span style="color: red;">[Bootloader傳什麼進入kernel]</span><br />
Bootloader 會傳入一串參數給kernel 以決定kernel 的運行<br />
傳給核心的參數是以空格分隔的字串,通常的型式是<br />
param[=value_1][,value_2]...[,value_10]<br />
<div>
param是keyword, 一個param後面可以接最多10個value</div>
由 bootloader 傳給核心的參數字串也可以包含傳給 init 程序的參數,kernel只會解析到 "--" 之前的字串,在 "--" 之後的字串會被當成傳給 init 程序的參數<br />
<div>
<br /></div>
<div>
<span style="color: red;">[Bootloader用什麼data struct 傳入kernel]</span></div>
<div>
使用struct tag, define 如下</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L146" name="L146" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">146</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag</a> {
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L147" name="L147" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">147</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_header" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_header</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=hdr" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">hdr</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L148" name="L148" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">148</a> union {
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L149" name="L149" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">149</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_core" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_core</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=core" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">core</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L150" name="L150" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">150</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_mem32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_mem32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=mem" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">mem</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L151" name="L151" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">151</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_videotext" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_videotext</a> videotext;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L152" name="L152" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">152</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_ramdisk" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_ramdisk</a> ramdisk;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L153" name="L153" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">153</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_initrd" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_initrd</a> initrd;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L154" name="L154" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">154</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_serialnr" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_serialnr</a> serialnr;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L155" name="L155" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">155</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_revision" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_revision</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=revision" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">revision</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L156" name="L156" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">156</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_videolfb" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_videolfb</a> videolfb;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L157" name="L157" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">157</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_cmdline" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_cmdline</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=cmdline" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cmdline</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L158" name="L158" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">158</a>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L159" name="L159" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">159</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L160" name="L160" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">160</a> <b><i> * Acorn specific</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L161" name="L161" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">161</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L162" name="L162" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">162</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_acorn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_acorn</a> acorn;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L163" name="L163" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">163</a>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L164" name="L164" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">164</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L165" name="L165" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">165</a> <b><i> * DC21285 specific</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L166" name="L166" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">166</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L167" name="L167" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">167</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_memclk" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_memclk</a> memclk;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L168" name="L168" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">168</a> } u;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L169" name="L169" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">169</a> };</pre>
每一個tag都有一個tag_header定義如下</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"> <a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L24" name="L24" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">24</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag_header" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag_header</a> {
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L25" name="L25" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">25</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__u32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=size" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">size</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L26" name="L26" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">26</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__u32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__u32</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=tag" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">tag</a>;
<a href="http://lxr.free-electrons.com/source/arch/arm/include/uapi/asm/setup.h?v=4.4#L27" name="L27" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">27</a> };</pre>
<span style="color: red;">[When will Bootloader pass into kernel]</span></div>
<div>
<pre style="background-color: white; font-family: monaco, "courier new", courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L227" name="L227" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">227</a><span style="color: #787878;"> void </span><a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=setup_arch" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_arch</a><span style="color: #787878;">(char **cmdline_p)
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L228" name="L228" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">228</a><span style="color: #787878;"> {
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L229" name="L229" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">229</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=pr_info" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_info</a><span style="color: #787878;">(</span><i style="color: #787878;">"Boot CPU: AArch64 Processor [%08x]\n"</i><span style="color: #787878;">, </span><a href="http://lxr.free-electrons.com/ident?i=read_cpuid_id" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">read_cpuid_id</a><span style="color: #787878;">());
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L230" name="L230" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">230</a><span style="color: #787878;">
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L231" name="L231" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">231</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=sprintf" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">sprintf</a><span style="color: #787878;">(</span><a href="http://lxr.free-electrons.com/ident?i=init_utsname" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init_utsname</a><span style="color: #787878;">()-></span><a href="http://lxr.free-electrons.com/ident?i=machine" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">machine</a><span style="color: #787878;">, </span><a href="http://lxr.free-electrons.com/ident?i=ELF_PLATFORM" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">ELF_PLATFORM</a><span style="color: #787878;">);
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L232" name="L232" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">232</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=init_mm" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init_mm</a><span style="color: #787878;">.start_code = (unsigned long) </span><a href="http://lxr.free-electrons.com/ident?i=_text" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">_text</a><span style="color: #787878;">;
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L233" name="L233" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">233</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=init_mm" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init_mm</a><span style="color: #787878;">.end_code = (unsigned long) </span><a href="http://lxr.free-electrons.com/ident?i=_etext" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">_etext</a><span style="color: #787878;">;
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L234" name="L234" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">234</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=init_mm" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init_mm</a><span style="color: #787878;">.end_data = (unsigned long) </span><a href="http://lxr.free-electrons.com/ident?i=_edata" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">_edata</a><span style="color: #787878;">;
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L235" name="L235" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">235</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=init_mm" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init_mm</a><span style="color: #787878;">.brk = (unsigned long) </span><a href="http://lxr.free-electrons.com/ident?i=_end" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">_end</a><span style="color: #787878;">;
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L236" name="L236" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">236</a><span style="color: #787878;">
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L237" name="L237" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">237</a><span style="color: #787878;"> *cmdline_p = </span><a href="http://lxr.free-electrons.com/ident?i=boot_command_line" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_command_line</a><span style="color: #787878;">;
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L238" name="L238" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">238</a><span style="color: #787878;">
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L239" name="L239" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">239</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=early_fixmap_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_fixmap_init</a><span style="color: #787878;">();
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L240" name="L240" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">240</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=early_ioremap_init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_ioremap_init</a><span style="color: #787878;">();
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L241" name="L241" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">241</a><span style="color: #787878;">
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L242" name="L242" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">242</a><span style="color: #787878;"> </span><a href="http://lxr.free-electrons.com/ident?i=setup_machine_fdt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_machine_fdt</a><span style="color: #787878;">(__fdt_pointer);
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L243" name="L243" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">243</a><span style="color: #787878;">
</span><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L244" name="L244" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">244</a><span style="color: #787878;"> </span><span style="color: red;"><a href="http://lxr.free-electrons.com/ident?i=parse_early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; text-decoration: none;">parse_early_param</a>();</span><span style="color: #787878;">
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L245" name="L245" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">245</a> ...</span></pre>
</div>
<br />
從start_kernel --> setup_arch --> parse_early_param<br />
進到parse_early_param就會開始解析preloader傳進來的參數<br />
<br />
<span style="color: red;">[early_param]</span><br />
有較高優先權的參數稱為early_param<br />
以maxcpus為例, 由preloader 傳給kernel, 因為(when __SMP__ is defined)boot up 時就需要知道maxcpus是多少, 因此在early_param時就會執行 maxcpus() in kernel/smp.c<br />
More 可以參考<br />
<a href="http://man7.org/linux/man-pages/man7/bootparam.7.html">http://man7.org/linux/man-pages/man7/bootparam.7.html</a><br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/kernel/smp.c#L524" name="L524" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">524</a> static int<span id="goog_469693571"></span><span id="goog_469693572"></span><a href="https://www.blogger.com/"></a> <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=maxcpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">maxcpus</a>(char *<a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>)
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L525" name="L525" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">525</a> {
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L526" name="L526" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">526</a> <a href="http://lxr.free-electrons.com/ident?i=get_option" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">get_option</a>(&<a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, &<a href="http://lxr.free-electrons.com/ident?i=setup_max_cpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_max_cpus</a>);
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L527" name="L527" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">527</a> if (<a href="http://lxr.free-electrons.com/ident?i=setup_max_cpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_max_cpus</a> == 0)
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L528" name="L528" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">528</a> <a href="http://lxr.free-electrons.com/ident?i=arch_disable_smp_support" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arch_disable_smp_support</a>();
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L529" name="L529" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">529</a>
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L530" name="L530" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">530</a> return 0;
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L531" name="L531" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">531</a> }
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L532" name="L532" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">532</a>
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L533" name="L533" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">533</a> <a href="http://lxr.free-electrons.com/ident?i=early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_param</a>(<i>"maxcpus"</i>, <a href="http://lxr.free-electrons.com/ident?i=maxcpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">maxcpus</a>);</pre>
至於early_param 這個macro又是什麼呢? 繼續往下看<br />
include/linux/init.h<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L238" name="L238" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">238</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L239" name="L239" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">239</a> <b><i> * Only for really core code. See moduleparam.h for the normal way.</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L240" name="L240" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">240</a> <b><i> *</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L241" name="L241" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">241</a> <b><i> * Force the alignment so the compiler doesn't space elements of the</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L242" name="L242" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">242</a> <b><i> * obs_kernel_param "array" too far apart in .init.setup.</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L243" name="L243" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">243</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L244" name="L244" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">244</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__setup_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup_param</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, unique_id, fn, early) \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L245" name="L245" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">245</a> static const char __setup_str_##unique_id[] <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__initconst" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__initconst</a> \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L246" name="L246" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">246</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__aligned" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__aligned</a>(1) = <a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>; \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L247" name="L247" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">247</a> static struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=obs_kernel_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">obs_kernel_param</a> __setup_##unique_id \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L248" name="L248" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">248</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__used" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__used</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__section" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__section</a>(.<a href="http://lxr.free-electrons.com/ident?v=4.4;i=init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">init</a>.<a href="http://lxr.free-electrons.com/ident?v=4.4;i=setup" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup</a>) \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L249" name="L249" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">249</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__attribute__" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__attribute__</a>((aligned((sizeof(long))))) \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L250" name="L250" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">250</a> = { __setup_str_##unique_id, fn, early }
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L251" name="L251" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">251</a>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L252" name="L252" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">252</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__setup" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, fn) \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L253" name="L253" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">253</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__setup_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup_param</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, fn, fn, 0)
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L254" name="L254" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">254</a>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L255" name="L255" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">255</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L256" name="L256" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">256</a> <b><i> * NOTE: fn is as per module_param, not __setup!</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L257" name="L257" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">257</a> <b><i> * Emits warning if fn returns non-zero.</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L258" name="L258" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">258</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L259" name="L259" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">259</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_param</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, fn) \
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L260" name="L260" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">260</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__setup_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup_param</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, fn, fn, 1)</pre>
<br />
early_param 跟 __setup 的實作都是 __setup_param, 只不過 early_param --> __setup_param會將其中的early參數設為1<br />
<br />
進入__setup_param會發現這個macro其實是define兩個variable<br />
(1) define 一個型態為 static const char 的variable, 並將str assign給它<br />
__setup_str_##unique_id[] = str<br />
<br />
(2) define 一個型態為 static struct obs_kernel_param 的variable __setup_##unique_id<br />
並初始化data structure<br />
__setup_##unique_id = {__setup_str_##unique_id, fn, early}<br />
<br />
struct obs_kernel_param 可以讓kernel記錄字串參數與相對應的處理函式<br />
一樣定義在 include/linux/init.h<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L232" name="L232" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">232</a> struct <a href="http://lxr.free-electrons.com/ident?v=4.4;i=obs_kernel_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">obs_kernel_param</a> {
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L233" name="L233" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">233</a> const char *<a href="http://lxr.free-electrons.com/ident?v=4.4;i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>; //name of params
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L234" name="L234" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">234</a> int (*setup_func)(char *); // function handler
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L235" name="L235" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">235</a> int early; //true if it's early_param
<a href="http://lxr.free-electrons.com/source/include/linux/init.h?v=4.4#L236" name="L236" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">236</a> };</pre>
我們再一次用上面maxcpus來展開<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/kernel/smp.c#L524" name="L524" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">524</a> static int<span id="goog_469693571"></span><span id="goog_469693572"></span><a href="https://www.blogger.com/"></a> <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=maxcpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">maxcpus</a>(char *<a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>)
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L525" name="L525" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">525</a> {
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L526" name="L526" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">526</a> <a href="http://lxr.free-electrons.com/ident?i=get_option" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">get_option</a>(&<a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, &<a href="http://lxr.free-electrons.com/ident?i=setup_max_cpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_max_cpus</a>);
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L527" name="L527" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">527</a> if (<a href="http://lxr.free-electrons.com/ident?i=setup_max_cpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_max_cpus</a> == 0)
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L528" name="L528" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">528</a> <a href="http://lxr.free-electrons.com/ident?i=arch_disable_smp_support" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arch_disable_smp_support</a>();
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L529" name="L529" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">529</a>
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L530" name="L530" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">530</a> return 0;
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L531" name="L531" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">531</a> }
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L532" name="L532" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">532</a>
<a href="http://lxr.free-electrons.com/source/kernel/smp.c#L533" name="L533" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">533</a> <a href="http://lxr.free-electrons.com/ident?i=early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_param</a>(<i>"maxcpus"</i>, <a href="http://lxr.free-electrons.com/ident?i=maxcpus" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">maxcpus</a>);</pre>
<div>
macro 炸開之後........</div>
static const char<span style="color: orange;"> __setup_str_maxcpus[]</span> __initconst __aligned(1) <span style="color: orange;">= "maxcpus"</span><br />
<div>
static struct obs_kernel_param<span style="color: orange;"> __setup_maxcpus</span> __used <span style="color: #3d85c6;">__section(.init.setup)</span> __attribute__((aligned(sizeof(long)))))</div>
<div>
<span style="color: orange;">= { __setup_str_maxcpus, maxcpus, 1};</span><br />
<div>
<br />
這樣就可以很清楚的發現<br />
我們定義了一個裝有"maxcpus"的字串陣列, 再來有一個記錄 kernel params的 struct obs_kernel_param, 用來告訴kernel 這個param叫什麼, 以及遇到這個param的時候開call 什麼fundtion handler來處理<br />
<br />
另外用藍色標起來的部分又是一個難題了<br />
這裡將這個macro定義的資料放在 .init.setup 這個section中<br />
關於.init.setup 這個section 是定義在 kernel-4.4\include\asm-generic\vmlinux_lds.h 中<br />
<br />
#define INIT_SETUP(initsetup_align)<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>. = ALIGN(initsetup_align);<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>VMLINUX_SYMBOL(__setup_start) = .;<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>*(.init.setup)<span class="Apple-tab-span" style="white-space: pre;"> </span>\<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>VMLINUX_SYMBOL(__setup_end) = .;<br />
<span style="color: red;"><br /></span>
代表所有被標註要放到.init.setup這個section的params都會被放在一起<br />
而起始為至是 __setup_start & __setup_end<br />
<br />
怎麼知道到底有哪些params會被放在 .init_setup中呢<br />
可以打開 out\System.map看看<br />
找到__setup_start了!! 下面緊接著都是 __setup_XXX<br />
還看到了前面的舉例 __setup_maxcpus 這個param<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_9OlFOY2fj08O5XuvbxUyqSyTUv4RlGIjEbJoXAzwC8BhdnYww6wd9Zr-26q-t47_H16w-DDtxze1Vznd_NHpIFtMAiQGL0k1AH_X0RaH_9Yr5IXGPjJ_wrXkczgVxfjKbSdc-AN7iqDz/s1600/system_map1.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="162" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_9OlFOY2fj08O5XuvbxUyqSyTUv4RlGIjEbJoXAzwC8BhdnYww6wd9Zr-26q-t47_H16w-DDtxze1Vznd_NHpIFtMAiQGL0k1AH_X0RaH_9Yr5IXGPjJ_wrXkczgVxfjKbSdc-AN7iqDz/s320/system_map1.PNG" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyjtcOVZpN_hOKyrHFQTuw-lIBJvKY2K4vOkX9z5236xBrs2LxQaxUWNs0Jf4h9vimDrTTPs8VrvnJw04xQlzSxG__xrVZb-alP0KfcDJqAiyJDUNoFrozE0kF1SQOrn1AECyy5fyVscvx/s1600/system_map2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="52" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyjtcOVZpN_hOKyrHFQTuw-lIBJvKY2K4vOkX9z5236xBrs2LxQaxUWNs0Jf4h9vimDrTTPs8VrvnJw04xQlzSxG__xrVZb-alP0KfcDJqAiyJDUNoFrozE0kF1SQOrn1AECyy5fyVscvx/s320/system_map2.PNG" width="320" /></a></div>
<br />
<span style="color: red;"><br /></span>
<span style="color: red;"><br /></span>
<br />
<br />
<br />
<span style="color: red;">[parse_early_param]</span><br />
回到start_kernel--> setup_arch--> parse_early_param<br />
這裡將boot_command_line copy 給 tmp_cmdline<br />
接著呼叫 parse_early_options--> parse_args 開始解析kernel parameters<br />
parse_args 會將cmd args切成一組組的<param,value>, 傳入callback function <b>do_early_param</b><br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/init/main.c#L430" name="L430" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">430</a> void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=parse_early_options" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">parse_early_options</a>(char *<a href="http://lxr.free-electrons.com/ident?i=cmdline" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cmdline</a>)
<a href="http://lxr.free-electrons.com/source/init/main.c#L431" name="L431" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">431</a> {
<a href="http://lxr.free-electrons.com/source/init/main.c#L432" name="L432" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">432</a> <a href="http://lxr.free-electrons.com/ident?i=parse_args" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">parse_args</a>(<i>"early options"</i>, <a href="http://lxr.free-electrons.com/ident?i=cmdline" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cmdline</a>, <a href="http://lxr.free-electrons.com/ident?i=NULL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NULL</a>, 0, 0, 0, <a href="http://lxr.free-electrons.com/ident?i=NULL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NULL</a>,
<a href="http://lxr.free-electrons.com/source/init/main.c#L433" name="L433" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">433</a> <a href="http://lxr.free-electrons.com/ident?i=do_early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">do_early_param</a>);
<a href="http://lxr.free-electrons.com/source/init/main.c#L434" name="L434" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">434</a> }
<a href="http://lxr.free-electrons.com/source/init/main.c#L435" name="L435" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">435</a>
<a href="http://lxr.free-electrons.com/source/init/main.c#L436" name="L436" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">436</a> <b><i>/* Arch code calls this early on, or if not, just before other parsing. */</i></b>
<a href="http://lxr.free-electrons.com/source/init/main.c#L437" name="L437" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">437</a> void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=parse_early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">parse_early_param</a>(void)
<a href="http://lxr.free-electrons.com/source/init/main.c#L438" name="L438" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">438</a> {
<a href="http://lxr.free-electrons.com/source/init/main.c#L439" name="L439" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">439</a> static int <a href="http://lxr.free-electrons.com/ident?i=done" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">done</a> <a href="http://lxr.free-electrons.com/ident?i=__initdata" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__initdata</a>;
<a href="http://lxr.free-electrons.com/source/init/main.c#L440" name="L440" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">440</a> static char tmp_cmdline[<a href="http://lxr.free-electrons.com/ident?i=COMMAND_LINE_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">COMMAND_LINE_SIZE</a>] <a href="http://lxr.free-electrons.com/ident?i=__initdata" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__initdata</a>;
<a href="http://lxr.free-electrons.com/source/init/main.c#L441" name="L441" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">441</a>
<a href="http://lxr.free-electrons.com/source/init/main.c#L442" name="L442" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">442</a> if (<a href="http://lxr.free-electrons.com/ident?i=done" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">done</a>)
<a href="http://lxr.free-electrons.com/source/init/main.c#L443" name="L443" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">443</a> return;
<a href="http://lxr.free-electrons.com/source/init/main.c#L444" name="L444" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">444</a>
<a href="http://lxr.free-electrons.com/source/init/main.c#L445" name="L445" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">445</a> <b><i>/* All fall through to do_early_param. */</i></b>
<a href="http://lxr.free-electrons.com/source/init/main.c#L446" name="L446" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">446</a> <a href="http://lxr.free-electrons.com/ident?i=strlcpy" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">strlcpy</a>(tmp_cmdline, <a href="http://lxr.free-electrons.com/ident?i=boot_command_line" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_command_line</a>, <a href="http://lxr.free-electrons.com/ident?i=COMMAND_LINE_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">COMMAND_LINE_SIZE</a>);
<a href="http://lxr.free-electrons.com/source/init/main.c#L447" name="L447" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">447</a> <a href="http://lxr.free-electrons.com/ident?i=parse_early_options" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">parse_early_options</a>(tmp_cmdline);
<a href="http://lxr.free-electrons.com/source/init/main.c#L448" name="L448" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">448</a> <a href="http://lxr.free-electrons.com/ident?i=done" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">done</a> = 1;
<a href="http://lxr.free-electrons.com/source/init/main.c#L449" name="L449" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">449</a> }</pre>
<br />
<span style="color: red;">[do_early_param]</span><br />
將傳入的params 跟 __setup_start , __setup_end區間中的args做比對, 若有符合的, 就call 該args的callback function (p->setup_func)做設定<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/init/main.c#L411" name="L411" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">411</a> <b><i>/* Check for early params. */</i></b>
<a href="http://lxr.free-electrons.com/source/init/main.c#L412" name="L412" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">412</a> static int <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=do_early_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">do_early_param</a>(char *<a href="http://lxr.free-electrons.com/ident?i=param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">param</a>, char *<a href="http://lxr.free-electrons.com/ident?i=val" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">val</a>,
<a href="http://lxr.free-electrons.com/source/init/main.c#L413" name="L413" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">413</a> const char *<a href="http://lxr.free-electrons.com/ident?i=unused" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">unused</a>, void *<a href="http://lxr.free-electrons.com/ident?i=arg" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">arg</a>)
<a href="http://lxr.free-electrons.com/source/init/main.c#L414" name="L414" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">414</a> {
<a href="http://lxr.free-electrons.com/source/init/main.c#L415" name="L415" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">415</a> const struct <a href="http://lxr.free-electrons.com/ident?i=obs_kernel_param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">obs_kernel_param</a> *<a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>;
<a href="http://lxr.free-electrons.com/source/init/main.c#L416" name="L416" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">416</a>
<a href="http://lxr.free-electrons.com/source/init/main.c#L417" name="L417" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">417</a> for (<a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a> = <a href="http://lxr.free-electrons.com/ident?i=__setup_start" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup_start</a>; <a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a> < <a href="http://lxr.free-electrons.com/ident?i=__setup_end" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__setup_end</a>; <a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>++) {
<a href="http://lxr.free-electrons.com/source/init/main.c#L418" name="L418" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">418</a> if ((<a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>->early && <a href="http://lxr.free-electrons.com/ident?i=parameq" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">parameq</a>(<a href="http://lxr.free-electrons.com/ident?i=param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">param</a>, <a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>-><a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>)) ||
<a href="http://lxr.free-electrons.com/source/init/main.c#L419" name="L419" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">419</a> (<a href="http://lxr.free-electrons.com/ident?i=strcmp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">strcmp</a>(<a href="http://lxr.free-electrons.com/ident?i=param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">param</a>, <i>"console"</i>) == 0 &&
<a href="http://lxr.free-electrons.com/source/init/main.c#L420" name="L420" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">420</a> <a href="http://lxr.free-electrons.com/ident?i=strcmp" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">strcmp</a>(<a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>-><a href="http://lxr.free-electrons.com/ident?i=str" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">str</a>, <i>"earlycon"</i>) == 0)
<a href="http://lxr.free-electrons.com/source/init/main.c#L421" name="L421" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">421</a> ) {
<a href="http://lxr.free-electrons.com/source/init/main.c#L422" name="L422" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">422</a> if (<a href="http://lxr.free-electrons.com/ident?i=p" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">p</a>->setup_func(<a href="http://lxr.free-electrons.com/ident?i=val" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">val</a>) != 0)
<a href="http://lxr.free-electrons.com/source/init/main.c#L423" name="L423" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">423</a> <a href="http://lxr.free-electrons.com/ident?i=pr_warn" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_warn</a>(<i>"Malformed early option '%s'\n"</i>, <a href="http://lxr.free-electrons.com/ident?i=param" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">param</a>);
<a href="http://lxr.free-electrons.com/source/init/main.c#L424" name="L424" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">424</a> }
<a href="http://lxr.free-electrons.com/source/init/main.c#L425" name="L425" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">425</a> }
<a href="http://lxr.free-electrons.com/source/init/main.c#L426" name="L426" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">426</a> <b><i>/* We accept everything at this stage. */</i></b>
<a href="http://lxr.free-electrons.com/source/init/main.c#L427" name="L427" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">427</a> return 0;
<a href="http://lxr.free-electrons.com/source/init/main.c#L428" name="L428" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">428</a> }</pre>
<br />
reference:<br />
[1] https://danielmaker.github.io/blog/linux/kernel_parameter_parsing.html<br />
[2] http://blog.csdn.net/goto_chen/article/details/17392245<br />
[3] http://blog.csdn.net/skyflying2012/article/details/41142801<br />
<br />
<br />
<br />
<br /></div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-4846729780149214472016-10-25T00:04:00.001-07:002016-11-08T03:49:09.529-08:00Fix-Mapped Linear Address<div>
Architecture: ARM64<br />
<span style="color: red;">[Intro]</span></div>
Fixmap是固定一直指到physical addr的特定位址<br />
<div>
Kernel會一次配一塊4K的virtual memory mapping 到physical addr</div>
<div>
<br /></div>
<div>
<span style="color: red;">[Usage of Fix-Mapped Linear Address]</span></div>
<div>
Kernel linear address的第四個GB中至少會有一塊128MB的memory mapping到physical address</div>
<div>
這一塊memory 可以讓kernel implement </div>
<div>
(1) noncontiguous memory allocation (2) fix-mapped linear address</div>
<div>
<br /></div>
<div>
<span style="color: red;">[Fix-Mapped Linear Address VS. Physical Address]</span></div>
<div>
Fix-Mapped Linear Address 是一個constant address. 例如 0xffffc000</div>
<div>
每一個Fix-Mapped Linear Address maps到一個page frame(4K) 的physical memory</div>
<div>
Fix-Mapped Linear Address 跟 linear address that map the first 896MB of RAM 很像</div>
<div>
但Fix-Mapped Linear Address可以mapping到任何physical address</div>
<div>
<br /></div>
<div>
<span style="color: red;">[Data Structure enum fixed_addresses]</span></div>
<div>
每一個fix-mapped linear address都有一個專用的integer index defined 在 enum fixed_addresses中</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"> <a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L36" name="L36" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">36</a> enum <a href="http://lxr.free-electrons.com/ident?i=fixed_addresses" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">fixed_addresses</a> {
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L37" name="L37" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">37</a> FIX_HOLE,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L38" name="L38" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">38</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L39" name="L39" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">39</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L40" name="L40" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">40</a> <b><i> * Reserve a virtual window for the FDT that is 2 MB larger than the</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L41" name="L41" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">41</a> <b><i> * maximum supported size, and put it at the top of the fixmap region.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L42" name="L42" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">42</a> <b><i> * The additional space ensures that any FDT that does not exceed</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L43" name="L43" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">43</a> <b><i> * MAX_FDT_SIZE can be mapped regardless of whether it crosses any</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L44" name="L44" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">44</a> <b><i> * 2 MB alignment boundaries.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L45" name="L45" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">45</a> <b><i> *</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L46" name="L46" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">46</a> <b><i> * Keep this at the top so it remains 2 MB aligned.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L47" name="L47" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">47</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L48" name="L48" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">48</a> #define <a href="http://lxr.free-electrons.com/ident?i=FIX_FDT_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">FIX_FDT_SIZE</a> (<a href="http://lxr.free-electrons.com/ident?i=MAX_FDT_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">MAX_FDT_SIZE</a> + <a href="http://lxr.free-electrons.com/ident?i=SZ_2M" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">SZ_2M</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L49" name="L49" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">49</a> FIX_FDT_END,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L50" name="L50" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">50</a> FIX_FDT = FIX_FDT_END + <a href="http://lxr.free-electrons.com/ident?i=FIX_FDT_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">FIX_FDT_SIZE</a> / <a href="http://lxr.free-electrons.com/ident?i=PAGE_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PAGE_SIZE</a> - 1,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L51" name="L51" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">51</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L52" name="L52" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">52</a> FIX_EARLYCON_MEM_BASE,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L53" name="L53" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">53</a> FIX_TEXT_POKE0,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L54" name="L54" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">54</a> __end_of_permanent_fixed_addresses,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L55" name="L55" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">55</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L56" name="L56" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">56</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L57" name="L57" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">57</a> <b><i> * Temporary boot-time mappings, used by early_ioremap(),</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L58" name="L58" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">58</a> <b><i> * before ioremap() is functional.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L59" name="L59" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">59</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L60" name="L60" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">60</a> #define <a href="http://lxr.free-electrons.com/ident?i=NR_FIX_BTMAPS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NR_FIX_BTMAPS</a> (<a href="http://lxr.free-electrons.com/ident?i=SZ_256K" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">SZ_256K</a> / <a href="http://lxr.free-electrons.com/ident?i=PAGE_SIZE" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PAGE_SIZE</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L61" name="L61" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">61</a> #define <a href="http://lxr.free-electrons.com/ident?i=FIX_BTMAPS_SLOTS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">FIX_BTMAPS_SLOTS</a> 7
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L62" name="L62" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">62</a> #define <a href="http://lxr.free-electrons.com/ident?i=TOTAL_FIX_BTMAPS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">TOTAL_FIX_BTMAPS</a> (<a href="http://lxr.free-electrons.com/ident?i=NR_FIX_BTMAPS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NR_FIX_BTMAPS</a> * <a href="http://lxr.free-electrons.com/ident?i=FIX_BTMAPS_SLOTS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">FIX_BTMAPS_SLOTS</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L63" name="L63" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">63</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L64" name="L64" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">64</a> FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L65" name="L65" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">65</a> FIX_BTMAP_BEGIN = FIX_BTMAP_END + <a href="http://lxr.free-electrons.com/ident?i=TOTAL_FIX_BTMAPS" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">TOTAL_FIX_BTMAPS</a> - 1,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L66" name="L66" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">66</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L67" name="L67" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">67</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L68" name="L68" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">68</a> <b><i> * Used for kernel page table creation, so unmapped memory may be used</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L69" name="L69" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">69</a> <b><i> * for tables.</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L70" name="L70" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">70</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L71" name="L71" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">71</a> FIX_PTE,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L72" name="L72" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">72</a> FIX_PMD,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L73" name="L73" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">73</a> FIX_PUD,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L74" name="L74" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">74</a> FIX_PGD,
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L75" name="L75" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">75</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L76" name="L76" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">76</a> <a href="http://lxr.free-electrons.com/ident?i=__end_of_fixed_addresses" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__end_of_fixed_addresses</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/include/asm/fixmap.h#L77" name="L77" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">77</a> };</pre>
</div>
<br />
<span style="color: red;">[How to Obtain the Linear Address Set of a Fix-Mapped Linear Address]</span><br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L23" name="L23" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">23</a> #ifndef __ASSEMBLY__
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L24" name="L24" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">24</a> <b><i>/*</i></b>
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L25" name="L25" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">25</a> <b><i> * 'index to address' translation. If anyone tries to use the idx</i></b>
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L26" name="L26" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">26</a> <b><i> * directly without translation, we catch the bug with a NULL-deference</i></b>
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L27" name="L27" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">27</a> <b><i> * kernel oops. Illegal ranges of incoming indices are caught too.</i></b>
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L28" name="L28" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">28</a> <b><i> */</i></b>
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L29" name="L29" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">29</a> static <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__always_inline" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__always_inline</a> unsigned long <a href="http://lxr.free-electrons.com/ident?v=4.4;i=fix_to_virt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">fix_to_virt</a>(const unsigned int <a href="http://lxr.free-electrons.com/ident?v=4.4;i=idx" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">idx</a>)
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L30" name="L30" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">30</a> {
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L31" name="L31" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">31</a> <a href="http://lxr.free-electrons.com/ident?v=4.4;i=BUILD_BUG_ON" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">BUILD_BUG_ON</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=idx" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">idx</a> >= __end_of_fixed_addresses);
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L32" name="L32" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">32</a> return <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__fix_to_virt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__fix_to_virt</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=idx" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">idx</a>);
<a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L33" name="L33" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">33</a> }</pre>
<br />
fix_to_virt -> __fix_to_virt: 能夠根據index找到 constant linear address<br />
如下, PAGE_SHIFT = 12<br />
所以每一個index 對應到的linear address是從FIXADDR_TOP開始減 4K 的倍數<br />
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/include/asm-generic/fixmap.h?v=4.4#L20" name="L20" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">20</a> #define <a href="http://lxr.free-electrons.com/ident?v=4.4;i=__fix_to_virt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__fix_to_virt</a>(<a href="http://lxr.free-electrons.com/ident?v=4.4;i=x" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">x</a>) (<a href="http://lxr.free-electrons.com/ident?v=4.4;i=FIXADDR_TOP" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">FIXADDR_TOP</a> - ((<a href="http://lxr.free-electrons.com/ident?v=4.4;i=x" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">x</a>) << <a href="http://lxr.free-electrons.com/ident?v=4.4;i=PAGE_SHIFT" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">PAGE_SHIFT</a>))</pre>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlkIjohdFmpo41fLj0SeNrVXbB0724PV9bXT8b_IAJi5Yg_UaJ8jFaXRQoJ9M8lzE3SUDvsUMG02D2QkO9EJzhmDlZGvivvg43LTs7HzdgjsqvqmDSdesC5Rmv6nsIEMvg1Ns4q7WmDWdD/s1600/memory+layout.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="253" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlkIjohdFmpo41fLj0SeNrVXbB0724PV9bXT8b_IAJi5Yg_UaJ8jFaXRQoJ9M8lzE3SUDvsUMG02D2QkO9EJzhmDlZGvivvg43LTs7HzdgjsqvqmDSdesC5Rmv6nsIEMvg1Ns4q7WmDWdD/s320/memory+layout.PNG" width="320" /></a></div>
<br />
目前畫出的memory layout不一定正確, 若有誤會再修正<br />
<span style="color: red;"><br /></span>
<span style="color: red;">[Reference]</span><br />
Fixmap:<br />
http://palliatory66.rssing.com/chan-60693167/latest.php<br />
<br />
ARM64 memory<br />
http://blog.csdn.net/qianlong4526888/article/details/9058221<br />
<br />
Linux doc about arm64 memory<br />
http://lxr.free-electrons.com/source/Documentation/arm64/memory.txt?v=4.4<br />
<br />
Linux kernel memory management<br />
https://0xax.gitbooks.io/linux-insides/content/mm/linux-mm-2.html<br />
<br />
Windows7 memory layout<br />
http://www.codemachine.com/article_x64kvas.html<br />
<br />
<br />ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-75923322332615826202016-10-24T20:52:00.000-07:002016-11-08T03:49:14.009-08:00setup_arch(1) - setup_machine_fdt()We will focus on device tree initialization in this article<br />
<div>
First, take a look of setup_arch() -> setup_machine_fdt()</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L179" name="L179" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">179</a> static void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=setup_machine_fdt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">setup_machine_fdt</a>(<a href="http://lxr.free-electrons.com/ident?i=phys_addr_t" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">phys_addr_t</a> dt_phys)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L180" name="L180" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">180</a> {
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L181" name="L181" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">181</a> void *dt_virt = <a href="http://lxr.free-electrons.com/ident?i=fixmap_remap_fdt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">fixmap_remap_fdt</a>(dt_phys);
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L182" name="L182" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">182</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L183" name="L183" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">183</a> if (!dt_virt || !<a href="http://lxr.free-electrons.com/ident?i=early_init_dt_scan" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_init_dt_scan</a>(dt_virt)) {
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L184" name="L184" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">184</a> <a href="http://lxr.free-electrons.com/ident?i=pr_crit" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">pr_crit</a>(<i>"\n"</i>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L185" name="L185" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">185</a> <i>"Error: invalid device tree blob at physical address %pa (virtual address 0x%p)\n"</i>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L186" name="L186" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">186</a> <i>"The dtb must be 8-byte aligned and must not exceed 2 MB in size\n"</i>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L187" name="L187" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">187</a> <i>"\nPlease check your bootloader."</i>,
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L188" name="L188" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">188</a> &dt_phys, dt_virt);
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L189" name="L189" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">189</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L190" name="L190" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">190</a> while (<a href="http://lxr.free-electrons.com/ident?i=true" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">true</a>)
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L191" name="L191" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">191</a> <a href="http://lxr.free-electrons.com/ident?i=cpu_relax" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">cpu_relax</a>();
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L192" name="L192" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">192</a> }
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L193" name="L193" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">193</a>
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L194" name="L194" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">194</a> <a href="http://lxr.free-electrons.com/ident?i=dump_stack_set_arch_desc" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">dump_stack_set_arch_desc</a>(<i>"%s (DT)"</i>, <a href="http://lxr.free-electrons.com/ident?i=of_flat_dt_get_machine_name" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_flat_dt_get_machine_name</a>());
<a href="http://lxr.free-electrons.com/source/arch/arm64/kernel/setup.c#L195" name="L195" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">195</a> }</pre>
</div>
<div>
<br /></div>
1. fixmap_remap_fdt(): 找到device tree的virtual addr<br />
2. early_init_dt_scan(dt_virt): 為之後的DTB scan 做準備, 並進行參數傳遞<br />
<div>
3. dump_stack_set_arch_desc(): 印出hardware name, 並把stack dump出來<br />
<div>
由 2 進一步從early_init_dt_scan -> early_init_dt_scan_nodes() 看</div>
<div>
<pre style="background-color: white; color: #787878; font-family: Monaco, "Courier New", Courier, monospace; font-size: 0.95em; font-weight: bold; overflow: auto; padding: 1em;"><a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1212" name="L1212" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1212</a> void <a href="http://lxr.free-electrons.com/ident?i=__init" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">__init</a> <a href="http://lxr.free-electrons.com/ident?i=early_init_dt_scan_nodes" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_init_dt_scan_nodes</a>(void)
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1213" name="L1213" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1213</a> {
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1214" name="L1214" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1214</a> <b><i>/* Retrieve various information from the /chosen node */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1215" name="L1215" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1215</a> <a href="http://lxr.free-electrons.com/ident?i=of_scan_flat_dt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_scan_flat_dt</a>(<a href="http://lxr.free-electrons.com/ident?i=early_init_dt_scan_chosen" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_init_dt_scan_chosen</a>, <a href="http://lxr.free-electrons.com/ident?i=boot_command_line" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">boot_command_line</a>);
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1216" name="L1216" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1216</a>
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1217" name="L1217" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1217</a> <b><i>/* Initialize {size,address}-cells info */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1218" name="L1218" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1218</a> <a href="http://lxr.free-electrons.com/ident?i=of_scan_flat_dt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_scan_flat_dt</a>(<a href="http://lxr.free-electrons.com/ident?i=early_init_dt_scan_root" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_init_dt_scan_root</a>, <a href="http://lxr.free-electrons.com/ident?i=NULL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NULL</a>);
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1219" name="L1219" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1219</a>
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1220" name="L1220" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1220</a> <b><i>/* Setup memory, calling early_init_dt_add_memory_arch */</i></b>
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1221" name="L1221" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1221</a> <a href="http://lxr.free-electrons.com/ident?i=of_scan_flat_dt" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">of_scan_flat_dt</a>(<a href="http://lxr.free-electrons.com/ident?i=early_init_dt_scan_memory" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">early_init_dt_scan_memory</a>, <a href="http://lxr.free-electrons.com/ident?i=NULL" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">NULL</a>);
<a href="http://lxr.free-electrons.com/source/drivers/of/fdt.c#L1222" name="L1222" style="border-bottom-color: rgb(153, 153, 153); border-bottom-style: dotted; border-bottom-width: 1px; color: black; text-decoration: none;">1222</a> }</pre>
<div>
<br /></div>
第一個of_scan_flat_dt: scan /chosen node, save bootargs to boot_command_line, 還處理initrd相關的property, 存到initrd_start, initrd_end這兩個global variables中</div>
<div>
<br />
<div>
第二個of_scan_flat_dt: scan root node, 取得 {size, addr}-cells 的資訊, 並存到dt_root_size_cells 和 dt_root_addr_cells global variables中</div>
<div>
<br /></div>
<div>
第三個of_scan_flat_dt: scan DTB中的memory node, 並把相關的資訊存入meminfo, meminfo是global variable, 保存系統的memory相關的資訊</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
</div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-15347990898395982782014-08-06T20:39:00.002-07:002016-10-24T05:47:19.842-07:00SSDT Hook<h3>
<span style="font-size: large;"><u>A. SSDT</u></span></h3>
SSDT 全名為System Service Dispatch Table,從圖來解釋比較快。Windows中Service Descriptor Table有兩種,分別是KeServiceDescriptorTable以及 KeServiceDescriptorTableShadow。每一個Table都是用一個SST Strucute來定義。<br />
而SST中的欄位:<br />
<b>ServiceTableBase</b>: points to the SSDT<br />
<b>ServiceCounterTableBase:</b> Not used<br />
<b>ServiceLimit</b>: number of entries in the SSDT<br />
<b>ArgumentTable</b>: points to the SSDP table (system service Parameter table). 每一個byte儲存每一個SSDT routine其parameter所需用到的bytes數<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ2cKxZ6uE8oldKxOatVdVNA0XdSkutUVQeVK4ZcDAXHMtf-tYBuG4wFp-ZYaLPd3ON8JGf_JJUMAllk1orZ-TFX-bqnsJcCIb43bnA8XC2hoy7JSYzHNwJLvYwnEp2xY2P3NitE7Gjx5a/s1600/ssdt_struct1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="497" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZ2cKxZ6uE8oldKxOatVdVNA0XdSkutUVQeVK4ZcDAXHMtf-tYBuG4wFp-ZYaLPd3ON8JGf_JJUMAllk1orZ-TFX-bqnsJcCIb43bnA8XC2hoy7JSYzHNwJLvYwnEp2xY2P3NitE7Gjx5a/s1600/ssdt_struct1.png" width="640" /></a></div>
<br />
因此循著ServiceTableBase的address可以找到SSDT的位置。在利用index找到target routine就可以進行hook了!<br />
<div>
<br /></div>
<div>
<div>
我們可以用windbg來實際看一下SSDT長什麼樣子</div>
<div>
依照前幾篇文章設定好的VS2013+VM target machine的 remote debug</div>
<div>
我就透過VS2013直接對我在VM中的windows7進行debug</div>
<div>
<br /></div>
<b>(1) dd KeServiceDescriptorTable</b><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIRbMpf9UQC2_7cbp2RJ-ZRLNnPp7sL_XaC_o2BOafdEKWA9MPTJn3oPHNoWN9WPXwy0Y6bJf0RwdxruxRxVP-Qujbv0G5xBpBswIjEZKLKbHP8zIrXaoJikA5o6an5ch_gTFactPTElKX/s1600/KeServiceDescriptorTable.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="165" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIRbMpf9UQC2_7cbp2RJ-ZRLNnPp7sL_XaC_o2BOafdEKWA9MPTJn3oPHNoWN9WPXwy0Y6bJf0RwdxruxRxVP-Qujbv0G5xBpBswIjEZKLKbHP8zIrXaoJikA5o6an5ch_gTFactPTElKX/s1600/KeServiceDescriptorTable.PNG" width="400" /></a></div>
<div>
<br /></div>
<div>
可以看到KeServiceDescriptorTable的內容被印出來啦!根據前面介紹的概念,紅線標出的部分就是Structure的內容,因此83e7f43c就是SSDT 的address。至於其他內容代表的是什麼還有待查證。</div>
<div>
用 dps nt!KeServiceDescriptorTable l4 也可以看到內容。</div>
<div>
<br /></div>
<div>
<div style="text-align: left;">
(指令 dd 的第一個d是代表印出指向指定位置的內容,第二個d代表用DWORD的形式,因此也有db(byte),du(unicode),dc(char)等指令)</div>
</div>
<div>
<div style="text-align: left;">
(指令 dps代表 display words and symbol,l4是line4,印出4行)</div>
</div>
<div>
<br /></div>
<div>
<b>(2) dps nt!KiServiceTable L poi nt!KiServiceLimit</b></div>
<div>
此時會依據KiServiceLimit內容印出KiServiceTable,由於KiServiceLimit是此SSDT的number of entris,因此這行指令代表的就是印出KiServieTable的全部內容啦! </div>
<div>
(這裡的KiServiceTable應該就是structue的name,就是SSDT本人啦)</div>
<div>
可以看到每一個SSDT routine以及他們的memory address。</div>
<div>
(圖中可以看到第一排的第一個addr 83e7f43c,這不就是我們前一步看到的KeServiceDescriptorTable的內容嗎?沒錯,事實證明83e7f43c就是SSDT的起始address啦~太棒啦)</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHqt5gCELQQF8fatz1EUuZVgLnT4PykCttHwnyu7W4rkiATHaDtI0dcZBYbWONN6WiGo5EGc2wtVlX0z9D9NWBtZqYF0gjuNR2qYC9MeZm2_NUldjthc8UOhFmFYzg1e0janxR_mqKIpSf/s1600/Kiservicetable.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHqt5gCELQQF8fatz1EUuZVgLnT4PykCttHwnyu7W4rkiATHaDtI0dcZBYbWONN6WiGo5EGc2wtVlX0z9D9NWBtZqYF0gjuNR2qYC9MeZm2_NUldjthc8UOhFmFYzg1e0janxR_mqKIpSf/s1600/Kiservicetable.PNG" width="640" /></a></div>
<h3 style="clear: both; text-align: left;">
<u>B. SSDT Hooking</u></h3>
<div class="separator" style="clear: both; text-align: left;">
Hook說穿了就是把SSDT中的某一個entry內容改掉,變成指向我們的hook function,為了避免system crash最後在hook function中再call 原先的SSDT routine。 </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
用A(2)的圖來解釋的話,如果我們想要hook NtAcceptConnectPort,就只要把SSDT[0]的內容改成我們自己的hook function address就可以啦(原本是8407afcf),如此一來每當系統要call這個native api並到SSDT中來找時就會循著address找到我們的hook function。hook function就會依照programmer的設計來做事了。</div>
<h3 style="clear: both; text-align: left;">
<u>C. Hooking ntQuerySystemInformation</u></h3>
<div class="separator" style="clear: both; text-align: left;">
這一次我想hook的native api是 ntQuerySystemInformation,要找到ntQuerySystemInformation要從 ZWQuerySystemInformation開始,ZWQuerySystemInformation是ntoskrnl.exe中的一個win32 API,只要將ZWQuerySystemInformation的code做disassemble就能夠發現ZWQuerySystemInformation其實是將index value存入eax register,在call KiServiceTable,也就是到SSDT中根據Index value找到ntQuerySystemInformation的address。最後就執行ntQuerySystemInformation。</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
用windbg command可以用 u nt!ZwQuerySystemInformation看到反組譯後的code,由mov到eax的value可以知道ntQuerySystemInformation的index value是261(10進制)。我們就可以用</div>
<div class="separator" style="clear: both; text-align: left;">
SSDT 起始address+4*index來算出ntQuerySystemInformation 存在SSDT中的哪一個位址。</div>
<h3 style="clear: both;">
D. Code Explaination</h3>
<div class="separator" style="clear: both;">
<b>(1) Function Prototypes</b></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<b>MyDriver_UnSupportedFunction</b>: assign給driver object的function,告訴driver object要做哪些事。目前沒有太大的用途囉。</div>
<div class="separator" style="clear: both;">
<b>MyDriver_Unload:</b> 當Driver要unload時會call此function</div>
<div class="separator" style="clear: both;">
<b>DriverEntry</b>:為此程式的entry point</div>
<code>
<br />/* Function Prototypes */
<br />NTSTATUS MyDriver_UnSupportedFunction(PDEVICE_OBJECT DeviceObject, PIRP Irp);
<br />VOID MyDriver_Unload(PDRIVER_OBJECT DriverObject);
<br />NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath);
</code>
<br />
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<b>(2) Compile directives</b></div>
<div class="separator" style="clear: both;">
<b><br /></b></div>
<code>#pragma alloc_text(INIT, DriverEntry)<br />#pragma alloc_text(PAGE, MyDriver_Unload)<br />#pragma alloc_text(PAGE, MyDriver_UnSupportedFunction)</code><br />
<div>
<div class="separator" style="clear: both;">
#pragma是一個預處理指令,告訴compiler要做些特別的事(如果compiler看得懂的話才會做)</div>
<div class="separator" style="clear: both;">
而 #pragma alloc_text 只能處理C function,用來指定section locations.Microsoft 文件有提到"The alloc_text pragma must appear after the declarations of any of the specified functions and before the definitions of these functions"因此要注意#pragma的位置。</div>
<div class="separator" style="clear: both;">
這裡指定DriverEntry載入到INIT記憶體區段中,最後Unload之後,可以退出memory。另外兩個function則是指定載入PAGE sections。</div>
<h4 style="clear: both;">
(3) System Service Table Structure</h4>
<code>/*The structure representing the System Service Table*/
<br /> typedef struct SystemServiceTable{
<br /> UINT32* ServiceTable;
<br /> UINT32* CounterTable;
<br /> UINT32* ServiceLimit;
<br /> UINT32* ArgumentTable;
<br />} SST;
<br />
<br />/* Declaration of KeServiceDescriptorTable, which is exported by ntoskrnl.exe */
<br />// KeserviceDescriptorTable symbol is just a memory addr exported by kernel
<br />__declspec(dllimport) SST KeServiceDescriptorTable;
</code>
<br />
<br />
<div class="separator" style="clear: both;">
KeServiceDescriptorTable可以由ntoskrnl.exe得到,因此為了得到kernel輸出的symbol,必須透過__declspec(dllimport)的方法。dllimport可以用來告訴compiler,kernel要export一個特定的function,叫compiler不要throw error出來。(一般來說compiler會反應error因為compiler不認識這個function)最後如果我們要用到此symbol時,linker會負責找到這個symbol的address。</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
因為kernel給我們的symbol 只有一個address,而address裡的內容我們必須要定義一個structure來取出我們要的info。因此我們定義了一個SystemServiceTable的結構以取出該address中的資料。</div>
<h4 style="clear: both;">
(4)ZwQuerySystemInformation Definition</h4>
<code>/* Required information for hooking ZwQuerySystemInformation */
<br />NTSYSAPI NTSTATUS NTAPI ZwQuerySystemInformation(
<br /> ULONG SystemInformationClass,
<br /> PVOID SystemInformation,
<br /> ULONG SystemInformationLength,
<br /> PULONG ReturnLength
<br /> );
<br />
<br />typedef NTSTATUS(*ZwQuerySystemInformationPrototype)(
<br /> ULONG SystemInformationClass,
<br /> PVOID SystemInformation,
<br /> ULONG SystemInformationLength,
<br /> PULONG ReturnLength
<br /> );
<br /><br />/* global variable is used as a placeholder for saving the old address from SSDT */
<br />ZwQuerySystemInformationPrototype oldZwQuerySystemInformation = NULL;
</code>
<br />
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
ZwQuerySystemInformation是我們想要hook的function,負責回傳特定的system information。(此function 在win8上好像已經不能使用?)和上面一樣,我們沒有kernel code,因此只好依著查到的prototype來定義一個自己用的ZwQuerySystemInformation。Structure的parameter說明如下:</div>
<div class="separator" style="clear: both; text-align: left;">
(a)SYSTEM_INFORMATION_CLASS:定義了我們想要retrieve的system information的type,可以是SystemBasicInformation、SystemProcessInformation、SystemProcessPerformanceInformation...等,詳細的資訊可以去msdn查。</div>
<div class="separator" style="clear: both; text-align: left;">
(b)SystemInformation: 是一個指向buffer的pointer。buffer中存的是retrieve回來的資料。至於buffer的大小和struct視SystemInformationClass 而定。</div>
<div class="separator" style="clear: both;">
(c)SystemInformationLength: buffer的size(bytes)</div>
<div class="separator" style="clear: both;">
(d)ReturnLength: optional 參數,就是實際被寫入buffer中的bytes</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
另外我們需要定義一個function pointer oldZwQuerySystemInformation,這個function pointer會儲存舊的native api的address,我們在hook function中會需要此function pointer來指到真正的ZwQuerySystemInformation,讓系統繼續完成他的工作。</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
這裡的oldZwQuerySystemInformation是一個global variable,當作一個容器儲存被我們hook的native function。</div>
</div>
<div>
<h4>
(5) Set Write Access to WP flag</h4>
<code>/* Disable the WriteProtect bit in CR0 register */
<br />void DisableWP(){
<br /> __asm{
<br /> push edx;
<br /> mov edx, cr0;
<br /> and edx, 0xFFFEFFFF;
<br /> mov cr0, edx;
<br /> pop edx;
<br /> }
<br />}
<br />/* Enable the WriteProtect bit in CR0 register */
<br />void EnableWP(){
<br /> __asm{
<br /> push edx;
<br /> mov edx, cr0;
<br /> or edx, 0x00010000;
<br /> mov cr0, edx;
<br /> pop edx;
<br /> }
<br />} </code><br />
<div style="text-align: left;">
我們對SSDT是沒有write access的,那要如何取得權限呢? reference[1]中有提到3個方法,那我一樣是採取最方便的做法,將CR0的WP flag 設成0,一旦設成0就能夠寫入SSDT新的資料,最後結束hooking時再將CR0的WP flag設回1</div>
<h4 style="text-align: left;">
(6) HookSSDT (mainly hooking function!)</h4>
<code> PULONG HookSSDT(PUCHAR syscall, PUCHAR hookaddr){
<br />
<br /> /* local variables */
<br /> UINT32 index;
<br /> PLONG ssdt;
<br /> PLONG target;
<br /> PULONG ret;<br />
<br />
/* disable WP bit in CR0 to enable writing to SSDT */
<br /> DisableWP();
<br /> //DbgPrint(" The WP flag in CR0 has been disabled.\n");
<br />
DbgPrint(" In HookSSDT().\n");
<br /> /* identify the address of SSDT table */
<br />
ssdt = KeServiceDescriptorTable.ServiceTable;
<br /> DbgPrint(" The system call address is %x\n", syscall);
<br /> DbgPrint(" The hook function address is %x\n", hookaddr);
<br /> DbgPrint(" The address of the SSDT is %x\n", ssdt);
<br /> /* identify 'syscall' index into the SSDT table */
<br /> /* *()means to dereference, to get the content at that addr */
<br /> index = *((PULONG)(syscall + 0x1));
<br /> DbgPrint(" The index into the SSDT table is %d\n", index);
<br /> /* get the address of the service routine in SSDT */
<br /> target = (PLONG)&(ssdt[index]);
<br /> DbgPrint(" The address of the SSDT routine to be hooked is %x\n", target);
<br /> DbgPrint(" The content of ssdt[261] is %x\n", ssdt[index]);
<br /> //ret = (PUCHAR)InterlockedExchange(target, hookaddr);
<br /> ret = (PVOID)InterlockedExchange(&ssdt[index], hookaddr);
<br /> DbgPrint(" exchange!new ssdt[261] is %x\n", ssdt[index]);
<br />
/* hook the service routine in SSDT */
<br /> return ret;
<br /> }
</code>
<br />
<div style="text-align: left;">
<br />
<div style="text-align: left;">
HookSSDT的參數是syscall 以及 hookaddr,syscall是要hook的api address,但此api不是native code。前面有提到,這種API一開始就會將index 放入eax中在call KiServiceTable到SSDT中呼叫真正的native api。(ntokrnl.exe中: Zw系列-->call Nt系列)。</div>
<br />
<div style="text-align: left;">
簡單來說這裡的sample中我給的參數是ZwQuerySystemInformation的addr,沿著此address找到index value之後我再去SSDT[index]得到我想要的NtQuerySystemInformation,就可以hook NtQuerySystemInformation啦!</div>
<br />
<div style="text-align: left;">
HookSSDT做的事情有:</div>
<div style="text-align: left;">
(1)Disable WPflag</div>
<div style="text-align: left;">
(2)利用KeServiceDescriptorTable.ServiceTable取出ssdt的起始address</div>
<div style="text-align: left;">
(3)利用syscall addr+1取出syscall的index(用*取出該address的內容)</div>
<div style="text-align: left;">
(4)取得SSDT[index]的address (用&取得)</div>
<div style="text-align: left;">
(5)用InterlockedExchange()交換兩address的內容</div>
<div style="text-align: left;">
(6)return InterlockedExchange的return value,也就是回傳ntQuerySystemInformation的address</div>
</div>
<h3>
(7) Hook_ZwQuerySystemInformation</h3>
<code> /* hook function */
<br /> NTSTATUS Hook_ZwQuerySystemInformation(ULONG SystemInformationClass,
<br /> PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength){
<br />
<br /> /* local variables */
<br /> NTSTATUS status;
<br /> PBYTE buffer;
<br /> /* calling new instructions */
<br /> DbgPrint(" ZwQuerySystemInformation hook called\n");
<br />
<br /> /* calling old function */
<br /> status=oldZwQuerySystemInformation(SystemInformationClass,SystemInformation, SystemInformationLength, ReturnLength);
<br /> // if(!NT_SUCCESS(status))
<br /> if (status == STATUS_INFO_LENGTH_MISMATCH) {
<br /> DbgPrint("Error:length mismatch! Allocate new buffer! ");<br />
<span style="font-family: monospace;"> </span><span style="font-family: monospace;"> </span>//PBYTE buffer = malloc((PULONG)ReturnLength * sizeof(PBYTE));<br />
<span style="font-family: monospace;"> </span><span style="font-family: monospace;"> </span>PBYTE buffer = ExAllocatePoolWithTag(PagedPool, ReturnLength, 'Tag1');<br /> if (buffer == NULL){
<br /> DbgPrint(" Allocate Error\n");
<br /> status = STATUS_INSUFFICIENT_RESOURCES;
<br /> return status;
<br /> }<br />
status = oldZwQuerySystemInformation(SystemInformationClass, (PVOID)buffer, ReturnLength, NULL);
<br /> if (status == STATUS_SUCCESS){
<br /> DbgPrint("--call origin api again and success! \n");
<br /> }
<br /> }else if (NT_SUCCESS(status)){
<br /> DbgPrint("call origin api success! \n");
<br /> }
<br /> return status;
<br /> }
</code></div>
<br />
HookSystemInformation會call old native api ,也就是ntQuerySystemInformation,來繼續retrieve system information。<br />
<h3>
(8) DriverUnload</h3>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUtEpXtntGPDx0BX495gNSrIIL8ADrUpa-H__2OXULvFyAFfDxLkBLjdSSVTOsc6MBvcXQj9TJhMoBUa_0KltrX_FPyS5MbTUnn5dF_TRxFgT5seBZsh3ijNuN0TMdYKAmZ3d2j-Pav6Oy/s1600/driverunload1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="61" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUtEpXtntGPDx0BX495gNSrIIL8ADrUpa-H__2OXULvFyAFfDxLkBLjdSSVTOsc6MBvcXQj9TJhMoBUa_0KltrX_FPyS5MbTUnn5dF_TRxFgT5seBZsh3ijNuN0TMdYKAmZ3d2j-Pav6Oy/s1600/driverunload1.png" width="400" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
Driver 的unload有分2部分,分別是DriverUnload Routine以及 Driver image實際上的unload,我參考了reference3畫了一個簡易圖示如下<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQr46ykLwZm_Agpd-XU4gW5zWis8djFTU1lqRqpquF-RQKJA-Y3Y0CgN9HFjC6NsS3mzq9192amyY-XG6nLGfPHg_qh_xLuHvdto-Yncfn7TO6rTanVyqKaQY9g1SpwMhYLIhRRd3V8i13/s1600/driverunload2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="235" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQr46ykLwZm_Agpd-XU4gW5zWis8djFTU1lqRqpquF-RQKJA-Y3Y0CgN9HFjC6NsS3mzq9192amyY-XG6nLGfPHg_qh_xLuHvdto-Yncfn7TO6rTanVyqKaQY9g1SpwMhYLIhRRd3V8i13/s1600/driverunload2.png" width="640" /></a></div>
<br />
<div style="text-align: left;">
程式碼部分這裡沒有做太多事,只有將SSDT有修改的地方restore回去,也就是將原本ntQuerySystemInformation的address放回SSDT[261]裡去。最後call IODeleteSymbolicLink以及 IODeleteDevice準備unload driver image。</div>
<code>
<br />VOID DriverUnload(PDRIVER_OBJECT DriverObject)
<br /> {
<br /> UNICODE_STRING usDosDeviceName;
<br /> /* restore the hook */
<br /> /* let syscall addr in SSDT point to original syscall addr*/
<br /> if (oldZwQuerySystemInformation != NULL){
<br /> oldZwQuerySystemInformation=(ZwQuerySystemInformationPrototype)HookSSDT((PULONG)ZwQuerySystemInformation, (PULONG)oldZwQuerySystemInformation);
<br /> EnableWP();
<br /> DbgPrint(" The original SSDT function restored\n");
<br /> }
<br />
<br /> DbgPrint("Driver unload\n");
<br /> RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\MySSDTHooking");
<br /> IoDeleteSymbolicLink(&usDosDeviceName);
<br /> IoDeleteDevice(DriverObject->DeviceObject);
<br /> }</code><br />
<h3>
(9) DriverEntry (Driver程式進入點)</h3>
<div>
<div style="text-align: left;">
DriverEntry中做的事情有</div>
<div style="text-align: left;">
(1)IOCreateDevice:create device object</div>
<div style="text-align: left;">
(2)若create 成功,assign major function給driver object。這裡全都assign同一個function,也就是 MyDriver_UnSupportedFunction,這個function什麼也不做,只是一個簡單的雛形。</div>
<div style="text-align: left;">
(3)assign DriverUnload function,這個動作有點像是callback function,就是告訴system當driver 要 unload時該call哪一個function。</div>
<div style="text-align: left;">
(4)IoCreateSymbolicLink:create symbolic link</div>
<div style="text-align: left;">
(5)call HookSSDT,最重要的step。第一個param是ZwQuerySystemInformation,因為他是我們的目標嘛,第二個param是Hook_ZwQuerySystemInformation,就是我們要replace ZwQuerySystemInformation的function。Call HookSSDT之後,SSDT的第261個entry內容就會指向Hook_ZwQuerySystemInformation,並且return 原來ZwQuerySystemInformation的address。我將他存在oldZwQuerySystemInformation(一個global variable),之後在driver unload以及Hook_ZwQuerySystemInformation裡都會用到此變數,因為我需要call 這個真正的native api以維持system 正常運作。</div>
</div>
<code>
<br />NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath){
<br />
<br /> NTSTATUS NtStatus = STATUS_SUCCESS;
<br /> unsigned int uiIndex = 0;
<br /> PDEVICE_OBJECT pDeviceObject = NULL;
<br /> UNICODE_STRING usDriverName, usDosDeviceName;
<br />
<br /> DbgPrint("DriverEntry called\n");
<br />
<br /> // initialize driver name and device name
<br /> RtlInitUnicodeString(&usDriverName, L"\\Device\\MySSDTHooking");
<br /> RtlInitUnicodeString(&usDosDeviceName, L"\\DosDevices\\MySSDTHooking");
<br /> // create a new device object(type is FILE_DEVICE_UNKNOWN, can only be used by a application)
<br /> NtStatus = IoCreateDevice(pDriverObject, 0, &usDriverName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pDeviceObject);
<br />
<br /> if (NtStatus == STATUS_SUCCESS){
<br /> /* MajorFunction: is a list of function pointers for entry points into the driver */
<br /> for (uiIndex = 0; uiIndex < IRP_MJ_MAXIMUM_FUNCTION; uiIndex++)
<br /> pDriverObject->MajorFunction[uiIndex] = MyDriver_UnSupportedFunction;<br />
<br /> pDriverObject->DriverUnload = DriverUnload;
<br /> pDeviceObject->Flags |= DO_BUFFERED_IO;
<br /> pDeviceObject->Flags &= (~DO_DEVICE_INITIALIZING);
<br />
<br /> // Create symbol link
<br /> IoCreateSymbolicLink(&usDosDeviceName, &usDriverName);
<br /> DbgPrint("ZwQuerySystemInformation is at %x\n", ZwQuerySystemInformation);
<br /> oldZwQuerySystemInformation = (ZwQuerySystemInformationPrototype)HookSSDT((PULONG)ZwQuerySystemInformation, (PULONG)Hook_ZwQuerySystemInformation);
<br /> DbgPrint("HookSSDT return addr is %x\n", oldZwQuerySystemInformation);
<br /> }
<br /> DbgPrint("DriverEntry finished\n");
<br /> return STATUS_SUCCESS;
<br /> }</code><br />
<div style="text-align: left;">
<h3>
(10) MyDriver_UnSupportedFunction</h3>
<div>
前面提過啦~這在這裡是一個不重要的function,以後有用到再紀錄</div>
<div>
<code>
<br />NTSTATUS MyDriver_UnSupportedFunction(PDEVICE_OBJECT DeviceObject, PIRP Irp){
<br /> NTSTATUS NtStatus = STATUS_NOT_SUPPORTED;
<br /> //DbgPrint("MyDriver_UnSupportedFunction called\n");
<br /> return NtStatus;
<br /> }</code></div>
<div>
<h3>
(11) Summary</h3>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4PgMDdjJ9Jt3sBQKe-GqG8vEnXCRpT62suBDHfecSW1xKBd73Eike9FltUfNID55MBo3typCVSjWBB_7oLpje1a5d_IuKpdJoqt27Fcn-Po0O2y9isihRVPS1pcMaJdtIJZ2AQVwUKMDk/s1600/flow1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4PgMDdjJ9Jt3sBQKe-GqG8vEnXCRpT62suBDHfecSW1xKBd73Eike9FltUfNID55MBo3typCVSjWBB_7oLpje1a5d_IuKpdJoqt27Fcn-Po0O2y9isihRVPS1pcMaJdtIJZ2AQVwUKMDk/s1600/flow1.png" width="276" /></a></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfpqzn1RLKjyEfr1AU5iHjyD_Q-O88KznJYo-zODU4Gj8AWWNpqRA9R3PbJe0afL0dgXtLb-EA1MKOuziaTsOlHy9CaEtKZVjaKraRPl51bh8CFpmyRGoYGoD9ZcllglggSvLDsOj7dD1e/s1600/flow2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="256" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfpqzn1RLKjyEfr1AU5iHjyD_Q-O88KznJYo-zODU4Gj8AWWNpqRA9R3PbJe0afL0dgXtLb-EA1MKOuziaTsOlHy9CaEtKZVjaKraRPl51bh8CFpmyRGoYGoD9ZcllglggSvLDsOj7dD1e/s1600/flow2.png" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
總結一下這一次的project是hook ZwQuerySystemInformation,但實際上是更改SSDT[261]指向的位置,原本指向NtQuerySystemInformation,我改成指向自己的hook_function,ZwQuerySystemInformation負責將index存入eax再call system service,所以真正回報系統info的是NtQuerySystemInformation。</div>
<h3 style="clear: both; text-align: left;">
(12) Reference</h3>
<div class="separator" style="clear: both; text-align: left;">
以上的程式大部分不是我自己會寫的,而是讀了許多文章學習而來,仍有許多問題還未解決,以後再陸續紀錄新問題與解決之法。</div>
<div class="separator" style="clear: both; text-align: left;">
[1] 完整hooking教學</div>
<div class="separator" style="clear: both; text-align: left;">
http://resources.infosecinstitute.com/hooking-system-service-dispatch-table-ssdt/</div>
<div class="separator" style="clear: both; text-align: left;">
[2]中文教學 </div>
<div class="separator" style="clear: both; text-align: left;">
http://www.cnblogs.com/BoyXiao/archive/2011/09/03/2164574.html</div>
<div class="separator" style="clear: both; text-align: left;">
[3] Unload driver concept</div>
<div class="separator" style="clear: both; text-align: left;">
http://blogs.msdn.com/b/usbcoreblog/archive/2009/10/06/why-doesn-t-my-driver-unload.aspx</div>
<div class="separator" style="clear: both; text-align: left;">
[4] alloc text msdn</div>
<div class="separator" style="clear: both; text-align: left;">
http://msdn.microsoft.com/en-us/library/sw8ty6zf.aspx</div>
<div class="separator" style="clear: both; text-align: left;">
[5]Building and deploying a basic WDF Kernel Mode Driver</div>
<div class="separator" style="clear: both; text-align: left;">
http://www.codeproject.com/Articles/13090/Building-and-deploying-a-basic-WDF-Kernel-Mode-Dri</div>
<div class="separator" style="clear: both; text-align: left;">
[6]DbgMessage filter</div>
<div class="separator" style="clear: both; text-align: left;">
http://msdn.microsoft.com/en-us/library/windows/hardware/ff551519(v=vs.85).aspx</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
終於寫完了然後code怎麼這麼醜阿~天啊 Q_Q</div>
<div class="separator" style="clear: both; text-align: left;">
by BlackCat </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div>
<br /></div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-25394555933371156982014-06-30T21:13:00.001-07:002014-06-30T21:34:05.371-07:00Windows Driver 3_ Provision Computer For Driver Deployment And Testing <span style="font-size: large;">In the previous discussion, I used [manually configure debuggers and do not provision], but in this way, the driver files must be installed by myself. In order to save time, I use [<span style="color: red;">Provision computer and choose debugger settings</span>], the more details is in </span><br />
http://msdn.microsoft.com/en-us/library/windows/hardware/hh698272(v=vs.85).aspx<br />
<br />
<span style="font-size: large;">I'll show steps briefly...</span><br />
<span style="font-size: large;">Assume that the driver has built already and the things we have to do is to deploy and test it.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">1. Go to C:\Program Files\Windows Kits\8.1\Remote\x86, then copy [WDK Test Target Setup x86-x86_en-us] into your target computer and install it. </span><span style="font-size: large;"><br /></span>
<span style="font-size: large;"><br /></span><br />
<span style="font-size: large;">2. In Host Computer (Visual Studio 2013)</span><br />
<br />
<span style="font-size: large;"> [Driver] menu -> test-> Configure Computer</span><br />
<span style="font-size: large;"></span><br />
<span style="font-size: large;"> choose second one, and notice that the computer name must as same as the name of your target computer,</span><br />
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQb6rDGIrBEj-nghydmglCazDdTBVFgxkFEVTX4FNMOEtzYxrq8FJkhChDnR5IvWj3KEGuqL_W-vR_UpJ5xJumubfPHquVTWhYbZowhgENuGXHc0adDztBt7awMOu-FqyYva4M6XXNyTra/s1600/1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQb6rDGIrBEj-nghydmglCazDdTBVFgxkFEVTX4FNMOEtzYxrq8FJkhChDnR5IvWj3KEGuqL_W-vR_UpJ5xJumubfPHquVTWhYbZowhgENuGXHc0adDztBt7awMOu-FqyYva4M6XXNyTra/s1600/1.PNG" height="375" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: start;">you can find your target computer's name just like second pictures:</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: start;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS-YoXp8gnvTO6uxlypMMvuXtNElLRoWpYwbmtkZB8dxVqba_bSx7zXu5bC3MLqwy2sg7SMAhopBPAo-QJmb4NSPdrMKqeFdjkdC6tGWjZGOGyy3gQLB_WGjrU09RQW6lmEoPY-ZRMe4tV/s1600/3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhS-YoXp8gnvTO6uxlypMMvuXtNElLRoWpYwbmtkZB8dxVqba_bSx7zXu5bC3MLqwy2sg7SMAhopBPAo-QJmb4NSPdrMKqeFdjkdC6tGWjZGOGyy3gQLB_WGjrU09RQW6lmEoPY-ZRMe4tV/s1600/3.PNG" height="400" width="347" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">After clicking next, you have to set the pipe name. </span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLZh_mdlZv9C3ZUqbKuYUzRvruiA8MDB1C4-UcdYVxse9uUYyPIrQHTOjKIlX1d7MRhW9jTxbrmaVWvmGlXblcQqnbvw-_Orn02JK9xW68a1OWMQHNrAjuWMKcX0pjQHRv5BkS_Kyo2qhI/s1600/2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLZh_mdlZv9C3ZUqbKuYUzRvruiA8MDB1C4-UcdYVxse9uUYyPIrQHTOjKIlX1d7MRhW9jTxbrmaVWvmGlXblcQqnbvw-_Orn02JK9xW68a1OWMQHNrAjuWMKcX0pjQHRv5BkS_Kyo2qhI/s1600/2.PNG" height="378" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
<span style="font-size: large; text-align: left;">Note that the pipe name must as same as the pipename you set in vmware. The picture below shows the pipe name that I set at VMware before.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">(We create this serial port to let virtual computer know that there's a port it can use. This serial port is a virtual port and VMware will receive the data from virtual computer through this port, then send the data out to the host computer according to the pipe name, the host computer must have the same pipe name to receive these data from VMware and handle them, and that's why we set a pipe name in Visual Studio and in VMware both the same.)</span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<span style="font-size: large; text-align: left;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzWGnOSocNKJWo3OvjpEj7YCa7hSN_TrL0fzj-XQV6XCFxnpM_3VuZNcdbLIcgD86TNjWv9yMiQVeLJAVV6uZ5Y1ElJOwYzHEvwlTwckp4QCMheVzUsueI8_00hU2SXxKmpFIPH20LMRkn/s1600/4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzWGnOSocNKJWo3OvjpEj7YCa7hSN_TrL0fzj-XQV6XCFxnpM_3VuZNcdbLIcgD86TNjWv9yMiQVeLJAVV6uZ5Y1ElJOwYzHEvwlTwckp4QCMheVzUsueI8_00hU2SXxKmpFIPH20LMRkn/s1600/4.PNG" height="347" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span style="font-size: large;">After finishing the configuration, system will connect to your target computer, and if success, it will show "complete" at last.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;">3. Now go back to the Visual Studio and in the Solution Manager Window(方案總管), right click [HelloWorld Package]-> properties -> Driver Install -> Deployment</span><br />
<span style="font-size: large;">Click [Enable deployment] and [Remove previous driver versions before deployment]</span><br />
<span style="font-size: large;">Then, entering Target Computer Name</span><br />
<span style="font-size: large;">Finally, in the [Hardware ID Driver Update], Type "Root\HelloWorld". Hardware ID does not identify a real hardware, it identifies an virtual device, and we must give it a place in the devie tree as child of the root node. The doc in Microsoft mentioned that we do not need to select [Hardware ID Driver Update] if it's a real hardware. Instead, we should choose [Install and Verify]</span><br />
<span style="font-size: large;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAV3_09gSimmhtE5UaOQY880P-w_ab8qI9R4s1s6xReUd6_qZR_HLchfhDEr_AhJSRmheeX1LaSo1pTyVgKsoppDXyAJodOaJOFwGyRKnkrioVwbogVCoOaBfDOrDrIa8dmELdt1rW9pci/s1600/5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAV3_09gSimmhtE5UaOQY880P-w_ab8qI9R4s1s6xReUd6_qZR_HLchfhDEr_AhJSRmheeX1LaSo1pTyVgKsoppDXyAJodOaJOFwGyRKnkrioVwbogVCoOaBfDOrDrIa8dmELdt1rW9pci/s1600/5.PNG" height="384" width="640" /></a></div>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"></span><span style="font-size: large;">4. When you click F5 in your visual studio trying to remote debug to the target computer, this program will control the target computer, create a WDKRemoteUser account and move the driver packages, even run the driver automatically.</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"></span><br />
<span style="font-size: large;">From now on, you don't need to copy your driver packages into the target computer manually, the debugger in Visual Studio will do it for U. Hurray!!!!!!</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<br />
<span style="font-size: large;"><br /></span>
<br />
<div>
<br /></div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-318453447213693072014-06-29T02:49:00.001-07:002014-06-29T02:53:41.222-07:00Windows Driver 2 _ HelloWorld Driver<span style="font-size: large;">It's time to write my first driver "HelloWorld"</span><br />
<div>
<span style="font-size: large;">I write this code in VS2013 and here's my steps</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div>
<div>
<span style="font-size: large;">A. Create a new project</span></div>
<div>
<span style="font-size: large;"> (1) [File] menu->[New]->[Project], in the left pane, select [Installed]->[WDF], in the middle pane, select [Kernel Mode Driver, Empty(KMDF)]. Fill in "HelloWorld" in the name field and choose the project's location in the location field. Check out Create directory for solution. Finally click OK ! </span></div>
</div>
<div>
<span style="font-size: large;">(Note that the name field can only be equal or less than 32 characters string, mentioned in Microsoft Official Doc</span><span style="font-size: large;">)</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2HK9eeorj92QYnQp7Kq518zapELmWPhddOVskg6J6P0I8AtbDQaDxHjEqsyB1l5Ef7mWqHNemtZzeJ6oZETIx0nFmw93UUw3rTDK8vmuYBE0To-3f-6QANW93bhzuSodjps84AkdHDomC/s1600/1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2HK9eeorj92QYnQp7Kq518zapELmWPhddOVskg6J6P0I8AtbDQaDxHjEqsyB1l5Ef7mWqHNemtZzeJ6oZETIx0nFmw93UUw3rTDK8vmuYBE0To-3f-6QANW93bhzuSodjps84AkdHDomC/s1600/1.PNG" height="305" width="400" /></a></div>
<div>
<br /></div>
<div>
<span style="font-size: large;"> (2) In the Solution Explorer(方案總管), right click [HelloWorld]->add->new Item(新增項目). </span><span style="font-size: large;">In the middle pane, select C++ File, and name "main.c" in the name field, then click add. </span><span style="font-size: large;">Finally, you will see main.c under the Source Files</span></div>
<div>
<span style="font-size: large;">(Note that the file name extension is .c !!)</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicbH9OmF_O4A0U5UqywAbkZkEgJkae8VMW5nAZTqn0rdO8NqiRvcS80nOWwBMuTDfhSKlmpv52BW9v-mBKcjsV_EaU9I_ZATHxr76bRVOktqjsXcu5xenViuw4EDsWabucd9P1AV44SMP5/s1600/2.1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicbH9OmF_O4A0U5UqywAbkZkEgJkae8VMW5nAZTqn0rdO8NqiRvcS80nOWwBMuTDfhSKlmpv52BW9v-mBKcjsV_EaU9I_ZATHxr76bRVOktqjsXcu5xenViuw4EDsWabucd9P1AV44SMP5/s1600/2.1.PNG" height="400" width="256" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigjixdiVj6rSNaV04fO956k0nxMDnXE4LSBozr6qV3HdKafSP3LjIk77LMmTaniEgE1Nd46J2nmMHeXXQp1HfpqAGSA_ETz-h5coj2AxPHM7dH-xTR748itLKF2usEiTIBfNJA12hIN__j/s1600/2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigjixdiVj6rSNaV04fO956k0nxMDnXE4LSBozr6qV3HdKafSP3LjIk77LMmTaniEgE1Nd46J2nmMHeXXQp1HfpqAGSA_ETz-h5coj2AxPHM7dH-xTR748itLKF2usEiTIBfNJA12hIN__j/s1600/2.PNG" height="273" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Here's the code:</span></div>
<div class="separator" style="clear: both; text-align: left;">
-------------------------------------------------------------------------------------------------------</div>
<div class="separator" style="clear: both;">
#include <ntddk.h> </div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
VOID DriverUnload(PDRIVER_OBJECT driver)</div>
<div class="separator" style="clear: both;">
{</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>DbgPrint("first:HelloWorld End!");</div>
<div class="separator" style="clear: both;">
}</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pUnicodeString)</div>
<div class="separator" style="clear: both;">
{</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>DbgPrint("first:HelloWorld Begin!");</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>pDriverObject->DriverUnload = DriverUnload;</div>
<div class="separator" style="clear: both;">
<span class="Apple-tab-span" style="white-space: pre;"> </span>return STATUS_SUCCESS;</div>
<div class="separator" style="clear: both;">
}</div>
<div>
-------------------------------------------------------------------------------------------------------</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> (3) Right click Solution'HelloWorld'(2 Solutions)(方案'HelloWorld')-> configuration manager(組態管理員). Choose configuration and platform both HelloWorld and HelloWorld Package</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw4bmAyXwZCASX-DB50UkQtrRujSfk3QP7qJA94r3w1n-LvDHERpiMgB_O025rLWp2aS1qjVbxQRACKQoeW1zF_FO-NSNrmszM_41P25PPs9scKmoY7hTgJykEemwJ8fxMVFQRtwebcxgc/s1600/3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhw4bmAyXwZCASX-DB50UkQtrRujSfk3QP7qJA94r3w1n-LvDHERpiMgB_O025rLWp2aS1qjVbxQRACKQoeW1zF_FO-NSNrmszM_41P25PPs9scKmoY7hTgJykEemwJ8fxMVFQRtwebcxgc/s1600/3.PNG" height="263" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> (4) Cancel Wpp Tracing</span></div>
<div>
<span style="font-size: large;">Solution Explorer->right click HelloWorld -> Properties -> set Run Wpp tracing to No -> OK</span></div>
<div>
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJmW-Ubp3xpGTghyphenhyphenqQAIX0uPrnGBOf6d-zrjd2xnrj-tyLtfEXI1j2SRH-mrCVqzJyIP30ElAiF0NC_DBk92gps-zSuwcVIk8-V2eXtIlNh0UqYCYEWQjqsCBrB9GPk3qaVWX2gsqkgfma/s1600/4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJmW-Ubp3xpGTghyphenhyphenqQAIX0uPrnGBOf6d-zrjd2xnrj-tyLtfEXI1j2SRH-mrCVqzJyIP30ElAiF0NC_DBk92gps-zSuwcVIk8-V2eXtIlNh0UqYCYEWQjqsCBrB9GPk3qaVWX2gsqkgfma/s1600/4.PNG" height="227" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">(5) also in Properties->C/C++ -> middle pane 警告視為錯誤->否</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> (6) Build project</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">Choose Build Solution->Build to build driver and create a driver package, the ouput window will show the build progress.</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr11wOGVhj4nhptOas0f5S9BKCnw7hHOhAfStRYE7Z8CKZs-MEA9WZMC4rcSLw8tzue4G9kUAdq2qUpdD5wymkSCr6At6kOvLVftVY_P081ABz__4-L53OyFBNv3kED4_xP_7SfJNCxSkk/s1600/5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr11wOGVhj4nhptOas0f5S9BKCnw7hHOhAfStRYE7Z8CKZs-MEA9WZMC4rcSLw8tzue4G9kUAdq2qUpdD5wymkSCr6At6kOvLVftVY_P081ABz__4-L53OyFBNv3kED4_xP_7SfJNCxSkk/s1600/5.PNG" height="157" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> (7) Navigate in Windows Explorer to your HelloWorld folder(..\Visual Studio 2013\Projects\HelloWorld), then go into win7Debug\HelloWorld Package folder, there will have several files:</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><span style="color: red;">HelloWorld.sys :</span> the kernel mode driver file</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><span style="color: red;">HelloWorld.inf :</span> an information file that Windows uses when driver is installed</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><span style="color: red;">HelloWorld.cat :</span> a catalog file that the installer uses to verify the test signature for the driver package</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><span style="color: red;">WdfCoinstaller01011.dll : </span>A co-installer for the Windows Driver Frameworks(WDF)</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrXMUPaXKEdaZtuXDyVLe2AdDfr91RbqY_lfXuUixH1nS66PZJeTQQ_ecdfrdLYr1U_NAwblKz-iAEewjzCr0mo8clpmFCkGowL1FKIMzVLYQA3YVMCLmn7Cc-gA2zVbrnLr92qHyMOQqQ/s1600/6.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrXMUPaXKEdaZtuXDyVLe2AdDfr91RbqY_lfXuUixH1nS66PZJeTQQ_ecdfrdLYr1U_NAwblKz-iAEewjzCr0mo8clpmFCkGowL1FKIMzVLYQA3YVMCLmn7Cc-gA2zVbrnLr92qHyMOQqQ/s1600/6.PNG" height="152" width="400" /></a></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">B. After building your project, it's time to test it on target computer.</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">Before testing your driver, you must copy your [HelloWorld Package]folder into your target computer.</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">Normally, you will have 4 files in your HelloWorld folder that I mentioned in last article.</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (1) Let's start from setting the DebugView </span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> Run -> regedit -> open key :[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager] -> create a key [Debug Print Filter] under this folder -> add a DEFAULT <span style="color: red;">DWORD </span>value and set a value <span style="color: red;">0x0f</span> on it -> reboot</span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5TKj5Lb48J6HaVs_AmhwKXSRS_-0o0NUm0-_rwIwQIoY3fTZ3CjhTUGTMWVBdMiM5iPt2QT_QbFu1M2-fr4huB91moNTc1Mq1GIFKWBAfe1ay9WcHNMuChbxndcgJiU3mK1HqTxWYGsYv/s1600/B3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5TKj5Lb48J6HaVs_AmhwKXSRS_-0o0NUm0-_rwIwQIoY3fTZ3CjhTUGTMWVBdMiM5iPt2QT_QbFu1M2-fr4huB91moNTc1Mq1GIFKWBAfe1ay9WcHNMuChbxndcgJiU3mK1HqTxWYGsYv/s1600/B3.PNG" height="336" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> (2) open DebugView and check out [capture]->[capture kernel]</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"><br /></span></div>
<div>
<span style="font-size: large;"> (3) open osrloader and select the sys file you want to load. Then click [Register Service] and [Start Service] then you will see "first:HelloWorld Begin" in DebugView.</span><br />
<span style="font-size: large;">Click [Stop Service] then you will see "first:HelloWorld End". If you want to remove the driver, click [Unregister Service].</span><br />
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgni6m9wSMOIfWhykKRpjbcpTVOSekaN_vBvHn7q9E5IyK6hqnYqr5DkKc8u6m4Gk64Btn0Sbeh_RH8q8_9aYM4U0OMzNBboaJ656UA-EjR6OpuD-VI8hDoxy6ZWA3BGUakW3lE2u1avGTA/s1600/B2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgni6m9wSMOIfWhykKRpjbcpTVOSekaN_vBvHn7q9E5IyK6hqnYqr5DkKc8u6m4Gk64Btn0Sbeh_RH8q8_9aYM4U0OMzNBboaJ656UA-EjR6OpuD-VI8hDoxy6ZWA3BGUakW3lE2u1avGTA/s1600/B2.PNG" height="242" width="400" /></a></div>
<span style="font-size: large;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTiaplLOWzpwvIxqex1FNu0dcEaaAnE700LLxe-3KUOC2zFFu8I_KqRHj3HD8AWj-QW2MybsSVX5-puXVwlLlnnXTs-FEoL1QRo7EMAr0MbmZGGdVkYVDsDAtXOd6to2wzztZocXzdOEku/s1600/B1+-+%25E8%25A4%2587%25E8%25A3%25BD.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTiaplLOWzpwvIxqex1FNu0dcEaaAnE700LLxe-3KUOC2zFFu8I_KqRHj3HD8AWj-QW2MybsSVX5-puXVwlLlnnXTs-FEoL1QRo7EMAr0MbmZGGdVkYVDsDAtXOd6to2wzztZocXzdOEku/s1600/B1+-+%25E8%25A4%2587%25E8%25A3%25BD.PNG" height="238" width="400" /></a></div>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"> P.s You don't need to install the osrloader to load the driver, just find out your inf file, and right click on it, click [install]. However, it's up to you to use osrloader or not.</span><br />
<span style="font-size: large;">Another way to load your driver is using command, just entering sc create HelloWorld binPath= "your_sys_file's_location" type= "kernel" start= "demand" error= "normal" Displayname= "HelloWorld", press Enter</span><br />
<span style="font-size: large;">then entering sc start HelloWorld</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"></span><br />
<span style="font-size: large;"> If you use remote debug, you will see your string at Debugger Immediate Window in VS2013 </span><br />
<span style="font-size: large;"><br /></span>
[Reference]<br />
1. http://home.educities.edu.tw/fushiyun2000/driver_nt_style_c_tutorial_hello_world.htm</div>
<div>
2. http://eagle-sw.blogspot.tw/2011/10/win7debugview.html<br />
3. http://blogs.microsoft.co.il/sasha/2011/06/04/baby-steps-in-windows-device-driver-development-part-2-hello-world-driver/<br />
4. http://blog.csdn.net/wsye88/article/details/26375459</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-69372874167717658072014-06-29T01:16:00.002-07:002014-06-29T02:52:58.048-07:00Windows Driver 1_Setting Environment to Remote Debug <span style="font-size: large;">In this article, I will discuss how to set up the environment on Host/Target Computer to remote debug the driver running on target computer.</span><br />
<span style="font-size: large;">(p.s Target Computer is a virtual computer to test your driver )</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><b>A. Environment</b></span><br />
<span style="font-size: large;">Host Computer : Windows7 SP1 x86</span><br />
<span style="font-size: large;"> WDK (Windows Driver Kit)8.1</span><br />
<span style="font-size: large;"> Visual Studio 2013</span><br />
<span style="font-size: large;">Target Computer : Windows7 SP1 x86 (Run on VMware Player)</span><br />
<span style="font-size: large;"> Debug View</span><br />
<span style="font-size: large;"> osrLoader</span><br />
<span style="font-size: large;"><br /></span>
<span style="font-size: large;"><b>B. Settings on VS2013</b></span><br />
<span style="font-size: large;"> (1) [ Driver] menu-> Test->Computer Configuration</span><br />
<span style="font-size: large;"> (2) select [Add New Computer] button -> choose [Manually configure debuggers and do not provision], remember to give it a name!</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgICj4uWeikcPDvwfdjtuF0tm-CacRDvgsfKW3ZQum_gXL-F4f_hEcthvHK_4HsNgkorR0ZHJXlkJoUwORt43ad_icFytEttMjnl7xAb_0qCwxRp7Dwyl-wqioVbmQKd0k6xa-8DHsMZ3o2/s1600/1.2.PNG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgICj4uWeikcPDvwfdjtuF0tm-CacRDvgsfKW3ZQum_gXL-F4f_hEcthvHK_4HsNgkorR0ZHJXlkJoUwORt43ad_icFytEttMjnl7xAb_0qCwxRp7Dwyl-wqioVbmQKd0k6xa-8DHsMZ3o2/s1600/1.2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgICj4uWeikcPDvwfdjtuF0tm-CacRDvgsfKW3ZQum_gXL-F4f_hEcthvHK_4HsNgkorR0ZHJXlkJoUwORt43ad_icFytEttMjnl7xAb_0qCwxRp7Dwyl-wqioVbmQKd0k6xa-8DHsMZ3o2/s1600/1.2.PNG" height="378" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-size: large;"> (3) choose [Kernel Mode] and set the values as the picture shows</span><span style="font-size: large;">->next->finish</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIYaeXRmVTfxdoSlPjPWZ6wLanuE9xISKckG2CesPImrKVQ0Br8hHGsZal83YuRl4fUBQjaLOuxJtItfbJJe6Twr92HB-Uiuyl8UWxYM_j8qkA9CMJaeAY9ieiC76Xjr4zoEmMmtDU9UDF/s1600/1.2.2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIYaeXRmVTfxdoSlPjPWZ6wLanuE9xISKckG2CesPImrKVQ0Br8hHGsZal83YuRl4fUBQjaLOuxJtItfbJJe6Twr92HB-Uiuyl8UWxYM_j8qkA9CMJaeAY9ieiC76Xjr4zoEmMmtDU9UDF/s1600/1.2.2.PNG" height="376" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">(4) finally you will get the settings as follow</span></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9dnL5Qx5JT6gPY0-ZYCqc1bILr0ReAW9wpPuejhlJGGpdpG7WzI3FwQPAFB_LpFlcijrvaQbdPtibmsNEs-EgNub0j2Dw9pSzXKcU7UxYGd6fPWlW4pgrjQ4iOGVnnlDFfyXI304vfJ85/s1600/1.2.3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9dnL5Qx5JT6gPY0-ZYCqc1bILr0ReAW9wpPuejhlJGGpdpG7WzI3FwQPAFB_LpFlcijrvaQbdPtibmsNEs-EgNub0j2Dw9pSzXKcU7UxYGd6fPWlW4pgrjQ4iOGVnnlDFfyXI304vfJ85/s1600/1.2.3.PNG" height="382" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">C. Settings on VM</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (1) open [Virtual Machine Settings]</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (2) delete the Printer in order to let new serial port=1</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (3) [add] -> serial port -> choose [output to named pipe] as its serial port type -> in the Named pipe field enter "\\.\pipe\com_1" and choose [this end is the server],[the other end is an application ] -> finish</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">Your settings may look the same as follow, and remember to check out the [Yield CPU on poll]</span></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzlLwGSg1ntbgoOa2CZrX2SwPlTl2hDNOjJqRBxpbcP4bQ_5Azh6q2KW05gIPkx02GdeW5-fpYkqaC0A3WR5qLwd509FBb5adONDOlamfnTNNf7kXjXzxkxZy5Qk-ZoXsy_3PcuwYgNH2e/s1600/1.3.1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzlLwGSg1ntbgoOa2CZrX2SwPlTl2hDNOjJqRBxpbcP4bQ_5Azh6q2KW05gIPkx02GdeW5-fpYkqaC0A3WR5qLwd509FBb5adONDOlamfnTNNf7kXjXzxkxZy5Qk-ZoXsy_3PcuwYgNH2e/s1600/1.3.1.PNG" height="347" width="400" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">D. After those settings, turn on the target computer on VM (i.e your target computer=windows7)</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"> (1) use system manager's identity to open the command line and enter "bcdedit" to open the Windows Boot Manager (以系統管理員身分執行)</span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWnpHjtA2_xh98xBPEkYzP0ZiFnhQ6welaLKhioMMmj6b-thvfHJ2NDpGMzQ2T0CgerBimMrqWkUzp9HwPU9TwqCBQM0ZFh3L9kwe3dICWtEDwomWvJ-AkTBqDOQX6uyYFYBYNF4baX7l4/s1600/1.3.2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWnpHjtA2_xh98xBPEkYzP0ZiFnhQ6welaLKhioMMmj6b-thvfHJ2NDpGMzQ2T0CgerBimMrqWkUzp9HwPU9TwqCBQM0ZFh3L9kwe3dICWtEDwomWvJ-AkTBqDOQX6uyYFYBYNF4baX7l4/s1600/1.3.2.PNG" height="360" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">(2) enter a command <u>bcdedit /copy {current} /d "Windows 7 Kernel Debug Mode"</u>. </span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">This command will copy current boot settings and give it a new name, i.e Windows 7 Kernel Debug Mode, </span><span style="font-size: large;">and you will see 2 booting selections in boot manager.</span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS6KokjzDolC0bDktlxoG_x7Su7F5BB4xswNQDYcNjrHhx4YsJJmogXtf-9puPjMsWNqNt0UhiT8pasppbbb68IE_3xqwflN7pj72Z7U0UpbfTzNULaIqx2r1t94HNQrAEb7NzOUtRmFm0/s1600/1.3.3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjS6KokjzDolC0bDktlxoG_x7Su7F5BB4xswNQDYcNjrHhx4YsJJmogXtf-9puPjMsWNqNt0UhiT8pasppbbb68IE_3xqwflN7pj72Z7U0UpbfTzNULaIqx2r1t94HNQrAEb7NzOUtRmFm0/s1600/1.3.3.PNG" height="320" width="249" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (3) press WIN+R and open "msconfig" service -> choose [boot] (開機) menu, </span><span style="font-size: large;">you'll see Windows 7 Kenel Debug Mode in it. Select to boot it as a default selection.(設定成預設值) </span><span style="font-size: large;">Now choose it and click 進階選項-> check out the debug(偵錯) box, and select debug serial port(com1), finally select transmit rate to 115200 -> OK -> reboot your target computer</span>.</div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS67T0dNK-I0ZhctFXTNFLIpKSGSezlJxkx3XoSv8R4RnHa11GjSyM5N83zNZp_IpVKXF5gQc2SSlfi0ZtmCgWAt-Nonr6bABLmZ2AjoNA1HQGMZmlWDUGgIc8jfVoFx3Jhjiku0moO9h6/s1600/1.3.3.2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgS67T0dNK-I0ZhctFXTNFLIpKSGSezlJxkx3XoSv8R4RnHa11GjSyM5N83zNZp_IpVKXF5gQc2SSlfi0ZtmCgWAt-Nonr6bABLmZ2AjoNA1HQGMZmlWDUGgIc8jfVoFx3Jhjiku0moO9h6/s1600/1.3.3.2.PNG" height="370" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">E. Wow!!! Get ready to remote debug</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (1) Go back to VS2013 and click [Debugging Tools for Windows-Kernel Debugger]</span></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg484IbzP_4h2gTtxJa6_CuM3NJPQBD2oPVWTGNJek4UfIrGWy7F4me_P1MTOncdtxytni84mneg0xF5nC45PRG7Uh3L-hLLB-SRZWRPQcpKiKIahG1vNTvLu1yvAz5C8svFZNat1tOBbq0/s1600/1.3.4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg484IbzP_4h2gTtxJa6_CuM3NJPQBD2oPVWTGNJek4UfIrGWy7F4me_P1MTOncdtxytni84mneg0xF5nC45PRG7Uh3L-hLLB-SRZWRPQcpKiKIahG1vNTvLu1yvAz5C8svFZNat1tOBbq0/s1600/1.3.4.PNG" height="52" width="400" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;">(2) select I know what I'm doing, continue debugging</span></div>
<div class="separator" style="clear: both;">
<span style="font-size: large;"> (3) then you can see your debugging progress in Debugger Immediate Window, if it keeps waiting to reconnect for too long, trying to reboot your vm again and the connection will be success.</span></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZu3F1o1nwx3hwU53_3F5vlxfX-TtQXadDwTSA1qgMCLLpeRMpNfHE1UmcbYR672ch51wxNmcY1j4d4HcnlOkwC57Z-BygH81Z_q6me3D4mgi_pq5_dqLuWX_x8JIPyuDLrnNFvkBQqKxP/s1600/1.3.5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZu3F1o1nwx3hwU53_3F5vlxfX-TtQXadDwTSA1qgMCLLpeRMpNfHE1UmcbYR672ch51wxNmcY1j4d4HcnlOkwC57Z-BygH81Z_q6me3D4mgi_pq5_dqLuWX_x8JIPyuDLrnNFvkBQqKxP/s1600/1.3.5.PNG" height="190" width="400" /></a></div>
<div class="separator" style="clear: both;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">Hurray!!!!! You can remote debug your driver on target computer right now!</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">[Reference]</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">1. http://blog.csdn.net/iceamber2012/article/details/18809813</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;">2. http://blog.csdn.net/iceamber2012/article/details/17963649</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-size: large;"><br /></span></div>
<br />ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-35742470991766982702014-01-09T05:04:00.002-08:002014-01-09T05:05:08.659-08:00Write your own system call<div class="MsoNormal">
<span lang="EN-US">Linux Version 2.6.35.4<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">(CentOS)<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-US">目錄前的Linux代表kernel source code的根目錄</span></div>
<div class="MsoNormal">
<span lang="EN-US">我的Linux= /usr/src/kernels/linux-2.6.35.4</span></div>
<div class="MsoNormal">
<span lang="EN-US"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><u><span lang="EN-US">A.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">加一個自己的</span></u><span lang="EN-US"><u>system call</u><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l1 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US">1.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">新增一筆</span><span lang="EN-US">syscall service
routine name</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">到</span> <span lang="EN-US">syscall table</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中</span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">Linux/arch/x86/kernel/syscall_table_32.S </span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中加</span> <span lang="EN-US">“.long sys_process_switch_info”<o:p></o:p></span></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">當</span><span lang="EN-US">syscall call</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">發生時</span><span lang="EN-US">kernel</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">會到此</span><span lang="EN-US">table</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中找到對應的</span><span lang="EN-US">service routine name<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuVdvXx3-UzTvbpaVJbI_C683P2oysoHWMoaKzGw-GnewW4QFNz0EU0Tqh8UYmC1nXMAR_Drpj5SXPCKUafTZ48rjO8LVP9cdUIUCmz769ZoMAFnjrTIO7721IyUw3FzgRF9OAlbC7Alhr/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuVdvXx3-UzTvbpaVJbI_C683P2oysoHWMoaKzGw-GnewW4QFNz0EU0Tqh8UYmC1nXMAR_Drpj5SXPCKUafTZ48rjO8LVP9cdUIUCmz769ZoMAFnjrTIO7721IyUw3FzgRF9OAlbC7Alhr/s1600/1.png" height="287" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US">2.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">定義</span><span lang="EN-US">syscall number<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">Linux/arch/x86/include/asm/unistd_32.h<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">把新的</span><span lang="EN-US">number</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">加上去,並將</span><span lang="EN-US">__NR_syscalls +1<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">(__NR_syscalls</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">代表</span><span lang="EN-US">maximum</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的</span><span lang="EN-US">syscalls number)<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLGeY4oAWQxEC_BrdKWdwCiMzat69TKfwQJosT2D2EVijD5H9H-xlzYtVibctRNcOrKdqDNAhLmi4J2mqwZCJD_BW6V8sWbxR-Aek_h6aXbPpSiqFGkm9cJ7NIdLDeQUig86qmvWzgBD6V/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLGeY4oAWQxEC_BrdKWdwCiMzat69TKfwQJosT2D2EVijD5H9H-xlzYtVibctRNcOrKdqDNAhLmi4J2mqwZCJD_BW6V8sWbxR-Aek_h6aXbPpSiqFGkm9cJ7NIdLDeQUig86qmvWzgBD6V/s1600/2.png" height="260" width="400" /></a></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US">3.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">定義</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的</span><span lang="EN-US">prototype<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">Linux/include/syscalls.h </span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">這裡定義所有的</span><span lang="EN-US">syscall
prototype<o:p></o:p></span></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">(asmlinkage</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是一種語法,用來與不同</span><span lang="EN-US">compiler</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">間溝通</span><span lang="EN-US">)<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzG3A_eqkX25_qTaoyioVyEDWdPU59SYH-KLobfgEyVbEG_an1R0kM1NWcshDW54RuDYXyKV60jk1NIpL0JUPUObQsm8O1mYBr8HVYtpn37YeRhIt2R0_u-fwGXeUtjN164iwTdnoLFLdE/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzG3A_eqkX25_qTaoyioVyEDWdPU59SYH-KLobfgEyVbEG_an1R0kM1NWcshDW54RuDYXyKV60jk1NIpL0JUPUObQsm8O1mYBr8HVYtpn37YeRhIt2R0_u-fwGXeUtjN164iwTdnoLFLdE/s1600/3.png" height="267" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<span lang="EN-US" style="text-indent: -18pt;">4.<span style="font-size: 7pt;">
</span></span><span lang="EN-US" style="text-indent: -18pt;">Syscall </span><span style="font-family: 新細明體, serif; text-indent: -18pt;">真正的</span><span lang="EN-US" style="text-indent: -18pt;">code</span><br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">此</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中我自己定義的一個</span><span lang="EN-US">structure (</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">在這裡不重要</span><span lang="EN-US">)<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">真正的</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">從</span><span lang="EN-US">SYSCALL_DEFINE[0-6](….)</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">開始</span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">SYSCALL_DEFINE</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可以接受</span><span lang="EN-US">0</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">到</span><span lang="EN-US">6</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">個參數</span><span lang="EN-US">, </span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">第一個參數是</span><span lang="EN-US">SYSCALL NAME</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">不算在內。定義形式是這樣的</span><span lang="EN-US">:<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<b><span lang="EN-US" style="color: red;">SYSCALL_DEFINE[</span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">參數個數</span><span lang="EN-US" style="color: red;">](SYSCALL NAME, </span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">參數</span><span lang="EN-US" style="color: red;">1</span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">型態</span><span lang="EN-US" style="color: red;">, </span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">參數</span><span lang="EN-US" style="color: red;">1, </span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">參數</span><span lang="EN-US" style="color: red;">2</span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">型態</span><span lang="EN-US" style="color: red;">,</span></b><b><span style="color: red; font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">參數</span><span lang="EN-US" style="color: red;">2….)<o:p></o:p></span></b></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: 新細明體, serif;">因為我的</span><span lang="EN-US">syscall</span><span style="font-family: 新細明體, serif;">只有一個型態為</span> <span lang="EN-US">process_switch_info*</span><span style="font-family: 新細明體, serif;">的參數</span><span lang="EN-US"> psi, </span><span style="font-family: 新細明體, serif;">因此我是</span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">SYSCALL_DEFINE</span><b><span lang="EN-US" style="color: #c0504d; mso-themecolor: accent2;">1(……)<o:p></o:p></span></b></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">(</span><span style="font-family: 新細明體, serif;">若沒有參數的話在第</span><span lang="EN-US">3</span><span style="font-family: 新細明體, serif;">步裡面參數地方要寫</span><span lang="EN-US">void</span><span style="font-family: 新細明體, serif;">不然會有錯</span><span lang="EN-US">)<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvuyD4S3kjjCmCJWFjgMWesQBqdGYE20Vusf721YEoCYhdlfprpdmrkv8aqXsUC7KPoNNN22Tpr_r2kOWd3IPSyLdp_bqJ6u0DicPUEZKPYQY5e7JhiH_OqxJNQ3OaqWfdng99y4rQOS8i/s1600/6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvuyD4S3kjjCmCJWFjgMWesQBqdGYE20Vusf721YEoCYhdlfprpdmrkv8aqXsUC7KPoNNN22Tpr_r2kOWd3IPSyLdp_bqJ6u0DicPUEZKPYQY5e7JhiH_OqxJNQ3OaqWfdng99y4rQOS8i/s1600/6.png" height="198" width="400" /></a></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span lang="EN-US">5.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">加入</span><span lang="EN-US">Makefile(</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">把</span><span lang="EN-US">object</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">檔放入</span> <span lang="EN-US">source code tree</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中</span><span lang="EN-US">)<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">Linux/kernel/Makefile<o:p></o:p></span></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">(</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">新增的</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">放在哪一層,就加在該層的</span><span lang="EN-US">Makefile</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中</span><span lang="EN-US">)<o:p></o:p></span></div>
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-fqiIuFyxJ9D3JT9nkPIFKsbZI4SaKUjBYwwCdRScPTTu8vJOC2eriHd6zwuOrOAT7aRePVbDC8eGDg0TkJ50iv7iViPUPV2gTsV9oymdEj0WEpDyj0lfRnA7YYpMv-2uWue2vz5TmzFk/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-fqiIuFyxJ9D3JT9nkPIFKsbZI4SaKUjBYwwCdRScPTTu8vJOC2eriHd6zwuOrOAT7aRePVbDC8eGDg0TkJ50iv7iViPUPV2gTsV9oymdEj0WEpDyj0lfRnA7YYpMv-2uWue2vz5TmzFk/s1600/4.png" height="263" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span lang="EN-US">6.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">重編</span><span lang="EN-US">kernel<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">make <o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">make modules_install<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">make install<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l1 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><u><span lang="EN-US">B.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">測試</span></u><span lang="EN-US"><u>system call</u><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l0 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US">1.<span style="font-size: 7pt;">
</span></span><!--[endif]--><span lang="EN-US">syscall(__NR_process_switch_info,
psi)</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是呼叫</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的方法</span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">第一個參數為</span><span lang="EN-US">syscall name, </span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">後面的參數放該</span><span lang="EN-US">syscall</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">所需的參數</span><span lang="EN-US"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US">
</span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可以直接寫在</span><span lang="EN-US">.c</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中,這裡定義了</span><span lang="EN-US">get_process_switch_info()</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">讓</span><span lang="EN-US">.c</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">中的</span><span lang="EN-US">function name</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">有意義,因此傳了一個自訂的</span><span lang="EN-US">structure</span><span style="font-family: "新細明體","serif"; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">進來才呼叫</span><span lang="EN-US">syscall<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAY-5YI1uWcTDrubXQrD7C3SrtITZhBO6E3aPTAb9zfRKpabjxqepfqEbJgnYIboYxMy5Ax7ZotLldUHmywwmoB6oYZpUR7dbBiVXRZgRYQEckTAsR4NUKuY8GQVqwXlI-8vV4aRYMtN18/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAY-5YI1uWcTDrubXQrD7C3SrtITZhBO6E3aPTAb9zfRKpabjxqepfqEbJgnYIboYxMy5Ax7ZotLldUHmywwmoB6oYZpUR7dbBiVXRZgRYQEckTAsR4NUKuY8GQVqwXlI-8vV4aRYMtN18/s1600/5.png" height="263" width="400" /></a></div>
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><br /></span></div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-26017442533141955632014-01-05T00:27:00.006-08:002014-01-05T00:28:46.697-08:00Ftrace 追蹤kernel process為了確認process到底是怎麼context switch以及context switch幾次,花了些時間研究了Ftrace。有些地方仍不是很了解,要再查資料研究<br />
Linux version : 2.6.35.4 (CentOS)<br />
<br />
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">1.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Ftrace </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是內建的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">tracker</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">,在編譯核心時可以到選單裡的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><kernel hacking></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">選擇</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> (</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">因為不太熟悉各選項的用途,因次我全選了</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">= _=)<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span style="font-size: 14pt;">2. </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">選完後開始編譯</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">
</span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="color: orange;"><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">make </span><span lang="EN-US" style="font-family: Wingdings; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;">à</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> make modules_install
</span><span lang="EN-US" style="font-family: Wingdings; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;">à</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> make install </span><span lang="EN-US" style="font-family: Wingdings; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;">à</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">reboot</span></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<span lang="EN-US"><span style="font-size: 19px;">3.</span><span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">到</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">/sys/kernel/debug , </span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">將</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">debugfs mount</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">上去</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">
</span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># mount –t debugfs
nodev /sys/kernel/debug </span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">4.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">現在可以到</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">/sys/kernel/debug/tracing</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">下</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">會看到一大堆檔案</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">
</span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可以查看</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">available_tracers </span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">看看有那些</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">tracer</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可以用</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAugPjksxuFIhTr0qrmx6MzHF7wSRj4IIOZbr4Ub53ZdNVNBdqxk-zPEWJbSpx6vktG2ms3wm5m2rYNWpjODTqb1lCk-8x-EZkaSykr_hvolpmeayUNxpR4emd_-Q-WpkYRS_WGUkErqFU/s1600/available_tracers.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjAugPjksxuFIhTr0qrmx6MzHF7wSRj4IIOZbr4Ub53ZdNVNBdqxk-zPEWJbSpx6vktG2ms3wm5m2rYNWpjODTqb1lCk-8x-EZkaSykr_hvolpmeayUNxpR4emd_-Q-WpkYRS_WGUkErqFU/s1600/available_tracers.png" height="72" width="640" /></a></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">5.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">使用</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">tracer</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的步驟</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(a)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">關閉</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">tracing_enabled (0</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">closed, 1 </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">opened)<o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo 0 >
tracing_enabled</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(b)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">打開</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">ftraced_enabled (</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">不太清楚原因</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo 1 >
/proc/sys/kernel/ftrace_enabled</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(c)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">選擇目前要用的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">tracer<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo … >
current_tracer</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(d)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">設定要跟蹤的函數到</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">set_ftrace_filter<o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo … >
set_ftrace_filter</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(e)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">打開</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">tracing enabled <o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo 1 >
tracing_enabled</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(f)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">執行想要追蹤的程式或做其他事</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">, ftrace</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">會開始追蹤</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">kernel <o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(g)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">結束追蹤</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo 0 >
tracing_enabled</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">或暫停追蹤</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">(tracer</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">只是暫停沒有結束</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># echo 0 >
tracing_on</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(h)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">看結果囉</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">!<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># cat trace</span><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可以搭配</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">grep</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">指令列出想看的東西</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># cat trace |
grep test </span>(test</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">是我剛剛執行的執行檔</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">)<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">或是</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> >> </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">將</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">trace</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">輸出成自己的檔案</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
</div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span style="color: orange;"># cat trace
>> /trace1</span> (</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">輸出到跟目錄下</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">檔名為</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">trace1)<o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><span lang="EN-US"><br /></span></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">6.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">我這一次觀察了</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">2</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">種</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">tracer<o:p></o:p></span></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l1 level1 lfo2; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(a)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Function<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">會列出</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">function</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">執行的順序</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">下圖是我執行</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">test </span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">之後的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">tracer, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">我有用</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">
<span lang="EN-US">filter</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">鎖定我要看的函數</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">也就是主要做</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">context_switch</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">schedule</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">了</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">欄位意思大概是這樣</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; margin-left: 36.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">TASK-PID<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Cpu#<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">TIMESTAMP<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">FUNCTION<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><test>-5049<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">000<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">13211.469334<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Schedule</span><span lang="EN-US" style="font-family: Wingdings; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-char-type: symbol; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-symbol-font-family: Wingdings;">ß</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">work_resched<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Process test pid
5049</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">正在執行</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">使用編號</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">0</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">CPU, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">時間是</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">timestamp, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">正由</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">work_resched</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">呼叫</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">schedule function<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
</div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">看樣子應該是準備進行</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">contest switch</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">了</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjCk4JWh4CCwjA1kr4vhhVn2Um3OzSP7pCZbaPot2rWP87e7zqIRQ1g2KCNNsjzcThoRl1x9r46L4YQF32bfQqgJSa90buETr2p6oKMygea7txw9_FbzhrD8LUHIVi4kSx6PCyn1ZLIIff/s1600/function.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjCk4JWh4CCwjA1kr4vhhVn2Um3OzSP7pCZbaPot2rWP87e7zqIRQ1g2KCNNsjzcThoRl1x9r46L4YQF32bfQqgJSa90buETr2p6oKMygea7txw9_FbzhrD8LUHIVi4kSx6PCyn1ZLIIff/s1600/function.png" height="228" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">我的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">test</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">就是會讓他睡</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">次的一支程式</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">(</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">作業需要</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">XD)<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">所以可以看到</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">8</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">個</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">nanosleep</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">呼叫</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">schedule</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">準備把控制權交出來然後去睡覺</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">(a)<span style="font-size: 7pt;"> </span></span><!--[endif]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Sched_switch<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">列出</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">context switch</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">info<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">下圖是使用</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">sched_switch</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">看</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">process </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">做</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">context switchc</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">的情況</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">我用</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> <span lang="EN-US">grep test </span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">過濾出我想看的</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">, </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">欄位意思大概是</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: none; margin-left: 36.0pt; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr>
<td style="border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">TASK-PID<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Cpu#<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">TIMESTAMP<o:p></o:p></span></div>
</td>
<td style="border-left: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">FUNCTION<o:p></o:p></span></div>
</td>
</tr>
<tr>
<td style="border-top: none; border: solid windowtext 1.0pt; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><test>-5182<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.5pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">000<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">14456.847013<o:p></o:p></span></div>
</td>
<td style="border-bottom: solid windowtext 1.0pt; border-left: none; border-right: solid windowtext 1.0pt; border-top: none; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0cm 5.4pt 0cm 5.4pt; width: 104.55pt;" valign="top" width="139">
<div class="MsoListParagraph" style="margin-left: 0cm; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">(*)<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">(*): 5182:120:S
== > [000] 0:120:R <idle><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"> pid 5182, priority 120,</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">目前狀態</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">S</span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">代表</span><span style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">
<span lang="EN-US">TASK_INTERRUPTIBLE</span></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可中斷睡眠狀態</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
</div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">== ></span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">代表轉移控制權</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">( + </span><span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;">可能是代表正在叫醒某</span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Process)<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjA_LqqfhyFoYlyOd0bKBFyfA2ZTdMErWpoBXJCSlfZSEJUupMxx8W0sGTvIqAwv0Uy5Tw_-KoskGlOdFL1lV1Ka1282wgCmSG7fb_f8w2P1P_hTrpHyrhkOoljZhut3AzKYc71JlNbEtA/s1600/sched_switch.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjA_LqqfhyFoYlyOd0bKBFyfA2ZTdMErWpoBXJCSlfZSEJUupMxx8W0sGTvIqAwv0Uy5Tw_-KoskGlOdFL1lV1Ka1282wgCmSG7fb_f8w2P1P_hTrpHyrhkOoljZhut3AzKYc71JlNbEtA/s1600/sched_switch.png" height="305" width="640" /></a></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><br /></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-list: l0 level1 lfo1; mso-para-margin-left: 0gd; text-indent: -18.0pt;">
<!--[if !supportLists]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-family: Calibri; mso-bidi-font-size: 11.0pt; mso-bidi-theme-font: minor-latin; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin;">7.<span style="font-size: 7pt;"> </span></span><!--[endif]--><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;">Reference<o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><a href="http://www.ibm.com/developerworks/cn/linux/l-cn-ftrace2/">http://www.ibm.com/developerworks/cn/linux/l-cn-ftrace2/</a><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><a href="http://jayiist.blog.163.com/blog/static/18715931120122555631948/">http://jayiist.blog.163.com/blog/static/18715931120122555631948/</a><o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="MsoListParagraph" style="margin-left: 18.0pt; mso-para-margin-left: 0gd;">
<span lang="EN-US"><a href="http://events.linuxfoundation.org/slides/2010/linuxcon_japan/linuxcon_jp2010_rostedt.pdf">http://events.linuxfoundation.org/slides/2010/linuxcon_japan/linuxcon_jp2010_rostedt.pdf</a></span><span lang="EN-US" style="font-size: 14.0pt; mso-bidi-font-size: 11.0pt;"><o:p></o:p></span></div>
<div class="MsoListParagraph" style="margin-left: 36.0pt; mso-para-margin-left: 0gd;">
<span style="font-family: "新細明體","serif"; font-size: 14.0pt; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-bidi-font-size: 11.0pt; mso-fareast-font-family: 新細明體; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin;"><br /></span></div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-50888959078612425902013-10-20T18:51:00.003-07:002013-10-21T07:32:31.888-07:00week4- 形容詞&副詞子句應用module 1:<br />
I live in Taiwan, <u>which has plenty of delicious food and beautiful landscapes</u>. <u>Although Taiwan is a tiny </u><u>island surrounded by ocean</u>, it is still abundant in natural resources. <u>Due to the limitation of ground </u><u>where people can live</u>, the cities in Taiwan usually have high population. Therefore, the culture of night market grows rapidly in Taiwan such that people can enjoy a variety of small eats <u>even though it's midnight</u>. "Taipei travel essentials: passport, cash, extra stomach", <u>which CNN had published before</u>, recommends 40 Taiwanese foods we can't live without. For instance, Bubble tea, <u>the most fabulous drink with tapioca balls</u>, is one of the most representative small food in Taiwan. <u>Except for small food</u>, Taiwanese also wins reputation of being hospitable and enthusiastic. You can experience our enthusiasm <u>wherever you go</u>, so come and visit our beautiful island, Taiwan.<br />
<br />
module 2 :<br />
<u>In my opinion</u>, natural disasters are a huge disadvantage of Taiwan. One of natural disasters is typhoon, <u>consisting of a tropical cyclone</u>. In summer, typhoons, <u>bringing an enormous rainfall and a strong breeze</u>, will come and cause a serious damage to our crops. <u>On account of the damage</u>, our agricultural economic losses hundreds of million dollars each year.<u> Besides, concerning about the shortage of fruits and vegetables</u>, people will buy lots of food before the coming of typhoon,<u> leading to a rise of food prices</u>. Furthermore, villages beside the mountains will risk losing their houses<u> due to mudflows and landslides</u>. <u>To ensure security of residents</u>, government will withdraw all of them by a strong hand to the safer place. Another natural disaster is earthquake,<u>known for its unpredictable occurrence and intense destructive power</u>. People cannot run out of the house immediately <u>while earthquake occurs</u>.<u>When it comes to an huge earthquake</u>, the ground will rumble <u>with house shaking violently</u>. Few seconds later, the houses will collapse rapidly that almost no one can survive. Natural disasters are unavoidable, the most important thing to do is <u>to reduce the damages as best as we can</u>.ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-17067497189032505882013-10-13T18:40:00.004-07:002013-10-14T01:58:54.751-07:00Week3module1:<br />
<b>This restaurant</b> is famous for its seafood and well-serviced quality.<b>Customers</b> have to make a reservation before dining.<b>There</b> are many kinds of seafood on the menu,such as fried-shrimps,roasted-lobster, and steamed-fish.<b>Everyone</b> enjoys their meals there. Due to the fresh seafood and its low price,<b> this restaurant</b> gains high popularity in this small town.<br />
<br />
module2: (underline action verbs)<br />
<b>This restaurant</b> is famous for its seafood and well-serviced quality.<b>Customers</b> have to<u> make</u> a reservation before dining.<b>There</b> are many kinds of seafood on the menu,such as fried-shrimps,roasted-lobster, and steamed-fish.<b>The main chef </b>strongly<u> recommends</u> the roasted-lobster with butter for main course.<b> The lobster </b>with fragrant butter <u>tastes</u> delicious that everyone enjoys it there. Due to the fresh seafood and its low price,<b> this restaurant</b><u> gains</u> high popularity in this small town.<br />
<br />
Assignment (improvement) :<br />
<div class="MsoNormal">
<b><span lang="EN-US" style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;">This restaurant</span></b><span lang="EN-US" style="background: white; color: #222222; font-family: "Arial","sans-serif"; font-size: 10.0pt;"> is famous for
its seafood and well-serviced quality. <b>There</b> always has a long line of people outside the door, waiting
for tasting seafood expectantly. <b>Customers</b> have better to<span class="apple-converted-space"><u> </u></span><u>make</u><span class="apple-converted-space"> a
reservation before dining.</span> <b>There</b> are many kinds of seafood on the menu, such as
fried-shrimps, roasted-lobster, and steamed-fish. <b>The main chef<span class="apple-converted-space"> </span></b>strongly<span class="apple-converted-space"><u> </u></span><u>recommends</u><span class="apple-converted-space"> the
roasted-lobster with butter for main course due to its freshness.<span class="apple-converted-space"><b> </b></span><b>The lobster<span class="apple-converted-space"> </span></b>with fragrant butter<span class="apple-converted-space"> </span><u>tastes</u><span class="apple-converted-space"> delicious that
everyone enjoys it there. Due to the fresh seafood and its low price,</span><b> this restaurant</b><u> gains</u><span class="apple-converted-space"> higher
and higher popularity in this small town.</span> Therefore, </span><b><span lang="EN-US" style="background-position: initial initial; background-repeat: initial initial; color: black; font-size: 10pt;">the </span></b><span lang="EN-US" style="background-position: initial initial; background-repeat: initial initial; color: black; font-size: 10pt;">local<b> tourism</b></span><span lang="EN-US" style="background-position: initial initial; background-repeat: initial initial; font-size: 10pt;"> also<u> gets</u> stronger and <u>brings</u> economic
recovery of the town.</span><span lang="EN-US"><o:p></o:p></span></span></div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-55661807955244061822013-09-01T03:27:00.002-07:002013-09-01T03:28:07.612-07:00Linux Device Driver - IOCTL (copy_to_user & copy_from_user)在 linux/include/linux/fs.h 中定義許多file operation能用的handler<br />
這一次<span style="color: red;">我針對的是 read、ioctl做練習</span><br />
file operation中沒實做到的handler會被定義成NULL<br />
這一支程式會先得到來自kernel的回應,接著kernel 換更改指定的數字<br />
<br />
先大概說一下主要概念<br />
我要先寫一個mydev.c 當作 driver<br />
執行完make 之後 就把 mydev.ko 加入到 kernel中<br />
此時的 mydev.ko 就是模組, 一個在kernel中的模組了<br />
那要如何與此模組互動呢?<br />
我要再寫一個 test_mydev.c 當作 user<br />
直接把他 gcc 產生執行檔 再指定我要跟mydev 模組溝通<br />
<br />
首先先來看 ioc.h<br />
這裡定義了 user 能夠透過 ioctl 傳達的指令<br />
<span style="color: red;">IOC_MAGIC 是device 的 major number </span>, 而我定義其major number為 k<br />
每一個裝置都有其major number 與 minor number<br />
接著我<span style="color: red;">設置 SETNUM GETNUM XNUM</span> 3種指令<br />
<span style="color: red;">_IOW _IOR _IOWR 是 kernel 的巨集 </span>, 我們用這3個巨集來定義我們的命令要做哪些事<br />
各聚集裡的1,2,3 是自訂的minor number<br />
<br />
<code>
#ifndef IOC_H<br />
#define IOC_H<br /><br />
#define IOC_MAGIC 'k'<br />
#define SETNUM _IOW(IOC_MAGIC, 1 , int)<br />
#define GETNUM _IOR(IOC_MAGIC, 2 , int)<br />
#define XNUM _IOWR(IOC_MAGIC,3 , int)<br />
#define IOC_MAXNR 3<br /><br />
#endif<br />
</code>
<br />
<br />
接著看到最主要的 driver code : mydev.c<br />
在file operations 中定義了我自訂的操作函數<br />
<b><span style="color: red;">dev_open</span></b> : 在user open device file 時會被呼叫<br />
<b><span style="color: red;">dev_close</span></b> : 在user close device file 時會被呼叫<br />
<b><span style="color: red;">dev_ioctl</span></b> : switch case 中寫了各種command該執行的動作<br />
若user 呼叫 ioctl 時傳入 SETNUM 則 driver 會將傳入的資料(args)取出,並指定給val 變數<br />
若user 呼叫 ioctl 時傳入 GETNUM 則 driver 會將val 變數傳出(args)<br />
若user 呼叫 ioctl 時傳入XNUM 則 driver 會將 user 輸入的數值指派給val變數達到更改資料<br />
的目的<br />
(因為user space 與 kernel space 儲存data的空間不同, 因此要用 copy_to_user 與<br />
copy_from_user來轉遞資料)<br />
<b><span style="color: red;">dev_read</span></b> : user 呼叫 read時會被呼叫, 我在這裡放了一個hello字串, kernel會利用copy_to_user 傳到<br />
buffer中給user<br />
<b><span style="color: red;">dev_write</span></b>: 我在這裡沒用到<br />
<b><span style="color: red;">init_modules:</span></b> 程式進入點 , 建立裝置並註冊到kernel<br />
<b><span style="color: red;">exit_modules</span></b>: 程式結束 , 移除裝置<br />
<br />
<code>
#include <linux/init.h><br />
#include <linux/module.h><br /><br />
#include <linux/fs.h> //chrdev<br />
#include <linux/cdev.h> //cdev_add() / cdev_del()<br /><br />
#include <asm/uaccess.h> //copy_*_user()<br /><br />
#include "ioc.h"<br /><br />
MODULE_LICENSE("GPL");<br />
MODULE_AUTHOR("IRENE 2013/09/01");<br />
#define DEV_BUFSIZE 1024<br /><br />
static int dev_major;<br />
static int dev_minor;<br />
struct cdev *dev_cdevp = NULL;<br />
static int dev_open(struct inode*, struct file*);<br />
static int dev_release(struct inode*, struct file*);<br />
static int dev_ioctl(struct inode*, struct file*, unsigned int, unsigned long);<br />
ssize_t dev_read(struct file*, char __user*, size_t, loff_t*);<br />
ssize_t dev_write(struct file*, char __user*, size_t, loff_t*);<br />
static void __exit exit_modules(void);<br /><br />
//Functions on the right side are the handler we just defined<br />
struct file_operations dev_fops = {<br /> .owner = THIS_MODULE,<br /> .open = dev_open,<br /> .release= dev_release,<br /> .ioctl = dev_ioctl,<br /> .read = dev_read,<br /> .write = dev_write<br />
};</code><br />
<code><br />
// dev_open will be Called when user open the device file<br />
static int dev_open(struct inode *inode, struct file *filp)<br />
{<br /> printk("%s():\n",__FUNCTION__);<br /> return 0;<br />
}<br /><br />
// dev_release will be Called when user close the device file<br />
static int dev_release(struct inode *inode, struct file *filp)<br />
{<br /> printk("%s():\n",__FUNCTION__);<br /> return 0;<br />
}<br /><br />
// mainly io control between user and kernel<br />
// args are pointed to user space's buffer<br />
static int val = 0;<br />
static int dev_ioctl(struct inode *inode, struct file *filp,<br />
unsigned int cmd, unsigned long args)<br />
{<br /> int tmp, err=0,ret=0;<br /><br /> if(_IOC_TYPE(cmd) != IOC_MAGIC)<br /> return -ENOTTY;<br /> if(_IOC_NR(cmd) > IOC_MAXNR)<br /> return -ENOTTY;<br /> if(_IOC_DIR(cmd) & _IOC_READ){<br /> err = !access_ok(VERIFY_WRITE, (void __user*)args, _IOC_SIZE(cmd));<br /> } else if (_IOC_DIR(cmd) & (_IOC_WRITE)){<br /> err = !access_ok(VERIFY_READ, (void __user *)args,_IOC_SIZE(cmd));<br /> }<br /><br /> if (err)<br /> return -EFAULT;<br /><br /> switch (cmd) {<br /> case SETNUM:<br /> //copy data from args(user) to val(kernel)<br /> if(copy_from_user(&val,(int __user *)args,1))<br /> return -1;<br /><br /> printk("%s():get val from user = %d\n",__FUNCTION__,val);<br /> break;<br /> case GETNUM:<br /> //copy data from val to args<br /> if(copy_to_user((int __user *)args,&val,1))<br /> return -1;<br /><br /> printk("%s():set val to %d\n",__FUNCTION__, val);<br /> break;<br /> case XNUM:<br /> // exchange data passed by user<br /> tmp = val;<br /> if(copy_from_user(&val,(int __user *)args,1))<br /> return -1;<br /><br /> if(copy_to_user((int __user *)args,&val,1))<br /> return -1;<br /><br /> printk("%s():change val from %d to %d\n",__FUNCTION__,tmp,val);<br /> break;<br /><br /> default: /* redundant. as cmd was checked against MAXNR */<br /> return -ENOTTY;<br /> }<br /> return 0;<br />
}</code><br />
<code><br />
static const char str[]="Hello Irene from kernel!";<br />
static const ssize_t str_size = sizeof(str);<br />
// send messages to user<br />
ssize_t dev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)<br />
{<br /><br /> printk("%s():\n",__FUNCTION__);<br /><br /> if( *f_pos >= str_size)<br /> return 0;<br /> if( *f_pos + count > str_size)<br /> count = str_size - *f_pos;<br /> if (copy_to_user(buf, str + *f_pos, count))<br /> return -EFAULT;<br /> *f_pos += count;<br /> return count;<br /><br />
}<br /><br />
ssize_t dev_write(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)<br />
{<br /> printk("%s():\n",__FUNCTION__);<br /> return 0;<br />
}<br /><br />
static int __init init_modules(void)<br />
{ </code><br />
<code> dev_t dev;<br /> int ret;<br /> // get major number dynamically<br /> ret = alloc_chrdev_region(&dev, 0, 1, "mydev");<br /> if (ret <0){<br /> printk("can't alloc chrdev\n");<br /> return ret;<br /> }<br /> dev_major = MAJOR(dev);<br /> dev_minor = MINOR(dev);<br /> printk("register chrdev(%d,%d)\n",dev_major,dev_minor);<br /><br /> dev_cdevp = kmalloc(sizeof(struct cdev), GFP_KERNEL);<br /> if (dev_cdevp == NULL){<br /> printk("kmalloc failed\n");<br /> goto failed;<br /> }<br /> // system call handler<br /> cdev_init(dev_cdevp, &dev_fops);<br /> dev_cdevp->owner = THIS_MODULE;<br /> //register my device to kernel<br /> ret = cdev_add(dev_cdevp, MKDEV(dev_major, dev_minor),1);<br /> if(ret < 0){<br /> printk("add chr dev failed\n");<br /> goto failed;<br /> }<br /> return 0;<br /><br />
failed:<br /> if(dev_cdevp) {<br /> kfree(dev_cdevp);<br /> dev_cdevp = NULL;<br />
}<br /> return 0;<br />
}</code><br />
<code><br />
static void __exit exit_modules(void)<br />
{<br /> dev_t dev;<br /> dev = MKDEV(dev_major, dev_minor);<br /> if (dev_cdevp){<br /> cdev_del(dev_cdevp);<br /> kfree(dev_cdevp);<br /> }<br /> unregister_chrdev_region(dev,1);<br /> printk("unregister chrdev\n");<br />
}<br /><br />
module_init(init_modules);<br />
module_exit(exit_modules);<br />
</code><br />
<br />
接著 是 user 端部分啦 test_mydev.c<br />
執行時要輸入的參數有 devicefile num<br />
device file 就是 在 /dev下的裝置檔名<br />
num 是 XNUM命令時要change的value (default 是 10 )<br />
首先利用 open 打開 device file<br />
然後<span style="color: red;"> read(fd, buffer, sizeof(buffer));</span><br />
buffer 是 user 拿來放kernel 回傳值的地方<br />
此時kernel 會回傳 Hello Irene from kernel!<br />
接著 user 開始下達 ioctl command<br />
--><span style="color: red;"> ioctl(fd, SETNUM, &ret)</span><br />
這是其中一個例子 , SETNUM 便是user 下達的command<br />
而&ret 是 回傳值的指標<br />
<br />
<code>
#include <stdio.h><br />
#include <sys/ioctl.h><br />
#include <sys/types.h><br />
#include <sys/stat.h><br />
#include <fcntl.h><br />
#include "ioc.h"<br />
<br />
int main(int argc, char *argv[])<br />
{<br />
int fd, ret=10;<br />
unsigned char buffer[50]={};<br />
if(argc < 2)<br />
{ <br />
printf("Usage: /dev/mydev param1.. \n"); <br />
return -1;<br />
}<br />
// open dev file<br />
fd=open(argv[1], O_RDWR);<br />
if(fd < 0)<br />
{<br />
printf("open %s failed\n", argv[1]);<br />
return -1;<br />
}<br />
//read from kernel <br />
read(fd, buffer, sizeof(buffer));<br />
printf("%s\n",buffer);<br />
// set num to 10<br />
if (ioctl(fd, SETNUM, &ret)< 0)<br />
{<br />
printf("set num failed\n");<br />
return -1;<br />
}<br />
if(ioctl(fd, GETNUM , &ret)< 0)<br />
{<br />
printf("get num failed\n");<br />
}<br />
printf("get default value=%d\n",ret);<br />
// exchange number
ret =atoi(argv[2]); <br />
if (ioctl(fd, XNUM, &ret)<0)<br />
{<br />
printf("exchange num failed\n");<br />
return -1;<br />
}<br />
printf("get value = %d\n",ret);<br />
return 0;<br />
}
</code><br />
<br />
最後是 Makefile<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2wGEGPDsOGhTErhHTSHv9eZLkCPIsifjOJiryALqsTUs4I74a0Vxcun4Me4w7BMowIj9Uv3wTU-Jb_ZjqdjmvrEiDpgEWwZ4jj-v1QH24pvkmAniWYeMWJI6rRPjg1F-lHOmUtV-fvIZK/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2wGEGPDsOGhTErhHTSHv9eZLkCPIsifjOJiryALqsTUs4I74a0Vxcun4Me4w7BMowIj9Uv3wTU-Jb_ZjqdjmvrEiDpgEWwZ4jj-v1QH24pvkmAniWYeMWJI6rRPjg1F-lHOmUtV-fvIZK/s1600/1.png" height="98" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
上面全部的檔案都存在mydev 資料夾中<br />
/usr/src/kernels/linux-2.6.18/mydev/..<br />
<br />
開始執行<br />
make 之後的指令如下<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggKW8XQcllTTHUzhiTsqQNCK0FE_DDUNuLxQa5qJAIHNu8MhvcCQP7eHLAB0QpJOnZ7gnSGfCrxmYdk0d9oMxH4CQXOqclqXVjZDrmwsnda7HW6_JuZ4b28VtNQXQB5sHr_UTf-s81UvQY/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggKW8XQcllTTHUzhiTsqQNCK0FE_DDUNuLxQa5qJAIHNu8MhvcCQP7eHLAB0QpJOnZ7gnSGfCrxmYdk0d9oMxH4CQXOqclqXVjZDrmwsnda7HW6_JuZ4b28VtNQXQB5sHr_UTf-s81UvQY/s1600/2.png" height="163" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="color: red;">在 insmod之後 dev會被賦予 major number 與 minor number </span><br />
開啟新的cmd 執行dmesg就可以看到kernel傳來一條msg<br />
register chrdev(252,0)<br />
或是可以到 /proc/devices中查看 major number 與 minor number<br />
在mknod時一定要給定對的major 與 minor number<br />
否則會有 找不到 file 的錯誤<br />
執行後可以看到<br />
kernel 傳回一條 hello messages<br />
而kernel也將預設為10 的value改為 user 設定的 100<br />
最後dmesg中可以看到kernel的訊息<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk1dKL-1AXFhiKa0LycmlmxSsxqq-zZFAvu7gmvZEwQKyIHak41oeZhda1XZM9gSUOKob1l87WSJttVTUIrZTlvXCYPvs3Ho88k5DF87p5o7XuFPio45hKrl1N430xF9N-JLNHO3peGTHW/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjk1dKL-1AXFhiKa0LycmlmxSsxqq-zZFAvu7gmvZEwQKyIHak41oeZhda1XZM9gSUOKob1l87WSJttVTUIrZTlvXCYPvs3Ho88k5DF87p5o7XuFPio45hKrl1N430xF9N-JLNHO3peGTHW/s1600/1.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
研究好多天仍有很多疑問, 有不完備之處之後繼續修改<br />
參考:<br />
<a href="http://csw17.pixnet.net/blog/post/11506143">http://csw17.pixnet.net/blog/post/11506143</a><br />
<a href="http://nano-chicken.blogspot.tw/2009/12/linux-modulesv-ioctl.html">http://nano-chicken.blogspot.tw/2009/12/linux-modulesv-ioctl.html</a><br />
<a href="http://www.codeproject.com/Articles/112474/A-Simple-Driver-for-Linux-OS">http://www.codeproject.com/Articles/112474/A-Simple-Driver-for-Linux-OS</a><br />
強烈建議大家在寫這個之前先到jollen的網站看相關的 device 觀念教學ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-80874627161580279472013-08-25T08:18:00.000-07:002013-08-25T08:18:29.590-07:00Linux Kernel Module 3 - command line argument1. 由command line傳入的value會被視為global<br />
2. 使用module_param() macro來加入變數<br />
3. 在runtime時, insmod會填入從command line輸入的value到相應的變數<br />
4. module_param()有3個params,依序為 變數名稱, 變數型態, 權限<br />
module_param(name, type, permission)<br />
目前支援的type有 <span style="background-color: white; font-family: tahoma, 'Trebuchet MS', lucida, helvetica, sans-serif; font-size: 13px; line-height: 18px;">byte, short, ushort, int, uint, long, ulong, charp, bool</span><br />
5.若要傳入array或string可以使用 module_param_array() or module_param_string()<br />
array的話在type之後要多一個count , module被載入的時候user所指定的array length會被fill到此變<br />
數中 , NULL也可以<br />
6. 使用 module_param_desc()則可以對某一變數做描述<br />
<br />
<code>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">/*</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * hello_5.c - Demonstrates command line argument passing to a module.</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> */</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">#include &lt;linux/module.h&gt;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">#include &lt;linux/moduleparam.h&gt;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">#include &lt;linux/kernel.h&gt;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">#include &lt;linux/init.h&gt;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">#include &lt;linux/stat.h&gt;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_LICENSE(&quot;GPL&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_AUTHOR(&quot;Irene&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static short int myshort = 1;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static int myint = 420;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static long int mylong = 9999;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static char *mystring =&quot;blah&quot;;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static int myintArray[2]= {6,6};</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static int arr_argc = 0;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">/*</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * module_param(foo, int , 0000)</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The first param is the parameters name</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The second param is it&#39;s data type</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The final argument is the permissions bits,</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * for exposing parameters in sysfs (if non-zero) at a later stage.</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> */</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_param(myshort, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_PARM_DESC(myshort, &quot;A short integer&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_param(myint, int, S_IRUSR | S_IWUSR | S_IRGRP |S_IROTH);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_PARM_DESC(myint, &quot;An integer&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_param(mylong, long, S_IRUSR);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_PARM_DESC(mylong, &quot;A long integer&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_param(mystring, charp, 0000);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_PARM_DESC(mystring, &quot;A character string&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">/*</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * module_param_array(name, type, num, perm);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The first param is the parameter&#39;s (in this case the array&#39;s)name</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The second param is the data type of the elements of the array</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The third argument is a pointer to the variable that will store the number</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * of the elements of the array initialized by the user at module loading time</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> * The fourth argument is the permission bits</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"> */</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_param_array(myintArray, int, &amp;arr_argc, 0000);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">MODULE_PARM_DESC(myintArray, &quot;An array of integers&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static int __init hello_5_init(void)</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">{</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int i;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;Hello, world 5\n==============\n&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;myshort is a short integer: %hd\n&quot;, myshort);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;myint is an integer: %d\n&quot;, myint);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;mylong is a long integer: %ld\n&quot;, mylong);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;mystring is a string: %s\n&quot;,mystring);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(i=0; i&lt;(sizeof myintArray / sizeof(int));i++)</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;myintArray[%d] = %d\n&quot;, i,myintArray[i]);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;got %d arguments for myintArray.\n&quot;, arr_argc);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">}</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">static void __exit hello_5_exit(void)</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">{</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printk(KERN_INFO &quot;Goodbye, world 5\n&quot;);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">}</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;"><br /></span></span>
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_init(hello_5_init);</span></span><br />
<span style="font-family: Courier New; font-size: x-small;"><span style="line-height: 16px;">module_exit(hello_5_exit);</span></span> </code><br />
<br />
<b><span style="color: blue;">利用 insmod hello_5.ko 看output messages ( 利用 cat /var/log/messages)
</span></b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXfu22iKb0NkBwnwq9lu5RXmjAIK-piJZcFPiUL5AQZFqHWVtG5HtpoRi8buDFwrz2e0O506vL67kdGLYjRl1C47h2X9QlK0wjfVRe2Ve-SmkuOZXt7Dfgz0bQ0PorMjnCelLZvMc8Zyp5/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXfu22iKb0NkBwnwq9lu5RXmjAIK-piJZcFPiUL5AQZFqHWVtG5HtpoRi8buDFwrz2e0O506vL67kdGLYjRl1C47h2X9QlK0wjfVRe2Ve-SmkuOZXt7Dfgz0bQ0PorMjnCelLZvMc8Zyp5/s640/1.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="color: blue;"><b>或是 insmod hello_5.ko myint=25 mystring="Irene" myintArray=1,2</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHlfuwLg3Rn_kxaI8PmDtB-Ho7q-BuAAPGW8xL1V8fXuE8f0HxF_FVqFIfarMPeaT4Kaqo0KsuyE2GfKhhmNf5PozW7nI-GPqKf9a4jlabgAb-aDqBeN9YoFrEfqO2boQ6uGveIc6cBeiS/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="195" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHlfuwLg3Rn_kxaI8PmDtB-Ho7q-BuAAPGW8xL1V8fXuE8f0HxF_FVqFIfarMPeaT4Kaqo0KsuyE2GfKhhmNf5PozW7nI-GPqKf9a4jlabgAb-aDqBeN9YoFrEfqO2boQ6uGveIc6cBeiS/s640/2.png" width="640" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
可以看到指定的變數都改value了!<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7Em6kL70nQOID45ceXf2JxKVSjZ5djcyP0Ka-XfH7v2FIG2bYfPWIodqIOvJxT4qacDnPMXrlR6LMD_rWAgUxI8j7yZb3LLOSBjsNsZikzI8_wnm4WzM4EEXpxNfdI8M58ha7ltg_f6G/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7Em6kL70nQOID45ceXf2JxKVSjZ5djcyP0Ka-XfH7v2FIG2bYfPWIodqIOvJxT4qacDnPMXrlR6LMD_rWAgUxI8j7yZb3LLOSBjsNsZikzI8_wnm4WzM4EEXpxNfdI8M58ha7ltg_f6G/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO7Em6kL70nQOID45ceXf2JxKVSjZ5djcyP0Ka-XfH7v2FIG2bYfPWIodqIOvJxT4qacDnPMXrlR6LMD_rWAgUxI8j7yZb3LLOSBjsNsZikzI8_wnm4WzM4EEXpxNfdI8M58ha7ltg_f6G/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><br /></a></div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-44469103740164895302013-08-24T06:40:00.000-07:002013-08-24T06:40:39.410-07:00Linux Kernel Module 2 - 顯示 module info在 Linux /include/linux/module.h 中可以找到定義一些module基本info的function<br />
for example:<br />
<br />
<b> <span style="color: orange;">MODULE_DESCRIPTION(DESC) </span>:</b> 定義MODULE在做些什麼<br />
<span style="color: orange;"><b>MODULE_AUTHOR(AUTHOR)</b> :</span> 明顯的就是告訴大家作者是誰<br />
<span style="color: orange;"><b>MODULE_LICENSE(GPL) </b>: </span>宣告GPL<br />
<br />
至於上面的DESC 和 AUTHOR 可以用 #define 來預先定義<br />
<span style="color: #134f5c;"><b>#define DESC "this is description"</b></span><br />
<span style="color: #134f5c;"><b>#define AUTHOR "I am author"</b></span><br />
<br />
這是書中 hello_4.c 範例<br />
寫完一樣 make和 insmode<br />
再來執行 modinfo hello_4.ko 就會顯示info了<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOnq8k_eVYFmjjpIeFs5Y5rdCskBArBmWWHGq5HJ9vs9yQLJhvSDdUxrPj8IDHqqHcSjQY5pJ1Rbb2dssVxh22zNH5rnDwdIDH-933GgyfAV9ufLQO2PH8C8vejGjLrlju70cJVTcxHJGE/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOnq8k_eVYFmjjpIeFs5Y5rdCskBArBmWWHGq5HJ9vs9yQLJhvSDdUxrPj8IDHqqHcSjQY5pJ1Rbb2dssVxh22zNH5rnDwdIDH-933GgyfAV9ufLQO2PH8C8vejGjLrlju70cJVTcxHJGE/s1600/1.png" height="153" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-4604316606605090602013-08-16T02:38:00.001-07:002013-08-22T00:28:44.099-07:00Linux Kernel Module 1 - 第一支Hello Irene Module<b>1. 先查詢自己的Linux version
</b><br />
<div>
--> uname -r</div>
<div>
我的版本是 Linux-2.6.18</div>
<div>
<br /></div>
<div>
<b>2. 下載Linux Kernel Source Code (壓縮檔放在/root底下)</b></div>
<div>
選擇 linux-2.6.18.tar.bz2</div>
<div>
<br /></div>
<div>
<b>3. 把 source code放在 /usr/src/kernels/ 目錄下</b></div>
<div>
--> tar -jxvf linux-2.6.18.tar.bz2 -C /usr/src/kernels/</div>
<div>
此時kernels下會有一個linex-2.6.18資料夾</div>
<div>
<br /></div>
<div>
<b>4.進入kernel 目錄</b></div>
<div>
--> cd /usr/src/kernels/linux-2.6.18</div>
<div>
<br /></div>
<div>
<b>5. 建立存放module的資料夾</b></div>
<div>
--> mkdir hello</div>
<div>
<br /></div>
<div>
<b>6.開始寫內部程式</b></div>
<div>
(1) hello-1.c</div>
<div>
--> vim hello-1.c</div>
<div>
--> i (編輯模式)</div>
<div>
-->按 Esc 回一般模式</div>
<div>
--> :wq (儲存並離開)</div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoPiF4oE5Z-7XCLCMCgSn_02NSPCmvUKUqwukqpBRbSVzQvV_uKf-usEAbQmMCCEAG7B-uBufxhqQ1b4FLSi9hTxcLP0AV-390n_fSymqGsK8ZrLer-VyQdvzNG-5KS7ZgPGnuoMT2UfK3/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoPiF4oE5Z-7XCLCMCgSn_02NSPCmvUKUqwukqpBRbSVzQvV_uKf-usEAbQmMCCEAG7B-uBufxhqQ1b4FLSi9hTxcLP0AV-390n_fSymqGsK8ZrLer-VyQdvzNG-5KS7ZgPGnuoMT2UfK3/s1600/1.png" /></a></div>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
(2) Makefile</div>
<div>
--> vim Makefile</div>
<div>
</div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsVH0g9pFkVkTnTccwBLrFUAOT78DVTWY1hSOgYHxgiO5hYJZkt6WW_GgPrkytzAH3ykpUMTid-gtgYBim4lin0RobHsSL_iUH94MRNZ4UsOz82XlCIgKbNqkhyphenhyphenlKxDp6LICvKRWP_ePCL/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsVH0g9pFkVkTnTccwBLrFUAOT78DVTWY1hSOgYHxgiO5hYJZkt6WW_GgPrkytzAH3ykpUMTid-gtgYBim4lin0RobHsSL_iUH94MRNZ4UsOz82XlCIgKbNqkhyphenhyphenlKxDp6LICvKRWP_ePCL/s1600/2.png" /></a></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>7 --> make</b></div>
<div class="separator" style="clear: both; text-align: left;">
make 之後會產生 hello-1.ko </div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLDiqRNJC3ri8WP6Ei40bMnzDtsOwXg5bbs6_2DnxEjFyQmvb2eL6UwWUTEsI09opuVb-T4-AYirmcNV76b-zjsAd0xKrTRqqtZgHxdca8a5PijFgGugHrh4XJGoBM9U9Ip4xQiLxPgWMe/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLDiqRNJC3ri8WP6Ei40bMnzDtsOwXg5bbs6_2DnxEjFyQmvb2eL6UwWUTEsI09opuVb-T4-AYirmcNV76b-zjsAd0xKrTRqqtZgHxdca8a5PijFgGugHrh4XJGoBM9U9Ip4xQiLxPgWMe/s1600/3.png" height="81" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>8 --> insmod ./hello-1.ko</b></div>
<div class="separator" style="clear: both; text-align: left;">
將hello-1.ko 加入至kernel module中</div>
<div class="separator" style="clear: both; text-align: left;">
可以到 /proc/modules/中看到hello-1 module正在kernel中</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCEdJk5tk-q7Ar_tDvHBrpny6RIWTq1mlqtIF3_98ru7v05-vJyDeOASe8Y1muWEyo9D0Uegz7Hi8qsh4TrJuRJrC9RQo7fFTBF0tW-SKNxHowoSfecPFfzlKYrRGD52x0g1pgeh-WJ5xJ/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCEdJk5tk-q7Ar_tDvHBrpny6RIWTq1mlqtIF3_98ru7v05-vJyDeOASe8Y1muWEyo9D0Uegz7Hi8qsh4TrJuRJrC9RQo7fFTBF0tW-SKNxHowoSfecPFfzlKYrRGD52x0g1pgeh-WJ5xJ/s1600/4.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
此時利用 cat /var/log/messages 到messages中會看到 Hello Irene</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<b>9. --> rmmod ./hello-1.ko</b></div>
<div class="separator" style="clear: both; text-align: left;">
將hello-1 module移除</div>
<div class="separator" style="clear: both; text-align: left;">
此時 /proc/modules/中就看不見 hello-1 module了</div>
<div class="separator" style="clear: both; text-align: left;">
而到 /var/log/messages/ 會看到 Goodbye Irene</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_9ZlwleDoD8bUUnnbnFYmEMYecb7MJn1kOMa0H6JrakD8f6rMOXJqihdFp4tQS5YwC164U18GBxPDFcQYp1erscCGC-Pet0CItM-YhQLKNQ-iM_qzZvbqZ0B_4BosGECHDg1pbHVrSwjt/s1600/5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_9ZlwleDoD8bUUnnbnFYmEMYecb7MJn1kOMa0H6JrakD8f6rMOXJqihdFp4tQS5YwC164U18GBxPDFcQYp1erscCGC-Pet0CItM-YhQLKNQ-iM_qzZvbqZ0B_4BosGECHDg1pbHVrSwjt/s1600/5.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
P.S 想要搜尋Hello與 Goodbye,可使用grep 指令</div>
<div class="separator" style="clear: both; text-align: left;">
--> cat /var/log/messages | grep Hello</div>
<div class="separator" style="clear: both; text-align: left;">
--> cat /var/log/messages | grep Goodbye</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
第一次寫kernel的東西~我連linux指令都還不太熟悉@@</div>
<div class="separator" style="clear: both; text-align: left;">
希望繼續加油囉!</div>
<div class="separator" style="clear: both; text-align: left;">
-------------------------------------------------------------------</div>
<div class="separator" style="clear: both; text-align: left;">
參考 : 鳥哥的 Linux私房菜 第三版 ch22,ch26</div>
<div class="separator" style="clear: both; text-align: left;">
The Linux Module Programming Guide </div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-17265504864754756092013-07-11T08:10:00.000-07:002013-08-16T02:40:51.037-07:00Pointer in C<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0y2RR5sVXxNpKDrjxmXPpAa4ECoBl5Ox1iAwv6zg81PXueViI-gxW21QlE6BJak81NiCeoF1hyphenhyphen3ND0gQBbCbdkXatmwoPd_flnlo_vLyiceZksxC8P0LBPHrQxMkgVoxw0hVN7UonJzcZ/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0y2RR5sVXxNpKDrjxmXPpAa4ECoBl5Ox1iAwv6zg81PXueViI-gxW21QlE6BJak81NiCeoF1hyphenhyphen3ND0gQBbCbdkXatmwoPd_flnlo_vLyiceZksxC8P0LBPHrQxMkgVoxw0hVN7UonJzcZ/s1600/1.png" height="268" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
圖1<br />
pointer有3種pointer arithmetic<br />
1) result: p指向a[3],q指向a[4]<br />
2) result: p指向a[5],q指向a[7]<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWcTyvmRM8MrNOJtJn0atKP99-4rk44_roESOYtmRpqTh7kza7cdGkMpDxsQG4qlXvRYFiQNuXCACp0kTmNznvX_P-AwxwMjB0vAD6QETUwV_g3cXIHF_n6dZX-vUo6-bcpnaOFEYONLZ2/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWcTyvmRM8MrNOJtJn0atKP99-4rk44_roESOYtmRpqTh7kza7cdGkMpDxsQG4qlXvRYFiQNuXCACp0kTmNznvX_P-AwxwMjB0vAD6QETUwV_g3cXIHF_n6dZX-vUo6-bcpnaOFEYONLZ2/s1600/2.png" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
圖2<br />
&b[0] 和 b 一樣代表的是array b的第一個元素<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuC3GjHaryShYWm8zPuEupYlUOQwg1xZsV_0qpitzEgXNWwPz2av7zyLIt4VIYLC9-_W65gHKhg4zG6BwnQqUiv-koNUr350DxPYHYTqwLJle1cZifyqkLhAqcK_GeKBq-hk58SF4_1X4f/s1600/3.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuC3GjHaryShYWm8zPuEupYlUOQwg1xZsV_0qpitzEgXNWwPz2av7zyLIt4VIYLC9-_W65gHKhg4zG6BwnQqUiv-koNUr350DxPYHYTqwLJle1cZifyqkLhAqcK_GeKBq-hk58SF4_1X4f/s1600/3.png" height="200" width="400" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
多維陣列也可以想成是一維陣列,ex:第一種寫法<br />
p指向第一個元素,接著一直向下指<br />
多維陣列也是多個一維陣列組成,ex:第二種寫法<br />
i 是row的index<br />
p先指向第一行陣列,c[i]此時代表的是第一行陣列第一個元素的addr<br />
p會先加完第一行所有列的元素在指向第二行<br />
<br />
<P.s 1><br />
終止條件寫成 p< &c[NUM_ROWS][NUM_COLS]可能會有錯<br />
因為c[NUM_ROWS][NUM_COLS]這一個元素已在array c預期的大小之外<br />
因此他的addr可能是一個任意位址<br />
若p的addr剛好小於此元素的位址就會造成錯誤。<br />
<br />
<P.s 2><br />
while(*a!=0)<br />
a++; //wrong<br />
雖然 a 是 array name也可以當作指標,但不能assign 給 a 新的值<br />
上述 a++指移動位址,因此錯誤<br />
可以給一個 pointer指向a<br />
再移動 p (assign p 新的值)<br />
p=a;<br />
while(*p!=0)<br />
p++; //correct<br />
<br />
<br />ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-26752332939403046662013-03-16T21:28:00.006-07:002013-03-17T19:18:43.410-07:00Pointer 2_const<span style="color: red; font-size: large;"><span style="font-family: Calibri;">(1)a
</span><span style="font-family: Calibri;">non-constant
pointer to non-constant </span><span style="font-family: Calibri;">data</span></span><br />
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial;">•</span><span style="color: blue; font-family: 新細明體;">存取權最高</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Data</span><span style="font-family: 新細明體;">可透過</span><span style="font-family: Calibri;">pointer</span><span style="font-family: 新細明體;">遭到更改</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Pointer</span><span style="font-family: 新細明體;">可以改為只向別的物件</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Ex:
pointer3.c</span><br />
<span style="font-family: Calibri;">----------------------------------------------------------------------------------</span><br />
<span style="font-family: Calibri;"><br /></span>
<code>
<span style="font-family: Calibri;">/* Converting lowercase letters to uppercase letters</span><br />
<span style="font-family: Calibri;">using a non-constant pointer to a non-constant data */</span><br />
<span style="font-family: Calibri;">#include <stdio.h></span><br />
<span style="font-family: Calibri;">#include <ctype.h></span><br />
<span style="font-family: Calibri;">void convertToUppercase(char *ptr);</span><br />
<span style="font-family: Calibri;">int main(void)</span><br />
<span style="font-family: Calibri;">{</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>char string[]="characters and $32.25";</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printf("The string before conversion is: %s",string);</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>convertToUppercase(string);</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>printf("\nThe string after conversion is:%s\n",string);</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;</span><br />
<span style="font-family: Calibri;">}</span><br />
<span style="font-family: Calibri;">void convertToUppercase(char *ptr)</span><br />
<span style="font-family: Calibri;">{</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>while(*ptr !='\0')</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if(islower(*ptr))</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>*ptr=toupper(*ptr);</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>++ptr;</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Calibri;">}</span>
</code>
</div>
<span style="font-family: Calibri;">-------------------------------------------------------------------------------------------</span><br />
<span style="color: red; font-size: large;"><span style="font-family: Calibri;">(2)a
</span><span style="font-family: Calibri;">non-constant
pointer to </span><span style="font-family: Calibri;">constant
data</span></span><br />
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial;">•</span><span style="font-family: Calibri;">Ex:
pointer5.c</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: 新細明體;">若隨意</span><span style="font-family: 新細明體;">更改指標指向的物件內容會有</span><span style="font-family: Calibri;">error</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: 新細明體;">編譯</span><span style="font-family: 新細明體;">錯誤</span><span style="font-family: Calibri;">:</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">assignment
of read only location “</span><span style="font-family: Calibri;">ptr</span><span style="font-family: Calibri;">”</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: 新細明體;">明顯</span><span style="font-family: 新細明體;">的問題出在</span><span style="font-family: Calibri;">ptr</span><span style="font-family: 新細明體;">指向的是</span><span style="font-family: Calibri;">read
only</span><span style="font-family: 新細明體;">的位置</span><span style="font-family: Calibri;">,</span><span style="font-family: 新細明體;">不能更改</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Tips:
</span><span style="font-family: 新細明體;">陣列當引數呼叫</span><span style="font-family: Calibri;">function</span><span style="font-family: 新細明體;">時,陣列會自動以傳參考呼叫</span><span style="font-family: Calibri;">function,</span><span style="font-family: 新細明體;">而</span><span style="font-family: Calibri;">struct</span><span style="font-family: 新細明體;">則是永遠以傳值的方式,傳遞整個副本過去會造成執行的負擔,因此必須將</span><span style="font-family: Calibri;">struct</span><span style="font-family: 新細明體;">傳給函式時使用指向</span><span style="font-family: Calibri;">constant
data</span><span style="font-family: 新細明體;">的指標,一方面獲得傳參考呼叫的效率,一方面能保護資料。也就是說只要複製一份</span><span style="font-family: Calibri;">struct</span><span style="font-family: 新細明體;">本身的位址就好。</span><span style="font-family: Calibri;">--</span><span style="font-family: 新細明體;">一個時間</span><span style="font-family: Calibri;">/</span><span style="font-family: 新細明體;">空間取捨</span><span style="font-family: Calibri;">(time/space
trade-off)</span><span style="font-family: 新細明體;">的例子</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Important:
memory </span><span style="font-family: 新細明體;">不夠大且執行效率很重要時,用指標</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 4.8pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">memory
</span><span style="font-family: 新細明體;">很大且效率不那麼重要,用</span><span style="font-family: Calibri;">call
by value</span><span style="font-family: 新細明體;">以</span><span style="font-family: 新細明體;">實行最小權限原則</span><br />
<span style="font-family: courier;">-----------------------------------------------------</span><br />
<span style="font-family: courier;"><br /></span>
<code>
<span style="font-family: courier;">/* Attempting to modify data through a non-constant pointer to constant data */</span><br />
<span style="font-family: courier;">#include<stdio.h></span><br />
<span style="font-family: courier;">void f(const int *ptr);</span><br />
<span style="font-family: courier;"><br /></span>
<span style="font-family: courier;">int main (void)</span><br />
<span style="font-family: courier;">{</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int y;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>f(&y);</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;</span><br />
<span style="font-family: courier;">}</span><br />
<span style="font-family: courier;">/* ptr cannot be used to modify the value of variable to which it points */</span><br />
<span style="font-family: courier;">void f(const int *ptr)</span><br />
<span style="font-family: courier;">{</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>*ptr=100; //error: cannot modify a const object</span><br />
<span style="font-family: courier;">}</span><br />
</code>
<br />
<span style="font-family: 新細明體;">-----------------------------------------------------------------------------------------------</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="color: red; font-size: large;"><span style="font-family: Calibri;">(3)a
constant </span><span style="font-family: Calibri;">pointer
</span><span style="font-family: Calibri;">to</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">a
non- constant data</span></span><br />
<br />
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 5.76pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial;">•</span><span style="font-family: 新細明體;">非常數指標的常數指標永遠會指向同一個記憶體位置,不過指標所指向的數值可以更改。</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 5.76pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Array</span><span style="font-family: 新細明體;">名稱預設就是這種指標。</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 5.76pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Const</span><span style="font-family: 新細明體;">的指標必須在宣告時指定初始值</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 5.76pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: 新細明體;">若指標是函式的參數,則初始值將設成傳入此函式的指標</span></div>
<div style="direction: ltr; margin-bottom: 0pt; margin-left: 0.38in; margin-top: 7.68pt; text-indent: -0.38in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Ex:pointer6.c</span></div>
<div class="O1" style="direction: ltr; margin-bottom: 0pt; margin-left: 0.81in; margin-top: 6.72pt; text-indent: -0.31in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Calibri;">Ptr</span><span style="font-family: 新細明體;">是一個指向整數的常數指標,但後來又指向</span><span style="font-family: Calibri;">y,</span><span style="font-family: 新細明體;">此時編譯器會</span><span style="font-family: Calibri;">error—assignment
of read only variable “</span><span style="font-family: Calibri;">ptr</span><span style="font-family: Calibri;">”</span></div>
<span style="font-family: Calibri;">-------------------------------------------------------------------------------------------------------------------</span><br />
<code>
<span style="font-family: courier;"></span><br />
<span style="font-family: courier;">/* Attempting to modify a constant pointer to a non-constant data */</span><br />
<span style="font-family: courier;">#inlcude <stdio.h></span><br />
<span style="font-family: courier;">int main(void)</span><br />
<span style="font-family: courier;">{</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int x;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int y;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>/* ptr is a constant pointer to an integer that can be modified through ptr,</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>but ptr always points to the same memory lacation */</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int *const ptr=&x;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>*ptr=7;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ptr=&y;</span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: courier;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return 0;</span><br />
<span style="font-family: courier;">}</span><br />
<br />
</code>
<span style="font-family: Calibri;">-------------------------------------------------------------------------------------------------------------------</span>
<br />
<span style="color: red; font-size: large;"><span style="font-family: Calibri;">(4)a
constant </span><span style="font-family: Calibri;">pointer
</span><span style="font-family: Calibri;">to</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">a
constant data</span></span><br />
<br />
<span style="font-family: Arial;">•</span><span style="color: blue; font-family: 新細明體;">存取權最低</span><br />
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Pointer</span><span style="font-family: 新細明體;">永遠指向同一個記憶體位置,且該位置內容不能更改</span><br />
<span style="font-family: Arial; mso-special-format: bullet;">•</span><span style="font-family: Calibri;">Ex:
pointer7.c</span><br />
<span style="font-family: Arial; mso-special-format: bullet;">–</span><span style="font-family: Calibri;">Const</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">int</span><span style="font-family: Calibri;"> *</span><span style="font-family: Calibri;">const</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">ptr</span><span style="font-family: Calibri;">=&x;</span><br />
<span style="font-family: Arial; mso-special-format: bullet;">–</span><span style="font-family: Calibri;">Ptr</span><span style="font-family: 新細明體;">是一個常數指標</span><span style="font-family: Calibri;">,</span><span style="font-family: 新細明體;">指向一個整數常數</span><br />
<span style="font-family: Arial; mso-special-format: bullet;">–</span><span style="font-family: 新細明體;">程式</span><span style="font-family: 新細明體;">中藥更改指標與指標指向的內容都失敗</span>
<span style="font-family: Arial; mso-special-format: bullet;">–</span><span style="font-family: Calibri;">Assignment
of read only location “</span><span style="font-family: Calibri;">ptr</span><span style="font-family: Calibri;">” </span><span style="font-family: Arial; mso-special-format: bullet;">–</span><span style="font-family: Calibri;">Assignment
of read only variable “</span><span style="font-family: Calibri;">ptr</span><span style="font-family: Calibri;">”</span><br />
<span style="font-family: Calibri;">-----------------------------------------------------------------------------------------------------------------</span><br />
<code><br />
<span style="font-family: Calibri;">/* Attempting to modify a constant pointer to constant data */</span><br />
<span style="font-family: Calibri;">#include<stdio.h></span><br />
<span style="font-family: Calibri;">int main(void)</span><br />
<span style="font-family: Calibri;">{</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int x=5;</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int y;</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>/*ptr is a constant pointer to a constant integer.ptr always</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>points to the same location;the integer at that location</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>cannot be modified */</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span>const int *const ptr=&x;</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span> printf("%d\n",*ptr);</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span> *ptr=7; //error : *ptr is const;cannot assign new value </span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span> ptr=&y; //error: ptr is const;cannot assign new address</span><br />
<span style="font-family: Calibri;"><span class="Apple-tab-span" style="white-space: pre;"> </span> return 0;</span><br />
<span style="font-family: Calibri;">}</span><br />
</code>
<br />
<span style="font-family: Calibri;">-----------------------------------------------------------------------------------------------------------------</span>
<br />
<div class="O1" style="direction: ltr; margin-bottom: 0pt; margin-left: 0.81in; margin-top: 6.72pt; text-indent: -0.31in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Calibri;"><br /></span></div>
<div class="O1" style="direction: ltr; margin-bottom: 0pt; margin-left: 0.81in; margin-top: 6.72pt; text-indent: -0.31in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Calibri;"><br /></span></div>
<div class="O1" style="direction: ltr; margin-bottom: 0pt; margin-left: 0.81in; margin-top: 6.72pt; text-indent: -0.31in; unicode-bidi: embed; word-break: normal;">
<span style="font-family: Calibri;"><br /></span></div>
</div>
ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0tag:blogger.com,1999:blog-3694042177742514665.post-13483600207456300792013-03-16T19:05:00.005-07:002013-03-17T19:18:52.767-07:00Pointer 1_basic<span style="font-family: Calibri;">1)
</span><span style="font-family: 新細明體;">指標可以指定</span><span style="font-family: Calibri;">0,NULL,</span><span style="font-family: 新細明體;">或某個位址<br />
</span><span style="font-family: Calibri;">2)
& operator</span><span style="font-family: 新細明體;">為取址運算子</span><span style="font-family: Calibri;">(address
operator)-</span><span style="font-family: 新細明體;">會回傳</span><span style="font-family: Calibri;">operator
address</span><span style="font-family: 新細明體;">的
一元運算子</span><span style="font-family: Calibri;">,</span><span style="font-family: 新細明體;">不能應用到</span><br />
<span style="font-family: 新細明體;"> 常數、運算式或宣</span><span style="font-family: 新細明體;">告為</span><span style="font-family: Calibri;">register</span><span style="font-family: 新細明體;">的變數</span><br />
<span style="font-family: Calibri;">
3) * operator</span><span style="font-family: 新細明體;">為</span><span style="font-family: Calibri;">indirection
operator or dereferencing operator(</span><span style="font-family: 新細明體;">間接或是反參考運算子</span><span style="font-family: Calibri;">)-</span><span style="font-family: 新細明體;">回傳運算元</span><br />
<span style="font-family: 新細明體;"> 所指向的物件的</span><span style="font-family: 新細明體;">值</span><br />
<span style="font-family: Calibri;">
4)</span><span style="font-family: Calibri;"> </span><span style="color: red; font-family: Calibri;">ex:pointer1.c</span><span style="font-family: Calibri;"><br />
</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">-</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">%p: </span><span style="font-family: 新細明體;">將記憶體位址以</span><span style="font-family: Calibri;">16</span><span style="font-family: 新細明體;">進制印出</span><span style="font-family: Calibri;"><br />
</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">-</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">&</span><span style="font-family: 新細明體;">和*是互補的,同時使用的話就是顯示指標內容</span><br />
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifIBul3iSYuKU1Uui89NPncThXk00lQALRR-JID8kHGCeA4dS-91sKXfRKUbbQJbKDNF_mukzv2B9fbApiQRjYb_YBcAvtZf3ect8XR79PN09LMdYRHOUTDB4irrGuKxwde17HMiluOOJ3/s1600/1.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="84" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifIBul3iSYuKU1Uui89NPncThXk00lQALRR-JID8kHGCeA4dS-91sKXfRKUbbQJbKDNF_mukzv2B9fbApiQRjYb_YBcAvtZf3ect8XR79PN09LMdYRHOUTDB4irrGuKxwde17HMiluOOJ3/s200/1.png" width="200" /></a></div>
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: 新細明體;"><br /></span></span>
<br />
<span style="font-family: Calibri;">5)</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">C</span><span style="font-family: 新細明體;">語言中所有的引數都是以值進行傳遞</span><span style="font-family: Calibri;"><br />
6)</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">Call
by value </span><span style="font-family: 新細明體;">、 </span><span style="font-family: Calibri;">Call
by reference<br />
7) </span><span style="font-family: 新細明體;">許多函式需要具有修改呼叫函式內定義之變數的能力,或傳遞一個指向大型物件的指標來</span><br />
<span style="font-family: 新細明體;"> 避免因為</span><span style="font-family: Calibri;">call
by value</span><span style="font-family: 新細明體;">所產生的額外負擔。因此</span><span style="font-family: Calibri;">C</span><span style="font-family: 新細明體;">提供</span><span style="font-family: Calibri;">simulating
call-by-reference</span><span style="font-family: 新細明體;">的功能</span><span style="font-family: Calibri;"><br />
8)</span><span style="font-family: Calibri;"> 引數加上</span><span style="font-family: Calibri;">&</span><span style="font-family: 新細明體;">來傳遞變數位址,而函式內部用*即可改變變數內容</span><span style="font-family: Calibri;"><br />
9)</span><span style="font-family: Calibri;">
陣列名稱相當於</span><span style="font-family: Calibri;">&array[0]</span><span style="font-family: 新細明體;">,</span><span style="font-family: Calibri;">C</span><span style="font-family: 新細明體;">會自動傳遞陣列的起始位址,所以當陣列是引數時不用加</span><span style="font-family: Calibri;">&</span><br />
<span style="font-family: Calibri;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY8VnfJIXTnw6cjbMwfY2SM4b44-A0KYLKyTxDMok9w1XhzYU56YXJRYKItephYdEmtdWUWQUnECYG0LnPV7Mx-nXyxWgU35ERsEhBW7V4dsl-UrwjaxcBpv13wV9bCsJ9QQeiFE1JbJwq/s1600/2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="257" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY8VnfJIXTnw6cjbMwfY2SM4b44-A0KYLKyTxDMok9w1XhzYU56YXJRYKItephYdEmtdWUWQUnECYG0LnPV7Mx-nXyxWgU35ERsEhBW7V4dsl-UrwjaxcBpv13wV9bCsJ9QQeiFE1JbJwq/s640/2.png" width="640" /></a></div>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-size: x-small;"><span style="font-family: Calibri;"><br /></span></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;"><br /></span>
<span style="font-family: Calibri;">10)</span><span style="font-family: Calibri;"> </span><span style="font-family: Calibri;">const</span><span style="font-family: 新細明體;">修飾詞:告訴編譯器變數不能被修改</span><span style="font-family: Calibri;"><br />
11)</span><span style="font-family: Calibri;">
軟工觀點:</span><span style="font-family: Calibri;">const</span><span style="font-family: Calibri;"> </span><span style="font-family: 新細明體;">可實現最小權限原則,減少偵錯時間,使程式更容易維護。</span><span style="font-family: Calibri;"><br />
12)</span><span style="font-family: Calibri;">
函式的參數使用</span><span style="font-family: Calibri;">const</span><span style="font-family: 新細明體;">有</span><span style="font-family: Calibri;">6</span><span style="font-family: 新細明體;">種方式,可利用</span><span style="font-family: Calibri;">principle
of least privilege</span><span style="font-family: 新細明體;">作為挑選原則。</span><span style="font-family: Calibri;"><br /> <span style="color: blue;"><1> a non-constant pointer to non-constant data</span><br />
</span><span style="font-family: 新細明體;"> 指向非常數資料的非常數指標</span><span style="font-family: Calibri;"><br /> <span style="color: blue;"><2> a constant pointer to non-constant data </span><br />
</span><span style="font-family: 新細明體;"> 指向非常數</span><span style="font-family: 新細明體;">資料</span><span style="font-family: 新細明體;">的常數</span><span style="font-family: 新細明體;">指標</span><span style="font-family: Calibri;"><br />
</span><span style="font-family: Calibri;"> <span style="color: blue;"><3>
a non-constant pointer to constant data</span><br />
</span><span style="font-family: 新細明體;"> 指向常數資料的非常數指標</span><span style="font-family: Calibri;"><br /> <span style="color: blue;"><4> a constant pointer to constant data</span><br />
</span><span style="font-family: 新細明體;"> 指向常數資料</span><span style="font-family: 新細明體;">的常數</span><span style="font-family: 新細明體;">指標</span>ironcathttp://www.blogger.com/profile/14710645437918950923noreply@blogger.com0