2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <multiboot.h>
28 #include <memkernel.h>
32 #include <interrupt.h>
48 char *basename(char *path
) {
50 char *basename
= path
;
51 for (i
=0;path
[i
];i
++) {
52 if (path
[i
]=='/') basename
= path
+i
;
54 if (*basename
==0) return basename
;
55 else return basename
+1;
62 int putsn(int out
,char *buf
,size_t maxlen
) {
64 for (i
=0;buf
[i
]!=0 && i
<maxlen
;i
++) {
65 if (out
==0) kprintchar(buf
[i
]);
66 else com_send(buf
[i
]);
72 * Initializes and runs kernel
73 * @param mbi Multiboot Info
74 * @param magic Multiboot magic number
75 * @return Should not return
77 int main(multiboot_info_t
*mbi
,uint32_t magic
) {
80 kprintf("meinOS\n\n");
82 if (magic
!=MULTIBOOT_MAGIC
) panic("Not booted with a multiboot bootloader.\n");
85 test(multiboot_init(mbi
));
88 test(memkernel_init());
93 test(interrupt_init());
100 test(memuser_init());
102 test(biosint_init());
104 /// @deprecated Only for debugging
105 syscall_create(SYSCALL_PUTSN
,putsn
,3);
106 syscall_create(SYSCALL_FOURTYTWO
,fourtytwo
,0);
108 // load initial programs
109 kprintf("Loading initial programs...\n");
116 for (i
=0;(addr
= multiboot_get_mod(i
,&file
,&size
));i
++) {
117 name
= basename(file
);
118 kprintf(" %s:\t%s:\t0x%x / 0x%x...",name
,file
,addr
,size
);
119 proc_t
*new = proc_create(name
,PERM_ROOTUID
,PERM_ROOTGID
,i
==0?NULL
:proc_init
,(i
==0),(i
==0));
120 if (i
==0) proc_init
= new;
122 void *entrypoint
= elf_load(new->addrspace
,addr
,size
);
123 if (entrypoint
!=NULL
) {
124 new->registers
.eip
= (uint32_t)entrypoint
;
125 new->registers
.esp
= (uint32_t)memuser_create_stack(new->addrspace
);
126 kprintf("(pid=%d) done\n",new->pid
);
129 else proc_destroy(new);