📄 head.s
字号:
<!doctype html public "-//W3C//DTD HTML 3.2//EN"><html><head><title>Linux/boot/head.s</title><meta http-equiv=Content-Type content="text/html; charset=gb2312"><base href="http://oldlinux.org/lxr/http/"></head><body bgcolor=white><div align=center> [<b><i>源代码浏览</i></b>] [<a href="diff/boot/head.s">区别标定</a>] [<a href="ident">标识符搜索</a>] [<a href="search">文本搜索</a>] [<a href="find">文件搜索</a>]</div><h1 align=center> <a href="http:/"> OldLinux</a> <a href="http:blurb.html"> 交叉引用</a><br> <a href="source/">Linux</a>/<a href="source/boot/">boot</a>/<a href="source/boot/head.s">head.s</a></h1><div align=center> <b>版本:</b> [<a href="source/boot/head.s?v=1.0">1.0</a>] [<a href="source/boot/head.s?v=0.99.11">0.99.11</a>] [<a href="source/boot/head.s?v=0.99">0.99</a>] [<a href="source/boot/head.s?v=0.97">0.97</a>] [<a href="source/boot/head.s?v=0.96a">0.96a</a>] [<a href="source/boot/head.s?v=0.95">0.95</a>] [<a href="source/boot/head.s?v=0.12">0.12</a>] [<b><i>0.11</i></b>] [<a href="source/boot/head.s?v=0.01">0.01</a>] <br> <b>体系结构:</b> [<b><i>i386</i></b>] <br></div><hr><pre> <a name=L1 href="source/boot/head.s#L1">1</a> /* <a name=L2 href="source/boot/head.s#L2">2</a> * linux/boot/head.s <a name=L3 href="source/boot/head.s#L3">3</a> * <a name=L4 href="source/boot/head.s#L4">4</a> * (C) 1991 Linus Torvalds <a name=L5 href="source/boot/head.s#L5">5</a> */ <a name=L6 href="source/boot/head.s#L6">6</a> <a name=L7 href="source/boot/head.s#L7">7</a> /* <a name=L8 href="source/boot/head.s#L8">8</a> * head.s contains the 32-bit startup code. <a name=L9 href="source/boot/head.s#L9">9</a> * <a name=L10 href="source/boot/head.s#L10">10</a> * NOTE!!! Startup happens at absolute address 0x00000000, which is also where <a name=L11 href="source/boot/head.s#L11">11</a> * the page directory will exist. The startup code will be overwritten by <a name=L12 href="source/boot/head.s#L12">12</a> * the page directory. <a name=L13 href="source/boot/head.s#L13">13</a> */ <a name=L14 href="source/boot/head.s#L14">14</a> .text <a name=L15 href="source/boot/head.s#L15">15</a> .globl _idt,_gdt,_pg_dir,_tmp_floppy_area <a name=L16 href="source/boot/head.s#L16">16</a> _pg_dir: <a name=L17 href="source/boot/head.s#L17">17</a> startup_32: <a name=L18 href="source/boot/head.s#L18">18</a> movl $0x10,%eax <a name=L19 href="source/boot/head.s#L19">19</a> mov %ax,%ds <a name=L20 href="source/boot/head.s#L20">20</a> mov %ax,%es <a name=L21 href="source/boot/head.s#L21">21</a> mov %ax,%fs <a name=L22 href="source/boot/head.s#L22">22</a> mov %ax,%gs <a name=L23 href="source/boot/head.s#L23">23</a> lss _stack_start,%esp <a name=L24 href="source/boot/head.s#L24">24</a> call setup_idt <a name=L25 href="source/boot/head.s#L25">25</a> call setup_gdt <a name=L26 href="source/boot/head.s#L26">26</a> movl $0x10,%eax # reload all the segment registers <a name=L27 href="source/boot/head.s#L27">27</a> mov %ax,%ds # after changing gdt. CS was already <a name=L28 href="source/boot/head.s#L28">28</a> mov %ax,%es # reloaded in 'setup_gdt' <a name=L29 href="source/boot/head.s#L29">29</a> mov %ax,%fs <a name=L30 href="source/boot/head.s#L30">30</a> mov %ax,%gs <a name=L31 href="source/boot/head.s#L31">31</a> lss _stack_start,%esp <a name=L32 href="source/boot/head.s#L32">32</a> xorl %eax,%eax <a name=L33 href="source/boot/head.s#L33">33</a> 1: incl %eax # check that A20 really IS enabled <a name=L34 href="source/boot/head.s#L34">34</a> movl %eax,0x000000 # loop forever if it isn't <a name=L35 href="source/boot/head.s#L35">35</a> cmpl %eax,0x100000 <a name=L36 href="source/boot/head.s#L36">36</a> je 1b <a name=L37 href="source/boot/head.s#L37">37</a> /* <a name=L38 href="source/boot/head.s#L38">38</a> * NOTE! 486 should set bit 16, to check for write-protect in supervisor <a name=L39 href="source/boot/head.s#L39">39</a> * mode. Then it would be unnecessary with the "verify_area()"-calls. <a name=L40 href="source/boot/head.s#L40">40</a> * 486 users probably want to set the NE (#5) bit also, so as to use <a name=L41 href="source/boot/head.s#L41">41</a> * int 16 for math errors. <a name=L42 href="source/boot/head.s#L42">42</a> */ <a name=L43 href="source/boot/head.s#L43">43</a> movl %cr0,%eax # check math chip <a name=L44 href="source/boot/head.s#L44">44</a> andl $0x80000011,%eax # Save PG,PE,ET <a name=L45 href="source/boot/head.s#L45">45</a> /* "orl $0x10020,%eax" here for 486 might be good */ <a name=L46 href="source/boot/head.s#L46">46</a> orl $2,%eax # set MP <a name=L47 href="source/boot/head.s#L47">47</a> movl %eax,%cr0 <a name=L48 href="source/boot/head.s#L48">48</a> call check_x87 <a name=L49 href="source/boot/head.s#L49">49</a> jmp after_page_tables <a name=L50 href="source/boot/head.s#L50">50</a> <a name=L51 href="source/boot/head.s#L51">51</a> /* <a name=L52 href="source/boot/head.s#L52">52</a> * We depend on ET to be correct. This checks for 287/387. <a name=L53 href="source/boot/head.s#L53">53</a> */ <a name=L54 href="source/boot/head.s#L54">54</a> check_x87: <a name=L55 href="source/boot/head.s#L55">55</a> fninit <a name=L56 href="source/boot/head.s#L56">56</a> fstsw %ax <a name=L57 href="source/boot/head.s#L57">57</a> cmpb $0,%al <a name=L58 href="source/boot/head.s#L58">58</a> je 1f /* no coprocessor: have to set bits */ <a name=L59 href="source/boot/head.s#L59">59</a> movl %cr0,%eax <a name=L60 href="source/boot/head.s#L60">60</a> xorl $6,%eax /* reset MP, set EM */ <a name=L61 href="source/boot/head.s#L61">61</a> movl %eax,%cr0 <a name=L62 href="source/boot/head.s#L62">62</a> ret <a name=L63 href="source/boot/head.s#L63">63</a> .align 2 <a name=L64 href="source/boot/head.s#L64">64</a> 1: .byte 0xDB,0xE4 /* fsetpm for 287, ignored by 387 */ <a name=L65 href="source/boot/head.s#L65">65</a> ret <a name=L66 href="source/boot/head.s#L66">66</a> <a name=L67 href="source/boot/head.s#L67">67</a> /* <a name=L68 href="source/boot/head.s#L68">68</a> * setup_idt <a name=L69 href="source/boot/head.s#L69">69</a> * <a name=L70 href="source/boot/head.s#L70">70</a> * sets up a idt with 256 entries pointing to <a name=L71 href="source/boot/head.s#L71">71</a> * ignore_int, interrupt gates. It then loads <a name=L72 href="source/boot/head.s#L72">72</a> * idt. Everything that wants to install itself <a name=L73 href="source/boot/head.s#L73">73</a> * in the idt-table may do so themselves. Interrupts <a name=L74 href="source/boot/head.s#L74">74</a> * are enabled elsewhere, when we can be relatively <a name=L75 href="source/boot/head.s#L75">75</a> * sure everything is ok. This routine will be over- <a name=L76 href="source/boot/head.s#L76">76</a> * written by the page tables. <a name=L77 href="source/boot/head.s#L77">77</a> */ <a name=L78 href="source/boot/head.s#L78">78</a> setup_idt: <a name=L79 href="source/boot/head.s#L79">79</a> lea ignore_int,%edx <a name=L80 href="source/boot/head.s#L80">80</a> movl $0x00080000,%eax <a name=L81 href="source/boot/head.s#L81">81</a> movw %dx,%ax /* selector = 0x0008 = cs */ <a name=L82 href="source/boot/head.s#L82">82</a> movw $0x8E00,%dx /* interrupt gate - dpl=0, present */ <a name=L83 href="source/boot/head.s#L83">83</a> <a name=L84 href="source/boot/head.s#L84">84</a> lea _idt,%edi <a name=L85 href="source/boot/head.s#L85">85</a> mov $256,%ecx <a name=L86 href="source/boot/head.s#L86">86</a> rp_sidt: <a name=L87 href="source/boot/head.s#L87">87</a> movl %eax,(%edi) <a name=L88 href="source/boot/head.s#L88">88</a> movl %edx,4(%edi) <a name=L89 href="source/boot/head.s#L89">89</a> addl $8,%edi <a name=L90 href="source/boot/head.s#L90">90</a> dec %ecx <a name=L91 href="source/boot/head.s#L91">91</a> jne rp_sidt <a name=L92 href="source/boot/head.s#L92">92</a> lidt idt_descr <a name=L93 href="source/boot/head.s#L93">93</a> ret <a name=L94 href="source/boot/head.s#L94">94</a> <a name=L95 href="source/boot/head.s#L95">95</a> /* <a name=L96 href="source/boot/head.s#L96">96</a> * setup_gdt <a name=L97 href="source/boot/head.s#L97">97</a> * <a name=L98 href="source/boot/head.s#L98">98</a> * This routines sets up a new gdt and loads it. <a name=L99 href="source/boot/head.s#L99">99</a> * Only two entries are currently built, the same<a name=L100 href="source/boot/head.s#L100">100</a> * ones that were built in init.s. The routine<a name=L101 href="source/boot/head.s#L101">101</a> * is VERY complicated at two whole lines, so this<a name=L102 href="source/boot/head.s#L102">102</a> * rather long comment is certainly needed :-).<a name=L103 href="source/boot/head.s#L103">103</a> * This routine will beoverwritten by the page tables.<a name=L104 href="source/boot/head.s#L104">104</a> */<a name=L105 href="source/boot/head.s#L105">105</a> setup_gdt:<a name=L106 href="source/boot/head.s#L106">106</a> lgdt gdt_descr<a name=L107 href="source/boot/head.s#L107">107</a> ret<a name=L108 href="source/boot/head.s#L108">108</a> <a name=L109 href="source/boot/head.s#L109">109</a> /*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -