2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "ke/multiboot.h"
26 #include "ke/interrupts.h"
29 #include "ke/process.h"
30 #include "mm/memory.h"
31 #include "ke/module.h"
37 static MultibootInfo
*mbinfo
;
39 void kernel_phys_start();
40 void kernel_phys_end();
42 static void keInit2(void)
44 keInitKernelSymbols(mbinfo
);
47 FsFileSystemDriver
*devfs
= fsGetDriver("devfs");
51 kePrint("devfs not available.\n");
54 fsMount(devfs
, "/dev/", 0, 0);
55 keInitModules(mbinfo
);
56 kePrint("Opening test file.\n");
57 FsFileHandle
*testfile
= fsOpen("/dev/cdrom0", 0);
60 kePrint("Could not open test file.\n");
64 unsigned char test
[512];
65 fsSeek(testfile
, 0x8000, 0);
66 int read
= fsRead(testfile
, test
, 512, 1);
67 kePrint("Read %d bytes.\n", read
);
71 for (i
= 0; i
< 512; i
++)
74 snprintf(buffer
, 2, "%c", test
[i
]);
75 kePrint("%s", buffer
);
80 kePrint("Closing test file.\n");
85 FsFileSystemDriver
*iso9660
= fsGetDriver("iso9660");
89 kePrint("iso9660 not available.\n");
92 fsMount(iso9660
, "/", "/dev/cdrom0", 0);
94 kePrint("Sleep (500)\n");
96 kePrint("Sleep (1000)\n");
103 void keInit(int magic
, MultibootInfo
*info
)
105 char *vidmem
= (char*)0xC00B8000;
106 memset(vidmem
, 0, 160 * 25);
110 if (!CHECK_FLAG(info
->flags
, 5))
112 kePrint("Error: no symbols available.\n");
116 uintptr_t kernel_begin
= ((uintptr_t)kernel_phys_start
& ~0xFFF) + 0xC0000000;
117 uintptr_t kernel_end
= (((uintptr_t)kernel_phys_end
+ 4095) & ~0xFFF) + 0xC0000000;
118 mmInitMemoryManager(info
, kernel_begin
, kernel_end
);
119 // Remap multiboot struct
120 uintptr_t info_addr
= mmFindFreeKernelPages(MM_MAX_KERNEL_PAGE
,
121 MM_MIN_KERNEL_PAGE
, 0, 0x1000);
122 mmMapKernelMemory((uintptr_t)info
& ~0xFFF, info_addr
,
123 MM_MAP_READ
| MM_MAP_WRITE
);
124 info_addr
+= (uintptr_t)info
& 0xFFF;
125 info
= (void*)info_addr
;
132 keInitProcessManager();
135 KeProcess
*testprocess
= keCreateProcess();
136 keLockSpinlock(mmGetMemoryLock());
137 uintptr_t progpaddr
= mmAllocPhysicalMemory(0, 0, 0x1000);
138 uintptr_t progkerneladdr
= mmFindFreeKernelPages(MM_MAX_KERNEL_PAGE
,
139 MM_MIN_KERNEL_PAGE
, 0, 0x1000);
140 mmMapKernelMemory(progpaddr
, progkerneladdr
, MM_MAP_READ
| MM_MAP_WRITE
);
141 ((uint8_t*)progkerneladdr
)[0] = 0xEB;
142 ((uint8_t*)progkerneladdr
)[1] = 0xFE;
143 mmMapKernelMemory(0, progkerneladdr
, 0);
144 mmMapMemory(&testprocess
->memory
, progpaddr
, 0x400000, MM_MAP_READ
| MM_MAP_EXECUTE
);
145 keUnlockSpinlock(mmGetMemoryLock());
146 KeThread
*testthread
= keCreateThread(testprocess
, 0x400000, 0);
147 keUnlockSpinlock(&testprocess
->lock
);
149 // Initial kernel thread
150 KeThread
*initthread
= keCreateKernelThread((uintptr_t)keInit2
, 0);
157 while (1) asm("hlt");