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:
@@ -6,50 +6,51 @@
|
|||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <arch/cpu.h>
|
#include <arch/cpu.h>
|
||||||
#include <vm.h>
|
#include <vm.h>
|
||||||
#include <smp.h>
|
#include <smp.h>
|
||||||
#include <arch/x86/selector.h>
|
#include <arch/x86/selector.h>
|
||||||
#include <tls.h>
|
#include <tls.h>
|
||||||
|
#include <boot/kernel_args.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
static struct tss **tss;
|
static struct tss **sTSS;
|
||||||
static int *tss_loaded;
|
static int *sIsTSSLoaded;
|
||||||
|
|
||||||
segment_descriptor *gGDT = NULL;
|
segment_descriptor *gGDT = NULL;
|
||||||
|
|
||||||
|
|
||||||
int
|
status_t
|
||||||
arch_cpu_preboot_init(kernel_args *ka)
|
arch_cpu_preboot_init(kernel_args *args)
|
||||||
{
|
{
|
||||||
write_dr3(0);
|
write_dr3(0);
|
||||||
return 0;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
status_t
|
||||||
arch_cpu_init(kernel_args *ka)
|
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
|
status_t
|
||||||
arch_cpu_init2(kernel_args *ka)
|
arch_cpu_init_post_vm(kernel_args *args)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
uint32 i;
|
||||||
|
|
||||||
// account for the segment descriptors
|
// account for the segment descriptors
|
||||||
|
|
||||||
gGDT = (segment_descriptor *)ka->arch_args.vir_gdt;
|
gGDT = (segment_descriptor *)args->arch_args.vir_gdt;
|
||||||
vm_create_anonymous_region(vm_get_kernel_aspace_id(), "gdt", (void **)&gGDT,
|
create_area("gdt", (void **)&gGDT, B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
||||||
B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
|
||||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||||
|
|
||||||
// currently taken out of the build, because it's not yet used (and assumes
|
// 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
|
// setup task-state segments
|
||||||
|
|
||||||
tss = malloc(sizeof(struct tss *) * ka->num_cpus);
|
sTSS = malloc(sizeof(struct tss *) * args->num_cpus);
|
||||||
if (tss == NULL) {
|
if (sTSS == NULL) {
|
||||||
panic("arch_cpu_init2: could not allocate buffer for tss pointers\n");
|
panic("arch_cpu_init_post_vm: could not allocate buffer for tss pointers\n");
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
tss_loaded = malloc(sizeof(int) * ka->num_cpus);
|
sIsTSSLoaded = malloc(sizeof(int) * args->num_cpus);
|
||||||
if (tss == NULL) {
|
if (sIsTSSLoaded == NULL) {
|
||||||
panic("arch_cpu_init2: could not allocate buffer for tss booleans\n");
|
panic("arch_cpu_init_post_vm: could not allocate buffer for tss booleans\n");
|
||||||
return B_NO_MEMORY;
|
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++) {
|
for (i = 0; i < args->num_cpus; i++) {
|
||||||
char tss_name[16];
|
char tssName[16];
|
||||||
region_id rid;
|
area_id area;
|
||||||
|
|
||||||
sprintf(tss_name, "tss%d", i);
|
sprintf(tssName, "tss%lu", i);
|
||||||
rid = vm_create_anonymous_region(vm_get_kernel_aspace_id(), tss_name, (void **)&tss[i],
|
area = create_area(tssName, (void **)&sTSS[i], B_ANY_KERNEL_ADDRESS, B_PAGE_SIZE,
|
||||||
B_ANY_KERNEL_ADDRESS, B_PAGE_SIZE, B_FULL_LOCK,
|
B_FULL_LOCK, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
||||||
B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA);
|
if (area < 0) {
|
||||||
if (rid < 0) {
|
|
||||||
panic("arch_cpu_init2: unable to create region for tss\n");
|
panic("arch_cpu_init2: unable to create region for tss\n");
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize TSS
|
// initialize TSS
|
||||||
memset(tss[i], 0, sizeof(struct tss));
|
memset(sTSS[i], 0, sizeof(struct tss));
|
||||||
tss[i]->ss0 = KERNEL_DATA_SEG;
|
sTSS[i]->ss0 = KERNEL_DATA_SEG;
|
||||||
|
|
||||||
// add TSS descriptor for this new TSS
|
// 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)
|
// 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,
|
set_segment_descriptor(&gGDT[TLS_BASE_SEGMENT + i], 0, TLS_SIZE,
|
||||||
DT_DATA_WRITEABLE, DPL_USER);
|
DT_DATA_WRITEABLE, DPL_USER);
|
||||||
}
|
}
|
||||||
@@ -109,14 +109,14 @@ i386_set_tss_and_kstack(addr_t kstack)
|
|||||||
int currentCPU = smp_get_current_cpu();
|
int currentCPU = smp_get_current_cpu();
|
||||||
|
|
||||||
// dprintf("i386_set_kstack: kstack 0x%x, cpu %d\n", kstack, currentCPU);
|
// 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;
|
short seg = ((TSS_BASE_SEGMENT + currentCPU) << 3) | DPL_KERNEL;
|
||||||
asm("movw %0, %%ax;"
|
asm("movw %0, %%ax;"
|
||||||
"ltr %%ax;" : : "r" (seg) : "eax");
|
"ltr %%ax;" : : "r" (seg) : "eax");
|
||||||
tss_loaded[currentCPU] = true;
|
sIsTSSLoaded[currentCPU] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
tss[currentCPU]->sp0 = kstack;
|
sTSS[currentCPU]->sp0 = kstack;
|
||||||
// dprintf("done\n");
|
// dprintf("done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,7 +124,7 @@ i386_set_tss_and_kstack(addr_t kstack)
|
|||||||
void
|
void
|
||||||
arch_cpu_invalidate_TLB_range(addr_t start, addr_t end)
|
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) {
|
while (num_pages-- >= 0) {
|
||||||
invalidate_TLB(start);
|
invalidate_TLB(start);
|
||||||
start += B_PAGE_SIZE;
|
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)
|
arch_cpu_user_memcpy(void *to, const void *from, size_t size, addr_t *fault_handler)
|
||||||
{
|
{
|
||||||
char *tmp = (char *)to;
|
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)
|
arch_cpu_user_strlcpy(char *to, const char *from, size_t size, addr_t *faultHandler)
|
||||||
{
|
{
|
||||||
int from_length = 0;
|
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)
|
arch_cpu_user_memset(void *s, char c, size_t count, addr_t *fault_handler)
|
||||||
{
|
{
|
||||||
char *xs = (char *)s;
|
char *xs = (char *)s;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002-2004, The OpenBeOS Team. All rights reserved.
|
** Copyright 2002-2004, The Haiku Team. All rights reserved.
|
||||||
** Distributed under the terms of the OpenBeOS License.
|
** Distributed under the terms of the Haiku License.
|
||||||
**
|
**
|
||||||
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
** Copyright 2001, Travis Geiselbrecht. All rights reserved.
|
||||||
** Distributed under the terms of the NewOS License.
|
** Distributed under the terms of the NewOS License.
|
||||||
@@ -274,11 +274,11 @@ i386_handle_trap(struct iframe frame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
status_t
|
||||||
arch_int_init(kernel_args *ka)
|
arch_int_init(kernel_args *args)
|
||||||
{
|
{
|
||||||
// set the global idt variable
|
// 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
|
// setup the interrupt controller
|
||||||
out8(0x11, 0x20); // Start initialization sequence for #1.
|
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(254, &trap254);
|
||||||
set_intr_gate(255, &trap255);
|
set_intr_gate(255, &trap255);
|
||||||
|
|
||||||
return 0;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
status_t
|
||||||
arch_int_init2(kernel_args *ka)
|
arch_int_init_post_vm(kernel_args *args)
|
||||||
{
|
{
|
||||||
idt = (desc_table *)ka->arch_args.vir_idt;
|
area_id area;
|
||||||
vm_create_anonymous_region(vm_get_kernel_aspace_id(), "idt", (void *)&idt,
|
|
||||||
B_EXACT_ADDRESS, B_PAGE_SIZE, B_ALREADY_WIRED,
|
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);
|
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>
|
#include <arch/x86/interrupts.h>
|
||||||
|
|
||||||
#define TRACE_ARCH_VM
|
//#define TRACE_ARCH_VM
|
||||||
#ifdef TRACE_ARCH_VM
|
#ifdef TRACE_ARCH_VM
|
||||||
# define TRACE(x) dprintf x
|
# define TRACE(x) dprintf x
|
||||||
#else
|
#else
|
||||||
@@ -40,7 +40,7 @@ arch_vm_init_post_area(kernel_args *args)
|
|||||||
void *dmaAddress;
|
void *dmaAddress;
|
||||||
area_id id;
|
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
|
// account for DMA area and mark the pages unusable
|
||||||
vm_mark_page_range_inuse(0x0, 0xa0000 / B_PAGE_SIZE);
|
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,
|
id = map_physical_memory("dma_region", (void *)0x0, 0xa0000,
|
||||||
B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &dmaAddress);
|
B_ANY_KERNEL_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, &dmaAddress);
|
||||||
if (id < 0) {
|
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;
|
return B_NO_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user