UbixOS V2 2.0

start.S
Go to the documentation of this file.
1 /*-
2 * Copyright (c) 2002-2018 The UbixOS Project.
3 * All rights reserved.
4 *
5 * This was developed by Christopher W. Olsen for the UbixOS Project.
6 *
7 * Redistribution and use in source and binary forms, with or without modification, are permitted
8 * provided that the following conditions are met:
9 *
10 * 1) Redistributions of source code must retain the above copyright notice, this list of
11 * conditions, the following disclaimer and the list of authors.
12 * 2) Redistributions in binary form must reproduce the above copyright notice, this list of
13 * conditions, the following disclaimer and the list of authors in the documentation and/or
14 * other materials provided with the distribution.
15 * 3) Neither the name of the UbixOS Project nor the names of its contributors may be used to
16 * endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #define BI_VERSION 0x0
30 #define BI_KERNELNAME 0x4
31 #define BI_ENDCOMMON 12
32 #define BI_SIZE 48
33 #define BOOTINFO_SIZE 135
34 #define RB_BOOTINFO 0x80000000 /* have `struct bootinfo *' arg */
35
36
37 .globl _start
38 .text
39 .code32
40 _start:
41 movw $0x1234,0x472
42 pushl %ebp
43 movl %esp,%ebp
44 pushl $0x00000002
45 popfl
46
47 /* Clear the BSS */
48 movl $(_end),%ecx
49 movl $(__bss_start),%edi
50 subl %edi,%ecx
51 xorl %eax,%eax
52 cld
53 rep
54 stosb
55
56 /* Fix Up GS/FS */
57 mov %dx,%ax
58 mov %ax,%fs
59 mov %ax,%gs
60
61 /* Get Boot Args */
62 call get_bootargs
63
64 /* Load GDT */
65 lgdtl (loadGDT)
66 mov $0x10,%eax
67 mov %eax,%ds
68 mov %eax,%es
69 mov %eax,%fs
70 mov %eax,%gs
71 mov %eax,%ss
72 mov $kStack,%eax
73 addl $0x1000,%eax
74 mov %esp,%edx
75 mov %eax,%esp
76 mov %eax,%ebp
77 mov $0x18,%ax
78 lldt %ax
79 mov $0x20,%ax
80 ltr %ax
81 ljmp $0x08,$start_next
82 start_next:
83 call vmm_init
84 pushl %esp
85 mov %esp,%ebp
86 mov $0xFFFFFFFF,%eax
87 mov %eax, %esp
88 pushl $0xDEAD; // Stack
89 pushl $0xBEEF; // Marker
90 subl $0xE,%esp;
91 call kmain
92 get_bootargs:
93 /*
94 * The old style disk boot blocks fake a frame on the stack and
95 * did an lret to get here. The frame on the stack has a return
96 * address of 0.
97 */
98
99 cmpl $0,4(%ebp)
100 je old_boot
101
102 /*
103 * We have some form of return address, so this is either the
104 * old diskless netboot code, or the new uniform code. That can
105 * be detected by looking at the 5th argument, if it is 0
106 * we are being booted by the new uniform boot code.
107 */
108 cmpl $0,24(%ebp)
109 je new_boot
110
111 hlt
112 new_boot:
113 movl 28(%ebp),%ebx /* &bootinfo.version */
114 movl BI_VERSION(%ebx),%eax
115 cmpl $1,%eax /* We only understand version 1 */
116 je 1f
117 movl $1,%eax /* Return status */
118 leave
119 /*
120 * XXX this returns to our caller's caller (as is required) since
121 * we didn't set up a frame and our caller did.
122 */
123 hlt /* MrO */
124 ret
125 1:
126 /*
127 * If we have a kernelname copy it in
128 */
129 movl BI_KERNELNAME(%ebx),%esi
130 cmpl $0,%esi
131 je 2f /* No kernelname */
132 movl 512,%ecx /* Brute force!!! */
133 movl $_kernelname,%edi
134 cmpb $'/',(%esi) /* Make sure it starts with a slash */
135 je 1f
136 movb $'/',(%edi)
137 incl %edi
138 decl %ecx
139 1:
140 cld
141 rep
142 movsb
143
144 2:
145 /*
146 * Determine the size of the boot loader's copy of the bootinfo
147 * struct. This is impossible to do properly because old versions
148 * of the struct don't contain a size field and there are 2 old
149 * versions with the same version number.
150 */
151 movl $BI_ENDCOMMON,%ecx /* prepare for sizeless version */
152 testl $RB_BOOTINFO,8(%ebp) /* bi_size (and bootinfo) valid? */
153 je got_bi_size /* no, sizeless version */
154 movl BI_SIZE(%ebx),%ecx
155 got_bi_size:
156
157 /*
158 * Copy the common part of the bootinfo struct
159 */
160 movl %ebx,%esi
161 movl $_bootinfo,%edi
162 cmpl $BOOTINFO_SIZE,%ecx
163 jbe got_common_bi_size
164 movl $BOOTINFO_SIZE,%ecx
165 got_common_bi_size:
166 cld
167 rep
168 movsb
169 old_boot:
170 movl 8(%ebp),%eax
171 movl %eax,(_boothowto)
172 movl 12(%ebp),%eax
173 movl %eax,(_bootdev)
174
175 ret
176
177 .data
178 .comm kStack,0x1000