优化项目结构

This commit is contained in:
xiaoyi1212 2024-05-25 18:35:01 +08:00
parent e700ab2dea
commit 9144d9f3bf
92 changed files with 115 additions and 232 deletions

View File

@ -21,6 +21,7 @@ if check_os() == "Windows":
cd = os.getcwd() # 获取当前执行目录 'D:\CrashPowerDOS-main\'
out = "target"
dir_ = "\\"
src = "src\\"
elif check_os() == "Linux":
gcc = 'gcc.exe -w -std=gnu99 -I include/ -std=gnu99 -ffreestanding -c -Wincompatible-pointer-types '
asm = 'gcc.exe'
@ -29,6 +30,7 @@ elif check_os() == "Linux":
cd = os.getcwd() # 获取当前执行目录 '\mnt\d\CrashPowerDOS-main\'
out = "target"
dir_ = "/"
src = "./src/"
def clean():
@ -41,13 +43,13 @@ def clean():
def build_boot(): # 构建引导程序
print("Building boot source code...")
status = True
for file in os.listdir(cd + dir_ + 'boot'):
for file in os.listdir(cd + dir_ + src + 'boot'):
if status and file == 'boot.asm':
cmd = cd + asm + " " + cd + dir_ + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \
cmd = cd + asm + " " + cd + dir_ + src + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \
file.split(".")[0] + ".o"
status = False
else:
cmd = nasm + " " + cd + dir_ + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \
cmd = nasm + " " + cd + dir_ + src + "boot" + dir_ + file + " -o " + cd + dir_ + "target" + dir_ + \
file.split(".")[0] + ".o"
e = os.system(cmd) # os.system 执行命令 e为返回值(非0即不正常退出,可做判断终止构建流程)
if e != 0:
@ -57,8 +59,17 @@ def build_boot(): # 构建引导程序
def build_driver(): # 构建内置驱动程序
print("Building driver source code...")
for file in os.listdir(cd + dir_ + 'driver'):
cmd = cd + gcc + "-O2 " + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
status_pci = True
status_ide = True
for file in os.listdir(cd + dir_ + src + 'driver'):
if status_pci and (file == 'pci.c'):
cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
status_pci = False
elif status_ide and (file == 'ide.c'):
cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
status_ide = False
else:
cmd = cd + gcc + "-O0 " + src + "driver" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -67,8 +78,8 @@ def build_driver(): # 构建内置驱动程序
def build_kernel(): # 构建内核本体
print("Building kernel source code...")
for file in os.listdir(cd + dir_ + 'kernel'):
cmd = cd + gcc + "-O2 " + "kernel" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
for file in os.listdir(cd + dir_ + src + 'kernel'):
cmd = cd + gcc + "-O0 " + src + "kernel" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -77,8 +88,8 @@ def build_kernel(): # 构建内核本体
def build_data(): # 构建常用工具
print("Building util source code...")
for file in os.listdir(cd + dir_ + 'util'):
cmd = cd + gcc + "-O2 " + "util" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
for file in os.listdir(cd + dir_ + src + 'util'):
cmd = cd + gcc + "-O2 " + src + "util" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -87,8 +98,8 @@ def build_data(): # 构建常用工具
def build_sysapp(): # 构建内置系统应用
print("Building sysapp source code...")
for file in os.listdir(cd + dir_ + 'sysapp'):
cmd = cd + gcc + "-O2 " + "sysapp" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
for file in os.listdir(cd + dir_ + src + 'sysapp'):
cmd = cd + gcc + "-O0 " + src + "sysapp" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -97,8 +108,8 @@ def build_sysapp(): # 构建内置系统应用
def build_network(): # 构建网络系统
print("Building network source code...")
for file in os.listdir(cd + dir_ + 'network'):
cmd = cd + gcc + "-O2 " + "network" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
for file in os.listdir(cd + dir_ + src + 'network'):
cmd = cd + gcc + "-O0 " + src + "network" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -107,8 +118,8 @@ def build_network(): # 构建网络系统
def build_fs(): # 构建文件系统
print("Building fs source code...")
for file in os.listdir(cd + dir_ + 'fs'):
cmd = cd + gcc + " " + "fs" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
for file in os.listdir(cd + dir_ + src + 'fs'):
cmd = cd + gcc + " " + src + "fs" + dir_ + file + " -o " + "target" + dir_ + file.split(".")[0] + ".o"
e = os.system(cmd)
if e != 0:
return -1
@ -162,3 +173,5 @@ a = linker()
if a != 0:
exit(-1)
print("Launching i386 vm...")
# launch()

View File

@ -1,7 +0,0 @@
#ifndef CRASHPOWEROS_DATE_H
#define CRASHPOWEROS_DATE_H
int setup_date();
void launch_date();
#endif //CRASHPOWEROS_DATE_H

View File

@ -1,17 +0,0 @@
#ifndef CRASHPOWEROS_PCAT_H
#define CRASHPOWEROS_PCAT_H
#include "task.h"
struct pcat_process{
uint32_t line;
uint32_t chars;
uint32_t buf_x,buf_y;
uint32_t buffer_screen;
int keys;
struct File *file;
};
void pcat_launch(struct File *file);
#endif

View File

@ -105,6 +105,7 @@ void pci_config(unsigned int bus, unsigned int f, unsigned int equipment, unsign
void init_pci(){
printf("[\035kernel\036]: Loading pci device...\n");
int PCI_NUM = 0;
PCI_ADDR_BASE = kmalloc(1 * 1024 * 1024);
unsigned int i, BUS, Equipment, F, ADDER, *i1;
@ -144,7 +145,7 @@ void init_pci(){
PCI_DATA1 += 4;
int i = ((uint32_t)(bar.address));
memcpy(PCI_DATA1, &i, 4);
printf("[pci]: Device Address: %08x Size: %d\n",bar.address,bar.size);
PCI_NUM++;
}
}
PCI_DATA = PCI_DATA + 0x110 + 4;
@ -154,4 +155,6 @@ void init_pci(){
}
}
}
printf("[pci]: Device Loaded: %d\n",PCI_NUM);
}

View File

@ -17,12 +17,35 @@ extern uint8_t plfont[];
bool vbe_status;
static void copy_char(uint32_t *vram, int off_x, int off_y, int x, int y, int x1,
int y1, int xsize) {
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 8; j++) {
vram[(y + i + off_y) * xsize + (j + x + off_x)] =
vram[(y1 + i + off_y) * xsize + (j + x1 + off_x)];
}
}
}
void vbe_scroll() {
if (cx > c_width) {
cx = 0;
cy++;
} else cx++;
if (cy >= c_height){
cy = c_height - 1;
memcpy((void *)screen,
(void *)screen + width * 16 * sizeof(uint32_t),
width * (height - 16) * sizeof(uint32_t));
for (int i = (width * (height - 16));
i != (width * height); i++) {
screen[i] = back_color;
}
}
/*
if (cy >= c_height) {
cy = c_height - 1;
for (int i = 0; i < height; i++) {
@ -44,6 +67,7 @@ void vbe_scroll() {
screen[height * (width + j) + i] = back_color;
}
}
*/
}
void vbe_draw_char(char c, int32_t x, int32_t y) {
@ -56,8 +80,9 @@ void vbe_draw_char(char c, int32_t x, int32_t y) {
return;
}
unsigned char *font;
font = plfont;
uint8_t *font = ascfont;
font += c * 16;
for (int i = 0; i < 16; i++) {
for (int j = 0; j < 9; j++) {
@ -95,6 +120,10 @@ void vbe_putchar(char ch) {
return;
} else if (ch == '\r') {
cx = 0;
return;
} else if(ch == '\t'){
vbe_putchar(" ");
return;
} else if (ch == '\b' && cx > 0) {
cx -= 1;
if (cx == 0) {
@ -139,19 +168,10 @@ void initVBE(multiboot_t *info) {
screen = (uint32_t) info->framebuffer_addr;
width = info->framebuffer_width;
height = info->framebuffer_height;
color = 0xFFFFFF;
back_color = 0x310924;
color = 0xc6c6c6;
back_color = 0x191f42;
c_width = width / 9;
c_height = height / 16;
vbe_clear();
/*
for (int i = 0; i < c_height; i++){
vbe_putchar('A');
vbe_putchar('\n');
}
while (1) io_hlt();
*/
}

View File

@ -47,7 +47,7 @@ typedef union header {
uint32_t memory_usage();
void *memcpy(void *dst_, const void *src_, uint32_t size);
void* memcpy(void* s, const void* ct, size_t n);
int memcmp(const void *a_, const void *b_, uint32_t size);
@ -89,6 +89,8 @@ void memclean(char *s, int len);
void *realloc(void *ptr, uint32_t size);
page_t *get_phy_page(uint32_t address, int make, page_directory_t *dir);
void alloc_frame_line(page_t *page, unsigned line,int is_kernel, int is_writable);
void free_frame(page_t *page);
#endif //CRASHPOWEROS_MEMORY_H

View File

@ -1,7 +1,7 @@
#ifndef CRASHPOWEROS_NET_H
#define CRASHPOWEROS_NET_H
#include "../include/common.h"
#include "common.h"
typedef struct {
bool (*find)();

4
src/include/panic.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef CRASHPOWEROS_PANIC_H
#define CRASHPOWEROS_PANIC_H
#endif

View File

@ -3,7 +3,7 @@
#define SECTORS_ONCE 8
#include "../include/common.h"
#include "common.h"
typedef struct {
void (*Read)(char drive, unsigned char *buffer, unsigned int number,

View File

@ -9,7 +9,6 @@
#include "../include/cmos.h"
#include "../include/keyboard.h"
#include "../include/shell.h"
#include "../include/date.h"
#include "../include/acpi.h"
#include "../include/syscall.h"
#include "../include/vdisk.h"
@ -85,7 +84,7 @@ void kernel_main(multiboot_t *multiboot) {
printf("[kernel]: Keyboard driver load success!\n");
io_sti();
kernel_thread(cur_task,NULL,"CPOS-VBE-SERVICE");
//kernel_thread(cur_task,NULL,"CPOS-VBE-SERVICE");
init_pit();
init_pci();
@ -99,22 +98,17 @@ void kernel_main(multiboot_t *multiboot) {
vfs_mount_disk('A','A');
if(vfs_change_disk('A'))
printf("[FileSystem]: Change disk win!\n");
else {
for(;;);
}
if(pcnet_find_card()){
//init_pcnet_card();
} else printf("[kernel]: Cannot found pcnet.\n");
print_cpu_id();
//printf("Memory: %dMB.",(multiboot->mem_upper + multiboot->mem_lower)/1024/1024);
clock_sleep(25);
int pid = kernel_thread(setup_shell, NULL, "CPOS-Shell");
kernel_thread(check_task,&pid,"CPOS-SHELL-CHECK");
launch_date();
for (;;) {
io_hlt();

View File

@ -9,11 +9,12 @@ void memclean(char *s, int len) {
return;
}
void *memcpy(void *dst_, const void *src_, uint32_t size) {
uint8_t *dst = dst_;
const uint8_t *src = src_;
while (size-- > 0) *dst++ = *src++;
return (void *) src_;
void* memcpy(void* s, const void* ct, size_t n) {
if (NULL == s || NULL == ct || n <= 0)
return NULL;
while (n--)
*(char*)s++ = *(char*)ct++;
return s;
}
int memcmp(const void *a_, const void *b_, uint32_t size) {

View File

@ -76,6 +76,7 @@ void alloc_frame_line(page_t *page, unsigned line,int is_kernel, int is_writable
page->frame = line / 0x1000;
}
void free_frame(page_t *page) {
uint32_t frame = page->frame;
if (!frame) return;
@ -211,6 +212,8 @@ void init_page(multiboot_t *mboot) {
alloc_frame_line(get_page(j,1,kernel_directory),j,0,0);
j += 0x1000;
}
for (int i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i++) {
alloc_frame(get_page(i, 1, kernel_directory), 0, 0);
}

View File

@ -1,4 +1,5 @@
#include "../include/syscall.h"
#include "../include/printf.h"
#include "../include/isr.h"
void syscall_handler(registers_t *regs){
@ -7,6 +8,8 @@ void syscall_handler(registers_t *regs){
void *location = NULL;//syscalls[regs->eax];
printf("Syscall Win: %08x\n",regs->eax);
int ret;
asm volatile (" \
push %1; \

View File

@ -159,7 +159,6 @@ void change_task_to(struct task_struct *next) {
switch_page_directory(current->pgd_dir);
switch_to(&(prev->context), &(current->context));
}
}

1
src/sysapp/panic.c Normal file
View File

@ -0,0 +1 @@
#include "../include/panic.h"

View File

@ -213,6 +213,27 @@ void cmd_cd(int argc, char **argv) {
if (vfs_change_path(argv[1]) == 0) printf("Invalid path.\n");
}
void cmd_type(int argc,char ** argv){
if (argc == 1) {
print("[Shell-TYPE]: If there are too few parameters, please specify the path.\n");
return;
}
char *buffer;
buffer = (char*) kmalloc(vfs_filesize(argv[1]));
if(buffer == NULL){
printf("Cannot read file.\n");
return;
}
if(vfs_readfile(argv[1],buffer))
printf("%s",buffer);
else printf("Cannot read file.\n");
kfree(buffer);
print("\n");
}
void cmd_disk(int argc, char **argv) {
if (argc > 1) {
if (!strcmp("list", argv[1])) {
@ -285,6 +306,7 @@ char *user() {
void setup_shell() {
char *user1 = "default";//user();
screen_clear();
printf("Welcome to %s %s (CPOS Kernel x86_64)\n"
@ -324,8 +346,8 @@ void setup_shell() {
if (!strcmp("version", argv[0]))
printf("%s for x86 [%s]\n", OS_NAME, OS_VERSION);
else if (!strcmp("echo", argv[0]))
cmd_echo(argc, argv);
else if (!strcmp("type", argv[0]))
cmd_type(argc, argv);
else if (!strcmp("clear", argv[0]))
screen_clear();
else if (!strcmp("proc", argv[0]))
@ -352,7 +374,7 @@ void setup_shell() {
print("-=[CoolPotShell Helper]=-\n");
print("help ? h Print shell help info.\n");
print("version Print os version.\n");
print("echo <msg> Print message.\n");
print("type <name> Read a file.\n");
print("ls List all files.\n");
print("mkdir <name> Make a directory.\n");
print("del rm <name> Delete a file.\n");

View File

@ -1,32 +0,0 @@
#include "../include/date.h"
#include "../include/cmos.h"
#include "../include/graphics.h"
#include "../include/timer.h"
#include "../include/common.h"
extern uint16_t *terminal_buffer;
extern uint8_t terminal_color;
extern bool vbe_status;
int date_pid;
void launch_date(){
if(!vbe_status)
date_pid = kernel_thread(setup_date, NULL, "CPOS-Date");
}
int setup_date(){
char* date_info;
int i;
while (1){
clock_sleep(5);
date_info = get_date_time(); //11
i = 0;
for(size_t x = VGA_WIDTH - 19; x < VGA_WIDTH ; x++){
const size_t index = (VGA_HEIGHT - 1) * VGA_WIDTH + x;
terminal_buffer[index] = vga_entry(date_info[i],terminal_color);
i++;
}
}
return 0;
}

View File

@ -1,126 +0,0 @@
#include "../include/pcat.h"
#include "../include/graphics.h"
#include "../include/keyboard.h"
#include "../include/date.h"
#include "../include/shell.h"
#include "../include/common.h"
struct task_struct *father_pcat;
struct pcat_process *this_process;
uint32_t pid_pcat;
extern KEY_STATUS *key_status;
extern uint16_t *terminal_buffer;
extern uint16_t cursor_x, cursor_y; // 光标位置
extern int date_pid;
static void pcat_movcur(){
cursor_x = this_process->buf_x;
cursor_y = this_process->buf_y;
move_cursor();
}
static void pcat_char(char c){
uint16_t *location;
uint8_t attribute = vga_entry_color(VGA_COLOR_DARK_GREY,VGA_COLOR_BLACK);
if(c == '\n'){
this_process->buf_y++;
this_process->buf_x = 0;
pcat_movcur();
return;
} else if (c == 0x09) {
location = terminal_buffer + (this_process->buf_y * 80 + this_process->buf_x);
*location = ' ' | attribute;
this_process->buf_x = (this_process->buf_x + 8) & ~(8 - 1);
pcat_movcur();
return;
} else if (c == '\b') {
if(this_process->buf_x){
this_process->buf_x--;
location = terminal_buffer + (this_process->buf_y * 80 + this_process->buf_x);
*location = ' ' | attribute;
} else{
if(this_process->buf_y){
this_process->buf_y--;
}
}
char* cc = (char*) this_process->buffer_screen;
int i = (this_process->chars)--;
cc[i] = '\0';
pcat_movcur();
return;
}
vga_putentryat(c, attribute,this_process->buf_x,this_process->buf_y);
this_process->buf_x++;
if (this_process->buf_x >= 80) {
this_process->buf_x = 0;
this_process->buf_y++;
}
pcat_movcur();
char* cc = (char*) this_process->buffer_screen;
int i = (this_process->chars)++;
cc[i] = c;
}
static void draw_string(const char *data){
size_t size = strlen(data);
for (size_t i = 0; i < size; i++)
pcat_char(data[i]);
}
static void draw_menu(){
for (size_t x = 0; x < VGA_WIDTH; x++) {
vga_putentryat(' ',vga_entry_color(VGA_COLOR_BLACK,VGA_COLOR_LIGHT_GREY),x,(VGA_HEIGHT - 1));
}
}
static int input_handler(){
int index = 0;
char c;
while (1) {
c = getc();
if(c == 27){
this_process->keys = 1;
return 0;
}
if (c == '\b') {
if (index > 0) {
index--;
draw_string("\b \b");
}
} else {
index++;
pcat_char(c);
}
}
}
static int check_exit(){
return this_process->keys;
}
void pcat_launch(struct File *file){
screen_clear(); task_kill(date_pid); vga_clear();
this_process = (struct pcat_process*) kmalloc(sizeof(struct pcat_process));
this_process->buf_x = this_process->buf_y = 0;
this_process->line = 1;
this_process->chars = 0;
this_process->buffer_screen = (uint16_t) kmalloc(VGA_WIDTH * (VGA_HEIGHT - 1));
this_process->file = file;
this_process->keys = 0;
int pid = kernel_thread(input_handler,NULL,"CPOS-pcat");
while (1){
if(check_exit()){
break;
}
draw_menu();
input_handler();
}
task_kill(pid);
screen_clear();
date_pid = kernel_thread(setup_date, NULL, "CPOS-Date");
}