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

Last change on this file since 43 was 15, checked in by max@…, 7 years ago

test (cosmetic)

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 <chdev.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        uint32_t gdt_ptr;
71        uint32_t tss_index;
72
73        kheap_start = ARROUND_UP((uint_t)&_end, 4096);
74        kheap_limit = kheap_start + (8<<20);
75
76        tty_clear();
77
78        printf("AlmOS Kernel has been loaded\n");
79
80        printf("RAM detected : %uk (lower), %uk (upper)\n", mbi->low_mem, mbi->high_mem);
81        printf("end of data, kheap start @%x, end @%x\n", kheap_start, kheap_limit);
82        printf("Initializaiton of CPU context ...\t");
83        cpu_gdt_init();
84        printf("[ OK ]\nloading IDT ...\t");
85        cpu_idt_init();
86        printf("[ OK ]\nloading GDT ...\t");
87
88        gdt_ptr = (uint32_t) cpu_get_gdt_ptr();
89        tss_index = (cpu_get_id() + GDT_FIXED_NR) << 3;
90
91#if 0
92        gdt_print((struct cpu_gdt_entry_s*)cpu_get_gdt_ptr()->base, GDT_FIXED_NR + CPU_NR);
93        printf("\n\ngdt_ptr %x\n", gdt_ptr);
94#endif
95
96        __asm__ __volatile__ ("" ::: "memory");
97
98#if 1   
99        asm volatile 
100                (".extern __boot_stack        \n"
101                 ".extern _init_              \n"
102                 "movl  %0,      %%ebx        \n"
103                 "movl  %1,      %%ecx        \n"
104                 "lgdt  (%%ebx)               \n"
105                 "movw  $0x10,   %%ax     \n" /* KDATA */
106                 "movw  %%ax,    %%ds     \n"
107                 "movw  %%ax,    %%es     \n"
108                 "movw  %%ax,    %%fs     \n"
109                 "movw  %%ax,    %%gs     \n"
110                 "ljmp  $0x08,   $next    \n" /* KTEXT */
111                 "next:                   \n"
112                 "xor   %%eax,  %%eax         \n"
113                 "leal  (__boot_stack), %%esi \n"
114                 "movw  $0x10,  %%ax          \n" /* KSTACK */
115                 "movw  %%ax,   %%ss          \n"
116                 "movl  %%esi,  %%esp         \n"
117                 "ltr   %%cx                  \n"
118                 "call  _boot_init            \n"
119                 :: "r" (gdt_ptr), "r"(tss_index));
120#endif
121}
Note: See TracBrowser for help on using the repository browser.