CoolPotOS/kernel/kernel.c

123 lines
3.0 KiB
C
Raw Normal View History

2024-04-11 22:53:15 +08:00
#include "../include/multiboot.h"
2024-04-09 23:46:56 +08:00
#include "../include/common.h"
2024-04-11 22:53:15 +08:00
#include "../include/graphics.h"
2024-04-09 23:46:56 +08:00
#include "../include/description_table.h"
#include "../include/io.h"
#include "../include/memory.h"
#include "../include/timer.h"
#include "../include/task.h"
#include "../include/cmos.h"
#include "../include/keyboard.h"
#include "../include/shell.h"
2024-04-10 01:18:08 +08:00
#include "../include/date.h"
2024-04-14 17:14:26 +08:00
#include "../include/acpi.h"
2024-04-20 02:43:22 +08:00
#include "../include/syscall.h"
2024-05-03 20:32:10 +08:00
#include "../include/vdisk.h"
#include "../include/pci.h"
#include "../include/pcnet.h"
2024-05-13 20:30:47 +08:00
#include "../include/ide.h"
#include "../include/vfs.h"
2024-05-18 23:44:25 +08:00
#include "../include/fat.h"
#include "../include/iso9660.h"
2024-04-09 23:46:56 +08:00
extern uint32_t end;
2024-04-11 22:53:15 +08:00
extern int status;
2024-04-09 23:46:56 +08:00
uint32_t placement_address = (uint32_t) & end;
2024-05-03 20:32:10 +08:00
2024-04-13 22:22:25 +08:00
void reset_kernel(){
2024-04-14 17:14:26 +08:00
printf("Restart %s for x86...\n",OS_NAME);
kill_all_task();
2024-04-13 22:22:25 +08:00
clock_sleep(10);
2024-04-14 17:14:26 +08:00
power_reset();
2024-04-13 22:22:25 +08:00
}
void shutdown_kernel(){
2024-04-14 17:14:26 +08:00
printf("Shutdown %s for x86...\n",OS_NAME);
kill_all_task();
clock_sleep(10);
power_off();
2024-04-13 22:22:25 +08:00
}
2024-04-15 00:24:36 +08:00
uint32_t memory_all(){
2024-05-21 21:09:04 +08:00
return 0;
2024-04-15 00:24:36 +08:00
}
2024-05-19 18:05:00 +08:00
int check_task(int *pid){
struct task_struct *shell = found_task_pid(*pid);
while (1){
if(shell->state == TASK_DEATH){
printf("\033\n[Task-Check]: Task was throw exception.\036\n");
printf("Enter any key to restart kernel.> ");
getc();
printf("\n");
reset_kernel();
}
}
return 0;
}
2024-04-11 22:53:15 +08:00
void kernel_main(multiboot_t *multiboot) {
2024-05-21 21:09:04 +08:00
2024-04-09 23:46:56 +08:00
io_cli();
vga_install();
2024-05-21 21:09:04 +08:00
2024-04-12 22:03:07 +08:00
if ((multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1 < 16) {
printf("[kernel] Minimal RAM amount for CPOS is 16 MB, but you have only %d MB.\n",
(multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1);
while (1) io_hlt();
}
2024-05-21 21:09:04 +08:00
initVBE(multiboot);
printf("[kernel]: VGA driver load success!\n");
2024-04-09 23:46:56 +08:00
gdt_install();
idt_install();
2024-05-21 21:09:04 +08:00
printf("[kernel]: description table config success!\n");
2024-05-19 18:05:00 +08:00
init_timer(1);
2024-04-14 17:14:26 +08:00
acpi_install();
2024-05-21 21:09:04 +08:00
printf("[kernel]: ACPI enable success!\n");
init_page(multiboot);
printf("[kernel]: page set success!\n");
2024-04-09 23:46:56 +08:00
init_sched();
2024-05-21 21:09:04 +08:00
printf("[kernel]: task load success!\n");
2024-04-09 23:46:56 +08:00
init_keyboard();
2024-05-21 21:09:04 +08:00
printf("[kernel]: Keyboard driver load success!\n");
2024-05-12 14:34:03 +08:00
io_sti();
2024-05-21 21:09:04 +08:00
kernel_thread(cur_task,NULL,"CPOS-VBE-SERVICE");
2024-05-12 14:34:03 +08:00
init_pit();
2024-05-03 20:32:10 +08:00
init_pci();
2024-05-18 23:44:25 +08:00
init_vdisk();
2024-05-13 20:30:47 +08:00
ide_initialize(0x1F0, 0x3F6, 0x170, 0x376, 0x000);
2024-05-18 23:44:25 +08:00
init_vfs();
Register_fat_fileSys();
init_iso9660();
2024-04-20 02:43:22 +08:00
syscall_install();
2024-05-03 20:32:10 +08:00
2024-05-18 23:44:25 +08:00
vfs_mount_disk('A','A');
if(vfs_change_disk('A'))
2024-05-19 18:05:00 +08:00
printf("[FileSystem]: Change disk win!\n");
2024-05-18 23:44:25 +08:00
else {
for(;;);
}
2024-05-03 20:32:10 +08:00
if(pcnet_find_card()){
2024-05-12 14:34:03 +08:00
//init_pcnet_card();
2024-05-21 21:09:04 +08:00
} else printf("[kernel]: Cannot found pcnet.\n");
2024-05-03 20:32:10 +08:00
2024-04-09 23:46:56 +08:00
print_cpu_id();
2024-05-21 21:09:04 +08:00
//printf("Memory: %dMB.",(multiboot->mem_upper + multiboot->mem_lower)/1024/1024);
2024-04-12 22:03:07 +08:00
2024-04-09 23:46:56 +08:00
clock_sleep(25);
2024-05-19 18:05:00 +08:00
int pid = kernel_thread(setup_shell, NULL, "CPOS-Shell");
kernel_thread(check_task,&pid,"CPOS-SHELL-CHECK");
2024-05-02 11:06:52 +08:00
launch_date();
2024-04-09 23:46:56 +08:00
2024-04-12 22:03:07 +08:00
for (;;) {
2024-04-09 23:46:56 +08:00
io_hlt();
clock_sleep(1);
}
}