2024-10-14 23:07:59 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015-2019 The University of Notre Dame
|
|
|
|
This software is distributed under the GNU General Public License.
|
|
|
|
See the file LICENSE for details.
|
|
|
|
*/
|
2024-12-09 20:42:57 +01:00
|
|
|
#include "kernel/config.h"
|
2024-10-14 23:07:59 +02:00
|
|
|
#include "console.h"
|
|
|
|
#include "page.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "interrupt.h"
|
|
|
|
#include "clock.h"
|
|
|
|
#include "ata.h"
|
|
|
|
#include "device.h"
|
|
|
|
#include "cdromfs.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "graphics.h"
|
|
|
|
#include "kernel/ascii.h"
|
|
|
|
#include "kernel/syscall.h"
|
|
|
|
#include "rtc.h"
|
|
|
|
#include "kernelcore.h"
|
|
|
|
#include "kmalloc.h"
|
|
|
|
#include "memorylayout.h"
|
|
|
|
#include "kshell.h"
|
|
|
|
#include "cdromfs.h"
|
|
|
|
#include "diskfs.h"
|
|
|
|
#include "serial.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is the C initialization point of the kernel.
|
|
|
|
By the time we reach this point, we are in protected mode,
|
|
|
|
with interrupts disabled, a valid C stack, but no malloc heap.
|
|
|
|
Now we initialize each subsystem in the proper order:
|
|
|
|
*/
|
|
|
|
|
|
|
|
int kernel_main()
|
|
|
|
{
|
|
|
|
struct console *console = console_create_root();
|
|
|
|
console_addref(console);
|
2024-12-09 20:42:57 +01:00
|
|
|
printf("Basekernel Version %d.%d %s\n",KERNEL_MAJOR,KERNEL_MINOR,__DATE__);
|
2024-10-14 23:07:59 +02:00
|
|
|
printf("video: %d x %d (addr %x)\n", video_xres, video_yres, video_buffer);
|
|
|
|
printf("kernel: %d bytes\n", kernel_size);
|
|
|
|
|
|
|
|
page_init();
|
|
|
|
kmalloc_init((char *) KMALLOC_START, KMALLOC_LENGTH);
|
|
|
|
interrupt_init();
|
|
|
|
mouse_init();
|
2024-12-09 20:42:57 +01:00
|
|
|
keyboard_init();
|
|
|
|
serial_init();
|
2024-10-14 23:07:59 +02:00
|
|
|
rtc_init();
|
|
|
|
clock_init();
|
|
|
|
process_init();
|
|
|
|
ata_init();
|
|
|
|
cdrom_init();
|
|
|
|
diskfs_init();
|
|
|
|
|
|
|
|
current->ktable[KNO_STDIN] = kobject_create_console(console);
|
|
|
|
current->ktable[KNO_STDOUT] = kobject_copy(current->ktable[0]);
|
|
|
|
current->ktable[KNO_STDERR] = kobject_copy(current->ktable[1]);
|
|
|
|
current->ktable[KNO_STDWIN] = kobject_create_window(&window_root);
|
|
|
|
current->ktable[KNO_STDDIR] = 0; // No current dir until something is mounted.
|
|
|
|
|
|
|
|
|
2024-12-09 20:42:57 +01:00
|
|
|
printf("kernel initialization is done.\n");
|
|
|
|
#define KSHELL_SERIAL
|
|
|
|
#ifndef KSHELL_SERIAL
|
2024-10-14 23:07:59 +02:00
|
|
|
kshell_launch();
|
2024-12-09 20:42:57 +01:00
|
|
|
// never reached!
|
|
|
|
#else
|
|
|
|
// main IO loop, from kshell_launch
|
|
|
|
char line[100];
|
|
|
|
int lineIndex=0;
|
|
|
|
|
2024-10-14 23:07:59 +02:00
|
|
|
while(1) {
|
2024-12-09 20:42:57 +01:00
|
|
|
// console_putchar(console,console_getchar(console));
|
|
|
|
char c;
|
|
|
|
while ((c = serial_read_nonblock(0))<0) clock_wait(10);
|
|
|
|
console_putchar(console,c);
|
|
|
|
if (c=='\n') { // End of line
|
|
|
|
const char *argv[100];
|
|
|
|
int argc;
|
|
|
|
argc = 0;
|
|
|
|
line[lineIndex]=0;
|
|
|
|
argv[argc] = strtok(line, " ");
|
|
|
|
|
|
|
|
// split line in tokens separated by spaces
|
|
|
|
while(argv[argc]) {
|
|
|
|
argc++;
|
|
|
|
argv[argc] = strtok(0, " ");
|
|
|
|
}
|
2024-10-14 23:07:59 +02:00
|
|
|
|
2024-12-09 20:42:57 +01:00
|
|
|
if(argc > 0) {
|
|
|
|
kshell_execute(argc, argv);
|
|
|
|
}
|
|
|
|
lineIndex=0;
|
|
|
|
} else line[lineIndex++]=c; // collect char
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
// never reached
|
2024-10-14 23:07:59 +02:00
|
|
|
return 0;
|
|
|
|
}
|