完善一些cpos私有api

This commit is contained in:
XIAOYI12 2024-09-01 20:09:41 +08:00
parent 1327ae7724
commit 55379d0c6d
16 changed files with 158 additions and 147486 deletions

30
apps/include/cpos.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef CRASHPOWEROS_CPOS_H
#define CRASHPOWEROS_CPOS_H
struct sysinfo{
char* osname;
char* kenlname;
char* cpu_vendor;
char* cpu_name;
unsigned int phy_mem_size;
unsigned int pci_device;
unsigned int frame_width;
unsigned int frame_height;
};
#include "syscall.h"
#include "stdlib.h"
static inline struct sysinfo* get_sysinfo(){
return syscall_sysinfo();
}
static inline void free_info(struct sysinfo *info){
free(info->kenlname);
free(info->osname);
free(info->cpu_name);
free(info->cpu_vendor);
free(info);
}
#endif

View File

@ -12,6 +12,7 @@
#define SYSCALL_VFS_FILESIZE 9 #define SYSCALL_VFS_FILESIZE 9
#define SYSCALL_VFS_READFILE 10 #define SYSCALL_VFS_READFILE 10
#define SYSCALL_VFS_WRITEFILE 11 #define SYSCALL_VFS_WRITEFILE 11
#define SYSCALL_SYSINFO 12
#include "ctype.h" #include "ctype.h"
@ -26,5 +27,6 @@ void syscall_get_cd(char *buffer);
int syscall_vfs_filesize(char* filename); int syscall_vfs_filesize(char* filename);
void syscall_vfs_readfile(char* filename,char* buffer); void syscall_vfs_readfile(char* filename,char* buffer);
void syscall_vfs_writefile(char* filename,char* buffer,unsigned int size); void syscall_vfs_writefile(char* filename,char* buffer,unsigned int size);
void* syscall_sysinfo();
#endif #endif

View File

@ -81,3 +81,9 @@ void syscall_vfs_writefile(char* filename,char* buffer,unsigned int size){
register uint32_t edx asm("edx") = __arg3; register uint32_t edx asm("edx") = __arg3;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_VFS_FILESIZE), "r"(ebx), "r"(ecx), "r"(edx) : "memory", "cc"); asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_VFS_FILESIZE), "r"(ebx), "r"(ecx), "r"(edx) : "memory", "cc");
} }
void* syscall_sysinfo(){
uint32_t rets;
asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_SYSINFO) : "memory", "cc");
return rets;
}

View File

@ -1,4 +1,4 @@
OBJS_PACK = out/shell.obj OBJS_PACK = out/shell.obj out/neofetch.obj
include ../def.mk include ../def.mk
default: $(OBJS_PACK) default: $(OBJS_PACK)

44
apps/shell/neofetch.c Normal file
View File

@ -0,0 +1,44 @@
#include "stdio.h"
#include "stdlib.h"
#include "../include/cpos.h"
void print_info(){
struct sysinfo *info = get_sysinfo();
printf(" .:=*#&&@@@@@@&&#+=:. \n"
" -+&@@@@@@@@@@@@@@@@@@@- ----------. -----------------\n"
" -*@@@@@@@@@@@@@@@@@@@@&=.-&@@@@@@@@@@+ OSName: %s\n"
" =&@@@@@@@@@@@@@@@@@@@@@=.-&@@@@@@@@@@@@+ Kernel: %s\n"
" -&@@@@@@@@@@@@@@@@@@@@@=.-&@@@@@@@@@@@@@@+ CPU Vendor: %s\n"
" *@@@@@@@@@@@@@@@@@@@@@=.-&@@@@@@@@@@@@@@@@+ CPU: %s\n"
" .&@@@@@@@@@@@@@@@&*=-:: :#@@@@@@@@@@@@@@@@@@= Memory: %dMB\n"
" &@@@@@@@@@@@@@&=. #@@@@@@@@@@@@@@@@@#:.= Console: CPOS_USER_SHELL\n"
" *@@@@@@@@@@@@@- #@@@@@@@@@@@@@@@#:.=@@+ PCI Device: %d\n"
":@@@@@@@@@@@@&. #@@@@@@@@@@@@@#: =@@@@@. Resolution: %d x %d\n"
"#@@@@@@@@@@@@. #@@@@@@@@@@@#: =@@@@@@@+\n"
"@@@@@@@@@@@@+ *&&&&&&&&&#- =@@@@@@@@@&\n"
"@@@@@@@@@@@@- :@@@@@@@@@@@@\n"
"@@@@@@@@@@@@+ #@@@@@@@@@@@&\n"
"*@@@@@@@@@@@@. :@@@@@@@@@@@@+\n"
":@@@@@@@@@@@@&. :@@@@@@@@@@@@@.\n"
" *@@@@@@@@@@@@@= =@@@@@@@@@@@@@+ \n"
" #@@@@@@@@@@@@@&+: :+@@@@@@@@@@@@@@# \n"
" #@@@@@@@@@@@@@@@&*+=----=+#&@@@@@@@@@@@@@@@* \n"
" +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@+ \n"
" :&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#: \n"
" -#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#- \n"
" :*@@@@@@@@@@@@@@@@@@@@@@@@@@@&+: \n"
" :+#@@@@@@@@@@@@@@@@@@@@#+: \n"
" :=+*#&@@@@@@&#*+-: \n",
info->osname,
info->kenlname,
info->cpu_vendor,
info->cpu_name,
info->phy_mem_size,
info->pci_device,
info->frame_width,
info->frame_height);
free_info(info);
}

View File

@ -1,11 +1,15 @@
#include <stdio.h> #include <stdio.h>
#include "../include/syscall.h" #include "../include/syscall.h"
#include "../include/string.h" #include "../include/string.h"
#include "../include/math.h" #include "../include/cpos.h"
extern void print_info();
static int gets(char *buf) {
static int gets(char *buf, int buf_size) {
int index = 0; int index = 0;
char c; char c;
while ((c = syscall_getch()) != '\n') { while ((c = syscall_getch()) != '\n') {
if (c == '\b') { if (c == '\b') {
if (index > 0) { if (index > 0) {
@ -51,24 +55,24 @@ int main(){
int argc = -1; int argc = -1;
char *buffer[255]; char *buffer[255];
double x = sin(12);
printf("%08f",x);
while (1){ while (1){
syscall_get_cd(buffer); syscall_get_cd(buffer);
printf("%s$ ",buffer); printf("\03343cd80;default@localhost: \0334169E1;%s\\\033c6c6c6;$ ",buffer);
if (gets(com, 100) <= 0) continue;
if (gets(com) <= 0) continue;
argc = cmd_parse(com, argv, ' '); argc = cmd_parse(com, argv, ' ');
if (argc == -1) { if (argc == -1) {
printf("[Shell]: Error: out of arguments buffer\n"); printf("[Shell]: Error: out of arguments buffer\n");
continue; continue;
} }
if (!strcmp("version", argv[0])) if (!strcmp("version", argv[0])){
printf("CoolPotOS for x86 [v0.3.1]\n"); print_info();
else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) { }else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) {
printf("-=[CoolPotShell Helper]=-\n"); printf("-=[CoolPotShell Helper]=-\n");
printf("help ? h Print shell help info.\n"); printf("help ? h Print shell help info.\n");
printf("version Print os version.\n"); printf("version Print os version.\n");
@ -87,5 +91,4 @@ int main(){
printf("exec <path> Execute a application.\n"); printf("exec <path> Execute a application.\n");
} else printf("\033ff3030;[Shell]: Unknown command '%s'.\033c6c6c6;\n", argv[0]); } else printf("\033ff3030;[Shell]: Unknown command '%s'.\033c6c6c6;\n", argv[0]);
} }
return 0;
} }

View File

@ -42,6 +42,14 @@ static void get_cpu_address_sizes(cpu_t *c) {
c->phys_bits = eax & 0xff; c->phys_bits = eax & 0xff;
} }
cpu_t * get_cpuid(){
cpu_t *c = (cpu_t *) kmalloc(sizeof(cpu_t));
get_vendor_name(c);
get_model_name(c);
get_cpu_address_sizes(c);
return c;
}
void print_cpu_id() { void print_cpu_id() {
cpu_t *c = (cpu_t *) kmalloc(sizeof(cpu_t)); cpu_t *c = (cpu_t *) kmalloc(sizeof(cpu_t));
get_vendor_name(c); get_vendor_name(c);

View File

@ -4,6 +4,7 @@
#include "../include/printf.h" #include "../include/printf.h"
unsigned int PCI_ADDR_BASE; unsigned int PCI_ADDR_BASE;
unsigned int PCI_NUM = 0;
uint8_t pci_get_drive_irq(uint8_t bus, uint8_t slot, uint8_t func) { uint8_t pci_get_drive_irq(uint8_t bus, uint8_t slot, uint8_t func) {
return (uint8_t)read_pci(bus, slot, func, 0x3c); return (uint8_t)read_pci(bus, slot, func, 0x3c);
@ -104,7 +105,6 @@ void pci_config(unsigned int bus, unsigned int f, unsigned int equipment, unsign
} }
void init_pci(){ void init_pci(){
int PCI_NUM = 0;
PCI_ADDR_BASE = kmalloc(1 * 1024 * 1024); PCI_ADDR_BASE = kmalloc(1 * 1024 * 1024);
unsigned int i, BUS, Equipment, F, ADDER, *i1; unsigned int i, BUS, Equipment, F, ADDER, *i1;

View File

@ -18,7 +18,6 @@ uint32_t *char_buffer;
extern uint8_t ascfont[]; extern uint8_t ascfont[];
extern uint8_t plfont[]; extern uint8_t plfont[];
extern uint8_t bafont[]; extern uint8_t bafont[];
extern uint8_t logo_bmp[];
bool vbe_status = false; bool vbe_status = false;
@ -182,10 +181,5 @@ void initVBE(multiboot_t *info) {
c_width = width / 9; c_width = width / 9;
c_height = height / 16; c_height = height / 16;
logkf("SCREEN BASS: %08x\n",screen);
vbe_clear(); vbe_clear();
Bmp *bmp = (Bmp*) &logo_bmp;
//display(bmp,0,0,false);
} }

View File

@ -29,6 +29,7 @@ typedef struct {
uint8_t read_cmos(uint8_t p); uint8_t read_cmos(uint8_t p);
char *get_date_time(); char *get_date_time();
void print_cpu_id(); void print_cpu_id();
cpu_t * get_cpuid();
uint32_t get_hour(); uint32_t get_hour();
uint32_t get_min(); uint32_t get_min();

View File

@ -3,6 +3,7 @@
#define OS_NAME "CoolPotOS" #define OS_NAME "CoolPotOS"
#define OS_VERSION "v0.3.1" #define OS_VERSION "v0.3.1"
#define KERNEL_NAME "CP_Kernel-i386-0.3.1"
// b 0x211972 // b 0x211972
// b 0x20d0a6 // b 0x20d0a6

View File

@ -16,6 +16,7 @@
#define SYSCALL_VFS_FILESIZE 9 #define SYSCALL_VFS_FILESIZE 9
#define SYSCALL_VFS_READFILE 10 #define SYSCALL_VFS_READFILE 10
#define SYSCALL_VFS_WRITEFILE 11 #define SYSCALL_VFS_WRITEFILE 11
#define SYSCALL_SYSINFO 12
void syscall_install(); void syscall_install();

View File

@ -29,6 +29,8 @@ extern vdisk vdisk_ctl[10];
extern bool hasFS; extern bool hasFS;
uint32_t placement_address = (uint32_t) & end; uint32_t placement_address = (uint32_t) & end;
uint32_t phy_mem_size;
void reset_kernel(){ void reset_kernel(){
printf("Restart %s for x86...\n",OS_NAME); printf("Restart %s for x86...\n",OS_NAME);
kill_all_task(); kill_all_task();
@ -74,6 +76,8 @@ void kernel_main(multiboot_t *multiboot) {
while (1) io_hlt(); while (1) io_hlt();
} }
phy_mem_size = (multiboot->mem_upper + multiboot->mem_lower) / 1024;
initVBE(multiboot); initVBE(multiboot);
char* cmdline = multiboot->cmdline; char* cmdline = multiboot->cmdline;
@ -81,7 +85,7 @@ void kernel_main(multiboot_t *multiboot) {
printf("Multiboot command line: %s\n",cmdline); printf("Multiboot command line: %s\n",cmdline);
} }
printf("CPOS_Kernel %s (GRUB Multiboot) on an i386.\n",OS_VERSION); printf("%s OS Version: %s (GRUB Multiboot) on an i386.\n",KERNEL_NAME,OS_VERSION);
printf("Memory Size: %dMB\n",(multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1); printf("Memory Size: %dMB\n",(multiboot->mem_upper + multiboot->mem_lower) / 1024 + 1);
gdt_install(); gdt_install();
idt_install(); idt_install();

View File

@ -8,6 +8,10 @@
#include "../include/heap.h" #include "../include/heap.h"
#include "../include/keyboard.h" #include "../include/keyboard.h"
#include "../include/vfs.h" #include "../include/vfs.h"
#include "../include/cmos.h"
extern uint32_t phy_mem_size;
extern unsigned int PCI_NUM;
static void syscall_puchar(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ static void syscall_puchar(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
printf("%c",ebx); printf("%c",ebx);
@ -60,6 +64,44 @@ static void syscall_vfs_writefile(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_
vfs_writefile(ebx,ecx,edx); vfs_writefile(ebx,ecx,edx);
} }
struct sysinfo{
char* osname;
char* kenlname;
char* cpu_vendor;
char* cpu_name;
unsigned int phy_mem_size;
unsigned int pci_device;
unsigned int frame_width;
unsigned int frame_height;
};
static void* syscall_sysinfo(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){
struct sysinfo *info = (struct sysinfo *) user_alloc(get_current(), sizeof(struct sysinfo));
cpu_t *cpu = get_cpuid();
char *os_name = user_alloc(get_current(), strlen(OS_NAME));
char *kernel = user_alloc(get_current(), strlen(OS_NAME));
char *cpu_vendor = user_alloc(get_current(), strlen(cpu->vendor));
char *cpu_name = user_alloc(get_current(), strlen(cpu->model_name));
memcpy(os_name,OS_NAME, 40);
memcpy(kernel,KERNEL_NAME, 40);
memcpy(cpu_vendor,cpu->vendor, strlen(cpu->vendor));
memcpy(cpu_name,cpu->model_name, strlen(cpu->model_name));
extern uint32_t width,height; //vbe.c
info->osname = os_name;
info->kenlname = kernel;
info->cpu_vendor = cpu_vendor;
info->cpu_name = cpu_name;
info->phy_mem_size = phy_mem_size;
info->pci_device = PCI_NUM;
info->frame_width = width;
info->frame_height = height;
return info;
}
void *sycall_handlers[MAX_SYSCALLS] = { void *sycall_handlers[MAX_SYSCALLS] = {
[SYSCALL_PUTC] = syscall_puchar, [SYSCALL_PUTC] = syscall_puchar,
[SYSCALL_PRINT] = syscall_print, [SYSCALL_PRINT] = syscall_print,
@ -72,6 +114,7 @@ void *sycall_handlers[MAX_SYSCALLS] = {
[SYSCALL_VFS_FILESIZE] = syscall_vfs_filesize, [SYSCALL_VFS_FILESIZE] = syscall_vfs_filesize,
[SYSCALL_VFS_READFILE] = syscall_vfs_readfile, [SYSCALL_VFS_READFILE] = syscall_vfs_readfile,
[SYSCALL_VFS_WRITEFILE] = syscall_vfs_writefile, [SYSCALL_VFS_WRITEFILE] = syscall_vfs_writefile,
[SYSCALL_SYSINFO] = syscall_sysinfo,
}; };
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t); typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);

View File

@ -212,7 +212,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
page_directory_t *page = clone_directory(kernel_directory); page_directory_t *page = clone_directory(kernel_directory);
new_task->pgd_dir = page; new_task->pgd_dir = page;
new_task->mem_size = 0; new_task->mem_size = 0;
new_task->program_break = USER_START; new_task->program_break = USER_START + 0xf0000;
new_task->program_break_end = USER_HEAP_END; new_task->program_break_end = USER_HEAP_END;
new_task->name = name; new_task->name = name;
new_task->isUser = 1; new_task->isUser = 1;

File diff suppressed because it is too large Load Diff