激活FAT32

This commit is contained in:
fslongjin 2022-04-26 13:12:59 +08:00
parent c14bd25059
commit d94d92f5ee
6 changed files with 33 additions and 60 deletions

View File

@ -497,11 +497,11 @@ void do_IRQ(struct pt_regs *rsp, ul number)
kwarn("do IRQ receive: %d", number);
}
kdebug("before softirq");
// kdebug("before softirq");
// 检测是否有未处理的软中断
if (softirq_status != 0)
do_softirq();
kdebug("after softirq");
// kdebug("after softirq");
// 检测当前进程是否持有自旋锁,若持有自旋锁,则不进行抢占式的进程调度
if (current_pcb->preempt_count > 0)
return;
@ -511,7 +511,7 @@ void do_IRQ(struct pt_regs *rsp, ul number)
// 检测当前进程是否可被调度
if (current_pcb->flags & PROC_NEED_SCHED)
{
kdebug("to sched");
// kdebug("to sched");
sched_cfs();
}
}

View File

@ -51,7 +51,7 @@ hardware_intr_controller HPET_intr_controller =
void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs)
{
printk("(HPET)");
// printk("(HPET)");
switch (param)
{
case 0: // 定时器0中断
@ -127,7 +127,7 @@ int HPET_init()
else // ACPI表中有HPET表
{
hpet_table = (struct acpi_HPET_description_table_t *)hpet_table_addr;
kdebug("hpet_table_addr=%#018lx", hpet_table_addr);
// kdebug("hpet_table_addr=%#018lx", hpet_table_addr);
// 由于这段内存与io/apic的映射在同一物理页内因此不需要重复映射
HPET_REG_BASE = SPECIAL_MEMOEY_MAPPING_VIRT_ADDR_BASE + hpet_table->address;

View File

@ -690,21 +690,22 @@ struct vfs_inode_operations_t fat32_inode_ops =
};
struct vfs_filesystem_type_t fat32_fs_type =
{
.name = "FAT32",
.fs_flags = 0,
.read_superblock = fat32_read_superblock,
.next = NULL,
struct vfs_filesystem_type_t fat32_fs_type =
{
.name = "FAT32",
.fs_flags = 0,
.read_superblock = fat32_read_superblock,
.next = NULL,
};
void fat32_init()
{
// kinfo("Initializing FAT32...");
kinfo("Initializing FAT32...");
// 在VFS中注册fat32文件系统
vfs_register_filesystem(&fat32_fs_type);
// 挂载根文件系统
vfs_root_sb = fat32_register_partition(0, 0, 0);
kinfo("FAT32 initialized.");
}

View File

@ -156,7 +156,7 @@ void system_initialize()
process_init();
HPET_init();
//fat32_init();
fat32_init();
}
@ -188,13 +188,13 @@ void Start_Kernel(void)
// int part_id = fat32_register_partition(0, 0, 0);
struct vfs_dir_entry_t *dentry = fat32_path_walk("a.txt", 0);
if (dentry != NULL)
printk_color(ORANGE, BLACK, "Find a.txt\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
printk_color(ORANGE, BLACK, "Found a.txt\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
else
printk_color(ORANGE, BLACK, "Can`t find file\n");
dentry = fat32_path_walk("xx/12.png", 0);
if (dentry != NULL)
printk_color(ORANGE, BLACK, "Find a.txt\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
printk_color(ORANGE, BLACK, "Found xx/12.png\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
else
printk_color(ORANGE, BLACK, "Can`t find file\n");

View File

@ -9,6 +9,8 @@
#include <sched/sched.h>
extern void system_call(void);
extern void kernel_thread_func(void);
ul _stack_start; // initial proc的栈基地址虚拟地址
struct mm_struct initial_mm = {0};
struct thread_struct initial_thread =
@ -41,9 +43,9 @@ struct tss_struct initial_tss[MAX_CPU_NUM] = {[0 ... MAX_CPU_NUM - 1] = INITIAL_
void __switch_to(struct process_control_block *prev, struct process_control_block *next)
{
initial_tss[proc_current_cpu_id].rsp0 = next->thread->rbp;
kdebug("next_rsp = %#018lx ", next->thread->rsp);
// set_tss64((uint *)phys_2_virt(TSS64_Table), initial_tss[0].rsp0, initial_tss[0].rsp1, initial_tss[0].rsp2, initial_tss[0].ist1,
// initial_tss[0].ist2, initial_tss[0].ist3, initial_tss[0].ist4, initial_tss[0].ist5, initial_tss[0].ist6, initial_tss[0].ist7);
// kdebug("next_rsp = %#018lx ", next->thread->rsp);
// set_tss64((uint *)phys_2_virt(TSS64_Table), initial_tss[0].rsp0, initial_tss[0].rsp1, initial_tss[0].rsp2, initial_tss[0].ist1,
// initial_tss[0].ist2, initial_tss[0].ist3, initial_tss[0].ist4, initial_tss[0].ist5, initial_tss[0].ist6, initial_tss[0].ist7);
__asm__ __volatile__("movq %%fs, %0 \n\t"
: "=a"(prev->thread->fs));
@ -90,7 +92,7 @@ void user_level_function()
: "memory", "r8");
if (err_code == 0)
{
char str[] = "errno is 0";
char str[] = "errno is 0\n";
addr = (ul)str;
__asm__ __volatile__(
"movq %2, %%r8 \n\t"
@ -166,7 +168,7 @@ ul do_execve(struct pt_regs *regs)
ul initial_kernel_thread(ul arg)
{
// kinfo("initial proc running...\targ:%#018lx", arg);
kdebug("6666");
struct pt_regs *regs;
current_pcb->thread->rip = (ul)ret_from_system_call;
@ -240,36 +242,6 @@ void kernel_thread_func(void)
*/
extern void kernel_thread_func(void);
/*
__asm__(
"kernel_thread_func: \n\t"
" popq %r15 \n\t"
" popq %r14 \n\t"
" popq %r13 \n\t"
" popq %r12 \n\t"
" popq %r11 \n\t"
" popq %r10 \n\t"
" popq %r9 \n\t"
" popq %r8 \n\t"
" popq %rbx \n\t"
" popq %rcx \n\t"
" popq %rdx \n\t"
" popq %rsi \n\t"
" popq %rdi \n\t"
" popq %rbp \n\t"
" popq %rax \n\t"
" movq %rax, %ds \n\t"
" popq %rax \n\t"
" movq %rax, %es \n\t"
" popq %rax \n\t"
" addq $0x38, %rsp \n\t"
/////////////////////////////////
" movq %rdx, %rdi \n\t"
" callq *%rbx \n\t"
" movq %rax, %rdi \n\t"
" callq process_thread_do_exit \n\t");
*/
/**
* @brief
*
@ -299,9 +271,9 @@ int kernel_thread(unsigned long (*fn)(unsigned long), unsigned long arg, unsigne
// rip寄存器指向内核线程的引导程序
regs.rip = (ul)kernel_thread_func;
kdebug("kernel_thread_func=%#018lx", kernel_thread_func);
kdebug("&kernel_thread_func=%#018lx", &kernel_thread_func);
kdebug("1111\tregs.rip = %#018lx", regs.rip);
// kdebug("kernel_thread_func=%#018lx", kernel_thread_func);
// kdebug("&kernel_thread_func=%#018lx", &kernel_thread_func);
// kdebug("1111\tregs.rip = %#018lx", regs.rip);
return do_fork(&regs, flags, 0, 0);
}
@ -372,8 +344,8 @@ void process_init()
unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned long stack_start, unsigned long stack_size)
{
struct process_control_block *tsk = NULL;
kdebug("222\tregs.rip = %#018lx", regs->rip);
// 获取一个物理页并在这个物理页内初始化pcb
// kdebug("222\tregs.rip = %#018lx", regs->rip);
// 获取一个物理页并在这个物理页内初始化pcb
struct Page *pp = alloc_pages(ZONE_NORMAL, 1, PAGE_PGT_MAPPED | PAGE_KERNEL);
tsk = (struct process_control_block *)phys_2_virt(pp->addr_phys);
@ -401,8 +373,8 @@ unsigned long do_fork(struct pt_regs *regs, unsigned long clone_flags, unsigned
struct thread_struct *thd = (struct thread_struct *)(tsk + 1);
memset(thd, 0, sizeof(struct thread_struct));
tsk->thread = thd;
kdebug("333\tregs.rip = %#018lx", regs->rip);
// 将寄存器信息存储到进程的内核栈空间的顶部
// kdebug("333\tregs.rip = %#018lx", regs->rip);
// 将寄存器信息存储到进程的内核栈空间的顶部
memcpy((void *)((ul)tsk + STACK_SIZE - sizeof(struct pt_regs)), regs, sizeof(struct pt_regs));
kdebug("regs.rip = %#018lx", regs->rip);

View File

@ -74,7 +74,7 @@ void sched_cfs()
break;
}
}
kdebug("before switch, next.rip = %#018lx\tnext->gs=%#018lx", proc->thread->rip, proc->thread->gs);
// kdebug("before switch, next.rip = %#018lx\tnext->gs=%#018lx", proc->thread->rip, proc->thread->gs);
switch_proc(current_pcb, proc);
}
else // 不进行切换
@ -108,8 +108,8 @@ void sched_cfs()
*/
void sched_update_jiffies()
{
//if (current_pcb->cpu_id == 0)
// return;
// if (current_pcb->cpu_id == 0)
// return;
switch (current_pcb->priority)
{
case 0: