From beee408a873eb915f6ca438c23b5ff9f9fd578e6 Mon Sep 17 00:00:00 2001 From: xiaoyi1212 Date: Fri, 6 Sep 2024 00:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9B=E7=A8=8Bvfs?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/include/cpos.h | 4 + apps/include/stdio.h | 1 + apps/include/stdlib.h | 1 + apps/include/syscall.h | 2 + apps/init/init.c | 10 +- apps/libs/libc.c | 11 ++ apps/libs/syscall.c | 8 ++ apps/shell/shell.c | 2 +- src/driver/sb16.c | 280 ----------------------------------------- src/fs/vfs.c | 15 ++- src/include/sb16.h | 65 ---------- src/include/syscall.h | 1 + src/include/tty.h | 6 + src/include/vfs.h | 1 + src/kernel/kernel.c | 15 +-- src/kernel/syscall.c | 5 + src/kernel/task.c | 13 +- src/kernel/tty.c | 56 ++++++++- src/sysapp/shell.c | 12 -- src/sysapp/soundtest.c | 71 ----------- src/util/textmode.c | 63 ++++++++++ 21 files changed, 184 insertions(+), 458 deletions(-) delete mode 100644 src/driver/sb16.c delete mode 100644 src/include/sb16.h delete mode 100644 src/sysapp/soundtest.c create mode 100644 src/util/textmode.c diff --git a/apps/include/cpos.h b/apps/include/cpos.h index 68e6ccf..c5fbb95 100644 --- a/apps/include/cpos.h +++ b/apps/include/cpos.h @@ -35,4 +35,8 @@ static inline void free_info(struct sysinfo *info){ free(info); } +static inline int exec_elf(const char* filename){ + return syscall_exec(filename); +} + #endif diff --git a/apps/include/stdio.h b/apps/include/stdio.h index 6aa4a15..57a7940 100644 --- a/apps/include/stdio.h +++ b/apps/include/stdio.h @@ -22,6 +22,7 @@ typedef struct FILE { } FILE; void put_char(char a); +int scanf(const char *format, ...); int printf(const char* fmt, ...); int puts(const char *s); int vsprintf(char *buf, const char *fmt, va_list args); diff --git a/apps/include/stdlib.h b/apps/include/stdlib.h index b84a2b8..5966295 100644 --- a/apps/include/stdlib.h +++ b/apps/include/stdlib.h @@ -8,5 +8,6 @@ void *malloc(size_t size); void free(void *ptr); void exit(int code); void *realloc(void *ptr, uint32_t size); +void *calloc(size_t n, size_t size); #endif diff --git a/apps/include/syscall.h b/apps/include/syscall.h index 844f777..0914765 100644 --- a/apps/include/syscall.h +++ b/apps/include/syscall.h @@ -13,6 +13,7 @@ #define SYSCALL_VFS_READFILE 10 #define SYSCALL_VFS_WRITEFILE 11 #define SYSCALL_SYSINFO 12 +#define SYSCALL_EXEC 13 #include "ctype.h" @@ -28,5 +29,6 @@ int syscall_vfs_filesize(char* filename); void syscall_vfs_readfile(char* filename,char* buffer); void syscall_vfs_writefile(char* filename,char* buffer,unsigned int size); void* syscall_sysinfo(); +int syscall_exec(char *filename); #endif diff --git a/apps/init/init.c b/apps/init/init.c index 35e9af4..ef1373c 100644 --- a/apps/init/init.c +++ b/apps/init/init.c @@ -1,6 +1,12 @@ #include "../include/stdio.h" +#include "../include/cpos.h" int main(){ - printf("User application %d\n",12); - return -1; + printf("Init service launched.\n"); + int pid = exec_elf("shell.bin"); + printf("Launching shell pid [%d]\n",pid); + if(pid != -1){ + printf("Shell launch win! PID:[%d]\n",pid); + } else printf("Error: Cannot launch shell\n"); + return 0; } diff --git a/apps/libs/libc.c b/apps/libs/libc.c index 456b5c3..d7bb68a 100644 --- a/apps/libs/libc.c +++ b/apps/libs/libc.c @@ -24,6 +24,13 @@ void *realloc(void *ptr, uint32_t size) { return new; } +void *calloc(size_t n, size_t size) { + void *ptr = malloc(n * size); + if (ptr == NULL) return NULL; + memset(ptr, 0, n * size); + return ptr; +} + long long atoi(const char* s){ long long temp = 0,sign = (*s <= '9' && *s >= '0') ; while(*s > '9' || *s < '0')s ++ ; @@ -37,6 +44,10 @@ void put_char(char c){ syscall_putchar(c); } +int scanf(const char *format, ...){ + +} + int fputc(int ch, FILE *stream) { if (CANWRITE(stream->mode)) { diff --git a/apps/libs/syscall.c b/apps/libs/syscall.c index 35865cb..86ccfbe 100644 --- a/apps/libs/syscall.c +++ b/apps/libs/syscall.c @@ -86,4 +86,12 @@ void* syscall_sysinfo(){ uint32_t rets; asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_SYSINFO) : "memory", "cc"); return rets; +} + +int syscall_exec(char *filename){ + uint32_t rets; + uint32_t __arg1 = (uint32_t)(filename); + register uint32_t ebx asm("ebx") = __arg1; + asm volatile("int $31\n\t" : "=a"(rets) : "0"(SYSCALL_EXEC), "r"(ebx) : "memory", "cc"); + return rets; } \ No newline at end of file diff --git a/apps/shell/shell.c b/apps/shell/shell.c index 3d09f66..5b9e312 100644 --- a/apps/shell/shell.c +++ b/apps/shell/shell.c @@ -57,7 +57,7 @@ int main(){ while (1){ syscall_get_cd(buffer); - printf("\03343cd80;default@localhost: \0334169E1;%s\\\033c6c6c6;$ ",buffer); + printf("\033[40m;default@localhost: \03330m;%s\\\03321m;$ ",buffer); if (gets(com) <= 0) continue; diff --git a/src/driver/sb16.c b/src/driver/sb16.c deleted file mode 100644 index decb9bd..0000000 --- a/src/driver/sb16.c +++ /dev/null @@ -1,280 +0,0 @@ -/* -#include "../include/sb16.h" -#include "../include/io.h" -#include "../include/printf.h" -#include "../include/timer.h" -#include "../include/dma.h" -#include "../include/file.h" - -static void *const DMA_BUF_ADDR1 = (void *)0x90000; // 不能跨越 64K 边界 -static void *const DMA_BUF_ADDR2 = (void *)0x90000 + DMA_BUF_SIZE; // 不能跨越 64K 边界 - -#define STAT_OFF 0 // 未开启 -#define STAT_WAITING 1 // 等待第一个缓冲区 -#define STAT_PAUSED 2 // 已暂停 -#define STAT_PLAYING 3 // 正在播放音频 -#define STAT_CLOSING 4 // 正在等待播放完毕并关闭 - -#if VSOUND_RWAPI -static void sb_exch_dmaaddr() { - char *addr = sb.addr1; - sb.addr1 = sb.addr2; - sb.addr2 = addr; - size_t size = sb.size1; - sb.size1 = sb.size2; - sb.size2 = size; -} -#endif - -static void sb_send(uint8_t cmd) { - waitif(io_in8(SB_WRITE) & MASK(7)); - io_out8(SB_WRITE, cmd); -} - -#if VSOUND_RWAPI -static void sb16_do_dma() { - size_t dmasize; - size_t len; - if (sb.auto_mode) { - dmasize = 2 * DMA_BUF_SIZE; - len = sb.depth == 8 ? DMA_BUF_SIZE : DMA_BUF_SIZE / 2; - len = sb.channels == 2 ? len / 2 : len; - if (sb.status != STAT_WAITING) return; - } else { - dmasize = sb.size2; - len = sb.depth == 8 ? sb.size2 : sb.size2 / 2; - len = sb.channels == 2 ? len / 2 : len; - } - - byte mode = (sb.auto_mode ? 16 : 0) | 0x48; // 0x48 为播放 0x44 为录音 - dma_start(mode, sb.dma_channel, sb.addr2, dmasize, sb.depth == 16); - if (sb.auto_mode) { - sb_send(sb.depth == 8 ? CMD_AUTO_OUT8 : CMD_AUTO_OUT16); - } else { - sb_send(sb.depth == 8 ? CMD_SINGLE_OUT8 : CMD_SINGLE_OUT16); - } - sb_send(sb.mode); - - sb_send((len - 1) & 0xff); - sb_send(((len - 1) >> 8) & 0xff); -} -#endif - -#if VSOUND_RWAPI -static void sb16_send_buffer() { - if (sb.size1 == 0) return; - sb_exch_dmaaddr(); - sb16_do_dma(); - if (sb.status == STAT_WAITING) sb.status = STAT_PLAYING; -} -#endif - -static void sb16_do_close() { - if (sb.auto_mode) { - sb_send(sb.depth == 8 ? 0xD9 : 0xDA); - } else { - sb_send(CMD_OFF); - } - sb.use_task = null; - sb.status = STAT_OFF; -} - -static vsound_t snd; - -void sb16_handler(registers_t *reg) { - - io_in8(sb.depth == 16 ? SB_INTR16 : SB_STATE); - -#if VSOUND_RWAPI - sb.size2 = 0; - if (sb.size1 == 0) sb.status = STAT_WAITING; - sb16_send_buffer(); -#else - vsound_played(snd); -#endif - - if (sb.status == STAT_CLOSING) { - sb16_do_close(); - return; - } -} - -void sb16_init() { - sb.use_task = NULL; - sb.status = STAT_OFF; - register_interrupt_handler(SB16_IRQ + 0x20, sb16_handler); -} - -static void sb_reset() { - io_out8(SB_RESET, 1); - auto oldcnt = timerctl.count; - waitif(timerctl.count <= oldcnt + 10); - io_out8(SB_RESET, 0); - uint8_t state = io_in8(SB_READ); -} - -static void sb_intr_irq() { - io_out8(SB_MIXER, 0x80); - uint8_t data = io_in8(SB_MIXER_DATA); - if (data != 2) { - io_out8(SB_MIXER, 0x80); - io_out8(SB_MIXER_DATA, 0x2); - } -} - -static void sb16_set_samplerate(uint16_t rate) { - sb_send(CMD_SOSR); - sb_send(rate >> 8); - sb_send(rate & 0xff); -} - -static void sb16_set_volume(double volume) { - volume = max(0, min(volume, 1)); - klogd("set sb16 volume to %d%%", (int)(volume * 100)); - io_out8(SB_MIXER, 0x22); - io_out8(SB_MIXER_DATA, volume * 255); -} - -extern bool is_vbox; - -static int sb16_open(vsound_t vsound) { - uint16_t fmt = vsound->fmt; - uint16_t channels = vsound->channels; - uint32_t rate = vsound->rate; - double volume = vsound->volume; - - sb.use_task = get_current(); - - sb_reset(); // 重置 DSP - sb_intr_irq(); // 设置中断 - sb_send(CMD_ON); // 打开声卡 - - if (fmt == SOUND_FMT_S16 || fmt == SOUND_FMT_U16) { - sb.depth = 16; - sb.dma_channel = 5; - } else if (fmt == SOUND_FMT_U8 || fmt == SOUND_FMT_S8) { - sb.depth = 8; - sb.dma_channel = 1; - } - if (channels == 1) { - sb.mode = (fmt == SOUND_FMT_S16 || fmt == SOUND_FMT_S8) ? MODE_SMONO : MODE_UMONO; - } else { - sb.mode = (fmt == SOUND_FMT_S16 || fmt == SOUND_FMT_S8) ? MODE_SSTEREO : MODE_USTEREO; - } - sb.status = STAT_WAITING; -#if VSOUND_RWAPI - sb.addr1 = DMA_BUF_ADDR1; - sb.addr2 = DMA_BUF_ADDR2; - sb.size1 = 0; - sb.size2 = 0; -#endif - sb.channels = channels; - sb.auto_mode = is_vbox ? true : false; - - sb16_set_samplerate(rate); - sb16_set_volume(volume); - - return 0; -} - -static void sb16_close(vsound_t vsound) { - if (sb.status == STAT_PLAYING) { - sb.status = STAT_CLOSING; - } else { - sb16_do_close(); - } -} - -#if VSOUND_RWAPI -static int sb16_write(vsound_t vsound, const void *data, size_t len) { - size_t size = len * vsound->settings.bytes_per_sample; - while (size > 0) { - waitif(sb.size1 == DMA_BUF_SIZE); - asm_cli; - size_t nwrite = min(size, DMA_BUF_SIZE - sb.size1); - memcpy(sb.addr1 + sb.size1, data, nwrite); - sb.size1 += nwrite; - data += nwrite; - size -= nwrite; - asm_sti; - if (sb.auto_mode) { - if (sb.status == STAT_WAITING && sb.size1 == DMA_BUF_SIZE) sb16_send_buffer(); - } else { - if (sb.status == STAT_WAITING) sb16_send_buffer(); - } - } - return 0; -} -#endif - -#if !VSOUND_RWAPI -static int sb16_start_dma(vsound_t vsound, void *addr) { - size_t dmasize; - size_t len; - if (sb.auto_mode) { - dmasize = 2 * DMA_BUF_SIZE; - len = DMA_BUF_SIZE / vsound->bytes_per_sample; - if (sb.status != STAT_WAITING) return 0; - } else { - dmasize = DMA_BUF_SIZE; - len = DMA_BUF_SIZE / vsound->bytes_per_sample; - } - - byte mode = (sb.auto_mode ? 16 : 0) | 0x48; // 0x48 为播放 0x44 为录音 - dma_start(mode, sb.dma_channel, addr, dmasize, sb.depth == 16); - if (sb.auto_mode) { - sb_send(sb.depth == 8 ? CMD_AUTO_OUT8 : CMD_AUTO_OUT16); - } else { - sb_send(sb.depth == 8 ? CMD_SINGLE_OUT8 : CMD_SINGLE_OUT16); - } - sb_send(sb.mode); - - sb_send((len - 1) & 0xff); - sb_send(((len - 1) >> 8) & 0xff); - - if (sb.status == STAT_WAITING) sb.status = STAT_PLAYING; - return 0; -} -#endif - -static struct vsound vsound = { - .is_output = true, -#if VSOUND_RWAPI - .is_rwmode = true, -#endif - .name = "sb16", - .open = sb16_open, - .close = sb16_close, -#if VSOUND_RWAPI - .write = sb16_write, -#else - .start_dma = sb16_start_dma, - .bufsize = DMA_BUF_SIZE, -#endif -}; - -static const i16 fmts[] = { - SOUND_FMT_S8, SOUND_FMT_U8, SOUND_FMT_S16, SOUND_FMT_U16, -1, -}; - -static const i32 rates[] = { - 8000, 11025, 16000, 22050, 24000, 32000, 44100, 47250, 48000, 50000, -1, -}; - -void sb16_regist() { - snd = &vsound; - if (!vsound_regist(snd)) { - klogw("注册 sb16 失败"); - return; - } - vsound_set_supported_fmts(snd, fmts, -1); - vsound_set_supported_rates(snd, rates, -1); - vsound_set_supported_ch(snd, 1); - vsound_set_supported_ch(snd, 2); -#if !VSOUND_RWAPI - vsound_addbuf(snd, DMA_BUF_ADDR1); - vsound_addbuf(snd, DMA_BUF_ADDR2); -#endif -} - - */ \ No newline at end of file diff --git a/src/fs/vfs.c b/src/fs/vfs.c index 7155b61..b2cdd1a 100644 --- a/src/fs/vfs.c +++ b/src/fs/vfs.c @@ -1,6 +1,6 @@ /* * PlantsOS FileSystem Abstract Interface - * Copyright by min0911 + * Author: min0911 */ #include "../include/printf.h" #include "../include/vfs.h" @@ -302,8 +302,6 @@ vfs_file *vfs_fileinfo(char *filename) { return false; } - - vfs_file *result = vfs->FileInfo(vfs, new_path); kfree(new_path); return result; @@ -417,4 +415,15 @@ bool vfs_register_fs(vfs_t vfs) { *seat = vfs; klogf(true,"Register file system: %s\n",vfs.FSName); return true; +} + +void vfs_copy(struct task_struct *task,vfs_t* src){ + vfs_change_disk(task, src->drive); + List *l; + char *path; + for (int i = 1; FindForCount(i, task->vfs_now->path) != NULL; i++) { + l = FindForCount(i, task->vfs_now->path); + path = (char *)l->val; + task->vfs_now->cd(task->vfs_now, path); + } } \ No newline at end of file diff --git a/src/include/sb16.h b/src/include/sb16.h deleted file mode 100644 index d768ce7..0000000 --- a/src/include/sb16.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef CRASHPOWEROS_SB16_H -#define CRASHPOWEROS_SB16_H - -#define SB_MIXER 0x224 // DSP 混合器端口 -#define SB_MIXER_DATA 0x225 // DSP 混合器数据端口 -#define SB_RESET 0x226 // DSP 重置 -#define SB_READ 0x22A // DSP 读 -#define SB_WRITE 0x22C // DSP 写 -#define SB_STATE 0x22E // DSP 读状态 -#define SB_INTR16 0x22F // DSP 16 位中断响应 - -#define CMD_STC 0x40 // Set Time Constant -#define CMD_SOSR 0x41 // Set Output Sample Rate -#define CMD_SISR 0x42 // Set Input Sample Rate - -#define CMD_SINGLE_IN8 0xC8 // Transfer mode 8bit input -#define CMD_SINGLE_OUT8 0xC0 // Transfer mode 8bit output -#define CMD_SINGLE_IN16 0xB8 // Transfer mode 16bit input -#define CMD_SINGLE_OUT16 0xB0 // Transfer mode 16bit output - -#define CMD_AUTO_IN8 0xCE // Transfer mode 8bit input auto -#define CMD_AUTO_OUT8 0xC6 // Transfer mode 8bit output auto -#define CMD_AUTO_IN16 0xBE // Transfer mode 16bit input auto -#define CMD_AUTO_OUT16 0xB6 // Transfer mode 16bit output auto - -#define CMD_ON 0xD1 // Turn speaker on -#define CMD_OFF 0xD3 // Turn speaker off -#define CMD_SP8 0xD0 // Stop playing 8 bit channel -#define CMD_RP8 0xD4 // Resume playback of 8 bit channel -#define CMD_SP16 0xD5 // Stop playing 16 bit channel -#define CMD_RP16 0xD6 // Resume playback of 16 bit channel -#define CMD_VERSION 0xE1 // Turn speaker off - -#define MODE_SMONO (0b01 << 4) -#define MODE_SSTEREO (0b11 << 4) -#define MODE_UMONO (0b00 << 4) -#define MODE_USTEREO (0b10 << 4) - -#define STATUS_READ 0x80 // read buffer status -#define STATUS_WRITE 0x80 // write buffer status - -#define DMA_BUF_SIZE 4096 // 缓冲区长度 -#define SB16_IRQ 5 - -#include "task.h" -#include "common.h" -#include "isr.h" - -static struct { - struct task_struct *use_task; // - int status; // - bool auto_mode; // -#if VSOUND_RWAPI - void *volatile addr1; // DMA 地址 - volatile size_t size1; // - void *volatile addr2; // DMA 地址 - volatile size_t size2; // -#endif - uint8_t mode; // 模式 - uint8_t dma_channel; // DMA 通道 - uint8_t depth; // 采样深度 - int channels; // 声道数 -} sb; - -#endif diff --git a/src/include/syscall.h b/src/include/syscall.h index e4ec5b5..c084af2 100644 --- a/src/include/syscall.h +++ b/src/include/syscall.h @@ -17,6 +17,7 @@ #define SYSCALL_VFS_READFILE 10 #define SYSCALL_VFS_WRITEFILE 11 #define SYSCALL_SYSINFO 12 +#define SYSCALL_EXEC 13 void syscall_install(); diff --git a/src/include/tty.h b/src/include/tty.h index 93f7687..2cd226c 100644 --- a/src/include/tty.h +++ b/src/include/tty.h @@ -36,9 +36,12 @@ typedef struct tty{ struct FIFO8 *fifo; // 键盘输出缓冲区 key_lis keyboard_press; // 键盘按下 key_lis keyboard_release; // 键盘松开 + uint32_t *vram; + uint32_t width,height; int xsize, ysize; int x, y; uint8_t color; + int Raw_y; /* vt100 */ int vt100; // 是否检测到标志 @@ -53,5 +56,8 @@ typedef struct tty{ void init_default_tty(struct task_struct *task); void free_tty(struct task_struct *task); +void clear_TextMode(struct tty *res); +void screen_ne_TextMode(struct tty *res); +void putchar_TextMode(struct tty *res, int c); #endif diff --git a/src/include/vfs.h b/src/include/vfs.h index cc50470..77b21a1 100644 --- a/src/include/vfs.h +++ b/src/include/vfs.h @@ -74,5 +74,6 @@ bool vfs_change_disk(struct task_struct *task,uint8_t drive); bool vfs_register_fs(vfs_t vfs); void init_vfs(); vfs_file *get_cur_file(char* filename); +void vfs_copy(struct task_struct *task,vfs_t* src); #endif diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 8a6d9e9..75a9942 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -159,21 +159,8 @@ void kernel_main(multiboot_t *multiboot) { clock_sleep(25); vfs_change_path("apps"); - int pid = user_process("shell.bin","Shell"); - klogf(pid != -1,"Shell process init.\n"); - if(pid == -1){ - printf("UserShell launch fault.\n"); - printf("Launching system shell...\n"); + klogf(user_process("init.bin","InitService") != -1,"Init service process init.\n"); - int pid = kernel_thread(setup_shell,NULL,"CPOS-Shell"); - klogf(pid != -1,"Launch kernel shell.\n"); - kernel_thread(check_task,&pid,"CPOS-CK"); - goto ker; - } - - kernel_thread(check_task_usershell,&pid,"CPOS-UCK"); - - ker: //klogf(user_process("init.bin","Init") != -1,"Init base process init.\n"); diff --git a/src/kernel/syscall.c b/src/kernel/syscall.c index 141235b..53c768f 100644 --- a/src/kernel/syscall.c +++ b/src/kernel/syscall.c @@ -115,6 +115,10 @@ static void* syscall_sysinfo(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi return info; } +static int syscall_exec(uint32_t ebx,uint32_t ecx,uint32_t edx,uint32_t esi,uint32_t edi){ + return user_process(ebx,ebx); +} + void *sycall_handlers[MAX_SYSCALLS] = { [SYSCALL_PUTC] = syscall_puchar, [SYSCALL_PRINT] = syscall_print, @@ -128,6 +132,7 @@ void *sycall_handlers[MAX_SYSCALLS] = { [SYSCALL_VFS_READFILE] = syscall_vfs_readfile, [SYSCALL_VFS_WRITEFILE] = syscall_vfs_writefile, [SYSCALL_SYSINFO] = syscall_sysinfo, + [SYSCALL_EXEC] = syscall_exec, }; typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t); diff --git a/src/kernel/task.c b/src/kernel/task.c index a5c0bb1..74718ba 100644 --- a/src/kernel/task.c +++ b/src/kernel/task.c @@ -193,6 +193,7 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 if(path == NULL){ return -1; } + io_sti(); uint32_t size = vfs_filesize(path); if(size == -1){ return -1; @@ -216,11 +217,13 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 new_task->program_break_end = USER_HEAP_END; new_task->name = name; new_task->isUser = 1; + new_task->vfs_now = NULL; new_task->tty = kmalloc(sizeof(tty_t)); init_default_tty(new_task); extern char root_disk; vfs_change_disk(new_task,root_disk); + vfs_copy(new_task,get_current()->vfs_now); io_sti(); @@ -241,7 +244,6 @@ int32_t user_process(char *path, char *name){ // 用户进程创建 memset(buffer,0,size); vfs_readfile(path,buffer); - Elf32_Ehdr *ehdr = buffer; if(!elf32Validate(ehdr)){ printf("Unknown exec file format.\n"); @@ -299,11 +301,12 @@ int32_t kernel_thread(int (*fn)(void *), void *arg, char *name) { // 内核进 extern header_t *tail; extern void *program_break; extern void *program_break_end; - current->head = head; - current->tail = tail; - current->program_break = program_break; - current->program_break_end = program_break_end; + new_task->head = head; + new_task->tail = tail; + new_task->program_break = program_break; + new_task->program_break_end = program_break_end; new_task->name = name; + new_task->vfs_now = current->vfs_now; new_task->tty = kmalloc(sizeof(tty_t)); init_default_tty(new_task); diff --git a/src/kernel/tty.c b/src/kernel/tty.c index 1777941..c8123ed 100644 --- a/src/kernel/tty.c +++ b/src/kernel/tty.c @@ -288,7 +288,6 @@ static int parse_vt100(struct tty *res, char *string) { } else if (delta[0] == 1 && k == 0) { // unsupported return 0; } - // klogd("switch k"); static const uint8_t color_map[8] = {0, 4, 2, 6, 1, 5, 3, 7}; switch (k) { case 0: { @@ -335,8 +334,51 @@ static int parse_vt100(struct tty *res, char *string) { void tty_print(struct tty *res,const char *string){ vbe_writestring(string); } -void tty_putchar(struct tty *res,int c){ - vbe_putchar(c); +void tty_putchar(struct tty *res,int ch){ + if (ch == '\033' && res->vt100 == 0) { + memset(res->buffer, 0, 81); + res->buf_p = 0; + res->buffer[res->buf_p++] = '\033'; + res->vt100 = 1; + res->done = 0; + return; + }else if (res->vt100 && res->buf_p == 1) { + if (ch == '[') { + res->buffer[res->buf_p++] = ch; + return; + } else { + res->vt100 = 0; + for (int i = 0; i < res->buf_p; i++) { + res->putchar(res, res->buffer[i]); + } + } + }else if (res->vt100 && res->buf_p == 81) { + for (int i = 0; i < res->buf_p; i++) { + res->putchar(res, res->buffer[i]); + } + res->vt100 = 0; + }else if (res->vt100) { + res->buffer[res->buf_p++] = ch; + if (t_is_eos(ch)) { + res->mode = (vt100_mode_t)ch; + if (!parse_vt100(res, res->buffer)) { // 失败了 + for (int i = 0; i < res->buf_p; i++) { + res->putchar(res, res->buffer[i]); + } + } + res->vt100 = 0; + return; + } else if (!isdigit(ch) && ch != ';') { + for (int i = 0; i < res->buf_p; i++) { + res->putchar(res, res->buffer[i]); + } + res->vt100 = 0; + return; + } + return; + } + //vbe_putchar(ch); + res->putchar(res,ch); } void tty_MoveCursor(struct tty *res,int x, int y){ @@ -351,9 +393,13 @@ void init_default_tty(struct task_struct *task){ task->tty->is_using = true; task->tty->print = tty_print; - task->tty->clear = tty_clear; - task->tty->putchar = tty_putchar; + task->tty->clear = clear_TextMode; + task->tty->putchar = putchar_TextMode; task->tty->gotoxy = tty_gotoxy; + task->tty->screen_ne = screen_ne_TextMode; + task->tty->vram = screen; + task->tty->width = width; + task->tty->height = height; fifo8_init(task->tty->fifo,256,buffer); } diff --git a/src/sysapp/shell.c b/src/sysapp/shell.c index 8abdc6e..1f55eeb 100644 --- a/src/sysapp/shell.c +++ b/src/sysapp/shell.c @@ -7,7 +7,6 @@ #include "../include/vdisk.h" #include "../include/vfs.h" #include "../include/common.h" -#include "../include/sb16.h" #include "../include/elf.h" #include "../include/keyboard.h" @@ -230,14 +229,6 @@ void cmd_cd(int argc, char **argv) { if (vfs_change_path(argv[1]) == 0) printf("Invalid path.\n"); } -void cmd_sb3(int argc, char **argv) { - if (argc == 1) { - print("[Shell-SB3]: If there are too few parameters, please specify the path.\n"); - return; - } - // wav_player(argv[1]); -} - void cmd_type(int argc,char ** argv){ if (argc == 1) { print("[Shell-TYPE]: If there are too few parameters, please specify the path.\n"); @@ -434,8 +425,6 @@ void setup_shell() { cmd_disk(argc, argv); else if (!strcmp("cd", argv[0])) cmd_cd(argc, argv); - else if (!strcmp("sb3", argv[0])) - cmd_sb3(argc, argv); else if (!strcmp("exec",argv[0])) cmd_exec(argc,argv); else if (!strcmp("help", argv[0]) || !strcmp("?", argv[0]) || !strcmp("h", argv[0])) { @@ -453,7 +442,6 @@ void setup_shell() { print("debug Print os debug info.\n"); print("disk[list||cg]List or view disks.\n"); print("cd Change shell top directory.\n"); - print("sb3 Player a wav sound file.\n"); print("exec Execute a application.\n"); } else printf("\033ff3030;[Shell]: Unknown command '%s'.\033c6c6c6;\n", argv[0]); } diff --git a/src/sysapp/soundtest.c b/src/sysapp/soundtest.c deleted file mode 100644 index 1294a2d..0000000 --- a/src/sysapp/soundtest.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "../include/soundtest.h" -#include "../include/sb16.h" -#include "../include/printf.h" -#include "../include/timer.h" - -#define buffer_len 32768 -static const char l[] = " QQffQQLLLfLLDDQQQfff rrff``UU QQDDQQLLLfLLDD<> 22 & 1 ? b : a; -} -static int r(int a, int t) { - return 112 >> (a >> 20 & 7) & 1 ? t >> 14 & 15 : (t >> 17 & 1) * 8; -} -static int b(const char *a, int p, int t) { - return (s(a, r(t, t) + p * 16, t << 2) * (254 >> (t >> 20 & 7) & 1)) & 20; -} -static int q(int a) { - return 120 >> (a >> 20 & 7) & 1 ? 1 : (-a >> 16 & 1); -} -static int g(int t) { - int p = 178 >> (t >> 19 & 7) & 1; - int n = - b("rrLr99rrUUrU99rULLyL<> 17 & 1) * 4 + p * 8, t << 2) & 7) * - (t * d(t >> 16) >> 12 & 15 ^ e(0, 5, t)) * 3 / 4 + - ((s("rf[L<9-\x1e&-3&-3-3\xab\x98\x90r`UH0+&9+&\x1d&+\x98\x88yfQL<(3> 13 & 31) + p * 32, t << 5 - (t >> 11 & 3)) | - t >> 8) * - q(t) & - 31) + - (((s(l, t >> 14 & 127, t << 6) & s(l, t >> 14 & 127, (t * e(89 / 88, 499 / 498, t)) << 6)) * - (63486 >> (t >> 15 & 15) & 1) * (102 >> (t >> 20 & 7) & 1)) & - e(42, 32, t)) + - ((((253507989 >> (t >> 6 & 31)) * (1 >> (t >> 11 & 3)) * (19593 >> (t >> 13 & 15) & 1) & 1) * - 50) + - ((((t * t / 21 + t & (t >> 3)) | t >> 7 | t >> 8) - 7) * (3 >> (t >> 11 & 3) & 1) * - (2450526224 >> (t >> 13 & 31) & 1) & - 31) * - 5 / 2) * - (112 >> (t >> 20 & 7) & 1); - return n; -} - -static int F, G; -static const int T = 125000; -static const int K = 10; - -static uint8_t gen(int t) { - if (t < (128 - F) * K) return 128 - t / K; - t -= (128 - F) * K; - if (t < T) return g(t); - t -= T; - if (t < (128 - G) * K) return G + t / K; - return 128; - // return g(t); -} - -void sound_test() { - -} - diff --git a/src/util/textmode.c b/src/util/textmode.c new file mode 100644 index 0000000..4426421 --- /dev/null +++ b/src/util/textmode.c @@ -0,0 +1,63 @@ +#include "../include/tty.h" + +void putchar_TextMode(struct tty *res, int c) { + if (res->x == res->xsize) { res->gotoxy(res, 0, res->y + 1); } + if (c == '\n') { + if (res->y == res->ysize - 1) { + res->screen_ne(res); + return; + } + res->MoveCursor(res, 0, res->y + 1); + return; + } else if (c == '\0') { + return; + } else if (c == '\b') { + if (res->x == 0) { + res->MoveCursor(res, res->xsize - 1, res->y - 1); + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2) = ' '; + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2 - 2 + 1) = res->color; + return; + } + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2 - 2) = ' '; + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2 - 2 + 1) = res->color; + res->MoveCursor(res, res->x - 1, res->y); + return; + } else if (c == '\t') { + // 制表符 + res->print(res, " "); + return; + } else if (c == '\r') { + return; + } + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2) = c; + *(uint8_t *)(res->vram + res->y * res->xsize * 2 + res->x * 2 + 1) = res->color; + res->MoveCursor(res, res->x + 1, res->y); +} + +void screen_ne_TextMode(struct tty *res) { + for (int i = 0; i < res->xsize * 2; i += 2) { + for (int j = 0; j < res->ysize; j++) { + *(uint8_t *)(res->vram + j * res->xsize * 2 + i) = + *(uint8_t *)(res->vram + (j + 1) * res->xsize * 2 + i); + *(uint8_t *)(res->vram + j * res->xsize * 2 + i + 1) = + *(uint8_t *)(res->vram + (j + 1) * res->xsize * 2 + i + 1); + } + } + for (int i = 0; i < res->xsize * 2; i += 2) { + *(uint8_t *)(res->vram + (res->ysize - 1) * res->xsize * 2 + i) = ' '; + *(uint8_t *)(res->vram + (res->ysize - 1) * res->xsize * 2 + i + 1) = res->color; + } + res->gotoxy(res, 0, res->ysize - 1); + res->Raw_y++; +} + +void clear_TextMode(struct tty *res) { + for (int i = 0; i < res->xsize * 2; i += 2) { + for (int j = 0; j < res->ysize; j++) { + *(uint8_t *)(res->vram + j * res->xsize * 2 + i) = ' '; + *(uint8_t *)(res->vram + j * res->xsize * 2 + i + 1) = res->color; + } + } + res->gotoxy(res, 0, 0); + res->Raw_y = 0; +} \ No newline at end of file