Renamed some init2() functions to init_post_vm() to make clearer when and why
they are called. Fixed some return types (mostly from int to status_t). Some minor other cleanup. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9440 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d330cc09e2
commit
8a37c740eb
@ -6,50 +6,51 @@
|
||||
** Distributed under the terms of the NewOS License.
|
||||
*/
|
||||
|
||||
|
||||
#include <arch/cpu.h>
|
||||
#include <vm.h>
|
||||
#include <smp.h>
|
||||
#include <arch/x86/selector.h>
|
||||
#include <tls.h>
|
||||
#include <boot/kernel_args.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static struct tss **tss;
|
||||
static int *tss_loaded;
|
||||
static struct tss **sTSS;
|
||||
static int *sIsTSSLoaded;
|
||||
|
||||
segment_descriptor *gGDT = NULL;
|
||||
|
||||
|
||||
int
|
||||
arch_cpu_preboot_init(kernel_args *ka)
|
||||
status_t
|
||||
arch_cpu_preboot_init(kernel_args *args)
|
||||
{
|
||||
write_dr3(0);
|
||||
return 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
arch_cpu_init(kernel_args *ka)
|
||||
status_t
|
||||
arch_cpu_init(kernel_args *args)
|
||||
{
|
||||
setup_system_time(ka->arch_args.system_time_cv_factor);
|
||||
setup_system_time(args->arch_args.system_time_cv_factor);
|
||||
|
||||
return 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
arch_cpu_init2(kernel_args *ka)
|
||||
status_t
|
||||
arch_cpu_init_post_vm(kernel_args *args)
|
||||
{
|
||||
unsigned int i;
|
||||
uint32 i;
|
||||
|
||||
// account for the segment descriptors
|
||||
|
||||
gGDT = (segment_descriptor *)ka->arch_args.vir_gdt;
|
||||
vm_create_anonymous_region(vm_get_kernel_aspace_id(), "gdt", (void **)&gGDT,
|
||||
B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
||||
gGDT = (segment_descriptor *)args->arch_args.vir_gdt;
|
||||
create_area("gdt", (void **)&gGDT, B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||
|
||||
// currently taken out of the build, because it's not yet used (and assumes
|
||||
@ -58,43 +59,42 @@ arch_cpu_init2(kernel_args *ka)
|
||||
|
||||
// setup task-state segments
|
||||
|
||||
tss = malloc(sizeof(struct tss *) * ka->num_cpus);
|
||||
if (tss == NULL) {
|
||||
panic("arch_cpu_init2: could not allocate buffer for tss pointers\n");
|
||||
sTSS = malloc(sizeof(struct tss *) * args->num_cpus);
|
||||
if (sTSS == NULL) {
|
||||
panic("arch_cpu_init_post_vm: could not allocate buffer for tss pointers\n");
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
tss_loaded = malloc(sizeof(int) * ka->num_cpus);
|
||||
if (tss == NULL) {
|
||||
panic("arch_cpu_init2: could not allocate buffer for tss booleans\n");
|
||||
sIsTSSLoaded = malloc(sizeof(int) * args->num_cpus);
|
||||
if (sIsTSSLoaded == NULL) {
|
||||
panic("arch_cpu_init_post_vm: could not allocate buffer for tss booleans\n");
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
memset(tss_loaded, 0, sizeof(int) * ka->num_cpus);
|
||||
memset(sIsTSSLoaded, 0, sizeof(int) * args->num_cpus);
|
||||
|
||||
for (i = 0; i < ka->num_cpus; i++) {
|
||||
char tss_name[16];
|
||||
region_id rid;
|
||||
for (i = 0; i < args->num_cpus; i++) {
|
||||
char tssName[16];
|
||||
area_id area;
|
||||
|
||||
sprintf(tss_name, "tss%d", i);
|
||||
rid = vm_create_anonymous_region(vm_get_kernel_aspace_id(), tss_name, (void **)&tss[i],
|
||||
B_ANY_KERNEL_ADDRESS, B_PAGE_SIZE, B_FULL_LOCK,
|
||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||
if (rid < 0) {
|
||||
sprintf(tssName, "tss%lu", i);
|
||||
area = create_area(tssName, (void **)&sTSS[i], B_ANY_KERNEL_ADDRESS, B_PAGE_SIZE,
|
||||
B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||
if (area < 0) {
|
||||
panic("arch_cpu_init2: unable to create region for tss\n");
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
// initialize TSS
|
||||
memset(tss[i], 0, sizeof(struct tss));
|
||||
tss[i]->ss0 = KERNEL_DATA_SEG;
|
||||
memset(sTSS[i], 0, sizeof(struct tss));
|
||||
sTSS[i]->ss0 = KERNEL_DATA_SEG;
|
||||
|
||||
// add TSS descriptor for this new TSS
|
||||
set_tss_descriptor(&gGDT[TSS_BASE_SEGMENT + i], (addr_t)tss[i], sizeof(struct tss));
|
||||
set_tss_descriptor(&gGDT[TSS_BASE_SEGMENT + i], (addr_t)sTSS[i], sizeof(struct tss));
|
||||
}
|
||||
|
||||
// setup TLS descriptors (one for every CPU)
|
||||
|
||||
for (i = 0; i < ka->num_cpus; i++) {
|
||||
for (i = 0; i < args->num_cpus; i++) {
|
||||
set_segment_descriptor(&gGDT[TLS_BASE_SEGMENT + i], 0, TLS_SIZE,
|
||||
DT_DATA_WRITEABLE, DPL_USER);
|
||||
}
|
||||
@ -109,14 +109,14 @@ i386_set_tss_and_kstack(addr_t kstack)
|
||||
int currentCPU = smp_get_current_cpu();
|
||||
|
||||
// dprintf("i386_set_kstack: kstack 0x%x, cpu %d\n", kstack, currentCPU);
|
||||
if (!tss_loaded[currentCPU]) {
|
||||
if (!sIsTSSLoaded[currentCPU]) {
|
||||
short seg = ((TSS_BASE_SEGMENT + currentCPU) << 3) | DPL_KERNEL;
|
||||
asm("movw %0, %%ax;"
|
||||
"ltr %%ax;" : : "r" (seg) : "eax");
|
||||
tss_loaded[currentCPU] = true;
|
||||
sIsTSSLoaded[currentCPU] = true;
|
||||
}
|
||||
|
||||
tss[currentCPU]->sp0 = kstack;
|
||||
sTSS[currentCPU]->sp0 = kstack;
|
||||
// dprintf("done\n");
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ i386_set_tss_and_kstack(addr_t kstack)
|
||||
void
|
||||
arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
|
||||
{
|
||||
int num_pages = end / B_PAGE_SIZE - start / B_PAGE_SIZE;
|
||||
int32 num_pages = end / B_PAGE_SIZE - start / B_PAGE_SIZE;
|
||||
while (num_pages-- >= 0) {
|
||||
invalidate_TLB(start);
|
||||
start += B_PAGE_SIZE;
|
||||
@ -142,7 +142,7 @@ arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
status_t
|
||||
arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *fault_handler)
|
||||
{
|
||||
char *tmp = (char *)to;
|
||||
@ -162,7 +162,7 @@ error:
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ssize_t
|
||||
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr_t *faultHandler)
|
||||
{
|
||||
int from_length = 0;
|
||||
@ -190,7 +190,7 @@ error:
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
status_t
|
||||
arch_cpu_user_memset(void *s, char c, size_t count, addr_t *fault_handler)
|
||||
{
|
||||
char *xs = (char *)s;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Copyright 2002-2004, The OpenBeOS Team. All rights reserved.
|
||||
** Distributed under the terms of the OpenBeOS License.
|
||||
** Copyright 2002-2004, The Haiku Team. All rights reserved.
|
||||
** Distributed under the terms of the Haiku License.
|
||||
**
|
||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||
** Distributed under the terms of the NewOS License.
|
||||
@ -274,11 +274,11 @@ i386_handle_trap(struct iframe frame)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
arch_int_init(kernel_args *ka)
|
||||
status_t
|
||||
arch_int_init(kernel_args *args)
|
||||
{
|
||||
// set the global idt variable
|
||||
idt = (desc_table *)ka->arch_args.vir_idt;
|
||||
idt = (desc_table *)args->arch_args.vir_idt;
|
||||
|
||||
// setup the interrupt controller
|
||||
out8(0x11, 0x20); // Start initialization sequence for #1.
|
||||
@ -337,16 +337,18 @@ arch_int_init(kernel_args *ka)
|
||||
set_intr_gate(254, &trap254);
|
||||
set_intr_gate(255, &trap255);
|
||||
|
||||
return 0;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
arch_int_init2(kernel_args *ka)
|
||||
status_t
|
||||
arch_int_init_post_vm(kernel_args *args)
|
||||
{
|
||||
idt = (desc_table *)ka->arch_args.vir_idt;
|
||||
vm_create_anonymous_region(vm_get_kernel_aspace_id(), "idt", (void *)&idt,
|
||||
B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
||||
area_id area;
|
||||
|
||||
idt = (desc_table *)args->arch_args.vir_idt;
|
||||
area = create_area("idt", (void *)&idt, B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||
return 0;
|
||||
|
||||
return area >= B_OK ? B_OK : area;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#include <arch/x86/interrupts.h>
|
||||
|
||||
#define TRACE_ARCH_VM
|
||||
//#define TRACE_ARCH_VM
|
||||
#ifdef TRACE_ARCH_VM
|
||||
# define TRACE(x) dprintf x
|
||||
#else
|
||||
@ -40,7 +40,7 @@ arch_vm_init_post_area(kernel_args *args)
|
||||
void *dmaAddress;
|
||||
area_id id;
|
||||
|
||||
TRACE(("arch_vm_init2: entry\n"));
|
||||
TRACE(("arch_vm_init_post_area: entry\n"));
|
||||
|
||||
// account for DMA area and mark the pages unusable
|
||||
vm_mark_page_range_inuse(0x0, 0xa0000 / B_PAGE_SIZE);
|
||||
@ -49,7 +49,7 @@ arch_vm_init_post_area(kernel_args *args)
|
||||
id = map_physical_memory("dma_region", (void *)0x0, 0xa0000,
|
||||
B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &dmaAddress);
|
||||
if (id < 0) {
|
||||
panic("arch_vm_init_post_areas: unable to map dma region\n");
|
||||
panic("arch_vm_init_post_area: unable to map dma region\n");
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user