-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkmain.c
101 lines (92 loc) · 3.84 KB
/
kmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/************************************************************************
* Copyright (c) 2012 Ákos Kovács - Akosix operating system
* http://akoskovacs.github.com/Akosix
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
************************************************************************/
#include <console.h>
#include <kernel.h>
#include <ksymbol.h>
#include <memory.h>
#include <multiboot.h>
#include <devices/input/keyboard.h>
#include <string.h>
#include <system.h>
#include <panic.h>
void kmain(struct multiboot_info *mbi, unsigned int magic)
{
unsigned int mem = mbi->mem_upper + mbi->mem_lower;
struct multiboot_info *nmbi, *an;
set_console_attributes(FG_COLOR_WHITE | LIGHT | BG_COLOR_CYAN);
console_init();
if (magic != 0x2BADB002) {
kpanic("Bad bootloader 'magic': %d [%x]", magic, magic);
}
kprintf("Booting Akosix...\nAt kmain() %p\n", kmain);
kprintf("Memory present %dKB (%dMB).\n", mem, mem/1024);
kprintf("Bootloader: %s\n", (const char *)mbi->boot_loader_name);
kprintf("Command line: %s\n", (const char *)mbi->cmdline);
kprintf("End of kernel %p\n", (void*)&__end_data_kernel);
kprintf("Paging enabled!\n\n");
kprintf("Multiboot info:\n");
if (mbi->flags & MB_INFO_BOOTDEV)
kprintf("\to Has multiboot bootdev\n");
if (mbi->flags & MB_INFO_CMDLINE)
kprintf("\to Has multiboot command line\n");
if (mbi->flags & MB_INFO_ELF_SECT)
kprintf("\to Has multiboot elf section info\n");
if (mbi->flags & MB_INFO_DRIVE_INFO)
kprintf("\to Has multiboot drive info\n");
if (mbi->flags & MB_INFO_VIDEO)
kprintf("\to Has multiboot video info\n");
if (mbi->flags & MB_INFO_MODS)
kprintf("\to Has multiboot module info\n");
if (mbi->flags & MB_INFO_MEMORY)
kprintf("\to Has multiboot memory\n");
if (mbi->flags & MB_INFO_MEM_MAP)
kprintf("\to Has multiboot memory-map info:\n");
memory_init(mbi);
nmbi = kmalloc(sizeof(struct multiboot_info), M_NORMAL | M_ZEROED);
void *km = get_symbol("kmalloc");
kprintf("kmalloc(): %p\n", km);
an = kmalloc(sizeof(struct multiboot_info), M_NORMAL);
kfree(nmbi);
nmbi = kmalloc(sizeof(struct multiboot_info), M_NORMAL | M_ZEROED);
kprintf("kmalloc() test (must be 0) %d\n", nmbi->mem_upper + nmbi->mem_lower);
void *sm = kmalloc(220, M_NORMAL);
// kpanic("Sorry dude! If you wanted some magic, you gonna have a bad time!" , sm);
/* Test the console and keyboard */
uint8_t pcd = 0;
uint8_t scode = 1;
forever {
char ch = keyboard_read(&scode);
if (pcd != scode) {
// reboot on DEL
if (scode == 0x53) {
ps2_kbd_reboot();
}
if (ch != '\0') {
kprintf("%c", ch);
}
//kprintf("\nscancode: %p, (character: %c)", scode, ch);
pcd = scode;
}
}
}