修复ACPI驱动无法处理电源键问题

This commit is contained in:
XIAOYI12 2024-08-29 22:00:28 +08:00
parent d73f236850
commit 9c0f4797ed
12 changed files with 71 additions and 72 deletions

View File

@ -1,7 +1,6 @@
#include "../include/stdio.h"
int main(){
debug_test();
while (1);
return 0;
}

View File

@ -1,7 +1,6 @@
#ifndef CRASHPOWEROS_STDIO_H
#define CRASHPOWEROS_STDIO_H
void put_char();
void debug_test();
void put_char(char a);
#endif

View File

@ -4,19 +4,8 @@ void hlt(){
while (1);
}
void putc(char c){
asm ("push %%eax\n"
"push %%edx\n"
"mov %0,%%edx\n"
"mov $0x1,%%eax\n"
"int $31\n"
"pop %%edx\n"
"pop %%eax\n"::"m"(c));
}
int main(){
//putc('A');
put_char();
put_char('A');
hlt();
return 0;
}

View File

@ -1,16 +1,8 @@
global put_char
global debug_test
put_char:
push eax
mov eax,0x01
push eax
mov eax, 21h
int 31h
pop eax
ret
debug_test:
push edx
mov edx,0x02
int 31h
pop edx
pop eax
ret

View File

@ -1,5 +1,6 @@
global taskX_switch
global asm_syscall_handler
global panic
taskX_switch:
mov eax, [esp+4]
@ -14,32 +15,25 @@ taskX_switch:
ret
extern syscall_handler
extern syscall
asm_syscall_handler:
cli
push byte 0
push 80h
push ds
push es
push fs
push gs
pusha
mov ax, ds
push eax ; 存储ds
mov ax, 0x10 ; 将内核数据段赋值给各段
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call syscall_handler
pop eax ; 恢复
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
call syscall
mov dword [esp+28], eax
popa
pop gs
pop fs
pop es
pop ds
IRETD
add esp, 8 ; 弹出错误码和中断ID
iret
panic:
ret;JMP 0xffff0

View File

@ -3,7 +3,10 @@
#include <stddef.h>
#define SYSCALL_NUM 10
#define MAX_SYSCALLS 256
#define SYSCALL_PUTC 1
#define SYSCALL_PRINT 2
#define DEFN_SYSCALL0(fn, num) \
int syscall_##fn() \

View File

@ -114,7 +114,6 @@ void kernel_main(multiboot_t *multiboot) {
}
}
}
init_eh();
hasFS = false;
if(disk_id != '0'){
if(vfs_change_disk(disk_id)){
@ -128,6 +127,7 @@ void kernel_main(multiboot_t *multiboot) {
if(pcnet_init){
//init_pcnet_card();
}
init_eh();
klogf(true,"Kernel load done!\n");
kernel_thread(sound_test,NULL,"Sound");
@ -135,16 +135,15 @@ void kernel_main(multiboot_t *multiboot) {
clock_sleep(25);
// vfs_change_path("apps");
vfs_change_path("apps");
//klogf(user_process("service.bin","Service") != -1,"Service base process init.\n");
//klogf(user_process("init.bin","Init") != -1,"Init base process init.\n");
klogf(user_process("init.bin","Init") != -1,"Init base 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");
//panic_pane("Proccess out of memory error!",OUT_OF_MEMORY);
//panic_pane("System out of memory error!",OUT_OF_MEMORY);
for (;;) {
io_hlt();

View File

@ -224,7 +224,7 @@ void init_page(multiboot_t *mboot) {
current_directory = kernel_directory;
int i = 0;
while (i < placement_address + 0x30000) {
while (i < placement_address + 0x50000) {
/*
* ring3而言不可读不可写
*

View File

@ -33,7 +33,7 @@ static GP_13(registers_t *reg){
static UD_6(registers_t *reg){
if(current->pid == 0){
printf("Kernel PANIC(#GP), Please restart your CPOS Kernel.\n");
printf("Kernel PANIC(#UD), Please restart your CPOS Kernel.\n");
while(1) io_hlt();
}else {
task_kill(current->pid);
@ -47,7 +47,7 @@ void panic_pane(char* msg,enum PANIC_TYPE type){
color = 0xffffff;
screen_clear();
if(panic_bmp != NULL){
display(panic_bmp,0,0,false);
display(panic_bmp,0,0,true);
} else klogf(false,"Cannot draw panic image.\n");
cx = 10;
@ -78,10 +78,10 @@ void panic_pane(char* msg,enum PANIC_TYPE type){
void init_eh(){
register_interrupt_handler(13,GP_13);
register_interrupt_handler(6,UD_6);
if(vfs_change_disk('B')){
panic_bmp = NULL;
//if(vfs_change_disk('B')){
uint32_t size = vfs_filesize("panic.bmp");
panic_bmp = NULL;
if(size == -1){
klogf(false,"Enable graphics user interface panic.\n");
} else{
@ -90,5 +90,5 @@ void init_eh(){
panic_bmp = bmp;
klogf(true,"Enable graphics user interface panic.\n");
}
}
//}
}

View File

@ -7,7 +7,8 @@
void syscall_handler(registers_t regs){
io_cli();
printf("Syscall is enable. EAX: %08x\n",regs.eax);
register uint32_t eax asm("eax");
printf("Syscall is enable. EAX: %08x PHIEAX: %08x\n",regs.eax,eax);
if(regs.eax == 0x01){
putchar((regs.edx));
}
@ -15,6 +16,31 @@ void syscall_handler(registers_t regs){
return;
}
void *sycall_handlers[MAX_SYSCALLS] = {
[SYSCALL_PUTC] = putchar,
[SYSCALL_PRINT] = print,
};
typedef size_t (*syscall_t)(size_t, size_t, size_t, size_t, size_t);
size_t syscall() {
volatile size_t eax, ebx, ecx, edx, esi, edi;
asm("mov %%eax, %0\n\t" : "=r"(eax));
asm("mov %%ebx, %0\n\t" : "=r"(ebx));
asm("mov %%ecx, %0\n\t" : "=r"(ecx));
asm("mov %%edx, %0\n\t" : "=r"(edx));
asm("mov %%esi, %0\n\t" : "=r"(esi));
asm("mov %%edi, %0\n\t" : "=r"(edi));
printf("eax: %d, ebx: %d, ecx: %d, edx: %d, esi: %d, edi: %d\n", eax, ebx, ecx, edx, esi, edi);
if (0 <= eax && eax < MAX_SYSCALLS && sycall_handlers[eax] != NULL) {
eax = ((syscall_t)sycall_handlers[eax])(ebx, ecx, edx, esi, edi);
} else {
eax = -1;
}
return eax;
}
void syscall_install(){
register_interrupt_handler(31,syscall_handler);
extern void asm_syscall_handler();
idt_use_reg(31,asm_syscall_handler);
}

View File

@ -237,16 +237,11 @@ int32_t user_process(char *path, char *name){ // 用户进程创建
printf("Unknown exec file format.\n");
return -1;
}
printf("Process Main Address: %08x\n",ehdr->e_entry);
uint32_t main = ehdr->e_entry;
load_elf(ehdr,page);
/*
uint32_t alloc_addr = (elf32_get_max_vaddr((Elf32_Ehdr *)ehdr) & 0xfffff000) + 0x1000;
uint32_t pg = padding_up( 0xf00000, 0x1000);
for (int i = 0; i < pg + 128; i++) {
alloc_frame(get_page(alloc_addr + i * 0x1000,1,page),0,1);
}
*/
uint32_t main = load_elf(ehdr,page);
uint32_t *stack_top = (uint32_t * )((uint32_t) new_task + STACK_SIZE);

View File

@ -32,6 +32,7 @@ void load_segment(Elf32_Phdr *phdr,page_directory_t *dir, void *elf) {
alloc_frame(get_page(i,1,dir,false),0,1);
}
printf("VDDR: %08x elf: %08x offset: %08x filesz: %08x elf+offset: %08x\n",phdr->p_vaddr, elf , phdr->p_offset, phdr->p_filesz, elf + phdr->p_offset);
//if(phdr->p_vaddr == 0xaffff000) return;
memcpy((void *)phdr->p_vaddr, elf + phdr->p_offset, phdr->p_filesz);
if (phdr->p_memsz > phdr->p_filesz) { // 这个是bss段
memset((void *)(phdr->p_vaddr + phdr->p_filesz), 0, phdr->p_memsz - phdr->p_filesz);
@ -41,7 +42,9 @@ void load_segment(Elf32_Phdr *phdr,page_directory_t *dir, void *elf) {
uint32_t load_elf(Elf32_Ehdr *hdr,page_directory_t *dir) {
Elf32_Phdr *phdr = (Elf32_Phdr *)((uint32_t)hdr + hdr->e_phoff);
for (int i = 0; i < hdr->e_phnum; i++) {
load_segment(phdr, (void *)hdr,dir);
if(phdr->p_type == PT_LOAD ){
load_segment(phdr,dir,(void *)hdr);
}
phdr++;
}
return hdr->e_entry;