Newer
Older
UbixOS / doc / html / smp_8c-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>UbixOS V2: src/sys/kernel/smp.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
  <ul>
    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="classes.html"><span>Data&nbsp;Structures</span></a></li>
    <li id="current"><a href="files.html"><span>Files</span></a></li>
    <li><a href="dirs.html"><span>Directories</span></a></li>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="files.html"><span>File&nbsp;List</span></a></li>
    <li><a href="globals.html"><span>Globals</span></a></li>
  </ul></div>
<div class="nav">
<a class="el" href="dir_897b6a2d7bab147dd1db58381aad3984.html">src</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_832905b1f7f5feaf61a306b40c0ac817.html">sys</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_7efffd2b1fae7bb6f2aa85845c863494.html">kernel</a></div>
<h1>smp.c</h1><a href="smp_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*****************************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment"> Copyright (c) 2002 The UbixOS Project</span>
<a name="l00003"></a>00003 <span class="comment"> All rights reserved.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment">Redistribution and use in source and binary forms, with or without modification, are</span>
<a name="l00006"></a>00006 <span class="comment">permitted provided that the following conditions are met:</span>
<a name="l00007"></a>00007 <span class="comment"></span>
<a name="l00008"></a>00008 <span class="comment">Redistributions of source code must retain the above copyright notice, this list of</span>
<a name="l00009"></a>00009 <span class="comment">conditions, the following disclaimer and the list of authors.  Redistributions in binary</span>
<a name="l00010"></a>00010 <span class="comment">form must reproduce the above copyright notice, this list of conditions, the following</span>
<a name="l00011"></a>00011 <span class="comment">disclaimer and the list of authors in the documentation and/or other materials provided</span>
<a name="l00012"></a>00012 <span class="comment">with the distribution. Neither the name of the UbixOS Project nor the names of its</span>
<a name="l00013"></a>00013 <span class="comment">contributors may be used to endorse or promote products derived from this software</span>
<a name="l00014"></a>00014 <span class="comment">without specific prior written permission.</span>
<a name="l00015"></a>00015 <span class="comment"></span>
<a name="l00016"></a>00016 <span class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY</span>
<a name="l00017"></a>00017 <span class="comment">EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF</span>
<a name="l00018"></a>00018 <span class="comment">MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL</span>
<a name="l00019"></a>00019 <span class="comment">THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,</span>
<a name="l00020"></a>00020 <span class="comment">SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT</span>
<a name="l00021"></a>00021 <span class="comment">OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)</span>
<a name="l00022"></a>00022 <span class="comment">HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR</span>
<a name="l00023"></a>00023 <span class="comment">TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00024"></a>00024 <span class="comment">SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00025"></a>00025 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment"> $Id: smp_8c-source.html 88 2016-01-12 00:11:29Z reddawg $</span>
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">*****************************************************************************************/</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="preprocessor">#include &lt;<a class="code" href="smp_8h.html">ubixos/smp.h</a>&gt;</span>
<a name="l00031"></a>00031 <span class="preprocessor">#include &lt;<a class="code" href="spinlock_8h.html">ubixos/spinlock.h</a>&gt;</span>
<a name="l00032"></a>00032 <span class="preprocessor">#include &lt;<a class="code" href="kpanic_8h.html">ubixos/kpanic.h</a>&gt;</span>
<a name="l00033"></a>00033 <span class="preprocessor">#include &lt;<a class="code" href="kprintf_8h.html">lib/kprintf.h</a>&gt;</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include &lt;<a class="code" href="lib_2string_8h.html">lib/string.h</a>&gt;</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include &lt;<a class="code" href="io_8h.html">sys/io.h</a>&gt;</span>
<a name="l00036"></a>00036 
<a name="l00037"></a><a class="code" href="smp_8c.html#9a5fd10dce49f2fe147d346b8de71902">00037</a> <span class="keyword">static</span> <a class="code" href="spinlock_8h.html#a240e9404b4ede1e0d714610080d1176">spinLock_t</a> <a class="code" href="smp_8c.html#9a5fd10dce49f2fe147d346b8de71902">initSpinLock</a> = <a class="code" href="spinlock_8h.html#0fe85a4f3642683148b25916d6c5eafd">SPIN_LOCK_INITIALIZER</a>;
<a name="l00038"></a><a class="code" href="smp_8c.html#d5f78a3dc61e0ca7819dc3d5d5794419">00038</a> <span class="keyword">static</span> <a class="code" href="spinlock_8h.html#a240e9404b4ede1e0d714610080d1176">spinLock_t</a> <a class="code" href="smp_8c.html#d5f78a3dc61e0ca7819dc3d5d5794419">cpuInfoLock</a> = <a class="code" href="spinlock_8h.html#0fe85a4f3642683148b25916d6c5eafd">SPIN_LOCK_INITIALIZER</a>;
<a name="l00039"></a><a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">00039</a> <span class="keyword">static</span> <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> <a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a> = 0;
<a name="l00040"></a><a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">00040</a> <span class="keyword">struct </span><a class="code" href="structcpuinfo__t.html">cpuinfo_t</a> <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[8];
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <a class="code" href="types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>(<span class="keywordtype">void</span>);
<a name="l00043"></a><a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">00043</a> <a class="code" href="types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> *<a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a> = (<a class="code" href="types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> *)0xB8000;
<a name="l00044"></a>00044 
<a name="l00045"></a><a class="code" href="smp_8c.html#98935271c68a482c194d4c784d814ddd">00045</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="smp_8c.html#98935271c68a482c194d4c784d814ddd">apicRead</a>(address) {
<a name="l00046"></a>00046   <span class="keywordflow">return</span> *(<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) (0xFEE00000 + address);
<a name="l00047"></a>00047   }
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">00049</a> <span class="keyword">static</span> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">apicWrite</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> address,<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> data) {
<a name="l00050"></a>00050   *(<span class="keyword">volatile</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *) (0xFEE00000 + address) = data;
<a name="l00051"></a>00051   }
<a name="l00052"></a>00052 
<a name="l00053"></a><a class="code" href="smp_8c.html#5607ecf06fd77905053dbb15eaf0ff6b">00053</a> <span class="keyword">static</span> __inline__ <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#5607ecf06fd77905053dbb15eaf0ff6b">setDr3</a> (<span class="keywordtype">void</span> *dr3) {
<a name="l00054"></a>00054   <span class="keyword">register</span> <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> value = (<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a>)dr3;
<a name="l00055"></a>00055   __asm__ __volatile__ (<span class="stringliteral">"mov %0, %%dr3"</span> :: <span class="stringliteral">"r"</span> (value));
<a name="l00056"></a>00056   }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="smp_8c.html#0f6e384fb3ad325aa2406af715ff341d">00058</a> <span class="keyword">static</span> __inline__ <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> <a class="code" href="smp_8c.html#0f6e384fb3ad325aa2406af715ff341d">getDr3</a> (<span class="keywordtype">void</span>) {
<a name="l00059"></a>00059   <span class="keyword">register</span> <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> value;
<a name="l00060"></a>00060   __asm__ __volatile__ (<span class="stringliteral">"mov %%dr3, %0"</span> : <span class="stringliteral">"=r"</span> (value));
<a name="l00061"></a>00061   <span class="keywordflow">return</span> value;
<a name="l00062"></a>00062   }
<a name="l00063"></a>00063 
<a name="l00064"></a><a class="code" href="structgdt__descr.html">00064</a> <span class="keyword">struct </span><a class="code" href="structgdt__descr.html">gdt_descr</a> {
<a name="l00065"></a><a class="code" href="structgdt__descr.html#2c59f0ca24b900a4bfc00019185296b7">00065</a>   <a class="code" href="types_8h.html#3b65128d2644e9b80cec9a69bfa7e094">uInt16</a>  <a class="code" href="structgdt__descr.html#2c59f0ca24b900a4bfc00019185296b7">limit</a>;
<a name="l00066"></a>00066   <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *base <a class="code" href="structgdt__descr.html#9c540c5e1672426b7c6430e1b2f66fba">__attribute__</a> ((<a class="code" href="gdt_8h.html#a8e25552752eade51544ff9e9fbd7bdf">packed</a>));
<a name="l00067"></a>00067 };
<a name="l00068"></a>00068 
<a name="l00069"></a><a class="code" href="smp_8c.html#b9f1e8692e06eb164641f50aa4d7aed6">00069</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#b9f1e8692e06eb164641f50aa4d7aed6">GDT_fixer</a>() {
<a name="l00070"></a>00070   <span class="keyword">struct </span><a class="code" href="structgdt__descr.html">gdt_descr</a>  gdt_descr;
<a name="l00071"></a>00071   <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *gdt = (<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *)0x20000; <span class="comment">// 128KB</span>
<a name="l00072"></a>00072 
<a name="l00073"></a>00073   gdt[0] = 0;
<a name="l00074"></a>00074   gdt[1] = 0;
<a name="l00075"></a>00075   gdt[2] = 0x0000ffff; <span class="comment">// seg 0x8  -- DPL 0 4GB code</span>
<a name="l00076"></a>00076   gdt[3] = 0x00cf9a00;
<a name="l00077"></a>00077   gdt[4] = 0x0000ffff; <span class="comment">// seg 0x10 -- DPL 0 4GB data</span>
<a name="l00078"></a>00078   gdt[5] = 0x00cf9200;
<a name="l00079"></a>00079   gdt[6] = 0x0000ffff; <span class="comment">// seg 0x1b -- DPL 3 4GB code</span>
<a name="l00080"></a>00080   gdt[7] = 0x00cffa00;
<a name="l00081"></a>00081   gdt[8] = 0x0000ffff; <span class="comment">// seg 0x23 -- DPL 3 4GB data</span>
<a name="l00082"></a>00082   gdt[9] = 0x00cff200;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084   gdt_descr.<a class="code" href="structgdt__descr.html#2c59f0ca24b900a4bfc00019185296b7">limit</a> = 32 * 4;
<a name="l00085"></a>00085   gdt_descr.base  = gdt;
<a name="l00086"></a>00086 
<a name="l00087"></a>00087   <span class="comment">/*</span>
<a name="l00088"></a>00088 <span class="comment">  asm("lgdt %0;" : : "m" (gdt_descr));</span>
<a name="l00089"></a>00089 <span class="comment">  __asm__ __volatile__ ("ljmp %0,$1f; 1:" :: "i" (0x08));</span>
<a name="l00090"></a>00090 <span class="comment">  __asm__ __volatile__ ("movw %w0,%%ds" :: "r" (0x10));</span>
<a name="l00091"></a>00091 <span class="comment">  __asm__ __volatile__ ("movw %w0,%%es" :: "r" (0x10));</span>
<a name="l00092"></a>00092 <span class="comment">  __asm__ __volatile__ ("movw %w0,%%ss" :: "r" (0x10));</span>
<a name="l00093"></a>00093 <span class="comment">  */</span>
<a name="l00094"></a>00094   }
<a name="l00095"></a>00095 
<a name="l00096"></a>00096 
<a name="l00097"></a><a class="code" href="smp_8c.html#66c37e11ba7abfcafc63146553b2cd16">00097</a> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#66c37e11ba7abfcafc63146553b2cd16">cpu0_thread</a>(<span class="keywordtype">void</span>) {
<a name="l00098"></a>00098   <span class="keywordflow">for</span>(;;) {
<a name="l00099"></a>00099     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[40+640] = <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>();
<a name="l00100"></a>00100     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[42+640]++;
<a name="l00101"></a>00101   }
<a name="l00102"></a>00102 }
<a name="l00103"></a><a class="code" href="smp_8c.html#5e82e9f1e0fec1ac5db2ebd16652a043">00103</a> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#5e82e9f1e0fec1ac5db2ebd16652a043">cpu1_thread</a>(<span class="keywordtype">void</span>) {
<a name="l00104"></a>00104   <span class="keywordflow">for</span>(;;) {
<a name="l00105"></a>00105     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[60+640] = <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>();
<a name="l00106"></a>00106     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[62+640]++;
<a name="l00107"></a>00107   }
<a name="l00108"></a>00108 }
<a name="l00109"></a><a class="code" href="smp_8c.html#cfec913213194039ad31b2602bf8af4f">00109</a> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#cfec913213194039ad31b2602bf8af4f">cpu2_thread</a>(<span class="keywordtype">void</span>) {
<a name="l00110"></a>00110   <span class="keywordflow">for</span>(;;) {
<a name="l00111"></a>00111     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[80+640] = <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>();
<a name="l00112"></a>00112     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[82+640]++;
<a name="l00113"></a>00113   }
<a name="l00114"></a>00114 }
<a name="l00115"></a><a class="code" href="smp_8c.html#13735e9644e3c9a01bfc7785b31691ab">00115</a> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#13735e9644e3c9a01bfc7785b31691ab">cpu3_thread</a>(<span class="keywordtype">void</span>) {
<a name="l00116"></a>00116   <span class="keywordflow">for</span>(;;) {
<a name="l00117"></a>00117     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[100+640] = <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>();
<a name="l00118"></a>00118     <a class="code" href="smp_8c.html#5f2d0854cc28b4f2ef16a03061d9d237">vram</a>[102+640]++;
<a name="l00119"></a>00119   }
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 
<a name="l00122"></a><a class="code" href="smp_8c.html#71085af55092ee7b25d4bd346169ce89">00122</a> <span class="keyword">static</span> <a class="code" href="spinlock_8h.html#a240e9404b4ede1e0d714610080d1176">spinLock_t</a> <a class="code" href="smp_8c.html#71085af55092ee7b25d4bd346169ce89">bkl</a> = <a class="code" href="spinlock_8h.html#0fe85a4f3642683148b25916d6c5eafd">SPIN_LOCK_INITIALIZER</a>;
<a name="l00123"></a><a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">00123</a> <a class="code" href="types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> <a class="code" href="smp_8c.html#0844b0ab23ee41899fc5d622078d20d6">kernel_function</a>(<span class="keywordtype">void</span>) {
<a name="l00124"></a>00124   <span class="keyword">struct </span><a class="code" href="structcpuinfo__t.html">cpuinfo_t</a> *cpu;
<a name="l00125"></a>00125 
<a name="l00126"></a>00126   <a class="code" href="spinlock_8h.html#2cd9a4502680fb8e7f0fe6b029e558b1">spinLock</a>(&amp;bkl);
<a name="l00127"></a>00127 
<a name="l00128"></a>00128 
<a name="l00129"></a>00129   cpu = (<span class="keyword">struct </span><a class="code" href="structcpuinfo__t.html">cpuinfo_t</a> *)<a class="code" href="smp_8c.html#0f6e384fb3ad325aa2406af715ff341d">getDr3</a>();
<a name="l00130"></a>00130 
<a name="l00131"></a>00131   <a class="code" href="spinlock_8h.html#dd996cbbb3b9826dd9c8cf02b66a4c65">spinUnlock</a>(&amp;bkl);
<a name="l00132"></a>00132 
<a name="l00133"></a>00133   <span class="keywordflow">return</span>(<span class="charliteral">'0'</span> + cpu-&gt;<a class="code" href="structcpuinfo__t.html#f5c4407ffad5df94902b218355267260">id</a>);
<a name="l00134"></a>00134 }
<a name="l00135"></a>00135 
<a name="l00136"></a>00136 
<a name="l00137"></a><a class="code" href="smp_8c.html#c7cb5b4b2fbc61966a6dfc8044a7b800">00137</a> <span class="keywordtype">void</span> <a class="code" href="smp_8c.html#c7cb5b4b2fbc61966a6dfc8044a7b800">c_ap_boot</a>(<span class="keywordtype">void</span>) {
<a name="l00138"></a>00138 
<a name="l00139"></a>00139   <span class="keywordflow">while</span>(<a class="code" href="spinlock_8h.html#cba75fe5ed894dc88030f7458b114a94">spinLockLocked</a>(&amp;<a class="code" href="smp_8c.html#9a5fd10dce49f2fe147d346b8de71902">initSpinLock</a>));
<a name="l00140"></a>00140 
<a name="l00141"></a>00141   <span class="keywordflow">switch</span>(<a class="code" href="smp_8h.html#452f210aee65a2a30cbc5cb8923a9881">cpuInfo</a>()) {
<a name="l00142"></a>00142   <span class="keywordflow">case</span> 1:
<a name="l00143"></a>00143     <a class="code" href="smp_8c.html#5e82e9f1e0fec1ac5db2ebd16652a043">cpu1_thread</a>();
<a name="l00144"></a>00144     <span class="keywordflow">break</span>;
<a name="l00145"></a>00145   <span class="keywordflow">case</span> 2:
<a name="l00146"></a>00146     <a class="code" href="smp_8c.html#cfec913213194039ad31b2602bf8af4f">cpu2_thread</a>();
<a name="l00147"></a>00147     <span class="keywordflow">break</span>;
<a name="l00148"></a>00148   <span class="keywordflow">case</span> 3:
<a name="l00149"></a>00149     <a class="code" href="smp_8c.html#13735e9644e3c9a01bfc7785b31691ab">cpu3_thread</a>();
<a name="l00150"></a>00150     <span class="keywordflow">break</span>;
<a name="l00151"></a>00151   }
<a name="l00152"></a>00152 
<a name="l00153"></a>00153   <a class="code" href="io_8h.html#8acc1a06073db2e7b92ffbd00fbd0cf1">outportByte</a>(0<a class="code" href="ap-boot_8S.html#d58beb3879ac361d068b0618ba2d7620">xe9</a>,<span class="charliteral">'5'</span>);
<a name="l00154"></a>00154 
<a name="l00155"></a>00155   <span class="keywordflow">for</span>(;;) {
<a name="l00156"></a>00156     <span class="keyword">asm</span>(<span class="stringliteral">"nop"</span>);
<a name="l00157"></a>00157   }
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160 
<a name="l00161"></a><a class="code" href="smp_8c.html#ce31619db109aa8b20a916d48969928d">00161</a> <span class="keywordtype">void</span> <a class="code" href="smp_8h.html#ce31619db109aa8b20a916d48969928d">smpInit</a>() {
<a name="l00162"></a>00162   <a class="code" href="spinlock_8h.html#2cd9a4502680fb8e7f0fe6b029e558b1">spinLock</a>(&amp;<a class="code" href="smp_8c.html#9a5fd10dce49f2fe147d346b8de71902">initSpinLock</a>);
<a name="l00163"></a>00163   <a class="code" href="smp_8c.html#b9f1e8692e06eb164641f50aa4d7aed6">GDT_fixer</a>();
<a name="l00164"></a>00164   <a class="code" href="smp_8h.html#c89d80447fce7d622c7dfc6620039600">cpuidDetect</a>();
<a name="l00165"></a>00165   <a class="code" href="smp_8h.html#452f210aee65a2a30cbc5cb8923a9881">cpuInfo</a>();
<a name="l00166"></a>00166   <a class="code" href="smp_8h.html#fb282ad2f10cfff4d0da79689e6dfc82">apicMagic</a>();
<a name="l00167"></a>00167   <a class="code" href="spinlock_8h.html#dd996cbbb3b9826dd9c8cf02b66a4c65">spinUnlock</a>(&amp;<a class="code" href="smp_8c.html#9a5fd10dce49f2fe147d346b8de71902">initSpinLock</a>);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169   <span class="comment">//cpu0_thread(); </span>
<a name="l00170"></a>00170  
<a name="l00171"></a>00171   }
<a name="l00172"></a>00172 
<a name="l00173"></a><a class="code" href="smp_8c.html#c89d80447fce7d622c7dfc6620039600">00173</a> <span class="keywordtype">void</span> <a class="code" href="smp_8h.html#c89d80447fce7d622c7dfc6620039600">cpuidDetect</a>() {
<a name="l00174"></a>00174   <span class="keywordflow">if</span> (!(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() &amp; (1&lt;&lt;21)) ) {
<a name="l00175"></a>00175     <a class="code" href="smp_8h.html#d58e8f36b58bd7c198307a1f012fd975">setEflags</a>(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() | (1&lt;&lt;21));
<a name="l00176"></a>00176     <span class="keywordflow">if</span>( !(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() &amp; (1&lt;&lt;21)) ) {
<a name="l00177"></a>00177       <a class="code" href="kpanic_8h.html#db9a182aa071791a306163d50d653deb">kpanic</a>(<span class="stringliteral">"CPU doesn't support CPUID, get a newer machine\n"</span>);
<a name="l00178"></a>00178       }
<a name="l00179"></a>00179     }
<a name="l00180"></a>00180   }
<a name="l00181"></a>00181 
<a name="l00182"></a><a class="code" href="smp_8c.html#452f210aee65a2a30cbc5cb8923a9881">00182</a> <a class="code" href="types_8h.html#a4e0f27a9aca905e340c06d2dcae843c">uInt8</a> <a class="code" href="smp_8h.html#452f210aee65a2a30cbc5cb8923a9881">cpuInfo</a>() {
<a name="l00183"></a>00183   <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> data[4],i;
<a name="l00184"></a>00184 
<a name="l00185"></a>00185   <span class="keywordflow">if</span>( !(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() &amp; (1&lt;&lt;21)) ) {       <span class="comment">// If the cpuid bit in eflags not set..</span>
<a name="l00186"></a>00186     <a class="code" href="smp_8h.html#d58e8f36b58bd7c198307a1f012fd975">setEflags</a>(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() | (1&lt;&lt;21));   <span class="comment">// ..try and set it to see if it comes on..</span>
<a name="l00187"></a>00187     <span class="keywordflow">if</span>( !(<a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() &amp; (1&lt;&lt;21)) ) {     <span class="comment">// It didn't.. This CPU suck</span>
<a name="l00188"></a>00188       <a class="code" href="kpanic_8h.html#db9a182aa071791a306163d50d653deb">kpanic</a>(<span class="stringliteral">"CPU doesn't support CPUID, get a newer machine\n"</span>);
<a name="l00189"></a>00189     }
<a name="l00190"></a>00190   }
<a name="l00191"></a>00191 
<a name="l00192"></a>00192   <a class="code" href="spinlock_8h.html#2cd9a4502680fb8e7f0fe6b029e558b1">spinLock</a>(&amp;<a class="code" href="smp_8c.html#d5f78a3dc61e0ca7819dc3d5d5794419">cpuInfoLock</a>);
<a name="l00193"></a>00193   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#55e6db773b2ec5602b132fe54ef2da27">ok</a> = 1;
<a name="l00194"></a>00194   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#a76ba6d81506e6a5d086cb8c61a6246f">apic_id</a>  = <a class="code" href="smp_8c.html#98935271c68a482c194d4c784d814ddd">apicRead</a>(0<a class="code" href="start_8S.html#62df326d54f8b2ece412319c4360ef3e">x20</a>) &gt;&gt; 24;
<a name="l00195"></a>00195   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#7b9f17434cf958ae23150aea98a91724">apic_ver</a> = <a class="code" href="smp_8c.html#98935271c68a482c194d4c784d814ddd">apicRead</a>(0<a class="code" href="ap-boot_8S.html#c2a218176530ced267bbcc8042da1000">x30</a>) &amp; 0xFF;
<a name="l00196"></a>00196 
<a name="l00197"></a>00197   <a class="code" href="smp_8h.html#8e797e0b8a36194fca8fa45767974c2f">cpuid</a>(0,data);
<a name="l00198"></a>00198   *(<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#e529ad76c06841e1f825296d0ec107a0">ident</a>[0] = data[1];
<a name="l00199"></a>00199   *(<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#e529ad76c06841e1f825296d0ec107a0">ident</a>[4] = data[3];
<a name="l00200"></a>00200   *(<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#e529ad76c06841e1f825296d0ec107a0">ident</a>[8] = data[2];
<a name="l00201"></a>00201   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#e529ad76c06841e1f825296d0ec107a0">ident</a>[17] = 0;
<a name="l00202"></a>00202   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#666edb35af6b506907e999f0c29ee91f">max</a> = data[0];
<a name="l00203"></a>00203 
<a name="l00204"></a>00204   <a class="code" href="smp_8h.html#8e797e0b8a36194fca8fa45767974c2f">cpuid</a>(1,data);
<a name="l00205"></a>00205   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#4dc954f30d7ac869a43702bc6a0389dc">signature</a> = data[0];
<a name="l00206"></a>00206   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#b8935d0ed0f78c40e238027b807d2ee7">feature</a>   = data[3];
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   <a class="code" href="smp_8h.html#8e797e0b8a36194fca8fa45767974c2f">cpuid</a>(0x80000000,data);
<a name="l00209"></a>00209   <span class="keywordflow">if</span>(data[0]&gt;=0x80000004) {
<a name="l00210"></a>00210     <span class="keywordflow">for</span>(i=0;i&lt;3;i++) {
<a name="l00211"></a>00211       <a class="code" href="smp_8h.html#8e797e0b8a36194fca8fa45767974c2f">cpuid</a>(0x80000002 + i,data);
<a name="l00212"></a>00212 
<a name="l00213"></a>00213       *(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[16*i+0]  = data[0];
<a name="l00214"></a>00214       *(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[16*i+4]  = data[1];
<a name="l00215"></a>00215       *(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[16*i+8]  = data[2];
<a name="l00216"></a>00216       *(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> *)&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[16*i+12] = data[3];
<a name="l00217"></a>00217     }
<a name="l00218"></a>00218     <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[48] = 0;
<a name="l00219"></a>00219   } <span class="keywordflow">else</span> {
<a name="l00220"></a>00220     <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>].<a class="code" href="structcpuinfo__t.html#bf3a842f1c5959d5a6abf52bda0b7dae">brand</a>[0] = 0;
<a name="l00221"></a>00221   }
<a name="l00222"></a>00222 
<a name="l00223"></a>00223   <a class="code" href="smp_8c.html#5607ecf06fd77905053dbb15eaf0ff6b">setDr3</a>(&amp;<a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[<a class="code" href="smp_8c.html#29c1aa6c61dfac505825b96920fa447d">cpus</a>]); <span class="comment">// DR3 always points to the cpu-struct for that CPU (should be thread-struct of current thread)</span>
<a name="l00224"></a>00224   <a class="code" href="smp_8c.html#963def6fffd92dece6dd156abbcf4fa0">cpuinfo</a>[cpus].<a class="code" href="structcpuinfo__t.html#f5c4407ffad5df94902b218355267260">id</a> = cpus;
<a name="l00225"></a>00225 
<a name="l00226"></a>00226   cpus++;
<a name="l00227"></a>00227 
<a name="l00228"></a>00228   <a class="code" href="spinlock_8h.html#dd996cbbb3b9826dd9c8cf02b66a4c65">spinUnlock</a>(&amp;<a class="code" href="smp_8c.html#d5f78a3dc61e0ca7819dc3d5d5794419">cpuInfoLock</a>);
<a name="l00229"></a>00229 
<a name="l00230"></a>00230   <span class="keywordflow">return</span>(cpus - 1);
<a name="l00231"></a>00231   }
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 <span class="keyword">extern</span> <span class="keywordtype">void</span> <a class="code" href="ap-boot_8S.html#b1cb92a8709c60591691af45d450d9f3">ap_trampoline_start</a>(),<a class="code" href="smp_8c.html#e4dc28abba9d6b02a779ca1b8ffecd98">ap_trampoline_end</a>();
<a name="l00234"></a><a class="code" href="smp_8c.html#70e557cb01aee676855cee05b0769288">00234</a> <span class="keywordtype">void</span> <a class="code" href="smp_8h.html#fb282ad2f10cfff4d0da79689e6dfc82">apicMagic</a>(<span class="keywordtype">void</span>) {
<a name="l00235"></a>00235   <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> tmp;
<a name="l00236"></a>00236 
<a name="l00237"></a>00237   <a class="code" href="kprint_8h.html#b2761bdf0cca73ad0fb5880895210cd8">kprintf</a>(<span class="stringliteral">"Copying %u bytes from 0x%x to 0x00\n"</span>,<a class="code" href="smp_8c.html#e4dc28abba9d6b02a779ca1b8ffecd98">ap_trampoline_end</a> - <a class="code" href="ap-boot_8S.html#b1cb92a8709c60591691af45d450d9f3">ap_trampoline_start</a>,<a class="code" href="ap-boot_8S.html#b1cb92a8709c60591691af45d450d9f3">ap_trampoline_start</a>);
<a name="l00238"></a>00238   <a class="code" href="lib_2string_8h.html#e33b18edb618c656b9b795b9fce2316c">memcpy</a>(0x0,(<span class="keywordtype">char</span> *)<a class="code" href="ap-boot_8S.html#b1cb92a8709c60591691af45d450d9f3">ap_trampoline_start</a>,<a class="code" href="smp_8c.html#e4dc28abba9d6b02a779ca1b8ffecd98">ap_trampoline_end</a> - ap_trampoline_start);
<a name="l00239"></a>00239   <a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">apicWrite</a>(0x280,0);
<a name="l00240"></a>00240   <a class="code" href="smp_8c.html#98935271c68a482c194d4c784d814ddd">apicRead</a>(0x280);
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   <a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">apicWrite</a>(0x300,0x000C4500);  <span class="comment">// INIT IPI to all CPUs</span>
<a name="l00243"></a>00243   <span class="keywordflow">for</span>(tmp=0;tmp&lt;800000;tmp++) <span class="keyword">asm</span>(<span class="stringliteral">"nop"</span>); <span class="comment">// Sleep a little (should be 10ms)</span>
<a name="l00244"></a>00244   <a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">apicWrite</a>(0x300,0x000C4600);  <span class="comment">// INIT SIPI to all CPUs</span>
<a name="l00245"></a>00245   <span class="keywordflow">for</span>(tmp=0;tmp&lt;800000;tmp++) <span class="keyword">asm</span>(<span class="stringliteral">"nop"</span>); <span class="comment">// Sleep a little (should be 200ms)</span>
<a name="l00246"></a>00246   <a class="code" href="smp_8c.html#ab4a831897afae67446bf78c88123749">apicWrite</a>(0x300,0x000C4600);  <span class="comment">// Second INIT SIPI</span>
<a name="l00247"></a>00247   <span class="keywordflow">for</span>(tmp=0;tmp&lt;800000;tmp++) <span class="keyword">asm</span>(<span class="stringliteral">"nop"</span>); <span class="comment">// Sleep a little (should be 200ms)</span>
<a name="l00248"></a>00248   }
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 
<a name="l00252"></a><a class="code" href="smp_8c.html#abe8182d15984977e87831f32527ff78">00252</a> <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> <a class="code" href="smp_8h.html#abe8182d15984977e87831f32527ff78">getEflags</a>() {
<a name="l00253"></a>00253   <a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> eflags = 0x0;
<a name="l00254"></a>00254   <span class="keyword">asm</span>(
<a name="l00255"></a>00255     <span class="stringliteral">"pushfl     \n"</span>
<a name="l00256"></a>00256     <span class="stringliteral">"popl %%eax \n"</span>
<a name="l00257"></a>00257     : <span class="stringliteral">"=a"</span> (eflags)
<a name="l00258"></a>00258     );
<a name="l00259"></a>00259   <span class="keywordflow">return</span>(eflags);
<a name="l00260"></a>00260   }
<a name="l00261"></a>00261 
<a name="l00262"></a><a class="code" href="smp_8c.html#133d6aaf4635e4585ee54a0438d0bf36">00262</a> <span class="keywordtype">void</span> <a class="code" href="smp_8h.html#d58e8f36b58bd7c198307a1f012fd975">setEflags</a>(<a class="code" href="types_8h.html#5847ea0262a5aa61eee48cbe95544a78">uInt32</a> eflags) {
<a name="l00263"></a>00263   <span class="keyword">asm</span>(
<a name="l00264"></a>00264     <span class="stringliteral">"pushl %%eax \n"</span>
<a name="l00265"></a>00265     <span class="stringliteral">"popfl       \n"</span>
<a name="l00266"></a>00266     :
<a name="l00267"></a>00267     : <span class="stringliteral">"a"</span> (eflags)
<a name="l00268"></a>00268     );
<a name="l00269"></a>00269   }
<a name="l00270"></a>00270 
<a name="l00271"></a>00271 <span class="keyword">asm</span>(
<a name="l00272"></a>00272   <span class="stringliteral">".globl cpuid            \n"</span>
<a name="l00273"></a>00273   <span class="stringliteral">"cpuid:                  \n"</span>
<a name="l00274"></a>00274   <span class="stringliteral">"  pushl   %ebx          \n"</span>
<a name="l00275"></a>00275   <span class="stringliteral">"  pushl   %edi          \n"</span>
<a name="l00276"></a>00276   <span class="stringliteral">"  movl    12(%esp),%eax \n"</span>
<a name="l00277"></a>00277   <span class="stringliteral">"  movl    16(%esp),%edi \n"</span>
<a name="l00278"></a>00278   <span class="stringliteral">"  cpuid                 \n"</span>
<a name="l00279"></a>00279   <span class="stringliteral">"  movl    %eax,0(%edi)  \n"</span>
<a name="l00280"></a>00280   <span class="stringliteral">"  movl    %ebx,4(%edi)  \n"</span>
<a name="l00281"></a>00281   <span class="stringliteral">"  movl    %ecx,8(%edi)  \n"</span>
<a name="l00282"></a>00282   <span class="stringliteral">"  movl    %edx,12(%edi) \n"</span>
<a name="l00283"></a>00283   <span class="stringliteral">"  popl    %edi          \n"</span>
<a name="l00284"></a>00284   <span class="stringliteral">"  popl    %ebx          \n"</span>
<a name="l00285"></a>00285   <span class="stringliteral">"  ret                   \n"</span>
<a name="l00286"></a>00286   );
<a name="l00287"></a>00287  
<a name="l00288"></a>00288 <span class="comment">/***</span>
<a name="l00289"></a>00289 <span class="comment"> END</span>
<a name="l00290"></a>00290 <span class="comment"> ***/</span>
<a name="l00291"></a>00291 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Fri Dec 15 11:18:55 2006 for UbixOS V2 by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>