source: trunk/hal/i386/boot.c @ 1

Last change on this file since 1 was 1, checked in by alain, 7 years ago

First import

File size: 3.2 KB
Line 
1/*
2 * boot.c - kernel low-level boot entry
3 *
4 * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless
5 * Copyright (c) 2011,2012 UPMC Sorbonne Universites
6 *
7 * This file is part of ALMOS-kernel.
8 *
9 * ALMOS-kernel is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2.0 of the License.
12 *
13 * ALMOS-kernel is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with ALMOS-kernel; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <kdmsg.h>
24#include <hardware.h>
25#include <device.h>
26#include <cpu.h>
27#include <cpu-internal.h>
28
29struct mb_partial_info_s
30{
31        unsigned long flags;
32        unsigned long low_mem;
33        unsigned long high_mem;
34        unsigned long boot_device;
35        unsigned long cmdline;
36};
37
38extern uint_t *_end;
39
40#define ARROUND_UP(val, size) (val) & ((size) -1) ? ((val) & ~((size)-1)) + (size) : (val)
41
42static uint_t kheap_start;
43static uint_t kheap_limit;
44extern void __do_init(uint_t, uint_t);
45extern void cpu_idt_init();
46
47static void tty_clear()
48{
49        register uint_t i = 0;
50        uint8_t *vga_ram = (uint8_t*)__tty_addr;
51
52        for(i = 0; i < TTY_SIZE; i+=2)
53        {
54                vga_ram[i] = 0;
55                vga_ram[i+1] = 0x7;
56        }
57}
58
59void _boot_init()
60{
61        printf("[ OK ]\n");
62        __do_init(kheap_start, kheap_limit);
63}
64       
65
66void gdt_print(struct cpu_gdt_entry_s *gdt, int nr);
67
68void kboot_entry(struct mb_partial_info_s *mbi)
69{
70 
71        uint32_t gdt_ptr;
72        uint32_t tss_index;
73 
74        kheap_start = ARROUND_UP((uint_t)&_end, 4096);
75        kheap_limit = kheap_start + (8<<20);
76
77        tty_clear();
78
79        printf("AlmOS Kernel has been loaded\n");
80
81        printf("RAM detected : %uk (lower), %uk (upper)\n", mbi->low_mem, mbi->high_mem);
82        printf("end of data, kheap start @%x, end @%x\n", kheap_start, kheap_limit);
83        printf("Initializaiton of CPU context ...\t");
84        cpu_gdt_init();
85        printf("[ OK ]\nloading IDT ...\t");
86        cpu_idt_init();
87        printf("[ OK ]\nloading GDT ...\t");
88
89        gdt_ptr = (uint32_t) cpu_get_gdt_ptr();
90        tss_index = (cpu_get_id() + GDT_FIXED_NR) << 3;
91 
92#if 0
93        gdt_print((struct cpu_gdt_entry_s*)cpu_get_gdt_ptr()->base, GDT_FIXED_NR + CPU_NR);
94        printf("\n\ngdt_ptr %x\n", gdt_ptr);
95#endif
96
97        __asm__ __volatile__ ("" ::: "memory");
98
99#if 1   
100        asm volatile 
101                (".extern __boot_stack        \n"
102                 ".extern _init_              \n"
103                 "movl  %0,      %%ebx        \n"
104                 "movl  %1,      %%ecx        \n"
105                 "lgdt  (%%ebx)               \n"
106                 "movw  $0x10,   %%ax     \n" /* KDATA */
107                 "movw  %%ax,    %%ds     \n"
108                 "movw  %%ax,    %%es     \n"
109                 "movw  %%ax,    %%fs     \n"
110                 "movw  %%ax,    %%gs     \n"
111                 "ljmp  $0x08,   $next    \n" /* KTEXT */
112                 "next:                   \n"
113                 "xor   %%eax,  %%eax         \n"
114                 "leal  (__boot_stack), %%esi \n"
115                 "movw  $0x10,  %%ax          \n" /* KSTACK */
116                 "movw  %%ax,   %%ss          \n"
117                 "movl  %%esi,  %%esp         \n"
118                 "ltr   %%cx                  \n"
119                 "call  _boot_init            \n"
120                 :: "r" (gdt_ptr), "r"(tss_index));
121#endif
122}
Note: See TracBrowser for help on using the repository browser.