x86_64: create idle thread and initialise runqueue during AP bootstrap
This commit is contained in:
@@ -10,32 +10,37 @@ using namespace arch::acpi;
|
||||
extern "C" uint8_t acpi_bsp_lapic_id(void);
|
||||
extern "C" char ap_trampoline[];
|
||||
|
||||
volatile struct vm_page *__ap_stack_page = NULL;
|
||||
volatile uintptr_t __ap_stack_top = 0;
|
||||
volatile uint8_t __this_ap_ok = 0;
|
||||
volatile uint8_t __all_ap_ok = 0;
|
||||
|
||||
/*
|
||||
static int __used send_ipi(void *lapic, unsigned int target_id, uint32_t
|
||||
payload)
|
||||
{
|
||||
uintptr_t lapic_ptr = (uintptr_t)lapic;
|
||||
|
||||
*((volatile uint32_t*)(lapic_ptr + LAPIC_IPI_STATUS_REG)) = 0;
|
||||
*((volatile uint32_t*)(lapic_ptr + LAPIC_IPI_DEST_REG)) = (*((volatile
|
||||
uint32_t*)(lapic_ptr + LAPIC_IPI_DEST_REG)) & 0x00ffffff) | (target_id << 24);
|
||||
*((volatile uint32_t*)(lapic_ptr + LAPIC_IPI_ICR_REG)) = (*((volatile
|
||||
uint32_t*)(lapic_ptr + LAPIC_IPI_ICR_REG)) & 0xfff00000) | payload; do { __asm__
|
||||
__volatile__ ("pause" : : : "memory"); }while(*((volatile uint32_t*)(lapic_ptr +
|
||||
LAPIC_IPI_ICR_REG)) & (1 << 12));
|
||||
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
volatile unsigned int __this_ap_id = 0;
|
||||
|
||||
extern "C" void ap_trampoline_exit(void)
|
||||
{
|
||||
printk("OK!");
|
||||
ml_cpu_block *this_cpu = (ml_cpu_block *)kmalloc(sizeof *this_cpu, VM_NORMAL);
|
||||
ml_cpu_block_init(this_cpu);
|
||||
ml_cpu_block_use(this_cpu);
|
||||
|
||||
this_cpu->c_cpu_id = __this_ap_id;
|
||||
|
||||
struct cpu_data *self = get_this_cpu();
|
||||
self->c_flags = CPU_ONLINE;
|
||||
self->c_id = __this_ap_id;
|
||||
this_cpu->c_data = self;
|
||||
|
||||
struct thread *this_thread = create_idle_thread();
|
||||
this_thread->tr_kstack = (struct vm_page *)__ap_stack_page;
|
||||
self->c_rq.rq_idle = self->c_rq.rq_cur = this_thread;
|
||||
|
||||
put_cpu(self);
|
||||
|
||||
ap_apic_init();
|
||||
|
||||
__this_ap_ok = 1;
|
||||
irq_enable();
|
||||
|
||||
idle();
|
||||
}
|
||||
|
||||
static int init_ap(struct acpi_madt_record *rec, local_apic& lapic, uint8_t bsp_id)
|
||||
@@ -46,12 +51,13 @@ static int init_ap(struct acpi_madt_record *rec, local_apic& lapic, uint8_t bsp_
|
||||
}
|
||||
|
||||
if (ap_lapic->l_apic_id == bsp_id) {
|
||||
printk("acpi: core %u online [BSP]", ap_lapic->l_apic_id);
|
||||
//printk("acpi: core %u online [BSP]", ap_lapic->l_apic_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct vm_page *ap_stack = vm_page_alloc(VM_PAGE_4K, VM_NORMAL);
|
||||
__ap_stack_top = (uintptr_t)vm_page_get_vaddr(ap_stack) + VM_PAGE_SIZE;
|
||||
__ap_stack_page = vm_page_alloc(VM_PAGE_4K, VM_NORMAL);
|
||||
__ap_stack_top = (uintptr_t)vm_page_get_vaddr((struct vm_page *)__ap_stack_page) + VM_PAGE_SIZE;
|
||||
__this_ap_id = ap_lapic->l_apic_id;
|
||||
|
||||
lapic.send_ipi(ap_lapic->l_apic_id, 0xC500);
|
||||
lapic.send_ipi(ap_lapic->l_apic_id, 0x8500);
|
||||
@@ -62,7 +68,7 @@ static int init_ap(struct acpi_madt_record *rec, local_apic& lapic, uint8_t bsp_
|
||||
ml_cpu_relax();
|
||||
} while (__this_ap_ok == 0);
|
||||
|
||||
printk("acpi: core %u online [AP]", ap_lapic->l_apic_id);
|
||||
//printk("acpi: core %u online [AP]", ap_lapic->l_apic_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user