磁盘请求在处理时,切换进程

This commit is contained in:
fslongjin 2022-04-19 15:13:59 +08:00
parent 0e8bf69d65
commit 39dd802ff1
14 changed files with 257 additions and 206 deletions

View File

@ -1,9 +1,13 @@
#include "ahci.h" #include "ahci.h"
#include "../../../common/kprint.h" #include "../../../common/kprint.h"
#include "../../../mm/slab.h" #include "../../../mm/slab.h"
#include <syscall/syscall.h>
#include <syscall/syscall_num.h>
struct pci_device_structure_header_t *ahci_devs[MAX_AHCI_DEVICES]; struct pci_device_structure_header_t *ahci_devs[MAX_AHCI_DEVICES];
struct block_device_request_queue ahci_req_queue;
uint32_t count_ahci_devices = 0; uint32_t count_ahci_devices = 0;
uint64_t ahci_port_base_vaddr; // 端口映射base addr uint64_t ahci_port_base_vaddr; // 端口映射base addr
@ -57,7 +61,7 @@ void ahci_init()
// 初始化请求队列 // 初始化请求队列
ahci_req_queue.in_service = NULL; ahci_req_queue.in_service = NULL;
list_init(&(ahci_req_queue.queue_list)); wait_queue_init(&ahci_req_queue.wait_queue_list, NULL);
ahci_req_queue.request_count = 0; ahci_req_queue.request_count = 0;
kinfo("AHCI initialized."); kinfo("AHCI initialized.");
} }
@ -278,6 +282,8 @@ static bool ahci_read(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t
kdebug("slot=%d", slot); kdebug("slot=%d", slot);
port->ci = 1 << slot; // Issue command port->ci = 1 << slot; // Issue command
sched_cfs();
int retval = AHCI_SUCCESS;
// Wait for completion // Wait for completion
while (1) while (1)
{ {
@ -288,7 +294,8 @@ static bool ahci_read(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t
if (port->is & HBA_PxIS_TFES) // Task file error if (port->is & HBA_PxIS_TFES) // Task file error
{ {
kerror("Read disk error"); kerror("Read disk error");
return E_TASK_FILE_ERROR; retval = E_TASK_FILE_ERROR;
break;
} }
} }
@ -296,10 +303,10 @@ static bool ahci_read(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t
if (port->is & HBA_PxIS_TFES) if (port->is & HBA_PxIS_TFES)
{ {
kerror("Read disk error"); kerror("Read disk error");
return E_TASK_FILE_ERROR; retval = E_TASK_FILE_ERROR;
} }
enter_syscall_int(SYS_AHCI_END_REQ, 0, 0, 0, 0, 0, 0, 0, 0);
return AHCI_SUCCESS; return retval;
} }
static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t count, static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t count,
@ -352,6 +359,10 @@ static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_
cmdfis->counth = count >> 8; cmdfis->counth = count >> 8;
// printk("[slot]{%d}", slot); // printk("[slot]{%d}", slot);
port->ci = 1; // Issue command port->ci = 1; // Issue command
sched_cfs();
int retval = AHCI_SUCCESS;
while (1) while (1)
{ {
// In some longer duration reads, it may be helpful to spin on the DPS bit // In some longer duration reads, it may be helpful to spin on the DPS bit
@ -361,16 +372,18 @@ static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_
if (port->is & HBA_PxIS_TFES) if (port->is & HBA_PxIS_TFES)
{ // Task file error { // Task file error
kerror("Write disk error"); kerror("Write disk error");
return E_TASK_FILE_ERROR; retval = E_TASK_FILE_ERROR;
break;
} }
} }
if (port->is & HBA_PxIS_TFES) if (port->is & HBA_PxIS_TFES)
{ {
kerror("Write disk error"); kerror("Write disk error");
return E_TASK_FILE_ERROR; retval = E_TASK_FILE_ERROR;
} }
return AHCI_SUCCESS; enter_syscall_int(SYS_AHCI_END_REQ, 0, 0, 0, 0, 0, 0, 0, 0);
return retval;
} }
// Find a free command list slot // Find a free command list slot
@ -410,32 +423,33 @@ long ahci_close()
* @param port_num ahci控制器端口号 * @param port_num ahci控制器端口号
* @return struct block_device_request_packet* * @return struct block_device_request_packet*
*/ */
static struct block_device_request_packet *ahci_make_request(long cmd, uint64_t base_addr, uint64_t count, uint64_t buffer, uint8_t ahci_ctrl_num, uint8_t port_num) static struct ahci_request_packet_t *ahci_make_request(long cmd, uint64_t base_addr, uint64_t count, uint64_t buffer, uint8_t ahci_ctrl_num, uint8_t port_num)
{ {
struct block_device_request_packet *pack = (struct block_device_request_packet *)kmalloc(sizeof(struct block_device_request_packet), 0); struct ahci_request_packet_t *pack = (struct ahci_request_packet_t *)kmalloc(sizeof(struct ahci_request_packet_t), 0);
list_init(&pack->list); wait_queue_init(&pack->blk_pak.wait_queue, current_pcb);
pack->blk_pak.device_type = BLK_TYPE_AHCI;
// 由于ahci不需要中断即可读取磁盘因此end handler为空 // 由于ahci不需要中断即可读取磁盘因此end handler为空
switch (cmd) switch (cmd)
{ {
case ATA_CMD_READ_DMA_EXT: case ATA_CMD_READ_DMA_EXT:
pack->end_handler = NULL; pack->blk_pak.end_handler = NULL;
pack->cmd = ATA_CMD_READ_DMA_EXT; pack->blk_pak.cmd = ATA_CMD_READ_DMA_EXT;
break; break;
case ATA_CMD_WRITE_DMA_EXT: case ATA_CMD_WRITE_DMA_EXT:
pack->end_handler = NULL; pack->blk_pak.end_handler = NULL;
pack->cmd = ATA_CMD_WRITE_DMA_EXT; pack->blk_pak.cmd = ATA_CMD_WRITE_DMA_EXT;
break; break;
default: default:
pack->end_handler = NULL; pack->blk_pak.end_handler = NULL;
pack->cmd = cmd; pack->blk_pak.cmd = cmd;
break; break;
} }
pack->LBA_start = base_addr; pack->blk_pak.LBA_start = base_addr;
pack->count = count; pack->blk_pak.count = count;
pack->buffer_vaddr = buffer; pack->blk_pak.buffer_vaddr = buffer;
pack->ahci_ctrl_num = ahci_ctrl_num; pack->ahci_ctrl_num = ahci_ctrl_num;
pack->port_num = port_num; pack->port_num = port_num;
@ -446,8 +460,10 @@ static struct block_device_request_packet *ahci_make_request(long cmd, uint64_t
* @brief * @brief
* *
*/ */
static void ahci_end_request() void ahci_end_request()
{ {
ahci_req_queue.in_service->wait_queue.pcb->state = PROC_RUNNING;
ahci_req_queue.in_service->wait_queue.pcb->flags |= PROC_NEED_SCHED;
kfree((uint64_t *)ahci_req_queue.in_service); kfree((uint64_t *)ahci_req_queue.in_service);
ahci_req_queue.in_service = NULL; ahci_req_queue.in_service = NULL;
@ -458,27 +474,31 @@ static void ahci_end_request()
static long ahci_query_disk() static long ahci_query_disk()
{ {
struct block_device_request_packet *pack = container_of(list_next(&ahci_req_queue.queue_list), struct block_device_request_packet, list); wait_queue_node_t *wait_queue_tmp = container_of(list_next(&ahci_req_queue.wait_queue_list.wait_list), wait_queue_node_t, wait_list);
ahci_req_queue.in_service = pack; struct ahci_request_packet_t *pack = (struct ahci_request_packet_t *)container_of(wait_queue_tmp, struct block_device_request_packet, wait_queue);
list_del(&(ahci_req_queue.in_service->list));
ahci_req_queue.in_service = (struct block_device_request_packet *)pack;
list_del(&(ahci_req_queue.in_service->wait_queue.wait_list));
--ahci_req_queue.request_count; --ahci_req_queue.request_count;
long ret_val; long ret_val;
switch (pack->cmd)
switch (pack->blk_pak.cmd)
{ {
case ATA_CMD_READ_DMA_EXT: case ATA_CMD_READ_DMA_EXT:
ret_val = ahci_read(&(ahci_devices[pack->ahci_ctrl_num].hba_mem->ports[pack->port_num]), pack->LBA_start & 0xFFFFFFFF, ((pack->LBA_start) >> 32) & 0xFFFFFFFF, pack->count, pack->buffer_vaddr); ret_val = ahci_read(&(ahci_devices[pack->ahci_ctrl_num].hba_mem->ports[pack->port_num]), pack->blk_pak.LBA_start & 0xFFFFFFFF, ((pack->blk_pak.LBA_start) >> 32) & 0xFFFFFFFF, pack->blk_pak.count, pack->blk_pak.buffer_vaddr);
break; break;
case ATA_CMD_WRITE_DMA_EXT: case ATA_CMD_WRITE_DMA_EXT:
ret_val = ahci_write(&(ahci_devices[pack->ahci_ctrl_num].hba_mem->ports[pack->port_num]), pack->LBA_start & 0xFFFFFFFF, ((pack->LBA_start) >> 32) & 0xFFFFFFFF, pack->count, pack->buffer_vaddr); ret_val = ahci_write(&(ahci_devices[pack->ahci_ctrl_num].hba_mem->ports[pack->port_num]), pack->blk_pak.LBA_start & 0xFFFFFFFF, ((pack->blk_pak.LBA_start) >> 32) & 0xFFFFFFFF, pack->blk_pak.count, pack->blk_pak.buffer_vaddr);
break; break;
default: default:
kerror("Unsupport ahci command: %#05lx", pack->cmd); kerror("Unsupport ahci command: %#05lx", pack->blk_pak.cmd);
ret_val = E_UNSUPPORTED_CMD; ret_val = E_UNSUPPORTED_CMD;
break; break;
} }
ahci_end_request();
// ahci_end_request();
return ret_val; return ret_val;
} }
@ -487,9 +507,9 @@ static long ahci_query_disk()
* *
* @param pack * @param pack
*/ */
static void ahci_submit(struct block_device_request_packet *pack) static void ahci_submit(struct ahci_request_packet_t *pack)
{ {
list_append(&(ahci_req_queue.queue_list), &(pack->list)); list_append(&(ahci_req_queue.wait_queue_list.wait_list), &(pack->blk_pak.wait_queue.wait_list));
++ahci_req_queue.request_count; ++ahci_req_queue.request_count;
if (ahci_req_queue.in_service == NULL) // 当前没有正在请求的io包立即执行磁盘请求 if (ahci_req_queue.in_service == NULL) // 当前没有正在请求的io包立即执行磁盘请求
@ -509,7 +529,7 @@ static void ahci_submit(struct block_device_request_packet *pack)
*/ */
static long ahci_transfer(long cmd, uint64_t base_addr, uint64_t count, uint64_t buf, uint8_t ahci_ctrl_num, uint8_t port_num) static long ahci_transfer(long cmd, uint64_t base_addr, uint64_t count, uint64_t buf, uint8_t ahci_ctrl_num, uint8_t port_num)
{ {
struct block_device_request_packet *pack = NULL; struct ahci_request_packet_t *pack = NULL;
if (cmd == ATA_CMD_READ_DMA_EXT || cmd == ATA_CMD_WRITE_DMA_EXT) if (cmd == ATA_CMD_READ_DMA_EXT || cmd == ATA_CMD_WRITE_DMA_EXT)
{ {

View File

@ -253,7 +253,6 @@ typedef volatile struct tagHBA_MEM
HBA_PORT ports[32]; // 1 ~ 32 HBA_PORT ports[32]; // 1 ~ 32
} HBA_MEM; } HBA_MEM;
// There are four kinds of FIS which may be sent to the host by the device as indicated in the following structure declaration. // There are four kinds of FIS which may be sent to the host by the device as indicated in the following structure declaration.
// //
typedef volatile struct tagHBA_FIS typedef volatile struct tagHBA_FIS
@ -297,8 +296,7 @@ typedef struct tagHBA_CMD_HEADER
uint16_t prdtl; // Physical region descriptor table length in entries uint16_t prdtl; // Physical region descriptor table length in entries
// DW1 // DW1
volatile volatile uint32_t prdbc; // Physical region descriptor byte count transferred
uint32_t prdbc; // Physical region descriptor byte count transferred
// DW2, 3 // DW2, 3
uint64_t ctba; // Command table descriptor base address uint64_t ctba; // Command table descriptor base address
@ -318,7 +316,6 @@ typedef struct tagHBA_PRDT_ENTRY
uint32_t i : 1; // Interrupt on completion uint32_t i : 1; // Interrupt on completion
} HBA_PRDT_ENTRY; } HBA_PRDT_ENTRY;
typedef struct tagHBA_CMD_TBL typedef struct tagHBA_CMD_TBL
{ {
// 0x00 // 0x00
@ -341,7 +338,6 @@ struct ahci_device_t
HBA_MEM *hba_mem; HBA_MEM *hba_mem;
} ahci_devices[MAX_AHCI_DEVICES]; } ahci_devices[MAX_AHCI_DEVICES];
#define SATA_SIG_ATA 0x00000101 // SATA drive #define SATA_SIG_ATA 0x00000101 // SATA drive
#define SATA_SIG_ATAPI 0xEB140101 // SATAPI drive #define SATA_SIG_ATAPI 0xEB140101 // SATAPI drive
#define SATA_SIG_SEMB 0xC33C0101 // Enclosure management bridge #define SATA_SIG_SEMB 0xC33C0101 // Enclosure management bridge
@ -356,13 +352,12 @@ struct ahci_device_t
#define HBA_PORT_IPM_ACTIVE 1 #define HBA_PORT_IPM_ACTIVE 1
#define HBA_PORT_DET_PRESENT 3 #define HBA_PORT_DET_PRESENT 3
struct ahci_request_packet_t
{
struct block_device_request_queue ahci_req_queue; struct block_device_request_packet blk_pak; // 块设备请求包
uint8_t ahci_ctrl_num; // ahci控制器号 默认应为0
uint8_t port_num; // ahci的设备端口号
};
/** /**
* @brief ahci模块 * @brief ahci模块
@ -403,3 +398,5 @@ static bool ahci_read(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t
*/ */
static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t count, static bool ahci_write(HBA_PORT *port, uint32_t startl, uint32_t starth, uint32_t count,
uint64_t buf); uint64_t buf);
void ahci_end_request();

View File

@ -2,7 +2,9 @@
#include "../../common/glib.h" #include "../../common/glib.h"
#include "stdint.h" #include "stdint.h"
#include <process/semaphore.h>
#define BLK_TYPE_AHCI 0
struct block_device_operation struct block_device_operation
{ {
long (*open)(); long (*open)();
@ -22,11 +24,10 @@ struct block_device_request_packet
uint32_t count; uint32_t count;
uint64_t buffer_vaddr; uint64_t buffer_vaddr;
uint8_t ahci_ctrl_num; // ahci控制器号 默认应为0 uint8_t device_type; // 0: ahci
uint8_t port_num; // ahci的设备端口号
void (*end_handler)(ul num, ul arg); void (*end_handler)(ul num, ul arg);
struct List list; wait_queue_node_t wait_queue;
}; };
/** /**
@ -35,7 +36,7 @@ struct block_device_request_packet
*/ */
struct block_device_request_queue struct block_device_request_queue
{ {
struct List queue_list; wait_queue_node_t wait_queue_list;
struct block_device_request_packet * in_service; // 正在请求的结点 struct block_device_request_packet * in_service; // 正在请求的结点
ul request_count; ul request_count;
}; };

View File

@ -57,9 +57,11 @@ void HPET_handler(uint64_t number, uint64_t param, struct pt_regs *regs)
case 0: // 定时器0中断 case 0: // 定时器0中断
++timer_jiffies; ++timer_jiffies;
/*
// 将HEPT中断消息转发到ap:1处理器 // 将HEPT中断消息转发到ap:1处理器
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8, ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8,
ICR_APIC_FIXED, ICR_ALL_EXCLUDE_Self, true, 0); ICR_APIC_FIXED, ICR_ALL_EXCLUDE_Self, true, 0);
*/
// 若当前时间比定时任务的时间间隔大,则进入中断下半部 // 若当前时间比定时任务的时间间隔大,则进入中断下半部
if (container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list)->expire_jiffies <= timer_jiffies) if (container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list)->expire_jiffies <= timer_jiffies)

View File

@ -53,6 +53,7 @@ Restore_all:
popq %rax popq %rax
addq $0x10, %rsp // FUNCerrcode addq $0x10, %rsp // FUNCerrcode
sti
iretq iretq
ret_from_exception: ret_from_exception:
@ -169,6 +170,7 @@ ENTRY(ret_from_system_call)
popq %rax popq %rax
addq $0x10, %rsp // FUNCerrcode addq $0x10, %rsp // FUNCerrcode
sti
iretq iretq

View File

@ -80,6 +80,7 @@ extern void (*syscall_intr_table[1])(void);
0x80 system call 0x80 system call
0x81 system interrupt
150 ~ 200 Local APIC 150 ~ 200 Local APIC
150 CMCI 150 CMCI

View File

@ -52,7 +52,7 @@ void do_softirq()
} }
} }
cli();
} }
void softirq_init() void softirq_init()

View File

@ -12,7 +12,7 @@ void do_divide_error(struct pt_regs *regs, unsigned long error_code)
kerror("do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_divide_error(0),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 1 #DB 调试异常 // 1 #DB 调试异常
@ -23,7 +23,7 @@ void do_debug(struct pt_regs *regs, unsigned long error_code)
printk(" ] do_debug(1),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); printk(" ] do_debug(1),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 2 不可屏蔽中断 // 2 不可屏蔽中断
@ -35,7 +35,7 @@ void do_nmi(struct pt_regs *regs, unsigned long error_code)
printk(" ] do_nmi(2),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); printk(" ] do_nmi(2),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 3 #BP 断点异常 // 3 #BP 断点异常
@ -47,7 +47,7 @@ void do_int3(struct pt_regs *regs, unsigned long error_code)
printk(" ] do_int3(3),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); printk(" ] do_int3(3),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 4 #OF 溢出异常 // 4 #OF 溢出异常
@ -59,7 +59,7 @@ void do_overflow(struct pt_regs *regs, unsigned long error_code)
printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); printk(" ] do_overflow(4),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 5 #BR 越界异常 // 5 #BR 越界异常
@ -69,7 +69,7 @@ void do_bounds(struct pt_regs *regs, unsigned long error_code)
kerror("do_bounds(5),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_bounds(5),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 6 #UD 无效/未定义的机器码 // 6 #UD 无效/未定义的机器码
@ -79,7 +79,7 @@ void do_undefined_opcode(struct pt_regs *regs, unsigned long error_code)
kerror("do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_undefined_opcode(6),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 7 #NM 设备异常FPU不存在 // 7 #NM 设备异常FPU不存在
@ -89,7 +89,7 @@ void do_dev_not_avaliable(struct pt_regs *regs, unsigned long error_code)
kerror("do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_dev_not_avaliable(7),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 8 #DF 双重错误 // 8 #DF 双重错误
@ -101,7 +101,7 @@ void do_double_fault(struct pt_regs *regs, unsigned long error_code)
printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); printk(" ] do_double_fault(8),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 9 协处理器越界(保留) // 9 协处理器越界(保留)
@ -111,7 +111,7 @@ void do_coprocessor_segment_overrun(struct pt_regs *regs, unsigned long error_co
kerror("do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_coprocessor_segment_overrun(9),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 10 #TS 无效的TSS段 // 10 #TS 无效的TSS段
@ -142,7 +142,7 @@ void do_invalid_TSS(struct pt_regs *regs, unsigned long error_code)
printk("\n"); printk("\n");
while (1) while (1)
; hlt();
} }
// 11 #NP 段不存在 // 11 #NP 段不存在
@ -152,7 +152,7 @@ void do_segment_not_exists(struct pt_regs *regs, unsigned long error_code)
kerror("do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_segment_not_exists(11),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 12 #SS SS段错误 // 12 #SS SS段错误
@ -162,7 +162,7 @@ void do_stack_segment_fault(struct pt_regs *regs, unsigned long error_code)
kerror("do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_stack_segment_fault(12),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 13 #GP 通用保护性异常 // 13 #GP 通用保护性异常
@ -187,7 +187,7 @@ void do_general_protection(struct pt_regs *regs, unsigned long error_code)
printk_color(RED, BLACK, "Segment Selector Index:%#010x\n", error_code & 0xfff8); printk_color(RED, BLACK, "Segment Selector Index:%#010x\n", error_code & 0xfff8);
while (1) while (1)
; hlt();
} }
// 14 #PF 页故障 // 14 #PF 页故障
@ -224,7 +224,7 @@ void do_page_fault(struct pt_regs *regs, unsigned long error_code)
printk_color(RED,BLACK,"CR2:%#018lx\n",cr2); printk_color(RED,BLACK,"CR2:%#018lx\n",cr2);
while (1) while (1)
; hlt();
} }
// 15 Intel保留请勿使用 // 15 Intel保留请勿使用
@ -236,7 +236,7 @@ void do_x87_FPU_error(struct pt_regs *regs, unsigned long error_code)
kerror("do_x87_FPU_error(16),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_x87_FPU_error(16),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 17 #AC 对齐检测 // 17 #AC 对齐检测
@ -246,7 +246,7 @@ void do_alignment_check(struct pt_regs *regs, unsigned long error_code)
kerror("do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_alignment_check(17),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 18 #MC 机器检测 // 18 #MC 机器检测
@ -256,7 +256,7 @@ void do_machine_check(struct pt_regs *regs, unsigned long error_code)
kerror("do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_machine_check(18),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 19 #XM SIMD浮点异常 // 19 #XM SIMD浮点异常
@ -266,7 +266,7 @@ void do_SIMD_exception(struct pt_regs *regs, unsigned long error_code)
kerror("do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_SIMD_exception(19),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 20 #VE 虚拟化异常 // 20 #VE 虚拟化异常
@ -276,7 +276,7 @@ void do_virtualization_exception(struct pt_regs *regs, unsigned long error_code)
kerror("do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id); kerror("do_virtualization_exception(20),\tError Code:%#18lx,\tRSP:%#18lx,\tRIP:%#18lx\t CPU:%d\n", error_code, regs->rsp, regs->rip, proc_current_cpu_id);
while (1) while (1)
; hlt();
} }
// 21-21 Intel保留请勿使用 // 21-21 Intel保留请勿使用

View File

@ -151,7 +151,9 @@ void system_initialize()
// process_init(); // process_init();
current_pcb->cpu_id = 0; current_pcb->cpu_id = 0;
current_pcb->preempt_count = 0; current_pcb->preempt_count = 0;
process_init();
HPET_init(); HPET_init();
} }
//操作系统内核从这里开始执行 //操作系统内核从这里开始执行
@ -178,7 +180,7 @@ void Start_Kernel(void)
system_initialize(); system_initialize();
/*
uint64_t buf[100]; uint64_t buf[100];
ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, 0, 1, (uint64_t)&buf, 0, 0); ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, 0, 1, (uint64_t)&buf, 0, 0);
kdebug("buf[0]=%#010lx",(uint32_t)buf[0]); kdebug("buf[0]=%#010lx",(uint32_t)buf[0]);
@ -187,7 +189,7 @@ void Start_Kernel(void)
ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, 0, 1, (uint64_t)&buf, 0, 0); ahci_operation.transfer(ATA_CMD_READ_DMA_EXT, 0, 1, (uint64_t)&buf, 0, 0);
kdebug("buf[0]=%#010lx",(uint32_t)buf[0]); kdebug("buf[0]=%#010lx",(uint32_t)buf[0]);
*/
// show_welcome(); // show_welcome();
// test_mm(); // test_mm();
@ -216,7 +218,7 @@ void Start_Kernel(void)
// ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8, ICR_APIC_FIXED, ICR_No_Shorthand, true, 1); // 测试ipi // ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8, ICR_APIC_FIXED, ICR_No_Shorthand, true, 1); // 测试ipi
int last_sec = rtc_now.second; //int last_sec = rtc_now.second;
/* /*
while (1) while (1)
{ {

View File

@ -54,7 +54,7 @@ void sched_cfs()
current_pcb->flags &= ~PROC_NEED_SCHED; current_pcb->flags &= ~PROC_NEED_SCHED;
struct process_control_block *proc = sched_cfs_dequeue(); struct process_control_block *proc = sched_cfs_dequeue();
if (current_pcb->virtual_runtime >= proc->virtual_runtime) // 当前进程运行时间大于了下一进程的运行时间,进行切换 if (current_pcb->virtual_runtime >= proc->virtual_runtime || current_pcb->state != PROC_RUNNING) // 当前进程运行时间大于了下一进程的运行时间,进行切换
{ {
if (current_pcb->state = PROC_RUNNING) // 本次切换由于时间片到期引发,则再次加入就绪队列,否则交由其它功能模块进行管理 if (current_pcb->state = PROC_RUNNING) // 本次切换由于时间片到期引发,则再次加入就绪队列,否则交由其它功能模块进行管理
@ -107,8 +107,8 @@ void sched_cfs()
*/ */
void sched_update_jiffies() void sched_update_jiffies()
{ {
if(current_pcb->cpu_id == 0) //if (current_pcb->cpu_id == 0)
return; // return;
switch (current_pcb->priority) switch (current_pcb->priority)
{ {
case 0: case 0:

View File

@ -153,8 +153,13 @@ void smp_ap_start()
current_pcb->preempt_count = 0; current_pcb->preempt_count = 0;
sti(); sti();
while(1)
hlt();
/*
if (proc_current_cpu_id == 1) if (proc_current_cpu_id == 1)
process_init(); process_init();
*/
while (1) while (1)
{ {
printk_color(BLACK, WHITE, "CPU:%d IDLE process.\n", proc_current_cpu_id); printk_color(BLACK, WHITE, "CPU:%d IDLE process.\n", proc_current_cpu_id);

View File

@ -2,6 +2,7 @@
#include "../process/process.h" #include "../process/process.h"
#include <exception/gate.h> #include <exception/gate.h>
#include <exception/irq.h> #include <exception/irq.h>
#include<driver/disk/ahci/ahci.h>
// 导出系统调用入口函数定义在entry.S中 // 导出系统调用入口函数定义在entry.S中
extern void system_call(void); extern void system_call(void);
@ -85,6 +86,12 @@ ul sys_printf(struct pt_regs *regs)
return 0; return 0;
} }
ul sys_ahci_end_req(struct pt_regs *regs)
{
ahci_end_request();
return 0;
}
// 系统调用的内核入口程序 // 系统调用的内核入口程序
void do_syscall_int(struct pt_regs *regs, unsigned long error_code) void do_syscall_int(struct pt_regs *regs, unsigned long error_code)
{ {

View File

@ -5,7 +5,7 @@
#include "../process/ptrace.h" #include "../process/ptrace.h"
// 定义最大系统调用数量 // 定义最大系统调用数量
#define MAX_SYSTEM_CALL_NUM 128 #define MAX_SYSTEM_CALL_NUM 256
#define ESYSCALL_NOT_EXISTS 1 #define ESYSCALL_NOT_EXISTS 1
@ -53,6 +53,8 @@ ul system_call_not_exists(struct pt_regs *regs)
*/ */
ul sys_printf(struct pt_regs *regs); ul sys_printf(struct pt_regs *regs);
ul sys_ahci_end_req(struct pt_regs *regs);
// 系统调用的内核入口程序 // 系统调用的内核入口程序
void do_syscall_int(struct pt_regs *regs, unsigned long error_code); void do_syscall_int(struct pt_regs *regs, unsigned long error_code);
@ -60,4 +62,5 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] =
{ {
[0] = system_call_not_exists, [0] = system_call_not_exists,
[1] = sys_printf, [1] = sys_printf,
[2 ... MAX_SYSTEM_CALL_NUM - 1] = system_call_not_exists}; [2 ... 254] = system_call_not_exists,
[255] = sys_ahci_end_req};

View File

@ -1,4 +1,15 @@
#pragma once #pragma once
/**
*
* 1 printf
*
*
* 255 AHCI end_request
*
*/
#define SYS_NOT_EXISTS 0 #define SYS_NOT_EXISTS 0
#define SYS_PRINTF 1 #define SYS_PRINTF 1
#define SYS_AHCI_END_REQ 255