mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
测试IPI
This commit is contained in:
24
kernel/smp/ipi.h
Normal file
24
kernel/smp/ipi.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef x86_64
|
||||
#include <arch/x86_64/x86_64_ipi.h>
|
||||
#else
|
||||
#error "error type of arch!"
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief 发送ipi消息
|
||||
*
|
||||
* @param dest_mode 目标模式
|
||||
* @param deliver_status 投递模式
|
||||
* @param level 信号驱动电平
|
||||
* @param trigger 触发模式
|
||||
* @param vector 中断向量
|
||||
* @param deliver_mode 投递模式
|
||||
* @param dest_shorthand 投递目标速记值
|
||||
* @param apic_type apic的类型 (0:xapic 1: x2apic)
|
||||
* @param destination 投递目标
|
||||
*/
|
||||
extern void ipi_send_IPI(uint32_t dest_mode, uint32_t deliver_status, uint32_t level, uint32_t trigger,
|
||||
uint32_t vector, uint32_t deliver_mode, uint32_t dest_shorthand, bool apic_type, uint32_t destination);
|
@ -7,20 +7,20 @@
|
||||
#include "../process/process.h"
|
||||
#include "../process/spinlock.h"
|
||||
|
||||
#include "ipi.h"
|
||||
|
||||
static spinlock_t multi_core_starting_lock; // 多核启动锁
|
||||
|
||||
static struct acpi_Processor_Local_APIC_Structure_t *proc_local_apic_structs[MAX_SUPPORTED_PROCESSOR_NUM];
|
||||
static uint32_t total_processor_num = 0;
|
||||
int current_starting_cpu = 0;
|
||||
|
||||
|
||||
|
||||
void smp_init()
|
||||
{
|
||||
spin_init(&multi_core_starting_lock);
|
||||
spin_init(&multi_core_starting_lock); // 初始化多核启动锁
|
||||
|
||||
ul tmp_vaddr[MAX_SUPPORTED_PROCESSOR_NUM] = {0};
|
||||
|
||||
|
||||
apic_get_ics(ACPI_ICS_TYPE_PROCESSOR_LOCAL_APIC, tmp_vaddr, &total_processor_num);
|
||||
|
||||
kdebug("processor num=%d", total_processor_num);
|
||||
@ -31,22 +31,12 @@ void smp_init()
|
||||
// 将引导程序复制到物理地址0x20000处
|
||||
memcpy((unsigned char *)0x20000, _apu_boot_start, (unsigned long)&_apu_boot_end - (unsigned long)&_apu_boot_start);
|
||||
|
||||
// wrmsr(0x830, 0xc4500); // init IPI
|
||||
struct INT_CMD_REG icr_entry;
|
||||
icr_entry.dest_mode = DEST_PHYSICAL;
|
||||
icr_entry.deliver_status = IDLE;
|
||||
icr_entry.res_1 = 0;
|
||||
icr_entry.level = ICR_LEVEL_DE_ASSERT;
|
||||
icr_entry.trigger = EDGE_TRIGGER;
|
||||
icr_entry.res_2 = 0;
|
||||
icr_entry.res_3 = 0;
|
||||
// 设置多核IPI中断门
|
||||
for (int i = 200; i < 210; ++i)
|
||||
set_intr_gate(i, 2, SMP_interrupt_table[i - 200]);
|
||||
memset(SMP_IPI_desc, 0, sizeof(irq_desc_t) * SMP_IRQ_NUM);
|
||||
|
||||
icr_entry.vector = 0x00;
|
||||
icr_entry.deliver_mode = ICR_INIT;
|
||||
icr_entry.dest_shorthand = ICR_ALL_EXCLUDE_Self;
|
||||
icr_entry.destination.x2apic_destination = 0x00;
|
||||
|
||||
wrmsr(0x830, *(unsigned long *)&icr_entry); // INIT IPI
|
||||
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0x00, ICR_INIT, ICR_ALL_EXCLUDE_Self, true, 0x00);
|
||||
|
||||
for (int i = 1; i < total_processor_num; ++i) // i从1开始,不初始化bsp
|
||||
{
|
||||
@ -67,18 +57,9 @@ void smp_init()
|
||||
kdebug("GDT Table %#018lx, \t %#018lx", GDT_Table[10 + i * 2], GDT_Table[10 + i * 2 + 1]);
|
||||
kdebug("(cpu_core_info[i].tss_vaddr)=%#018lx", (cpu_core_info[i].tss_vaddr));
|
||||
kdebug("(cpu_core_info[i].stack_start)=%#018lx", (cpu_core_info[i].stack_start));
|
||||
icr_entry.vector = 0x20;
|
||||
icr_entry.deliver_mode = ICR_Start_up;
|
||||
icr_entry.dest_shorthand = ICR_No_Shorthand;
|
||||
icr_entry.destination.x2apic_destination = proc_local_apic_structs[i]->ACPI_ID;
|
||||
|
||||
// 先init ipi, 然后连续发送两次start-up IPI
|
||||
// x2APIC下,ICR寄存器地址为0x830
|
||||
// xAPIC下则为0xfee00300(31-0) 0xfee00310 (63-32)
|
||||
|
||||
wrmsr(0x830, *(ul *)&icr_entry); // start-up IPI
|
||||
wrmsr(0x830, *(ul *)&icr_entry); // start-up IPI
|
||||
//for(int k=0;i<1e5;++k);
|
||||
// 连续发送两次start-up IPI
|
||||
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0x20, ICR_Start_up, ICR_No_Shorthand, true, proc_local_apic_structs[i]->ACPI_ID);
|
||||
ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0x20, ICR_Start_up, ICR_No_Shorthand, true, proc_local_apic_structs[i]->ACPI_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,7 +70,7 @@ void smp_init()
|
||||
void smp_ap_start()
|
||||
{
|
||||
// 切换栈基地址
|
||||
//uint64_t stack_start = (uint64_t)kmalloc(STACK_SIZE, 0) + STACK_SIZE;
|
||||
// uint64_t stack_start = (uint64_t)kmalloc(STACK_SIZE, 0) + STACK_SIZE;
|
||||
__asm__ __volatile__("movq %0, %%rbp \n\t" ::"m"(cpu_core_info[current_starting_cpu].stack_start)
|
||||
: "memory");
|
||||
__asm__ __volatile__("movq %0, %%rsp \n\t" ::"m"(cpu_core_info[current_starting_cpu].stack_start)
|
||||
@ -107,8 +88,11 @@ void smp_ap_start()
|
||||
spin_unlock(&multi_core_starting_lock);
|
||||
sti();
|
||||
kdebug("IDT_addr = %#018lx", &IDT_Table);
|
||||
//sti();
|
||||
// int a = 1 / 0; // 在这儿会出现异常,cs fs gs ss寄存器会被改变
|
||||
// sti();
|
||||
// int a = 1 / 0; // 在这儿会出现异常,cs fs gs ss寄存器会被改变
|
||||
kdebug("IDT_addr = %#018lx", &IDT_Table);
|
||||
hlt();
|
||||
|
||||
|
||||
while (1) // 这里要循环hlt,原因是当收到中断后,核心会被唤醒,处理完中断之后不会自动hlt
|
||||
hlt();
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include "../common/glib.h"
|
||||
|
||||
#include "../common/asm.h"
|
||||
|
Reference in New Issue
Block a user