Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 1395 → Rev 1394

/boot/trunk/arch/ppc64/loader/pack
File deleted
Property changes:
Deleted: svn:executable
-*
\ No newline at end of property
/boot/trunk/arch/ppc64/loader/asm.S
106,19 → 106,12
# r3 = bootinfo (pa)
# r4 = bootinfo_size
# r5 = trans (pa)
# r6 = bytes to copy
# r7 = real_mode (pa)
# r6 = kernel size
# r7 = framebuffer (pa)
# r8 = real_mode (pa)
# disable interrupts
mtspr srr0, r8
mfmsr r31
rlwinm r31, r31, 0, 17, 15
mtmsr r31
# set real_mode meeting point address
mtspr srr0, r7
# jumps to real_mode
mfmsr r31
131,7 → 124,7
isync
rfid
 
.section REALMODE, "ax"
.section REALMODE
.align PAGE_WIDTH
.global real_mode
 
140,7 → 133,8
# copy kernel to proper location
#
# r5 = trans (pa)
# r6 = bytes to copy
# r6 = kernel size
# r7 = framebuffer (pa)
li r31, PAGE_SIZE >> 2
li r30, 0
174,23 → 168,74
copy_end:
# initially fill segment registers
# invalidate segment registers
 
li r31, 16
mtctr r31
li r31, 0
li r30, 0x2000
li r30, 0
 
seg_fill:
mtsrin r30, r31
addi r30, r30, 0x111
addis r31, r31, 0x1000 # move to next SR
bdnz seg_fill
# invalidate block address translation registers
mtspr ibat0u, r30
mtspr ibat0l, r30
mtspr ibat1u, r30
mtspr ibat1l, r30
mtspr ibat2u, r30
mtspr ibat2l, r30
mtspr ibat3u, r30
mtspr ibat3l, r30
mtspr dbat0u, r30
mtspr dbat0l, r30
mtspr dbat1u, r30
mtspr dbat1l, r30
mtspr dbat2u, r30
mtspr dbat2l, r30
mtspr dbat3u, r30
mtspr dbat3l, r30
# create identity mapping
# FIXME: map exactly the size of RAM
lis r31, 0x8000
ori r31, r31, 0x0ffe
lis r30, 0x0000
ori r30, r30, 0x0002
mtspr ibat0u, r31
mtspr ibat0l, r30
mtspr dbat0u, r31
mtspr dbat0l, r30
# FIXME: temporal framebuffer mapping
lis r31, 0xf000
ori r31, r31, 0x0ffe
mr r30, r7
ori r30, r30, 0x0002
mtspr dbat1u, r31
mtspr dbat1l, r30
tlbia
tlbsync
# start the kernel
#
/boot/trunk/arch/ppc64/loader/ofw.h
47,16 → 47,16
 
typedef struct {
unsigned long total;
unsigned int count;
unsigned long count;
memzone_t zones[MEMMAP_MAX_RECORDS];
} memmap_t;
 
typedef struct {
void *addr;
unsigned int width;
unsigned int height;
unsigned int bpp;
unsigned int scanline;
unsigned long width;
unsigned long height;
unsigned long bpp;
unsigned long scanline;
} screen_t;
 
 
64,8 → 64,8
extern void ofw_write(const char *str, const long len);
 
extern void *ofw_translate(const void *virt);
extern int ofw_map(const void *phys, const void *virt, const long size, const int mode);
extern int ofw_memmap(memmap_t *map);
extern int ofw_screen(screen_t *screen);
extern long ofw_map(const void *phys, const void *virt, const long size, const long mode);
extern long ofw_memmap(memmap_t *map);
extern long ofw_screen(screen_t *screen);
 
#endif
/boot/trunk/arch/ppc64/loader/main.c
29,8 → 29,11
#include "main.h"
#include "printf.h"
#include "asm.h"
#include "_components.h"
 
#define KERNEL_START ((void *) &_binary_____________kernel_kernel_bin_start)
#define KERNEL_END ((void *) &_binary_____________kernel_kernel_bin_end)
#define KERNEL_SIZE ((unsigned long) KERNEL_END - (unsigned long) KERNEL_START)
 
#define HEAP_GAP 1024000
 
bootinfo_t bootinfo;
73,30 → 76,24
 
void bootstrap(void)
{
printf("\nHelenOS PPC Bootloader\n");
printf("\nHelenOS PPC64 Bootloader\n");
init_components();
check_align(KERNEL_START, "Kernel image");
check_align(&real_mode, "Bootstrap trampoline");
check_align(&trans, "Translation table");
unsigned int i;
for (i = 0; i < COMPONENTS; i++)
check_align(components[i].start, components[i].name);
check_align(&real_mode, "bootstrap trampoline");
check_align(&trans, "translation table");
if (!ofw_memmap(&bootinfo.memmap)) {
printf("Error: unable to get memory map, halting.\n");
printf("Error: Unable to get memory map, halting.\n");
halt();
}
if (bootinfo.memmap.total == 0) {
printf("Error: no memory detected, halting.\n");
printf("Error: No memory detected, halting.\n");
halt();
}
if (!ofw_screen(&bootinfo.screen)) {
printf("Error: unable to get screen properties, halting.\n");
printf("Error: Unable to get screen properties, halting.\n");
halt();
}
106,49 → 103,26
void *real_mode_pa = ofw_translate(&real_mode);
void *trans_pa = ofw_translate(&trans);
void *bootinfo_pa = ofw_translate(&bootinfo);
void *fb = (void *) (((unsigned long) bootinfo.screen.addr) & ((unsigned long) ~0 << 17));
printf("\nMemory statistics (total %d MB)\n", bootinfo.memmap.total >> 20);
printf(" %L: boot info structure (physical %L)\n", &bootinfo, bootinfo_pa);
printf(" %L: bootstrap trampoline (physical %L)\n", &real_mode, real_mode_pa);
printf(" %L: translation table (physical %L)\n", &trans, trans_pa);
for (i = 0; i < COMPONENTS; i++)
printf(" %L: %s image (size %d bytes)\n", components[i].start, components[i].name, components[i].size);
printf(" kernel image at %L (size %d bytes)\n", KERNEL_START, KERNEL_SIZE);
printf(" boot info at %L (physical %L)\n", &bootinfo, bootinfo_pa);
printf(" bootstrap trampoline at %L (physical %L)\n", &real_mode, real_mode_pa);
printf(" translation table at %L (physical %L)\n", &trans, trans_pa);
unsigned long top = 0;
for (i = 0; i < COMPONENTS; i++)
top += ALIGN_UP(components[i].size, PAGE_SIZE);
unsigned long pages = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE) >> PAGE_WIDTH;
for (i = 0; i < pages; i++) {
void *pa = ofw_translate(KERNEL_START + (i << PAGE_WIDTH));
fix_overlap(KERNEL_START + (i << PAGE_WIDTH), &pa, "kernel", &top);
trans[i] = pa;
unsigned long top = ALIGN_UP(KERNEL_SIZE, PAGE_SIZE);
unsigned long addr;
for (addr = 0; addr < KERNEL_SIZE; addr += PAGE_SIZE) {
void *pa = ofw_translate(KERNEL_START + addr);
fix_overlap(KERNEL_START + addr, &pa, "Kernel image", &top);
trans[addr >> PAGE_WIDTH] = pa;
}
bootinfo.taskmap.count = 0;
for (i = 1; i < COMPONENTS; i++) {
unsigned long component_pages = ALIGN_UP(components[i].size, PAGE_SIZE) >> PAGE_WIDTH;
unsigned long j;
for (j = 0; j < component_pages; j++) {
void *pa = ofw_translate(components[i].start + (j << PAGE_WIDTH));
fix_overlap(components[i].start + (j << PAGE_WIDTH), &pa, components[i].name, &top);
trans[pages + j] = pa;
if (j == 0) {
bootinfo.taskmap.tasks[bootinfo.taskmap.count].addr = (void *) (pages << PAGE_WIDTH);
bootinfo.taskmap.tasks[bootinfo.taskmap.count].size = components[i].size;
bootinfo.taskmap.count++;
}
}
pages += component_pages;
}
fix_overlap(&real_mode, &real_mode_pa, "Bootstrap trampoline", &top);
fix_overlap(&trans, &trans_pa, "Translation table", &top);
fix_overlap(&bootinfo, &bootinfo_pa, "Boot info", &top);
fix_overlap(&real_mode, &real_mode_pa, "bootstrap trampoline", &top);
fix_overlap(&trans, &trans_pa, "translation table", &top);
fix_overlap(&bootinfo, &bootinfo_pa, "boot info", &top);
printf("\nBooting the kernel...\n");
jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, pages << PAGE_WIDTH, real_mode_pa);
jump_to_kernel(bootinfo_pa, sizeof(bootinfo), trans_pa, KERNEL_SIZE, fb, real_mode_pa);
}
/boot/trunk/arch/ppc64/loader/asm.h
33,7 → 33,7
#define PAGE_WIDTH 12
 
#define TRANS_SIZE 1024
#define TRANS_ITEM_SIZE 8
#define TRANS_ITEM_SIZE 4
 
#define KERNEL_START_ADDR 0x80004000
 
44,7 → 44,7
extern void *trans[TRANS_SIZE];
 
extern void halt();
extern void jump_to_kernel(void *bootinfo, unsigned long bootinfo_size, void *trans, unsigned long kernel_size, void *real_mode) __attribute__((noreturn));
extern void jump_to_kernel(void *bootinfo, unsigned long bootinfo_size, void *trans, unsigned long kernel_size, void *framebuffer, void *real_mode) __attribute__((noreturn));
extern void real_mode();
 
#endif
/boot/trunk/arch/ppc64/loader/_link.ld
0,0 → 1,28
/*
* PPC linker script
*
*/
 
OUTPUT_FORMAT("elf64-powerpc")
OUTPUT_ARCH("powerpc:common64")
ENTRY(start)
 
SECTIONS {
.boot 0x0000000010000000: AT (0) {
*(BOOTSTRAP);
*(REALMODE);
*(.text);
*(.rodata);
*(.rodata.*);
*(.data); /* initialized data */
*(.sdata);
*(.sdata2);
*(.sbss);
*(.bss); /* uninitialized static variables */
*(COMMON); /* global variables */
. = ALIGN(4096);
*(.image);
}
}
/boot/trunk/arch/ppc64/loader/main.h
38,24 → 38,13
*/
#define ALIGN_UP(addr, align) (((addr) + ((align) - 1)) & ~((align) - 1))
 
#define TASKMAP_MAX_RECORDS 32
 
typedef struct {
void *addr;
unsigned long size;
} task_t;
 
typedef struct {
unsigned int count;
task_t tasks[TASKMAP_MAX_RECORDS];
} taskmap_t;
 
typedef struct {
taskmap_t taskmap;
memmap_t memmap;
screen_t screen;
} bootinfo_t;
 
extern long _binary_____________kernel_kernel_bin_start;
extern long _binary_____________kernel_kernel_bin_end;
extern void start(void);
extern void bootstrap(void);
 
/boot/trunk/arch/ppc64/loader/ofw.c
33,9 → 33,9
#define MAX_OFW_ARGS 10
#define BUF_SIZE 1024
 
typedef unsigned int ofw_arg_t;
typedef unsigned int ihandle;
typedef unsigned int phandle;
typedef unsigned long ofw_arg_t;
typedef unsigned long ihandle;
typedef unsigned long phandle;
 
/** OpenFirmware command structure
*
42,8 → 42,8
*/
typedef struct {
const char *service; /**< Command name */
unsigned int nargs; /**< Number of in arguments */
unsigned int nret; /**< Number of out arguments */
unsigned long nargs; /**< Number of in arguments */
unsigned long nret; /**< Number of out arguments */
ofw_arg_t args[MAX_OFW_ARGS]; /**< List of arguments */
} ofw_args_t;
 
60,11 → 60,11
phandle ofw_aliases;
 
 
static int ofw_call(const char *service, const int nargs, const int nret, ofw_arg_t *rets, ...)
static long ofw_call(const char *service, const long nargs, const long nret, ofw_arg_t *rets, ...)
{
va_list list;
ofw_args_t args;
int i;
long i;
args.service = service;
args.nargs = nargs;
93,15 → 93,15
}
 
 
static int ofw_get_property(const phandle device, const char *name, const void *buf, const int buflen)
static long ofw_get_property(const phandle device, const char *name, const void *buf, const long buflen)
{
return ofw_call("getprop", 4, 1, NULL, device, name, buf, buflen);
}
 
 
static unsigned int ofw_get_address_cells(const phandle device)
static unsigned long ofw_get_address_cells(const phandle device)
{
unsigned int ret;
unsigned long ret;
if (ofw_get_property(device, "#address-cells", &ret, sizeof(ret)) <= 0)
if (ofw_get_property(ofw_root, "#address-cells", &ret, sizeof(ret)) <= 0)
111,9 → 111,9
}
 
 
static unsigned int ofw_get_size_cells(const phandle device)
static unsigned long ofw_get_size_cells(const phandle device)
{
unsigned int ret;
unsigned long ret;
if (ofw_get_property(device, "#size-cells", &ret, sizeof(ret)) <= 0)
if (ofw_get_property(ofw_root, "#size-cells", &ret, sizeof(ret)) <= 0)
184,28 → 184,28
}
 
 
int ofw_map(const void *phys, const void *virt, const int size, const int mode)
long ofw_map(const void *phys, const void *virt, const long size, const long mode)
{
return ofw_call("call-method", 6, 1, NULL, "map", ofw_mmu, mode, size, virt, phys);
}
 
 
int ofw_memmap(memmap_t *map)
long ofw_memmap(memmap_t *map)
{
unsigned int buf[BUF_SIZE];
int ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned int) * BUF_SIZE);
unsigned long buf[BUF_SIZE];
long ret = ofw_get_property(ofw_memory, "reg", buf, sizeof(unsigned long) * BUF_SIZE);
if (ret <= 0)
return false;
unsigned int ac = ofw_get_address_cells(ofw_memory);
unsigned int sc = ofw_get_size_cells(ofw_memory);
unsigned long ac = ofw_get_address_cells(ofw_memory);
unsigned long sc = ofw_get_size_cells(ofw_memory);
int pos;
long pos;
map->total = 0;
map->count = 0;
for (pos = 0; (pos < ret / sizeof(unsigned int)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
for (pos = 0; (pos < ret / sizeof(unsigned long)) && (map->count < MEMMAP_MAX_RECORDS); pos += ac + sc) {
void * start = (void *) buf[pos + ac - 1];
unsigned int size = buf[pos + ac + sc - 1];
unsigned long size = buf[pos + ac + sc - 1];
if (size > 0) {
map->zones[map->count].start = start;
217,7 → 217,7
}
 
 
int ofw_screen(screen_t *screen)
long ofw_screen(screen_t *screen)
{
char device_name[BUF_SIZE];
/boot/trunk/arch/ppc64/loader/Makefile
30,7 → 30,7
#
 
TARGET = ppc-linux-gnu
TOOLCHAIN_DIR = /usr/local/ppc64/bin
TOOLCHAIN_DIR = /usr/local/ppc/bin
 
ifeq ($(COMPILER),native)
CC = gcc
46,7 → 46,7
OBJDUMP = $(TOOLCHAIN_DIR)/$(TARGET)-objdump
endif
 
CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc64 -msoft-float -m64
CFLAGS = -nostdinc -nostdlib -fno-builtin -Werror-implicit-function-declaration -Wmissing-prototypes -Werror -O3 -mcpu=powerpc64 -m64
DEFS =
 
SOURCES = \
56,14 → 56,7
asm.S \
boot.S
 
COMPONENTS = \
$(KERNELDIR)/kernel.bin \
$(USPACEDIR)/ns/ns \
$(USPACEDIR)/init/init \
$(USPACEDIR)/fb/fb
 
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
 
.PHONY: all clean depend
 
71,17 → 64,17
 
-include Makefile.depend
 
image.boot: depend _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) kernel.o
$(LD) -no-check-sections -N -T _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) -o $@
image.boot: depend $(OBJECTS) kernel.o
$(LD) -no-check-sections -N -T _link.ld $(OBJECTS) kernel.o -o $@
 
depend:
-makedepend $(DEFS) $(CFLAGS) -f - $(SOURCES) > Makefile.depend 2> /dev/null
 
clean:
-rm -f _components.h _link.ld $(COMPONENT_OBJECTS) $(OBJECTS) image.boot Makefile.depend
-rm -f $(OBJECTS) image.boot kernel.o Makefile.depend
 
_components.h _link.ld $(COMPONENT_OBJECTS): $(COMPONENTS)
./pack $(OBJCOPY) $(COMPONENTS)
kernel.o: $(KERNEL)
$(OBJCOPY) -I binary -O elf64-powerpc -B powerpc --rename-section .data=.image $(KERNEL) $@
 
%.o: %.S
$(CC) $(DEFS) $(CFLAGS) -D__ASM__ -c $< -o $@
/boot/trunk/arch/ppc64/loader/boot.S
28,7 → 28,7
 
#include "regname.h"
 
.section BOOTSTRAP, "ax"
.section BOOTSTRAP
 
.global start
 
/boot/trunk/arch/ppc64/loader/regname.h
26,8 → 26,8
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
#ifndef __ppc32_REGNAME_H__
#define __ppc32_REGNAME_H__
#ifndef __ppc64_REGNAME_H__
#define __ppc64_REGNAME_H__
 
/* Condition Register Bit Fields */
#define cr0 0
189,6 → 189,22
#define sprg2 274
#define sprg3 275
#define prv 287
#define ibat0u 528
#define ibat0l 529
#define ibat1u 530
#define ibat1l 531
#define ibat2u 532
#define ibat2l 533
#define ibat3u 534
#define ibat3l 535
#define dbat0u 536
#define dbat0l 537
#define dbat1u 538
#define dbat1l 539
#define dbat2u 540
#define dbat2l 541
#define dbat3u 542
#define dbat3l 543
#define hid0 1008
 
/* MSR bits */
/boot/trunk/arch/ppc64/Makefile.inc
28,12 → 28,12
 
build: image.boot
 
image.boot: kernel uspace
make -C arch/$(ARCH)/loader COMPILER=$(COMPILER) KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
image.boot: kernel
make -C arch/$(ARCH)/loader COMPILER=$(COMPILER) KERNEL=../../../$(KERNELDIR)/kernel.bin
cp arch/$(ARCH)/loader/image.boot image.boot
 
clean: clean_kernel clean_uspace
make -C arch/$(ARCH)/loader clean KERNELDIR=../../../$(KERNELDIR) USPACEDIR=../../../$(USPACEDIR)
clean: clean_kernel
make -C arch/$(ARCH)/loader clean
-rm -f image.boot
 
arch_distclean: distclean_kernel distclean_uspace
arch_distclean: distclean_kernel