3 Copyright (C) 2006-2009 Jörg Pfähler
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <kernel/kernel.hpp>
24 #include <kernel/smp.hpp>
25 #include <kernel/acpi.hpp>
26 #include <kernel/elf.hpp>
27 #include <kernel/log.hpp>
28 #include <kernel/scheduler.hpp>
29 #include <kernel/io_port_manager.hpp>
30 #include <kernel/x86_shared/pic.hpp>
31 #include <kernel/x86_shared/apic.hpp>
32 #include <kernel/x86_shared/serial.hpp>
33 #include <kernel/x86_shared/gdt.hpp>
34 #include <kernel/x86_shared/interrupt_controller.hpp>
35 #include <kernel/range_allocator.hpp>
36 #include <kernel/virtual_memory.hpp>
37 #include <kernel/processor.hpp>
39 using namespace kernel
;
40 using kernel::virtual_memory
;
42 void kernel_main(const kernel::boot_info
&info
)
44 // Go through the module list
45 kernel::module_info
*Module
= physical_address
<kernel::module_info
*>(reinterpret_cast<kernel::module_info
*>(info
.mod
));
46 for (size_t i
= 0;i
< info
.module_count
;i
++)
48 elf
Elf(physical_address
<void*>(reinterpret_cast<void*>(Module
[i
].start
)),
49 Module
[i
].end
- Module
[i
].start
);
50 if (Elf
.valid() == false)
52 FATAL(reinterpret_cast<char*>(Module
[i
].name
) << ": Not a valid elf file.");
56 if (Elf
.is_library() == true)
59 const char *name
= physical_address
<char*>(reinterpret_cast<char*>(Module
[i
].name
));
60 Elf
.create_library_image(name
);
64 // Create the process image
68 bool result
= Elf
.create_process_image(Context
, Pages
, libName
);
70 string
path(physical_address
<char*>(reinterpret_cast<char*>(Module
[i
].name
)));
74 process::create(Context
,
78 lightOS::process::server
);
82 if (libName
.length() != 0)
84 ERROR("kernel: shared-library \"" << libName
.c_str() << "\" for \"" << path
.c_str() << "\" not loaded");
88 ERROR("kernel: invalid elf file \"" << path
.c_str() << "\"");
94 range_allocator
&RangeAllocator
= range_allocator::instance();
95 size_t size
= Module
[i
].end
- Module
[i
].start
+ virtual_memory::page_size
- 1;
96 RangeAllocator
.free_range(Module
[i
].start
, size
/ virtual_memory::page_size
);
99 // Initialize the I/O Port Manager
100 io_port_manager
&IOPortManager
= io_port_manager::instance();
101 IOPortManager
.init();
103 // Has this processor a local APIC?
104 if (processor::has_local_apic() == true)
107 // Initialize the APIC class
108 local_apic::initialize();
113 LOG("No local APIC found");
116 // Initialize the processor class
117 // NOTE Also calls initialize_this() for the BSP
118 processor::initialize();
122 if (processor::has_local_apic() == true)
135 // Initialize the GDT
136 gdt
&Gdt
= gdt::instance();
140 // Load the Task Register
141 processor::load_taskregister();
145 if (smp::compatible() == true)
147 // Complete initialization & schedule!
152 // Initialize the interrupt controller
153 interrupt_controller
&InterruptController
= interrupt_controller::instance();
154 InterruptController
.init();
156 scheduler::schedule(0);