/branches/network/boot/arch/sparc64/loader/asm.S |
---|
106,8 → 106,27 |
* 2. Invalidate I-cache. |
* 3. Flush instruction pipeline. |
*/ |
/* |
* US3 processors have a write-invalidate cache, so explicitly |
* invalidating it is not required. Whether to invalidate I-cache |
* or not is decided according to the value of the global |
* "subarchitecture" variable (set in the bootstrap). |
*/ |
set subarchitecture, %g2 |
ldub [%g2], %g2 |
cmp %g2, 3 |
be 1f |
nop |
0: |
call icache_flush |
nop |
1: |
membar #StoreStore |
/* |
* Flush the instruction pipeline. |
*/ |
flush %i7 |
mov %o0, %l1 |
134,7 → 153,6 |
retl |
! SF Erratum #51 |
nop |
.global ofw |
ofw: |
save %sp, -STACK_WINDOW_SAVE_AREA_SIZE, %sp |
/branches/network/boot/arch/sparc64/loader/boot.S |
---|
53,6 → 53,15 |
.ascii "HdrS" |
.word 0 |
.half 0 |
.half 0 |
.half 0 |
.half 0 |
.global silo_ramdisk_image |
silo_ramdisk_image: |
.word 0 |
.global silo_ramdisk_size |
silo_ramdisk_size: |
.word 0 |
.align 8 |
1: |
/branches/network/boot/arch/sparc64/loader/main.c |
---|
36,34 → 36,87 |
#include <ofw_tree.h> |
#include "ofwarch.h" |
#include <align.h> |
#include <macros.h> |
#include <string.h> |
bootinfo_t bootinfo; |
component_t components[COMPONENTS]; |
char *release = RELEASE; |
char *release = STRING(RELEASE); |
#ifdef REVISION |
char *revision = ", revision " REVISION; |
char *revision = ", revision " STRING(REVISION); |
#else |
char *revision = ""; |
#endif |
#ifdef TIMESTAMP |
char *timestamp = "\nBuilt on " TIMESTAMP; |
char *timestamp = "\nBuilt on " STRING(TIMESTAMP); |
#else |
char *timestamp = ""; |
#endif |
/** UltraSPARC subarchitecture - 1 for US, 3 for US3 */ |
uint8_t subarchitecture; |
/** |
* mask of the MID field inside the ICBUS_CONFIG register shifted by |
* MID_SHIFT bits to the right |
*/ |
uint16_t mid_mask; |
/** Print version information. */ |
static void version_print(void) |
{ |
printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\nCopyright (c) 2006 HelenOS project\n", release, revision, timestamp); |
printf("HelenOS SPARC64 Bootloader\nRelease %s%s%s\n" |
"Copyright (c) 2006 HelenOS project\n", |
release, revision, timestamp); |
} |
/* the lowest ID (read from the VER register) of some US3 CPU model */ |
#define FIRST_US3_CPU 0x14 |
/* the greatest ID (read from the VER register) of some US3 CPU model */ |
#define LAST_US3_CPU 0x19 |
/* UltraSPARC IIIi processor implementation code */ |
#define US_IIIi_CODE 0x15 |
/** |
* Sets the global variables "subarchitecture" and "mid_mask" to |
* correct values. |
*/ |
static void detect_subarchitecture(void) |
{ |
uint64_t v; |
asm volatile ("rdpr %%ver, %0\n" : "=r" (v)); |
v = (v << 16) >> 48; |
if ((v >= FIRST_US3_CPU) && (v <= LAST_US3_CPU)) { |
subarchitecture = SUBARCH_US3; |
if (v == US_IIIi_CODE) |
mid_mask = (1 << 5) - 1; |
else |
mid_mask = (1 << 10) - 1; |
} else if (v < FIRST_US3_CPU) { |
subarchitecture = SUBARCH_US; |
mid_mask = (1 << 5) - 1; |
} else { |
printf("\nThis CPU is not supported by HelenOS."); |
} |
} |
void bootstrap(void) |
{ |
void *base = (void *) KERNEL_VIRTUAL_ADDRESS; |
void *balloc_base; |
unsigned int top = 0; |
int i, j; |
version_print(); |
detect_subarchitecture(); |
init_components(components); |
if (!ofw_get_physmem_start(&bootinfo.physmem_start)) { |
81,6 → 134,23 |
halt(); |
} |
/* |
* SILO for some reason adds 0x400000 and subtracts |
* bootinfo.physmem_start to/from silo_ramdisk_image. |
* We just need plain physical address so we fix it up. |
*/ |
if (silo_ramdisk_image) { |
silo_ramdisk_image += bootinfo.physmem_start; |
silo_ramdisk_image -= 0x400000; |
/* Install 1:1 mapping for the ramdisk. */ |
if (ofw_map((void *)((uintptr_t) silo_ramdisk_image), |
(void *)((uintptr_t) silo_ramdisk_image), |
silo_ramdisk_size, -1) != 0) { |
printf("Failed to map ramdisk.\n"); |
halt(); |
} |
} |
printf("\nSystem info\n"); |
printf(" memory: %dM starting at %P\n", |
bootinfo.memmap.total >> 20, bootinfo.physmem_start); |
89,21 → 159,73 |
printf(" kernel entry point at %P\n", KERNEL_VIRTUAL_ADDRESS); |
printf(" %P: boot info structure\n", &bootinfo); |
unsigned int i; |
for (i = 0; i < COMPONENTS; i++) |
/* |
* Figure out destination address for each component. |
* In this phase, we don't copy the components yet because we want to |
* to be careful not to overwrite anything, especially the components |
* which haven't been copied yet. |
*/ |
bootinfo.taskmap.count = 0; |
for (i = 0; i < COMPONENTS; i++) { |
printf(" %P: %s image (size %d bytes)\n", components[i].start, |
components[i].name, components[i].size); |
top = ALIGN_UP(top, PAGE_SIZE); |
if (i > 0) { |
if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
printf("Skipping superfluous components.\n"); |
break; |
} |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
base + top; |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
components[i].size; |
strncpy(bootinfo.taskmap.tasks[ |
bootinfo.taskmap.count].name, components[i].name, |
BOOTINFO_TASK_NAME_BUFLEN); |
bootinfo.taskmap.count++; |
} |
top += components[i].size; |
} |
void * base = (void *) KERNEL_VIRTUAL_ADDRESS; |
unsigned int top = 0; |
j = bootinfo.taskmap.count - 1; /* do not consider ramdisk */ |
printf("\nCopying components\n"); |
bootinfo.taskmap.count = 0; |
for (i = 0; i < COMPONENTS; i++) { |
printf(" %s...", components[i].name); |
if (silo_ramdisk_image) { |
/* Treat the ramdisk as the last bootinfo task. */ |
if (bootinfo.taskmap.count == TASKMAP_MAX_RECORDS) { |
printf("Skipping ramdisk.\n"); |
goto skip_ramdisk; |
} |
top = ALIGN_UP(top, PAGE_SIZE); |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
base + top; |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
silo_ramdisk_size; |
bootinfo.taskmap.count++; |
printf("\nCopying ramdisk..."); |
/* |
* Claim and map the whole ramdisk as it may exceed the area |
* given to us by SILO. |
*/ |
(void) ofw_claim_phys(base + top, silo_ramdisk_size); |
(void) ofw_map(bootinfo.physmem_start + base + top, base + top, |
silo_ramdisk_size, -1); |
memmove(base + top, (void *)((uintptr_t)silo_ramdisk_image), |
silo_ramdisk_size); |
printf("done.\n"); |
top += silo_ramdisk_size; |
} |
skip_ramdisk: |
/* |
* Now we can proceed to copy the components. We do it in reverse order |
* so that we don't overwrite anything even if the components overlap |
* with base. |
*/ |
printf("\nCopying bootinfo tasks\n"); |
for (i = COMPONENTS - 1; i > 0; i--, j--) { |
printf(" %s...", components[i].name); |
/* |
* At this point, we claim the physical memory that we are |
* going to use. We should be safe in case of the virtual |
* address space because the OpenFirmware, according to its |
110,36 → 232,41 |
* SPARC binding, should restrict its use of virtual memory |
* to addresses from [0xffd00000; 0xffefffff] and |
* [0xfe000000; 0xfeffffff]. |
* |
* XXX We don't map this piece of memory. We simply rely on |
* SILO to have it done for us already in this case. |
*/ |
(void) ofw_claim_phys(bootinfo.physmem_start + base + top, |
(void) ofw_claim_phys(bootinfo.physmem_start + |
bootinfo.taskmap.tasks[j].addr, |
ALIGN_UP(components[i].size, PAGE_SIZE)); |
memcpy(base + top, components[i].start, components[i].size); |
if (i > 0) { |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = |
base + top; |
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = |
components[i].size; |
bootinfo.taskmap.count++; |
} |
top += components[i].size; |
memcpy((void *)bootinfo.taskmap.tasks[j].addr, |
components[i].start, components[i].size); |
printf("done.\n"); |
} |
printf("\nCopying kernel..."); |
(void) ofw_claim_phys(bootinfo.physmem_start + base, |
ALIGN_UP(components[0].size, PAGE_SIZE)); |
memcpy(base, components[0].start, components[0].size); |
printf("done.\n"); |
/* |
* Claim the physical memory for the boot allocator. |
* Claim and map the physical memory for the boot allocator. |
* Initialize the boot allocator. |
*/ |
(void) ofw_claim_phys(bootinfo.physmem_start + |
base + ALIGN_UP(top, PAGE_SIZE), BALLOC_MAX_SIZE); |
balloc_init(&bootinfo.ballocs, ALIGN_UP(((uintptr_t) base) + top, |
PAGE_SIZE)); |
balloc_base = base + ALIGN_UP(top, PAGE_SIZE); |
(void) ofw_claim_phys(bootinfo.physmem_start + balloc_base, |
BALLOC_MAX_SIZE); |
(void) ofw_map(bootinfo.physmem_start + balloc_base, balloc_base, |
BALLOC_MAX_SIZE, -1); |
balloc_init(&bootinfo.ballocs, (uintptr_t)balloc_base); |
printf("\nCanonizing OpenFirmware device tree..."); |
bootinfo.ofw_root = ofw_tree_build(); |
printf("done.\n"); |
#ifdef CONFIG_SMP |
#ifdef CONFIG_AP |
printf("\nChecking for secondary processors..."); |
if (!ofw_cpu()) |
printf("Error: unable to get CPU properties\n"); |
146,9 → 273,10 |
printf("done.\n"); |
#endif |
ofw_setup_palette(); |
printf("\nBooting the kernel...\n"); |
jump_to_kernel((void *) KERNEL_VIRTUAL_ADDRESS, |
bootinfo.physmem_start | BSP_PROCESSOR, &bootinfo, |
sizeof(bootinfo)); |
} |
/branches/network/boot/arch/sparc64/loader/main.h |
---|
38,12 → 38,19 |
#define TASKMAP_MAX_RECORDS 32 |
/** Size of buffer for storing task name in task_t. */ |
#define BOOTINFO_TASK_NAME_BUFLEN 32 |
#define BSP_PROCESSOR 1 |
#define AP_PROCESSOR 0 |
#define SUBARCH_US 1 |
#define SUBARCH_US3 3 |
typedef struct { |
void *addr; |
uint32_t size; |
char name[BOOTINFO_TASK_NAME_BUFLEN]; |
} task_t; |
typedef struct { |
59,6 → 66,9 |
ofw_tree_node_t *ofw_root; |
} bootinfo_t; |
extern uint32_t silo_ramdisk_image; |
extern uint32_t silo_ramdisk_size; |
extern bootinfo_t bootinfo; |
extern void start(void); |
/branches/network/boot/arch/sparc64/loader/ofwarch.c |
---|
40,6 → 40,10 |
#include "main.h" |
#include "asm.h" |
/* these tho variables will be set by the detect_subarchitecture function */ |
extern uint8_t subarchitecture; |
extern uint16_t mid_mask; |
void write(const char *str, const int len) |
{ |
int i; |
56,36 → 60,40 |
return flag != -1; |
} |
int ofw_cpu(void) |
/** |
* Starts all CPUs represented by following siblings of the given node, |
* except for the current CPU. |
* |
* @param child The first child of the OFW tree node whose children |
* represent CPUs to be woken up. |
* @param current_mid MID of the current CPU, the current CPU will |
* (of course) not be woken up. |
* @return Number of CPUs which have the same parent node as |
* "child". |
*/ |
static int wake_cpus_in_node(phandle child, uint64_t current_mid) |
{ |
int cpus; |
char type_name[BUF_SIZE]; |
phandle node; |
node = ofw_get_child_node(ofw_root); |
if (node == 0 || node == -1) { |
printf("Could not find any child nodes of the root node.\n"); |
return 0; |
} |
uint64_t current_mid; |
asm volatile ("ldxa [%1] %2, %0\n" |
: "=r" (current_mid) |
: "r" (0), "i" (ASI_UPA_CONFIG)); |
current_mid >>= UPA_CONFIG_MID_SHIFT; |
current_mid &= UPA_CONFIG_MID_MASK; |
int cpus; |
for (cpus = 0; node != 0 && node != -1; node = ofw_get_peer_node(node), |
cpus++) { |
if (ofw_get_property(node, "device_type", type_name, |
for (cpus = 0; child != 0 && child != -1; |
child = ofw_get_peer_node(child), cpus++) { |
if (ofw_get_property(child, "device_type", type_name, |
sizeof(type_name)) > 0) { |
if (strcmp(type_name, "cpu") == 0) { |
uint32_t mid; |
if (ofw_get_property(node, "upa-portid", &mid, |
sizeof(mid)) <= 0) |
/* |
* "upa-portid" for US, "portid" for US-III, |
* "cpuid" for US-IV |
*/ |
if (ofw_get_property( |
child, "upa-portid", |
&mid, sizeof(mid)) <= 0 |
&& ofw_get_property(child, "portid", |
&mid, sizeof(mid)) <= 0 |
&& ofw_get_property(child, "cpuid", |
&mid, sizeof(mid)) <= 0) |
continue; |
if (current_mid != mid) { |
93,7 → 101,7 |
* Start secondary processor. |
*/ |
(void) ofw_call("SUNW,start-cpu", 3, 1, |
NULL, node, KERNEL_VIRTUAL_ADDRESS, |
NULL, child, KERNEL_VIRTUAL_ADDRESS, |
bootinfo.physmem_start | |
AP_PROCESSOR); |
} |
104,6 → 112,53 |
return cpus; |
} |
/** |
* Finds out the current CPU's MID and wakes up all AP processors. |
*/ |
int ofw_cpu(void) |
{ |
int cpus; |
phandle node; |
phandle subnode; |
phandle cpus_parent; |
phandle cmp; |
char name[BUF_SIZE]; |
/* get the current CPU MID */ |
uint64_t current_mid; |
asm volatile ("ldxa [%1] %2, %0\n" |
: "=r" (current_mid) |
: "r" (0), "i" (ASI_ICBUS_CONFIG)); |
current_mid >>= ICBUS_CONFIG_MID_SHIFT; |
current_mid &= mid_mask; |
/* wake up CPUs */ |
cpus_parent = ofw_find_device("/ssm@0,0"); |
if (cpus_parent == 0 || cpus_parent == -1) { |
cpus_parent = ofw_find_device("/"); |
} |
node = ofw_get_child_node(cpus_parent); |
cpus = wake_cpus_in_node(node, current_mid); |
while (node != 0 && node != -1) { |
if (ofw_get_property(node, "name", name, |
sizeof(name)) > 0) { |
if (strcmp(name, "cmp") == 0) { |
subnode = ofw_get_child_node(node); |
cpus += wake_cpus_in_node(subnode, |
current_mid); |
} |
} |
node = ofw_get_peer_node(node); |
} |
return cpus; |
} |
/** Get physical memory starting address. |
* |
* @param start Pointer to variable where the physical memory starting |
/branches/network/boot/arch/sparc64/loader/register.h |
---|
33,8 → 33,7 |
#define PSTATE_PRIV_BIT 4 |
#define PSTATE_AM_BIT 8 |
#define ASI_UPA_CONFIG 0x4a |
#define UPA_CONFIG_MID_SHIFT 17 |
#define UPA_CONFIG_MID_MASK 0x1f |
#define ASI_ICBUS_CONFIG 0x4a |
#define ICBUS_CONFIG_MID_SHIFT 17 |
#endif |
/branches/network/boot/arch/sparc64/loader/Makefile |
---|
27,7 → 27,7 |
# |
include ../../../../version |
include ../../../Makefile.config |
-include ../../../../Makefile.config |
## Toolchain configuration |
# |
57,16 → 57,8 |
OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump |
endif |
CFLAGS = -DRELEASE=\"$(RELEASE)\" -I. -I../../../generic -I../../../genarch -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=ultrasparc -m64 |
CFLAGS = -DRELEASE=$(RELEASE) -I. -I../../../generic -I../../../genarch -imacros ../../../../config.h -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=ultrasparc -m64 -mno-fpu -pipe |
ifdef REVISION |
CFLAGS += "-DREVISION=\"$(REVISION)\"" |
endif |
ifdef TIMESTAMP |
CFLAGS += "-DTIMESTAMP=\"$(TIMESTAMP)\"" |
endif |
SOURCES = \ |
main.c \ |
_components.c \ |
79,6 → 71,9 |
asm.S \ |
boot.S |
# |
# All components that go to image.boot without the ramdisk. |
# |
COMPONENTS = \ |
$(KERNELDIR)/kernel.bin \ |
$(USPACEDIR)/srv/ns/ns \ |
94,19 → 89,40 |
COMPONENTS += $(USPACEDIR)/srv/fs/fat/fat |
endif |
RD_TASKS = \ |
# |
# Final list of all components that go to image.boot. |
# |
ALL_COMPONENTS = $(COMPONENTS) |
ifeq ($(CONFIG_RD_EXTERNAL),n) |
ALL_COMPONENTS += ./initrd.img |
endif |
RD_SRVS = \ |
$(USPACEDIR)/srv/fb/fb \ |
$(USPACEDIR)/srv/kbd/kbd \ |
$(USPACEDIR)/srv/console/console \ |
$(USPACEDIR)/srv/fs/tmpfs/tmpfs \ |
$(USPACEDIR)/srv/fs/tmpfs/tmpfs |
ifeq ($(MACHINE),generic) |
RD_SRVS += \ |
$(USPACEDIR)/srv/fs/fat/fat \ |
$(USPACEDIR)/srv/fhc/fhc \ |
$(USPACEDIR)/srv/obio/obio |
endif |
RD_APPS = \ |
$(USPACEDIR)/app/tetris/tetris \ |
$(USPACEDIR)/app/tester/tester \ |
$(USPACEDIR)/app/trace/trace \ |
$(USPACEDIR)/app/bdsh/bdsh \ |
$(USPACEDIR)/app/klog/klog |
ifeq ($(MACHINE),generic) |
RD_APPS += \ |
$(USPACEDIR)/app/tester/tester |
endif |
OBJECTS := $(addsuffix .o,$(basename $(SOURCES))) |
COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS)))) |
ALL_COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(ALL_COMPONENTS)))) |
.PHONY: all clean depend |
114,31 → 130,37 |
-include Makefile.depend |
image.boot: depend _components.h _link.ld $(COMPONENT_OBJECTS) initrd.o $(OBJECTS) |
$(LD) -Map image.map -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) initrd.o $(OBJECTS) -o $@ |
image.boot: depend _components.h _link.ld $(ALL_COMPONENT_OBJECTS) $(OBJECTS) |
$(LD) -Map image.map -no-check-sections -N -T _link.ld $(ALL_COMPONENT_OBJECTS) $(OBJECTS) -o $@ |
depend: |
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null |
-makedepend -f - -- $(DEFS) $(CFLAGS) -- $(SOURCES) > Makefile.depend 2> /dev/null |
clean: |
-for task in $(RD_TASKS) ; do \ |
rm -f $(USPACEDIR)/dist/sbin/`basename $$task` ; \ |
-for file in $(RD_SRVS) ; do \ |
rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \ |
done |
-rm -f _components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o $(OBJECTS) initrd.img image.boot image.map image.disasm Makefile.depend |
-for file in $(RD_APPS) ; do \ |
rm -f $(USPACEDIR)/dist/app/`basename $$file` ; \ |
done |
-rm -f _components.h _components.c _link.ld $(ALL_COMPONENT_OBJECTS) $(OBJECTS) initrd.img image.boot image.map image.disasm Makefile.depend |
_components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o: $(COMPONENTS) $(RD_TASKS) _link.ld.in |
for task in $(RD_TASKS) ; do \ |
cp $$task $(USPACEDIR)/dist/sbin/ ; \ |
_components.h _components.c _link.ld $(ALL_COMPONENT_OBJECTS): $(COMPONENTS) $(RD_SRVS) $(RD_APPS) _link.ld.in |
for file in $(RD_SRVS) ; do \ |
cp $$file $(USPACEDIR)/dist/srv/ ; \ |
done |
for file in $(RD_APPS) ; do \ |
cp $$file $(USPACEDIR)/dist/app/ ; \ |
done |
ifeq ($(RDFMT),tmpfs) |
../../../../tools/mktmpfs.py $(USPACEDIR)/dist/ initrd.fs |
endif |
ifeq ($(RDFMT),fat) |
../../../../tools/mkfat.sh $(USPACEDIR)/dist/ initrd.fs |
../../../../tools/mkfat.py $(USPACEDIR)/dist/ initrd.fs |
endif |
../../../../tools/mkhord.py 16384 initrd.fs initrd.img |
rm initrd.fs |
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 1 "unsigned long" $(COMPONENTS) ./initrd.img |
../../../tools/pack.py $(OBJCOPY) $(BFD_NAME) $(BFD_ARCH) 1 "unsigned long" $(ALL_COMPONENTS) |
%.o: %.S |
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@ |