<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Windows CE Kernel</title>
        <link>http://geekswithblogs.net/BruceEitman/category/8118.aspx</link>
        <description>A collection of posts about the Windows CE Kernel</description>
        <language>en-US</language>
        <copyright>Bruce Eitman</copyright>
        <managingEditor>Bruce.Eitman@EuroTech.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Platform Builder: Understanding the Serial Debug Port</title>
            <link>http://geekswithblogs.net/BruceEitman/archive/2008/09/08/platform-builder-understanding-the-serial-debug-port.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 10pt"&gt;Recently, there have been a few questions in the newsgroups about the serial debug port. The questions were along the lines of:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;         &lt;/span&gt;&lt;/span&gt;Which COM port do I use for debug output?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;·&lt;span style="FONT: 7pt 'Times New Roman'"&gt;         &lt;/span&gt;&lt;/span&gt;How do I change the COM port that is used for debug output?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;These are actually quite common questions, so I thought I would address these. Every CPU and/or UART is different so I won’t give you a how to lesson, but I will provide you with enough information to look inside your BSP to figure it out for yourself.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;First, let’s address the term COM port. COM is a special name used in device drivers to indicate that the driver is manageable through special COM APIs for controlling the communications through a UART. The term doesn’t apply to the debug serial port because:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;1.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;No device driver. The serial debug port must be available before the device manager is even running. The serial debug port is available in the single threaded bootloader and is available early in the kernel initialization.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;2.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;No run time API support for baud rate, parity, stop bit…&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;3.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;The debug serial port is not manageable by the COM APIs.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;Getting the Serial Debug Port Started&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;On the most base level, the serial debug port can be initialized and written to in the assembly code that starts your bootloader. This is not the focus of this article, but I mention it because you may need to delve into the assembly code to change the serial debug port.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;Talking C though, the serial debug port is initialized in OEMInitDebugSerial(). OEMInitDebugSerial() should initialize the UART. It should set the baud rate, parity and stop bits, may need to turn on power to external hardware and may need to start a clock to run the UART. OEMInitDebugSerial() may select different UARTs or even disable the serial output depending on platform specific features.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;Outputting on the Serial Debug Port&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;OEMWriteDebugString() and OEMWriteDebugByte() provide the functionality of outputting on the serial debug port. OEMWriteDebugByte () usually implements putting a byte on the output FIFO of the UART and OEMWriteDebugString () usually processes a string and calls OEMWriteDebugByte () for each character to be output.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;Reading Input on the Serial Debug Port&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;OEMReadDebugByte() implements reading a byte from the UART input FIFO. OEMReadDebugByte() is non-blocking, so if a character isn’t available or an error occurs it returns with a status code of either &lt;span style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%"&gt;OEM&lt;/span&gt;&lt;span style="COLOR: black"&gt;_DEBUG_COM_ERROR, OEM_DEBUG_READ_NODATA. I have provided a code sample of reading from the serial debug port in &lt;a href="http://geekswithblogs.net/BruceEitman/archive/2008/05/09/windows-ce--using-the-debug-serial-port-for-input.aspx"&gt;&lt;u&gt;&lt;strong&gt;Windows CE: Using the debug serial port for input&lt;/strong&gt;&lt;/u&gt;&lt;/a&gt;.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;&lt;span style="COLOR: black"&gt;Answering the Questions&lt;/span&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;span style="COLOR: black"&gt;How would you answer the questions about the serial debug port? Every BSP is different, so I the only concrete advice that I can give is to look for the serial debug port functions in your code. But in more generic terms, these functions are often implemented in both the bootloader and the OAL or Kernel, so you may need to look in both. The functions are sometimes implemented in a file named debug.c. If you look at CEPC, you will find that it actually has three implementations of these functions in eboot, sboot and the kernel uses an implementation in Platform\Common.&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;Copyright © 2008 – Bruce Eitman&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;All Rights Reserved&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125022"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=125022" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BruceEitman/aggbug/125022.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Bruce Eitman</dc:creator>
            <guid>http://geekswithblogs.net/BruceEitman/archive/2008/09/08/platform-builder-understanding-the-serial-debug-port.aspx</guid>
            <pubDate>Tue, 09 Sep 2008 01:32:51 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BruceEitman/comments/125022.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BruceEitman/archive/2008/09/08/platform-builder-understanding-the-serial-debug-port.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BruceEitman/comments/commentRss/125022.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Windows CE: Number of Processes and Threads </title>
            <link>http://geekswithblogs.net/BruceEitman/archive/2008/08/06/windows-ce-number-of-processes-and-threads.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 10pt"&gt;Once in a while I am asked how many processes can run at any time in a Windows CE system. It is also one of my interview questions when interviewing a candidate with Windows CE experience, and the follow on question is how many threads can run at one time?&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;Number of Processes:&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;Then number of processes is controlled by the kernel and was changed for Windows CE 6.0 to be 32K processes. Pretty impressive, but I suspect that the limit is much smaller because on most, if not all, Windows CE systems you will run out of physical memory long before creating even close to 32K processes (I suppose that there is another post topic in that sentence.) Each process has up to 2GB of virtual address space available to it.   As a result, Microsoft lifted the artificial limits on number of processes and virtual address space, now the limit is hardware.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;The number of processes that can run at simultaneously in Windows CE 5.0 and earlier versions is 32. Each process has 32MB of virtual address space available to it. The reason for these limits is that the address space for processes is divided into 33 slots each having 32MB of virtual address space available to it. The slots are numbered 0 through 32, with slot 0 being the currently running process.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;There was a significant change to the slot architecture in Windows CE 4.0. Slot 1, which was where the kernel ran in prior versions, was reserved for loading DLLs that were specifically fixed up to run in slot 1. The kernel moved out of the slots altogether, so this change didn’t reduce the number of processes that could run. This change was significant because in previous versions all DLLs loaded in slot 0, which meant that the DLLs reduced the amount of available virtual address space available to the running process. That is if any process loaded a DLL, all processes suffered the loss of virtual address space.   This was still true for Windows CE 4.x and 5.0, but only if the DLL was not fixed up to run in slot 1, but most of the DLLs that are loaded are included in the OS and are fixed up to run in slot 1.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;strong&gt;Number of Threads&lt;/strong&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;The number of threads is only limited by the available system resources. That is a fancy way of saying that when the system runs out of physical RAM, no more threads can be started.&lt;/div&gt;
&lt;table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1"&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 95.75pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt; &lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Number of Processes&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Number of Threads&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: black 1pt solid; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Virtual Address Space per Process&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Windows CE 5.0 and before&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;32&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Limited by System Resources&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;32 MB&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0in; BORDER-LEFT: black 1pt solid; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Windows CE 6.0&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;32K&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;Limited By System Resources&lt;/div&gt;
            &lt;/td&gt;
            &lt;td style="BORDER-RIGHT: black 1pt solid; PADDING-RIGHT: 5.4pt; PADDING-LEFT: 5.4pt; BORDER-LEFT-COLOR: #d4d0c8; PADDING-BOTTOM: 0in; WIDTH: 95.75pt; BORDER-TOP-COLOR: #d4d0c8; PADDING-TOP: 0in; BORDER-BOTTOM: black 1pt solid; BACKGROUND-COLOR: transparent" valign="top" width="128"&gt;
            &lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal"&gt;2 GB&lt;/div&gt;
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt; &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;&lt;span style="FONT-SIZE: 9pt; LINE-HEIGHT: 115%"&gt;Tags: &lt;/span&gt;&lt;a rel="tag" href="http://technorati.com/tags/Kernel"&gt;&lt;span style="FONT-SIZE: 9pt; LINE-HEIGHT: 115%"&gt;Kernel&lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;Copyright © 2008 – Bruce Eitman&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;All Rights Reserved&lt;/span&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124282"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124282" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BruceEitman/aggbug/124282.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Bruce Eitman</dc:creator>
            <guid>http://geekswithblogs.net/BruceEitman/archive/2008/08/06/windows-ce-number-of-processes-and-threads.aspx</guid>
            <pubDate>Thu, 07 Aug 2008 02:37:42 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BruceEitman/comments/124282.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BruceEitman/archive/2008/08/06/windows-ce-number-of-processes-and-threads.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BruceEitman/comments/commentRss/124282.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Platform Builder: Clone Public Code</title>
            <link>http://geekswithblogs.net/BruceEitman/archive/2008/07/02/platform-builder-clone-public-code.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 10pt"&gt;I recently wrote an article about modifying the behavior of KernelIoControl when called by User Mode code. In that article, I stated that you need to clone the Public oemioctl code to your platform. Sounds so simple doesn’t it, and really it isn’t that difficult if you know what you are doing, but for the rest of you I thought that I would walk through the process of cloning code.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;Many of us use the term “clone code” but what does it really mean? Cloning code means to copy the code to another build tree and modify the build environment to build the code under the new tree. In the old days of Windows CE development, that meant reverse engineering how Microsoft builds the code to apply your knowledge of the build system to it. Today we have sysgen_capture.bat to do most of the hard work for us.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;Here is how I would clone oemioctl:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;1.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Create a new folder in my platform to build oemoctl.dll, I will call mine OALIoctlDir. This folder will be a holding place for two new folders; one will build the lib that is built in Public\Common\OAK\oalioctl, and the other will link the lib to create the dll. You certainly can create the dll with one folder, but that is more involved that the discussion here.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;2.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Copy the %_WINCEROOT%\Public\Common\OAK\OEMICTL folder and paste it as a new subfolder of OALIoctlDir. This is the folder that creates OALIoctl.lib.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;3.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Create an new folder in OALIoctlDir named BuildDll; this is the folder that will do the linking to create OALIoctl.dll.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;4.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Create a dirs file OALIoctlDir that contains&lt;br /&gt;
&lt;br /&gt;
&lt;span style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0in; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0in; PADDING-BOTTOM: 0in; BORDER-LEFT: windowtext 1pt solid; PADDING-TOP: 0in; BORDER-BOTTOM: windowtext 1pt solid"&gt;DIRS=oalicotl BuildDll&lt;br /&gt;
&lt;/span&gt;This tells build to go into OALIoctl first to build the lib, then go to BuildDll to link the dll.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;5.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Add OEMIocltDir to its parent folder’s dirs file, which tells build to build our clone of OALIoctl.dll.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;6.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Modify OALIoctlDir\OALIoctl\sources to add RELEASETYPE=PLATFORM, this tells build to put the lib in the platform build tree&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;7.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Open a build window and change directories to OALIocltDir\BuildDll&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;8.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Run “sysgen_capture OALIoctl” which will create a file named sources.OALIoctl. This new file contains the information that Microsoft uses to link OALIoctl.lib to create OALIoctl.dll, we need that information to build.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;9.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;Rename souces.OALIoctl to sources, so that build.exe can use it.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;10.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;   &lt;/span&gt;&lt;/span&gt;Modify OALIoctlDir\BuildDll\sources to &lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;a.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;       &lt;/span&gt;&lt;/span&gt;change    $(_PUBLICROOT)\common\oak\lib\$(_CPUINDPATH)\OALIoctl.lib to    $(_TARGETPLATROOT)\lib\$(_CPUINDPATH)\OALIoctl.lib&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 1in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;b.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;      &lt;/span&gt;&lt;/span&gt;Change the DEFFILE to DEFFILE=OALIoctl.def&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;11.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;   &lt;/span&gt;&lt;/span&gt;Copy OALIoctl.def from OALIoctlDir\oalioclt to OALIoctlDir\BuildDll, this is necessary so that when BuildDll is built it can find the def file. There are alternative solutions for this, but this one is easy.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;12.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;   &lt;/span&gt;&lt;/span&gt;Copy a makefile from one another folder to BuildDll, this is necessary because build.exe needs the makefile when it calls nmake.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;13.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;   &lt;/span&gt;&lt;/span&gt;Change directories to OALIocltDir and run build&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt 0.5in; TEXT-INDENT: -0.25in"&gt;&lt;span&gt;14.&lt;span style="FONT: 7pt 'Times New Roman'"&gt;   &lt;/span&gt;&lt;/span&gt;Now you have an OALIoctl.dll in your Platform’s Target folder. When you run buildrel, this OALIoctl.dll will overwrite the one created in the Public folder.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;Now you have a clone of OALIoctl that you can modify to suit the needs of your platform.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;span style="FONT-SIZE: 9pt; LINE-HEIGHT: 115%"&gt;
&lt;p&gt;Tags: &lt;a rel="tag" href="http://technorati.com/tags/Sysgen_Capture"&gt;Sysgen_Capture&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tags/Clone"&gt;Clone&lt;/a&gt;&lt;/p&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt; TEXT-INDENT: -0.25in; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;Copyright © 2008 – Bruce Eitman&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt; TEXT-INDENT: -0.25in; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;All Rights Reserved&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123531"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123531" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BruceEitman/aggbug/123531.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Bruce Eitman</dc:creator>
            <guid>http://geekswithblogs.net/BruceEitman/archive/2008/07/02/platform-builder-clone-public-code.aspx</guid>
            <pubDate>Wed, 02 Jul 2008 18:32:13 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BruceEitman/comments/123531.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BruceEitman/archive/2008/07/02/platform-builder-clone-public-code.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/BruceEitman/comments/commentRss/123531.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Windows CE 6.0: User Mode KernelIoControl</title>
            <link>http://geekswithblogs.net/BruceEitman/archive/2008/07/01/windows-ce-6.0-user-mode-kerneliocontrol.aspx</link>
            <description>&lt;div style="MARGIN: 0in 0in 10pt"&gt;Windows CE 6.0 introduces some new security features including new meaning for User Mode and Kernel Mode.   Loosely speaking, Kernel Mode has access to the system’s resources and User Mode is greatly restricted. One of the new restrictions on User Mode code is that calls to KernelIoControl are limited to the following OEMIoControl IOCTLs:&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;        IOCTL_HAL_GET_CACHE_INFO&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;        IOCTL_HAL_GET_DEVICE_INFO&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;        IOCTL_HAL_GET_DEVICEID&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 0pt"&gt;        IOCTL_HAL_GET_UUID&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;        IOCTL_PROCESSOR_INFORMATION&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;As an OEM you can change this to allow access to other IOCTLs. The default restriction makes a lot of sense for consumer devices, but for closed systems or systems that the OEM wants to provide more functionality, there is a need to provide more IOCTLs for use from User Mode code.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;User Mode code accesses these IOCTLS through a new oalioctl.dll. The code for oalioctl.dll is available in %_WINCEROOT%\Public\Common\Oak\Oalioctl, so I won’t publish the code here. But basically it has an IoControl function that has a switch statement which limits access to OEMIoControl(). So to add more IOCTLs, we need to clone the code and change the switch statement.&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt"&gt;
&lt;div style="MARGIN: 0in 0in 0pt; TEXT-INDENT: -0.25in; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;Copyright © 2008 – Bruce Eitman&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt; TEXT-INDENT: -0.25in; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;All Rights Reserved&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123502"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=123502" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BruceEitman/aggbug/123502.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Bruce Eitman</dc:creator>
            <guid>http://geekswithblogs.net/BruceEitman/archive/2008/07/01/windows-ce-6.0-user-mode-kerneliocontrol.aspx</guid>
            <pubDate>Tue, 01 Jul 2008 06:21:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BruceEitman/comments/123502.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BruceEitman/archive/2008/07/01/windows-ce-6.0-user-mode-kerneliocontrol.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BruceEitman/comments/commentRss/123502.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Windows CE:  Why does my system halt for 20 minutes?</title>
            <link>http://geekswithblogs.net/BruceEitman/archive/2008/05/12/windows-ce--why-does-my-system-halt-for-20.aspx</link>
            <description>&lt;span style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'; mso-fareast-font-family: 'Times New Roman'; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA"&gt;
&lt;p&gt;I don't know how many systems are affected by this problem, but apparently there are still some.  I do know that the reference BSP for the Intel PXA25x processor boards has a problem.  This problem is still biting people because there have recently been questions about it in the Platform Builder newsgroup.&lt;/p&gt;
&lt;p&gt;The cause is really quite simple.  A shared resource with nothing to protect it from interrupts during read-modify-write operations.&lt;/p&gt;
&lt;p&gt;In this case, there are two sets of code that access the time match register.  One is in OEMIdle() which is called when the scheduler doesn't have any threads to run.  The other is in the system timer Interrupt Service Routine (ISR).&lt;/p&gt;
&lt;p&gt;The timer match register (OSMR0) is used with the timer counter register (OSCR) to cause an interrupt to occur when a certain time is reached.  When the two registers contain the same value the interrupt is fired.   The counter register increments with the CPU ocsilator.  Both registers roll over in just under 20 minutes.  Anyone see a coorilation between that rollover and the amount of time that the system halts?&lt;/p&gt;
&lt;p&gt;So what is happening in the reference BSP?  The code in OEMIdle is setting the match register by:&lt;/p&gt;
&lt;p&gt; 1.  Reading the OSCR value&lt;br /&gt;
 2.  Adding something to it &lt;br /&gt;
 3.  Then writing it to OSMR0&lt;/p&gt;
&lt;p&gt;That makes sense, unless you consider that the interrupts are still enabled.  Imagine that the time interrupt fires just after reading the OSCR and before writing it back.  And maybe we have one or more other interrupts.  If everything goes wrong for us, by the time we write OSMR0, OSCR has incremented past OSMR0.  That means that we must wait until OSCR rolls over to reach a match with OSMR0 and the next system tick occurs.&lt;/p&gt;
&lt;p&gt;How can you know if this is happening?  A simple application that outputs the current time and the current tick count can tell you.  If the output indicates that 20 minutes past and the current tick count didn't increment, you have this problem.&lt;/p&gt;
&lt;p&gt;How can you fix it?  Disable interrupts while modifying the counter register.&lt;/p&gt;
&lt;div style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;Copyright © 2008 – Bruce Eitman&lt;/span&gt;&lt;/div&gt;
&lt;div style="MARGIN: 0in 0in 10pt; LINE-HEIGHT: normal" align="center"&gt;&lt;span style="FONT-SIZE: 9pt"&gt;All Rights Reserved&lt;/span&gt;&lt;/div&gt;
&lt;/span&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122093"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=122093" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/BruceEitman/aggbug/122093.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Bruce Eitman</dc:creator>
            <guid>http://geekswithblogs.net/BruceEitman/archive/2008/05/12/windows-ce--why-does-my-system-halt-for-20.aspx</guid>
            <pubDate>Mon, 12 May 2008 22:26:26 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/BruceEitman/comments/122093.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/BruceEitman/archive/2008/05/12/windows-ce--why-does-my-system-halt-for-20.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/BruceEitman/comments/commentRss/122093.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>