comparison cos/kernel/kernel.c @ 36:91f91ff07ea8

Removed test variables
author windel
date Mon, 16 Jan 2012 20:47:05 +0100
parents bcb3b68c8147
children 5c20bd53cccd
comparison
equal deleted inserted replaced
35:bcb3b68c8147 36:91f91ff07ea8
12 printf("Got b at %x\n", b); 12 printf("Got b at %x\n", b);
13 b[0] = 'B'; 13 b[0] = 'B';
14 kfree(a); 14 kfree(a);
15 } 15 }
16 16
17 uint64_t testvar = 1234; // Ends up in data section
18 uint64_t testvar2 = 0; // Ends up in bss section
19
20 multiboot_info_t *multiboot_info = 0; // Set by startup code. 17 multiboot_info_t *multiboot_info = 0; // Set by startup code.
21 18
22 /* This routine initializes the kernel. 19 /* This routine initializes the kernel.
23 * We are left here in 64-bit long mode with the first 6 MB identity mapped. 20 * We are left here in 64-bit long mode with the first 6 MB identity mapped.
24 * */ 21 * */
25 void kmain() 22 void kmain()
26 { 23 {
27 // No kmalloc required here yet: 24 // No kmalloc required here yet:
28 init_screen(); 25 init_screen();
29 setupIDT(); 26 setupIDT();
30 keyboard_init();
31 timer_init();
32
33 testvar++;
34 testvar2++;
35 printf("Test variable = %d, testvar2 = %d\n", testvar, testvar2);
36 27
37 /* Retrieve memory information from multiboot header */ 28 /* Retrieve memory information from multiboot header */
38 uint64_t available_memory = 0; 29 uint64_t available_memory = 0;
39 if ((multiboot_info->flags & (1<<6)) == (1<<6)) 30 if ((multiboot_info->flags & (1 << 6)) == (1 << 6))
40 { 31 {
41 multiboot_memory_map_t *mmap; 32 multiboot_memory_map_t *mmap;
42 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr; 33 for (mmap = (multiboot_memory_map_t*)(uint64_t)multiboot_info->mmap_addr;
43 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length; 34 (uint64_t)mmap < multiboot_info->mmap_addr + multiboot_info->mmap_length;
44 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) ) 35 mmap = (multiboot_memory_map_t*) ( (uint64_t)mmap + mmap->size + sizeof(mmap->size)) )
52 { 43 {
53 available_memory = mmap->length; 44 available_memory = mmap->length;
54 } 45 }
55 } 46 }
56 } 47 }
57 else 48
49 if (available_memory == 0)
58 { 50 {
59 panic("Found no GRUB memory map\n"); 51 panic("Found no usable memory in grub's memory map\n");
60 } 52 }
61 53
62 printf("Running with %d MB ram\n", available_memory / 1000000); 54 printf("Running with %d MB ram\n", available_memory / 1000000);
55
56 init_memory(available_memory); // Setup paging and memory manager
57
58 keyboard_init();
59 timer_init();
63 60
64 /* 61 /*
65 fs_node_t *fs_root = 0; 62 fs_node_t *fs_root = 0;
66 if ( (multiboot_info->flags & (1<<3)) == (1<<3)) 63 if ( (multiboot_info->flags & (1<<3)) == (1<<3))
67 { 64 {
90 87
91 } 88 }
92 } 89 }
93 */ 90 */
94 91
95 // Assume first 16MB:
96 // TODO: get size from grub
97 init_memory(0x1000000);
98 92
99 // TODO: make below a user space program! 93 // TODO: make below a user space program!
100 printf("Welcome!\n"); 94 printf("Welcome!\n");
101 95
102 while (1) 96 while (1)
135 /* Test general protection exception */ 129 /* Test general protection exception */
136 uint64_t *x; 130 uint64_t *x;
137 x = (uint64_t*)0x4000000; // Address that is not mapped 131 x = (uint64_t*)0x4000000; // Address that is not mapped
138 *x = 0x2; // trigger paging exception 132 *x = 0x2; // trigger paging exception
139 } 133 }
140
141 } 134 }
142 } 135 }
143 136
144 137