diff options
author | 2015-08-28 09:58:54 +0800 | |
---|---|---|
committer | 2015-09-01 12:44:00 +0800 | |
commit | e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch) | |
tree | 66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/openbios/arch | |
parent | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff) |
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/openbios/arch')
210 files changed, 30814 insertions, 0 deletions
diff --git a/qemu/roms/openbios/arch/amd64/Kconfig b/qemu/roms/openbios/arch/amd64/Kconfig new file mode 100644 index 000000000..f1f677dba --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/Kconfig @@ -0,0 +1,48 @@ +mainmenu "OpenBIOS Configuration" + +config AMD64 + bool + default y + help + Building for AMD64 hardware. + +config LITTLE_ENDIAN + bool + default y + help + AMD64 is little endian. + + +menu "Kernel binaries (AMD64)" + +config IMAGE_ELF + bool "ELF image (for LinuxBIOS)" + default y + help + Build a simple elf image that can be used with LinuxBIOS + This image will be called openbios.elf + +config IMAGE_ELF_EMBEDDED + bool "ELF image with embedded dictionary" + default y + help + Build an elf image with embedded dictionary. This image + can easily be used with etherboot. + The image filename is openbios.full + +config IMAGE_ELF_MULTIBOOT + bool "Multiboot image" + default y + help + Build a multiboot image for booting with grub + +endmenu + +menu "Build hosted UNIX Binary" +source "arch/unix/Kconfig" +endmenu + +source "kernel/Kconfig" +source "forth/Kconfig" +source "libopenbios/Kconfig" +source "drivers/Kconfig" diff --git a/qemu/roms/openbios/arch/amd64/boot.c b/qemu/roms/openbios/arch/amd64/boot.c new file mode 100644 index 000000000..0e1fe7efd --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/boot.c @@ -0,0 +1,41 @@ +/* + * + */ +#undef BOOTSTRAP +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elfload.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libopenbios/sys_info.h" + +int elf_load(struct sys_info *, const char *filename, const char *cmdline); +int linux_load(struct sys_info *, const char *filename, const char *cmdline); + +void boot(void); + +void boot(void) +{ + char *path=pop_fstr_copy(), *param; + + // char *param="root=/dev/hda2 console=ttyS0,115200n8 console=tty0"; + + if(!path) { + printk("[x86] Booting default not supported.\n"); + return; + } + + param = strchr(path, ' '); + if(param) { + *param = '\0'; + param++; + } + + printk("[x86] Booting file '%s' with parameters '%s'\n",path, param); + + if (elf_load(&sys_info, path, param) == LOADER_NOT_SUPPORT) + if (linux_load(&sys_info, path, param) == LOADER_NOT_SUPPORT) + printk("Unsupported image format\n"); + + free(path); +} diff --git a/qemu/roms/openbios/arch/amd64/build.xml b/qemu/roms/openbios/arch/amd64/build.xml new file mode 100644 index 000000000..8f436d001 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/build.xml @@ -0,0 +1,6 @@ +<build condition="AMD64"> + <dictionary name="openbios-amd64" init="openbios" target="forth"> + <object source="init.fs"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA" /> + </dictionary> +</build> diff --git a/qemu/roms/openbios/arch/amd64/builtin.c b/qemu/roms/openbios/arch/amd64/builtin.c new file mode 100644 index 000000000..93ced0ae3 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/builtin.c @@ -0,0 +1,25 @@ +/* tag: openbios forth starter for builtin dictionary for amd64 + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include <asm/types.h> +#include "libopenbios/sys_info.h" + +/* + * wrap an array around the hex'ed dictionary file + */ + +#include "static-dict.h" + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)forth_dictionary; + info->dict_end=(unsigned long *)((ucell)forth_dictionary + + sizeof(forth_dictionary)); +} diff --git a/qemu/roms/openbios/arch/amd64/console.c b/qemu/roms/openbios/arch/amd64/console.c new file mode 100644 index 000000000..71a22b681 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/console.c @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "openbios.h" + +#ifdef CONFIG_DEBUG_CONSOLE + +/* ****************************************************************** + * serial console functions + * ****************************************************************** */ + +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + +#define RBR(x) x==2?0x2f8:0x3f8 +#define THR(x) x==2?0x2f8:0x3f8 +#define IER(x) x==2?0x2f9:0x3f9 +#define IIR(x) x==2?0x2fa:0x3fa +#define LCR(x) x==2?0x2fb:0x3fb +#define MCR(x) x==2?0x2fc:0x3fc +#define LSR(x) x==2?0x2fd:0x3fd +#define MSR(x) x==2?0x2fe:0x3fe +#define SCR(x) x==2?0x2ff:0x3ff +#define DLL(x) x==2?0x2f8:0x3f8 +#define DLM(x) x==2?0x2f9:0x3f9 + +static int uart_charav(int port) +{ + if (!port) + return -1; + return ((inb(LSR(port)) & 1) != 0); +} + +static char uart_getchar(int port) +{ + if (!port) + return -1; + while (!uart_charav(port)); + return ((char) inb(RBR(port)) & 0177); +} + +static void uart_putchar(int port, unsigned char c) +{ + if (!port) + return; + if (c == '\n') + uart_putchar(port, '\r'); + while (!(inb(LSR(port)) & 0x20)); + outb(c, THR(port)); +} + +static void uart_init_line(int port, unsigned long baud) +{ + int i, baudconst; + + if (!port) + return; + + switch (baud) { + case 115200: + baudconst = 1; + break; + case 57600: + baudconst = 2; + break; + case 38400: + baudconst = 3; + break; + case 19200: + baudconst = 6; + break; + case 9600: + default: + baudconst = 12; + break; + } + + outb(0x87, LCR(port)); + outb(0x00, DLM(port)); + outb(baudconst, DLL(port)); + outb(0x07, LCR(port)); + outb(0x0f, MCR(port)); + + for (i = 10; i > 0; i--) { + if (inb(LSR(port)) == (unsigned int) 0) + break; + inb(RBR(port)); + } +} + +int uart_init(int port, unsigned long speed) +{ + if (port) + uart_init_line(port, speed); + return -1; +} + +static void serial_putchar(int c) +{ + uart_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff)); +} + +static void serial_cls(void) +{ + serial_putchar(27); + serial_putchar('['); + serial_putchar('H'); + serial_putchar(27); + serial_putchar('['); + serial_putchar('J'); +} + +#endif + +/* ****************************************************************** + * simple polling video/keyboard console functions + * ****************************************************************** */ + +#ifdef CONFIG_DEBUG_CONSOLE_VGA + +/* raw vga text mode */ +#define COLUMNS 80 /* The number of columns. */ +#define LINES 25 /* The number of lines. */ +#define ATTRIBUTE 7 /* The attribute of an character. */ + +#define VGA_BASE 0xB8000 /* The video memory address. */ + +/* VGA Index and Data Registers */ +#define VGA_REG_INDEX 0x03D4 /* VGA index register */ +#define VGA_REG_DATA 0x03D5 /* VGA data register */ + +#define VGA_IDX_CURMSL 0x09 /* cursor maximum scan line */ +#define VGA_IDX_CURSTART 0x0A /* cursor start */ +#define VGA_IDX_CUREND 0x0B /* cursor end */ +#define VGA_IDX_CURLO 0x0F /* cursor position (low 8 bits) */ +#define VGA_IDX_CURHI 0x0E /* cursor position (high 8 bits) */ + +/* Save the X and Y position. */ +static int xpos, ypos; +/* Point to the video memory. */ +static volatile unsigned char *video = (unsigned char *) VGA_BASE; + +static void video_initcursor(void) +{ + u8 val; + outb(VGA_IDX_CURMSL, VGA_REG_INDEX); + val = inb(VGA_REG_DATA) & 0x1f; /* maximum scan line -1 */ + + outb(VGA_IDX_CURSTART, VGA_REG_INDEX); + outb(0, VGA_REG_DATA); + + outb(VGA_IDX_CUREND, VGA_REG_INDEX); + outb(val, VGA_REG_DATA); +} + + + +static void video_poscursor(unsigned int x, unsigned int y) +{ + unsigned short pos; + + /* Calculate new cursor position as a function of x and y */ + pos = (y * COLUMNS) + x; + + /* Output the new position to VGA card */ + outb(VGA_IDX_CURLO, VGA_REG_INDEX); /* output low 8 bits */ + outb((u8) (pos), VGA_REG_DATA); + outb(VGA_IDX_CURHI, VGA_REG_INDEX); /* output high 8 bits */ + outb((u8) (pos >> 8), VGA_REG_DATA); + +}; + + +static void video_newline(void) +{ + xpos = 0; + + if (ypos < LINES - 1) { + ypos++; + } else { + int i; + memmove((void *) video, (void *) (video + 2 * COLUMNS), + (LINES - 1) * COLUMNS * 2); + + for (i = ((LINES - 1) * 2 * COLUMNS); + i < 2 * COLUMNS * LINES;) { + video[i++] = 0; + video[i++] = ATTRIBUTE; + } + } + +} + +/* Put the character C on the screen. */ +static void video_putchar(int c) +{ + int p=1; + + if (c == '\n' || c == '\r') { + video_newline(); + return; + } + + if (c == '\b') { + if (xpos) xpos--; + c=' '; + p=0; + } + + + if (xpos >= COLUMNS) + video_newline(); + + *(video + (xpos + ypos * COLUMNS) * 2) = c & 0xFF; + *(video + (xpos + ypos * COLUMNS) * 2 + 1) = ATTRIBUTE; + + if (p) + xpos++; + + video_poscursor(xpos, ypos); +} + +static void video_cls(void) +{ + int i; + + for (i = 0; i < 2 * COLUMNS * LINES;) { + video[i++] = 0; + video[i++] = ATTRIBUTE; + } + + + xpos = 0; + ypos = 0; + + video_initcursor(); + video_poscursor(xpos, ypos); +} + +void video_init(void) +{ + video=phys_to_virt((unsigned char*)VGA_BASE); +} + +/* + * keyboard driver + */ + +static char normal[] = { + 0x0, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', + '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', + 'p', '[', ']', 0xa, 0x0, 'a', 's', 'd', 'f', 'g', 'h', 'j', + 'k', 'l', ';', 0x27, 0x60, 0x0, 0x5c, 'z', 'x', 'c', 'v', 'b', + 'n', 'm', ',', '.', '/', 0x0, '*', 0x0, ' ', 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, '0', 0x7f +}; + +static char shifted[] = { + 0x0, 0x1b, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', + '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', + 'P', '{', '}', 0xa, 0x0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', + 'K', 'L', ':', 0x22, '~', 0x0, '|', 'Z', 'X', 'C', 'V', 'B', + 'N', 'M', '<', '>', '?', 0x0, '*', 0x0, ' ', 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, '7', '8', + '9', 0x0, '4', '5', '6', 0x0, '1', '2', '3', '0', 0x7f +}; + +static int key_ext; +static int key_lshift = 0, key_rshift = 0, key_caps = 0; + +static char last_key; + +static void keyboard_cmd(unsigned char cmd, unsigned char val) +{ + outb(cmd, 0x60); + /* wait until keyboard controller accepts cmds: */ + while (inb(0x64) & 2); + outb(val, 0x60); + while (inb(0x64) & 2); +} + +static char keyboard_poll(void) +{ + unsigned int c; + if (inb(0x64) & 1) { + c = inb(0x60); + switch (c) { + case 0xe0: + key_ext = 1; + return 0; + case 0x2a: + key_lshift = 1; + return 0; + case 0x36: + key_rshift = 1; + return 0; + case 0xaa: + key_lshift = 0; + return 0; + case 0xb6: + key_rshift = 0; + return 0; + case 0x3a: + if (key_caps) { + key_caps = 0; + keyboard_cmd(0xed, 0); + } else { + key_caps = 1; + keyboard_cmd(0xed, 4); /* set caps led */ + } + return 0; + } + + if (key_ext) { + // void printk(const char *format, ...); + printk("extended keycode: %x\n", c); + + key_ext = 0; + return 0; + } + + if (c & 0x80) /* unhandled key release */ + return 0; + + if (key_lshift || key_rshift) + return key_caps ? normal[c] : shifted[c]; + else + return key_caps ? shifted[c] : normal[c]; + } + return 0; +} + +static int keyboard_dataready(void) +{ + if (last_key) + return 1; + + last_key = keyboard_poll(); + + return (last_key != 0); +} + +static unsigned char keyboard_readdata(void) +{ + char tmp; + while (!keyboard_dataready()); + tmp = last_key; + last_key = 0; + return tmp; +} +#endif + + +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +int arch_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + serial_putchar(c); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + video_putchar(c); +#endif + return c; +} + +int arch_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (keyboard_dataready()) + return 1; +#endif + return 0; +} + +int arch_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return (uart_getchar(CONFIG_SERIAL_PORT)); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (keyboard_dataready()) + return (keyboard_readdata()); +#endif + return 0; +} + +void cls(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + serial_cls(); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + video_cls(); +#endif +} + +struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + +#endif // CONFIG_DEBUG_CONSOLE diff --git a/qemu/roms/openbios/arch/amd64/context.c b/qemu/roms/openbios/arch/amd64/context.c new file mode 100644 index 000000000..2e4df6a3d --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/context.c @@ -0,0 +1,124 @@ +/* + * context switching + * 2003-10 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "segment.h" +#include "context.h" + +#define MAIN_STACK_SIZE 16384 +#define IMAGE_STACK_SIZE 4096 + +#define debug printk + +static void start_main(void); /* forward decl. */ +void __exit_context(void); /* assembly routine */ + +/* + * Main context structure + * It is placed at the bottom of our stack, and loaded by assembly routine + * to start us up. + */ +struct context main_ctx __attribute__((section (".initctx"))) = { + .gdt_base = (uint64_t) gdt, + .gdt_limit = GDT_LIMIT, + .cs = FLAT_CS, + .ds = FLAT_DS, + .es = FLAT_DS, + .fs = FLAT_DS, + .gs = FLAT_DS, + .ss = FLAT_DS, + .esp = (uint32_t) ESP_LOC(&main_ctx), + .eip = (uint32_t) start_main, + .return_addr = (uint32_t) __exit_context, +}; + +/* This is used by assembly routine to load/store the context which + * it is to switch/switched. */ +struct context *__context = &main_ctx; + +/* Stack for loaded ELF image */ +static uint8_t image_stack[IMAGE_STACK_SIZE]; + +/* Pointer to startup context (physical address) */ +unsigned long __boot_ctx; + +/* + * Main starter + * This is the C function that runs first. + */ +static void start_main(void) +{ + int retval; + extern int openbios(void); + + /* Save startup context, so we can refer to it later. + * We have to keep it in physical address since we will relocate. */ + __boot_ctx = virt_to_phys(__context); + + /* Start the real fun */ + retval = openbios(); + + /* Pass return value to startup context. Bootloader may see it. */ + boot_ctx->eax = retval; + + /* Returning from here should jump to __exit_context */ + __context = boot_ctx; +} + +/* Setup a new context using the given stack. + */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_params) +{ + struct context *ctx; + + ctx = (struct context *) + (stack + stack_size - (sizeof(*ctx) + num_params*sizeof(uint32_t))); + memset(ctx, 0, sizeof(*ctx)); + + /* Fill in reasonable default for flat memory model */ + ctx->gdt_base = virt_to_phys(gdt); + ctx->gdt_limit = GDT_LIMIT; + ctx->cs = FLAT_CS; + ctx->ds = FLAT_DS; + ctx->es = FLAT_DS; + ctx->fs = FLAT_DS; + ctx->gs = FLAT_DS; + ctx->ss = FLAT_DS; + ctx->esp = virt_to_phys(ESP_LOC(ctx)); + ctx->return_addr = virt_to_phys(__exit_context); + + return ctx; +} + +/* Switch to another context. */ +struct context *switch_to(struct context *ctx) +{ + struct context *save, *ret; + + debug("switching to new context:\n"); + save = __context; + __context = ctx; + asm ("pushl %cs; call __switch_context"); + ret = __context; + __context = save; + return ret; +} + +/* Start ELF Boot image */ +uint32_t start_elf(uint32_t entry_point, uint32_t param) +{ + struct context *ctx; + + ctx = init_context(image_stack, sizeof image_stack, 1); + ctx->eip = entry_point; + ctx->param[0] = param; + ctx->eax = 0xe1fb007; + ctx->ebx = param; + + ctx = switch_to(ctx); + return ctx->eax; +} diff --git a/qemu/roms/openbios/arch/amd64/context.h b/qemu/roms/openbios/arch/amd64/context.h new file mode 100644 index 000000000..4c3832efb --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/context.h @@ -0,0 +1,48 @@ +#ifndef AMD64_CONTEXT_H +#define AMD64_CONTEXT_H + +struct context { + /* Stack Segment, placed here because of the alignment issue... */ + uint16_t ss; + /* Used with sgdt/lgdt */ + uint16_t gdt_limit; + uint64_t gdt_base; + /* General registers, accessed with pushal/popal */ + uint32_t edi; + uint32_t esi; + uint32_t ebp; + uint32_t esp; /* points just below eax */ + uint32_t ebx; + uint32_t edx; + uint32_t ecx; + uint32_t eax; +#define ESP_LOC(ctx) (&(ctx)->gs) + /* Segment registers */ + uint32_t gs; + uint32_t fs; + uint32_t es; + uint32_t ds; + /* Flags */ + uint32_t eflags; + /* Code segment:offset */ + uint32_t eip; + uint32_t cs; + /* Optional stack contents */ + uint32_t return_addr; + uint32_t param[0]; +}; + +/* Create a new context in the given stack */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_param); + +/* Switch context */ +struct context *switch_to(struct context *); + +/* Holds physical address of boot context */ +extern unsigned long __boot_ctx; + +/* This can always be safely used to refer to the boot context */ +#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx)) + +#endif /* AMD64_CONTEXT_H */ diff --git a/qemu/roms/openbios/arch/amd64/defconfig b/qemu/roms/openbios/arch/amd64/defconfig new file mode 100644 index 000000000..570a6c869 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/defconfig @@ -0,0 +1,65 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_AMD64=y +CONFIG_LITTLE_ENDIAN=y + +# +# Kernel binaries (AMD64) +# +# CONFIG_IMAGE_ELF is not set +# CONFIG_IMAGE_ELF_EMBEDDED is not set +# CONFIG_IMAGE_ELF_MULTIBOOT is not set + +# +# Build hosted UNIX Binary +# +CONFIG_HOST_UNIX=y +# CONFIG_PLUGIN_PCI is not set + +# +# Kernel Debugging +# +# CONFIG_DEBUG is not set +CONFIG_DEBUG_CONSOLE=y +CONFIG_DEBUG_CONSOLE_SERIAL=y +CONFIG_SERIAL_PORT=1 +CONFIG_SERIAL_SPEED=115200 +CONFIG_DEBUG_CONSOLE_VGA=y + +# +# Module Configuration +# +CONFIG_CMDLINE=y +CONFIG_DEBLOCKER=y + +# +# Filesystem Configuration +# +CONFIG_DISK_LABEL=y +CONFIG_PART_SUPPORT=y +CONFIG_PC_PARTS=y +CONFIG_FS=y +CONFIG_GRUBFS=y +CONFIG_FSYS_EXT2FS=y +CONFIG_FSYS_FAT=y +CONFIG_FSYS_JFS=y +# CONFIG_FSYS_MINIX is not set +CONFIG_FSYS_REISERFS=y +CONFIG_FSYS_XFS=y +CONFIG_FSYS_ISO9660=y +# CONFIG_FSYS_FFS is not set +# CONFIG_FSYS_VSTAFS is not set +# CONFIG_DEBUG_FS is not set + +# +# Miscellaneous +# +CONFIG_LINUXBIOS=y + +# +# Drivers +# +CONFIG_DRIVER_PCI=y +CONFIG_DRIVER_IDE=y +# CONFIG_DEBUG_IDE is not set diff --git a/qemu/roms/openbios/arch/amd64/init.fs b/qemu/roms/openbios/arch/amd64/init.fs new file mode 100644 index 000000000..fda3acdc8 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/init.fs @@ -0,0 +1,83 @@ +include config.fs + +:noname + ." Type 'help' for detailed information" cr + \ ." boot secondary slave cdrom: " cr + \ ." 0 > boot hd:2,\boot\vmlinuz root=/dev/hda2" cr + ; DIAG-initializer + +" /" find-device + +new-device + " memory" device-name + \ 12230 encode-int " reg" property + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " cpus" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +finish-device + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +:noname + set-defaults +; SYSTEM-initializer + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /cpus/@0" preopen + " stdout" " /builtin/console" preopen + " stdin" " /builtin/console" preopen + +; SYSTEM-initializer + +\ use the tty interface if available +:noname + " /builtin/console" find-dev if drop + " /builtin/console" " input-device" $setenv + " /builtin/console" " output-device" $setenv + then +; SYSTEM-initializer + +:noname + " keyboard" input +; CONSOLE-IN-initializer + +\ Load VGA FCode driver blob +[IFDEF] CONFIG_DRIVER_VGA + -1 value vga-driver-fcode + " QEMU,VGA.bin" $encode-file to vga-driver-fcode +[THEN] diff --git a/qemu/roms/openbios/arch/amd64/ldscript b/qemu/roms/openbios/arch/amd64/ldscript new file mode 100644 index 000000000..8976c7af0 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/ldscript @@ -0,0 +1,73 @@ +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386) + +ENTRY(entry) + +/* Initial load address + * To be loaded by GRUB, this must be >= 1MB + */ +BASE_ADDR = 0x100000; + +/* 16KB heap and stack */ +HEAP_SIZE = 16384; +STACK_SIZE = 16384; + +SECTIONS +{ + . = BASE_ADDR; + + /* Put Multiboot header near beginning of file, if any. */ + .hdr : { *(.hdr) *(.hdr.*) } + + /* Start of the program. + * Now the version string is in the note, we must include it + * in the program. Otherwise we lose the string after relocation. */ + . = ALIGN(16); + _start = .; + + /* Putting ELF notes near beginning of file might help bootloaders. + * We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + .note : { *(.note.ELFBoot) } + + /* Normal sections */ + .text : { *(.text) *(.text.*) } + .rodata : { + . = ALIGN(4); + sound_drivers_start = .; + *(.rodata.sound_drivers) + sound_drivers_end = .; + *(.rodata) + *(.rodata.*) + } + .data : { *(.data) *(.data.*) } + + .bss : { + *(.bss) + *(.bss.*) + *(COMMON) + + /* Put heap and stack here, so they are included in PT_LOAD segment + * and the bootloader is aware of it. */ + + . = ALIGN(16); + _heap = .; + . += HEAP_SIZE; + . = ALIGN(16); + _eheap = .; + + _stack = .; + . += STACK_SIZE; + . = ALIGN(16); + _estack = .; + } + + .initctx : { + /* Initial contents of stack. This MUST BE just after the stack. */ + *(.initctx) + } + + _end = .; + + /DISCARD/ : { *(.comment) *(.note) } +} diff --git a/qemu/roms/openbios/arch/amd64/lib.c b/qemu/roms/openbios/arch/amd64/lib.c new file mode 100644 index 000000000..f04458e1a --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/lib.c @@ -0,0 +1,56 @@ +/* lib.c + * tag: simple function library + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "asm/types.h" +#include <stdarg.h> +#include "libc/stdlib.h" +#include "libc/vsprintf.h" +#include "kernel/kernel.h" + +/* Format a string and print it on the screen, just like the libc + * function printf. + */ +int printk( const char *fmt, ... ) +{ + char *p, buf[512]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) + putchar(*p); + return i; +} + +// dumb quick memory allocator until we get a decent thing here. + +#define MEMSIZE 128*1024 +static char memory[MEMSIZE]; +static void *memptr=memory; +static int memsize=MEMSIZE; + +void *malloc(int size) +{ + void *ret=(void *)0; + if(memsize>=size) { + memsize-=size; + ret=memptr; + memptr+=size; + } + return ret; +} + +void free(void *ptr) +{ + /* Nothing yet */ +} diff --git a/qemu/roms/openbios/arch/amd64/linux_load.c b/qemu/roms/openbios/arch/amd64/linux_load.c new file mode 100644 index 000000000..f1ed98df1 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/linux_load.c @@ -0,0 +1,647 @@ +/* + * Linux/i386 loader + * Supports bzImage, zImage and Image format. + * + * Based on work by Steve Gehlbach. + * Portions are taken from mkelfImage. + * + * 2003-09 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "segment.h" +#include "loadfs.h" + +#define printf printk +#define debug printk +#define strtoull_with_suffix strtol + +#define LINUX_PARAM_LOC 0x90000 +#define COMMAND_LINE_LOC 0x91000 +#define GDT_LOC 0x92000 +#define STACK_LOC 0x93000 + +#define E820MAX 32 /* number of entries in E820MAP */ +struct e820entry { + unsigned long long addr; /* start of memory segment */ + unsigned long long size; /* size of memory segment */ + unsigned long type; /* type of memory segment */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */ +#define E820_NVS 4 +}; + +/* The header of Linux/i386 kernel */ +struct linux_header { + uint8_t reserved1[0x1f1]; /* 0x000 */ + uint8_t setup_sects; /* 0x1f1 */ + uint16_t root_flags; /* 0x1f2 */ + uint8_t reserved2[6]; /* 0x1f4 */ + uint16_t vid_mode; /* 0x1fa */ + uint16_t root_dev; /* 0x1fc */ + uint16_t boot_sector_magic; /* 0x1fe */ + /* 2.00+ */ + uint8_t reserved3[2]; /* 0x200 */ + uint8_t header_magic[4]; /* 0x202 */ + uint16_t protocol_version; /* 0x206 */ + uint32_t realmode_swtch; /* 0x208 */ + uint16_t start_sys; /* 0x20c */ + uint16_t kver_addr; /* 0x20e */ + uint8_t type_of_loader; /* 0x210 */ + uint8_t loadflags; /* 0x211 */ + uint16_t setup_move_size; /* 0x212 */ + uint32_t code32_start; /* 0x214 */ + uint32_t ramdisk_image; /* 0x218 */ + uint32_t ramdisk_size; /* 0x21c */ + uint8_t reserved4[4]; /* 0x220 */ + /* 2.01+ */ + uint16_t heap_end_ptr; /* 0x224 */ + uint8_t reserved5[2]; /* 0x226 */ + /* 2.02+ */ + uint32_t cmd_line_ptr; /* 0x228 */ + /* 2.03+ */ + uint32_t initrd_addr_max; /* 0x22c */ +} __attribute__ ((packed)); + + +/* Paramters passed to 32-bit part of Linux + * This is another view of the structure above.. */ +struct linux_params { + uint8_t orig_x; /* 0x00 */ + uint8_t orig_y; /* 0x01 */ + uint16_t ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */ + uint16_t orig_video_page; /* 0x04 */ + uint8_t orig_video_mode; /* 0x06 */ + uint8_t orig_video_cols; /* 0x07 */ + uint16_t unused2; /* 0x08 */ + uint16_t orig_video_ega_bx; /* 0x0a */ + uint16_t unused3; /* 0x0c */ + uint8_t orig_video_lines; /* 0x0e */ + uint8_t orig_video_isVGA; /* 0x0f */ + uint16_t orig_video_points; /* 0x10 */ + + /* VESA graphic mode -- linear frame buffer */ + uint16_t lfb_width; /* 0x12 */ + uint16_t lfb_height; /* 0x14 */ + uint16_t lfb_depth; /* 0x16 */ + uint32_t lfb_base; /* 0x18 */ + uint32_t lfb_size; /* 0x1c */ + uint16_t cl_magic; /* 0x20 */ +#define CL_MAGIC_VALUE 0xA33F + uint16_t cl_offset; /* 0x22 */ + uint16_t lfb_linelength; /* 0x24 */ + uint8_t red_size; /* 0x26 */ + uint8_t red_pos; /* 0x27 */ + uint8_t green_size; /* 0x28 */ + uint8_t green_pos; /* 0x29 */ + uint8_t blue_size; /* 0x2a */ + uint8_t blue_pos; /* 0x2b */ + uint8_t rsvd_size; /* 0x2c */ + uint8_t rsvd_pos; /* 0x2d */ + uint16_t vesapm_seg; /* 0x2e */ + uint16_t vesapm_off; /* 0x30 */ + uint16_t pages; /* 0x32 */ + uint8_t reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */ + + //struct apm_bios_info apm_bios_info; /* 0x40 */ + uint8_t apm_bios_info[0x40]; + //struct drive_info_struct drive_info; /* 0x80 */ + uint8_t drive_info[0x20]; + //struct sys_desc_table sys_desc_table; /* 0xa0 */ + uint8_t sys_desc_table[0x140]; + uint32_t alt_mem_k; /* 0x1e0 */ + uint8_t reserved5[4]; /* 0x1e4 */ + uint8_t e820_map_nr; /* 0x1e8 */ + uint8_t reserved6[9]; /* 0x1e9 */ + uint16_t mount_root_rdonly; /* 0x1f2 */ + uint8_t reserved7[4]; /* 0x1f4 */ + uint16_t ramdisk_flags; /* 0x1f8 */ +#define RAMDISK_IMAGE_START_MASK 0x07FF +#define RAMDISK_PROMPT_FLAG 0x8000 +#define RAMDISK_LOAD_FLAG 0x4000 + uint8_t reserved8[2]; /* 0x1fa */ + uint16_t orig_root_dev; /* 0x1fc */ + uint8_t reserved9[1]; /* 0x1fe */ + uint8_t aux_device_info; /* 0x1ff */ + uint8_t reserved10[2]; /* 0x200 */ + uint8_t param_block_signature[4]; /* 0x202 */ + uint16_t param_block_version; /* 0x206 */ + uint8_t reserved11[8]; /* 0x208 */ + uint8_t loader_type; /* 0x210 */ +#define LOADER_TYPE_LOADLIN 1 +#define LOADER_TYPE_BOOTSECT_LOADER 2 +#define LOADER_TYPE_SYSLINUX 3 +#define LOADER_TYPE_ETHERBOOT 4 +#define LOADER_TYPE_KERNEL 5 + uint8_t loader_flags; /* 0x211 */ + uint8_t reserved12[2]; /* 0x212 */ + uint32_t kernel_start; /* 0x214 */ + uint32_t initrd_start; /* 0x218 */ + uint32_t initrd_size; /* 0x21c */ + uint8_t reserved12_5[8]; /* 0x220 */ + uint32_t cmd_line_ptr; /* 0x228 */ + uint8_t reserved13[164]; /* 0x22c */ + struct e820entry e820_map[E820MAX]; /* 0x2d0 */ + uint8_t reserved16[688]; /* 0x550 */ +#define COMMAND_LINE_SIZE 256 + /* Command line is copied here by 32-bit i386/kernel/head.S. + * So I will follow the boot protocol, rather than putting it + * directly here. --ts1 */ + uint8_t command_line[COMMAND_LINE_SIZE]; /* 0x800 */ + uint8_t reserved17[1792]; /* 0x900 - 0x1000 */ +}; + +uint64_t forced_memsize; + +/* Load the first part the file and check if it's Linux */ +static uint32_t load_linux_header(struct linux_header *hdr) +{ + int load_high; + uint32_t kern_addr; + + if (lfile_read(hdr, sizeof *hdr) != sizeof *hdr) { + debug("Can't read Linux header\n"); + return 0; + } + if (hdr->boot_sector_magic != 0xaa55) { + debug("Not a Linux kernel image\n"); + return 0; + } + + /* Linux is found. Print some information */ + if (memcmp(hdr->header_magic, "HdrS", 4) != 0) { + /* This may be floppy disk image or something. + * Perform a simple (incomplete) sanity check. */ + if (hdr->setup_sects >= 16 + || file_size() - (hdr->setup_sects<<9) >= 512<<10) { + debug("This looks like a bootdisk image but not like Linux...\n"); + return 0; + } + + printf("Possible very old Linux"); + /* This kernel does not even have a protocol version. + * Force the value. */ + hdr->protocol_version = 0; /* pre-2.00 */ + } else + printf("Found Linux"); + if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { + char kver[256]; + file_seek(hdr->kver_addr + 0x200); + if (lfile_read(kver, sizeof kver) != 0) { + kver[255] = 0; + printf(" version %s", kver); + } + } + debug(" (protocol %#x)", hdr->protocol_version); + load_high = 0; + if (hdr->protocol_version >= 0x200) { + debug(" (loadflags %#x)", hdr->loadflags); + load_high = hdr->loadflags & 1; + } + if (load_high) { + printf(" bzImage"); + kern_addr = 0x100000; + } else { + printf(" zImage or Image"); + kern_addr = 0x1000; + } + printf(".\n"); + + return kern_addr; +} + +/* Set up parameters for 32-bit kernel */ +static void +init_linux_params(struct linux_params *params, struct linux_header *hdr) +{ + debug("Setting up paramters at %#lx\n", virt_to_phys(params)); + memset(params, 0, sizeof *params); + + /* Copy some useful values from header */ + params->mount_root_rdonly = hdr->root_flags; + params->orig_root_dev = hdr->root_dev; + + /* Video parameters. + * This assumes we have VGA in standard 80x25 text mode, + * just like our vga.c does. + * Cursor position is filled later to allow some more printf's. */ + params->orig_video_mode = 3; + params->orig_video_cols = 80; + params->orig_video_lines = 25; + params->orig_video_isVGA = 1; + params->orig_video_points = 16; + + params->loader_type = 0xff; /* Unregistered Linux loader */ +} + +/* Memory map */ +static void +set_memory_size(struct linux_params *params, struct sys_info *info) +{ + int i; + uint64_t end; + uint32_t ramtop = 0; + struct e820entry *linux_map; + struct memrange *filo_map; + + linux_map = params->e820_map; + filo_map = info->memrange; + for (i = 0; i < info->n_memranges; i++, linux_map++, filo_map++) { + if (i < E820MAX) { + /* Convert to BIOS e820 style */ + linux_map->addr = filo_map->base; + linux_map->size = filo_map->size; + linux_map->type = E820_RAM; + debug("%016Lx - %016Lx\n", linux_map->addr, + linux_map->addr + linux_map->size); + params->e820_map_nr = i+1; + } + + /* Find out top of RAM. XXX This ignores hole above 1MB */ + end = filo_map->base + filo_map->size; + if (end < (1ULL << 32)) { /* don't count memory above 4GB */ + if (end > ramtop) + ramtop = (uint32_t) end; + } + } + debug("ramtop=%#x\n", ramtop); + /* Size of memory above 1MB in KB */ + params->alt_mem_k = (ramtop - (1<<20)) >> 10; + /* old style, 64MB max */ + if (ramtop >= (64<<20)) + params->ext_mem_k = (63<<10); + else + params->ext_mem_k = params->alt_mem_k; + debug("ext_mem_k=%d, alt_mem_k=%d\n", params->ext_mem_k, params->alt_mem_k); +} + +/* + * Parse command line + * Some parameters, like initrd=<file>, are not passed to kernel, + * we are responsible to process them. + * Parameters for kernel are copied to kern_cmdline. Returns name of initrd. + */ +static char *parse_command_line(const char *orig_cmdline, char *kern_cmdline) +{ + const char *start, *sep, *end, *val; + char name[64]; + int len; + int k_len; + int to_kern; + char *initrd = 0; + int toolong = 0; + + forced_memsize = 0; + + if (!orig_cmdline) { + *kern_cmdline = 0; + return 0; + } + + k_len = 0; + debug("original command line: \"%s\"\n", orig_cmdline); + debug("kernel command line at %#lx\n", virt_to_phys(kern_cmdline)); + + start = orig_cmdline; + while (*start == ' ') + start++; + while (*start) { + end = strchr(start, ' '); + if (!end) + end = start + strlen(start); + sep = strchr(start, '='); + if (!sep || sep > end) + sep = end; + len = sep - start; + if (len >= sizeof(name)) + len = sizeof(name) - 1; + memcpy(name, start, len); + name[len] = 0; + + if (*sep == '=') { + val = sep + 1; + len = end - val; + } else { + val = 0; + len = 0; + } + + /* Only initrd= and mem= are handled here. vga= is not, + * which I believe is a paramter to the realmode part of Linux, + * which we don't execute. */ + if (strcmp(name, "initrd") == 0) { + if (!val) + printf("Missing filename to initrd parameter\n"); + else { + initrd = malloc(len + 1); + memcpy(initrd, val, len); + initrd[len] = 0; + debug("initrd=%s\n", initrd); + } + /* Don't pass this to kernel */ + to_kern = 0; + } else if (strcmp(name, "mem") == 0) { + if (!val) + printf("Missing value for mem parameter\n"); + else { + forced_memsize = strtoull_with_suffix(val, (char**)&val, 0); + if (forced_memsize == 0) + printf("Invalid mem option, ignored\n"); + if (val != end) { + printf("Garbage after mem=<size>, ignored\n"); + forced_memsize = 0; + } + debug("mem=%Lu\n", forced_memsize); + } + /* mem= is for both loader and kernel */ + to_kern = 1; + } else + to_kern = 1; + + if (to_kern) { + /* Copy to kernel command line buffer */ + if (k_len != 0) + kern_cmdline[k_len++] = ' '; /* put separator */ + len = end - start; + if (k_len + len >= COMMAND_LINE_SIZE) { + len = COMMAND_LINE_SIZE - k_len - 1; + if (!toolong) { + printf("Kernel command line is too long; truncated to " + "%d bytes\n", COMMAND_LINE_SIZE-1); + toolong = 1; + } + } + memcpy(kern_cmdline + k_len, start, len); + k_len += len; + } + + start = end; + while (*start == ' ') + start++; + } + kern_cmdline[k_len] = 0; + debug("kernel command line (%d bytes): \"%s\"\n", k_len, kern_cmdline); + + return initrd; +} + +/* Set command line location */ +static void set_command_line_loc(struct linux_params *params, + struct linux_header *hdr) +{ + if (hdr->protocol_version >= 0x202) { + /* new style */ + params->cmd_line_ptr = COMMAND_LINE_LOC; + } else { + /* old style */ + params->cl_magic = CL_MAGIC_VALUE; + params->cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC; + } +} + +/* Load 32-bit part of kernel */ +static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) +{ + uint32_t kern_offset, kern_size; + + if (hdr->setup_sects == 0) + hdr->setup_sects = 4; + kern_offset = (hdr->setup_sects + 1) * 512; + file_seek(kern_offset); + kern_size = file_size() - kern_offset; + debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as kernel; " + "specify the image size\n"); + return 0; + } +#endif + + printf("Loading kernel... "); + if (lfile_read(phys_to_virt(kern_addr), kern_size) != kern_size) { + printf("Can't read kernel\n"); + return 0; + } + printf("ok\n"); + + return kern_size; +} + +static int load_initrd(struct linux_header *hdr, struct sys_info *info, + uint32_t kern_end, struct linux_params *params, const char *initrd_file) +{ + uint32_t max; + uint32_t start, end, size; + uint64_t forced; + extern char _start[], _end[]; + + if (!file_open(initrd_file)) { + printf("Can't open initrd: %s\n", initrd_file); + return -1; + } + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as initrd; " + "specify the image size\n"); + return -1; + } +#endif + + size = file_size(); + + + /* Find out the kernel's restriction on how high the initrd can be + * placed */ + if (hdr->protocol_version >= 0x203) + max = hdr->initrd_addr_max; + else + max = 0x38000000; /* Hardcoded value for older kernels */ + + /* FILO itself is at the top of RAM. (relocated) + * So, try putting initrd just below us. */ + end = virt_to_phys(_start); + if (end > max) + end = max; + + /* If "mem=" option is given, we have to put the initrd within + * the specified range. */ + if (forced_memsize) { + forced = forced_memsize; + if (forced > max) + forced = max; + /* If the "mem=" is lower, it's easy */ + if (forced <= end) + end = forced; + else { + /* Otherwise, see if we can put it above us */ + if (virt_to_phys(_end) + size <= forced) + end = forced; /* Ok */ + } + } + + start = end - size; + start &= ~0xfff; /* page align */ + end = start + size; + + debug("start=%#x end=%#x\n", start, end); + + if (start < kern_end) { + printf("Initrd is too big to fit in memory\n"); + return -1; + } + + printf("Loading initrd... "); + if (lfile_read(phys_to_virt(start), size) != size) { + printf("Can't read initrd\n"); + return -1; + } + printf("ok\n"); + + params->initrd_start = start; + params->initrd_size = size; + + return 0; +} + +static void hardware_setup(void) +{ + /* Disable nmi */ + outb(0x80, 0x70); + + /* Make sure any coprocessor is properly reset.. */ + outb(0, 0xf0); + outb(0, 0xf1); + + /* we're getting screwed again and again by this problem of the 8259. + * so we're going to leave this lying around for inclusion into + * crt0.S on an as-needed basis. + * + * well, that went ok, I hope. Now we have to reprogram the interrupts :-( + * we put them right after the intel-reserved hardware interrupts, at + * int 0x20-0x2F. There they won't mess up anything. Sadly IBM really + * messed this up with the original PC, and they haven't been able to + * rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, + * which is used for the internal hardware interrupts as well. We just + * have to reprogram the 8259's, and it isn't fun. + */ + + outb(0x11, 0x20); /* initialization sequence to 8259A-1 */ + outb(0x11, 0xA0); /* and to 8259A-2 */ + + outb(0x20, 0x21); /* start of hardware int's (0x20) */ + outb(0x28, 0xA1); /* start of hardware int's 2 (0x28) */ + + outb(0x04, 0x21); /* 8259-1 is master */ + outb(0x02, 0xA1); /* 8259-2 is slave */ + + outb(0x01, 0x21); /* 8086 mode for both */ + outb(0x01, 0xA1); + + outb(0xFF, 0xA1); /* mask off all interrupts for now */ + outb(0xFB, 0x21); /* mask all irq's but irq2 which is cascaded */ +} + +/* Start Linux */ +static int start_linux(uint32_t kern_addr, struct linux_params *params) +{ + struct segment_desc *linux_gdt; + struct context *ctx; + //extern int cursor_x, cursor_y; + + ctx = init_context(phys_to_virt(STACK_LOC), 4096, 0); + + /* Linux expects GDT being in low memory */ + linux_gdt = phys_to_virt(GDT_LOC); + memset(linux_gdt, 0, 13*sizeof(struct segment_desc)); + /* Normal kernel code/data segments */ + linux_gdt[2] = gdt[FLAT_CODE]; + linux_gdt[3] = gdt[FLAT_DATA]; + /* 2.6 kernel uses 12 and 13, but head.S uses backward-compatible + * segments (2 and 3), so it SHOULD not be a problem. + * However, some distro kernels (eg. RH9) with backported threading + * patch use 12 and 13 also when booting... */ + linux_gdt[12] = gdt[FLAT_CODE]; + linux_gdt[13] = gdt[FLAT_DATA]; + ctx->gdt_base = GDT_LOC; + ctx->gdt_limit = 14*8-1; + ctx->cs = 0x10; + ctx->ds = 0x18; + ctx->es = 0x18; + ctx->fs = 0x18; + ctx->gs = 0x18; + ctx->ss = 0x18; + + /* Parameter location */ + ctx->esi = virt_to_phys(params); + + /* Entry point */ + ctx->eip = kern_addr; + + debug("eip=%#x\n", kern_addr); + printf("Jumping to entry point...\n"); + +#ifdef VGA_CONSOLE + /* Update VGA cursor position. + * This must be here because the printf changes the value! */ + params->orig_x = cursor_x; + params->orig_y = cursor_y; +#endif + + /* Go... */ + ctx = switch_to(ctx); + + /* It's impossible but... */ + printf("Returned with eax=%#x\n", ctx->eax); + + return ctx->eax; +} + +int linux_load(struct sys_info *info, const char *file, const char *cmdline) +{ + struct linux_header hdr; + struct linux_params *params; + uint32_t kern_addr, kern_size; + char *initrd_file = 0; + + if (!file_open(file)) + return -1; + + kern_addr = load_linux_header(&hdr); + if (kern_addr == 0) + return LOADER_NOT_SUPPORT; + + params = phys_to_virt(LINUX_PARAM_LOC); + init_linux_params(params, &hdr); + set_memory_size(params, info); + initrd_file = parse_command_line(cmdline, phys_to_virt(COMMAND_LINE_LOC)); + set_command_line_loc(params, &hdr); + + kern_size = load_linux_kernel(&hdr, kern_addr); + if (kern_size == 0) { + if (initrd_file) + free(initrd_file); + return -1; + } + + if (initrd_file) { + if (load_initrd(&hdr, info, kern_addr+kern_size, params, initrd_file) + != 0) { + free(initrd_file); + return -1; + } + free(initrd_file); + } + + hardware_setup(); + + start_linux(kern_addr, params); + return 0; +} diff --git a/qemu/roms/openbios/arch/amd64/multiboot.c b/qemu/roms/openbios/arch/amd64/multiboot.c new file mode 100644 index 000000000..4271bd52b --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/multiboot.c @@ -0,0 +1,125 @@ +/* Support for Multiboot */ + +#include "config.h" +#include "asm/io.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +struct mbheader { + unsigned int magic, flags, checksum; +}; +const struct mbheader multiboot_header + __attribute__((section (".hdr"))) = +{ + MULTIBOOT_HEADER_MAGIC, + MULTIBOOT_HEADER_FLAGS, + -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) +}; + +/* Multiboot information structure, provided by loader to us */ + +struct multiboot_mmap { + unsigned entry_size; + unsigned base_lo, base_hi; + unsigned size_lo, size_hi; + unsigned type; +}; + +#define MULTIBOOT_MEM_VALID 0x01 +#define MULTIBOOT_BOOT_DEV_VALID 0x02 +#define MULTIBOOT_CMDLINE_VALID 0x04 +#define MULTIBOOT_MODS_VALID 0x08 +#define MULTIBOOT_AOUT_SYMS_VALID 0x10 +#define MULTIBOOT_ELF_SYMS_VALID 0x20 +#define MULTIBOOT_MMAP_VALID 0x40 + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + struct multiboot_info *mbinfo; + struct multiboot_mmap *mbmem; + unsigned mbcount, mbaddr; + int i; + struct memrange *mmap; + int mmap_count; + module_t *mod; + + if (info->boot_type != 0x2BADB002) + return; + + debug("Using Multiboot information at %#lx\n", info->boot_data); + + mbinfo = phys_to_virt(info->boot_data); + + if (mbinfo->mods_count != 1) { + printf("Multiboot: no dictionary\n"); + return; + } + + mod = (module_t *) mbinfo->mods_addr; + info->dict_start=(unsigned long *)mod->mod_start; + info->dict_end=(unsigned long *)mod->mod_end; + + if (mbinfo->flags & MULTIBOOT_MMAP_VALID) { + /* convert mmap records */ + mbmem = phys_to_virt(mbinfo->mmap_addr); + mbcount = mbinfo->mmap_length / (mbmem->entry_size + 4); + mmap = malloc(mbcount * sizeof(struct memrange)); + mmap_count = 0; + mbaddr = mbinfo->mmap_addr; + for (i = 0; i < mbcount; i++) { + mbmem = phys_to_virt(mbaddr); + debug("%08x%08x %08x%08x (%d)\n", + mbmem->base_hi, + mbmem->base_lo, + mbmem->size_hi, + mbmem->size_lo, + mbmem->type); + if (mbmem->type == 1) { /* Only normal RAM */ + mmap[mmap_count].base = mbmem->base_lo + + (((unsigned long long) mbmem->base_hi) << 32); + mmap[mmap_count].size = mbmem->size_lo + + (((unsigned long long) mbmem->size_hi) << 32); + mmap_count++; + } + mbaddr += mbmem->entry_size + 4; + if (mbaddr >= mbinfo->mmap_addr + mbinfo->mmap_length) + break; + } + /* simple sanity check - there should be at least 2 RAM segments + * (base 640k and extended) */ + if (mmap_count >= 2) + goto got_it; + + printf("Multiboot mmap is broken\n"); + free(mmap); + /* fall back to mem_lower/mem_upper */ + } + + if (mbinfo->flags & MULTIBOOT_MEM_VALID) { + /* use mem_lower and mem_upper */ + mmap_count = 2; + mmap = malloc(2 * sizeof(*mmap)); + mmap[0].base = 0; + mmap[0].size = mbinfo->mem_lower << 10; + mmap[1].base = 1 << 20; /* 1MB */ + mmap[1].size = mbinfo->mem_upper << 10; + goto got_it; + } + + printf("Can't get memory information from Multiboot\n"); + return; + +got_it: + info->memrange = mmap; + info->n_memranges = mmap_count; + + return; +} diff --git a/qemu/roms/openbios/arch/amd64/multiboot.h b/qemu/roms/openbios/arch/amd64/multiboot.h new file mode 100644 index 000000000..17cf202ec --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/multiboot.h @@ -0,0 +1,96 @@ +/* multiboot.h + * tag: header for multiboot + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* magic number for multiboot header */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* flags for multiboot header */ +#define MULTIBOOT_HEADER_FLAGS 0x00010003 + +/* magic number passed by multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (8KB). */ +#define STACK_SIZE 0x2000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* We don't want these declarations in boot.S */ + +/* multiboot header */ +typedef struct multiboot_header { + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* symbol table for a.out */ +typedef struct aout_symbol_table { + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* section header table for ELF */ +typedef struct elf_section_header_table { + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* multiboot information */ +typedef struct multiboot_info { + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* module structure */ +typedef struct module { + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map { + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +#endif /* ! ASM */ diff --git a/qemu/roms/openbios/arch/amd64/openbios.c b/qemu/roms/openbios/arch/amd64/openbios.c new file mode 100644 index 000000000..15d3b6254 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/openbios.c @@ -0,0 +1,108 @@ +/* tag: openbios forth environment, executable code + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "asm/types.h" +#include "dict.h" +#include "kernel/kernel.h" +#include "kernel/stack.h" +#include "libopenbios/sys_info.h" +#include "openbios.h" +#include "relocate.h" + +void boot(void); + +#define DICTIONARY_SIZE (256*1024) /* 256K for the dictionary */ +static char intdict[DICTIONARY_SIZE]; + +static void init_memory(void) +{ + /* push start and end of available memory to the stack + * so that the forth word QUIT can initialize memory + * management. For now we use hardcoded memory between + * 0x10000 and 0x9ffff (576k). If we need more memory + * than that we have serious bloat. + */ + + PUSH(0x10000); + PUSH(0x9FFFF); +} + +static void +arch_init( void ) +{ + void setup_timers(void); + + openbios_init(); + modules_init(); +#ifdef CONFIG_DRIVER_IDE + setup_timers(); + ob_ide_init("/pci/pci-ata", 0x1f0, 0x3f6, 0x170, 0x376); +#endif + device_end(); + bind_func("platform-boot", boot ); +} + +extern struct _console_ops arch_console_ops; + +int openbios(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); +#endif + /* Clear the screen. */ + cls(); +#endif + + collect_sys_info(&sys_info); + + dict=intdict; + dictlimit = DICTIONARY_SIZE; + + load_dictionary((char *)sys_info.dict_start, + sys_info.dict_end-sys_info.dict_start); + forth_init(); + + relocate(&sys_info); + +#ifdef CONFIG_DEBUG_CONSOLE + video_init(); +#endif +#ifdef CONFIG_DEBUG_BOOT + printk("forth started.\n"); + printk("initializing memory..."); +#endif + + init_memory(); + +#ifdef CONFIG_DEBUG_BOOT + printk("done\n"); +#endif + + PUSH_xt( bind_noname_func(arch_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + + if (!PC) { + printk("panic: no dictionary entry point.\n"); + return -1; + } +#ifdef CONFIG_DEBUG_DICTIONARY + printk("done (%d bytes).\n", dicthead); + printk("Jumping to dictionary...\n"); +#endif + + enterforth((xt_t)PC); + + return 0; +} diff --git a/qemu/roms/openbios/arch/amd64/openbios.h b/qemu/roms/openbios/arch/amd64/openbios.h new file mode 100644 index 000000000..2d49dbf54 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/openbios.h @@ -0,0 +1,29 @@ +/* + * Creation Date: <2004/01/15 16:14:05 samuel> + * Time-stamp: <2004/01/15 16:14:05 samuel> + * + * <openbios.h> + * + * + * + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_OPENBIOS +#define _H_OPENBIOS + +int openbios(void); + +/* console.c */ +extern void cls(void); +#ifdef CONFIG_DEBUG_CONSOLE +extern int uart_init(int port, unsigned long speed); +extern void video_init(void); +#endif + +#endif /* _H_OPENBIOS */ diff --git a/qemu/roms/openbios/arch/amd64/plainboot.c b/qemu/roms/openbios/arch/amd64/plainboot.c new file mode 100644 index 000000000..08dab2d12 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/plainboot.c @@ -0,0 +1,21 @@ +/* tag: openbios fixed address forth starter + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define FIXED_DICTSTART 0xfffe0000 +#define FIXED_DICTEND 0xfffeffff + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)FIXED_DICTSTART; + info->dict_end=(unsigned long *)FIXED_DICTEND; +} diff --git a/qemu/roms/openbios/arch/amd64/relocate.h b/qemu/roms/openbios/arch/amd64/relocate.h new file mode 100644 index 000000000..d91160a03 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/relocate.h @@ -0,0 +1 @@ +void relocate(struct sys_info *); diff --git a/qemu/roms/openbios/arch/amd64/segment.c b/qemu/roms/openbios/arch/amd64/segment.c new file mode 100644 index 000000000..09763bd14 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/segment.c @@ -0,0 +1,134 @@ +/* Segmentation of the AMD64 architecture. + * + * 2003-07 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/sys_info.h" +#include "relocate.h" +#include "segment.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +/* i386 lgdt argument */ +struct gdtarg { + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +/* How far the virtual address (used in C) is different from physical + * address. Since we start in flat mode, the initial value is zero. */ +unsigned long virt_offset = 0; + +/* GDT, the global descriptor table */ +struct segment_desc gdt[NUM_SEG] = { + /* 0x00: null segment */ + {0, 0, 0, 0, 0, 0}, + /* 0x08: flat code segment */ + {0xffff, 0, 0, 0x9f, 0xcf, 0}, + /* 0x10: flat data segment */ + {0xffff, 0, 0, 0x93, 0xcf, 0}, + /* 0x18: code segment for relocated execution */ + {0xffff, 0, 0, 0x9f, 0xcf, 0}, + /* 0x20: data segment for relocated execution */ + {0xffff, 0, 0, 0x93, 0xcf, 0}, +}; + +extern char _start[], _end[]; + +void relocate(struct sys_info *info) +{ + int i; + unsigned long prog_addr; + unsigned long prog_size; + unsigned long addr, new_base; + unsigned long long segsize; + unsigned long new_offset; + unsigned d0, d1, d2; + struct gdtarg gdtarg; +#define ALIGNMENT 16 + + prog_addr = virt_to_phys(&_start); + prog_size = virt_to_phys(&_end) - virt_to_phys(&_start); + debug("Current location: %#lx-%#lx\n", prog_addr, prog_addr+prog_size-1); + + new_base = 0; + for (i = 0; i < info->n_memranges; i++) { + if (info->memrange[i].base >= 1ULL<<32) + continue; + segsize = info->memrange[i].size; + if (info->memrange[i].base + segsize > 1ULL<<32) + segsize = (1ULL<<32) - info->memrange[i].base; + if (segsize < prog_size+ALIGNMENT) + continue; + addr = info->memrange[i].base + segsize - prog_size; + addr &= ~(ALIGNMENT-1); + if (addr >= prog_addr && addr < prog_addr + prog_size) + continue; + if (prog_addr >= addr && prog_addr < addr + prog_size) + continue; + if (addr > new_base) + new_base = addr; + } + if (new_base == 0) { + printf("Can't find address to relocate\n"); + return; + } + + debug("Relocating to %#lx-%#lx... ", + new_base, new_base + prog_size - 1); + + /* New virtual address offset */ + new_offset = new_base - (unsigned long) &_start; + + /* Tweak the GDT */ + gdt[RELOC_CODE].base_0 = (unsigned short) new_offset; + gdt[RELOC_CODE].base_16 = (unsigned char) (new_offset>>16); + gdt[RELOC_CODE].base_24 = (unsigned char) (new_offset>>24); + gdt[RELOC_DATA].base_0 = (unsigned short) new_offset; + gdt[RELOC_DATA].base_16 = (unsigned char) (new_offset>>16); + gdt[RELOC_DATA].base_24 = (unsigned char) (new_offset>>24); + + /* Load new GDT and reload segments */ + gdtarg.base = new_offset + (unsigned long) gdt; + gdtarg.limit = GDT_LIMIT; + __asm__ __volatile__ ( + "rep; movsb\n\t" /* copy everything */ + "lgdt %3\n\t" + "ljmp %4, $1f\n1:\t" + "movw %5, %%ds\n\t" + "movw %5, %%es\n\t" + "movw %5, %%fs\n\t" + "movw %5, %%gs\n\t" + "movw %5, %%ss\n" + : "=&S" (d0), "=&D" (d1), "=&c" (d2) + : "m" (gdtarg), "n" (RELOC_CS), "q" ((unsigned short) RELOC_DS), + "0" (&_start), "1" (new_base), "2" (prog_size)); + + virt_offset = new_offset; + debug("ok\n"); +} + +#if 0 +/* Copy GDT to new location and reload it */ +void move_gdt(unsigned long newgdt) +{ + struct gdtarg gdtarg; + + debug("Moving GDT to %#lx...", newgdt); + memcpy(phys_to_virt(newgdt), gdt, sizeof gdt); + gdtarg.base = newgdt; + gdtarg.limit = GDT_LIMIT; + debug("reloading GDT..."); + __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg)); + debug("reloading CS for fun..."); + __asm__ __volatile__ ("ljmp %0, $1f\n1:" : : "n" (RELOC_CS)); + debug("ok\n"); +} +#endif diff --git a/qemu/roms/openbios/arch/amd64/segment.h b/qemu/roms/openbios/arch/amd64/segment.h new file mode 100644 index 000000000..0371a80ae --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/segment.h @@ -0,0 +1,30 @@ + +/* Segment indexes. Must match the gdt definition in segment.c. */ +enum { + NULL_SEG, + FLAT_CODE, + FLAT_DATA, + RELOC_CODE, + RELOC_DATA, + NUM_SEG, +}; + +/* Values for segment selector register */ +#define FLAT_CS (FLAT_CODE << 3) +#define FLAT_DS (FLAT_DATA << 3) +#define RELOC_CS (RELOC_CODE << 3) +#define RELOC_DS (RELOC_DATA << 3) + +/* i386 segment descriptor */ +struct segment_desc { + unsigned short limit_0; + unsigned short base_0; + unsigned char base_16; + unsigned char types; + unsigned char flags; + unsigned char base_24; +}; + +extern struct segment_desc gdt[NUM_SEG]; + +#define GDT_LIMIT ((NUM_SEG << 3) - 1) diff --git a/qemu/roms/openbios/arch/amd64/switch.S b/qemu/roms/openbios/arch/amd64/switch.S new file mode 100644 index 000000000..66668150d --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/switch.S @@ -0,0 +1,116 @@ + .globl entry, __switch_context, __exit_context, halt + + .text + .align 4 + +/* + * Entry point + * We start execution from here. + * It is assumed that CPU is in 32-bit protected mode and + * all segments are 4GB and base zero (flat model). + */ +entry: + /* Save boot context and switch to our main context. + * Main context is statically defined in C. + */ + pushl %cs + call __switch_context + + /* We get here when the main context switches back to + * the boot context. + * Return to previous bootloader. + */ + ret + +/* + * Switch execution context + * This saves registers, segments, and GDT in the stack, then + * switches the stack, and restores everything from the new stack. + * This function takes no argument. New stack pointer is + * taken from global variable __context, and old stack pointer + * is also saved to __context. This way we can just jump to + * this routine to get back to the original context. + * + * Call this routine with lcall or pushl %cs; call. + */ +__switch_context: + /* Save everything in current stack */ + pushfl /* 56 */ + pushl %ds /* 52 */ + pushl %es /* 48 */ + pushl %fs /* 44 */ + pushl %gs /* 40 */ + pushal /* 8 */ + subl $8, %esp + movw %ss, (%esp) /* 0 */ + sgdt 2(%esp) /* 2 */ + +#if 0 + /* Swap %cs and %eip on the stack, so lret will work */ + movl 60(%esp), %eax + xchgl %eax, 64(%esp) + movl %eax, 60(%esp) +#endif + + /* At this point we don't know if we are on flat segment + * or relocated. So compute the address offset from %eip. + * Assuming CS.base==DS.base==SS.base. + */ + call 1f +1: popl %ebx + subl $1b, %ebx + + /* Interrupts are not allowed... */ + cli + + /* Current context pointer is our stack pointer */ + movl %esp, %esi + + /* Normalize the ctx pointer */ + subl %ebx, %esi + + /* Swap it with new value */ + xchgl %esi, __context(%ebx) + + /* Adjust new ctx pointer for current address offset */ + addl %ebx, %esi + + /* Load new %ss and %esp to temporary */ + movzwl (%esi), %edx + movl 20(%esi), %eax + + /* Load new GDT */ + lgdt 2(%esi) + + /* Load new stack segment with new GDT */ + movl %edx, %ss + + /* Set new stack pointer, but we have to adjust it because + * pushal saves %esp value before pushal, and we want the value + * after pushal. + */ + leal -32(%eax), %esp + + /* Load the rest from new stack */ + popal + popl %gs + popl %fs + popl %es + popl %ds + popfl + + /* Finally, load new %cs and %eip */ + lret + +__exit_context: + /* Get back to the original context */ + pushl %cs + call __switch_context + + /* We get here if the other context attempt to switch to this + * dead context. This should not happen. */ + +halt: + cli + hlt + jmp halt diff --git a/qemu/roms/openbios/arch/amd64/sys_info.c b/qemu/roms/openbios/arch/amd64/sys_info.c new file mode 100644 index 000000000..d62070be0 --- /dev/null +++ b/qemu/roms/openbios/arch/amd64/sys_info.c @@ -0,0 +1,58 @@ +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/sys_info.h" +#include "context.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +void collect_multiboot_info(struct sys_info *); +void collect_sys_info(struct sys_info *info); + +void collect_sys_info(struct sys_info *info) +{ + int i; + unsigned long long total = 0; + struct memrange *mmap; + + /* Pick up paramters given by bootloader to us */ + info->boot_type = boot_ctx->eax; + info->boot_data = boot_ctx->ebx; + info->boot_arg = boot_ctx->param[0]; + debug("boot eax = %#lx\n", info->boot_type); + debug("boot ebx = %#lx\n", info->boot_data); + debug("boot arg = %#lx\n", info->boot_arg); + + collect_elfboot_info(info); +#ifdef CONFIG_LINUXBIOS + collect_linuxbios_info(info); +#endif +#ifdef CONFIG_IMAGE_ELF_MULTIBOOT + collect_multiboot_info(info); +#endif + + if (!info->memrange) { + printf("Can't get memory map from firmware. " + "Using hardcoded default.\n"); + info->n_memranges = 2; + info->memrange = malloc(2 * sizeof(struct memrange)); + info->memrange[0].base = 0; + info->memrange[0].size = 640*1024; + info->memrange[1].base = 1024*1024; + info->memrange[1].size = 32*1024*1024 + - info->memrange[1].base; + } + + debug("\n"); + mmap=info->memrange; + for (i = 0; i < info->n_memranges; i++) { + debug("%016Lx-", mmap[i].base); + debug("%016Lx\n", mmap[i].base+mmap[i].size); + total += mmap[i].size; + } + debug("RAM %Ld MB\n", (total + 512*1024) >> 20); +} diff --git a/qemu/roms/openbios/arch/build.xml b/qemu/roms/openbios/arch/build.xml new file mode 100644 index 000000000..e3f324412 --- /dev/null +++ b/qemu/roms/openbios/arch/build.xml @@ -0,0 +1,10 @@ +<?xml version="1.0"?> +<build> + <include href="x86/build.xml"/> + <include href="amd64/build.xml"/> + <include href="ppc/build.xml"/> + <include href="ia64/build.xml"/> + <include href="unix/build.xml"/> + <include href="sparc32/build.xml"/> + <include href="sparc64/build.xml"/> +</build> diff --git a/qemu/roms/openbios/arch/ia64/Kconfig b/qemu/roms/openbios/arch/ia64/Kconfig new file mode 100644 index 000000000..6ba86de5d --- /dev/null +++ b/qemu/roms/openbios/arch/ia64/Kconfig @@ -0,0 +1,22 @@ +mainmenu "OpenBIOS Configuration" + +config IPF + bool + default y + help + Building for IPF hardware. + +config LITTLE_ENDIAN + bool + default y + help + IPF is little endian. + +menu "Build hosted UNIX Binary" +source "arch/unix/Kconfig" +endmenu + +source "kernel/Kconfig" +source "forth/Kconfig" +source "libopenbios/Kconfig" +source "drivers/Kconfig" diff --git a/qemu/roms/openbios/arch/ia64/build.xml b/qemu/roms/openbios/arch/ia64/build.xml new file mode 100644 index 000000000..8f3ea0d86 --- /dev/null +++ b/qemu/roms/openbios/arch/ia64/build.xml @@ -0,0 +1,5 @@ +<build condition="IPF"> + <dictionary name="openbios-ia64" init="openbios" target="forth"> + <object source="init.fs"/> + </dictionary> +</build> diff --git a/qemu/roms/openbios/arch/ia64/defconfig b/qemu/roms/openbios/arch/ia64/defconfig new file mode 100644 index 000000000..70cd97e51 --- /dev/null +++ b/qemu/roms/openbios/arch/ia64/defconfig @@ -0,0 +1,65 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_IPF=y +CONFIG_LITTLE_ENDIAN=y + +# +# Kernel binaries (x86) +# +# CONFIG_IMAGE_ELF is not set +# CONFIG_IMAGE_ELF_EMBEDDED is not set +# CONFIG_IMAGE_ELF_MULTIBOOT is not set + +# +# Build hosted UNIX Binary +# +CONFIG_HOST_UNIX=y +# CONFIG_PLUGIN_PCI is not set + +# +# Kernel Debugging +# +# CONFIG_DEBUG is not set +CONFIG_DEBUG_CONSOLE=y +CONFIG_DEBUG_CONSOLE_SERIAL=y +CONFIG_SERIAL_PORT=1 +CONFIG_SERIAL_SPEED=115200 +CONFIG_DEBUG_CONSOLE_VGA=y + +# +# Module Configuration +# +CONFIG_CMDLINE=y +CONFIG_DEBLOCKER=y + +# +# Filesystem Configuration +# +CONFIG_DISK_LABEL=y +CONFIG_PART_SUPPORT=y +CONFIG_PC_PARTS=y +CONFIG_FS=y +CONFIG_GRUBFS=y +CONFIG_FSYS_EXT2FS=y +CONFIG_FSYS_FAT=y +CONFIG_FSYS_JFS=y +# CONFIG_FSYS_MINIX is not set +CONFIG_FSYS_REISERFS=y +CONFIG_FSYS_XFS=y +CONFIG_FSYS_ISO9660=y +# CONFIG_FSYS_FFS is not set +# CONFIG_FSYS_VSTAFS is not set +# CONFIG_DEBUG_FS is not set + +# +# Miscellaneous +# +CONFIG_LINUXBIOS=y + +# +# Drivers +# +CONFIG_DRIVER_PCI=y +CONFIG_DRIVER_IDE=y +# CONFIG_DEBUG_IDE is not set diff --git a/qemu/roms/openbios/arch/ia64/init.fs b/qemu/roms/openbios/arch/ia64/init.fs new file mode 100644 index 000000000..5b65dd103 --- /dev/null +++ b/qemu/roms/openbios/arch/ia64/init.fs @@ -0,0 +1,76 @@ +:noname + ." Type 'help' for detailed information" cr + \ ." boot secondary slave cdrom: " cr + \ ." 0 > boot hd:2,\boot\vmlinuz root=/dev/hda2" cr + ; DIAG-initializer + +" /" find-device + +new-device + " memory" device-name + \ 12230 encode-int " reg" property + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " cpus" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +finish-device + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +:noname + set-defaults +; SYSTEM-initializer + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /cpus/@0" preopen + " stdout" " /builtin/console" preopen + " stdin" " /builtin/console" preopen + +; SYSTEM-initializer + +\ use the tty interface if available +:noname + " /builtin/console" find-dev if drop + " /builtin/console" " input-device" $setenv + " /builtin/console" " output-device" $setenv + then +; SYSTEM-initializer + +:noname + " keyboard" input +; CONSOLE-IN-initializer + diff --git a/qemu/roms/openbios/arch/ppc/Kconfig b/qemu/roms/openbios/arch/ppc/Kconfig new file mode 100644 index 000000000..f317c0a4d --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/Kconfig @@ -0,0 +1,48 @@ +mainmenu "OpenBIOS Configuration" + +config PPC + bool + default y + help + Building for PPC hardware. + +config BIG_ENDIAN + bool + default y + help + PPC hardware is big endian (per default) + +choice + prompt "Platform Type" + default MOL + +config MOL + bool "Mac-on-Linux" + help + Build an image for Mac-on-Linux + +config MPC107 + bool "MPC107 board (Crescendo)" + help + Build for Crescendo board. + +config BRIQ + bool "Total Impact briQ" + help + Build an image for the Total Impact briQ + +config NO_ARCH + bool "None" + help + Don't build any images. + +endchoice + +menu "Build hosted UNIX Binary" +source "arch/unix/Kconfig" +endmenu + +source "kernel/Kconfig" +source "forth/Kconfig" +source "libopenbios/Kconfig" +source "drivers/Kconfig" diff --git a/qemu/roms/openbios/arch/ppc/Makefile b/qemu/roms/openbios/arch/ppc/Makefile new file mode 100644 index 000000000..e182825e5 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/Makefile @@ -0,0 +1,79 @@ + +include ../../config/Makefile.top + +SUBDIRS = +MOL = $(CONFIG_MOL:y=mol) +BRIQ = $(CONFIG_BRIQ:y=briq) +XTARGETS = $(MOL) $(BRIQ) ppc mollink +DICTIONARIES = $(MOL) $(BRIQ) + +INCLUDES = -I../../kernel -I../../kernel/include \ + -I../../include/molasm -I$(ODIR)/include + +############################################################################# + +mol-OBJS = mol/init.o mol/main.o mol/mol.o mol/console.o mol/osi-blk.o \ + mol/osi-scsi.o mol/pseudodisk.o mol/methods.o ofmem.o \ + mol/video.o mol/prom.o mol/tree.o misc.o mol/kernel.o + +briq-OBJS = briq/init.o briq/main.o briq/briq.o briq/vfd.o \ + ofmem.o briq/methods.o briq/tree.o \ + misc.o briq/kernel.o + +ppc-OBJS = $(KOBJS) $(MODULE_LIBS) \ + $(FS_LIBS) $(DRIVER_LIBS) $(LIBC_LIBS) + +all-$(CONFIG_MOL) += $(ODIR)/mol.image +all-$(CONFIG_BRIQ) += $(ODIR)/briq.image +all-$(CONFIG_MPC107) += $(ODIR)/mpc107.image + + +############################################################################# + +mol-SRC = ppc.fs tree.fs mol.fs $(ARCHDICT_SRC) +briq-SRC = ppc.fs briq/tree.fs briq/briq.fs $(ARCHDICT_SRC) + +$(ODIR)/mol/kernel.o: $(ODIR)/include/mol-dict.h +$(ODIR)/briq/kernel.o: $(ODIR)/include/briq-dict.h + +$(ODIR)/include/mol-dict.h: $(ODIR)/mol.dict + test -d $(dir $@) || $(INSTALL) -d $(dir $@) + @echo "static const char forth_dictionary[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@ + +$(ODIR)/include/briq-dict.h: $(ODIR)/briq.dict + test -d $(dir $@) || $(INSTALL) -d $(dir $@) + @echo "static const char forth_dictionary[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@ + +############################################################################# + +$(ODIR)/mol.image: $(ODIR)/start.o $(ODIR)/libmol.a $(ODIR)/libppc.a + @printf "= Building %-22s : " $@ + building= + $(LD) -Ttext=0x01e01000 -Bstatic $^ $(LIBGCC) -o $@ + @nm $@ | sort > $(ODIR)/mol.syms + strip -g $@ + @echo "ok" + +$(ODIR)/briq.image: $(ODIR)/start.o $(ODIR)/timebase.o $(ODIR)/libbriq.a $(ODIR)/libppc.a + @printf "= Building %-22s : " $@ + building= + $(LD) -g -Ttext=0x01e01000 -Bstatic $^ $(LIBGCC) -o $@ + @nm $@ | sort > $(ODIR)/briq.syms + #strip -g $@ + @echo "ok" + +$(ODIR)/mpc107.image: + @echo "BUILDING mpc107.image (not yet implemented)" + +clean-local: + $(RM) $(ODIR)/*.image $(ODIR)/*.syms $(ODIR)/include/mol-dict.h + +include Makefile.asm +include $(rules)/Rules.make +include $(rules)/Rules.forth diff --git a/qemu/roms/openbios/arch/ppc/Makefile.asm b/qemu/roms/openbios/arch/ppc/Makefile.asm new file mode 100644 index 000000000..32d43376d --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/Makefile.asm @@ -0,0 +1,32 @@ +# -*- makefile -*- +# +# Makefile.asm - assembly support +# +# Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 + + +################################################# +# Rules for asm targets +################################################# + +ASMFLAGS = -D__ASSEMBLY__ -I$(top_srcdir) $(ALTIVEC) +FILTERBIN = $(top_srcdir)/scripts/asfilter +ASFILTER = $(shell if test -x $(FILTERBIN) ; then echo $(FILTERBIN) \ + ; else echo "tr ';' '\n'" ; fi) +INVOKE_M4 = | $(M4) -s $(M4_NO_GNU) | $(ASFILTER) + +$(ODIR)/%.o: %.S + @printf " Compiling %-20s: " $(notdir $@) + assembly= + @install -d $(dir $@) + @$(RM) $@ $@.s + @$(CPP) $(ASMFLAGS) $(IDIRS) $< > /dev/null + $(CPP) $(ASMFLAGS) $(IDIRS) $(DEPFLAGS) $< $(INVOKE_M4) > $@.s + $(AS) $@.s $(AS_FLAGS) -o $@ + @$(DEPEXTRA) + @$(RM) $@.s + @echo "ok" diff --git a/qemu/roms/openbios/arch/ppc/briq/briq.c b/qemu/roms/openbios/arch/ppc/briq/briq.c new file mode 100644 index 000000000..a8541c370 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/briq.c @@ -0,0 +1,194 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <briq.c> + * + * Copyright (C) 2004, Greg Watson + * + * derived from mol.c + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/nvram.h" +#include "libc/vsprintf.h" +#include "libc/string.h" +#include "briq/briq.h" +#include <stdarg.h> + +#define UART_BASE 0x3f8 + +unsigned long virt_offset = 0; + +void +exit( int status ) +{ + for (;;); +} + +void +fatal_error( const char *err ) +{ + printk("Fatal error: %s\n", err ); + exit(0); +} + +void +panic( const char *err ) +{ + printk("Panic: %s\n", err ); + exit(0); + + /* won't come here... this keeps the gcc happy */ + for( ;; ) + ; +} + + +/************************************************************************/ +/* print using OSI interface */ +/************************************************************************/ + +static int do_indent; + +int +printk( const char *fmt, ... ) +{ + char *p, buf[1024]; + va_list args; + int i; + + va_start(args, fmt); + i = vnsprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) { + if( *p == '\n' ) + do_indent = 0; + if( do_indent++ == 1 ) { + putchar( '>' ); + putchar( '>' ); + putchar( ' ' ); + } + putchar( *p ); + } + return i; +} + + +/************************************************************************/ +/* TTY iface */ +/************************************************************************/ + +static int ttychar = -1; + +static int +tty_avail( void ) +{ + return 1; +} + +static int +tty_putchar( int c ) +{ + if( tty_avail() ) { + while (!(inb(UART_BASE + 0x05) & 0x20)) + ; + outb(c, UART_BASE); + while (!(inb(UART_BASE + 0x05) & 0x40)) + ; + } + return c; +} + +int +availchar( void ) +{ + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + ttychar = inb(UART_BASE); + return (ttychar >= 0); +} + +int +getchar( void ) +{ + int ch; + + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + return inb(UART_BASE); + ch = ttychar; + ttychar = -1; + return ch; +} + +int +putchar( int c ) +{ + if (c == '\n') + tty_putchar('\r'); + return tty_putchar(c); +} + + +/************************************************************************/ +/* briQ specific stuff */ +/************************************************************************/ + +static char nvram[2048]; + +void +dump_nvram(void) +{ + static char hexdigit[] = "0123456789abcdef"; + int i; + for (i = 0; i < 16*4; i++) + { + printk ("%c", hexdigit[nvram[i] >> 4]); + printk ("%c", hexdigit[nvram[i] % 16]); + if (!((i + 1) % 16)) + { + printk ("\n"); + } + else + { + printk (" "); + } + } +} + + +int +arch_nvram_size( void ) +{ + return sizeof(nvram); +} + +void +arch_nvram_put( char *buf ) +{ + memcpy(nvram, buf, sizeof(nvram)); + printk("new nvram:\n"); + dump_nvram(); +} + +void +arch_nvram_get( char *buf ) +{ + memcpy(buf, nvram, sizeof(nvram)); + printk("current nvram:\n"); + dump_nvram(); +} diff --git a/qemu/roms/openbios/arch/ppc/briq/briq.fs b/qemu/roms/openbios/arch/ppc/briq/briq.fs new file mode 100644 index 000000000..78d77970c --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/briq.fs @@ -0,0 +1,115 @@ +\ briq specific initialization code +\ +\ Copyright (C) 2004 Greg Watson +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + + +\ ------------------------------------------------------------------------- +\ initialization +\ ------------------------------------------------------------------------- + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " rtc" " /pci/isa/rtc" preopen + " memory" " /memory" preopen + " mmu" " /cpu@0" preopen + " stdout" " /packages/terminal-emulator" preopen + " stdin" " keyboard" preopen + +; SYSTEM-initializer + + +\ ------------------------------------------------------------------------- +\ device tree fixing +\ ------------------------------------------------------------------------- + +\ add decode-address methods +: (make-decodable) ( phandle -- ) + + dup " #address-cells" rot get-package-property 0= if + decode-int nip nip + over " decode-unit" rot find-method if 2drop else + ( save phandle ncells ) + + over active-package! + case + 1 of ['] parse-hex " decode-unit" is-xt-func endof + 3 of + " bus-range" active-package get-package-property 0= if + decode-int nip nip + ['] encode-unit-pci " encode-unit" is-xt-func + " decode-unit" is-func-begin + ['] (lit) , , + ['] decode-unit-pci-bus , + is-func-end + then + endof + endcase + then + then + drop +; + +: init-briq-tree ( -- ) + active-package + + iterate-tree-begin + begin ?dup while + + dup (make-decodable) + + iterate-tree + repeat + + active-package! +; + +\ use the tty interface if available +: activate-tty-interface + " /packages/terminal-emulator" find-dev if drop + " /packages/terminal-emulator" " input-device" $setenv + " /packages/terminal-emulator" " output-device" $setenv + then +; + +:noname + " keyboard" input +; CONSOLE-IN-initializer + + +\ ------------------------------------------------------------------------- +\ pre-booting +\ ------------------------------------------------------------------------- + +: update-chosen + " /chosen" find-device + stdin @ encode-int " stdin" property + stdout @ encode-int " stdout" property + " /pci/isa/interrupt-controller" find-dev if encode-int " interrupt-controller" property then + device-end +; diff --git a/qemu/roms/openbios/arch/ppc/briq/briq.h b/qemu/roms/openbios/arch/ppc/briq/briq.h new file mode 100644 index 000000000..33a2cafa8 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/briq.h @@ -0,0 +1,24 @@ +/* + * Creation Date: <2004/08/28 17:50:12 stepan> + * Time-stamp: <2004/08/28 17:50:12 stepan> + * + * <briq.h> + * + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_BRIQ +#define _H_BRIQ + +/* vfd.c */ +extern int vfd_draw_str( const char *str ); +extern void vfd_close( void ); + +#include "kernel.h" + +#endif /* _H_BRIQ */ diff --git a/qemu/roms/openbios/arch/ppc/briq/init.c b/qemu/roms/openbios/arch/ppc/briq/init.c new file mode 100644 index 000000000..b32e97aa2 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/init.c @@ -0,0 +1,130 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <init.c> + * + * Initialization for briq + * + * Copyright (C) 2004 Greg Watson + * + * based on mol/init.c: + * + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel & David Rydh + * (samuel@ibrium.se, dary@lindesign.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "briq/briq.h" +#include "libopenbios/ofmem.h" +#include "openbios-version.h" + +extern void unexpected_excep( int vector ); +extern void setup_timers( void ); + +#if 0 +int +get_bool_res( const char *res ) +{ + char buf[8], *p; + + p = BootHGetStrRes( res, buf, sizeof(buf) ); + if( !p ) + return -1; + if( !strcasecmp(p,"true") || !strcasecmp(p,"yes") || !strcasecmp(p,"1") ) + return 1; + return 0; +} +#endif + +void +unexpected_excep( int vector ) +{ + printk("briQ panic: Unexpected exception %x\n", vector ); + for( ;; ) + ; +} + +unsigned long isa_io_base; + +void +entry( void ) +{ + isa_io_base = 0x80000000; + + printk("\n"); + printk("=============================================================\n"); + printk(PROGRAM_NAME " " OPENBIOS_VERSION_STR " [%s]\n", + OPENBIOS_BUILD_DATE); + + ofmem_init(); + initialize_forth(); + /* won't return */ + + printk("of_startup returned!\n"); + for( ;; ) + ; +} + +static void +setenv( char *env, char *value ) +{ + push_str( value ); + push_str( env ); + fword("$setenv"); +} + +void +arch_of_init( void ) +{ +#if CONFIG_RTAS + phandle_t ph; +#endif + int autoboot; + + devtree_init(); + node_methods_init(); + modules_init(); + setup_timers(); +#ifdef CONFIG_DRIVER_PCI + ob_pci_init(); +#endif + +#if CONFIG_RTAS + if( !(ph=find_dev("/rtas")) ) + printk("Warning: No /rtas node\n"); + else { + unsigned long size = 0x1000; + while( size < (unsigned long)of_rtas_end - (unsigned long)of_rtas_start ) + size *= 2; + set_property( ph, "rtas-size", (char*)&size, sizeof(size) ); + } +#endif + +#if 0 + /* tweak boot settings */ + autoboot = !!get_bool_res("autoboot"); +#endif + autoboot = 0; + if( !autoboot ) + printk("Autobooting disabled - dropping into OpenFirmware\n"); + setenv("auto-boot?", autoboot ? "true" : "false" ); + setenv("boot-command", "briqboot"); + +#if 0 + if( get_bool_res("tty-interface") == 1 ) +#endif + fword("activate-tty-interface"); + + /* hack */ + device_end(); + bind_func("briqboot", boot ); +} diff --git a/qemu/roms/openbios/arch/ppc/briq/kernel.c b/qemu/roms/openbios/arch/ppc/briq/kernel.c new file mode 100644 index 000000000..e85134d43 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/kernel.c @@ -0,0 +1,16 @@ +/* + * Creation Date: <2004/08/28 18:03:25 stepan> + * Time-stamp: <2004/08/28 18:03:25 stepan> + * + * <briq/kernel.c> + * + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "briq-dict.h" +#include "../kernel.c" diff --git a/qemu/roms/openbios/arch/ppc/briq/main.c b/qemu/roms/openbios/arch/ppc/briq/main.c new file mode 100644 index 000000000..fbb2a26de --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/main.c @@ -0,0 +1,145 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <main.c> + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elfload.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "briq/briq.h" +#include "libopenbios/ofmem.h" + +static void +transfer_control_to_elf( unsigned long entry ) +{ + extern void call_elf( unsigned long entry ); + printk("Starting ELF image at 0x%08lX\n", entry); + call_elf( 0x400000 ); + //call_elf( entry ); + + fatal_error("call_elf returned unexpectedly\n"); +} + +static int +load_elf_rom( unsigned long *entry, int fd ) +{ + int i, lszz_offs, elf_offs; + char buf[128], *addr; + Elf_ehdr ehdr; + Elf_phdr *phdr; + size_t s; + + printk("Loading '%s'\n", get_file_path(fd)); + + /* the ELF-image (usually) starts at offset 0x4000 */ + if( (elf_offs=find_elf(fd)) < 0 ) { + printk("----> %s is not an ELF image\n", buf ); + exit(1); + } + if( !(phdr=elf_readhdrs(fd, elf_offs, &ehdr)) ) + fatal_error("elf_readhdrs failed\n"); + + *entry = ehdr.e_entry; + + /* load segments. Compressed ROM-image assumed to be located immediately + * after the last segment */ + lszz_offs = elf_offs; + for( i=0; i<ehdr.e_phnum; i++ ) { + /* p_memsz, p_flags */ + s = MIN( phdr[i].p_filesz, phdr[i].p_memsz ); + seek_io( fd, elf_offs + phdr[i].p_offset ); + + /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n", + phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset, + phdr[i].p_vaddr ); */ + + if( phdr[i].p_vaddr != phdr[i].p_paddr ) + printk("WARNING: ELF segment virtual addr != physical addr\n"); + lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz ); + if( !s ) + continue; + if( ofmem_claim( phdr[i].p_vaddr, phdr[i].p_memsz, 0 ) == -1 ) + fatal_error("Claim failed!\n"); + + addr = (char*)phdr[i].p_vaddr; + if( read_io(fd, addr, s) != s ) + fatal_error("read failed\n"); + +#if 0 + /* patch CODE segment */ + if( *entry >= phdr[i].p_vaddr && *entry < phdr[i].p_vaddr + s ) { + patch_newworld_rom( (char*)phdr[i].p_vaddr, s ); + newworld_timer_hack( (char*)phdr[i].p_vaddr, s ); + } +#endif + flush_icache_range( addr, addr+s ); + + /*printk("ELF ROM-section loaded at %08lX (size %08lX)\n", + (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz );*/ + } + free( phdr ); + return lszz_offs; +} + + +static void +encode_bootpath( const char *spec, const char *args ) +{ + phandle_t chosen_ph = find_dev("/chosen"); + set_property( chosen_ph, "bootpath", spec, strlen(spec)+1 ); + set_property( chosen_ph, "bootargs", args, strlen(args)+1 ); +} + +/************************************************************************/ +/* briq booting */ +/************************************************************************/ + +static void +briq_startup( void ) +{ + const char *paths[] = { "hd:0,\\zImage.chrp", NULL }; + const char *args[] = { "root=/dev/hda2 console=ttyS0,115200", NULL }; + unsigned long entry; + int i, fd; + + for( i=0; paths[i]; i++ ) { + if( (fd=open_io(paths[i])) == -1 ) + continue; + (void) load_elf_rom( &entry, fd ); + close_io( fd ); + encode_bootpath( paths[i], args[i] ); + + update_nvram(); + transfer_control_to_elf( entry ); + /* won't come here */ + } + printk("*** Boot failure! No secondary bootloader specified ***\n"); +} + + +/************************************************************************/ +/* entry */ +/************************************************************************/ + +void +boot( void ) +{ + fword("update-chosen"); + briq_startup(); +} diff --git a/qemu/roms/openbios/arch/ppc/briq/methods.c b/qemu/roms/openbios/arch/ppc/briq/methods.c new file mode 100644 index 000000000..649e9bafa --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/methods.c @@ -0,0 +1,333 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <methods.c> + * + * Misc device node methods + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "briq/briq.h" +#include "libopenbios/ofmem.h" + +/************************************************************************/ +/* RTAS (run-time abstraction services) */ +/************************************************************************/ + +#ifdef CONFIG_RTAS +DECLARE_NODE( rtas, INSTALL_OPEN, 0, "+/rtas" ); + +/* ( physbase -- rtas_callback ) */ +static void +rtas_instantiate( void ) +{ + int physbase = POP(); + int s=0x1000, size = (int)of_rtas_end - (int)of_rtas_start; + unsigned long virt; + + while( s < size ) + s += 0x1000; + virt = ofmem_claim_virt( 0, s, 0x1000 ); + ofmem_map( physbase, virt, s, -1 ); + memcpy( (char*)virt, of_rtas_start, size ); + + printk("RTAS instantiated at %08x\n", physbase ); + flush_icache_range( (char*)virt, (char*)virt + size ); + + PUSH( physbase ); +} + +NODE_METHODS( rtas ) = { + { "instantiate", rtas_instantiate }, + { "instantiate-rtas", rtas_instantiate }, +}; +#endif + + +/************************************************************************/ +/* stdout */ +/************************************************************************/ + +DECLARE_NODE( vfd_stdout, INSTALL_OPEN, 0, "Tdisplay" ); + +/* ( addr len -- actual ) */ +static void +stdout_write( void ) +{ + int len = POP(); + char *addr = (char*)POP(); + char *s = malloc( len + 1 ); + + strncpy_nopad( s, addr, len ); + s[len]=0; + + printk( "%s", s ); + //vfd_draw_str( s ); + free( s ); + + PUSH( len ); +} + +NODE_METHODS( vfd_stdout ) = { + { "write", stdout_write }, +}; + + +/************************************************************************/ +/* tty */ +/************************************************************************/ + +DECLARE_NODE( tty, INSTALL_OPEN, 0, "/packages/terminal-emulator" ); + +/* ( addr len -- actual ) */ +static void +tty_read( void ) +{ + int ch, len = POP(); + char *p = (char*)POP(); + int ret=0; + + if( len > 0 ) { + ret = 1; + ch = getchar(); + if( ch >= 0 ) { + *p = ch; + } else { + ret = 0; + } + } + PUSH( ret ); +} + +/* ( addr len -- actual ) */ +static void +tty_write( void ) +{ + int i, len = POP(); + char *p = (char*)POP(); + for( i=0; i<len; i++ ) + putchar( *p++ ); + RET( len ); +} + +NODE_METHODS( tty ) = { + { "read", tty_read }, + { "write", tty_write }, +}; + +/************************************************************************/ +/* client interface 'quiesce' */ +/************************************************************************/ + +DECLARE_NODE( ciface, 0, 0, "/packages/client-iface" ); + +/* ( -- ) */ +static void +ciface_quiesce( unsigned long args[], unsigned long ret[] ) +{ +#if 0 + unsigned long msr; + /* This seems to be the correct thing to do - but I'm not sure */ + asm volatile("mfmsr %0" : "=r" (msr) : ); + msr &= ~(MSR_IR | MSR_DR); + asm volatile("mtmsr %0" :: "r" (msr) ); +#endif + printk("=============================================================\n\n"); +} + +/* ( -- ms ) */ +static void +ciface_milliseconds( unsigned long args[], unsigned long ret[] ) +{ + extern unsigned long get_timer_freq(); + static unsigned long mticks=0, usecs=0; + unsigned long t; + + asm volatile("mftb %0" : "=r" (t) : ); + if( mticks ) + usecs += get_timer_freq() / 1000000 * ( t-mticks ); + mticks = t; + + PUSH( usecs/1000 ); +} + + +NODE_METHODS( ciface ) = { + { "quiesce", ciface_quiesce }, + { "milliseconds", ciface_milliseconds }, +}; + + +/************************************************************************/ +/* MMU/memory methods */ +/************************************************************************/ + +DECLARE_NODE( memory, INSTALL_OPEN, 0, "/memory" ); +DECLARE_NODE( mmu, INSTALL_OPEN, 0, "/cpu@0" ); +DECLARE_NODE( mmu_ciface, 0, 0, "/packages/client-iface" ); + + +/* ( phys size align --- base ) */ +static void +mem_claim( void ) +{ + int align = POP(); + int size = POP(); + int phys = POP(); + int ret = ofmem_claim_phys( phys, size, align ); + + if( ret == -1 ) { + printk("MEM: claim failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mem_release( void ) +{ + POP(); POP(); +} + +/* ( phys size align --- base ) */ +static void +mmu_claim( void ) +{ + int align = POP(); + int size = POP(); + int phys = POP(); + int ret = ofmem_claim_virt( phys, size, align ); + + if( ret == -1 ) { + printk("MMU: CLAIM failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mmu_release( void ) +{ + POP(); POP(); +} + +/* ( phys virt size mode -- [ret???] ) */ +static void +mmu_map( void ) +{ + int mode = POP(); + int size = POP(); + int virt = POP(); + int phys = POP(); + int ret; + + /* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ + ret = ofmem_map( phys, virt, size, mode ); + + if( ret ) { + printk("MMU: map failure\n"); + throw( -13 ); + return; + } +} + +/* ( virt size -- ) */ +static void +mmu_unmap( void ) +{ + POP(); POP(); +} + +/* ( virt -- false | phys mode true ) */ +static void +mmu_translate( void ) +{ + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode ); + + if( phys == -1 ) { + PUSH( 0 ); + } else { + PUSH( phys ); + PUSH( mode ); + PUSH( -1 ); + } +} + +/* ( virt size align -- baseaddr|-1 ) */ +static void +ciface_claim( void ) +{ + int align = POP(); + int size = POP(); + int virt = POP(); + int ret = ofmem_claim( virt, size, align ); + + /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ + PUSH( ret ); +} + +/* ( virt size -- ) */ +static void +ciface_release( void ) +{ + POP(); + POP(); +} + + +NODE_METHODS( memory ) = { + { "claim", mem_claim }, + { "release", mem_release }, +}; + +NODE_METHODS( mmu ) = { + { "claim", mmu_claim }, + { "release", mmu_release }, + { "map", mmu_map }, + { "unmap", mmu_unmap }, + { "translate", mmu_translate }, +}; + +NODE_METHODS( mmu_ciface ) = { + { "cif-claim", ciface_claim }, + { "cif-release", ciface_release }, +}; + + +/************************************************************************/ +/* init */ +/************************************************************************/ + +void +node_methods_init( void ) +{ +#ifdef CONFIG_RTAS + REGISTER_NODE( rtas ); +#endif + REGISTER_NODE( vfd_stdout ); + REGISTER_NODE( ciface ); + REGISTER_NODE( memory ); + REGISTER_NODE( mmu ); + REGISTER_NODE( mmu_ciface ); + REGISTER_NODE( tty ); +} diff --git a/qemu/roms/openbios/arch/ppc/briq/tree.c b/qemu/roms/openbios/arch/ppc/briq/tree.c new file mode 100644 index 000000000..177183889 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/tree.c @@ -0,0 +1,23 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <tree.c> + * + * device tree setup + * + * Copyright (C) 2004 Greg Watson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" + +void devtree_init( void ) +{ + fword("init-briq-tree"); +} diff --git a/qemu/roms/openbios/arch/ppc/briq/tree.fs b/qemu/roms/openbios/arch/ppc/briq/tree.fs new file mode 100644 index 000000000..ae503266c --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/tree.fs @@ -0,0 +1,305 @@ +\ briq specific initialization code +\ +\ Copyright (C) 2004 Greg Watson +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + +\ ------------------------------------------------------------- +\ device-tree +\ ------------------------------------------------------------- + +" /" find-device + +" chrp" device-type +" TotalImpact,BRIQ-1" model +h# 80000000 encode-int " isa-io-base" property +1 encode-int " #interrupt-cells" property +1 encode-int " #size-cells" property + +new-device + " memory" device-name + " memory" device-type + 0 encode-int h# 1E00000 encode-int encode+ + h# 2000000 encode-int encode+ h# 40000000 encode-int encode+ + " available" property + 0 h# 40000000 reg + external + : open true ; + : close ; +finish-device + +new-device + " cpu" device-name + " cpu" device-type + " " encode-string " translations" property + 0 encode-phys h# 8000000 encode-int encode+ " available" property + d# 32 encode-int " d-cache-block-size" property + 8 encode-int " d-cache-sets" property + d# 32768 encode-int " d-cache-size" property + d# 32 encode-int " i-cache-block-size" property + 8 encode-int " i-cache-sets" property + d# 32768 encode-int " i-cache-size" property + " " encode-string " cache-unified" property + 2 encode-int " i-tlb-sets" property + d# 128 encode-int " i-tlb-size" property + 2 encode-int " d-tlb-sets" property + d# 128 encode-int " d-tlb-size" property + " " encode-string " tlb-split" property + 2 encode-int " tlb-sets" property + d# 256 encode-int " tlb-size" property + " " encode-string " performance-monitor" property + " " encode-string " graphics" property + 4 encode-int " reservation-granule-size" property + d# 25000000 encode-int " timebase-frequency" property + d# 300000000 encode-int " clock-frequency" property + d# 66000000 encode-int " bus-frequency" property + h# 88201 encode-int " cpu-version" property + 0 encode-int " reg" property +finish-device + +" /pci" find-device + h# 01000000 encode-int 0 encode-int encode+ 0 encode-int encode+ + h# 80000000 encode-int encode+ 0 encode-int encode+ + h# 01000000 encode-int encode+ + h# 02000000 encode-int encode+ 0 encode-int encode+ 0 encode-int encode+ + h# C0000000 encode-int encode+ 0 encode-int encode+ + h# 08000000 encode-int encode+ + " ranges" property + " IBM,CPC710" model + h# FF5F7700 encode-int " 8259-interrupt-acknowledge" property + h# 0000F800 encode-int 0 encode-int encode+ 0 encode-int encode+ + 7 encode-int encode+ + " interrupt-map-mask" property + 1 encode-int " #interrupt-cells" property + h# 80000000 encode-int " system-dma-base" property + d# 33333333 encode-int " clock-frequency" property + " " encode-string " primary-bridge" property + 0 encode-int " pci-bridge-number" property + h# FF500000 encode-int h# 100000 encode-int encode+ " reg" property + 0 encode-int 0 encode-int encode+ " bus-range" property + +new-device + " isa" device-name + " isa" device-type + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + + external + : open true ; + : close ; + +finish-device + +: ?devalias ( alias-str alias-len device-str device-len -- + \ alias-str alias-len false | true ) + active-package >r + " /aliases" find-device + \ 2dup ." Checking " type + 2dup find-dev if \ check if device exists + drop + 2over find-dev if \ do we already have an alias? + \ ." alias exists" cr + drop 2drop false + else + \ ." device exists" cr + encode-string + 2swap property + true + then + else + \ ." device doesn't exist" cr + 2drop false + then + r> active-package! + ; + +:noname + " hd" + " /pci/pci-ata/ata-1/disk@0" ?devalias not if + " /pci/pci-ata/ata-1/disk@1" ?devalias not if + " /pci/pci-ata/ata-2/disk@0" ?devalias not if + " /pci/pci-ata/ata-2/disk@1" ?devalias not if + 2drop ." No disk found." cr + then + then + then + then + + " cdrom" + " /pci/pci-ata/ata-1/cdrom@0" ?devalias not if + " /pci/pci-ata/ata-1/cdrom@1" ?devalias not if + " /pci/pci-ata/ata-2/cdrom@0" ?devalias not if + " /pci/pci-ata/ata-2/cdrom@1" ?devalias not if + 2drop ." No cdrom found" cr + then + then + then + then +; SYSTEM-initializer + +new-device + " ide" device-name + " ide" device-type + " WINBOND,82C553" model + h# 28 encode-int " max-latency" property + h# 2 encode-int " min-grant" property + h# 1 encode-int " devsel-speed" property + h# 0 encode-int " subsystem-vendor-id" property + h# 0 encode-int " subsystem-id" property + h# 1018A encode-int " class-code" property + h# 5 encode-int " revision-id" property + h# 105 encode-int " device-id" property + h# 10AD encode-int " vendor-id" property + h# 1003110 encode-int 0 encode-int encode+ h# 10020 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003114 encode-int 0 encode-int encode+ h# 10030 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003118 encode-int 0 encode-int encode+ h# 10040 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 100311C encode-int 0 encode-int encode+ h# 10034 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003120 encode-int 0 encode-int encode+ h# 10050 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003124 encode-int 0 encode-int encode+ h# 10060 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + " assigned-addresses" property + h# 3100 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ + h# 1003110 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003114 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003118 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 100311C encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003120 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003124 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + " reg" property +finish-device + +new-device + " ethernet" device-name + " network" device-type + " AMD,79C973" model + h# 3800 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ + " reg" property +finish-device + +" /pci/isa" find-device + 0 0 " assigned-addresses" property + 0 0 " ranges" property + 0 encode-int " slot-names" property + d# 8333333 encode-int " clock-frequency" property + 0 encode-int " eisa-slots" property + 2 encode-int " #interrupt-cells" property + " W83C553F" encode-string " compatible" property + " WINBOND,82C553" model + 0 encode-int " max-latency" property + 0 encode-int " min-grant" property + 1 encode-int " devsel-speed" property + 0 encode-int " subsystem-vendor-id" property + 0 encode-int " subsystem-id" property + h# 60100 encode-int " class-code" property + h# 10 encode-int " revision-id" property + h# 565 encode-int " device-id" property + h# 10AD encode-int " vendor-id" property + h# 3000 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ " reg" property + +new-device + " rtc" device-name + " rtc" device-type + " DS17285S" model + " MC146818" encode-string + " DS17285S" encode-string encode+ + " pnpPNP,b00" encode-string encode+ " compatible" property + 8 encode-int 0 encode-int encode+ " interrupts" property + h# 70 encode-int 1 encode-int encode+ + 2 encode-int encode+ " reg" property +finish-device + +new-device + " interrupt-controller" device-name + " interrupt-controller" device-type + " 8259" model + " " encode-string " interrupt-controller" property + 2 encode-int " #interrupt-cells" property + 1 encode-int + 2 encode-int encode+ + 3 encode-int encode+ + 6 encode-int encode+ + " reserved-interrupts" property + " 8259" encode-string + " chrp,iic" encode-string encode+ + " compatible" property + h# 20 encode-int 1 encode-int encode+ + 2 encode-int encode+ " reg" property +finish-device + +new-device + " serial" device-name + " serial" device-type + " no" encode-string " ctsrts" property + " no" encode-string " xon" property + " no" encode-string " parity" property + d# 115200 encode-int " bps" property + 1 encode-int " stop-bits" property + 8 encode-int " data-bits" property + h# 70800 encode-int " divisor" property + h# 708000 encode-int " clock-frequency" property + 4 encode-int 0 encode-int encode+ " interrupts" property + h# 3F8 encode-int 1 encode-int encode+ + 8 encode-int encode+ " reg" property +finish-device + +" /pci" find-device + " /pci/isa/interrupt-controller" find-dev if + encode-int " interrupt-parent" property + then + h# 3800 encode-int 0 encode-int encode+ + 0 encode-int encode+ 1 encode-int encode+ + " /pci/isa/interrupt-controller" find-dev if + encode-int encode+ + then + h# 0C encode-int encode+ 1 encode-int encode+ + " interrupt-map" property + +" /pci/isa" find-device + " /pci/isa/interrupt-controller" find-dev if + encode-int " interrupt-parent" property + then + +\ ------------------------------------------------------------- +\ /packages +\ ------------------------------------------------------------- + +" /packages" find-device + + " packages" device-name + external + \ allow packages to be opened with open-dev + : open true ; + : close ; + +\ /packages/terminal-emulator +new-device + " terminal-emulator" device-name + external + : open true ; + : close ; + \ : write ( addr len -- actual ) + \ dup -rot type + \ ; +finish-device + +\ ------------------------------------------------------------- +\ The END +\ ------------------------------------------------------------- +device-end diff --git a/qemu/roms/openbios/arch/ppc/briq/vfd.c b/qemu/roms/openbios/arch/ppc/briq/vfd.c new file mode 100644 index 000000000..ffc87a079 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/briq/vfd.c @@ -0,0 +1,42 @@ +/* + * Creation Date: <2004/08/28 17:29:43 greg> + * Time-stamp: <2004/08/28 17:29:43 greg> + * + * <vfd.c> + * + * Simple text console + * + * Copyright (C) 2004 Greg Watson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "briq/briq.h" + +static int vfd_is_open; + +static int +vfd_init( void ) +{ + vfd_is_open = 1; + return 0; +} + +void +vfd_close( void ) +{ +} + +int +vfd_draw_str( const char *str ) +{ + if (!vfd_is_open) + vfd_init(); + + return 0; +} diff --git a/qemu/roms/openbios/arch/ppc/build.xml b/qemu/roms/openbios/arch/ppc/build.xml new file mode 100644 index 000000000..29f6601f9 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/build.xml @@ -0,0 +1,211 @@ +<?xml version="1.0"?> +<build condition="PPC"> + + <dictionary name="openbios-briq" init="openbios" target="forth" condition="BRIQ"> + <object source="ppc.fs"/> + <object source="briq/tree.fs"/> + <object source="briq/briq.fs"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <dictionary name="openbios-pearpc" init="openbios" target="forth" condition="PEARPC"> + <object source="ppc.fs"/> + <object source="pearpc/tree.fs"/> + <object source="pearpc/pearpc.fs"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <dictionary name="openbios-qemu" init="openbios" target="forth" condition="QEMU"> + <object source="ppc.fs"/> + <object source="qemu/tree.fs"/> + <object source="qemu/qemu.fs"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <dictionary name="openbios-mol" init="openbios" target="forth" condition="MOL"> + <object source="ppc.fs"/> + <object source="mol/tree.fs"/> + <object source="mol/mol.fs"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <!-- HACK ALERT --> + + <executable name="target/include/briq-dict.h" target="target" condition="BRIQ"> + <rule><![CDATA[ + $(call quiet-command,true, " GEN $(TARGET_DIR)$@") + @echo "static const char forth_dictionary[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@]]></rule> + <external-object source="openbios-briq.dict"/> + </executable> + + <executable name="target/arch/ppc/briq/kernel.o" target="target" condition="BRIQ"> + <rule><![CDATA[ $(SRCDIR)/arch/ppc/briq/kernel.c $(ODIR)/target/include/static-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/ppc/briq/kernel.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + + <executable name="target/include/pearpc-dict.h" target="target" condition="PEARPC"> + <rule><![CDATA[ + $(call quiet-command,true, " GEN $(TARGET_DIR)$@") + @echo "static const char forth_dictionary[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@]]></rule> + <external-object source="openbios-pearpc.dict"/> + </executable> + + <executable name="target/arch/ppc/pearpc/kernel.o" target="target" condition="PEARPC"> + <rule><![CDATA[ $(SRCDIR)/arch/ppc/pearpc/kernel.c $(ODIR)/target/include/pearpc-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/ppc/pearpc/kernel.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + <executable name="target/include/qemu-dict.h" target="target" condition="QEMU"> + <rule><![CDATA[ + $(call quiet-command,$(ODIR)/forthstrap -x -D $@ -d $< </dev/null, " GEN $(TARGET_DIR)$@")]]></rule> + <external-object source="openbios-qemu.dict"/> + </executable> + + <executable name="target/arch/ppc/qemu/kernel.o" target="target" condition="QEMU"> + <rule><![CDATA[ $(SRCDIR)/arch/ppc/qemu/kernel.c $(ODIR)/target/include/qemu-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/ppc/qemu/kernel.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + + <executable name="target/include/mol-dict.h" target="target" condition="MOL"> + <rule><![CDATA[ + $(call quiet-command,true, " GEN $(TARGET_DIR)$@") + @echo "static const char forth_dictionary[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@]]></rule> + <external-object source="openbios-mol.dict"/> + </executable> + + <executable name="target/arch/ppc/mol/kernel.o" target="target" condition="MOL"> + <rule><![CDATA[ + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/ppc/mol/kernel.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + <!-- END OF HACK ALERT --> + + <library name="briq" target="target" type="static" condition="BRIQ"> + <object source="misc.S"/> + <object source="ofmem.c"/> + <object source="briq/briq.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="briq/init.c" flags="-I$(SRCDIR)/arch/ppc"/> + <external-object source="target/arch/ppc/briq/kernel.o"/> + <object source="briq/main.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="briq/methods.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="briq/tree.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="briq/vfd.c" flags="-I$(SRCDIR)/arch/ppc"/> + </library> + + <library name="pearpc" target="target" type="static" condition="PEARPC"> + <object source="misc.S"/> + <object source="ofmem.c"/> + <object source="pearpc/pearpc.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="pearpc/init.c" flags="-I$(SRCDIR)/arch/ppc"/> + <external-object source="target/arch/ppc/pearpc/kernel.o"/> + <object source="pearpc/main.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="pearpc/methods.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="pearpc/tree.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="pearpc/vfd.c" flags="-I$(SRCDIR)/arch/ppc"/> + <!-- taken from mol: generalize --> + <object source="pearpc/console.c" flags="-I$(SRCDIR)/arch/ppc"/> + </library> + + <library name="qemu" target="target" type="static" condition="QEMU"> + <object source="qemu/ofmem.c"/> + <object source="qemu/qemu.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="qemu/init.c" flags="-I$(SRCDIR)/arch/ppc"/> + <external-object source="target/arch/ppc/qemu/kernel.o"/> + <object source="qemu/main.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="qemu/methods.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="qemu/vfd.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="qemu/console.c" flags="-I$(SRCDIR)/arch/ppc"/> + </library> + + <library name="mol" target="target" type="static" condition="MOL"> + <object source="misc.S"/> + <object source="ofmem.c"/> + <object source="mol/init.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/main.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/mol.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/console.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/osi-blk.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/osi-scsi.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/pseudodisk.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/methods.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/prom.c" flags="-I$(SRCDIR)/arch/ppc"/> + <object source="mol/tree.c" flags="-I$(SRCDIR)/arch/ppc"/> + <external-object source="target/arch/ppc/mol/kernel.o"/> + </library> + + <executable name="openbios-briq.elf" target="target" condition="BRIQ"> + <rule> + $(call quiet-command,$(LD) -g -Ttext=0x01e01000 -Bstatic $^ $(shell $(CC) -print-libgcc-file-name) -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-briq.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="start.S"/> + <object source="timebase.S"/> + <external-object source="libbriq.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + </executable> + + <executable name="openbios-pearpc.elf" target="target" condition="PEARPC"> + <rule> + $(call quiet-command,$(LD) -g -Ttext=0x01e01000 -Bstatic $^ $(shell $(CC) -print-libgcc-file-name) -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-pearpc.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="start.S"/> + <object source="timebase.S"/> + <external-object source="libpearpc.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + </executable> + + <executable name="openbios-qemu.elf" target="target" condition="QEMU"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/$(ARCH)/qemu/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-qemu.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="qemu/start.S"/> + <object source="timebase.S"/> + <external-object source="libqemu.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + <external-object source="libgcc.a"/> + </executable> + + <executable name="openbios-mol.elf" target="target" condition="MOL"> + <rule> + $(call quiet-command,$(LD) -g -Ttext=0x01e01000 -Bstatic $^ $(shell $(CC) -print-libgcc-file-name) -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-mol.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="start.S"/> + <external-object source="libmol.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + </executable> + +</build> diff --git a/qemu/roms/openbios/arch/ppc/defconfig b/qemu/roms/openbios/arch/ppc/defconfig new file mode 100644 index 000000000..adfb181ea --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/defconfig @@ -0,0 +1,48 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_PPC=y +CONFIG_MOL=y +# CONFIG_MPC107 is not set +# CONFIG_NO_ARCH is not set + +# +# Build hosted UNIX Binary +# +CONFIG_HOST_UNIX=y +# CONFIG_PLUGIN_PCI is not set + +# +# Kernel Debugging +# +CONFIG_DEBUG=y +CONFIG_DEBUG_BOOT=y +# CONFIG_DEBUG_DSTACK is not set +# CONFIG_DEBUG_RSTACK is not set +# CONFIG_DEBUG_DICTIONARY is not set +# CONFIG_DEBUG_INTERNAL is not set +# CONFIG_DEBUG_INTERPRETER is not set +CONFIG_DEBUG_CONSOLE=y +CONFIG_DEBUG_CONSOLE_SERIAL=y +CONFIG_SERIAL_PORT=1 +CONFIG_SERIAL_SPEED=115200 +CONFIG_DEBUG_CONSOLE_VGA=y + +# +# Packages +# +# CONFIG_PKG_DEBLOCKER is not set +# CONFIG_PKG_DISKLABEL is not set +# CONFIG_PKG_OBP_TFTP is not set +# CONFIG_PKG_TERMINAL_EMULATOR is not set + +# +# Module Configuration +# +CONFIG_DEBLOCKER=y +CONFIG_DISK_LABEL=y +CONFIG_PART_SUPPORT=y +CONFIG_MAC_PARTS=y +CONFIG_FS=y +CONFIG_HFS=y +CONFIG_HFSP=y diff --git a/qemu/roms/openbios/arch/ppc/kernel.c b/qemu/roms/openbios/arch/ppc/kernel.c new file mode 100644 index 000000000..28f2965bb --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/kernel.c @@ -0,0 +1,99 @@ +/* + * Creation Date: <2003/10/25 14:07:17 samuel> + * Time-stamp: <2004/08/28 17:48:19 stepan> + * + * <kernel.c> + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * Based upon unix.c (from OpenBIOS): + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "dict.h" +#include "libopenbios/bindings.h" +#include "kernel/stack.h" +#include "kernel/kernel.h" +#include "libc/string.h" +#include "kernel.h" + +#define MEMORY_SIZE (256*1024) /* 256K ram for hosted system */ +#define DICTIONARY_SIZE (512*1024) /* 512K for the dictionary */ + +static ucell *memory; + +/************************************************************************/ +/* F U N C T I O N S */ +/************************************************************************/ + +int +forth_segv_handler( char *segv_addr ) +{ + ucell addr = 0xdeadbeef; + + if( PC >= (ucell) dict && PC <= (ucell) dict + dicthead ) + addr = *(ucell *) PC; + + printk("panic: segmentation violation at %x\n", (int)segv_addr); + printk("dict=0x%x here=0x%x(dict+0x%x) pc=0x%x(dict+0x%x)\n", + (int)dict, (int)(dict + dicthead), dicthead, + PC, PC - (ucell) dict); + printk("dstackcnt=%d rstackcnt=%d instruction=%x\n", + dstackcnt, rstackcnt, addr); + +#ifdef DEBUG_DSTACK + printdstack(); +#endif +#ifdef DEBUG_RSTACK + printrstack(); +#endif + return -1; +} + +/* + * allocate memory and prepare engine for memory management. + */ + +static void +init_memory( void ) +{ + memory = malloc(MEMORY_SIZE); + if( !memory ) + panic("panic: not enough memory on host system.\n"); + + /* we push start and end of memory to the stack + * so that it can be used by the forth word QUIT + * to initialize the memory allocator + */ + + PUSH( (ucell)memory ); + PUSH( (ucell)memory + MEMORY_SIZE ); +} + +int +initialize_forth( void ) +{ + dict = malloc(DICTIONARY_SIZE); + load_dictionary( forth_dictionary, sizeof(forth_dictionary) ); + forth_init(); + + PUSH_xt( bind_noname_func(arch_of_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + if( PC ) { + init_memory(); + enterforth((xt_t)PC); + free( memory ); + } + free( dict ); + return 0; +} diff --git a/qemu/roms/openbios/arch/ppc/kernel.h b/qemu/roms/openbios/arch/ppc/kernel.h new file mode 100644 index 000000000..20cda489e --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/kernel.h @@ -0,0 +1,41 @@ +/* + * Creation Date: <2004/08/28 17:50:12 stepan> + * Time-stamp: <2004/08/28 17:50:12 stepan> + * + * <kernel.h> + * + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef __KERNEL_H__ +#define __KERNEL_H__ + +/* misc.c */ +extern void fatal_error( const char *str ); +extern void exit( int status ); + +/* start.S */ +extern void flush_icache_range( char *start, char *stop ); +extern char of_rtas_start[], of_rtas_end[]; + +/* methods.c */ +extern void node_methods_init( void ); + +/* main.c */ +extern void boot( void ); + +/* init.c */ +extern void entry( void ); +extern void arch_of_init( void ); +extern int get_bool_res( const char *str ); + +/* tree.c */ +extern void devtree_init( void ); + + +#endif /* __KERNEL_H__ */ diff --git a/qemu/roms/openbios/arch/ppc/misc.S b/qemu/roms/openbios/arch/ppc/misc.S new file mode 100644 index 000000000..435ce0eca --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/misc.S @@ -0,0 +1,74 @@ +/* + * Creation Date: <2002/10/20 15:54:50 samuel> + * Time-stamp: <2002/10/20 15:57:21 samuel> + * + * <misc.S> + * + * Low-level stuff + * + * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * Based upon misc.S from the the linux kernel with the following + * copyrights: + * + * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org), + * Cort Dougan (cort@cs.nmt.edu), Paul Mackerras + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "asm/asmdefs.h" +#include "asm/processor.h" + + +/* + * Extended precision shifts. + * + * Updated to be valid for shift counts from 0 to 63 inclusive. + * -- Gabriel + * + * R3/R4 has 64 bit value + * R5 has shift count + * result in R3/R4 + * + * ashrdi3: arithmetic right shift (sign propagation) + * lshrdi3: logical right shift + * ashldi3: left shift + */ +GLOBL(__ashrdi3): + subfic r6,r5,32 + srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count + addi r7,r5,32 # could be xori, or addi with -32 + slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) + rlwinm r8,r7,0,32 # t3 = (count < 32) ? 32 : 0 + sraw r7,r3,r7 # t2 = MSW >> (count-32) + or r4,r4,r6 # LSW |= t1 + slw r7,r7,r8 # t2 = (count < 32) ? 0 : t2 + sraw r3,r3,r5 # MSW = MSW >> count + or r4,r4,r7 # LSW |= t2 + blr + +GLOBL(__ashldi3): + subfic r6,r5,32 + slw r3,r3,r5 # MSW = count > 31 ? 0 : MSW << count + addi r7,r5,32 # could be xori, or addi with -32 + srw r6,r4,r6 # t1 = count > 31 ? 0 : LSW >> (32-count) + slw r7,r4,r7 # t2 = count < 32 ? 0 : LSW << (count-32) + or r3,r3,r6 # MSW |= t1 + slw r4,r4,r5 # LSW = LSW << count + or r3,r3,r7 # MSW |= t2 + blr + +GLOBL(__lshrdi3): + subfic r6,r5,32 + srw r4,r4,r5 # LSW = count > 31 ? 0 : LSW >> count + addi r7,r5,32 # could be xori, or addi with -32 + slw r6,r3,r6 # t1 = count > 31 ? 0 : MSW << (32-count) + srw r7,r3,r7 # t2 = count < 32 ? 0 : MSW >> (count-32) + or r4,r4,r6 # LSW |= t1 + srw r3,r3,r5 # MSW = MSW >> count + or r4,r4,r7 # LSW |= t2 + blr diff --git a/qemu/roms/openbios/arch/ppc/mmutypes.h b/qemu/roms/openbios/arch/ppc/mmutypes.h new file mode 100644 index 000000000..441d7f8bc --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mmutypes.h @@ -0,0 +1,76 @@ +/* + * Creation Date: <2002/01/13 13:53:14 samuel> + * Time-stamp: <2002/01/27 19:56:11 samuel> + * + * <mmutypes.h> + * + * MMU definitions + * + * Most of these declarations originate from the Linux Kernel + * + * Copyright (C) 2002 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_MMUTYPES +#define _H_MMUTYPES + +/* Hardware Page Table Entry */ +typedef struct mPTE { + unsigned long v:1; /* Entry is valid */ + unsigned long vsid:24; /* Virtual segment identifier */ + unsigned long h:1; /* Hash algorithm indicator */ + unsigned long api:6; /* Abbreviated page index */ + + unsigned long rpn:20; /* Real (physical) page number */ + unsigned long :3; /* Unused */ + unsigned long r:1; /* Referenced */ + unsigned long c:1; /* Changed */ + unsigned long w:1; /* Write-thru cache mode */ + unsigned long i:1; /* Cache inhibited */ + unsigned long m:1; /* Memory coherence */ + unsigned long g:1; /* Guarded */ + unsigned long :1; /* Unused */ + unsigned long pp:2; /* Page protection */ +} mPTE_t; + + +typedef struct _mBATU { /* Upper part of BAT (all except 601) */ + unsigned long bepi:15; /* Effective page index (virtual address) */ + unsigned long :4; /* Unused */ + unsigned long bl:11; /* Block size mask */ + unsigned long vs:1; /* Supervisor valid */ + unsigned long vp:1; /* User valid */ +} mBATU; + +typedef struct _mBATL { /* Lower part of BAT (all except 601) */ + unsigned long brpn:15; /* Real page index (physical address) */ + unsigned long :10; /* Unused */ + unsigned long w:1; /* Write-thru cache */ + unsigned long i:1; /* Cache inhibit */ + unsigned long m:1; /* Memory coherence */ + unsigned long g:1; /* Guarded (MBZ in IBAT) */ + unsigned long :1; /* Unused */ + unsigned long pp:2; /* Page access protections */ +} mBATL; + +typedef struct _mBAT { + mBATU batu; /* Upper register */ + mBATL batl; /* Lower register */ +} mBAT; + +typedef struct _mSEGREG { + unsigned long t:1; /* Normal or I/O type */ + unsigned long ks:1; /* Supervisor 'key' (normally 0) */ + unsigned long kp:1; /* User 'key' (normally 1) */ + unsigned long n:1; /* No-execute */ + unsigned long :4; /* Unused */ + unsigned long vsid:24; /* Virtual Segment Identifier */ +} mSEGREG; + + +#endif /* _H_MMUTYPES */ diff --git a/qemu/roms/openbios/arch/ppc/mol/console.c b/qemu/roms/openbios/arch/ppc/mol/console.c new file mode 100644 index 000000000..966011e19 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/console.c @@ -0,0 +1,30 @@ +/* + * Creation Date: <2002/10/29 18:59:05 samuel> + * Time-stamp: <2003/12/28 22:51:11 samuel> + * + * <console.c> + * + * Simple text console + * + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2005 Stefan Reinauer <stepan@openbios.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/diskio.h" +#include "osi_calls.h" +#include "libopenbios/ofmem.h" +#include "mol/mol.h" +#include "boothelper_sh.h" +#include "video_sh.h" + +#define openbios_GetFBInfo(x) OSI_GetFBInfo(x) + +#include "../../../packages/video.c" +#include "../../../libopenbios/console_common.c" diff --git a/qemu/roms/openbios/arch/ppc/mol/init.c b/qemu/roms/openbios/arch/ppc/mol/init.c new file mode 100644 index 000000000..15333b4e1 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/init.c @@ -0,0 +1,119 @@ +/* + * Creation Date: <1999/11/16 00:49:26 samuel> + * Time-stamp: <2004/04/12 16:26:50 samuel> + * + * <init.c> + * + * Initialization + * + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel & David Rydh + # (samuel@ibrium.se, dary@lindesign.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "mol/mol.h" +#include "libopenbios/ofmem.h" +#include "mol/prom.h" +#include "openbios-version.h" +#include "osi_calls.h" +#include "boothelper_sh.h" + +extern void unexpected_excep( int vector ); + +int +get_bool_res( const char *res ) +{ + char buf[8], *p; + + p = BootHGetStrRes( res, buf, sizeof(buf) ); + if( !p ) + return -1; + if( !strcasecmp(p,"true") || !strcasecmp(p,"yes") || !strcasecmp(p,"1") ) + return 1; + return 0; +} + +void +unexpected_excep( int vector ) +{ + printk("MOL panic: Unexpected exception %x\n", vector ); + for( ;; ) + ; +} + +unsigned long isa_io_base; + +void +entry( void ) +{ + isa_io_base = 0x80000000; + + printk("\n"); + printk("=============================================================\n"); + printk(PROGRAM_NAME " " OPENBIOS_VERSION_STR " [%s]\n", + OPENBIOS_BUILD_DATE); + + ofmem_init(); + initialize_forth(); + /* won't return */ + + printk("of_startup returned!\n"); + for( ;; ) + ; +} + +static void +setenv( char *env, char *value ) +{ + push_str( value ); + push_str( env ); + fword("$setenv"); +} + +void +arch_of_init( void ) +{ + mol_phandle_t ph; + int autoboot; + + devtree_init(); + node_methods_init(); + nvram_init("/pci/mac-io/nvram"); + openbios_init(); + modules_init(); + pseudodisk_init(); + osiblk_init(); + osiscsi_init(); + init_video(); + + if( (ph=prom_find_device("/rtas")) == -1 ) + printk("Warning: No /rtas node\n"); + else { + unsigned long size = 0x1000; + while( size < (unsigned long)of_rtas_end - (unsigned long)of_rtas_start ) + size *= 2; + prom_set_prop( ph, "rtas-size", (char*)&size, sizeof(size) ); + } + + /* tweak boot settings */ + autoboot = !!get_bool_res("autoboot"); + if( !autoboot ) + printk("Autobooting disabled - dropping into OpenFirmware\n"); + setenv("auto-boot?", autoboot ? "true" : "false" ); + setenv("boot-command", "molboot"); + + if( get_bool_res("tty-interface") == 1 ) + fword("activate-tty-interface"); + + /* hack */ + device_end(); + bind_func("molboot", boot ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/kernel.c b/qemu/roms/openbios/arch/ppc/mol/kernel.c new file mode 100644 index 000000000..1454b8a85 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/kernel.c @@ -0,0 +1,16 @@ +/* + * Creation Date: <2004/08/28 18:03:25 stepan> + * Time-stamp: <2004/08/28 18:03:25 stepan> + * + * <mol/kernel.c> + * + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "mol-dict.h" +#include "../kernel.c" diff --git a/qemu/roms/openbios/arch/ppc/mol/main.c b/qemu/roms/openbios/arch/ppc/mol/main.c new file mode 100644 index 000000000..f6ed934d0 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/main.c @@ -0,0 +1,370 @@ +/* + * Creation Date: <2002/10/02 22:24:24 samuel> + * Time-stamp: <2004/03/27 01:57:55 samuel> + * + * <main.c> + * + * + * + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elfload.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "mol/mol.h" +#include "libopenbios/ofmem.h" +#include "osi_calls.h" +#include "ablk_sh.h" +#include "boothelper_sh.h" + + +static void patch_newworld_rom( char *start, size_t size ); +static void newworld_timer_hack( char *start, size_t size ); + +static void +transfer_control_to_elf( unsigned long entry ) +{ + extern void call_elf( unsigned long entry ); + printk("Starting ELF boot loader\n"); + call_elf( entry ); + + fatal_error("call_elf returned unexpectedly\n"); +} + +static int +load_elf_rom( unsigned long *entry, int fd ) +{ + int i, lszz_offs, elf_offs; + char buf[128], *addr; + Elf_ehdr ehdr; + Elf_phdr *phdr; + size_t s; + + printk("Loading '%s' from '%s'\n", get_file_path(fd), + get_volume_name(fd) ); + + /* the ELF-image (usually) starts at offset 0x4000 */ + if( (elf_offs=find_elf(fd)) < 0 ) { + printk("----> %s is not an ELF image\n", buf ); + exit(1); + } + if( !(phdr=elf_readhdrs(fd, elf_offs, &ehdr)) ) + fatal_error("elf_readhdrs failed\n"); + + *entry = ehdr.e_entry; + + /* load segments. Compressed ROM-image assumed to be located immediately + * after the last segment */ + lszz_offs = elf_offs; + for( i=0; i<ehdr.e_phnum; i++ ) { + /* p_memsz, p_flags */ + s = MIN( phdr[i].p_filesz, phdr[i].p_memsz ); + seek_io( fd, elf_offs + phdr[i].p_offset ); + + /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n", + phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset, + phdr[i].p_vaddr ); */ + + if( phdr[i].p_vaddr != phdr[i].p_paddr ) + printk("WARNING: ELF segment virtual addr != physical addr\n"); + lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz ); + if( !s ) + continue; + if( ofmem_claim( phdr[i].p_vaddr, phdr[i].p_memsz, 0 ) == -1 ) + fatal_error("Claim failed!\n"); + + addr = (char*)phdr[i].p_vaddr; + if( read_io(fd, addr, s) != s ) + fatal_error("read failed\n"); + + /* patch CODE segment */ + if( *entry >= phdr[i].p_vaddr && *entry < phdr[i].p_vaddr + s ) { + patch_newworld_rom( (char*)phdr[i].p_vaddr, s ); + newworld_timer_hack( (char*)phdr[i].p_vaddr, s ); + } + flush_icache_range( addr, addr+s ); + + /* printk("ELF ROM-section loaded at %08lX (size %08lX)\n", + (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz );*/ + } + free( phdr ); + return lszz_offs; +} + + +/************************************************************************/ +/* newworld ROM loading */ +/************************************************************************/ + +#define ROM_BASE 0x1100000 /* where we decide to put things */ + +/* fix bug present in the 2.4 and the 3.0 Apple ROM */ +static void +patch_newworld_rom( char *start, size_t size ) +{ + int s; + unsigned long mark[] = { 0x7c7d1b78, /* mr r29,r3 */ + 0x7c9c2378, /* mr r28,r4 */ + 0x7cc33378, /* mr r3,r6 */ + 0x7c864214, /* add r4,r6,r8 <------ BUG -- */ + 0x80b10000, /* lwz r5,0(r17) */ + 0x38a500e8 }; /* addi r5,r5,232 */ + + /* Correcting add r4,r6,r8 ----> addi r4,r6,8 */ + for( s=0; s<size-sizeof(mark); s+=4 ) + if( memcmp( start+s, mark, sizeof(mark)) == 0 ) { + printk("FIXING ROM BUG @ %X!\n", s+12); + ((unsigned long*)(start+s))[3] = 0x38860008; /* addi r4,r6,8 */ + } +} + +/* This hack is only needed on machines with a timebase slower than 12.5 MHz + * (50 MHz bus frequency). Typically only old, accelerated machines fall + * into this category. The cause of the problem is an overflow in Apple's + * calibration routine. + */ +static void +newworld_timer_hack( char *start, size_t size ) +{ + int s; + unsigned long mark[] = { 0x7d0000a6, 0x5507045e, 0x7ce00124, 0x4c00012c, + 0x38e00000, 0x3c80000f, 0x6084ffff, 0x98830c00, + 0x7c0006ac, 0x98830a00, 0x7c0006ac, 0x7c9603a6, + 0x4c00012c, 0x7cb602a6, 0x2c050000, 0x4181fff8, + 0x7c0004ac, 0x88830a00, 0x7c0006ac, 0x88a30800, + 0x7c0006ac, 0x88c30a00, 0x7c0006ac, 0x7c043040, + 0x40a2ffe4, 0x5085442e, 0x7ca500d0, 0x54a5043e, + 0x7c053840, 0x7ca72b78, 0x4082ff9c, 0x7ca32b78, + 0x7d000124, 0x4c00012c, 0x4e800020 + }; + + /* return #via ticks corresponding to 0xfffff DEC ticks (VIA frequency == 47/60 MHz) */ + for( s=0; s < size-sizeof(mark); s+=4 ) { + if( !memcmp( start+s, mark, sizeof(mark)) ) { + extern char timer_calib_start[], timer_calib_end[]; + extern unsigned long nw_dec_calibration; + int hz = OSI_UsecsToMticks(1000); + nw_dec_calibration = OSI_MticksToUsecs(0xfffff*47)/60; + memcpy( start + s, timer_calib_start, timer_calib_end - timer_calib_start ); + + printk("Timer calibration fix: %d.%02d MHz [%ld]\n", + hz/1000, (hz/10)%100, nw_dec_calibration ); + break; + } + } +} + +static unsigned long +load_newworld_rom( int fd ) +{ + int lszz_offs, lszz_size; + unsigned long entry, data[2]; + phandle_t ph; + + lszz_offs = load_elf_rom( &entry, fd ); + seek_io( fd, -1 ); + lszz_size = tell(fd) - lszz_offs; + seek_io( fd, lszz_offs ); + + /* printk("Compressed ROM image: offset %08X, size %08X loaded at %08x\n", + lszz_offs, lszz_size, ROM_BASE ); */ + + if( ofmem_claim(ROM_BASE, lszz_size, 0) == -1 ) + fatal_error("Claim failure (lszz)!\n"); + + read_io( fd, (char*)ROM_BASE, lszz_size ); + + /* Fix the /rom/macos/AAPL,toolbox-image,lzss property (phys, size) */ +#if 0 + if( (ph=prom_create_node("/rom/macos/")) == -1 ) + fatal_error("Failed creating /rom/macos/"); +#else + ph = find_dev("/rom/macos"); +#endif + data[0] = ROM_BASE; + data[1] = lszz_size; + set_property( ph, "AAPL,toolbox-image,lzss", (char*)data, sizeof(data) ); + + /* The 7.8 rom (MacOS 9.2) uses AAPL,toolbox-parcels instead of + * AAPL,toolbox-image,lzss. It probably doesn't hurt to have it + * always present (we don't have an easy way to determine ROM version...) + */ + set_property( ph, "AAPL,toolbox-parcels", (char*)data, sizeof(data) ); + return entry; +} + +static int +search_nwrom( int fd, int fast ) +{ + char *s, buf[128]; + int found = 0; + + if( fast ) { + int ind; + found = !reopen( fd, "\\\\:tbxi" ); + for( ind=0; !found && (s=BootHGetStrResInd("macos_rompath", buf, sizeof(buf), ind++, 0)) ; ) + found = !reopen( fd, s ); + for( ind=0; !found && (s=BootHGetStrResInd("macos_rompath_", buf, sizeof(buf), ind++, 0)) ; ) + found = !reopen( fd, s ); + } else { + printk("Searching %s for a 'Mac OS ROM' file\n", get_volume_name(fd) ); + if( !(found=reopen_nwrom(fd)) ) { + printk(" \n**** HINT ***************************************************\n"); + printk("* The booting can be speeded up by adding the line\n"); + printk("* macos_rompath: '%s'\n", get_file_path(fd) ); + printk("* to the /etc/mol/molrc.macos (recommended).\n"); + printk("*************************************************************\n \n"); + } + } + return found; +} + +static void +encode_bootpath( const char *spec, const char *args ) +{ + phandle_t chosen_ph = find_dev("/chosen"); + set_property( chosen_ph, "bootpath", spec, strlen(spec)+1 ); + set_property( chosen_ph, "bootargs", args, strlen(args)+1 ); +} + +static char * +newworld_load( const char *node_path, const char *spec, int do_search ) +{ + char *p, *entry, buf[80]; + int fd, len; + + if( (fd=open_io(spec)) == -1 ) + return NULL; + + if( !search_nwrom(fd, do_search) ) { + close_io(fd); + return NULL; + } + printk("Boot Disk: %s [%s]\n", spec, get_fstype(fd) ); + + entry = (char*)load_newworld_rom( fd ); + +#if 1 + PUSH_ih( get_ih_from_fd(fd) ); + fword("get-instance-path"); + len = POP(); + p = (char*)POP(); + buf[0] = 0; + if( len < sizeof(buf) ) { + memcpy( buf, p, len ); + buf[len] =0; + } + strcat( buf, "/x@:" ); + printk("boot_path: %s\n", buf ); + encode_bootpath( buf, "" ); +#endif + close_io( fd ); + return entry; +} + +static void +newworld_startup( void ) +{ + int i, j, bootunit, type, fd; + ablk_disk_info_t info; + char *entry = NULL; + char spec[80]; + phandle_t ph; + + char path[]="/pci/pci-bridge/mol-blk"; + if( !(ph=find_dev(path)) ) + fatal_error("MOLBlockDriver node not found\n"); + + /* user-specified newworld ROMs take precedence */ + if( (fd=open_io("pseudo:,nwrom")) >= 0 ) { + entry = (char*)load_newworld_rom( fd ); + close_io( fd ); + } + + /* determine boot volume */ + for( bootunit=-1, type=0; bootunit==-1 && type<3 ; type++ ) { + for( i=0; !OSI_ABlkDiskInfo(0, i, &info) ; i++ ) { + if( type<=1 && !(info.flags & ABLK_BOOT_HINT) ) + continue; + if( type>1 && (info.flags & ABLK_BOOT_HINT) ) + continue; + + for( j=0; !entry && j<32; j++ ) { + snprintf( spec, sizeof(spec), "%s/disk@%x:%d", + path, i, j ); + entry = newworld_load( path, spec, (!type || type==2) ); + } + if( entry ) { + bootunit = i; + break; + } + } + } + + if( entry ) { + OSI_ABlkBlessDisk( 0 /*channel*/, bootunit ); + + update_nvram(); + transfer_control_to_elf( (unsigned long)entry ); + /* won't come here */ + return; + } + + printk("\n--- No bootable disk was found! -----------------------------\n"); + printk("If this is an oldworld machine, try booting from the MacOS\n"); + printk("install CD and install MacOS from within MOL.\n"); + printk("-------------------------------------------------------------\n"); + exit(1); +} + + +/************************************************************************/ +/* yaboot booting */ +/************************************************************************/ + +static void +yaboot_startup( void ) +{ + const char *paths[] = { "pseudo:,ofclient", "pseudo:,yaboot", NULL }; + unsigned long entry; + int i, fd; + + for( i=0; paths[i]; i++ ) { + if( (fd=open_io(paths[i])) == -1 ) + continue; + (void) load_elf_rom( &entry, fd ); + close_io( fd ); + encode_bootpath( paths[i], "" ); + + update_nvram(); + transfer_control_to_elf( entry ); + /* won't come here */ + } + printk("*** Boot failure! No secondary bootloader specified ***\n"); + exit(1); +} + + +/************************************************************************/ +/* entry */ +/************************************************************************/ + +void +boot( void ) +{ + fword("update-chosen"); + if( find_dev("/mol-platform") ) + yaboot_startup(); + else + newworld_startup(); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/methods.c b/qemu/roms/openbios/arch/ppc/mol/methods.c new file mode 100644 index 000000000..bfaf51506 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/methods.c @@ -0,0 +1,470 @@ +/* + * Creation Date: <2003/10/18 13:24:29 samuel> + * Time-stamp: <2004/03/27 02:00:30 samuel> + * + * <methods.c> + * + * Misc device node methods + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "mol/mol.h" +#include "libopenbios/ofmem.h" +#include "mol/prom.h" +#include "osi_calls.h" +#include "kbd_sh.h" + +/************************************************************************/ +/* Power Management */ +/************************************************************************/ + +DECLARE_NODE( powermgt, INSTALL_OPEN, 0, "/pci/pci-bridge/mac-io/power-mgt" ); + +/* ( -- ) */ +static void +set_hybernot_flag( void ) +{ +} + +NODE_METHODS( powermgt ) = { + { "set-hybernot-flag", set_hybernot_flag }, +}; + + +/************************************************************************/ +/* RTAS (run-time abstraction services) */ +/************************************************************************/ + +DECLARE_NODE( rtas, INSTALL_OPEN, 0, "+/rtas" ); + +/* ( physbase -- rtas_callback ) */ +static void +rtas_instantiate( void ) +{ + int physbase = POP(); + int s=0x1000, size = (int)of_rtas_end - (int)of_rtas_start; + unsigned long virt; + + while( s < size ) + s += 0x1000; + virt = ofmem_claim_virt( 0, s, 0x1000 ); + ofmem_map( physbase, virt, s, -1 ); + memcpy( (char*)virt, of_rtas_start, size ); + + printk("RTAS instantiated at %08x\n", physbase ); + flush_icache_range( (char*)virt, (char*)virt + size ); + + PUSH( physbase ); +} + +NODE_METHODS( rtas ) = { + { "instantiate", rtas_instantiate }, + { "instantiate-rtas", rtas_instantiate }, +}; + + + +/************************************************************************/ +/* stdout */ +/************************************************************************/ + +DECLARE_NODE( video_stdout, INSTALL_OPEN, 0, "Tdisplay" ); + +/* ( addr len -- actual ) */ +static void +stdout_write( void ) +{ + int len = POP(); + char *addr = (char*)POP(); + + /* printk( "%s", s ); */ + console_draw_fstr(addr, len); + + PUSH( len ); +} + +NODE_METHODS( video_stdout ) = { + { "write", stdout_write }, +}; + + +/************************************************************************/ +/* tty */ +/************************************************************************/ + +DECLARE_NODE( tty, INSTALL_OPEN, 0, "+/mol/mol-tty" ); + +/* ( addr len -- actual ) */ +static void +tty_read( void ) +{ + int ch, len = POP(); + char *p = (char*)POP(); + int ret=0; + + if( len > 0 ) { + ret = 1; + ch = OSI_TTYGetc(); + if( ch >= 0 ) { + *p = ch; + } else { + ret = 0; + OSI_USleep(1); + } + } + PUSH( ret ); +} + +/* ( addr len -- actual ) */ +static void +tty_write( void ) +{ + int i, len = POP(); + char *p = (char*)POP(); + for( i=0; i<len; i++ ) + OSI_TTYPutc( *p++ ); + RET( len ); +} + +NODE_METHODS( tty ) = { + { "read", tty_read }, + { "write", tty_write }, +}; + + +/************************************************************************/ +/* keyboard */ +/************************************************************************/ + +typedef struct { + int cntrl; + int shift; + int meta; + int alt; + int save_key; + char keytable[32]; +} kbd_state_t; + +static const unsigned char adb_ascii_table[128] = + /* 0x00 */ "asdfhgzxcv`bqwer" + /* 0x10 */ "yt123465=97-80]o" + /* 0x20 */ "u[ip\nlj'k;\\,/nm." + /* 0x30 */ "\t <\b \e " + /* 0x40 */ " . * + / - " + /* 0x50 */ " =01234567 89 " + /* 0x60 */ " " + /* 0x70 */ " "; + +static const unsigned char adb_shift_table[128] = + /* 0x00 */ "ASDFHGZXCV~BQWER" + /* 0x10 */ "YT!@#$^%+(&_*)}O" + /* 0x20 */ "U{IP\nLJ\"K:|<?NM>" + /* 0x30 */ "\t <\b \e " + /* 0x40 */ " . * + / - " + /* 0x50 */ " =01234567 89 " + /* 0x60 */ " " + /* 0x70 */ " "; + +DECLARE_NODE( kbd, INSTALL_OPEN, sizeof(kbd_state_t), + "/psuedo-hid/keyboard", + "/mol/mol-keyboard", + "/mol/keyboard" +); + +/* ( -- keymap ) (?) */ +/* should return a pointer to an array with 32 bytes (256 bits) */ +static void +kbd_get_key_map( kbd_state_t *ks ) +{ + /* printk("met_kbd_get_key_map\n"); */ + + /* keytable[5] = 0x40; */ + PUSH( (int)ks->keytable ); +} + +/* ( buf len --- actlen ) */ +static void +kbd_read( kbd_state_t *ks ) +{ + int ret=0, len = POP(); + char *p = (char*)POP(); + int key; + + if( !p || !len ) { + PUSH( -1 ); + return; + } + + if( ks->save_key ) { + *p = ks->save_key; + ks->save_key = 0; + RET( 1 ); + } + OSI_USleep(1); /* be nice */ + + for( ; (key=OSI_GetAdbKey()) >= 0 ; ) { + int code = (key & 0x7f); + int down = !(key & 0x80); + + if( code == 0x36 /* ctrl */ ) { + ks->cntrl = down; + continue; + } + if( code == 0x38 /* shift */ || code == 0x7b) { + ks->shift = down; + continue; + } + if( code == 0x37 /* command */ ) { + ks->meta = down; + continue; + } + if( code == 0x3a /* alt */ ) { + ks->alt = down; + continue; + } + if( !down ) + continue; + + ret = 1; + if( ks->shift ) + key = adb_shift_table[ key & 0x7f ]; + else + key = adb_ascii_table[ key & 0x7f ]; + + if( ks->meta ) { + ks->save_key = key; + key = 27; + } else if( ks->cntrl ) { + key = key - 'a' + 1; + } + *p = key; + if( !*p ) + *p = 'x'; + break; + } + PUSH( ret ); +} + +NODE_METHODS( kbd ) = { + { "read", kbd_read }, + { "get-key-map", kbd_get_key_map }, +}; + + +/************************************************************************/ +/* client interface 'quiesce' */ +/************************************************************************/ + +DECLARE_NODE( ciface, 0, 0, "/packages/client-iface" ); + +/* ( -- ) */ +static void +ciface_quiesce( unsigned long args[], unsigned long ret[] ) +{ +#if 0 + unsigned long msr; + /* This seems to be the correct thing to do - but I'm not sure */ + asm volatile("mfmsr %0" : "=r" (msr) : ); + msr &= ~(MSR_IR | MSR_DR); + asm volatile("mtmsr %0" :: "r" (msr) ); +#endif + printk("=============================================================\n\n"); + prom_close(); + + OSI_KbdCntrl( kKbdCntrlSuspend ); +} + +/* ( -- ms ) */ +static void +ciface_milliseconds( unsigned long args[], unsigned long ret[] ) +{ + static unsigned long mticks=0, usecs=0; + unsigned long t; + + asm volatile("mftb %0" : "=r" (t) : ); + if( mticks ) + usecs += OSI_MticksToUsecs( t-mticks ); + mticks = t; + + PUSH( usecs/1000 ); +} + + +NODE_METHODS( ciface ) = { + { "quiesce", ciface_quiesce }, + { "milliseconds", ciface_milliseconds }, +}; + + +/************************************************************************/ +/* MMU/memory methods */ +/************************************************************************/ + +DECLARE_NODE( memory, INSTALL_OPEN, 0, "/memory" ); +DECLARE_NODE( mmu, INSTALL_OPEN, 0, "/cpus/@0" ); +DECLARE_NODE( mmu_ciface, 0, 0, "/packages/client-iface" ); + + +/* ( phys size align --- base ) */ +static void +mem_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_phys( phys, size, align ); + + if( ret == -1 ) { + printk("MEM: claim failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mem_release( void ) +{ + POP(); POP(); +} + +/* ( phys size align --- base ) */ +static void +mmu_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align ); + + if( ret == -1 ) { + printk("MMU: CLAIM failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mmu_release( void ) +{ + POP(); POP(); +} + +/* ( phys virt size mode -- [ret???] ) */ +static void +mmu_map( void ) +{ + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret; + + /* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ + ret = ofmem_map( phys, virt, size, mode ); + + if( ret ) { + printk("MMU: map failure\n"); + throw( -13 ); + return; + } +} + +/* ( virt size -- ) */ +static void +mmu_unmap( void ) +{ + POP(); POP(); +} + +/* ( virt -- false | phys mode true ) */ +static void +mmu_translate( void ) +{ + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode ); + + if( phys == -1 ) { + PUSH( 0 ); + } else { + PUSH( phys ); + PUSH( mode ); + PUSH( -1 ); + } +} + +/* ( virt size align -- baseaddr|-1 ) */ +static void +ciface_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align ); + + /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ + PUSH( ret ); +} + +/* ( virt size -- ) */ +static void +ciface_release( void ) +{ + POP(); + POP(); +} + + +NODE_METHODS( memory ) = { + { "claim", mem_claim }, + { "release", mem_release }, +}; + +NODE_METHODS( mmu ) = { + { "claim", mmu_claim }, + { "release", mmu_release }, + { "map", mmu_map }, + { "unmap", mmu_unmap }, + { "translate", mmu_translate }, +}; + +NODE_METHODS( mmu_ciface ) = { + { "cif-claim", ciface_claim }, + { "cif-release", ciface_release }, +}; + + +/************************************************************************/ +/* init */ +/************************************************************************/ + +void +node_methods_init( void ) +{ + REGISTER_NODE( rtas ); + REGISTER_NODE( powermgt ); + REGISTER_NODE( kbd ); + REGISTER_NODE( video_stdout ); + REGISTER_NODE( ciface ); + REGISTER_NODE( memory ); + REGISTER_NODE( mmu ); + REGISTER_NODE( mmu_ciface ); + + if( OSI_CallAvailable(OSI_TTY_GETC) ) + REGISTER_NODE( tty ); + + OSI_KbdCntrl( kKbdCntrlActivate ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/mol.c b/qemu/roms/openbios/arch/ppc/mol/mol.c new file mode 100644 index 000000000..86b3b66bf --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/mol.c @@ -0,0 +1,165 @@ +/* + * Creation Date: <2003/12/19 18:46:21 samuel> + * Time-stamp: <2004/04/12 16:27:12 samuel> + * + * <mol.c> + * + * + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/nvram.h" +#include "libc/vsprintf.h" +#include "libc/string.h" +#include "mol/mol.h" +#include "osi_calls.h" +#include <stdarg.h> + +void +exit( int status ) +{ + OSI_Exit(); +} + +void +fatal_error( const char *err ) +{ + printk("Fatal error: %s\n", err ); + OSI_Exit(); +} + +void +panic( const char *err ) +{ + printk("Panic: %s\n", err ); + OSI_Exit(); + + /* won't come here... this keeps the gcc happy */ + for( ;; ) + ; +} + + +/************************************************************************/ +/* print using OSI interface */ +/************************************************************************/ + +static int do_indent; + +int +printk( const char *fmt, ... ) +{ + char *p, buf[1024]; + va_list args; + int i; + + va_start(args, fmt); + i = vnsprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) { + if( *p == '\n' ) + do_indent = 0; + if( do_indent++ == 1 ) { + OSI_PutC( '>' ); + OSI_PutC( '>' ); + OSI_PutC( ' ' ); + } + OSI_PutC( *p ); + } + return i; +} + + +/************************************************************************/ +/* TTY iface */ +/************************************************************************/ + +static int ttychar = -1; + +static int +tty_avail( void ) +{ + return OSI_CallAvailable( OSI_TTY_GETC ); +} + +int +availchar( void ) +{ + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + ttychar = OSI_TTYGetc(); + if( ttychar < 0 ) + OSI_USleep(1); + return (ttychar >= 0); +} + +int +getchar( void ) +{ + int ch; + + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + return OSI_TTYGetc(); + ch = ttychar; + ttychar = -1; + return ch; +} + +int +putchar( int c ) +{ + printk("%c", c ); + + if( tty_avail() ) + OSI_TTYPutc( c ); + return c; +} + + +/************************************************************************/ +/* MOL specific stuff */ +/************************************************************************/ + +int +arch_nvram_size( void ) +{ + return OSI_NVRamSize(); +} + +void +arch_nvram_put( char *buf ) +{ + int i, size = arch_nvram_size(); + + for( i=0; i<size; i++ ) + OSI_WriteNVRamByte( i, buf[i] ); +} + +void +arch_nvram_get( char *buf ) +{ + int i, size = arch_nvram_size(); + + /* support for zapping the nvram */ + if( get_bool_res("zap_nvram") == 1 ) { + memset( buf, 0, size ); + return; + } + + for( i=0; i<size; i++ ) + buf[i] = OSI_ReadNVRamByte( i ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/mol.fs b/qemu/roms/openbios/arch/ppc/mol/mol.fs new file mode 100644 index 000000000..10c99bd79 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/mol.fs @@ -0,0 +1,107 @@ + + +\ ------------------------------------------------------------------------- +\ initialization +\ ------------------------------------------------------------------------- + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /cpus/@0" preopen + " stdout" " /packages/mol-stdout" preopen + " stdin" " keyboard" preopen + " nvram" " /pci/pci-bridge/mac-io/nvram" preopen + " nvram" " /mol/nvram" preopen + +; SYSTEM-initializer + + +\ ------------------------------------------------------------------------- +\ device tree fixing +\ ------------------------------------------------------------------------- + +\ add decode-address methods +: (make-decodable) ( phandle -- ) + + dup " #address-cells" rot get-package-property 0= if + decode-int nip nip + over " decode-unit" rot find-method if 2drop else + ( save phandle ncells ) + + over active-package! + case + 1 of ['] parse-hex " decode-unit" is-xt-func endof + 3 of + " bus-range" active-package get-package-property 0= if + decode-int nip nip + ['] encode-unit-pci " encode-unit" is-xt-func + " decode-unit" is-func-begin + ['] (lit) , , + ['] decode-unit-pci-bus , + is-func-end + then + endof + endcase + then + then + drop +; + +: tree-fixes ( -- ) + active-package + + iterate-tree-begin + begin ?dup while + + dup (make-decodable) + + iterate-tree + repeat + + active-package! +; + +\ use the tty interface if available +: activate-tty-interface + " /mol/mol-tty" find-dev if drop + " /mol/mol-tty" " input-device" $setenv + " /mol/mol-tty" " output-device" $setenv + then +; + +:noname + " keyboard" input +; CONSOLE-IN-initializer + + +\ ------------------------------------------------------------------------- +\ pre-booting +\ ------------------------------------------------------------------------- + +: update-chosen + " /chosen" find-device + stdin @ encode-int " stdin" property + stdout @ encode-int " stdout" property + device-end +; diff --git a/qemu/roms/openbios/arch/ppc/mol/mol.h b/qemu/roms/openbios/arch/ppc/mol/mol.h new file mode 100644 index 000000000..cea15a350 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/mol.h @@ -0,0 +1,44 @@ +/* + * Creation Date: <2003/12/20 00:20:12 samuel> + * Time-stamp: <2004/03/27 01:52:50 samuel> + * + * <mol.h> + * + * + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_MOL +#define _H_MOL + +/* video.c */ +extern void init_video( void ); +extern int video_get_res( int *w, int *h ); +extern void draw_pixel( int x, int y, int colind ); +extern void set_color( int index, unsigned long color ); + +/* console.c */ +extern int console_draw_fstr(const char *str, int len); +extern void console_close( void ); + +/* pseudodisk.c */ +extern void pseudodisk_init( void ); + +/* osi-blk.c */ +extern void osiblk_init( void ); + +/* osi-scsi.c */ +extern void osiscsi_init( void ); + +/* pseudofs.c */ +extern void pseudofs_init( void ); + +#include "../kernel.h" + +#endif /* _H_MOL */ diff --git a/qemu/roms/openbios/arch/ppc/mol/osi-blk.c b/qemu/roms/openbios/arch/ppc/mol/osi-blk.c new file mode 100644 index 000000000..4ed1b5ab3 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/osi-blk.c @@ -0,0 +1,119 @@ +/* + * Creation Date: <2003/12/07 19:08:33 samuel> + * Time-stamp: <2004/01/07 19:38:36 samuel> + * + * <osi-blk.c> + * + * OSI-block interface + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "mol/mol.h" +#include "osi_calls.h" + +typedef struct { + int unit; + int channel; +} osiblk_data_t; + + +DECLARE_NODE( osiblk, INSTALL_OPEN, sizeof(osiblk_data_t), + "/pci/pci-bridge/mol-blk/disk", "/mol/mol-blk" ); + + +static void +osiblk_open( osiblk_data_t *pb ) +{ + phandle_t ph; + + fword("my-unit"); + pb->unit = POP(); + pb->channel = 0; /* FIXME */ + + selfword("open-deblocker"); + + /* interpose disk-label */ + ph = find_dev("/packages/disk-label"); + fword("my-args"); + PUSH_ph( ph ); + fword("interpose"); + + /* printk("osi-blk: open %d\n", pb->unit ); */ + PUSH( -1 ); +} + +static void +osiblk_close( osiblk_data_t *pb ) +{ + selfword("close-deblocker"); +} + + +/* ( buf blk nblks -- actual ) */ +static void +osiblk_read_blocks( osiblk_data_t *pb ) +{ + int i, n = POP(); + int blk = POP(); + char *dest = (char*)POP(); + + /* printk("osiblk_read_blocks %x block=%d n=%d\n", (int)dest, blk, n ); */ + + for( i=0; i<n; ) { + char buf[4096]; + int m = MIN( n-i, sizeof(buf)/512 ); + + if( OSI_ABlkSyncRead(pb->channel, pb->unit, blk+i, (int)buf, m*512) < 0 ) { + printk("SyncRead: error\n"); + RET(0); + } + memcpy( dest, buf, m * 512 ); + i += m; + dest += m * 512; + } + PUSH( n ); +} + +/* ( -- bs ) */ +static void +osiblk_block_size( osiblk_data_t *pb ) +{ + PUSH( 512 ); +} + +/* ( -- maxbytes ) */ +static void +osiblk_max_transfer( osiblk_data_t *pb ) +{ + PUSH( 1024*1024 ); +} + +static void +osiblk_initialize( osiblk_data_t *pb ) +{ + fword("is-deblocker"); +} + + +NODE_METHODS( osiblk ) = { + { NULL, osiblk_initialize }, + { "open", osiblk_open }, + { "close", osiblk_close }, + { "read-blocks", osiblk_read_blocks }, + { "block-size", osiblk_block_size }, + { "max-transfer", osiblk_max_transfer }, +}; + +void +osiblk_init( void ) +{ + REGISTER_NODE( osiblk ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/osi-scsi.c b/qemu/roms/openbios/arch/ppc/mol/osi-scsi.c new file mode 100644 index 000000000..18f3dc577 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/osi-scsi.c @@ -0,0 +1,271 @@ +/* + * Creation Date: <2003/12/11 21:23:54 samuel> + * Time-stamp: <2004/01/07 19:38:45 samuel> + * + * <osi-scsi.c> + * + * SCSI device node + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "mol/mol.h" +#include "scsi_sh.h" +#include "osi_calls.h" + +#define MAX_TARGETS 32 + +typedef struct { + int probed; + int valid; /* a useable device found */ + + int is_cd; + int blocksize; +} target_info_t; + +static target_info_t scsi_devs[ MAX_TARGETS ]; + +typedef struct { + int target; + target_info_t *info; +} instance_data_t; + + +DECLARE_NODE( scsi, INSTALL_OPEN, sizeof(instance_data_t), + "/pci/pci-bridge/mol-scsi/sd", "/mol/mol-scsi/sd" ); + + +static int +scsi_cmd_( instance_data_t *sd, const char *cmd, int cmdlen, char *dest, + int len, int prelen, int postlen ) +{ + char prebuf[4096], postbuf[4096]; + scsi_req_t r[2]; /* the [2] is a hack to get space for the sg-list */ + char sb[32]; + + /* memset( dest, 0, len ); */ + + if( (unsigned int)prelen > sizeof(prebuf) || (unsigned int)postlen > sizeof(postbuf) ) { + printk("bad pre/post len %d %d\n", prelen, postlen ); + return 1; + } + + memset( r, 0, sizeof(r[0]) ); + r->lun = 0; + r->target = sd->target; + r->is_write = 0; + memcpy( r->cdb, cmd, cmdlen ); + r->client_addr = (int)&r; + r->cdb_len = cmdlen; + r->sense[0].base = (int)&sb; + r->sense[0].size = sizeof(sb); + r->size = prelen + len + postlen; + r->n_sg = 3; + r->sglist.n_el = 3; + r->sglist.vec[0].base = (int)prebuf; + r->sglist.vec[0].size = prelen; + r->sglist.vec[1].base = (int)dest; + r->sglist.vec[1].size = len; + r->sglist.vec[2].base = (int)postbuf; + r->sglist.vec[2].size = postlen; + + if( OSI_SCSISubmit((int)&r) ) { + printk("OSI_SCSISubmit: error!\n"); + return 1; + } + while( !OSI_SCSIAck() ) + OSI_USleep( 10 ); + + if( r->adapter_status ) + return -1; + if( r->scsi_status ) + return ((sb[2] & 0xf) << 16) | (sb[12] << 8) | sb[13]; + return 0; +} + +static int +scsi_cmd( instance_data_t *sd, const char *cmd, int cmdlen ) +{ + return scsi_cmd_( sd, cmd, cmdlen, NULL, 0, 0, 0 ); +} + +/* ( buf blk nblks -- actual ) */ +static void +scsi_read_blocks( instance_data_t *sd ) +{ + int nblks = POP(); + int blk = POP(); + char *dest = (char*)POP(); + unsigned char cmd[10]; + int len = nblks * sd->info->blocksize; + + memset( dest, 0, len ); + + /* printk("READ: blk: %d length %d\n", blk, len ); */ + memset( cmd, 0, sizeof(cmd) ); + cmd[0] = 0x28; /* READ_10 */ + cmd[2] = blk >> 24; + cmd[3] = blk >> 16; + cmd[4] = blk >> 8; + cmd[5] = blk; + cmd[7] = nblks >> 8; + cmd[8] = nblks; + + if( scsi_cmd_(sd, cmd, 10, dest, len, 0, 0) ) { + printk("read: scsi_cmd failed\n"); + RET( -1 ); + } + PUSH( nblks ); +} + +static int +inquiry( instance_data_t *sd ) +{ + char inquiry_cmd[6] = { 0x12, 0, 0, 0, 32, 0 }; + char start_stop_unit_cmd[6] = { 0x1b, 0, 0, 0, 1, 0 }; + char test_unit_ready_cmd[6] = { 0x00, 0, 0, 0, 0, 0 }; + char prev_allow_medium_removal[6] = { 0x1e, 0, 0, 0, 1, 0 }; + char set_cd_speed_cmd[12] = { 0xbb, 0, 0xff, 0xff, 0xff, 0xff, + 0, 0, 0, 0, 0, 0 }; + target_info_t *info = &scsi_devs[sd->target]; + char ret[32]; + int i, sense; + + if( sd->target >= MAX_TARGETS ) + return -1; + sd->info = info; + + if( info->probed ) + return info->valid ? 0:-1; + info->probed = 1; + + if( (sense=scsi_cmd_(sd, inquiry_cmd, 6, ret, 2, 0, 0)) ) { + if( sense < 0 ) + return -1; + printk("INQUIRY failed\n"); + return -1; + } + + /* medium present? */ + if( (scsi_cmd(sd, test_unit_ready_cmd, 6) >> 8) == 0x23a ) { + printk("no media\n"); + return -1; + } + + info->is_cd = 0; + info->blocksize = 512; + + if( ret[0] == 5 /* CD/DVD */ ) { + info->blocksize = 2048; + info->is_cd = 1; + + scsi_cmd( sd, prev_allow_medium_removal, 6 ); + scsi_cmd( sd, set_cd_speed_cmd, 12 ); + scsi_cmd( sd, start_stop_unit_cmd, 6 ); + + } else if( ret[0] == 0 /* DISK */ ) { + scsi_cmd( sd, test_unit_ready_cmd, 6 ); + scsi_cmd( sd, start_stop_unit_cmd, 6 ); + } else { + /* don't boot from this device (could be a scanner :-)) */ + return -1; + } + + /* wait for spin-up (or whatever) to complete */ + for( i=0; ; i++ ) { + if( i > 300 ) { + printk("SCSI timeout (sense %x)\n", sense ); + return -1; + } + sense = scsi_cmd( sd, test_unit_ready_cmd, 6 ); + if( (sense & 0xf0000) == 0x20000 ) { + OSI_USleep( 10000 ); + continue; + } + break; + } + + info->valid = 1; + return 0; +} + +/* ( -- success? ) */ +static void +scsi_open( instance_data_t *sd ) +{ + static int once = 0; + phandle_t ph; + + fword("my-unit"); + sd->target = POP(); + + if( !once ) { + once++; + OSI_SCSIControl( SCSI_CTRL_INIT, 0 ); + } + + /* obtiain device information */ + if( inquiry(sd) ) + RET(0); + + selfword("open-deblocker"); + + /* interpose disk-label */ + ph = find_dev("/packages/disk-label"); + fword("my-args"); + PUSH_ph( ph ); + fword("interpose"); + + PUSH( -1 ); +} + +/* ( -- ) */ +static void +scsi_close( instance_data_t *pb ) +{ + selfword("close-deblocker"); +} + + +/* ( -- bs ) */ +static void +scsi_block_size( instance_data_t *sd ) +{ + PUSH( sd->info->blocksize ); +} + +/* ( -- maxbytes ) */ +static void +scsi_max_transfer( instance_data_t *sd ) +{ + PUSH( 1024*1024 ); +} + +static void +scsi_initialize( instance_data_t *sd ) +{ + fword("is-deblocker"); +} + + +NODE_METHODS( scsi ) = { + { NULL, scsi_initialize }, + { "open", scsi_open }, + { "close", scsi_close }, + { "read-blocks", scsi_read_blocks }, + { "block-size", scsi_block_size }, + { "max-transfer", scsi_max_transfer }, +}; + +void +osiscsi_init( void ) +{ + REGISTER_NODE( scsi ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/prom.c b/qemu/roms/openbios/arch/ppc/mol/prom.c new file mode 100644 index 000000000..0bc8bcfbc --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/prom.c @@ -0,0 +1,175 @@ +/* + * Creation Date: <2002/10/03 20:55:02 samuel> + * Time-stamp: <2002/10/29 13:00:23 samuel> + * + * <prom.c> + * + * oftree interface + * + * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "osi_calls.h" +#include "mol/prom.h" + +/* OSI_PromClose (free linux side device tree) */ +int +prom_close( void ) +{ + return OSI_PromIface( kPromClose, 0 ); +} + +/* ret: 0 no more peers, -1 if error */ +mol_phandle_t +prom_peer( mol_phandle_t phandle ) +{ + return OSI_PromIface( kPromPeer, phandle ); +} + +/* ret: 0 no child, -1 if error */ +mol_phandle_t +prom_child( mol_phandle_t phandle ) +{ + return OSI_PromIface( kPromChild, phandle ); +} + +/* ret: 0 if root node, -1 if error */ +mol_phandle_t +prom_parent( mol_phandle_t phandle ) +{ + return OSI_PromIface( kPromParent, phandle ); +} + +/* ret: -1 error */ +int +prom_package_to_path( mol_phandle_t phandle, char *buf, long buflen ) +{ + return OSI_PromIface2( kPromPackageToPath, phandle, (int)buf, buflen ); +} + +/* ret: -1 error */ +int +prom_get_prop_len( mol_phandle_t phandle, const char *name ) +{ + return OSI_PromIface1( kPromGetPropLen, phandle, (int)name ); +} + +/* ret: prop len or -1 if error */ +int +prom_get_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen ) +{ + return OSI_PromIface3( kPromGetProp, phandle, (int)name, (int)buf, buflen ); +} + +/* ret: prop len or -1 if error */ +int +prom_get_prop_by_path( const char *path, const char *name, char *buf, long buflen ) +{ + mol_phandle_t ph = prom_find_device(path); + return (ph != -1)? prom_get_prop( ph, name, buf, buflen) : -1; +} + +/* ret: -1 error, 0 last prop, 1 otherwise */ +int +prom_next_prop( mol_phandle_t phandle, const char *prev, char *buf ) +{ + return OSI_PromIface2( kPromNextProp, phandle, (int)prev, (int)buf ); +} + +/* ret: -1 if error */ +int +prom_set_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen ) +{ + return OSI_PromIface3( kPromSetProp, phandle, (int)name, (int)buf, buflen ); +} + +/* ret: -1 if error */ +mol_phandle_t +prom_create_node( const char *path ) +{ + return OSI_PromPathIface( kPromCreateNode, path ); +} + +/* ret: -1 if not found */ +mol_phandle_t +prom_find_device( const char *path ) +{ + mol_phandle_t ph; + char buf2[256], ch, *p; + + if( !path ) + return -1; + + if( (ph=OSI_PromPathIface( kPromFindDevice, path )) != -1 ) + return ph; + else if( path[0] == '/' ) + return -1; + + /* might be an alias */ + if( !(p=strpbrk(path, "@:/")) ) + p = (char*)path + strlen(path); + + ch = *p; + *p = 0; + if( (ph=prom_get_prop(prom_find_device("/aliases"), path, buf2, sizeof(buf2))) == -1 ) + return -1; + *p = ch; + strncat( buf2, p, sizeof(buf2) ); + + if( buf2[0] != '/' ) { + printk("Error: aliases must be absolute!\n"); + return -1; + } + ph = OSI_PromPathIface( kPromFindDevice, buf2 ); + return ph; +} + + + +/************************************************************************/ +/* search the tree for nodes with matching device_type */ +/************************************************************************/ + +static mol_phandle_t +prom_find_device_type_( mol_phandle_t ph, const char *type, int *icount, int index ) +{ + char buf[64]; + int ph2; + + if( ph == -1 || !ph ) + return -1; + if( prom_get_prop( ph, "device_type", buf, sizeof(buf)) > 0 ) + if( !strcmp(buf, type) ) + if( (*icount)++ == index ) + return ph; + if( (ph2=prom_find_device_type_( prom_peer(ph), type, icount, index )) != -1 ) + return ph2; + if( (ph2=prom_find_device_type_( prom_child(ph), type, icount, index )) != -1 ) + return ph2; + return -1; +} + +mol_phandle_t +prom_find_device_type( const char *type, int index ) +{ + int count = 0; + return prom_find_device_type_( prom_peer(0), type, &count, index ); +} + + +/************************************************************************/ +/* device tree tweaking */ +/************************************************************************/ + +/* -1 if error */ +int +prom_change_phandle( mol_phandle_t old_ph, mol_phandle_t new_ph ) +{ + return OSI_PromIface1( kPromChangePHandle, old_ph, (int)new_ph ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/prom.h b/qemu/roms/openbios/arch/ppc/mol/prom.h new file mode 100644 index 000000000..54a856c27 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/prom.h @@ -0,0 +1,47 @@ +/* + * Creation Date: <2002/10/03 21:07:27 samuel> + * Time-stamp: <2003/10/22 22:45:26 samuel> + * + * <prom.h> + * + * device tree interface + * + * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_PROM +#define _H_PROM + +/* Note 1: MOL uses -1 as the invalid phandle while OpenFirmware uses 0 as the + * invalid phandle (it is also the root node). + * + * Note 2: phandles might be negative. For instance, phandles originating from + * a real Open Firmware tree might look like 0xff123000 (a ROM address)... + */ + +typedef enum { kGetRootPhandle=0 } mol_phandle_t; /* must promote to int */ + +extern int prom_close( void ); + +extern mol_phandle_t prom_peer( mol_phandle_t phandle ); +extern mol_phandle_t prom_child( mol_phandle_t phandle ); +extern mol_phandle_t prom_parent( mol_phandle_t phandle ); +extern int prom_package_to_path( mol_phandle_t phandle, char *buf, long buflen ); +extern int prom_get_prop_len( mol_phandle_t phandle, const char *name ); +extern int prom_get_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen ); +extern int prom_get_prop_by_path( const char *path, const char *name, char *buf, long buflen ); +extern int prom_next_prop( mol_phandle_t phandle, const char *prev, char *buf ); +extern int prom_set_prop( mol_phandle_t phandle, const char *name, char *buf, long buflen ); +extern mol_phandle_t prom_create_node( const char *path ); +extern mol_phandle_t prom_find_device( const char *path ); + +extern mol_phandle_t prom_find_device_type( const char *type, int index ); + +extern int prom_change_phandle( mol_phandle_t old_ph, mol_phandle_t new_ph ); + +#endif /* _H_PROM */ diff --git a/qemu/roms/openbios/arch/ppc/mol/pseudodisk.c b/qemu/roms/openbios/arch/ppc/mol/pseudodisk.c new file mode 100644 index 000000000..a98e54845 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/pseudodisk.c @@ -0,0 +1,178 @@ +/* + * Creation Date: <2003/11/26 16:55:47 samuel> + * Time-stamp: <2004/01/07 19:41:54 samuel> + * + * <pseudodisk.c> + * + * pseudodisk (contains files exported from linux) + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "osi_calls.h" +#include "libc/string.h" +#include "libopenbios/ofmem.h" +#include "mol/prom.h" +#include "mol/mol.h" +#include "osi_calls.h" +#include "pseudofs_sh.h" + +typedef struct { + int seekpos; + int fd; + char *myargs; + char *name; + int size; +} pdisk_data_t; + + +DECLARE_NODE( pdisk, INSTALL_OPEN, sizeof(pdisk_data_t), "/mol/pseudo-disk/disk" ); + +static void +pdisk_open( pdisk_data_t *pb ) +{ + char *ep, *name = NULL; + int part; + + pb->myargs = my_args_copy(); + /* printk("pdisk-open: %s\n", pb->myargs ); */ + + part = strtol( pb->myargs, &ep, 10 ); + if( *ep ) { + if( (name=strchr(pb->myargs, ',')) ) { + *name = 0; + name++; + } else { + name = pb->myargs; + } + } + if( part ) + goto err; + + if( !name || !strlen(name) ) + pb->fd = -1; + else { + if( (pb->fd=PseudoFSOpen(name)) < 0 ) + goto err; + pb->size = PseudoFSGetSize( pb->fd ); + } + pb->name = name; + RET( -1 ); + err: + free( pb->myargs ); + RET(0); +} + +/* ( addr len -- actual ) */ +static void +pdisk_read( pdisk_data_t *pb ) +{ + int len = POP(); + char *dest = (char*)POP(); + int cnt; + + if( pb->fd < 0 ) { + memset( dest, 0, len ); + PUSH(len); + return; + } + /* dest is not "mol-DMA" safe (might have a nontrivial mapping) */ + for( cnt=0; cnt<len; ) { + char buf[2048]; + int n = MIN( len-cnt, sizeof(buf) ); + + n = PseudoFSRead( pb->fd, pb->seekpos, buf, n ); + if( n <= 0 ) + break; + + memcpy( dest+cnt, buf, n ); + cnt += n; + pb->seekpos += n; + } + PUSH( cnt ); +} + +/* ( addr len -- actual ) */ +static void +pdisk_write( pdisk_data_t *pb ) +{ + POP(); POP(); PUSH(-1); + printk("pdisk write\n"); +} + +/* ( pos.lo pos.hi -- status ) */ +static void +pdisk_seek( pdisk_data_t *pb ) +{ + int pos_lo; + POP(); + pos_lo = POP(); + + if( pb->fd >= 0 ) { + if( pos_lo == -1 ) + pos_lo = pb->size; + } + + pb->seekpos = pos_lo; + + PUSH(0); /* ??? */ +} + +/* ( -- pos.d ) */ +static void +pdisk_tell( pdisk_data_t *pb ) +{ + DPUSH( pb->seekpos ); +} + +/* ( -- cstr ) */ +static void +pdisk_get_path( pdisk_data_t *pb ) +{ + PUSH( (int)pb->name ); +} + +/* ( -- cstr ) */ +static void +pdisk_get_fstype( pdisk_data_t *pb ) +{ + PUSH( (int)"PSEUDO" ); +} + +/* ( -- cstr ) */ +static void +pdisk_volume_name( pdisk_data_t *pb ) +{ + PUSH( (int)"Virtual Volume" ); +} + +static void +pdisk_block_size( pdisk_data_t *pb ) +{ + PUSH(1); +} + +NODE_METHODS( pdisk ) = { + { "open", pdisk_open }, + { "read", pdisk_read }, + { "write", pdisk_write }, + { "seek", pdisk_seek }, + { "tell", pdisk_tell }, + { "block-size", pdisk_block_size }, + { "get-path", pdisk_get_path }, + { "get-fstype", pdisk_get_fstype }, + { "volume-name", pdisk_volume_name }, +}; + +void +pseudodisk_init( void ) +{ + REGISTER_NODE( pdisk ); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/tree.c b/qemu/roms/openbios/arch/ppc/mol/tree.c new file mode 100644 index 000000000..b82c8c2c8 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/tree.c @@ -0,0 +1,165 @@ +/* + * Creation Date: <2003/11/18 14:55:05 samuel> + * Time-stamp: <2004/03/27 02:03:55 samuel> + * + * <tree.c> + * + * device tree setup + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "mol/mol.h" +#include "mol/prom.h" + + +/************************************************************************/ +/* copy device tree */ +/************************************************************************/ + +static void +copy_node( mol_phandle_t molph ) +{ + char name[40], path[80]; + int exists; + phandle_t ph; + + if( !molph ) + return; + + prom_package_to_path( molph, path, sizeof(path) ); + + /* don't copy /options node */ + if( !strcmp("/options", path) ) { + copy_node( prom_peer(molph) ); + return; + } + + exists = 1; + if( !(ph=find_dev(path)) ) { + exists = 0; + fword("new-device"); + ph = get_cur_dev(); + } + activate_dev( ph ); + + name[0] = 0; + while( prom_next_prop(molph, name, name) > 0 ) { + int len = prom_get_prop_len( molph, name ); + char *p; +#if 0 + if( len > 0x1000 ) { + printk("prop to large (%d)\n", len ); + continue; + } +#endif + /* don't copy /chosen/{stdin,stdout} (XXX: ugly hack...) */ + if( !strcmp("/chosen", path) ) + if( !strcmp("stdio", name) || !strcmp("stdout", name) ) + continue; + + p = malloc( len ); + prom_get_prop( molph, name, p, len ); + set_property( ph, name, p, len ); + free( p ); + } + + set_int_property( ph, "MOL,phandle", molph ); + copy_node( prom_child(molph) ); + + if( !exists ) + fword("finish-device"); + else + activate_device(".."); + + copy_node( prom_peer(molph) ); +} + + + +/************************************************************************/ +/* device tree cloning and tweaking */ +/************************************************************************/ + +static phandle_t +translate_molph( mol_phandle_t molph ) +{ + static mol_phandle_t cached_molph; + static phandle_t cached_ph; + phandle_t ph=0; + + if( cached_molph == molph ) + return cached_ph; + + while( (ph=dt_iterate(ph)) ) + if( get_int_property(ph, "MOL,phandle", NULL) == molph ) + break; + cached_molph = molph; + cached_ph = ph; + + if( !ph ) + printk("failed to translate molph\n"); + return ph; +} + +static void +fix_phandles( void ) +{ + static char *pnames[] = { "interrupt-parent", "interrupt-controller", NULL } ; + int len, *map; + phandle_t ph=0; + char **pp; + + while( (ph=dt_iterate(ph)) ) { + for( pp=pnames; *pp; pp++ ) { + phandle_t *p = (phandle_t*)get_property( ph, *pp, &len ); + if( len == 4 ) + *p = translate_molph( *(int*)p ); + } + + /* need to fix interrupt map properties too */ + if( (map=(int*)get_property(ph, "interrupt-map", &len)) ) { + int i, acells = get_int_property(ph, "#address-cells", NULL); + int icells = get_int_property(ph, "#interrupt-cells", NULL); + + len /= sizeof(int); + for( i=0; i<len; i++ ) { + phandle_t ch_ph; + int ch_acells, ch_icells; + + i += acells + icells; + if( !(ch_ph=translate_molph(map[i])) ) + break; + map[i] = (int)ch_ph; + ch_acells = get_int_property(ch_ph, "#address-cells", NULL); + ch_icells = get_int_property(ch_ph, "#interrupt-cells", NULL); + i += ch_acells + icells; + } + if( i != len ) + printk("interrupt map fixing failure\n"); + } + } + /* delete MOL,phandle properties */ + for( ph=0; (ph=dt_iterate(ph)) ; ) { + push_str("MOL,phandle"); + PUSH_ph(ph); + fword("(delete-property)"); + } + fword("device-end"); +} + +void +devtree_init( void ) +{ + activate_device("/"); + copy_node( prom_peer(0) ); + fix_phandles(); + fword("tree-fixes"); +} diff --git a/qemu/roms/openbios/arch/ppc/mol/tree.fs b/qemu/roms/openbios/arch/ppc/mol/tree.fs new file mode 100644 index 000000000..228163ffc --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/mol/tree.fs @@ -0,0 +1,103 @@ + +: int-property ( val name -- ) + rot encode-int 2swap property +; + + +\ ------------------------------------------------------------- +\ device-tree +\ ------------------------------------------------------------- + +" /" find-device + + " device-tree" device-name + " bootrom" device-type + +\ ------------------------------------------------------------- +\ /memory +\ ------------------------------------------------------------- + +new-device + " memory" device-name + \ 12230 encode-int " reg" property + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +\ ------------------------------------------------------------- +\ /mol/ +\ ------------------------------------------------------------- + +new-device + " mol" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + +new-device + " test" device-name + + external + : open + ." /mol/test opened" cr + " argument-str" " ipose" find-package drop interpose + true + ; +finish-device +finish-device + +\ ------------------------------------------------------------- +\ /cpus/ +\ ------------------------------------------------------------- + +new-device + " cpus" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +finish-device + +\ ------------------------------------------------------------- +\ /packages +\ ------------------------------------------------------------- + +" /packages" find-device + + " packages" device-name + external + \ allow packages to be opened with open-dev + : open true ; + : close ; + +\ /packages/mol-stdout +new-device + " mol-stdout" device-name + external + : open true ; + : close ; + : write ( addr len -- actual ) + dup -rot type + ; +finish-device + +\ XXXXXXXXXXXXXXXXXXXXXXX TESTING +" /" find-device +new-device + " test" device-name +finish-device + +\ ------------------------------------------------------------- +\ The END +\ ------------------------------------------------------------- +device-end diff --git a/qemu/roms/openbios/arch/ppc/ofmem.c b/qemu/roms/openbios/arch/ppc/ofmem.c new file mode 100644 index 000000000..c9b066ed6 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/ofmem.c @@ -0,0 +1,308 @@ +/* + * Creation Date: <1999/11/07 19:02:11 samuel> + * Time-stamp: <2004/01/07 19:42:36 samuel> + * + * <ofmem.c> + * + * OF Memory manager + * + * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +/* TODO: Clean up MOLisms in a decent way */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "libopenbios/ofmem.h" +#include "kernel.h" +#ifdef I_WANT_MOLISMS +#include "mol/prom.h" +#include "mol/mol.h" +#endif +#include "mmutypes.h" +#include "asm/processor.h" +#ifdef I_WANT_MOLISMS +#include "osi_calls.h" +#endif + +#define BIT(n) (1U<<(31-(n))) + +/* called from assembly */ +extern void dsi_exception( void ); +extern void isi_exception( void ); +extern void setup_mmu( unsigned long code_base, unsigned long code_size, unsigned long ramsize ); + +/**************************************************************** + * Memory usage (before of_quiesce is called) + * + * Physical + * + * 0x00000000 Exception vectors + * 0x00004000 Free space + * 0x01e00000 Open Firmware (us) + * 0x01f00000 OF allocations + * 0x01ff0000 PTE Hash + * 0x02000000- Free space + * + * Allocations grow downwards from 0x01e00000 + * + ****************************************************************/ + +#define HASH_SIZE (2 << 15) +#define SEGR_BASE 0x400 /* segment number range to use */ + +#define FREE_BASE_1 0x00004000 +#define OF_CODE_START 0x01e00000 +/* #define OF_MALLOC_BASE 0x01f00000 */ +extern char _end[]; +#define OF_MALLOC_BASE _end + +#define HASH_BASE (0x02000000 - HASH_SIZE) +#define FREE_BASE_2 0x02000000 + +#define RAMSIZE 0x02000000 /* XXXXXXXXXXXXXXXXXXX FIXME XXXXXXXXXXXXXXX */ + +static ofmem_t s_ofmem; + +#define IO_BASE 0x80000000 +#define OFMEM (&s_ofmem) + +static inline unsigned long +get_hash_base( void ) +{ + return HASH_BASE; +} + +static inline unsigned long +get_hash_size( void ) +{ + return HASH_SIZE; +} + +static ucell get_heap_top( void ) +{ + return HASH_BASE; +} + +static inline size_t ALIGN_SIZE(size_t x, size_t a) +{ + return (x + a - 1) & ~(a-1); +} + +ofmem_t* ofmem_arch_get_private(void) +{ + return OFMEM; +} + +void* ofmem_arch_get_malloc_base(void) +{ + return OF_MALLOC_BASE; +} + +ucell ofmem_arch_get_heap_top(void) +{ + return get_heap_top(); +} + +ucell ofmem_arch_get_virt_top(void) +{ + return IO_BASE; +} + +void ofmem_arch_unmap_pages(ucell virt, ucell size) +{ + /* kill page mappings in provided range */ +} + +void ofmem_arch_map_pages(ucell phys, ucell virt, ucell size, ucell mode) +{ + /* none yet */ +} + +/************************************************************************/ +/* OF private allocations */ +/************************************************************************/ + +void * +malloc( int size ) +{ + return ofmem_malloc(size); +} + +void +free( void *ptr ) +{ + return ofmem_free(ptr); +} + +void * +realloc( void *ptr, size_t size ) +{ + return ofmem_realloc(ptr, size); +} + + +/************************************************************************/ +/* misc */ +/************************************************************************/ + +ucell ofmem_arch_default_translation_mode( ucell phys ) +{ + /* XXX: Guard bit not set as it should! */ + if( phys < IO_BASE || phys >= 0xffc00000 ) + return 0x02; /*0xa*/ /* wim GxPp */ + return 0x6a; /* WIm GxPp, I/O */ +} + + +/************************************************************************/ +/* page fault handler */ +/************************************************************************/ + +static ucell +ea_to_phys( ucell ea, ucell *mode ) +{ + ucell phys; + + /* hardcode our translation needs */ + if( ea >= OF_CODE_START && ea < FREE_BASE_2 ) { + *mode = ofmem_arch_default_translation_mode( ea ); + return ea; + } + + phys = ofmem_translate(ea, mode); + if( phys == (ucell)-1 ) { +#ifdef I_WANT_MOLISMS + if( ea != 0x80816c00 ) + printk("ea_to_phys: no translation for %08lx, using 1-1\n", ea ); +#endif + phys = ea; + *mode = ofmem_arch_default_translation_mode( phys ); + +#ifdef I_WANT_MOLISMS + forth_segv_handler( (char*)ea ); + OSI_Debugger(1); +#endif + /* print_virt_range(); */ + /* print_phys_range(); */ + /* print_trans(); */ + } + return phys; +} + +static void +hash_page( ucell ea, ucell phys, ucell mode ) +{ + static int next_grab_slot=0; + unsigned long *upte, cmp, hash1; + int i, vsid, found; + mPTE_t *pp; + + vsid = (ea>>28) + SEGR_BASE; + cmp = BIT(0) | (vsid << 7) | ((ea & 0x0fffffff) >> 22); + + hash1 = vsid; + hash1 ^= (ea >> 12) & 0xffff; + hash1 &= (get_hash_size() - 1) >> 6; + + pp = (mPTE_t*)(get_hash_base() + (hash1 << 6)); + upte = (unsigned long*)pp; + + /* replace old translation */ + for( found=0, i=0; !found && i<8; i++ ) + if( cmp == upte[i*2] ) + found=1; + + /* otherwise use a free slot */ + for( i=0; !found && i<8; i++ ) + if( !pp[i].v ) + found=1; + + /* out of slots, just evict one */ + if( !found ) { + i = next_grab_slot + 1; + next_grab_slot = (next_grab_slot + 1) % 8; + } + i--; + upte[i*2] = cmp; + upte[i*2+1] = (phys & ~0xfff) | mode; + + asm volatile( "tlbie %0" :: "r"(ea) ); +} + +void +dsi_exception( void ) +{ + unsigned long dar, dsisr; + ucell mode; + ucell phys; + + asm volatile("mfdar %0" : "=r" (dar) : ); + asm volatile("mfdsisr %0" : "=r" (dsisr) : ); + + //printk("dsi-exception @ %08lx <%08lx>\n", dar, dsisr ); + + phys = ea_to_phys(dar, &mode); + hash_page( dar, phys, mode ); +} + +void +isi_exception( void ) +{ + unsigned long nip, srr1; + ucell mode; + ucell phys; + + asm volatile("mfsrr0 %0" : "=r" (nip) : ); + asm volatile("mfsrr1 %0" : "=r" (srr1) : ); + + //printk("isi-exception @ %08lx <%08lx>\n", nip, srr1 ); + + phys = ea_to_phys(nip, &mode); + hash_page( nip, phys, mode ); +} + + +/************************************************************************/ +/* init / cleanup */ +/************************************************************************/ + +void +setup_mmu( unsigned long code_base, unsigned long code_size, unsigned long ramsize ) +{ + unsigned long sdr1 = HASH_BASE | ((HASH_SIZE-1) >> 16); + unsigned long sr_base = (0x20 << 24) | SEGR_BASE; + unsigned long msr; + int i; + + asm volatile("mtsdr1 %0" :: "r" (sdr1) ); + for( i=0; i<16; i++ ) { + int j = i << 28; + asm volatile("mtsrin %0,%1" :: "r" (sr_base + i), "r" (j) ); + } + asm volatile("mfmsr %0" : "=r" (msr) : ); + msr |= MSR_IR | MSR_DR; + asm volatile("mtmsr %0" :: "r" (msr) ); +} + +void +ofmem_init( void ) +{ + ofmem_t *ofmem = OFMEM; + /* In case we can't rely on memory being zero initialized */ + memset(ofmem, 0, sizeof(ofmem)); + + ofmem->ramsize = RAMSIZE; + + ofmem_claim_phys( 0, FREE_BASE_1, 0 ); + ofmem_claim_virt( 0, FREE_BASE_1, 0 ); + ofmem_claim_phys( OF_CODE_START, FREE_BASE_2 - OF_CODE_START, 0 ); + ofmem_claim_virt( OF_CODE_START, FREE_BASE_2 - OF_CODE_START, 0 ); +} diff --git a/qemu/roms/openbios/arch/ppc/osi.h b/qemu/roms/openbios/arch/ppc/osi.h new file mode 100644 index 000000000..3baae1575 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/osi.h @@ -0,0 +1,170 @@ +/* + * Creation Date: <1999/03/18 03:19:43 samuel> + * Time-stamp: <2003/12/26 16:58:19 samuel> + * + * <os_interface.h> + * + * This file includes definitions for drivers + * running in the "emulated" OS. (Mainly the 'sc' + * mechanism of communicating) + * + * Copyright (C) 1999, 2000, 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_OSI +#define _H_OSI + +/* Magic register values loaded into r3 and r4 before the 'sc' assembly instruction */ +#define OSI_SC_MAGIC_R3 0x113724FA +#define OSI_SC_MAGIC_R4 0x77810F9B + + +/************************************************************************/ +/* Selectors (passed in r5) */ +/************************************************************************/ + +#define OSI_CALL_AVAILABLE 0 +#define OSI_DEBUGGER 1 /* enter debugger */ +/* obsolete OSI_LOG_STR 3 */ +#define OSI_CMOUNT_DRV_VOL 4 /* conditionally mount driver volume */ +/* obsolete OSI_SCSI_xxx 5-6 */ +#define OSI_GET_GMT_TIME 7 +#define OSI_MOUSE_CNTRL 8 +#define OSI_GET_LOCALTIME 9 /* return time in secs from 01/01/04 */ + +#define OSI_ENET_OPEN 10 +#define OSI_ENET_CLOSE 11 +#define OSI_ENET_GET_ADDR 12 +#define OSI_ENET_GET_STATUS 13 +#define OSI_ENET_CONTROL 14 +#define OSI_ENET_ADD_MULTI 16 +#define OSI_ENET_DEL_MULTI 17 +#define OSI_ENET_GET_PACKET 18 +#define OSI_ENET_SEND_PACKET 19 + +#define OSI_OF_INTERFACE 20 +#define OSI_OF_TRAP 21 +#define OSI_OF_RTAS 22 + +#define OSI_SCSI_CNTRL 23 +#define OSI_SCSI_SUBMIT 24 +#define OSI_SCSI_ACK 25 + +#define OSI_GET_MOUSE 26 /* -- r3 status, r4-r8 mouse data */ +#define OSI_ACK_MOUSE_IRQ 27 /* -- int */ + +#define OSI_SET_VMODE 28 /* modeID, depth -- error */ +#define OSI_GET_VMODE_INFO 29 /* mode, depth -- r3 status, r4-r9 pb */ +#define OSI_GET_MOUSE_DPI 30 /* -- mouse_dpi */ + +#define OSI_SET_VIDEO_POWER 31 +#define OSI_GET_FB_INFO 32 /* void -- r3 status, r4-r8 video data */ + +#define OSI_SOUND_WRITE 33 +/* #define OSI_SOUND_FORMAT 34 */ +#define OSI_SOUND_SET_VOLUME 35 +#define OSI_SOUND_CNTL 36 +/* obsolete OSI_SOUND call 37 */ + +#define OSI_VIDEO_ACK_IRQ 38 +#define OSI_VIDEO_CNTRL 39 + +#define OSI_SOUND_IRQ_ACK 40 +#define OSI_SOUND_START_STOP 41 + +#define OSI_REGISTER_IRQ 42 /* reg_property[0] appl_int -- irq_cookie */ +/* obsolete OSI_IRQ 43-46 */ + +#define OSI_LOG_PUTC 47 /* char -- */ + +#define OSI_KBD_CNTRL 50 +#define OSI_GET_ADB_KEY 51 /* -- adb_keycode (keycode | keycode_id in r4) */ + +#define OSI_WRITE_NVRAM_BYTE 52 /* offs, byte -- */ +#define OSI_READ_NVRAM_BYTE 53 /* offs -- byte */ + +#define OSI_EXIT 54 + +#define OSI_KEYCODE_TO_ADB 55 /* (keycode | keycode_id) -- adb_keycode */ +#define OSI_MAP_ADB_KEY 56 /* keycode, adbcode -- */ +#define OSI_SAVE_KEYMAPPING 57 /* -- */ +#define OSI_USLEEP 58 /* usecs -- */ +#define OSI_SET_COLOR 59 /* index value -- */ + +#define OSI_PIC_MASK_IRQ 60 /* irq -- */ +#define OSI_PIC_UNMASK_IRQ 61 /* irq -- */ +#define OSI_PIC_ACK_IRQ 62 /* irq mask_flag -- */ +#define OSI_PIC_GET_ACTIVE_IRQ 63 + +#define OSI_GET_COLOR 64 /* index -- value */ + +/* 65-67 old ablk implementation */ +#define OSI_IRQTEST 65 + +#define OSI_ENET2_OPEN 68 +#define OSI_ENET2_CLOSE 69 +#define OSI_ENET2_CNTRL 70 +#define OSI_ENET2_RING_SETUP 71 +#define OSI_ENET2_KICK 72 +#define OSI_ENET2_GET_HWADDR 73 +#define OSI_ENET2_IRQ_ACK 74 + +#define OSI_PROM_IFACE 76 +#define kPromClose 0 +#define kPromPeer 1 +#define kPromChild 2 +#define kPromParent 3 +#define kPromPackageToPath 4 +#define kPromGetPropLen 5 +#define kPromGetProp 6 +#define kPromNextProp 7 +#define kPromSetProp 8 +#define kPromChangePHandle 9 + +#define OSI_PROM_PATH_IFACE 77 +#define kPromCreateNode 16 +#define kPromFindDevice 17 + +#define OSI_BOOT_HELPER 78 +#define kBootHAscii2Unicode 32 +#define kBootHUnicode2Ascii 33 +#define kBootHGetStrResInd 34 /* key, buf, len -- buf */ +#define kBootHGetRAMSize 35 /* -- ramsize */ + +#define OSI_ABLK_RING_SETUP 79 +#define OSI_ABLK_CNTRL 80 +#define OSI_ABLK_DISK_INFO 81 +#define OSI_ABLK_KICK 82 +#define OSI_ABLK_IRQ_ACK 83 +#define OSI_ABLK_SYNC_READ 84 +#define OSI_ABLK_SYNC_WRITE 85 +#define OSI_ABLK_BLESS_DISK 86 + +#define OSI_EMUACCEL 89 /* EMULATE_xxx, nip -- index */ +#define OSI_MAPIN_MREGS 90 /* mphys */ +#define OSI_NVRAM_SIZE 91 + +#define OSI_MTICKS_TO_USECS 92 +#define OSI_USECS_TO_MTICKS 93 + +/* obsolete OSI_BLK 94-95 */ + +#define OSI_PSEUDO_FS 96 +#define kPseudoFSOpen 1 +#define kPseudoFSClose 2 +#define kPseudoFSGetSize 3 +#define kPseudoFSRead 4 +#define kPseudoFSIndex2Name 5 + +#define OSI_TTY_PUTC 97 +#define OSI_TTY_GETC 98 +#define OSI_TTY_IRQ_ACK 99 + +#define NUM_OSI_SELECTORS 100 /* remember to increase this... */ + +#endif /* _H_OSI */ diff --git a/qemu/roms/openbios/arch/ppc/osi_calls.h b/qemu/roms/openbios/arch/ppc/osi_calls.h new file mode 100644 index 000000000..1d6b3dc5e --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/osi_calls.h @@ -0,0 +1,454 @@ +/* + * Creation Date: <2002/06/16 01:40:57 samuel> + * Time-stamp: <2003/12/26 17:02:09 samuel> + * + * <osi_calls.h> + * + * OSI call inlines + * + * Copyright (C) 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_OSI_CALLS +#define _H_OSI_CALLS + +#include "osi.h" + +/* Old gcc versions have a limit on the number of registers used. + * Newer gcc versions (gcc 3.3) require that the clobber list does + * not overlap declared registers. + */ +#if __GNUC__ == 2 || ( __GNUC__ == 3 && __GNUC_MINOR__ < 3 ) +#define SHORT_REGLIST +#endif + + +/************************************************************************/ +/* OSI call instantiation macros */ +/************************************************************************/ + +#define dreg(n) __oc_##n __asm__ (#n) +#define ir(n) "r" (__oc_##n) +#define rr(n) "=r" (__oc_##n) + +#define _oc_head( input_regs... ) \ +{ \ + int _ret=0; \ + { \ + register unsigned long dreg(r3); \ + register unsigned long dreg(r4); \ + register unsigned long dreg(r5) \ + ,##input_regs ; + +#define _oc_syscall( number, extra_ret_regs... ) \ + __oc_r3 = OSI_SC_MAGIC_R3; \ + __oc_r4 = OSI_SC_MAGIC_R4; \ + __oc_r5 = number; \ + __asm__ __volatile__ ( \ + "sc " : rr(r3) ,## extra_ret_regs + +#define _oc_input( regs... ) \ + : ir(r3), ir(r4), ir(r5) \ + , ## regs \ + : "memory" ); + +/* the tail memory clobber is necessary since we violate the strict + * aliasing rules when we return structs through the registers. + */ +#define _oc_tail \ + asm volatile ( "" : : : "memory" ); \ + _ret = __oc_r3; \ + } \ + return _ret; \ +} + + +/************************************************************************/ +/* Alternatives */ +/************************************************************************/ + +#ifdef SHORT_REGLIST +#define _oc_syscall_r10w6( number, inputregs... ) \ + __oc_r3 = OSI_SC_MAGIC_R3; \ + __oc_r4 = OSI_SC_MAGIC_R4; \ + __oc_r5 = number; \ + __asm__ __volatile__ ( \ + "sc \n" \ + "stw 4,0(10) \n" \ + "stw 5,4(10) \n" \ + "stw 6,8(10) \n" \ + "stw 7,12(10) \n" \ + "stw 8,16(10) \n" \ + "stw 9,20(10) \n" \ + : rr(r3) \ + : ir(r3), ir(r4), ir(r5), ir(r10) \ + ,## inputregs \ + : "memory", \ + "r4", "r5", "r6", "r7", "r8", "r9" ); +#endif + + +/************************************************************************/ +/* Common helper functions */ +/************************************************************************/ + +#define _osi_call0( type, name, number ) \ +type name( void ) \ + _oc_head() \ + _oc_syscall( number ) \ + _oc_input() \ + _oc_tail + +#define _osi_call1( type, name, number, type1, arg1 ) \ +type name( type1 arg1 ) \ + _oc_head( dreg(r6) ) \ + __oc_r6 = (unsigned long)arg1; \ + _oc_syscall( number ) \ + _oc_input( ir(r6) ) \ + _oc_tail + +#define _osi_call2( type, name, number, t1, a1, t2, a2 ) \ +type name( t1 a1, t2 a2 ) \ + _oc_head( dreg(r6), dreg(r7) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + _oc_syscall( number ) \ + _oc_input( ir(r6), ir(r7) ) \ + _oc_tail + +#define _osi_call3( type, name, number, t1, a1, t2, a2, t3, a3 ) \ +type name( t1 a1, t2 a2, t3 a3 ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + __oc_r8 = (unsigned long)a3; \ + _oc_syscall( number ) \ + _oc_input( ir(r6), ir(r7), ir(r8) ) \ + _oc_tail + +#define _osi_call4( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4 ) \ +type name( t1 a1, t2 a2, t3 a3, t4 a4 ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + __oc_r8 = (unsigned long)a3; \ + __oc_r9 = (unsigned long)a4; \ + _oc_syscall( number ) \ + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9) ) \ + _oc_tail + +#define _osi_call5( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5 ) \ +type name( t1 a1, t2 a2, t3 a3, t4 a4, t5 a5 ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9), dreg(r10) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + __oc_r8 = (unsigned long)a3; \ + __oc_r9 = (unsigned long)a4; \ + __oc_r10 = (unsigned long)a5; \ + _oc_syscall( number ) \ + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9), ir(r10) ) \ + _oc_tail + +#define _osi_call6( type, name, number, t1, a1, t2, a2, t3, a3, t4, a4, t5, a5, t6, a6 ) \ +type name( t1 a1, t2 a2, t3 a3, t4 a4, t5 a5, t6 a6 ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9), dreg(r10), dreg(r11) )\ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + __oc_r8 = (unsigned long)a3; \ + __oc_r9 = (unsigned long)a4; \ + __oc_r10 = (unsigned long)a5; \ + __oc_r11 = (unsigned long)a6; \ + _oc_syscall( number ) \ + _oc_input( ir(r6), ir(r7), ir(r8), ir(r9), ir(r10), ir(r11) ) \ + _oc_tail + + +/************************************************************************/ +/* Special */ +/************************************************************************/ + +/* r4 returned in retarg1 pointer */ +#define _osi_call0_w1( type, name, number, type1, retarg1 ) \ +type name( type1 retarg1 ) \ + _oc_head() \ + _oc_syscall( number, rr(r4) ) \ + _oc_input() \ + *retarg1 = __oc_r4; \ + _oc_tail + +#define _osi_call0_w2( type, name, number, type1, retarg1 ) \ +type name( type1 retarg1 ) \ + _oc_head() \ + _oc_syscall( number, rr(r4), rr(r5) ) \ + _oc_input() \ + ((unsigned long*)retarg1)[0] = __oc_r4; \ + ((unsigned long*)retarg1)[1] = __oc_r5; \ + _oc_tail + +/* r4-r8 returned in retarg1 pointer */ +#define _osi_call0_w5( type, name, number, type1, retarg1 ) \ +type name( type1 retarg1 ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8) ) \ + _oc_syscall( number, \ + rr(r4), rr(r5), rr(r6), rr(r7), rr(r8) ) \ + _oc_input() \ + ((unsigned long*)retarg1)[0] = __oc_r4; \ + ((unsigned long*)retarg1)[1] = __oc_r5; \ + ((unsigned long*)retarg1)[2] = __oc_r6; \ + ((unsigned long*)retarg1)[3] = __oc_r7; \ + ((unsigned long*)retarg1)[4] = __oc_r8; \ + _oc_tail + +/* r4 returned in retarg pointer */ +#define _osi_call1_w1( type, name, number, t1, a1, t2, retarg ) \ +type name( t1 a1, t2 retarg ) \ + _oc_head( dreg(r6) ) \ + __oc_r6 = (unsigned long)a1; \ + _oc_syscall( number, rr(r4) ) \ + _oc_input( ir(r6) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + _oc_tail + +/* r4,r5 returned in retarg1, retarg2 */ +#define _osi_call1_w1w1( type, name, number, t1, a1, t2, retarg1, t3, retarg2 ) \ +type name( t1 a1, t2 retarg1, t3 retarg2 ) \ + _oc_head( dreg(r6) ) \ + __oc_r6 = (unsigned long)a1; \ + _oc_syscall( number, rr(r4), rr(r5) ) \ + _oc_input( ir(r6) ) \ + ((unsigned long*)retarg1)[0] = __oc_r4; \ + ((unsigned long*)retarg2)[0] = __oc_r5; \ + _oc_tail + +/* r4,r5 returned in retarg1, retarg2, retarg3 */ +#define _osi_call1_w1w1w1( type, name, number, t1, a1, t2, retarg1, t3, retarg2, t4, retarg3 ) \ +type name( t1 a1, t2 retarg1, t3 retarg2, t4 retarg3 ) \ + _oc_head( dreg(r6) ) \ + __oc_r6 = (unsigned long)a1; \ + _oc_syscall( number, rr(r4), rr(r5), rr(r6) ) \ + _oc_input( ir(r6) ) \ + ((unsigned long*)retarg1)[0] = __oc_r4; \ + ((unsigned long*)retarg2)[0] = __oc_r5; \ + ((unsigned long*)retarg3)[0] = __oc_r6; \ + _oc_tail + +/* r4,r5 returned in retarg pointer */ +#define _osi_call1_w2( type, name, number, t1, a1, t2, retarg ) \ +type name( t1 a1, t2 retarg ) \ + _oc_head( dreg(r6) ) \ + __oc_r6 = (unsigned long)a1; \ + _oc_syscall( number, rr(r4), rr(r5) ) \ + _oc_input( ir(r6) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + ((unsigned long*)retarg)[1] = __oc_r5; \ + _oc_tail + +/* r4-r7 returned in retarg pointer */ +#define _osi_call1_w4( type, name, number, t1, a1, t2, retarg ) \ +type name( t1 a1, t2 retarg ) \ + _oc_head( dreg(r6), dreg(r7) ) \ + __oc_r6 = (unsigned long)a1; \ + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7) ) \ + _oc_input( ir(r6) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + ((unsigned long*)retarg)[1] = __oc_r5; \ + ((unsigned long*)retarg)[2] = __oc_r6; \ + ((unsigned long*)retarg)[3] = __oc_r7; \ + _oc_tail + + +/* r4-r5 returned in retarg pointer */ +#define _osi_call2_w2( type, name, number, t1, a1, t2, a2, t3, retarg ) \ +type name( t1 a1, t2 a2, t3 retarg ) \ + _oc_head( dreg(r6), dreg(r7) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + _oc_syscall( number, rr(r4), rr(r5) ) \ + _oc_input( ir(r6), ir(r7) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + ((unsigned long*)retarg)[1] = __oc_r5; \ + _oc_tail + +/* r4-r7 returned in retarg pointer */ +#define _osi_call2_w4( type, name, number, t1, a1, t2, a2, t3, retarg ) \ +type name( t1 a1, t2 a2, t3 retarg ) \ + _oc_head( dreg(r6), dreg(r7) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7) ) \ + _oc_input( ir(r6), ir(r7) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + ((unsigned long*)retarg)[1] = __oc_r5; \ + ((unsigned long*)retarg)[2] = __oc_r6; \ + ((unsigned long*)retarg)[3] = __oc_r7; \ + _oc_tail + +#ifdef SHORT_REGLIST +/* r4-r9 returned in retarg pointer */ +#define _osi_call2_w6( type, name, number, t1, a1, t2, a2, t3, retarg ) \ +type name( t1 a1, t2 a2, t3 retarg ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r10) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + __oc_r10 = (unsigned long)retarg; \ + _oc_syscall_r10w6( number, ir(r6), ir(r7) ) \ + _oc_tail + +#else /* SHORT_REGLIST */ + +/* r4-r9 returned in retarg pointer */ +#define _osi_call2_w6( type, name, number, t1, a1, t2, a2, t3, retarg ) \ +type name( t1 a1, t2 a2, t3 retarg ) \ + _oc_head( dreg(r6), dreg(r7), dreg(r8), dreg(r9) ) \ + __oc_r6 = (unsigned long)a1; \ + __oc_r7 = (unsigned long)a2; \ + _oc_syscall( number, rr(r4), rr(r5), rr(r6), rr(r7), rr(r8), rr(r9) ) \ + _oc_input( ir(r6), ir(r7) ) \ + ((unsigned long*)retarg)[0] = __oc_r4; \ + ((unsigned long*)retarg)[1] = __oc_r5; \ + ((unsigned long*)retarg)[2] = __oc_r6; \ + ((unsigned long*)retarg)[3] = __oc_r7; \ + ((unsigned long*)retarg)[4] = __oc_r8; \ + ((unsigned long*)retarg)[5] = __oc_r9; \ + _oc_tail + +#endif /* SHORT_REGLIST */ + + +/************************************************************************/ +/* OSI call inlines */ +/************************************************************************/ + +static inline _osi_call1( int, OSI_CallAvailable, OSI_CALL_AVAILABLE, int, osi_num ); + +static inline _osi_call1( int, OSI_PutC, OSI_LOG_PUTC, int, ch ); + +static inline _osi_call1( int, OSI_Debugger, OSI_DEBUGGER, int, num ); +static inline _osi_call0( int, OSI_Exit, OSI_EXIT ); + +/* misc */ +static inline _osi_call0( unsigned long, OSI_GetLocalTime, OSI_GET_LOCALTIME ); +static inline _osi_call0( unsigned long, OSI_GetGMTTime, OSI_GET_GMT_TIME ); +static inline _osi_call1( int, OSI_USleep, OSI_USLEEP, int, usecs ); + +/* NVRAM */ +static inline _osi_call0( int, OSI_NVRamSize, OSI_NVRAM_SIZE ); +static inline _osi_call1( int, OSI_ReadNVRamByte, OSI_READ_NVRAM_BYTE, int, offs ); +static inline _osi_call2( int, OSI_WriteNVRamByte, OSI_WRITE_NVRAM_BYTE, int, offs, + unsigned char, ch ); + +/* keyboard stuff */ +static inline _osi_call0_w1( int, OSI_GetAdbKey2, OSI_GET_ADB_KEY, int *, raw_key ); +static inline _osi_call1( int, OSI_KbdCntrl, OSI_KBD_CNTRL, int, cmd ); + +static inline int OSI_GetAdbKey( void ) + { int dummy_raw_key; return OSI_GetAdbKey2( &dummy_raw_key ); } +static inline _osi_call2( int, OSI_MapAdbKey, OSI_MAP_ADB_KEY, int, keycode, int, adbkey ) +static inline _osi_call1( int, OSI_KeycodeToAdb, OSI_KEYCODE_TO_ADB, int, keycode ); +static inline _osi_call0( int, OSI_SaveKeymapping, OSI_SAVE_KEYMAPPING ); + +/* mouse support */ +struct osi_mouse; +static inline _osi_call0_w5( int, OSI_GetMouse, OSI_GET_MOUSE, struct osi_mouse *, ret ); +static inline _osi_call0( int, OSI_GetMouseDPI, OSI_GET_MOUSE_DPI ); + +/* video */ +static inline _osi_call2( int, OSI_SetVMode_, OSI_SET_VMODE, int, mode, int, depth_mode ); +struct osi_get_vmode_info; +static inline _osi_call2_w6( int, OSI_GetVModeInfo_, OSI_GET_VMODE_INFO, int, mode, int, depth_mode, + struct osi_get_vmode_info *, ret ); +static inline _osi_call1( int, OSI_SetVPowerState, OSI_SET_VIDEO_POWER, int, power_state ); +static inline _osi_call2( int, OSI_SetColor, OSI_SET_COLOR, int, index, int, rgb ); +static inline _osi_call0_w1( int, OSI_VideoAckIRQ, OSI_VIDEO_ACK_IRQ, int *, events ); + +static inline void OSI_RefreshPalette( void ) { OSI_SetColor(-1,0); } + +/* PIC (mac-io replacement) */ +static inline _osi_call1( int, OSI_PICMaskIRQ, OSI_PIC_MASK_IRQ, int, irq ); +static inline _osi_call1( int, OSI_PICUnmaskIRQ, OSI_PIC_UNMASK_IRQ, int, irq ); +static inline _osi_call2( int, OSI_PICAckIRQ, OSI_PIC_ACK_IRQ, int, irq, int, mask_it ); +static inline _osi_call0( int, OSI_PICGetActiveIRQ, OSI_PIC_GET_ACTIVE_IRQ ); + +/* sound */ +static inline _osi_call1( int, OSI_SoundCntl, OSI_SOUND_CNTL, int, cmd ); +static inline _osi_call2( int, OSI_SoundCntl1, OSI_SOUND_CNTL, int, cmd, int, p1 ); +static inline _osi_call3( int, OSI_SoundCntl2, OSI_SOUND_CNTL, int, cmd, int, p1, int, p2 ); +static inline _osi_call0_w2( int, OSI_SoundIRQAck, OSI_SOUND_IRQ_ACK, unsigned long *, timestamp ); +static inline _osi_call3( int, OSI_SoundWrite, OSI_SOUND_WRITE, int, physbuf, int, len, int, restart ); +static inline _osi_call3( int, OSI_SoundSetVolume, OSI_SOUND_SET_VOLUME, int, hwvol, int, speakervol, int, mute ); + +/* async block driver */ +struct ablk_disk_info; +static inline _osi_call2_w4( int, OSI_ABlkDiskInfo, OSI_ABLK_DISK_INFO, int, channel, int, unit, + struct ablk_disk_info *, retinfo ); +static inline _osi_call1( int, OSI_ABlkKick, OSI_ABLK_KICK, int, channel ); +static inline _osi_call1_w1w1w1( int, OSI_ABlkIRQAck, OSI_ABLK_IRQ_ACK, int, channel, int *, req_count, + int *, active, int *, events ); +static inline _osi_call3( int, OSI_ABlkRingSetup, OSI_ABLK_RING_SETUP, int, channel, int, mphys, int, n_el ); +static inline _osi_call2( int, OSI_ABlkCntrl, OSI_ABLK_CNTRL, int, channel, int, cmd ); +static inline _osi_call3( int, OSI_ABlkCntrl1, OSI_ABLK_CNTRL, int, channel, int, cmd, int, param ); +static inline _osi_call5( int, OSI_ABlkSyncRead, OSI_ABLK_SYNC_READ, int, channel, int, unit, + int, blk, unsigned long, mphys, int, size ); +static inline _osi_call5( int, OSI_ABlkSyncWrite, OSI_ABLK_SYNC_WRITE, int, channel, int, unit, + int, blk, unsigned long, mphys, int, size ); +static inline _osi_call2( int, OSI_ABlkBlessDisk, OSI_ABLK_BLESS_DISK, int, channel, int, unit ); + +static inline _osi_call0( int, OSI_CMountDrvVol, OSI_CMOUNT_DRV_VOL ); + +/* enet2 */ +static inline _osi_call0( int, OSI_Enet2Open, OSI_ENET2_OPEN ); +static inline _osi_call0( int, OSI_Enet2Close, OSI_ENET2_CLOSE ); +static inline _osi_call3( int, OSI_Enet2RingSetup, OSI_ENET2_RING_SETUP, int, which_ring, + int, ring_mphys, int, n_el ); +static inline _osi_call2( int, OSI_Enet2Cntrl1, OSI_ENET2_CNTRL, int, cmd, int, param ); +static inline _osi_call1( int, OSI_Enet2Cntrl, OSI_ENET2_CNTRL, int, cmd ); +static inline _osi_call0( int, OSI_Enet2Kick, OSI_ENET2_KICK ); + +static inline _osi_call0_w2( int, OSI_Enet2GetHWAddr__, OSI_ENET2_GET_HWADDR, unsigned long *, retbuf ); +static inline int OSI_Enet2GetHWAddr( unsigned char *addr ) { + int ret; + unsigned long buf[2]; + + ret = OSI_Enet2GetHWAddr__( buf ); + + ((unsigned long*)addr)[0] = buf[0]; + ((unsigned short*)addr)[2] = (buf[1] >> 16); + return ret; +} +static inline _osi_call2( int, OSI_Enet2IRQAck, OSI_ENET2_IRQ_ACK, int, irq_enable, int, rx_head ); + +/* PROM (device-tree) */ +static inline _osi_call2( int, OSI_PromIface, OSI_PROM_IFACE, int, what, int, ph ); +static inline _osi_call3( int, OSI_PromIface1, OSI_PROM_IFACE, int, what, int, ph, int, p1 ); +static inline _osi_call4( int, OSI_PromIface2, OSI_PROM_IFACE, int, what, int, ph, int, p1, int, p2 ); +static inline _osi_call5( int, OSI_PromIface3, OSI_PROM_IFACE, int, what, int, ph, int, p1, int, p2, int, p3 ); +static inline _osi_call2( int, OSI_PromPathIface, OSI_PROM_PATH_IFACE, int, what, const char *, p ); + +/* emulation acceleration */ +static inline _osi_call1( int, OSI_MapinMregs, OSI_MAPIN_MREGS, unsigned long, mphys ); +static inline _osi_call3( int, OSI_EmuAccel, OSI_EMUACCEL, int, emuaccel_flags, int, param, int, inst_addr ); + +/* timer frequency */ +static inline _osi_call1( int, OSI_MticksToUsecs, OSI_MTICKS_TO_USECS, unsigned long, mticks ); +static inline _osi_call1( int, OSI_UsecsToMticks, OSI_USECS_TO_MTICKS, unsigned long, usecs ); + +/* fb info */ +struct osi_fb_info; +static inline _osi_call0_w5( int, OSI_GetFBInfo, OSI_GET_FB_INFO, struct osi_fb_info *, retinfo ); + +/* SCSI */ +static inline _osi_call0( int, OSI_SCSIAck, OSI_SCSI_ACK ); +static inline _osi_call1( int, OSI_SCSISubmit, OSI_SCSI_SUBMIT, int, req_mphys ); +static inline _osi_call2( int, OSI_SCSIControl, OSI_SCSI_CNTRL, int, sel, int, param ); + +/* TTY */ +static inline _osi_call0( int, OSI_TTYGetc, OSI_TTY_GETC ); +static inline _osi_call1( int, OSI_TTYPutc, OSI_TTY_PUTC, int, ch ); +static inline _osi_call0( int, OSI_TTYIRQAck, OSI_TTY_IRQ_ACK ); + +#endif /* _H_OSI_CALLS */ diff --git a/qemu/roms/openbios/arch/ppc/pearpc/console.c b/qemu/roms/openbios/arch/ppc/pearpc/console.c new file mode 100644 index 000000000..3869cbab5 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/console.c @@ -0,0 +1,43 @@ + +/* + * <console.c> + * + * Simple text console + * + * Copyright (C) 2005 Stefan Reinauer <stepan@openbios.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/diskio.h" +#include "libopenbios/ofmem.h" +#include "pearpc/pearpc.h" + + +typedef struct osi_fb_info { + unsigned long mphys; + int rb, w, h, depth; +} osi_fb_info_t; + + +int PearPC_GetFBInfo( osi_fb_info_t *fb ) +{ + + fb->w=1024; + fb->h=768; + fb->depth=15; + fb->rb=2048; + fb->mphys=0x84000000; + + return 0; +} + +#define openbios_GetFBInfo(x) PearPC_GetFBInfo(x) + +#include "../../../packages/video.c" +#include "../../../libopenbios/console_common.c" diff --git a/qemu/roms/openbios/arch/ppc/pearpc/init.c b/qemu/roms/openbios/arch/ppc/pearpc/init.c new file mode 100644 index 000000000..ca6da0a44 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/init.c @@ -0,0 +1,136 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <init.c> + * + * Initialization for pearpc + * + * Copyright (C) 2004 Greg Watson + * Copyright (C) 2005 Stefan Reinauer + * + * based on mol/init.c: + * + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel & David Rydh + * (samuel@ibrium.se, dary@lindesign.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "pearpc/pearpc.h" +#include "libopenbios/ofmem.h" +#include "openbios-version.h" + +extern void unexpected_excep( int vector ); +extern void ob_pci_init( void ); +extern void ob_adb_init( void ); +extern void setup_timers( void ); + +#if 0 +int +get_bool_res( const char *res ) +{ + char buf[8], *p; + + p = BootHGetStrRes( res, buf, sizeof(buf) ); + if( !p ) + return -1; + if( !strcasecmp(p,"true") || !strcasecmp(p,"yes") || !strcasecmp(p,"1") ) + return 1; + return 0; +} +#endif + +void +unexpected_excep( int vector ) +{ + printk("openbios panic: Unexpected exception %x\n", vector ); + for( ;; ) + ; +} + +unsigned long isa_io_base; + +void +entry( void ) +{ + isa_io_base = 0x80000000; + + printk("\n"); + printk("=============================================================\n"); + printk(PROGRAM_NAME " " OPENBIOS_VERSION_STR " [%s]\n", + OPENBIOS_BUILD_DATE); + + ofmem_init(); + initialize_forth(); + /* won't return */ + + printk("of_startup returned!\n"); + for( ;; ) + ; +} + +static void +setenv( char *env, char *value ) +{ + push_str( value ); + push_str( env ); + fword("$setenv"); +} + +void +arch_of_init( void ) +{ +#if CONFIG_RTAS + phandle_t ph; +#endif + int autoboot; + + devtree_init(); + nvram_init("/pci/mac-io/nvram"); + openbios_init(); + modules_init(); + setup_timers(); +#ifdef CONFIG_DRIVER_PCI + ob_pci_init(); +#endif + node_methods_init(); + init_video(); + +#if CONFIG_RTAS + if( !(ph=find_dev("/rtas")) ) + printk("Warning: No /rtas node\n"); + else { + unsigned long size = 0x1000; + while( size < (unsigned long)of_rtas_end - (unsigned long)of_rtas_start ) + size *= 2; + set_property( ph, "rtas-size", (char*)&size, sizeof(size) ); + } +#endif + +#if 0 + /* tweak boot settings */ + autoboot = !!get_bool_res("autoboot"); +#endif + autoboot = 0; + if( !autoboot ) + printk("Autobooting disabled - dropping into OpenFirmware\n"); + setenv("auto-boot?", autoboot ? "true" : "false" ); + setenv("boot-command", "pearpcboot"); + +#if 0 + if( get_bool_res("tty-interface") == 1 ) +#endif + fword("activate-tty-interface"); + + /* hack */ + device_end(); + bind_func("pearpcboot", boot ); +} diff --git a/qemu/roms/openbios/arch/ppc/pearpc/kernel.c b/qemu/roms/openbios/arch/ppc/pearpc/kernel.c new file mode 100644 index 000000000..6408e421e --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/kernel.c @@ -0,0 +1,16 @@ +/* + * Creation Date: <2004/08/28 18:03:25 stepan> + * Time-stamp: <2004/08/28 18:03:25 stepan> + * + * <pearpc/kernel.c> + * + * Copyright (C) 2005 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "pearpc-dict.h" +#include "../kernel.c" diff --git a/qemu/roms/openbios/arch/ppc/pearpc/main.c b/qemu/roms/openbios/arch/ppc/pearpc/main.c new file mode 100644 index 000000000..085494e56 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/main.c @@ -0,0 +1,145 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <main.c> + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elfload.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "pearpc/pearpc.h" +#include "libopenbios/ofmem.h" + +static void +transfer_control_to_elf( unsigned long entry ) +{ + extern void call_elf( unsigned long entry ); + printk("Starting ELF image at 0x%08lX\n", entry); + call_elf( 0x400000 ); + //call_elf( entry ); + + fatal_error("call_elf returned unexpectedly\n"); +} + +static int +load_elf_rom( unsigned long *entry, int fd ) +{ + int i, lszz_offs, elf_offs; + char buf[128], *addr; + Elf_ehdr ehdr; + Elf_phdr *phdr; + size_t s; + + printk("Loading '%s'\n", get_file_path(fd)); + + /* the ELF-image (usually) starts at offset 0x4000 */ + if( (elf_offs=find_elf(fd)) < 0 ) { + printk("----> %s is not an ELF image\n", buf ); + exit(1); + } + if( !(phdr=elf_readhdrs(fd, elf_offs, &ehdr)) ) + fatal_error("elf_readhdrs failed\n"); + + *entry = ehdr.e_entry; + + /* load segments. Compressed ROM-image assumed to be located immediately + * after the last segment */ + lszz_offs = elf_offs; + for( i=0; i<ehdr.e_phnum; i++ ) { + /* p_memsz, p_flags */ + s = MIN( phdr[i].p_filesz, phdr[i].p_memsz ); + seek_io( fd, elf_offs + phdr[i].p_offset ); + + /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n", + phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset, + phdr[i].p_vaddr ); */ + + if( phdr[i].p_vaddr != phdr[i].p_paddr ) + printk("WARNING: ELF segment virtual addr != physical addr\n"); + lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz ); + if( !s ) + continue; + if( ofmem_claim( phdr[i].p_vaddr, phdr[i].p_memsz, 0 ) == -1 ) + fatal_error("Claim failed!\n"); + + addr = (char*)phdr[i].p_vaddr; + if( read_io(fd, addr, s) != s ) + fatal_error("read failed\n"); + +#if 0 + /* patch CODE segment */ + if( *entry >= phdr[i].p_vaddr && *entry < phdr[i].p_vaddr + s ) { + patch_newworld_rom( (char*)phdr[i].p_vaddr, s ); + newworld_timer_hack( (char*)phdr[i].p_vaddr, s ); + } +#endif + flush_icache_range( addr, addr+s ); + + /*printk("ELF ROM-section loaded at %08lX (size %08lX)\n", + (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz );*/ + } + free( phdr ); + return lszz_offs; +} + + +static void +encode_bootpath( const char *spec, const char *args ) +{ + phandle_t chosen_ph = find_dev("/chosen"); + set_property( chosen_ph, "bootpath", spec, strlen(spec)+1 ); + set_property( chosen_ph, "bootargs", args, strlen(args)+1 ); +} + +/************************************************************************/ +/* pearpc booting */ +/************************************************************************/ + +static void +pearpc_startup( void ) +{ + const char *paths[] = { "hd:0,\\zImage.chrp", NULL }; + const char *args[] = { "root=/dev/hda2 console=ttyS0,115200", NULL }; + unsigned long entry; + int i, fd; + + for( i=0; paths[i]; i++ ) { + if( (fd=open_io(paths[i])) == -1 ) + continue; + (void) load_elf_rom( &entry, fd ); + close_io( fd ); + encode_bootpath( paths[i], args[i] ); + + update_nvram(); + transfer_control_to_elf( entry ); + /* won't come here */ + } + printk("*** Boot failure! No secondary bootloader specified ***\n"); +} + + +/************************************************************************/ +/* entry */ +/************************************************************************/ + +void +boot( void ) +{ + fword("update-chosen"); + pearpc_startup(); +} diff --git a/qemu/roms/openbios/arch/ppc/pearpc/methods.c b/qemu/roms/openbios/arch/ppc/pearpc/methods.c new file mode 100644 index 000000000..f505b6cea --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/methods.c @@ -0,0 +1,329 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <methods.c> + * + * Misc device node methods + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "pearpc/pearpc.h" +#include "libopenbios/ofmem.h" + +/************************************************************************/ +/* RTAS (run-time abstraction services) */ +/************************************************************************/ + +#ifdef CONFIG_RTAS +DECLARE_NODE( rtas, INSTALL_OPEN, 0, "+/rtas" ); + +/* ( physbase -- rtas_callback ) */ +static void +rtas_instantiate( void ) +{ + int physbase = POP(); + int s=0x1000, size = (int)of_rtas_end - (int)of_rtas_start; + unsigned long virt; + + while( s < size ) + s += 0x1000; + virt = ofmem_claim_virt( 0, s, 0x1000 ); + ofmem_map( physbase, virt, s, -1 ); + memcpy( (char*)virt, of_rtas_start, size ); + + printk("RTAS instantiated at %08x\n", physbase ); + flush_icache_range( (char*)virt, (char*)virt + size ); + + PUSH( physbase ); +} + +NODE_METHODS( rtas ) = { + { "instantiate", rtas_instantiate }, + { "instantiate-rtas", rtas_instantiate }, +}; +#endif + + +/************************************************************************/ +/* stdout */ +/************************************************************************/ + +DECLARE_NODE( video_stdout, INSTALL_OPEN, 0, "Tdisplay" ); + +/* ( addr len -- actual ) */ +static void +stdout_write( void ) +{ + int len = POP(); + char *addr = (char*)POP(); + + printk( "%s", s ); + //vfd_draw_str( s ); + console_draw_fstr(addr, len); + + PUSH( len ); +} + +NODE_METHODS( video_stdout ) = { + { "write", stdout_write }, +}; + + +/************************************************************************/ +/* tty */ +/************************************************************************/ + +DECLARE_NODE( tty, INSTALL_OPEN, 0, "/packages/terminal-emulator" ); + +/* ( addr len -- actual ) */ +static void +tty_read( void ) +{ + int ch, len = POP(); + char *p = (char*)POP(); + int ret=0; + + if( len > 0 ) { + ret = 1; + ch = getchar(); + if( ch >= 0 ) { + *p = ch; + } else { + ret = 0; + } + } + PUSH( ret ); +} + +/* ( addr len -- actual ) */ +static void +tty_write( void ) +{ + int i, len = POP(); + char *p = (char*)POP(); + for( i=0; i<len; i++ ) + putchar( *p++ ); + RET( len ); +} + +NODE_METHODS( tty ) = { + { "read", tty_read }, + { "write", tty_write }, +}; + +/************************************************************************/ +/* client interface 'quiesce' */ +/************************************************************************/ + +DECLARE_NODE( ciface, 0, 0, "/packages/client-iface" ); + +/* ( -- ) */ +static void +ciface_quiesce( unsigned long args[], unsigned long ret[] ) +{ +#if 0 + unsigned long msr; + /* This seems to be the correct thing to do - but I'm not sure */ + asm volatile("mfmsr %0" : "=r" (msr) : ); + msr &= ~(MSR_IR | MSR_DR); + asm volatile("mtmsr %0" :: "r" (msr) ); +#endif + printk("=============================================================\n\n"); +} + +/* ( -- ms ) */ +static void +ciface_milliseconds( unsigned long args[], unsigned long ret[] ) +{ + extern unsigned long get_timer_freq(); + static unsigned long mticks=0, usecs=0; + unsigned long t; + + asm volatile("mftb %0" : "=r" (t) : ); + if( mticks ) + usecs += get_timer_freq() / 1000000 * ( t-mticks ); + mticks = t; + + PUSH( usecs/1000 ); +} + + +NODE_METHODS( ciface ) = { + { "quiesce", ciface_quiesce }, + { "milliseconds", ciface_milliseconds }, +}; + + +/************************************************************************/ +/* MMU/memory methods */ +/************************************************************************/ + +DECLARE_NODE( memory, INSTALL_OPEN, 0, "/memory" ); +DECLARE_NODE( mmu, INSTALL_OPEN, 0, "/cpu@0" ); +DECLARE_NODE( mmu_ciface, 0, 0, "/packages/client-iface" ); + + +/* ( phys size align --- base ) */ +static void +mem_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_phys( phys, size, align ); + + if( ret == (ucell)-1 ) { + printk("MEM: claim failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mem_release( void ) +{ + POP(); POP(); +} + +/* ( phys size align --- base ) */ +static void +mmu_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align ); + + if( ret == -1 ) { + printk("MMU: CLAIM failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mmu_release( void ) +{ + POP(); POP(); +} + +/* ( phys virt size mode -- [ret???] ) */ +static void +mmu_map( void ) +{ + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret; + + /* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ + ret = ofmem_map( phys, virt, size, mode ); + + if( ret ) { + printk("MMU: map failure\n"); + throw( -13 ); + return; + } +} + +/* ( virt size -- ) */ +static void +mmu_unmap( void ) +{ + POP(); POP(); +} + +/* ( virt -- false | phys mode true ) */ +static void +mmu_translate( void ) +{ + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode ); + + if( phys == -1 ) { + PUSH( 0 ); + } else { + PUSH( phys ); + PUSH( mode ); + PUSH( -1 ); + } +} + +/* ( virt size align -- baseaddr|-1 ) */ +static void +ciface_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align ); + + /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ + PUSH( ret ); +} + +/* ( virt size -- ) */ +static void +ciface_release( void ) +{ + POP(); + POP(); +} + + +NODE_METHODS( memory ) = { + { "claim", mem_claim }, + { "release", mem_release }, +}; + +NODE_METHODS( mmu ) = { + { "claim", mmu_claim }, + { "release", mmu_release }, + { "map", mmu_map }, + { "unmap", mmu_unmap }, + { "translate", mmu_translate }, +}; + +NODE_METHODS( mmu_ciface ) = { + { "cif-claim", ciface_claim }, + { "cif-release", ciface_release }, +}; + + +/************************************************************************/ +/* init */ +/************************************************************************/ + +void +node_methods_init( void ) +{ +#ifdef CONFIG_RTAS + REGISTER_NODE( rtas ); +#endif + REGISTER_NODE( video_stdout ); + REGISTER_NODE( ciface ); + REGISTER_NODE( memory ); + REGISTER_NODE( mmu ); + REGISTER_NODE( mmu_ciface ); + REGISTER_NODE( tty ); +} diff --git a/qemu/roms/openbios/arch/ppc/pearpc/pearpc.c b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.c new file mode 100644 index 000000000..234052ce4 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.c @@ -0,0 +1,206 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <pearpc.c> + * + * Copyright (C) 2004, Greg Watson + * + * derived from mol.c + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/nvram.h" +#include "libc/vsprintf.h" +#include "libc/string.h" +#include "pearpc/pearpc.h" +#include <stdarg.h> + +#define UART_BASE 0x3f8 + +// FIXME +unsigned long virt_offset = 0; + + +void +exit( int status ) +{ + for (;;); +} + +void +fatal_error( const char *err ) +{ + printk("Fatal error: %s\n", err ); + exit(0); +} + +void +panic( const char *err ) +{ + printk("Panic: %s\n", err ); + exit(0); + + /* won't come here... this keeps the gcc happy */ + for( ;; ) + ; +} + + +/************************************************************************/ +/* print using OSI interface */ +/************************************************************************/ + +static int do_indent; + +int +printk( const char *fmt, ... ) +{ + char *p, buf[1024]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) { + if( *p == '\n' ) + do_indent = 0; + if( do_indent++ == 1 ) { + putchar( '>' ); + putchar( '>' ); + putchar( ' ' ); + } + putchar( *p ); + } + return i; +} + + +/************************************************************************/ +/* TTY iface */ +/************************************************************************/ + +static int ttychar = -1; + +static int +tty_avail( void ) +{ + return 1; +} + +static int +tty_putchar( int c ) +{ + if( tty_avail() ) { + while (!(inb(UART_BASE + 0x05) & 0x20)) + ; + outb(c, UART_BASE); + while (!(inb(UART_BASE + 0x05) & 0x40)) + ; + } + return c; +} + +int +availchar( void ) +{ + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + ttychar = inb(UART_BASE); + return (ttychar >= 0); +} + +int +getchar( void ) +{ + int ch; + + if( !tty_avail() ) + return 0; + + if( ttychar < 0 ) + return inb(UART_BASE); + ch = ttychar; + ttychar = -1; + return ch; +} + +int +putchar( int c ) +{ + if (c == '\n') + tty_putchar('\r'); + return tty_putchar(c); +} + + +/************************************************************************/ +/* briQ specific stuff */ +/************************************************************************/ + +#define IO_NVRAM_PA_START 0x80860000 +#define IO_NVRAM_PA_END 0x80880000 + +static char *nvram=(char *)IO_NVRAM_PA_START; + +void +dump_nvram(void) +{ + static char hexdigit[] = "0123456789abcdef"; + int i; + for (i = 0; i < 16*4; i++) + { + printk ("%c", hexdigit[nvram[i<<4] >> 4]); + printk ("%c", hexdigit[nvram[i<<4] % 16]); + if (!((i + 1) % 16)) + { + printk ("\n"); + } + else + { + printk (" "); + } + } +} + + +int +arch_nvram_size( void ) +{ + return (IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4; +} + +void +arch_nvram_put( char *buf ) +{ + int i; + for (i=0; i<(IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4; i++) + nvram[i<<4]=buf[i]; + // memcpy(nvram, buf, IO_NVRAM_PA_END-IO_NVRAM_PA_START); + printk("new nvram:\n"); + dump_nvram(); +} + +void +arch_nvram_get( char *buf ) +{ + int i; + for (i=0; i<(IO_NVRAM_PA_END-IO_NVRAM_PA_START)>>4; i++) + buf[i]=nvram[i<<4]; + + //memcpy(buf, nvram, IO_NVRAM_PA_END-IO_NVRAM_PA_START); + printk("current nvram:\n"); + dump_nvram(); +} diff --git a/qemu/roms/openbios/arch/ppc/pearpc/pearpc.fs b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.fs new file mode 100644 index 000000000..0d018b1c3 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.fs @@ -0,0 +1,116 @@ +\ pearpc specific initialization code +\ +\ Copyright (C) 2005 Stefan Reinauer +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + + +\ ------------------------------------------------------------------------- +\ initialization +\ ------------------------------------------------------------------------- + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " rtc" " /pci/isa/rtc" preopen + " memory" " /memory" preopen + " mmu" " /cpu@0" preopen + \ " stdout" " /packages/terminal-emulator" preopen + " stdout" " /pci/pci6666,6666" preopen + " stdin" " /pci/via-cuda/adb" preopen + +; SYSTEM-initializer + + +\ ------------------------------------------------------------------------- +\ device tree fixing +\ ------------------------------------------------------------------------- + +\ add decode-address methods +: (make-decodable) ( phandle -- ) + + dup " #address-cells" rot get-package-property 0= if + decode-int nip nip + over " decode-unit" rot find-method if 2drop else + ( save phandle ncells ) + + over active-package! + case + 1 of ['] parse-hex " decode-unit" is-xt-func endof + 3 of + " bus-range" active-package get-package-property 0= if + decode-int nip nip + ['] encode-unit-pci " encode-unit" is-xt-func + " decode-unit" is-func-begin + ['] (lit) , , + ['] decode-unit-pci-bus , + is-func-end + then + endof + endcase + then + then + drop +; + +: init-pearpc-tree ( -- ) + active-package + + iterate-tree-begin + begin ?dup while + + dup (make-decodable) + + iterate-tree + repeat + + active-package! +; + +\ use the tty interface if available +: activate-tty-interface + " /packages/terminal-emulator" find-dev if drop + " /pci/via-cuda/adb" " input-device" $setenv + " /pci/pci6666,6666" " output-device" $setenv + then +; + +:noname + " keyboard" input +; CONSOLE-IN-initializer + + +\ ------------------------------------------------------------------------- +\ pre-booting +\ ------------------------------------------------------------------------- + +: update-chosen + " /chosen" find-device + stdin @ encode-int " stdin" property + stdout @ encode-int " stdout" property + " /pci/isa/interrupt-controller" find-dev if encode-int " interrupt-controller" property then + device-end +; diff --git a/qemu/roms/openbios/arch/ppc/pearpc/pearpc.h b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.h new file mode 100644 index 000000000..44497d79e --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/pearpc.h @@ -0,0 +1,26 @@ +/* + * Creation Date: <2004/08/28 17:50:12 stepan> + * Time-stamp: <2004/08/28 17:50:12 stepan> + * + * <pearpc.h> + * + * Copyright (C) 2005 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_PEARPC +#define _H_PEARPC + +/* vfd.c */ +extern int vfd_draw_str( const char *str ); +extern void vfd_close( void ); + +extern int console_draw_fstr(const char *str, int len); + +#include "kernel.h" + +#endif /* _H_PEARPC */ diff --git a/qemu/roms/openbios/arch/ppc/pearpc/tree.c b/qemu/roms/openbios/arch/ppc/pearpc/tree.c new file mode 100644 index 000000000..abd1bf024 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/tree.c @@ -0,0 +1,23 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <tree.c> + * + * device tree setup + * + * Copyright (C) 2004 Greg Watson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" + +void devtree_init( void ) +{ + fword("init-pearpc-tree"); +} diff --git a/qemu/roms/openbios/arch/ppc/pearpc/tree.fs b/qemu/roms/openbios/arch/ppc/pearpc/tree.fs new file mode 100644 index 000000000..d19b485f8 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/tree.fs @@ -0,0 +1,305 @@ +\ PearPC specific initialization code +\ +\ Copyright (C) 2005 Stefan Reinauer +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + +\ ------------------------------------------------------------- +\ device-tree +\ ------------------------------------------------------------- + +" /" find-device + +" chrp" device-type +" OpenSource,PEARPC" model +h# 80000000 encode-int " isa-io-base" property +1 encode-int " #interrupt-cells" property +1 encode-int " #size-cells" property + +new-device + " memory" device-name + " memory" device-type + 0 encode-int h# 1E00000 encode-int encode+ + h# 2000000 encode-int encode+ h# 40000000 encode-int encode+ + " available" property + 0 h# 40000000 reg + external + : open true ; + : close ; +finish-device + +new-device + " cpu" device-name + " cpu" device-type + " " encode-string " translations" property + 0 encode-phys h# 8000000 encode-int encode+ " available" property + d# 32 encode-int " d-cache-block-size" property + 8 encode-int " d-cache-sets" property + d# 32768 encode-int " d-cache-size" property + d# 32 encode-int " i-cache-block-size" property + 8 encode-int " i-cache-sets" property + d# 32768 encode-int " i-cache-size" property + " " encode-string " cache-unified" property + 2 encode-int " i-tlb-sets" property + d# 128 encode-int " i-tlb-size" property + 2 encode-int " d-tlb-sets" property + d# 128 encode-int " d-tlb-size" property + " " encode-string " tlb-split" property + 2 encode-int " tlb-sets" property + d# 256 encode-int " tlb-size" property + " " encode-string " performance-monitor" property + " " encode-string " graphics" property + 4 encode-int " reservation-granule-size" property + d# 25000000 encode-int " timebase-frequency" property + d# 300000000 encode-int " clock-frequency" property + d# 66000000 encode-int " bus-frequency" property + h# 88201 encode-int " cpu-version" property + 0 encode-int " reg" property +finish-device + +" /pci" find-device + h# 01000000 encode-int 0 encode-int encode+ 0 encode-int encode+ + h# 80000000 encode-int encode+ 0 encode-int encode+ + h# 01000000 encode-int encode+ + h# 02000000 encode-int encode+ 0 encode-int encode+ 0 encode-int encode+ + h# C0000000 encode-int encode+ 0 encode-int encode+ + h# 08000000 encode-int encode+ + " ranges" property + " IBM,CPC710" model + h# FF5F7700 encode-int " 8259-interrupt-acknowledge" property + h# 0000F800 encode-int 0 encode-int encode+ 0 encode-int encode+ + 7 encode-int encode+ + " interrupt-map-mask" property + 1 encode-int " #interrupt-cells" property + h# 80000000 encode-int " system-dma-base" property + d# 33333333 encode-int " clock-frequency" property + " " encode-string " primary-bridge" property + 0 encode-int " pci-bridge-number" property + h# FEC00000 encode-int h# 100000 encode-int encode+ " reg" property + 0 encode-int 0 encode-int encode+ " bus-range" property + +new-device + " isa" device-name + " isa" device-type + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + + external + : open true ; + : close ; + +finish-device + +: ?devalias ( alias-str alias-len device-str device-len -- + \ alias-str alias-len false | true ) + active-package >r + " /aliases" find-device + \ 2dup ." Checking " type + 2dup find-dev if \ check if device exists + drop + 2over find-dev if \ do we already have an alias? + \ ." alias exists" cr + drop 2drop false + else + \ ." device exists" cr + encode-string + 2swap property + true + then + else + \ ." device doesn't exist" cr + 2drop false + then + r> active-package! + ; + +:noname + " hd" + " /pci/pci-ata/ata-1/disk@0" ?devalias not if + " /pci/pci-ata/ata-1/disk@1" ?devalias not if + " /pci/pci-ata/ata-2/disk@0" ?devalias not if + " /pci/pci-ata/ata-2/disk@1" ?devalias not if + 2drop ." No disk found." cr + then + then + then + then + + " cdrom" + " /pci/pci-ata/ata-1/cdrom@0" ?devalias not if + " /pci/pci-ata/ata-1/cdrom@1" ?devalias not if + " /pci/pci-ata/ata-2/cdrom@0" ?devalias not if + " /pci/pci-ata/ata-2/cdrom@1" ?devalias not if + 2drop ." No cdrom found" cr + then + then + then + then +; SYSTEM-initializer + +new-device + " ide" device-name + " ide" device-type + " WINBOND,82C553" model + h# 28 encode-int " max-latency" property + h# 2 encode-int " min-grant" property + h# 1 encode-int " devsel-speed" property + h# 0 encode-int " subsystem-vendor-id" property + h# 0 encode-int " subsystem-id" property + h# 1018A encode-int " class-code" property + h# 5 encode-int " revision-id" property + h# 105 encode-int " device-id" property + h# 10AD encode-int " vendor-id" property + h# 1003110 encode-int 0 encode-int encode+ h# 10020 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003114 encode-int 0 encode-int encode+ h# 10030 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003118 encode-int 0 encode-int encode+ h# 10040 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 100311C encode-int 0 encode-int encode+ h# 10034 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003120 encode-int 0 encode-int encode+ h# 10050 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003124 encode-int 0 encode-int encode+ h# 10060 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + " assigned-addresses" property + h# 3100 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ + h# 1003110 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003114 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003118 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 100311C encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 4 encode-int encode+ 0 encode-int encode+ + h# 1003120 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + h# 1003124 encode-int 0 encode-int encode+ h# 0 encode-int encode+ + h# 10 encode-int encode+ 0 encode-int encode+ + " reg" property +finish-device + +new-device + " ethernet" device-name + " network" device-type + " AMD,79C973" model + h# 3800 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ + " reg" property +finish-device + +" /pci/isa" find-device + 0 0 " assigned-addresses" property + 0 0 " ranges" property + 0 encode-int " slot-names" property + d# 8333333 encode-int " clock-frequency" property + 0 encode-int " eisa-slots" property + 2 encode-int " #interrupt-cells" property + " W83C553F" encode-string " compatible" property + " WINBOND,82C553" model + 0 encode-int " max-latency" property + 0 encode-int " min-grant" property + 1 encode-int " devsel-speed" property + 0 encode-int " subsystem-vendor-id" property + 0 encode-int " subsystem-id" property + h# 60100 encode-int " class-code" property + h# 10 encode-int " revision-id" property + h# 565 encode-int " device-id" property + h# 10AD encode-int " vendor-id" property + h# 3000 encode-int 0 encode-int encode+ 0 encode-int encode+ + 0 encode-int encode+ 0 encode-int encode+ " reg" property + +new-device + " rtc" device-name + " rtc" device-type + " DS17285S" model + " MC146818" encode-string + " DS17285S" encode-string encode+ + " pnpPNP,b00" encode-string encode+ " compatible" property + 8 encode-int 0 encode-int encode+ " interrupts" property + h# 70 encode-int 1 encode-int encode+ + 2 encode-int encode+ " reg" property +finish-device + +new-device + " interrupt-controller" device-name + " interrupt-controller" device-type + " 8259" model + " " encode-string " interrupt-controller" property + 2 encode-int " #interrupt-cells" property + 1 encode-int + 2 encode-int encode+ + 3 encode-int encode+ + 6 encode-int encode+ + " reserved-interrupts" property + " 8259" encode-string + " chrp,iic" encode-string encode+ + " compatible" property + h# 20 encode-int 1 encode-int encode+ + 2 encode-int encode+ " reg" property +finish-device + +new-device + " serial" device-name + " serial" device-type + " no" encode-string " ctsrts" property + " no" encode-string " xon" property + " no" encode-string " parity" property + d# 115200 encode-int " bps" property + 1 encode-int " stop-bits" property + 8 encode-int " data-bits" property + h# 70800 encode-int " divisor" property + h# 708000 encode-int " clock-frequency" property + 4 encode-int 0 encode-int encode+ " interrupts" property + h# 3F8 encode-int 1 encode-int encode+ + 8 encode-int encode+ " reg" property +finish-device + +" /pci" find-device + " /pci/isa/interrupt-controller" find-dev if + encode-int " interrupt-parent" property + then + h# 3800 encode-int 0 encode-int encode+ + 0 encode-int encode+ 1 encode-int encode+ + " /pci/isa/interrupt-controller" find-dev if + encode-int encode+ + then + h# 0C encode-int encode+ 1 encode-int encode+ + " interrupt-map" property + +" /pci/isa" find-device + " /pci/isa/interrupt-controller" find-dev if + encode-int " interrupt-parent" property + then + +\ ------------------------------------------------------------- +\ /packages +\ ------------------------------------------------------------- + +" /packages" find-device + + " packages" device-name + external + \ allow packages to be opened with open-dev + : open true ; + : close ; + +\ /packages/terminal-emulator +new-device + " terminal-emulator" device-name + external + : open true ; + : close ; + \ : write ( addr len -- actual ) + \ dup -rot type + \ ; +finish-device + +\ ------------------------------------------------------------- +\ The END +\ ------------------------------------------------------------- +device-end diff --git a/qemu/roms/openbios/arch/ppc/pearpc/vfd.c b/qemu/roms/openbios/arch/ppc/pearpc/vfd.c new file mode 100644 index 000000000..06485f2dc --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/pearpc/vfd.c @@ -0,0 +1,42 @@ +/* + * Creation Date: <2004/08/28 17:29:43 greg> + * Time-stamp: <2004/08/28 17:29:43 greg> + * + * <vfd.c> + * + * Simple text console + * + * Copyright (C) 2004 Greg Watson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "pearpc/pearpc.h" + +static int vfd_is_open; + +static int +vfd_init( void ) +{ + vfd_is_open = 1; + return 0; +} + +void +vfd_close( void ) +{ +} + +int +vfd_draw_str( const char *str ) +{ + if (!vfd_is_open) + vfd_init(); + + return 0; +} diff --git a/qemu/roms/openbios/arch/ppc/ppc.fs b/qemu/roms/openbios/arch/ppc/ppc.fs new file mode 100644 index 000000000..0414f22c4 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/ppc.fs @@ -0,0 +1,68 @@ +include config.fs + +\ ------------------------------------------------------------------------- +\ registers +\ ------------------------------------------------------------------------- + +0 value %cr +0 value %ctr +0 value %lr +0 value %msr +0 value %srr0 +0 value %srr1 +0 value %pc \ should be an alias for %srr0 + +0 value %r0 +0 value %r1 +0 value %r2 +0 value %r3 +0 value %r4 +0 value %r5 +0 value %r6 +0 value %r7 +0 value %r8 +0 value %r9 +0 value %r10 +0 value %r11 +0 value %r12 +0 value %r13 +0 value %r14 +0 value %r15 +0 value %r16 +0 value %r17 +0 value %r18 +0 value %r19 +0 value %r20 +0 value %r21 +0 value %r22 +0 value %r23 +0 value %r24 +0 value %r25 +0 value %r26 +0 value %r27 +0 value %r28 +0 value %r29 +0 value %r30 +0 value %r31 + +0 value %xer +0 value %sprg0 +0 value %sprg1 +0 value %sprg2 +0 value %sprg3 + +\ ------------------------------------------------------------------------- +\ Load VGA FCode driver blob +\ ------------------------------------------------------------------------- + +[IFDEF] CONFIG_DRIVER_VGA + -1 value vga-driver-fcode + " QEMU,VGA.bin" $encode-file to vga-driver-fcode +[THEN] + +\ ------------------------------------------------------------------------- +\ other +\ ------------------------------------------------------------------------- + +\ Set by BootX when booting Mac OS X +defer spin diff --git a/qemu/roms/openbios/arch/ppc/qemu/console.c b/qemu/roms/openbios/arch/ppc/qemu/console.c new file mode 100644 index 000000000..53a321525 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/console.c @@ -0,0 +1,88 @@ +/* + * <console.c> + * + * Simple text console + * + * Copyright (C) 2005 Stefan Reinauer <stepan@openbios.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "drivers/drivers.h" + +#ifdef CONFIG_DEBUG_CONSOLE +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +static int mac_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + escc_uart_putchar(c & 0xff); +#endif + return c; +} + +static int mac_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif + return 0; +} + +static int mac_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return (escc_uart_getchar(CONFIG_SERIAL_PORT)); +#endif + return 0; +} + +struct _console_ops mac_console_ops = { + .putchar = mac_putchar, + .availchar = mac_availchar, + .getchar = mac_getchar +}; + +static int prep_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_putchar(c & 0xff); +#endif + return c; +} + +static int prep_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif + return 0; +} + +static int prep_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return (uart_getchar(CONFIG_SERIAL_PORT)); +#endif + return 0; +} + +struct _console_ops prep_console_ops = { + .putchar = prep_putchar, + .availchar = prep_availchar, + .getchar = prep_getchar +}; + +#endif // CONFIG_DEBUG_CONSOLE diff --git a/qemu/roms/openbios/arch/ppc/qemu/init.c b/qemu/roms/openbios/arch/ppc/qemu/init.c new file mode 100644 index 000000000..4fe8b7220 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/init.c @@ -0,0 +1,951 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <init.c> + * + * Initialization for qemu + * + * Copyright (C) 2004 Greg Watson + * Copyright (C) 2005 Stefan Reinauer + * + * based on mol/init.c: + * + * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Samuel & David Rydh + * (samuel@ibrium.se, dary@lindesign.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "drivers/pci.h" +#include "arch/common/nvram.h" +#include "drivers/drivers.h" +#include "qemu/qemu.h" +#include "libopenbios/ofmem.h" +#include "openbios-version.h" +#include "libc/byteorder.h" +#include "libc/vsprintf.h" +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h" +#include "arch/ppc/processor.h" + +#define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" + +struct cpudef { + unsigned int iu_version; + const char *name; + int icache_size, dcache_size; + int icache_sets, dcache_sets; + int icache_block_size, dcache_block_size; + int tlb_sets, tlb_size; + void (*initfn)(const struct cpudef *cpu); +}; + +static uint16_t machine_id = 0; + +extern void unexpected_excep(int vector); + +void +unexpected_excep(int vector) +{ + printk("openbios panic: Unexpected exception %x\n", vector); + for (;;) { + } +} + +extern void __divide_error(void); + +void +__divide_error(void) +{ + return; +} + +enum { + ARCH_PREP = 0, + ARCH_MAC99, + ARCH_HEATHROW, + ARCH_MAC99_U3, +}; + +int is_apple(void) +{ + return is_oldworld() || is_newworld(); +} + +int is_oldworld(void) +{ + return machine_id == ARCH_HEATHROW; +} + +int is_newworld(void) +{ + return (machine_id == ARCH_MAC99) || + (machine_id == ARCH_MAC99_U3); +} + +static const pci_arch_t known_arch[] = { + [ARCH_PREP] = { + .name = "PREP", + .vendor_id = PCI_VENDOR_ID_MOTOROLA, + .device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN, + .cfg_addr = 0x80000cf8, + .cfg_data = 0x80000cfc, + .cfg_base = 0x80000000, + .cfg_len = 0x00100000, + .host_pci_base = 0xc0000000, + .pci_mem_base = 0x100000, /* avoid VGA at 0xa0000 */ + .mem_len = 0x10000000, + .io_base = 0x80000000, + .io_len = 0x00010000, + .rbase = 0x00000000, + .rlen = 0x00400000, + .irqs = { 9, 11, 9, 11 } + }, + [ARCH_MAC99] = { + .name = "MAC99", + .vendor_id = PCI_VENDOR_ID_APPLE, + .device_id = PCI_DEVICE_ID_APPLE_UNI_N_PCI, + .cfg_addr = 0xf2800000, + .cfg_data = 0xf2c00000, + .cfg_base = 0xf2000000, + .cfg_len = 0x02000000, + .host_pci_base = 0x0, + .pci_mem_base = 0x80000000, + .mem_len = 0x10000000, + .io_base = 0xf2000000, + .io_len = 0x00800000, + .rbase = 0x00000000, + .rlen = 0x01000000, + .irqs = { 0x1b, 0x1c, 0x1d, 0x1e } + }, + [ARCH_MAC99_U3] = { + .name = "MAC99_U3", + .vendor_id = PCI_VENDOR_ID_APPLE, + .device_id = PCI_DEVICE_ID_APPLE_U3_AGP, + .cfg_addr = 0xf0800000, + .cfg_data = 0xf0c00000, + .cfg_base = 0xf0000000, + .cfg_len = 0x02000000, + .host_pci_base = 0x0, + .pci_mem_base = 0x80000000, + .mem_len = 0x10000000, + .io_base = 0xf2000000, + .io_len = 0x00800000, + .rbase = 0x00000000, + .rlen = 0x01000000, + .irqs = { 0x1b, 0x1c, 0x1d, 0x1e } + }, + [ARCH_HEATHROW] = { + .name = "HEATHROW", + .vendor_id = PCI_VENDOR_ID_MOTOROLA, + .device_id = PCI_DEVICE_ID_MOTOROLA_MPC106, + .cfg_addr = 0xfec00000, + .cfg_data = 0xfee00000, + .cfg_base = 0x80000000, + .cfg_len = 0x7f000000, + .host_pci_base = 0x0, + .pci_mem_base = 0x80000000, + .mem_len = 0x10000000, + .io_base = 0xfe000000, + .io_len = 0x00800000, + .rbase = 0xfd000000, + .rlen = 0x01000000, + .irqs = { 21, 22, 23, 24 } + }, +}; +unsigned long isa_io_base; + +extern struct _console_ops mac_console_ops, prep_console_ops; + +void +entry(void) +{ + uint32_t temp = 0; + char buf[5]; + + arch = &known_arch[ARCH_HEATHROW]; + + fw_cfg_init(); + + fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); + buf[4] = '\0'; + if (strncmp(buf, "QEMU", 4) == 0) { + temp = fw_cfg_read_i32(FW_CFG_ID); + if (temp == 1) { + machine_id = fw_cfg_read_i16(FW_CFG_MACHINE_ID); + arch = &known_arch[machine_id]; + } + } + + isa_io_base = arch->io_base; + +#ifdef CONFIG_DEBUG_CONSOLE + if (is_apple()) { + init_console(mac_console_ops); + } else { + init_console(prep_console_ops); + } +#endif + + if (temp != 1) { + printk("Incompatible configuration device version, freezing\n"); + for (;;) { + } + } + + ofmem_init(); + initialize_forth(); + /* won't return */ + + printk("of_startup returned!\n"); + for (;;) { + } +} + +/* -- phys.lo ... phys.hi */ +static void +push_physaddr(phys_addr_t value) +{ + PUSH(value); +#ifdef CONFIG_PPC64 + PUSH(value >> 32); +#endif +} + +/* From drivers/timer.c */ +extern unsigned long timer_freq; + +static void +cpu_generic_init(const struct cpudef *cpu) +{ + push_str("/cpus"); + fword("find-device"); + + fword("new-device"); + + push_str(cpu->name); + fword("device-name"); + + push_str("cpu"); + fword("device-type"); + + PUSH(mfpvr()); + fword("encode-int"); + push_str("cpu-version"); + fword("property"); + + PUSH(cpu->dcache_size); + fword("encode-int"); + push_str("d-cache-size"); + fword("property"); + + PUSH(cpu->icache_size); + fword("encode-int"); + push_str("i-cache-size"); + fword("property"); + + PUSH(cpu->dcache_sets); + fword("encode-int"); + push_str("d-cache-sets"); + fword("property"); + + PUSH(cpu->icache_sets); + fword("encode-int"); + push_str("i-cache-sets"); + fword("property"); + + PUSH(cpu->dcache_block_size); + fword("encode-int"); + push_str("d-cache-block-size"); + fword("property"); + + PUSH(cpu->icache_block_size); + fword("encode-int"); + push_str("i-cache-block-size"); + fword("property"); + + PUSH(cpu->tlb_sets); + fword("encode-int"); + push_str("tlb-sets"); + fword("property"); + + PUSH(cpu->tlb_size); + fword("encode-int"); + push_str("tlb-size"); + fword("property"); + + timer_freq = fw_cfg_read_i32(FW_CFG_PPC_TBFREQ); + PUSH(timer_freq); + fword("encode-int"); + push_str("timebase-frequency"); + fword("property"); + + PUSH(fw_cfg_read_i32(FW_CFG_PPC_CLOCKFREQ)); + fword("encode-int"); + push_str("clock-frequency"); + fword("property"); + + PUSH(fw_cfg_read_i32(FW_CFG_PPC_BUSFREQ)); + fword("encode-int"); + push_str("bus-frequency"); + fword("property"); + + push_str("running"); + fword("encode-string"); + push_str("state"); + fword("property"); +} + +static void +cpu_add_pir_property(void) +{ + unsigned long pir; + + asm("mfspr %0, 1023\n" + : "=r"(pir) :); + PUSH(pir); + fword("encode-int"); + push_str("reg"); + fword("property"); +} + +static void +cpu_604_init(const struct cpudef *cpu) +{ + cpu_generic_init(cpu); + cpu_add_pir_property(); + + fword("finish-device"); +} + +static void +cpu_750_init(const struct cpudef *cpu) +{ + cpu_generic_init(cpu); + + PUSH(0); + fword("encode-int"); + push_str("reg"); + fword("property"); + + fword("finish-device"); +} + +static void +cpu_g4_init(const struct cpudef *cpu) +{ + cpu_generic_init(cpu); + cpu_add_pir_property(); + + fword("finish-device"); +} + +#ifdef CONFIG_PPC_64BITSUPPORT +/* In order to get 64 bit aware handlers that rescue all our + GPRs from getting truncated to 32 bits, we need to patch the + existing handlers so they jump to our 64 bit aware ones. */ +static void +ppc64_patch_handlers(void) +{ + uint32_t *dsi = (uint32_t *)0x300UL; + uint32_t *isi = (uint32_t *)0x400UL; + + // Patch the first DSI handler instruction to: ba 0x2000 + *dsi = 0x48002002; + + // Patch the first ISI handler instruction to: ba 0x2200 + *isi = 0x48002202; + + // Invalidate the cache lines + asm ("icbi 0, %0" : : "r"(dsi)); + asm ("icbi 0, %0" : : "r"(isi)); +} +#endif + +static void +cpu_970_init(const struct cpudef *cpu) +{ + cpu_generic_init(cpu); + + PUSH(0); + fword("encode-int"); + push_str("reg"); + fword("property"); + + PUSH(0); + PUSH(0); + fword("encode-bytes"); + push_str("64-bit"); + fword("property"); + + fword("finish-device"); + +#ifdef CONFIG_PPC_64BITSUPPORT + /* The 970 is a PPC64 CPU, so we need to activate + * 64bit aware interrupt handlers */ + + ppc64_patch_handlers(); +#endif + + /* The 970 also implements the HIOR which we need to set to 0 */ + + mtspr(S_HIOR, 0); +} + +static const struct cpudef ppc_defs[] = { + { + .iu_version = 0x00040000, + .name = "PowerPC,604", + .icache_size = 0x4000, + .dcache_size = 0x4000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_604_init, + }, + { // XXX find out real values + .iu_version = 0x00090000, + .name = "PowerPC,604e", + .icache_size = 0x4000, + .dcache_size = 0x4000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_604_init, + }, + { // XXX find out real values + .iu_version = 0x000a0000, + .name = "PowerPC,604r", + .icache_size = 0x4000, + .dcache_size = 0x4000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_604_init, + }, + { // XXX find out real values + .iu_version = 0x80040000, + .name = "PowerPC,MPC86xx", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { + .iu_version = 0x000080000, + .name = "PowerPC,750", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { // XXX find out real values + .iu_version = 0x10080000, + .name = "PowerPC,750", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { // XXX find out real values + .iu_version = 0x70000000, + .name = "PowerPC,750", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { // XXX find out real values + .iu_version = 0x70020000, + .name = "PowerPC,750", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { // XXX find out real values + .iu_version = 0x800c0000, + .name = "PowerPC,74xx", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_750_init, + }, + { + .iu_version = 0x0000c0000, + .name = "PowerPC,G4", + .icache_size = 0x8000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x20, + .dcache_block_size = 0x20, + .tlb_sets = 0x40, + .tlb_size = 0x80, + .initfn = cpu_g4_init, + }, + { + .iu_version = 0x00390000, + .name = "PowerPC,970", + .icache_size = 0x10000, + .dcache_size = 0x8000, + .icache_sets = 0x200, + .dcache_sets = 0x80, + .icache_block_size = 0x80, + .dcache_block_size = 0x80, + .tlb_sets = 0x100, + .tlb_size = 0x1000, + .initfn = cpu_970_init, + }, + { // XXX find out real values + .iu_version = 0x003C0000, + .name = "PowerPC,970FX", + .icache_size = 0x10000, + .dcache_size = 0x8000, + .icache_sets = 0x80, + .dcache_sets = 0x80, + .icache_block_size = 0x80, + .dcache_block_size = 0x80, + .tlb_sets = 0x100, + .tlb_size = 0x1000, + .initfn = cpu_970_init, + }, + { + .iu_version = 0x00350000, + .name = "PowerPC,POWER4", + .icache_size = 0x10000, + .dcache_size = 0x8000, + .icache_sets = 0x100, + .dcache_sets = 0x40, + .icache_block_size = 0x80, + .dcache_block_size = 0x80, + .tlb_sets = 0x100, + .tlb_size = 0x1000, + .initfn = cpu_970_init, + }, +}; + +static const struct cpudef * +id_cpu(void) +{ + unsigned int iu_version; + unsigned int i; + + iu_version = mfpvr() & 0xffff0000; + + for (i = 0; i < sizeof(ppc_defs) / sizeof(struct cpudef); i++) { + if (iu_version == ppc_defs[i].iu_version) + return &ppc_defs[i]; + } + printk("Unknown cpu (pvr %x), freezing!\n", iu_version); + for (;;) { + } +} + +static void go(void); + +static void +go(void) +{ + ucell addr; + + feval("saved-program-state >sps.entry @"); + addr = POP(); + + call_elf(0, 0, addr); +} + +static void kvm_of_init(void) +{ + char hypercall[4 * 4]; + uint32_t *hc32; + + /* Don't expose /hypervisor when not in KVM */ + if (!fw_cfg_read_i32(FW_CFG_PPC_IS_KVM)) + return; + + push_str("/"); + fword("find-device"); + + fword("new-device"); + + push_str("hypervisor"); + fword("device-name"); + + push_str("hypervisor"); + fword("device-type"); + + /* compatible */ + + push_str("linux,kvm"); + fword("encode-string"); + push_str("epapr,hypervisor-0.2"); + fword("encode-string"); + fword("encode+"); + push_str("compatible"); + fword("property"); + + /* Tell the guest about the hypercall instructions */ + fw_cfg_read(FW_CFG_PPC_KVM_HC, hypercall, 4 * 4); + hc32 = (uint32_t*)hypercall; + PUSH(hc32[0]); + fword("encode-int"); + PUSH(hc32[1]); + fword("encode-int"); + fword("encode+"); + PUSH(hc32[2]); + fword("encode-int"); + fword("encode+"); + PUSH(hc32[3]); + fword("encode-int"); + fword("encode+"); + push_str("hcall-instructions"); + fword("property"); + + /* ePAPR requires us to provide a unique guest id */ + PUSH(fw_cfg_read_i32(FW_CFG_PPC_KVM_PID)); + fword("encode-int"); + push_str("guest-id"); + fword("property"); + + /* ePAPR requires us to provide a guest name */ + push_str("KVM guest"); + fword("encode-string"); + push_str("guest-name"); + fword("property"); + + fword("finish-device"); +} + +/* + * filll ( addr bytes quad -- ) + */ + +static void ffilll(void) +{ + const u32 longval = POP(); + u32 bytes = POP(); + u32 *laddr = (u32 *)cell2pointer(POP()); + u32 len; + + for (len = 0; len < bytes / sizeof(u32); len++) { + *laddr++ = longval; + } +} + +void +arch_of_init(void) +{ +#ifdef CONFIG_RTAS + phandle_t ph; +#endif + uint64_t ram_size; + const struct cpudef *cpu; + char buf[64], qemu_uuid[16]; + const char *stdin_path, *stdout_path, *boot_path; + uint32_t temp = 0; + char *boot_device; + ofmem_t *ofmem = ofmem_arch_get_private(); + + openbios_init(); + modules_init(); + setup_timers(); +#ifdef CONFIG_DRIVER_PCI + ob_pci_init(); +#endif + + printk("\n"); + printk("=============================================================\n"); + printk(PROGRAM_NAME " " OPENBIOS_VERSION_STR " [%s]\n", + OPENBIOS_BUILD_DATE); + + fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); + buf[4] = '\0'; + printk("Configuration device id %s", buf); + + temp = fw_cfg_read_i32(FW_CFG_ID); + printk(" version %d machine id %d\n", temp, machine_id); + + temp = fw_cfg_read_i32(FW_CFG_NB_CPUS); + + printk("CPUs: %x\n", temp); + + ram_size = ofmem->ramsize; + + printk("Memory: %lldM\n", ram_size / 1024 / 1024); + + fw_cfg_read(FW_CFG_UUID, qemu_uuid, 16); + + printk("UUID: " UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], + qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], + qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], + qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], + qemu_uuid[15]); + + /* set device tree root info */ + + push_str("/"); + fword("find-device"); + + switch(machine_id) { + case ARCH_HEATHROW: /* OldWorld */ + + /* model */ + + push_str("Power Macintosh"); + fword("model"); + + /* compatible */ + + push_str("AAPL,PowerMac G3"); + fword("encode-string"); + push_str("MacRISC"); + fword("encode-string"); + fword("encode+"); + push_str("compatible"); + fword("property"); + + /* misc */ + + push_str("device-tree"); + fword("encode-string"); + push_str("AAPL,original-name"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("AAPL,cpu-id"); + fword("property"); + + PUSH(66 * 1000 * 1000); + fword("encode-int"); + push_str("clock-frequency"); + fword("property"); + break; + + case ARCH_MAC99: + case ARCH_MAC99_U3: + case ARCH_PREP: + default: + + /* model */ + + push_str("PowerMac3,1"); + fword("model"); + + /* compatible */ + + push_str("PowerMac3,1"); + fword("encode-string"); + push_str("MacRISC"); + fword("encode-string"); + fword("encode+"); + push_str("MacRISC2"); + fword("encode-string"); + fword("encode+"); + push_str("Power Macintosh"); + fword("encode-string"); + fword("encode+"); + push_str("compatible"); + fword("property"); + + /* misc */ + + push_str("bootrom"); + fword("device-type"); + + PUSH(100 * 1000 * 1000); + fword("encode-int"); + push_str("clock-frequency"); + fword("property"); + break; + } + + /* Perhaps we can store UUID here ? */ + + push_str("0000000000000"); + fword("encode-string"); + push_str("system-id"); + fword("property"); + + /* memory info */ + + push_str("/memory"); + fword("find-device"); + + /* all memory */ + + push_physaddr(0); + fword("encode-phys"); + /* This needs adjusting if #size-cells gets increased. + Alternatively use multiple (address, size) tuples. */ + PUSH(ram_size & 0xffffffff); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); + + cpu = id_cpu(); + cpu->initfn(cpu); + printk("CPU type %s\n", cpu->name); + + snprintf(buf, sizeof(buf), "/cpus/%s", cpu->name); + ofmem_register(find_dev("/memory"), find_dev(buf)); + node_methods_init(buf); + +#ifdef CONFIG_RTAS + /* OldWorld Macs don't have an /rtas node. */ + switch (machine_id) { + case ARCH_MAC99: + case ARCH_MAC99_U3: + if (!(ph = find_dev("/rtas"))) { + printk("Warning: No /rtas node\n"); + } else { + unsigned long size = 0x1000; + while (size < (unsigned long)of_rtas_end - (unsigned long)of_rtas_start) + size *= 2; + set_property(ph, "rtas-size", (char*)&size, sizeof(size)); + set_int_property(ph, "rtas-version", is_apple() ? 0x41 : 1); + } + break; + } +#endif + + if (fw_cfg_read_i16(FW_CFG_NOGRAPHIC)) { + if (is_apple()) { + if (CONFIG_SERIAL_PORT) { + stdin_path = "scca"; + stdout_path = "scca"; + } else { + stdin_path = "sccb"; + stdout_path = "sccb"; + } + } else { + stdin_path = "ttya"; + stdout_path = "ttya"; + } + + /* Some bootloaders force the output to the screen device, so + let's create a screen alias for the serial device too */ + + push_str("/aliases"); + fword("find-device"); + + push_str(stdout_path); + fword("pathres-resolve-aliases"); + fword("encode-string"); + push_str("screen"); + fword("property"); + } else { + if (is_apple()) { + stdin_path = "adb-keyboard"; + stdout_path = "screen"; + } else { + stdin_path = "keyboard"; + stdout_path = "screen"; + } + } + + kvm_of_init(); + + /* Setup nvram variables */ + push_str("/options"); + fword("find-device"); + + /* Setup default boot devices (not overriding user settings) */ + fword("boot-device"); + boot_device = pop_fstr_copy(); + if (boot_device && strcmp(boot_device, "disk") == 0) { + switch (fw_cfg_read_i16(FW_CFG_BOOT_DEVICE)) { + case 'c': + boot_path = "hd"; + break; + default: + case 'd': + boot_path = "cd"; + break; + } + + snprintf(buf, sizeof(buf), "%s:,\\\\:tbxi %s:,\\ppc\\bootinfo.txt %s:,%%BOOT", boot_path, boot_path, boot_path); + push_str(buf); + fword("encode-string"); + push_str("boot-device"); + fword("property"); + } + free(boot_device); + + /* Set up other properties */ + + push_str("/chosen"); + fword("find-device"); + + push_str(stdin_path); + fword("pathres-resolve-aliases"); + push_str("input-device"); + fword("$setenv"); + + push_str(stdout_path); + fword("pathres-resolve-aliases"); + push_str("output-device"); + fword("$setenv"); + +#if 0 + if(getbool("tty-interface?") == 1) +#endif + fword("activate-tty-interface"); + + device_end(); + + /* Implementation of filll word (required by BootX) */ + bind_func("filll", ffilll); + + bind_func("platform-boot", boot); + bind_func("(go)", go); +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/kernel.c b/qemu/roms/openbios/arch/ppc/qemu/kernel.c new file mode 100644 index 000000000..b26fba5f7 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/kernel.c @@ -0,0 +1,115 @@ +/* + * Creation Date: <2003/10/25 14:07:17 samuel> + * Time-stamp: <2004/08/28 17:48:19 stepan> + * + * <kernel.c> + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * Based upon unix.c (from OpenBIOS): + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "dict.h" +#include "libopenbios/bindings.h" +#include "kernel/stack.h" +#include "kernel/kernel.h" +#include "libc/string.h" +#include "kernel.h" + +#define MEMORY_SIZE (256*1024) /* 256K ram for hosted system */ +/* 512K for the dictionary */ +#define DICTIONARY_SIZE (512 * 1024 / sizeof(ucell)) +#ifdef __powerpc64__ +#define DICTIONARY_BASE 0xfff08000 /* this must match the value in ldscript! */ +#define DICTIONARY_SECTION __attribute__((section(".data.dict"))) +#else +#define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary)) +#define DICTIONARY_SECTION +#endif + +static ucell forth_dictionary[DICTIONARY_SIZE] DICTIONARY_SECTION = { +#include "qemu-dict.h" +}; + +static ucell *memory; + +/************************************************************************/ +/* F U N C T I O N S */ +/************************************************************************/ + +int +forth_segv_handler( char *segv_addr ) +{ + ucell addr = 0xdeadbeef; + + if( PC >= pointer2cell(dict) && PC <= pointer2cell(dict) + dicthead ) + addr = *(ucell *)cell2pointer(PC); + + printk("panic: segmentation violation at 0x%p\n", segv_addr); + printk("dict=0x%p here=0x%p(dict+0x%x) pc=0x%x(dict+0x%x)\n", + dict, (char*)dict + dicthead, dicthead, + PC, PC - pointer2cell(dict)); + printk("dstackcnt=%d rstackcnt=%d instruction=%x\n", + dstackcnt, rstackcnt, addr); + +#ifdef DEBUG_DSTACK + printdstack(); +#endif +#ifdef DEBUG_RSTACK + printrstack(); +#endif + return -1; +} + +/* + * allocate memory and prepare engine for memory management. + */ + +static void +init_memory( void ) +{ + memory = malloc(MEMORY_SIZE); + if( !memory ) + panic("panic: not enough memory on host system.\n"); + + /* we push start and end of memory to the stack + * so that it can be used by the forth word QUIT + * to initialize the memory allocator + */ + + PUSH( pointer2cell(memory) ); + PUSH( pointer2cell(memory) + MEMORY_SIZE ); +} + +int +initialize_forth( void ) +{ + dict = (unsigned char *)forth_dictionary; + dicthead = (ucell)FORTH_DICTIONARY_END; + last = (ucell *)((unsigned char *)forth_dictionary + + FORTH_DICTIONARY_LAST); + dictlimit = sizeof(forth_dictionary); + + forth_init(); + + PUSH_xt( bind_noname_func(arch_of_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + if( PC ) { + init_memory(); + enterforth((xt_t)PC); + free( memory ); + } + free( dict ); + return 0; +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/kernel.h b/qemu/roms/openbios/arch/ppc/qemu/kernel.h new file mode 100644 index 000000000..fe9be83d9 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/kernel.h @@ -0,0 +1,42 @@ +/* + * Creation Date: <2004/08/28 17:50:12 stepan> + * Time-stamp: <2004/08/28 17:50:12 stepan> + * + * <kernel.h> + * + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef __KERNEL_H__ +#define __KERNEL_H__ + +/* misc.c */ +extern void fatal_error( const char *str ); +extern void exit( int status ) __attribute__ ((noreturn)); + +/* start.S */ +extern void flush_icache_range( char *start, char *stop ); +extern char of_rtas_start[], of_rtas_end[]; +extern void call_elf( unsigned long arg1, unsigned long arg2, unsigned long elf_entry ); + +/* methods.c */ +extern void node_methods_init( const char *cpuname ); + +/* main.c */ +extern void boot( void ); + +/* init.c */ +extern void entry( void ); +extern void arch_of_init( void ); +extern int get_bool_res( const char *str ); + +/* tree.c */ +extern void devtree_init( void ); + + +#endif /* __KERNEL_H__ */ diff --git a/qemu/roms/openbios/arch/ppc/qemu/ldscript b/qemu/roms/openbios/arch/ppc/qemu/ldscript new file mode 100644 index 000000000..8027b39db --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/ldscript @@ -0,0 +1,68 @@ +OUTPUT_FORMAT(elf32-powerpc) +OUTPUT_ARCH(powerpc:common) + +/* Initial load address + */ +BASE_ADDR = 0xfff00000; + +/* As NVRAM is at 0xfff04000, the .text needs to be after that + */ +TEXT_ADDR = 0xfff08000; + +/* Hard reset vector address + */ +HRESET_ADDR = 0xfffffffc; + +CSTACK_SIZE = 32768; /* client stack size */ + +SECTIONS +{ + . = BASE_ADDR; + + _start = BASE_ADDR + 0x0100; + .text.vectors ALIGN(4096): { + *(.text.vectors) + } + + . = TEXT_ADDR; + /* Normal sections */ + .text ALIGN(4096): { + *(.text) + *(.text.*) + } + + .rodata ALIGN(4096): { + _rodata = .; + *(.rodata) + *(.rodata.*) + *(.note.ELFBoot) + } + .data ALIGN(4096): { + _data = .; + *(.data) + *(.data.*) + _edata = .; + } + + .bss ALIGN(4096): { + _bss = .; + *(.sbss) + *(.sbss.*) + *(.bss) + *(.bss.*) + *(COMMON) + _ebss = .; + } + + . = HRESET_ADDR; + + .romentry : { *(.romentry) } + + . = ALIGN(4096); + _end = .; + + /* We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + + /DISCARD/ : { *(.comment*) *(.note.*) } +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/main.c b/qemu/roms/openbios/arch/ppc/qemu/main.c new file mode 100644 index 000000000..44b16666b --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/main.c @@ -0,0 +1,85 @@ +/* + * Creation Date: <2002/10/02 22:24:24 samuel> + * Time-stamp: <2004/03/27 01:57:55 samuel> + * + * <main.c> + * + * + * + * Copyright (C) 2002, 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elf_load.h" +#include "arch/common/nvram.h" +#include "packages/nvram.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "kernel.h" +#include "drivers/drivers.h" +#include "libopenbios/ofmem.h" +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h" + +//#define DEBUG_QEMU + +#ifdef DEBUG_QEMU +#define SUBSYS_DPRINTF(subsys, fmt, args...) \ + do { printk("%s - %s: " fmt, subsys, __func__ , ##args); } while (0) +#else +#define SUBSYS_DPRINTF(subsys, fmt, args...) \ + do { } while (0) +#endif +#define CHRP_DPRINTF(fmt, args...) SUBSYS_DPRINTF("CHRP", fmt, ##args) +#define ELF_DPRINTF(fmt, args...) SUBSYS_DPRINTF("ELF", fmt, ##args) +#define NEWWORLD_DPRINTF(fmt, args...) SUBSYS_DPRINTF("NEWWORLD", fmt, ##args) + +static void check_preloaded_kernel(void) +{ + unsigned long kernel_image, kernel_size; + unsigned long initrd_image, initrd_size; + const char * kernel_cmdline; + + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); + if (kernel_size) { + kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR); + kernel_cmdline = (const char *)(uintptr_t) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE); + initrd_image = fw_cfg_read_i32(FW_CFG_INITRD_ADDR); + initrd_size = fw_cfg_read_i32(FW_CFG_INITRD_SIZE); + printk("[ppc] Kernel already loaded (0x%8.8lx + 0x%8.8lx) " + "(initrd 0x%8.8lx + 0x%8.8lx)\n", + kernel_image, kernel_size, initrd_image, initrd_size); + if (kernel_cmdline) { + phandle_t ph; + printk("[ppc] Kernel command line: %s\n", kernel_cmdline); + ph = find_dev("/chosen"); + set_property(ph, "bootargs", strdup(kernel_cmdline), strlen(kernel_cmdline) + 1); + } + call_elf(initrd_image, initrd_size, kernel_image); + } +} + +/************************************************************************/ +/* entry */ +/************************************************************************/ + +void +boot( void ) +{ + uint16_t boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE); + + fword("update-chosen"); + if (boot_device == 'm') { + check_preloaded_kernel(); + } + + if (is_apple()) { + update_nvram(); + } +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/methods.c b/qemu/roms/openbios/arch/ppc/qemu/methods.c new file mode 100644 index 000000000..fd993daa9 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/methods.c @@ -0,0 +1,327 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <methods.c> + * + * Misc device node methods + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "drivers/drivers.h" +#include "libc/string.h" +#include "qemu/qemu.h" +#include "libopenbios/ofmem.h" +#include "arch/ppc/processor.h" +#include "drivers/usb.h" + +/************************************************************************/ +/* RTAS (run-time abstraction services) */ +/************************************************************************/ + +#ifdef CONFIG_RTAS +DECLARE_NODE( rtas, INSTALL_OPEN, 0, "+/rtas" ); + +/* ( physbase -- rtas_callback ) */ +static void +rtas_instantiate( void ) +{ + ucell physbase = POP(); + ucell s=0x1000, size = (ucell)of_rtas_end - (ucell)of_rtas_start; + unsigned long virt; + + while( s < size ) + s += 0x1000; + virt = ofmem_claim_virt( 0, s, 0x1000 ); + ofmem_map( physbase, virt, s, -1 ); + memcpy( (char*)virt, of_rtas_start, size ); + + printk("RTAS instantiated at %08x\n", physbase ); + flush_icache_range( (char*)virt, (char*)virt + size ); + + PUSH( physbase ); +} + +NODE_METHODS( rtas ) = { + { "instantiate", rtas_instantiate }, + { "instantiate-rtas", rtas_instantiate }, +}; +#endif + + +/************************************************************************/ +/* tty */ +/************************************************************************/ + +DECLARE_NODE( tty, INSTALL_OPEN, 0, "/packages/terminal-emulator" ); + +/* ( addr len -- actual ) */ +static void +tty_read( void ) +{ + int ch, len = POP(); + char *p = (char*)cell2pointer(POP()); + int ret=0; + + if( len > 0 ) { + ret = 1; + ch = getchar(); + if( ch >= 0 ) { + *p = ch; + } else { + ret = 0; + } + } + PUSH( ret ); +} + +/* ( addr len -- actual ) */ +static void +tty_write( void ) +{ + int i, len = POP(); + char *p = (char*)cell2pointer(POP()); + for( i=0; i<len; i++ ) + putchar( *p++ ); + RET( len ); +} + +NODE_METHODS( tty ) = { + { "read", tty_read }, + { "write", tty_write }, +}; + +/************************************************************************/ +/* client interface 'quiesce' */ +/************************************************************************/ + +DECLARE_NODE( ciface, 0, 0, "+/openprom/client-services" ); + +/* ( -- ) */ +static void +ciface_quiesce( unsigned long args[], unsigned long ret[] ) +{ + usb_exit(); +#if 0 + unsigned long msr; + /* This seems to be the correct thing to do - but I'm not sure */ + asm volatile("mfmsr %0" : "=r" (msr) : ); + msr &= ~(MSR_IR | MSR_DR); + asm volatile("mtmsr %0" :: "r" (msr) ); +#endif +} + +/* ( -- ms ) */ +#define TIMER_FREQUENCY 16600000ULL + +static void +ciface_milliseconds( unsigned long args[], unsigned long ret[] ) +{ + unsigned long tbu, tbl, temp; + unsigned long long ticks, msecs; + + asm volatile( + "1:\n" + "mftbu %2\n" + "mftb %0\n" + "mftbu %1\n" + "cmpw %2,%1\n" + "bne 1b\n" + : "=r"(tbl), "=r"(tbu), "=r"(temp) + : + : "cc"); + + ticks = (((unsigned long long)tbu) << 32) | (unsigned long long)tbl; + msecs = (1000 * ticks) / TIMER_FREQUENCY; + PUSH( msecs ); +} + + +NODE_METHODS( ciface ) = { + { "quiesce", ciface_quiesce }, + { "milliseconds", ciface_milliseconds }, +}; + + +/************************************************************************/ +/* MMU/memory methods */ +/************************************************************************/ + +DECLARE_NODE( memory, INSTALL_OPEN, 0, "/memory" ); +DECLARE_UNNAMED_NODE( mmu, INSTALL_OPEN, 0 ); +DECLARE_NODE( mmu_ciface, 0, 0, "+/openprom/client-services" ); + + +/* ( phys size align --- base ) */ +static void +mem_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_phys( phys, size, align ); + + if( ret == -1 ) { + printk("MEM: claim failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mem_release( void ) +{ + POP(); POP(); +} + +/* ( phys size align --- base ) */ +static void +mmu_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell phys = POP(); + ucell ret = ofmem_claim_virt( phys, size, align ); + + if( ret == -1 ) { + printk("MMU: CLAIM failure\n"); + throw( -13 ); + return; + } + PUSH( ret ); +} + +/* ( phys size --- ) */ +static void +mmu_release( void ) +{ + POP(); POP(); +} + +/* ( phys virt size mode -- [ret???] ) */ +static void +mmu_map( void ) +{ + ucell mode = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell phys = POP(); + ucell ret; + + /* printk("mmu_map: %x %x %x %x\n", phys, virt, size, mode ); */ + ret = ofmem_map( phys, virt, size, mode ); + + if( ret ) { + printk("MMU: map failure\n"); + throw( -13 ); + return; + } +} + +/* ( virt size -- ) */ +static void +mmu_unmap( void ) +{ + POP(); POP(); +} + +/* ( virt -- false | phys mode true ) */ +static void +mmu_translate( void ) +{ + ucell mode; + ucell virt = POP(); + ucell phys = ofmem_translate( virt, &mode ); + + if( phys == -1 ) { + PUSH( 0 ); + } else { + PUSH( phys ); + PUSH( mode ); + PUSH( -1 ); + } +} + +/* ( virt size align -- baseaddr|-1 ) */ +static void +ciface_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align ); + + /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ + PUSH( ret ); +} + +/* ( virt size -- ) */ +static void +ciface_release( void ) +{ + ucell size = POP(); + ucell virt = POP(); + ofmem_release(virt, size); +} + + +NODE_METHODS( memory ) = { + { "claim", mem_claim }, + { "release", mem_release }, +}; + +NODE_METHODS( mmu ) = { + { "claim", mmu_claim }, + { "release", mmu_release }, + { "map", mmu_map }, + { "unmap", mmu_unmap }, + { "translate", mmu_translate }, +}; + +NODE_METHODS( mmu_ciface ) = { + { "cif-claim", ciface_claim }, + { "cif-release", ciface_release }, +}; + + +/************************************************************************/ +/* init */ +/************************************************************************/ + +void +node_methods_init( const char *cpuname ) +{ + phandle_t chosen, ph; +#ifdef CONFIG_RTAS + if (is_newworld()) { + REGISTER_NODE( rtas ); + } +#endif + REGISTER_NODE( ciface ); + REGISTER_NODE( memory ); + REGISTER_NODE_METHODS( mmu, cpuname ); + REGISTER_NODE( mmu_ciface ); + REGISTER_NODE( tty ); + + chosen = find_dev("/chosen"); + if (chosen) { + push_str(cpuname); + fword("open-dev"); + ph = POP(); + set_int_property(chosen, "mmu", ph); + } +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/mmutypes.h b/qemu/roms/openbios/arch/ppc/qemu/mmutypes.h new file mode 100644 index 000000000..512c23d0e --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/mmutypes.h @@ -0,0 +1,97 @@ +/* + * Creation Date: <2002/01/13 13:53:14 samuel> + * Time-stamp: <2002/01/27 19:56:11 samuel> + * + * <mmutypes.h> + * + * MMU definitions + * + * Most of these declarations originate from the Linux Kernel + * + * Copyright (C) 2002 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#ifndef _H_MMUTYPES +#define _H_MMUTYPES + +/* Hardware Page Table Entry */ +typedef struct mPTE { + unsigned long v:1; /* Entry is valid */ + unsigned long vsid:24; /* Virtual segment identifier */ + unsigned long h:1; /* Hash algorithm indicator */ + unsigned long api:6; /* Abbreviated page index */ + + unsigned long rpn:20; /* Real (physical) page number */ + unsigned long :3; /* Unused */ + unsigned long r:1; /* Referenced */ + unsigned long c:1; /* Changed */ + unsigned long w:1; /* Write-thru cache mode */ + unsigned long i:1; /* Cache inhibited */ + unsigned long m:1; /* Memory coherence */ + unsigned long g:1; /* Guarded */ + unsigned long :1; /* Unused */ + unsigned long pp:2; /* Page protection */ +} mPTE_t; + +typedef struct mPTE_64 { + uint32_t avpn_low; /* Abbreviated Virtual Page Number (unused) */ + uint32_t avpn:25; /* Abbreviated Virtual Page Number */ + uint32_t sw:4; /* Software Use */ + uint32_t :1; /* Reserved */ + uint32_t h:1; /* Hash algorithm indicator */ + uint32_t v:1; /* Entry is valid */ + + uint32_t rpn_low; /* Real (physical) page number (unused) */ + uint32_t rpn:20; /* Real (physical) page number */ + uint32_t :2; /* Reserved */ + uint32_t ac:1; /* Address Compare*/ + uint32_t r:1; /* Referenced */ + uint32_t c:1; /* Changed */ + uint32_t w:1; /* Write-thru cache mode */ + uint32_t i:1; /* Cache inhibited */ + uint32_t m:1; /* Memory coherence */ + uint32_t g:1; /* Guarded */ + uint32_t n:1; /* No-Execute */ + uint32_t pp:2; /* Page protection */ +} mPTE_64_t; + +typedef struct _mBATU { /* Upper part of BAT (all except 601) */ + unsigned long bepi:15; /* Effective page index (virtual address) */ + unsigned long :4; /* Unused */ + unsigned long bl:11; /* Block size mask */ + unsigned long vs:1; /* Supervisor valid */ + unsigned long vp:1; /* User valid */ +} mBATU; + +typedef struct _mBATL { /* Lower part of BAT (all except 601) */ + unsigned long brpn:15; /* Real page index (physical address) */ + unsigned long :10; /* Unused */ + unsigned long w:1; /* Write-thru cache */ + unsigned long i:1; /* Cache inhibit */ + unsigned long m:1; /* Memory coherence */ + unsigned long g:1; /* Guarded (MBZ in IBAT) */ + unsigned long :1; /* Unused */ + unsigned long pp:2; /* Page access protections */ +} mBATL; + +typedef struct _mBAT { + mBATU batu; /* Upper register */ + mBATL batl; /* Lower register */ +} mBAT; + +typedef struct _mSEGREG { + unsigned long t:1; /* Normal or I/O type */ + unsigned long ks:1; /* Supervisor 'key' (normally 0) */ + unsigned long kp:1; /* User 'key' (normally 1) */ + unsigned long n:1; /* No-execute */ + unsigned long :4; /* Unused */ + unsigned long vsid:24; /* Virtual Segment Identifier */ +} mSEGREG; + + +#endif /* _H_MMUTYPES */ diff --git a/qemu/roms/openbios/arch/ppc/qemu/ofmem.c b/qemu/roms/openbios/arch/ppc/qemu/ofmem.c new file mode 100644 index 000000000..6f346a3d4 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/ofmem.c @@ -0,0 +1,563 @@ +/* + * Creation Date: <1999/11/07 19:02:11 samuel> + * Time-stamp: <2004/01/07 19:42:36 samuel> + * + * <ofmem.c> + * + * OF Memory manager + * + * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "libopenbios/ofmem.h" +#include "kernel.h" +#include "mmutypes.h" +#include "asm/processor.h" + +#define BIT(n) (1U << (31 - (n))) + +#define SLB_VSID_SHIFT 12 + +/* called from assembly */ +extern void dsi_exception(void); +extern void isi_exception(void); +extern void setup_mmu(unsigned long code_base); + +/* + * From Apple's BootX source comments: + * + * 96 MB map (currently unused - 4363357 tracks re-adoption) + * 00000000 - 00003FFF : Exception Vectors + * 00004000 - 03FFFFFF : Kernel Image, Boot Struct and Drivers (~64 MB) + * 04000000 - 04FFFFFF : File Load Area (16 MB) [80 MB] + * 05000000 - 053FFFFF : FS Cache (4 MB) [84 MB] + * 05400000 - 055FFFFF : Malloc Zone (2 MB) [86 MB] + * 05600000 - 057FFFFF : BootX Image (2 MB) [88 MB] + * 05800000 - 05FFFFFF : Unused/OF (8 MB) [96 MB] + * + */ + +#define FREE_BASE 0x00004000UL +#define OF_CODE_START 0xfff00000UL +#define OF_CODE_SIZE 0x00100000 +#define IO_BASE 0x80000000UL + +#ifdef __powerpc64__ +#define HASH_BITS 18 +#else +#define HASH_BITS 15 +#endif +#define HASH_SIZE (2 << HASH_BITS) +#define OFMEM_SIZE (1 * 1024 * 1024 + 512 * 1024) + +#define SEGR_USER BIT(2) +#define SEGR_BASE 0x0400 + +static inline unsigned long +get_hash_base(void) +{ + return (mfsdr1() & SDR1_HTABORG_MASK); +} + +static inline unsigned long +get_rom_base(void) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + return ofmem->ramsize - OF_CODE_SIZE; +} + +static unsigned long +get_ram_top(void) +{ + return get_hash_base() - (32 + 64 + 64) * 1024 - OFMEM_SIZE; +} + +static unsigned long +get_ram_bottom(void) +{ + return FREE_BASE; +} + +static unsigned long get_heap_top(void) +{ + return get_hash_base() - (32 + 64 + 64) * 1024; +} + +static inline size_t ALIGN_SIZE(size_t x, size_t a) +{ + return (x + a - 1) & ~(a - 1); +} + +ofmem_t* ofmem_arch_get_private(void) +{ + return (ofmem_t*)cell2pointer(get_heap_top() - OFMEM_SIZE); +} + +void* ofmem_arch_get_malloc_base(void) +{ + return (char*)ofmem_arch_get_private() + ALIGN_SIZE(sizeof(ofmem_t), 4); +} + +ucell ofmem_arch_get_heap_top(void) +{ + return get_heap_top(); +} + +ucell ofmem_arch_get_virt_top(void) +{ + return IO_BASE; +} + +void ofmem_arch_unmap_pages(ucell virt, ucell size) +{ + /* kill page mappings in provided range */ +} + +void ofmem_arch_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) +{ + /* none yet */ +} + +ucell ofmem_arch_get_iomem_base(void) +{ + /* Currently unused */ + return 0; +} + +ucell ofmem_arch_get_iomem_top(void) +{ + /* Currently unused */ + return 0; +} + +retain_t *ofmem_arch_get_retained(void) +{ + /* not implemented */ + return NULL; +} + +int ofmem_arch_get_physaddr_cellsize(void) +{ +#ifdef CONFIG_PPC64 + return 2; +#else + return 1; +#endif +} + +int ofmem_arch_encode_physaddr(ucell *p, phys_addr_t value) +{ + int n = 0; +#ifdef CONFIG_PPC64 + p[n++] = value >> 32; +#endif + p[n++] = value; + return n; +} + +/* Return size of a single MMU package translation property entry in cells */ +int ofmem_arch_get_translation_entry_size(void) +{ + return 3 + ofmem_arch_get_physaddr_cellsize(); +} + +/* Generate translation property entry for PPC. + * According to the platform bindings for PPC + * (http://www.openfirmware.org/1275/bindings/ppc/release/ppc-2_1.html#REF34579) + * a translation property entry has the following layout: + * + * virtual address + * length + * physical address + * mode + */ +void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t) +{ + int i = 0; + + transentry[i++] = t->virt; + transentry[i++] = t->size; + i += ofmem_arch_encode_physaddr(&transentry[i], t->phys); + transentry[i++] = t->mode; +} + +/* Return the size of a memory available entry given the phandle in cells */ +int ofmem_arch_get_available_entry_size(phandle_t ph) +{ + if (ph == s_phandle_memory) { + return 1 + ofmem_arch_get_physaddr_cellsize(); + } else { + return 1 + 1; + } +} + +/* Generate memory available property entry for PPC */ +void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size) +{ + int i = 0; + + if (ph == s_phandle_memory) { + i += ofmem_arch_encode_physaddr(availentry, start); + } else { + availentry[i++] = start; + } + + availentry[i] = size; +} + +/************************************************************************/ +/* OF private allocations */ +/************************************************************************/ + +/* Private functions for mapping between physical/virtual addresses */ +phys_addr_t +va2pa(unsigned long va) +{ + if (va >= OF_CODE_START && va < OF_CODE_START + OF_CODE_SIZE) { + return (phys_addr_t)get_rom_base() - OF_CODE_START + va; + } else { + return (phys_addr_t)va; + } +} + +unsigned long +pa2va(phys_addr_t pa) +{ + if ((pa - get_rom_base() + OF_CODE_START >= OF_CODE_START) && + (pa - get_rom_base() + OF_CODE_START < OF_CODE_START + OF_CODE_SIZE)) + return (unsigned long)pa - get_rom_base() + OF_CODE_START; + else + return (unsigned long)pa; +} + +void * +malloc(int size) +{ + return ofmem_malloc(size); +} + +void +free(void *ptr) +{ + ofmem_free(ptr); +} + +void * +realloc(void *ptr, size_t size) +{ + return ofmem_realloc(ptr, size); +} + + +/************************************************************************/ +/* misc */ +/************************************************************************/ + +ucell ofmem_arch_default_translation_mode(phys_addr_t phys) +{ + /* XXX: Guard bit not set as it should! */ + if (phys < IO_BASE) + return 0x02; /*0xa*/ /* wim GxPp */ + return 0x6a; /* WIm GxPp, I/O */ +} + +ucell ofmem_arch_io_translation_mode(phys_addr_t phys) +{ + return 0x6a; /* WIm GxPp, I/O */ +} + +/************************************************************************/ +/* page fault handler */ +/************************************************************************/ + +static phys_addr_t +ea_to_phys(unsigned long ea, ucell *mode) +{ + phys_addr_t phys; + + if (ea >= OF_CODE_START && ea <= 0xffffffffUL) { + /* ROM into RAM */ + ea -= OF_CODE_START; + phys = get_rom_base() + ea; + *mode = 0x02; + return phys; + } + + phys = ofmem_translate(ea, mode); + if (phys == -1) { + phys = ea; + *mode = ofmem_arch_default_translation_mode(phys); + + /* print_virt_range(); */ + /* print_phys_range(); */ + /* print_trans(); */ + } + return phys; +} + +/* Converts a global variable (from .data or .bss) into a pointer that + can be accessed from real mode */ +static void * +global_ptr_real(void *p) +{ + return (void*)((uintptr_t)p - OF_CODE_START + get_rom_base()); +} + +/* Return the next slot to evict, in the range of [0..7] */ +static int +next_evicted_slot(void) +{ + static int next_grab_slot; + int *next_grab_slot_va; + int r; + + next_grab_slot_va = global_ptr_real(&next_grab_slot); + r = *next_grab_slot_va; + *next_grab_slot_va = (r + 1) % 8; + + return r; +} + +static void +hash_page_64(unsigned long ea, phys_addr_t phys, ucell mode) +{ + uint64_t vsid_mask, page_mask, pgidx, hash; + uint64_t htab_mask, mask, avpn; + unsigned long pgaddr; + int i, found; + unsigned int vsid, vsid_sh, sdr, sdr_sh, sdr_mask; + mPTE_64_t *pp; + + vsid = (ea >> 28) + SEGR_BASE; + vsid_sh = 7; + vsid_mask = 0x00003FFFFFFFFF80ULL; + sdr = mfsdr1(); + sdr_sh = 18; + sdr_mask = 0x3FF80; + page_mask = 0x0FFFFFFF; // XXX correct? + pgidx = (ea & page_mask) >> PAGE_SHIFT; + avpn = (vsid << 12) | ((pgidx >> 4) & 0x0F80);; + + hash = ((vsid ^ pgidx) << vsid_sh) & vsid_mask; + htab_mask = 0x0FFFFFFF >> (28 - (sdr & 0x1F)); + mask = (htab_mask << sdr_sh) | sdr_mask; + pgaddr = sdr | (hash & mask); + pp = (mPTE_64_t *)pgaddr; + + /* replace old translation */ + for (found = 0, i = 0; !found && i < 8; i++) + if (pp[i].avpn == avpn) + found = 1; + + /* otherwise use a free slot */ + for (i = 0; !found && i < 8; i++) + if (!pp[i].v) + found = 1; + + /* out of slots, just evict one */ + if (!found) + i = next_evicted_slot() + 1; + i--; + { + mPTE_64_t p = { + // .avpn_low = avpn, + .avpn = avpn >> 7, + .h = 0, + .v = 1, + + .rpn = (phys & ~0xfffUL) >> 12, + .r = mode & (1 << 8) ? 1 : 0, + .c = mode & (1 << 7) ? 1 : 0, + .w = mode & (1 << 6) ? 1 : 0, + .i = mode & (1 << 5) ? 1 : 0, + .m = mode & (1 << 4) ? 1 : 0, + .g = mode & (1 << 3) ? 1 : 0, + .n = mode & (1 << 2) ? 1 : 0, + .pp = mode & 3, + }; + pp[i] = p; + } + + asm volatile("tlbie %0" :: "r"(ea)); +} + +static void +hash_page_32(unsigned long ea, phys_addr_t phys, ucell mode) +{ +#ifndef __powerpc64__ + unsigned long *upte, cmp, hash1; + int i, vsid, found; + mPTE_t *pp; + + vsid = (ea >> 28) + SEGR_BASE; + cmp = BIT(0) | (vsid << 7) | ((ea & 0x0fffffff) >> 22); + + hash1 = vsid; + hash1 ^= (ea >> 12) & 0xffff; + hash1 &= (((mfsdr1() & 0x1ff) << 16) | 0xffff) >> 6; + + pp = (mPTE_t*)(get_hash_base() + (hash1 << 6)); + upte = (unsigned long*)pp; + + /* replace old translation */ + for (found = 0, i = 0; !found && i < 8; i++) + if (cmp == upte[i*2]) + found = 1; + + /* otherwise use a free slot */ + for (i = 0; !found && i < 8; i++) + if (!pp[i].v) + found = 1; + + /* out of slots, just evict one */ + if (!found) + i = next_evicted_slot() + 1; + i--; + upte[i * 2] = cmp; + upte[i * 2 + 1] = (phys & ~0xfff) | mode; + + asm volatile("tlbie %0" :: "r"(ea)); +#endif +} + +static int is_ppc64(void) +{ +#ifdef __powerpc64__ + return 1; +#elif defined(CONFIG_PPC_64BITSUPPORT) + unsigned int pvr = mfpvr(); + return ((pvr >= 0x330000) && (pvr < 0x70330000)); +#else + return 0; +#endif +} + +/* XXX Remove these ugly constructs when legacy 64-bit support is dropped. */ +static void hash_page(unsigned long ea, phys_addr_t phys, ucell mode) +{ + if (is_ppc64()) + hash_page_64(ea, phys, mode); + else + hash_page_32(ea, phys, mode); +} + +void +dsi_exception(void) +{ + unsigned long dar, dsisr; + ucell mode; + phys_addr_t phys; + + asm volatile("mfdar %0" : "=r" (dar) : ); + asm volatile("mfdsisr %0" : "=r" (dsisr) : ); + + phys = ea_to_phys(dar, &mode); + hash_page(dar, phys, mode); +} + +void +isi_exception(void) +{ + unsigned long nip, srr1; + ucell mode; + phys_addr_t phys; + + asm volatile("mfsrr0 %0" : "=r" (nip) : ); + asm volatile("mfsrr1 %0" : "=r" (srr1) : ); + + phys = ea_to_phys(nip, &mode); + hash_page(nip, phys, mode); +} + + +/************************************************************************/ +/* init / cleanup */ +/************************************************************************/ + +void +setup_mmu(unsigned long ramsize) +{ + ofmem_t *ofmem; +#ifndef __powerpc64__ + unsigned long sr_base; +#endif + unsigned long hash_base; + unsigned long hash_mask = ~0x000fffffUL; /* alignment for ppc64 */ + int i; + + /* SDR1: Storage Description Register 1 */ + + hash_base = (ramsize - OF_CODE_SIZE - HASH_SIZE) & hash_mask; + memset((void *)hash_base, 0, HASH_SIZE); + if (is_ppc64()) + mtsdr1(hash_base | MAX(HASH_BITS - 18, 0)); + else + mtsdr1(hash_base | ((HASH_SIZE - 1) >> 16)); + +#ifdef __powerpc64__ + + /* Segment Lookaside Buffer */ + + slbia(); /* Invalidate all SLBs except SLB 0 */ + for (i = 0; i < 16; i++) { + unsigned long rs = (0x400 + i) << SLB_VSID_SHIFT; + unsigned long rb = ((unsigned long)i << 28) | (1 << 27) | i; + slbmte(rs, rb); + } + +#else + + /* Segment Register */ + + sr_base = SEGR_USER | SEGR_BASE ; + for (i = 0; i < 16; i++) { + int j = i << 28; + asm volatile("mtsrin %0,%1" :: "r" (sr_base + i), "r" (j)); + } + +#endif + + ofmem = ofmem_arch_get_private(); + memset(ofmem, 0, sizeof(ofmem_t)); + ofmem->ramsize = ramsize; + + memcpy((void *)get_rom_base(), (void *)OF_CODE_START, OF_CODE_SIZE); + + /* Enable MMU */ + + mtmsr(mfmsr() | MSR_IR | MSR_DR); +} + +void +ofmem_init(void) +{ + ofmem_t *ofmem = ofmem_arch_get_private(); + + /* Map the memory (don't map page 0 to allow catching of NULL dereferences) */ + ofmem_claim_phys(PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0); + ofmem_claim_virt(PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0); + ofmem_map(PAGE_SIZE, PAGE_SIZE, get_ram_bottom() - PAGE_SIZE, 0); + + /* Mark the first page as non-free */ + ofmem_claim_phys(0, PAGE_SIZE, 0); + ofmem_claim_virt(0, PAGE_SIZE, 0); + + /* Map everything at the top of physical RAM 1:1, minus the OpenBIOS ROM in RAM copy */ + ofmem_claim_phys(get_ram_top(), get_hash_base() + HASH_SIZE - get_ram_top(), 0); + ofmem_claim_virt(get_ram_top(), get_hash_base() + HASH_SIZE - get_ram_top(), 0); + ofmem_map(get_ram_top(), get_ram_top(), get_hash_base() + HASH_SIZE - get_ram_top(), 0); + + /* Map the OpenBIOS ROM in RAM copy */ + ofmem_claim_phys(ofmem->ramsize - OF_CODE_SIZE, OF_CODE_SIZE, 0); + ofmem_claim_virt(OF_CODE_START, OF_CODE_SIZE, 0); + ofmem_map(ofmem->ramsize - OF_CODE_SIZE, OF_CODE_START, OF_CODE_SIZE, 0); +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/qemu.c b/qemu/roms/openbios/arch/ppc/qemu/qemu.c new file mode 100644 index 000000000..381affb77 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/qemu.c @@ -0,0 +1,106 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <qemu.c> + * + * Copyright (C) 2004, Greg Watson + * + * derived from mol.c + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/nvram.h" +#include "libopenbios/bindings.h" +#include "drivers/drivers.h" +#include "libc/vsprintf.h" +#include "libc/string.h" +#include "libc/byteorder.h" +#include "qemu/qemu.h" +#include <stdarg.h> + +//#define DUMP_NVRAM + +unsigned long virt_offset = 0; + +void +exit( int status __attribute__ ((unused))) +{ + for (;;); +} + +void +fatal_error( const char *err ) +{ + printk("Fatal error: %s\n", err ); + exit(0); +} + +void +panic( const char *err ) +{ + printk("Panic: %s\n", err ); + exit(0); +} + +static int do_indent; + +int +printk( const char *fmt, ... ) +{ + char *p, buf[1024]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) { + if( *p == '\n' ) + do_indent = 0; + if( do_indent++ == 1 ) { + putchar( '>' ); + putchar( '>' ); + putchar( ' ' ); + } + putchar( *p ); + } + return i; +} + +int arch_nvram_size(void) +{ + if (is_apple()) { + return macio_get_nvram_size(); + } else { + // not implemented + } + return 0; +} + +void arch_nvram_put(char *buf) +{ + if (is_apple()) { + macio_nvram_put(buf); + } else { + // not implemented + } +} + +void arch_nvram_get(char *buf) +{ + if (is_apple()) { + macio_nvram_get(buf); + } else { + // not implemented + } +} diff --git a/qemu/roms/openbios/arch/ppc/qemu/qemu.fs b/qemu/roms/openbios/arch/ppc/qemu/qemu.fs new file mode 100644 index 000000000..458af1bc7 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/qemu.fs @@ -0,0 +1,95 @@ +\ qemu specific initialization code +\ +\ Copyright (C) 2005 Stefan Reinauer +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + + +\ ------------------------------------------------------------------------- +\ initialization +\ ------------------------------------------------------------------------- + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " rtc" " rtc" preopen + " memory" " /memory" preopen +; SYSTEM-initializer + + +\ use the tty interface if available +: activate-tty-interface + " /packages/terminal-emulator" find-dev if drop + then +; + +variable keyboard-phandle 0 keyboard-phandle ! + +: (find-keyboard-device) ( phandle -- ) + recursive + keyboard-phandle @ 0= if \ Return first match + >dn.child @ + begin ?dup while + dup dup " device_type" rot get-package-property 0= if + drop dup cstrlen + " keyboard" strcmp 0= if + dup to keyboard-phandle + then + then + (find-keyboard-device) + >dn.peer @ + repeat + else + drop + then +; + +\ create the keyboard devalias +:noname + device-tree @ (find-keyboard-device) + keyboard-phandle @ if + active-package + " /aliases" find-device + keyboard-phandle @ get-package-path + encode-string " keyboard" property + active-package! + then +; SYSTEM-initializer + +\ ------------------------------------------------------------------------- +\ pre-booting +\ ------------------------------------------------------------------------- + +: update-chosen + " /chosen" find-device + stdin @ encode-int " stdin" property + stdout @ encode-int " stdout" property + device-end +; + +:noname + set-defaults +; PREPOST-initializer diff --git a/qemu/roms/openbios/arch/ppc/qemu/qemu.h b/qemu/roms/openbios/arch/ppc/qemu/qemu.h new file mode 100644 index 000000000..6edf4d451 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/qemu.h @@ -0,0 +1,24 @@ +/* + * Creation Date: <2004/08/28 17:50:12 stepan> + * Time-stamp: <2004/08/28 17:50:12 stepan> + * + * <qemu.h> + * + * Copyright (C) 2005 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_QEMU +#define _H_QEMU + +/* vfd.c */ +extern int vfd_draw_str( const char *str ); +extern void vfd_close( void ); + +#include "kernel.h" + +#endif /* _H_QEMU */ diff --git a/qemu/roms/openbios/arch/ppc/qemu/start.S b/qemu/roms/openbios/arch/ppc/qemu/start.S new file mode 100644 index 000000000..ae2fd53dc --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/start.S @@ -0,0 +1,729 @@ +/* + * Creation Date: <2001/06/16 21:30:18 samuel> + * Time-stamp: <2003/04/04 16:32:06 samuel> + * + * <init.S> + * + * Asm glue for ELF images + * + * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "autoconf.h" +#include "asm/asmdefs.h" +#include "asm/processor.h" + +/************************************************************************/ +/* Macros */ +/************************************************************************/ + +#define ILLEGAL_VECTOR( v ) .org __vectors + v ; vector__##v: bl trap_error ; +#define VECTOR( v, dummystr ) .org __vectors + v ; vector__##v + +#ifdef CONFIG_PPC_64BITSUPPORT + +/* We're trying to use the same code for the ppc32 and ppc64 handlers here. + * On ppc32 we only save/restore the registers, C considers volatile. + * + * On ppc64 on the other hand, we have to save/restore all registers, because + * all OF code is 32 bits, which only saves/restores the low 32 bits of the + * registers it clobbers. + */ + +#define EXCEPTION_PREAMBLE_TEMPLATE \ + mtsprg1 r1 ; /* scratch */ \ + mfcr r1 ; \ + mtsprg2 r1 ; /* scratch */ \ + lis r1, 0x8000 ; /* r1=0x80000000 */ \ + add. r1,r1,r1 ; /* r1=r1+r1 (high 32bit !0) */ \ + beq 1f; \ + \ + mfmsr r1 ; /* unset MSR_SF */ \ + clrldi r1,r1,1 ; \ + mtmsrd r1 ; \ +1: \ + mfsprg0 r1 ; /* exception stack in sprg0 */ \ +.ifc ULONG_SIZE, 8 ; \ + addi r1,r1,-(40 * ULONG_SIZE) ; /* push exception frame */ \ +.else ; \ + addi r1,r1,-(20 * ULONG_SIZE) ; /* push exception frame */ \ +.endif ; \ + \ + stl r0,(0 * ULONG_SIZE)(r1) ; /* save r0 */ \ + mfsprg1 r0 ; \ + stl r0,(1 * ULONG_SIZE)(r1) ; /* save r1 */ \ + stl r2,(2 * ULONG_SIZE)(r1) ; /* save r2 */ \ + stl r3,(3 * ULONG_SIZE)(r1) ; /* save r3 */ \ + stl r4,(4 * ULONG_SIZE)(r1) ; \ + stl r5,(5 * ULONG_SIZE)(r1) ; \ + stl r6,(6 * ULONG_SIZE)(r1) ; \ + stl r7,(7 * ULONG_SIZE)(r1) ; \ + stl r8,(8 * ULONG_SIZE)(r1) ; \ + stl r9,(9 * ULONG_SIZE)(r1) ; \ + stl r10,(10 * ULONG_SIZE)(r1) ; \ + stl r11,(11 * ULONG_SIZE)(r1) ; \ + stl r12,(12 * ULONG_SIZE)(r1) ; \ +.ifc ULONG_SIZE, 8 ; \ + stl r13,(17 * ULONG_SIZE)(r1) ; \ + stl r14,(18 * ULONG_SIZE)(r1) ; \ + stl r15,(19 * ULONG_SIZE)(r1) ; \ + stl r16,(20 * ULONG_SIZE)(r1) ; \ + stl r17,(21 * ULONG_SIZE)(r1) ; \ + stl r18,(22 * ULONG_SIZE)(r1) ; \ + stl r19,(23 * ULONG_SIZE)(r1) ; \ + stl r20,(24 * ULONG_SIZE)(r1) ; \ + stl r21,(25 * ULONG_SIZE)(r1) ; \ + stl r22,(26 * ULONG_SIZE)(r1) ; \ + stl r23,(27 * ULONG_SIZE)(r1) ; \ + stl r24,(28 * ULONG_SIZE)(r1) ; \ + stl r25,(29 * ULONG_SIZE)(r1) ; \ + stl r26,(30 * ULONG_SIZE)(r1) ; \ + stl r27,(31 * ULONG_SIZE)(r1) ; \ + stl r28,(32 * ULONG_SIZE)(r1) ; \ + stl r29,(33 * ULONG_SIZE)(r1) ; \ + stl r30,(34 * ULONG_SIZE)(r1) ; \ + stl r31,(35 * ULONG_SIZE)(r1) ; \ +.endif ; \ + \ + mflr r0 ; \ + stl r0,(13 * ULONG_SIZE)(r1) ; \ + mfsprg2 r0 ; \ + stl r0,(14 * ULONG_SIZE)(r1) ; \ + mfctr r0 ; \ + stl r0,(15 * ULONG_SIZE)(r1) ; \ + mfxer r0 ; \ + stl r0,(16 * ULONG_SIZE)(r1) ; \ + \ + /* 76(r1) unused */ \ + addi r1,r1,-16 ; /* C ABI uses 0(r1) and 4(r1)... */ + +#define EXCEPTION_EPILOGUE_TEMPLATE \ + addi r1,r1,16 ; /* pop ABI frame */ \ +\ + ll r0,(13 * ULONG_SIZE)(r1) ; \ + mtlr r0 ; \ + ll r0,(14 * ULONG_SIZE)(r1) ; \ + mtcr r0 ; \ + ll r0,(15 * ULONG_SIZE)(r1) ; \ + mtctr r0 ; \ + ll r0,(16 * ULONG_SIZE)(r1) ; \ + mtxer r0 ; \ +\ + ll r0,(0 * ULONG_SIZE)(r1) ; \ + ll r2,(2 * ULONG_SIZE)(r1) ; \ + ll r3,(3 * ULONG_SIZE)(r1) ; \ + ll r4,(4 * ULONG_SIZE)(r1) ; \ + ll r5,(5 * ULONG_SIZE)(r1) ; \ + ll r6,(6 * ULONG_SIZE)(r1) ; \ + ll r7,(7 * ULONG_SIZE)(r1) ; \ + ll r8,(8 * ULONG_SIZE)(r1) ; \ + ll r9,(9 * ULONG_SIZE)(r1) ; \ + ll r10,(10 * ULONG_SIZE)(r1) ; \ + ll r11,(11 * ULONG_SIZE)(r1) ; \ + ll r12,(12 * ULONG_SIZE)(r1) ; \ +.ifc ULONG_SIZE, 8 ; \ + ll r13,(17 * ULONG_SIZE)(r1) ; \ + ll r14,(18 * ULONG_SIZE)(r1) ; \ + ll r15,(19 * ULONG_SIZE)(r1) ; \ + ll r16,(20 * ULONG_SIZE)(r1) ; \ + ll r17,(21 * ULONG_SIZE)(r1) ; \ + ll r18,(22 * ULONG_SIZE)(r1) ; \ + ll r19,(23 * ULONG_SIZE)(r1) ; \ + ll r20,(24 * ULONG_SIZE)(r1) ; \ + ll r21,(25 * ULONG_SIZE)(r1) ; \ + ll r22,(26 * ULONG_SIZE)(r1) ; \ + ll r23,(27 * ULONG_SIZE)(r1) ; \ + ll r24,(28 * ULONG_SIZE)(r1) ; \ + ll r25,(29 * ULONG_SIZE)(r1) ; \ + ll r26,(30 * ULONG_SIZE)(r1) ; \ + ll r27,(31 * ULONG_SIZE)(r1) ; \ + ll r28,(32 * ULONG_SIZE)(r1) ; \ + ll r29,(33 * ULONG_SIZE)(r1) ; \ + ll r30,(34 * ULONG_SIZE)(r1) ; \ + ll r31,(35 * ULONG_SIZE)(r1) ; \ +.endif ; \ + ll r1,(1 * ULONG_SIZE)(r1) ; /* restore stack at last */ \ + rfi + +// PPC32 + +#define ULONG_SIZE 4 +#define stl stw +#define ll lwz + +.macro EXCEPTION_PREAMBLE + EXCEPTION_PREAMBLE_TEMPLATE +.endm + +.macro EXCEPTION_EPILOGUE + EXCEPTION_EPILOGUE_TEMPLATE +.endm + +#undef ULONG_SIZE +#undef stl +#undef ll + +// PPC64 + +#define ULONG_SIZE 8 +#define stl std +#define ll ld + +.macro EXCEPTION_PREAMBLE_64 + EXCEPTION_PREAMBLE_TEMPLATE +.endm + +.macro EXCEPTION_EPILOGUE_64 + EXCEPTION_EPILOGUE_TEMPLATE +.endm + +#undef ULONG_SIZE +#undef stl +#undef ll + +#define ULONG_SIZE 4 +#define STACKFRAME_MINSIZE 16 + +#else /* !CONFIG_PPC_64BITSUPPORT */ + +#ifdef __powerpc64__ + +#define ULONG_SIZE 8 +#define STACKFRAME_MINSIZE 48 +#define stl std +#define ll ld + +#else + +#define ULONG_SIZE 4 +#define STACKFRAME_MINSIZE 16 +#define stl stw +#define ll lwz + +#endif + +.macro EXCEPTION_PREAMBLE + mtsprg1 r1 /* scratch */ + mfsprg0 r1 /* exception stack in sprg0 */ + addi r1, r1, -(20 * ULONG_SIZE) /* push exception frame */ + + stl r0, ( 0 * ULONG_SIZE)(r1) /* save r0 */ + mfsprg1 r0 + stl r0, ( 1 * ULONG_SIZE)(r1) /* save r1 */ + stl r2, ( 2 * ULONG_SIZE)(r1) /* save r2 */ + stl r3, ( 3 * ULONG_SIZE)(r1) /* save r3 */ + stl r4, ( 4 * ULONG_SIZE)(r1) + stl r5, ( 5 * ULONG_SIZE)(r1) + stl r6, ( 6 * ULONG_SIZE)(r1) + stl r7, ( 7 * ULONG_SIZE)(r1) + stl r8, ( 8 * ULONG_SIZE)(r1) + stl r9, ( 9 * ULONG_SIZE)(r1) + stl r10, (10 * ULONG_SIZE)(r1) + stl r11, (11 * ULONG_SIZE)(r1) + stl r12, (12 * ULONG_SIZE)(r1) + + mflr r0 + stl r0, (13 * ULONG_SIZE)(r1) + mfcr r0 + stl r0, (14 * ULONG_SIZE)(r1) + mfctr r0 + stl r0, (15 * ULONG_SIZE)(r1) + mfxer r0 + stl r0, (16 * ULONG_SIZE)(r1) + + addi r1, r1, -STACKFRAME_MINSIZE /* C ABI saves LR and SP */ +.endm + +.macro EXCEPTION_EPILOGUE + addi r1, r1, STACKFRAME_MINSIZE /* pop ABI frame */ + + ll r0, (13 * ULONG_SIZE)(r1) + mtlr r0 + ll r0, (14 * ULONG_SIZE)(r1) + mtcr r0 + ll r0, (15 * ULONG_SIZE)(r1) + mtctr r0 + ll r0, (16 * ULONG_SIZE)(r1) + mtxer r0 + + ll r0, ( 0 * ULONG_SIZE)(r1) + ll r2, ( 2 * ULONG_SIZE)(r1) + ll r3, ( 3 * ULONG_SIZE)(r1) + ll r4, ( 4 * ULONG_SIZE)(r1) + ll r5, ( 5 * ULONG_SIZE)(r1) + ll r6, ( 6 * ULONG_SIZE)(r1) + ll r7, ( 7 * ULONG_SIZE)(r1) + ll r8, ( 8 * ULONG_SIZE)(r1) + ll r9, ( 9 * ULONG_SIZE)(r1) + ll r10, (10 * ULONG_SIZE)(r1) + ll r11, (11 * ULONG_SIZE)(r1) + ll r12, (12 * ULONG_SIZE)(r1) + + ll r1, ( 1 * ULONG_SIZE)(r1) /* restore stack at last */ + RFI +.endm + +#endif /* !CONFIG_PPC_64BITSUPPORT */ + +/************************************************************************/ +/* vectors */ +/************************************************************************/ + + .section .text.vectors, "ax" +GLOBL(__vectors): + nop // NULL-jmp trap +1: nop // + b 1b + +VECTOR( 0x100, "SRE" ): + b _entry + +trap_error: + lis r1, 0x8000 /* r1=0x80000000 */ + add. r1,r1,r1 /* r1=r1+r1 (high 32bit !0) */ + beq 1f + + mfmsr r1 /* unset MSR_SF */ + clrldi r1,r1,1 + mtmsrd r1 +1: + mflr r3 + LOAD_REG_FUNC(r4, unexpected_excep) + mtctr r4 + bctr + +ILLEGAL_VECTOR( 0x200 ) + +VECTOR( 0x300, "DSI" ): + b real_dsi + +ILLEGAL_VECTOR( 0x380 ) + +VECTOR( 0x400, "ISI" ): + b real_isi + +ILLEGAL_VECTOR( 0x480 ) + + ILLEGAL_VECTOR( 0x500 ) + ILLEGAL_VECTOR( 0x600 ) + ILLEGAL_VECTOR( 0x700 ) + +VECTOR( 0x800, "FPU" ): + mtsprg1 r3 + mfsrr1 r3 + ori r3,r3,0x2000 + mtsrr1 r3 + mfsprg1 r3 + RFI + +ILLEGAL_VECTOR( 0x900 ) +ILLEGAL_VECTOR( 0xa00 ) +ILLEGAL_VECTOR( 0xb00 ) +ILLEGAL_VECTOR( 0xc00 ) +ILLEGAL_VECTOR( 0xd00 ) +ILLEGAL_VECTOR( 0xe00 ) +ILLEGAL_VECTOR( 0xf00 ) +ILLEGAL_VECTOR( 0xf20 ) +ILLEGAL_VECTOR( 0x1000 ) +ILLEGAL_VECTOR( 0x1100 ) +ILLEGAL_VECTOR( 0x1200 ) +ILLEGAL_VECTOR( 0x1300 ) +ILLEGAL_VECTOR( 0x1400 ) +ILLEGAL_VECTOR( 0x1500 ) +ILLEGAL_VECTOR( 0x1600 ) +ILLEGAL_VECTOR( 0x1700 ) + +#ifdef CONFIG_PPC_64BITSUPPORT + +VECTOR( 0x2000, "DSI_64" ): + EXCEPTION_PREAMBLE_64 + LOAD_REG_IMMEDIATE(r3, dsi_exception) + mtctr r3 + bctrl + EXCEPTION_EPILOGUE_64 + +VECTOR( 0x2200, "ISI_64" ): + EXCEPTION_PREAMBLE_64 + LOAD_REG_IMMEDIATE(r3, isi_exception) + mtctr r3 + bctrl + EXCEPTION_EPILOGUE_64 + +#endif + +real_dsi: + EXCEPTION_PREAMBLE + LOAD_REG_FUNC(r3, dsi_exception) + mtctr r3 + bctrl + b exception_return + +real_isi: + EXCEPTION_PREAMBLE + LOAD_REG_FUNC(r3, isi_exception) + mtctr r3 + bctrl + b exception_return + +exception_return: + EXCEPTION_EPILOGUE + +GLOBL(__vectors_end): + +/************************************************************************/ +/* entry */ +/************************************************************************/ + +GLOBL(_entry): + +#ifdef CONFIG_PPC_64BITSUPPORT + li r0,0 + + lis r3, 0x8000 /* r1=0x80000000 */ + add. r3,r3,r3 /* r1=r1+r1 (high 32bit !0) */ + beq no_64bit /* only true when !MSR_SF */ + + /* clear MSR, disable MMU, SF */ + mtmsrd r0 + b real_entry + +no_64bit: + /* clear MSR, disable MMU */ + mtmsr r0 + +real_entry: +#endif + + /* copy exception vectors */ + + LOAD_REG_IMMEDIATE(r3, __vectors) + li r4,0 + li r5,__vectors_end - __vectors + 16 + rlwinm r5,r5,0,0,28 +1: lwz r6,0(r3) + lwz r7,4(r3) + lwz r8,8(r3) + lwz r9,12(r3) + stw r6,0(r4) + stw r7,4(r4) + stw r8,8(r4) + stw r9,12(r4) + dcbst 0,r4 + sync + icbi 0,r4 + sync + addi r5,r5,-16 + addi r3,r3,16 + addi r4,r4,16 + cmpwi r5,0 + bgt 1b + isync + + bl compute_ramsize + + /* Memory map: + * + * Top +-------------------------+ + * | | + * | ROM into RAM (1 MB) | + * | | + * +-------------------------+ + * | | + * | MMU Hash Table (64 kB) | + * | | + * +-------------------------+ + * | | + * | Exception Stack (32 kB) | + * | | + * +-------------------------+ + * | | + * | Stack (64 kB) | + * | | + * +-------------------------+ + * | | + * | Client Stack (64 kB) | + * | | + * +-------------------------+ + * | | + * | Malloc Zone (2 MiB) | + * | | + * +-------------------------+ + * : : + * Bottom + */ + + addis r1, r3, -16 /* ramsize - 1MB */ + + /* setup hash table */ + + addis r1, r1, -1 /* - 64 kB */ + clrrwi r1, r1, 5*4 /* & ~0xfffff */ + + /* setup exception stack */ + + mtsprg0 r1 + + /* setup stack */ + + addi r1, r1, -32768 /* - 32 kB */ + + /* save memory size in stack */ + +#ifdef __powerpc64__ + /* set up TOC pointer */ + + LOAD_REG_IMMEDIATE(r2, setup_mmu) + ld r2, 8(r2) +#endif + + bl BRANCH_LABEL(setup_mmu) + bl BRANCH_LABEL(entry) +1: nop + b 1b + + + /* According to IEEE 1275, PPC bindings: + * + * MSR = FP, ME + (DR|IR) + * r1 = stack (32 K + 32 bytes link area above) + * r5 = client interface handler + * r6 = address of client program arguments (unused) + * r7 = length of client program arguments (unused) + * + * Yaboot and Linux use r3 and r4 for initrd address and size + */ + .data +saved_stack: + DATA_LONG(0) + .previous + /* void call_elf( arg1, arg2, entry ) */ +_GLOBAL(call_elf): + mflr r0 + PPC_STLU r1, -STACKFRAME_MINSIZE(r1) + PPC_STL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) + mtlr r5 + LOAD_REG_IMMEDIATE(r8, saved_stack) // save our stack pointer + PPC_STL r1,0(r8) + mfsdr1 r1 + addi r1, r1, -32768 /* - 32 KiB exception stack */ + addis r1, r1, -1 /* - 64 KiB stack */ + LOAD_REG_IMMEDIATE(r5, of_client_callback) // r5 = callback + li r6,0 // r6 = address of client program arguments (unused) + li r7,0 // r7 = length of client program arguments (unused) + li r0,MSR_FP | MSR_ME | MSR_DR | MSR_IR + MTMSRD(r0) + blrl + +#ifdef CONFIG_PPC64 + /* Restore SF bit */ + LOAD_REG_IMMEDIATE(r0, MSR_SF | MSR_FP | MSR_ME | MSR_DR | MSR_IR) + MTMSRD(r0) +#endif + LOAD_REG_IMMEDIATE(r8, saved_stack) // restore stack pointer + mr r1,r8 + PPC_LL r0, (STACKFRAME_MINSIZE + PPC_LR_STKOFF)(r1) + mtlr r0 + addi r1, r1, STACKFRAME_MINSIZE + // XXX: should restore r12-r31 etc.. + // we should not really come here though + blr + +#ifdef __powerpc64__ +#define STKOFF STACKFRAME_MINSIZE +#define SAVE_SPACE 320 +#else +#define STKOFF 8 +#define SAVE_SPACE 144 +#endif +GLOBL(of_client_callback): + +#ifdef CONFIG_PPC64 + PPC_STLU r1, -(STACKFRAME_MINSIZE + 16)(r1) +#else + PPC_STLU r1, -STACKFRAME_MINSIZE(r1) /* fits within alignment */ +#endif + + /* save r4 */ + + PPC_STL r4, STKOFF(r1) + + /* save lr */ + + mflr r4 + PPC_STL r4, PPC_LR_STKOFF(r1) + + /* restore OF stack */ + + LOAD_REG_IMMEDIATE(r4, saved_stack) + PPC_LL r4, 0(r4) + + PPC_STLU r4,-SAVE_SPACE(r4) + PPC_STL r1,(STKOFF)(r4) // save caller stack + mr r1,r4 + + PPC_STL r2, (STKOFF + 1 * ULONG_SIZE)(r1) + PPC_STL r0, (STKOFF + 2 * ULONG_SIZE)(r1) + + /* save ctr, cr and xer */ + + mfctr r2 + PPC_STL r2, (STKOFF + 3 * ULONG_SIZE)(r1) + mfcr r2 + PPC_STL r2, (STKOFF + 4 * ULONG_SIZE)(r1) + mfxer r2 + PPC_STL r2, (STKOFF + 5 * ULONG_SIZE)(r1) + + /* save r5 - r31 */ + + PPC_STL r5, (STKOFF + 6 * ULONG_SIZE)(r1) + PPC_STL r6, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_STL r7, (STKOFF + 8 * ULONG_SIZE)(r1) + PPC_STL r8, (STKOFF + 9 * ULONG_SIZE)(r1) + PPC_STL r9, (STKOFF + 10 * ULONG_SIZE)(r1) + PPC_STL r10, (STKOFF + 11 * ULONG_SIZE)(r1) + PPC_STL r11, (STKOFF + 12 * ULONG_SIZE)(r1) + PPC_STL r12, (STKOFF + 13 * ULONG_SIZE)(r1) + PPC_STL r13, (STKOFF + 14 * ULONG_SIZE)(r1) + PPC_STL r14, (STKOFF + 15 * ULONG_SIZE)(r1) + PPC_STL r15, (STKOFF + 16 * ULONG_SIZE)(r1) + PPC_STL r16, (STKOFF + 17 * ULONG_SIZE)(r1) + PPC_STL r17, (STKOFF + 18 * ULONG_SIZE)(r1) + PPC_STL r18, (STKOFF + 19 * ULONG_SIZE)(r1) + PPC_STL r19, (STKOFF + 20 * ULONG_SIZE)(r1) + PPC_STL r20, (STKOFF + 21 * ULONG_SIZE)(r1) + PPC_STL r21, (STKOFF + 22 * ULONG_SIZE)(r1) + PPC_STL r22, (STKOFF + 23 * ULONG_SIZE)(r1) + PPC_STL r23, (STKOFF + 24 * ULONG_SIZE)(r1) + PPC_STL r24, (STKOFF + 25 * ULONG_SIZE)(r1) + PPC_STL r25, (STKOFF + 26 * ULONG_SIZE)(r1) + PPC_STL r26, (STKOFF + 27 * ULONG_SIZE)(r1) + PPC_STL r27, (STKOFF + 28 * ULONG_SIZE)(r1) + PPC_STL r28, (STKOFF + 29 * ULONG_SIZE)(r1) + PPC_STL r29, (STKOFF + 30 * ULONG_SIZE)(r1) + PPC_STL r30, (STKOFF + 31 * ULONG_SIZE)(r1) + PPC_STL r31, (STKOFF + 32 * ULONG_SIZE)(r1) + +#ifdef CONFIG_PPC64 + LOAD_REG_IMMEDIATE(r2, of_client_interface) + ld r2, 8(r2) +#endif + bl BRANCH_LABEL(of_client_interface) + + /* restore r5 - r31 */ + + PPC_LL r5, (STKOFF + 6 * ULONG_SIZE)(r1) + PPC_LL r6, (STKOFF + 7 * ULONG_SIZE)(r1) + PPC_LL r7, (STKOFF + 8 * ULONG_SIZE)(r1) + PPC_LL r8, (STKOFF + 9 * ULONG_SIZE)(r1) + PPC_LL r9, (STKOFF + 10 * ULONG_SIZE)(r1) + PPC_LL r10, (STKOFF + 11 * ULONG_SIZE)(r1) + PPC_LL r11, (STKOFF + 12 * ULONG_SIZE)(r1) + PPC_LL r12, (STKOFF + 13 * ULONG_SIZE)(r1) + PPC_LL r13, (STKOFF + 14 * ULONG_SIZE)(r1) + PPC_LL r14, (STKOFF + 15 * ULONG_SIZE)(r1) + PPC_LL r15, (STKOFF + 16 * ULONG_SIZE)(r1) + PPC_LL r16, (STKOFF + 17 * ULONG_SIZE)(r1) + PPC_LL r17, (STKOFF + 18 * ULONG_SIZE)(r1) + PPC_LL r18, (STKOFF + 19 * ULONG_SIZE)(r1) + PPC_LL r19, (STKOFF + 20 * ULONG_SIZE)(r1) + PPC_LL r20, (STKOFF + 21 * ULONG_SIZE)(r1) + PPC_LL r21, (STKOFF + 22 * ULONG_SIZE)(r1) + PPC_LL r22, (STKOFF + 23 * ULONG_SIZE)(r1) + PPC_LL r23, (STKOFF + 24 * ULONG_SIZE)(r1) + PPC_LL r24, (STKOFF + 25 * ULONG_SIZE)(r1) + PPC_LL r25, (STKOFF + 26 * ULONG_SIZE)(r1) + PPC_LL r26, (STKOFF + 27 * ULONG_SIZE)(r1) + PPC_LL r27, (STKOFF + 28 * ULONG_SIZE)(r1) + PPC_LL r28, (STKOFF + 29 * ULONG_SIZE)(r1) + PPC_LL r29, (STKOFF + 30 * ULONG_SIZE)(r1) + PPC_LL r30, (STKOFF + 31 * ULONG_SIZE)(r1) + PPC_LL r31, (STKOFF + 32 * ULONG_SIZE)(r1) + + /* restore ctr, cr and xer */ + + PPC_LL r2, (STKOFF + 3 * ULONG_SIZE)(r1) + mtctr r2 + PPC_LL r2, (STKOFF + 4 * ULONG_SIZE)(r1) + mtcr r2 + PPC_LL r2, (STKOFF + 5 * ULONG_SIZE)(r1) + mtxer r2 + + /* restore r0 and r2 */ + + PPC_LL r2, (STKOFF + 1 * ULONG_SIZE)(r1) + PPC_LL r0, (STKOFF + 2 * ULONG_SIZE)(r1) + + /* restore caller stack */ + + PPC_LL r1, (STKOFF)(r1) + + PPC_LL r4, PPC_LR_STKOFF(r1) + mtlr r4 + PPC_LL r4, STKOFF(r1) + PPC_LL r1, 0(r1) + + blr + + /* rtas glue (must be reloctable) */ +GLOBL(of_rtas_start): + /* r3 = argument buffer, r4 = of_rtas_start */ + /* according to the CHRP standard, cr must be preserved (cr0/cr1 too?) */ + blr +GLOBL(of_rtas_end): + + +#define CACHE_LINE_SIZE 32 +#define LG_CACHE_LINE_SIZE 5 + +/* flush_icache_range( unsigned long start, unsigned long stop) */ +_GLOBAL(flush_icache_range): + li r5,CACHE_LINE_SIZE-1 + andc r3,r3,r5 + subf r4,r3,r4 + add r4,r4,r5 + srwi. r4,r4,LG_CACHE_LINE_SIZE + beqlr + mtctr r4 + mr r6,r3 +1: dcbst 0,r3 + addi r3,r3,CACHE_LINE_SIZE + bdnz 1b + sync /* wait for dcbst's to get to ram */ + mtctr r4 +2: icbi 0,r6 + addi r6,r6,CACHE_LINE_SIZE + bdnz 2b + sync /* additional sync needed on g4 */ + isync + blr + + /* Get RAM size from QEMU configuration device */ + +#define CFG_ADDR 0xf0000510 +#define FW_CFG_RAM_SIZE 0x03 + +compute_ramsize: + LOAD_REG_IMMEDIATE(r9, CFG_ADDR) + li r0,FW_CFG_RAM_SIZE + sth r0,0(r9) + LOAD_REG_IMMEDIATE(r9, CFG_ADDR + 2) + lbz r1,0(r9) + lbz r0,0(r9) + slwi r0,r0,8 + or r1,r1,r0 + lbz r0,0(r9) + slwi r0,r0,16 + or r1,r1,r0 + lbz r0,0(r9) + slwi r0,r0,24 + or r3,r1,r0 + blr + + /* Hard reset vector */ + .section .romentry,"ax" + bl _entry diff --git a/qemu/roms/openbios/arch/ppc/qemu/tree.fs b/qemu/roms/openbios/arch/ppc/qemu/tree.fs new file mode 100644 index 000000000..1ed838397 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/tree.fs @@ -0,0 +1,71 @@ +\ QEMU specific initialization code +\ +\ This program is free software; you can redistribute it and/or +\ modify it under the terms of the GNU General Public License +\ as published by the Free Software Foundation +\ + +include config.fs + +\ ------------------------------------------------------------- +\ device-tree +\ ------------------------------------------------------------- + +" /" find-device +\ Apple calls the root node device-tree +" device-tree" device-name +[IFDEF] CONFIG_PPC64 2 [ELSE] 1 [THEN] encode-int " #address-cells" property +1 encode-int " #size-cells" property +h# 05f5e100 encode-int " clock-frequency" property + +new-device + " cpus" device-name + 1 encode-int " #address-cells" property + 0 encode-int " #size-cells" property + external + + : encode-unit ( unit -- str len ) + pocket tohexstr + ; + + : decode-unit ( str len -- unit ) + parse-hex + ; + +finish-device + +new-device + " memory" device-name + " memory" device-type + external + : open true ; + : close ; +finish-device + +\ ------------------------------------------------------------- +\ /packages +\ ------------------------------------------------------------- + +" /packages" find-device + + " packages" device-name + external + \ allow packages to be opened with open-dev + : open true ; + : close ; + +\ /packages/terminal-emulator +new-device + " terminal-emulator" device-name + external + : open true ; + : close ; + \ : write ( addr len -- actual ) + \ dup -rot type + \ ; +finish-device + +\ ------------------------------------------------------------- +\ The END +\ ------------------------------------------------------------- +device-end diff --git a/qemu/roms/openbios/arch/ppc/qemu/vfd.c b/qemu/roms/openbios/arch/ppc/qemu/vfd.c new file mode 100644 index 000000000..308d0e338 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/qemu/vfd.c @@ -0,0 +1,42 @@ +/* + * Creation Date: <2004/08/28 17:29:43 greg> + * Time-stamp: <2004/08/28 17:29:43 greg> + * + * <vfd.c> + * + * Simple text console + * + * Copyright (C) 2004 Greg Watson + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "qemu/qemu.h" + +static int vfd_is_open; + +static int +vfd_init( void ) +{ + vfd_is_open = 1; + return 0; +} + +void +vfd_close( void ) +{ +} + +int +vfd_draw_str( const char *str ) +{ + if (!vfd_is_open) + vfd_init(); + + return 0; +} diff --git a/qemu/roms/openbios/arch/ppc/start.S b/qemu/roms/openbios/arch/ppc/start.S new file mode 100644 index 000000000..40ee08963 --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/start.S @@ -0,0 +1,335 @@ +/* + * Creation Date: <2001/06/16 21:30:18 samuel> + * Time-stamp: <2003/04/04 16:32:06 samuel> + * + * <init.S> + * + * Asm glue for ELF images run inside MOL + * + * Copyright (C) 2001, 2002, 2003 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "asm/asmdefs.h" +#include "asm/processor.h" +#include "osi.h" + +/************************************************************************/ +/* Macros */ +/************************************************************************/ + +#define ILLEGAL_VECTOR( v ) .org __vectors + v ; bl trap_error ; +#define VECTOR( v, dummystr ) .org __vectors + v ; vector__##v + +#define EXCEPTION_PREAMBLE \ + mtsprg1 r1 ; /* scratch */ \ + mfsprg0 r1 ; /* exception stack in sprg0 */ \ + addi r1,r1,-80 ; /* push exception frame */ \ + \ + stw r0,0(r1) ; /* save r0 */ \ + mfsprg1 r0 ; \ + stw r0,4(r1) ; /* save r1 */ \ + stw r2,8(r1) ; /* save r2 */ \ + stw r3,12(r1) ; /* save r3 */ \ + stw r4,16(r1) ; \ + stw r5,20(r1) ; \ + stw r6,24(r1) ; \ + stw r7,28(r1) ; \ + stw r8,32(r1) ; \ + stw r9,36(r1) ; \ + stw r10,40(r1) ; \ + stw r11,44(r1) ; \ + stw r12,48(r1) ; \ + \ + mflr r0 ; \ + stw r0,52(r1) ; \ + mfcr r0 ; \ + stw r0,56(r1) ; \ + mfctr r0 ; \ + stw r0,60(r1) ; \ + mfxer r0 ; \ + stw r0,64(r1) ; \ + \ + /* 76(r1) unused */ \ + addi r1,r1,-16 ; /* call conventions uses 0(r1) and 4(r1)... */ + + +/************************************************************************/ +/* stack space */ +/************************************************************************/ + + .section .bss + .balign 32 + .space 32*1024 // 32 K client stack +client_stack: + .space 128 + + .space 64*1024 // 64 K stack +stack: .space 64 + + .space 32*1024 // 32 K exception stack +estack: .space 128 + + +/************************************************************************/ +/* entry */ +/************************************************************************/ + + .text +GLOBL(_start): + li r0,0 + mtmsr r0 + + lis r1,HA(estack) + addi r1,r1,LO(estack) + mtsprg0 r1 // setup exception stack + lis r1,HA(stack) + addi r1,r1,LO(stack) + + // copy exception vectors + lis r3,HA(__vectors) + addi r3,r3,LO(__vectors) + li r4,0 + li r5,__vectors_end - __vectors + 16 + rlwinm r5,r5,0,0,28 +1: lwz r6,0(r3) + lwz r7,4(r3) + lwz r8,8(r3) + lwz r9,12(r3) + stw r6,0(r4) + stw r7,4(r4) + stw r8,8(r4) + stw r9,12(r4) + dcbst 0,r4 + sync + icbi 0,r4 + sync + addi r5,r5,-16 + addi r3,r3,16 + addi r4,r4,16 + cmpwi r5,0 + bgt 1b + isync + + bl setup_mmu + bl entry +1: nop + b 1b + + + /* According to IEEE 1275, PPC bindings: + * + * MSR = FP, ME + (DR|IR) + * r1 = stack (32 K + 32 bytes link area above) + * r5 = clint interface handler + * r6 = address of client program arguments (unused) + * r7 = length of client program arguments (unsed) + */ +saved_stack: + .long 0 + /* void call_elf( entry ) */ +GLOBL(call_elf): + mflr r0 + stwu r1,-16(r1) + stw r0,20(r1) + mtlr r3 + lis r8,HA(saved_stack) + addi r8,r8,LO(saved_stack) // save our stack pointer + stw r1,0(r8) + lis r1,HA(client_stack) + addi r1,r1,LO(client_stack) + lis r5,HA(of_client_callback) + addi r5,r5,LO(of_client_callback) // r5 = callback + li r6,0 // r6 = address of client program arguments (unused) + li r7,0 // r7 = length of client program arguments (unused) + li r0,MSR_FP | MSR_ME | MSR_DR | MSR_IR + mtmsr r0 + blrl + + lis r8,HA(saved_stack) + addi r8,r8,LO(saved_stack) // restore stack pointer + mr r1,r8 + lwz r0,20(r1) + mtlr r0 + addi r1,r1,16 + // XXX: should restore r12-r31 etc.. + // we should not really come here though + blr + +GLOBL(of_client_callback): + lis r4,HA(saved_stack) + addi r4,r4,LO(saved_stack) + lwz r4,0(r4) + stwu r4,-32(r4) + mflr r5 + stw r5,32+4(r4) + stw r1,8(r4) // save caller stack + mr r1,r4 + stw r2,12(r1) + stw r0,16(r1) + mfctr r2 + stw r2,20(r1) + mfcr r2 + stw r2,24(r1) + mfxer r2 + stw r2,28(r1) + // do we need to save more registers? + bl of_client_interface + lwz r4,32+4(r1) + mtlr r4 + lwz r2,20(r1) + mtctr r2 + lwz r2,24(r1) + mtcr r2 + lwz r2,28(r1) + mtxer r2 + lwz r2,12(r1) + lwz r0,16(r1) + lwz r1,8(r1) // restore caller stack + blr + + /* rtas glue (must be reloctable) */ +GLOBL(of_rtas_start): + /* r3 = argument buffer, r4 = of_rtas_start */ + /* according to the CHRP standard, cr must be preserved (cr0/cr1 too?) */ + mr r6,r3 + lis r3,HA(OSI_SC_MAGIC_R3) + addi r3,r3,LO(OSI_SC_MAGIC_R3) + lis r4,HA(OSI_SC_MAGIC_R4) + addi r4,r4,LO(OSI_SC_MAGIC_R4) + li r5,OSI_OF_RTAS + sc + blr +GLOBL(of_rtas_end): + + + /* used in a hack to the newworld calibration */ +GLOBL(nw_dec_calibration): + .long 0 +GLOBL(timer_calib_start): + lis r3,HA(nw_dec_calibration) + addi r3,r3,LO(nw_dec_calibration) + lwz r3,0(r3) + blr +GLOBL(timer_calib_end): + + +/************************************************************************/ +/* vectors */ +/************************************************************************/ + +GLOBL(__vectors): + nop // NULL-jmp trap +1: nop // + b 1b + +exception_return: + addi r1,r1,16 // pop ABI frame + + lwz r0,52(r1) + mtlr r0 + lwz r0,56(r1) + mtcr r0 + lwz r0,60(r1) + mtctr r0 + lwz r0,64(r1) + mtxer r0 + + lwz r0,0(r1) // restore r0 + lwz r2,8(r1) // restore r2 + lwz r3,12(r1) // restore r3 + lwz r4,16(r1) + lwz r5,20(r1) + lwz r6,24(r1) + lwz r7,28(r1) + lwz r8,32(r1) + lwz r9,36(r1) + lwz r10,40(r1) + lwz r11,44(r1) + lwz r12,48(r1) + lwz r1,4(r1) // restore r1 + rfi + +trap_error: + mflr r3 + b unexpected_excep + +ILLEGAL_VECTOR( 0x100 ) +ILLEGAL_VECTOR( 0x200 ) + +VECTOR( 0x300, "DSI" ): + EXCEPTION_PREAMBLE + lis r3,HA(dsi_exception) + addi r3,r3,LO(dsi_exception) + mtctr r3 + bctrl + b exception_return + +VECTOR( 0x400, "ISI" ): + EXCEPTION_PREAMBLE + lis r3,HA(isi_exception) + addi r3,r3,LO(isi_exception) + mtctr r3 + bctrl + b exception_return + + ILLEGAL_VECTOR( 0x500 ) + ILLEGAL_VECTOR( 0x600 ) + ILLEGAL_VECTOR( 0x700 ) + +VECTOR( 0x800, "FPU" ): + mtsprg1 r3 + mfsrr1 r3 + ori r3,r3,0x2000 + mtsrr1 r3 + mfsprg1 r3 + rfi + +ILLEGAL_VECTOR( 0x900 ) +ILLEGAL_VECTOR( 0xa00 ) +ILLEGAL_VECTOR( 0xb00 ) +ILLEGAL_VECTOR( 0xc00 ) +ILLEGAL_VECTOR( 0xd00 ) +ILLEGAL_VECTOR( 0xe00 ) +ILLEGAL_VECTOR( 0xf00 ) +ILLEGAL_VECTOR( 0xf20 ) +ILLEGAL_VECTOR( 0x1000 ) +ILLEGAL_VECTOR( 0x1100 ) +ILLEGAL_VECTOR( 0x1200 ) +ILLEGAL_VECTOR( 0x1300 ) +ILLEGAL_VECTOR( 0x1400 ) +ILLEGAL_VECTOR( 0x1500 ) +ILLEGAL_VECTOR( 0x1600 ) +ILLEGAL_VECTOR( 0x1700 ) + +GLOBL(__vectors_end): + + +#define CACHE_LINE_SIZE 32 +#define LG_CACHE_LINE_SIZE 5 + +/* flush_icache_range( unsigned long start, unsigned long stop) */ +GLOBL(flush_icache_range): + li r5,CACHE_LINE_SIZE-1 + andc r3,r3,r5 + subf r4,r3,r4 + add r4,r4,r5 + srwi. r4,r4,LG_CACHE_LINE_SIZE + beqlr + mtctr r4 + mr r6,r3 +1: dcbst 0,r3 + addi r3,r3,CACHE_LINE_SIZE + bdnz 1b + sync /* wait for dcbst's to get to ram */ + mtctr r4 +2: icbi 0,r6 + addi r6,r6,CACHE_LINE_SIZE + bdnz 2b + sync /* additional sync needed on g4 */ + isync + blr diff --git a/qemu/roms/openbios/arch/ppc/timebase.S b/qemu/roms/openbios/arch/ppc/timebase.S new file mode 100644 index 000000000..19faed49d --- /dev/null +++ b/qemu/roms/openbios/arch/ppc/timebase.S @@ -0,0 +1,33 @@ +#include "asm/asmdefs.h" +#include "asm/processor.h" + +/* + * unsigned long long _get_ticks(void); + */ +_GLOBAL(_get_ticks): +1: mftbu r3 + mftb r4 + mftbu r5 + cmpw 0,r3,r5 + bne 1b + blr + +/* + * Delay for a number of ticks + */ +_GLOBAL(_wait_ticks): + mflr r8 /* save link register */ + mr r7, r3 /* save tick count */ + bl BRANCH_LABEL(_get_ticks) /* Get start time */ + + /* Calculate end time */ + addc r7, r4, r7 /* Compute end time lower */ + addze r6, r3 /* and end time upper */ + +1: bl BRANCH_LABEL(_get_ticks) /* Get current time */ + subfc r4, r4, r7 /* Subtract current time from end time */ + subfe. r3, r3, r6 + bge 1b /* Loop until time expired */ + + mtlr r8 /* restore link register */ + blr diff --git a/qemu/roms/openbios/arch/ppc64/qemu/ldscript b/qemu/roms/openbios/arch/ppc64/qemu/ldscript new file mode 100644 index 000000000..fbbcc546f --- /dev/null +++ b/qemu/roms/openbios/arch/ppc64/qemu/ldscript @@ -0,0 +1,85 @@ +OUTPUT_FORMAT(elf64-powerpc) +OUTPUT_ARCH(powerpc:common64) + +/* Initial load address + */ +BASE_ADDR = 0xfff00000; + +/* As NVRAM is at 0xfff04000, the .text needs to be after that + * The value in arch/ppc/qemu/kernel.c must match this value! + */ +TEXT_ADDR = 0xfff08000; + +/* Hard reset vector address + */ +HRESET_ADDR = 0xfffffffc; + +CSTACK_SIZE = 32768; /* client stack size */ + +SECTIONS +{ + . = BASE_ADDR; + + _start = BASE_ADDR + 0x0100; + .text.vectors ALIGN(4096): { + *(.text.vectors) + } + + . = TEXT_ADDR; + /* Normal sections */ + .data.dict ALIGN(4096): { + _dict_start = .; + *(.data.dict) + _dict_end = .; + } + + .text ALIGN(4096): { + *(.text) + *(.text.*) + } + + .rodata ALIGN(4096): { + _rodata = .; + *(.rodata) + *(.rodata.*) + *(.note.ELFBoot) + } + .data ALIGN(4096): { + _data = .; + *(.data) + *(.data.*) + *(.toc1) + *(.branch_lt) + _edata = .; + } + .opd : { + *(.opd) + } + .got : { + __toc_start = .; + *(.got) + *(.toc) + } + + .bss ALIGN(4096): { + _bss = .; + *(.sbss) + *(.sbss.*) + *(.bss) + *(.bss.*) + *(COMMON) + _ebss = .; + } + + . = HRESET_ADDR; + + .romentry : { *(.romentry) } + + . = ALIGN(4096); + _end = .; + + /* We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + + /DISCARD/ : { *(.comment*) *(.note.*) } +} diff --git a/qemu/roms/openbios/arch/sparc32/boot.c b/qemu/roms/openbios/arch/sparc32/boot.c new file mode 100644 index 000000000..49ec4cfb3 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/boot.c @@ -0,0 +1,261 @@ +/* + * + */ +#undef BOOTSTRAP +#include "config.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "drivers/drivers.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "libopenbios/ofmem.h" +#include "libopenbios/sys_info.h" +#include "openprom.h" +#include "boot.h" +#include "context.h" + +uint32_t kernel_image; +uint32_t kernel_size; +uint32_t qemu_cmdline; +uint32_t cmdline_size; +char boot_device; +const void *romvec; + +static struct linux_mlist_v0 *totphyslist, *availlist, *prommaplist; + +static void setup_romvec(void) +{ + /* SPARC32 is slightly unusual in that before invoking any loaders, a romvec array + needs to be set up to pass certain parameters using a C struct. Hence this function + extracts the relevant boot information and places it in obp_arg. */ + + int intprop, proplen, target, device, i; + unsigned int *intprop_ptr; + phandle_t chosen; + char *prop, *id, *name; + static char bootpathbuf[128], bootargsbuf[128], buf[128]; + struct linux_mlist_v0 **pp; + + /* Get the stdin and stdout paths */ + chosen = find_dev("/chosen"); + intprop = get_int_property(chosen, "stdin", &proplen); + PUSH(intprop); + fword("get-instance-path"); + ((struct linux_romvec *)romvec)->pv_stdin = pop_fstr_copy(); + + intprop = get_int_property(chosen, "stdout", &proplen); + PUSH(intprop); + fword("get-instance-path"); + ((struct linux_romvec *)romvec)->pv_stdout = pop_fstr_copy(); + + /* Get the name of the selected boot device, along with the device and unit number */ + prop = get_property(chosen, "bootpath", &proplen); + strncpy(bootpathbuf, prop, proplen); + prop = get_property(chosen, "bootargs", &proplen); + strncpy(bootargsbuf, prop, proplen); + + /* Set bootpath pointer used in romvec table to the bootpath */ + push_str(bootpathbuf); + fword("pathres-resolve-aliases"); + bootpath = pop_fstr_copy(); + printk("bootpath: %s\n", bootpath); + + /* Now do some work to get hold of the target, partition etc. */ + push_str(bootpathbuf); + feval("open-dev"); + feval("ihandle>boot-device-handle drop to my-self"); + push_str("name"); + fword("get-my-property"); + POP(); + name = pop_fstr_copy(); + + if (!strncmp(name, "sd", 2)) { + + /* + Old-style SunOS disk paths are given in the form: + + sd(c,t,d):s + + where: + c = controller (Nth controller in system, usually 0) + t = target (my-unit phys.hi) + d = device/LUN (my-unit phys.lo) + s = slice/partition (my-args) + */ + + /* Controller currently always 0 */ + obp_arg.boot_dev_ctrl = 0; + + /* Get the target, device and slice */ + fword("my-unit"); + target = POP(); + device = POP(); + + fword("my-args"); + id = pop_fstr_copy(); + + if (id != NULL) { + snprintf(buf, sizeof(buf), "sd(0,%d,%d):%c", target, device, id[0]); + obp_arg.dev_partition = id[0] - 'a'; + } else { + snprintf(buf, sizeof(buf), "sd(0,%d,%d)", target, device); + obp_arg.dev_partition = 0; + } + + obp_arg.boot_dev_unit = target; + + obp_arg.boot_dev[0] = buf[0]; + obp_arg.boot_dev[1] = buf[1]; + obp_arg.argv[0] = buf; + obp_arg.argv[1] = bootargsbuf; + + } else if (!strncmp(name, "SUNW,fdtwo", 10)) { + + obp_arg.boot_dev_ctrl = 0; + obp_arg.boot_dev_unit = 0; + obp_arg.dev_partition = 0; + + strcpy(buf, "fd()"); + + obp_arg.boot_dev[0] = buf[0]; + obp_arg.boot_dev[1] = buf[1]; + obp_arg.argv[0] = buf; + obp_arg.argv[1] = bootargsbuf; + + } else if (!strncmp(name, "le", 2)) { + + obp_arg.boot_dev_ctrl = 0; + obp_arg.boot_dev_unit = 0; + obp_arg.dev_partition = 0; + + strcpy(buf, "le()"); + + obp_arg.boot_dev[0] = buf[0]; + obp_arg.boot_dev[1] = buf[1]; + obp_arg.argv[0] = buf; + obp_arg.argv[1] = bootargsbuf; + + } + + /* Generate the totphys (total memory available) list */ + prop = get_property(s_phandle_memory, "reg", &proplen); + intprop_ptr = (unsigned int *)prop; + + for (pp = &totphyslist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) { + *pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0)); + (**pp).theres_more = NULL; + (**pp).start_adr = (char *)intprop_ptr[1]; + (**pp).num_bytes = intprop_ptr[2]; + + intprop_ptr += 3; + } + + /* Generate the avail (physical memory available) list */ + prop = get_property(s_phandle_memory, "available", &proplen); + intprop_ptr = (unsigned int *)prop; + + for (pp = &availlist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) { + *pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0)); + (**pp).theres_more = NULL; + (**pp).start_adr = (char *)intprop_ptr[1]; + (**pp).num_bytes = intprop_ptr[2]; + + intprop_ptr += 3; + } + + /* Generate the prommap (taken virtual memory) list from inverse of available */ + prop = get_property(s_phandle_mmu, "available", &proplen); + intprop_ptr = (unsigned int *)prop; + + for (pp = &prommaplist, i = 0; i < (proplen / sizeof(int)); pp = &(**pp).theres_more, i+=3) { + *pp = (struct linux_mlist_v0 *)malloc(sizeof(struct linux_mlist_v0)); + (**pp).theres_more = NULL; + (**pp).start_adr = (char *)(intprop_ptr[1] + intprop_ptr[2]); + + if (i + 3 < (proplen / sizeof(int))) { + /* Size from next entry */ + (**pp).num_bytes = (intprop_ptr[4] + intprop_ptr[5]) - (intprop_ptr[1] + intprop_ptr[2]); + } else { + /* Tail (size from top of virtual memory) */ + (**pp).num_bytes = 0xffffffffUL - (intprop_ptr[1] + intprop_ptr[2]) + 1; + } + + intprop_ptr += 3; + } + + /* Finally set the memory properties */ + ((struct linux_romvec *)romvec)->pv_v0mem.v0_totphys = &totphyslist; + ((struct linux_romvec *)romvec)->pv_v0mem.v0_available = &availlist; + ((struct linux_romvec *)romvec)->pv_v0mem.v0_prommap = &prommaplist; +} + + +void go(void) +{ + ucell address, type, size; + int image_retval = 0; + + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + setup_romvec(); + + printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + image_retval = start_elf((unsigned long)address, + (unsigned long)romvec); + + break; + + case 0x1: + /* Start ELF image */ + image_retval = start_elf((unsigned long)address, + (unsigned long)romvec); + + break; + + case 0x5: + /* Start a.out image */ + image_retval = start_elf((unsigned long)address, + (unsigned long)romvec); + + break; + + case 0x10: + /* Start Fcode image */ + printk("Evaluating FCode...\n"); + PUSH(address); + PUSH(1); + fword("byte-load"); + image_retval = 0; + break; + + case 0x11: + /* Start Forth image */ + PUSH(address); + PUSH(size); + fword("eval2"); + image_retval = 0; + break; + } + + printk("Image returned with return value %#x\n", image_retval); +} + + +void boot(void) +{ + /* Boot preloaded kernel */ + if (kernel_size) { + printk("[sparc] Kernel already loaded\n"); + start_elf(kernel_image, (unsigned long)romvec); + } +} diff --git a/qemu/roms/openbios/arch/sparc32/boot.h b/qemu/roms/openbios/arch/sparc32/boot.h new file mode 100644 index 000000000..55e391ac5 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/boot.h @@ -0,0 +1,41 @@ +/* tag: openbios loader prototypes for sparc32 + * + * Copyright (C) 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +// linux_load.c +int linux_load(struct sys_info *info, const char *file, const char *cmdline); + +// context.c +extern struct context *__context; +unsigned int start_elf(unsigned long entry_point, unsigned long param); + +// boot.c +extern const char *bootpath; +extern void boot(void); +extern void go(void); + +// sys_info.c +extern unsigned int qemu_mem_size; +extern void collect_sys_info(struct sys_info *info); + +// romvec.c +extern struct linux_arguments_v0 obp_arg; +extern const void *romvec; +extern const char *obp_stdin_path, *obp_stdout_path; +extern char obp_stdin, obp_stdout; + +// openbios.c +extern int qemu_machine_type; + +// arch/sparc32/lib.c +struct linux_mlist_v0; +extern struct linux_mlist_v0 *ptphys; +extern struct linux_mlist_v0 *ptmap; +extern struct linux_mlist_v0 *ptavail; + +void ob_init_mmu(void); +void init_mmu_swift(void); diff --git a/qemu/roms/openbios/arch/sparc32/build.xml b/qemu/roms/openbios/arch/sparc32/build.xml new file mode 100644 index 000000000..81c3586e0 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/build.xml @@ -0,0 +1,74 @@ +<build condition="SPARC32"> + + <dictionary name="openbios-sparc32" init="openbios"> + <object source="tree.fs" target="forth"/> + <object source="init.fs" target="forth"/> + <object source="QEMU,tcx.bin" target="fcode" condition="DRIVER_SBUS"/> + <object source="QEMU,cgthree.bin" target="fcode" condition="DRIVER_SBUS"/> + </dictionary> + + <library name="sparc32" type="static" target="target"> + <object source="openbios.c"/> + <object source="console.c"/> + <object source="lib.c"/> + <object source="boot.c"/> + <object source="context.c"/> + <object source="switch.S"/> + <object source="udiv.S"/> + <object source="linux_load.c"/> + <object source="sys_info.c"/> + <object source="ofmem_sparc32.c"/> + <object source="romvec.c"/> + <object source="call-romvec.S"/> + <object source="entry.S"/> + <object source="vectors.S"/> + </library> + + <executable name="openbios-plain.elf" target="target" condition="IMAGE_ELF"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/sparc32/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-plain.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="plainboot.c"/> + <external-object source="libsparc32.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + <external-object source="libgcc.a"/> + </executable> + + <!-- HACK ALERT --> + + <executable name="target/include/static-dict.h" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ + $(call quiet-command,$(ODIR)/forthstrap -x -D $@ -d $< </dev/null, " GEN $(TARGET_DIR)$@")]]></rule> + <external-object source="openbios-sparc32.dict"/> + </executable> + + <executable name="target/arch/sparc32/builtin.o" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ $(SRCDIR)/arch/sparc32/builtin.c $(ODIR)/target/include/static-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/sparc32/builtin.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + <!-- END OF HACK ALERT --> + + <executable name="openbios-builtin.elf" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/sparc32/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-builtin.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <external-object source="target/arch/sparc32/builtin.o"/> + <external-object source="libsparc32.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + <external-object source="libgcc.a"/> + </executable> + +</build> diff --git a/qemu/roms/openbios/arch/sparc32/builtin.c b/qemu/roms/openbios/arch/sparc32/builtin.c new file mode 100644 index 000000000..971a4009d --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/builtin.c @@ -0,0 +1,33 @@ +/* tag: openbios forth starter for builtin dictionary for sparc32 + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "asm/types.h" +#include "libopenbios/sys_info.h" + +/* + * wrap an array around the hex'ed dictionary file + */ + +/* 256K for the dictionary */ +#define DICTIONARY_SIZE (256 * 1024 / sizeof(ucell)) +#define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary)) + +static ucell forth_dictionary[DICTIONARY_SIZE] = { +#include "static-dict.h" +}; + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)forth_dictionary; + info->dict_end = (unsigned long *)FORTH_DICTIONARY_END; + info->dict_last = (ucell *)((unsigned char *)forth_dictionary + + FORTH_DICTIONARY_LAST); + info->dict_limit = sizeof(forth_dictionary); +} diff --git a/qemu/roms/openbios/arch/sparc32/call-romvec.S b/qemu/roms/openbios/arch/sparc32/call-romvec.S new file mode 100644 index 000000000..be77b232e --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/call-romvec.S @@ -0,0 +1,94 @@ +#define __ASSEMBLY +#include "psr.h" +#include "asm/asi.h" + + .text + .align 4 + +#define STACKFRAME_SZ 0x60 + +/* These are just handy. */ +#define _SV save %sp, -STACKFRAME_SZ, %sp +#define _RS restore + +#define FLUSH_ALL_KERNEL_WINDOWS \ + _SV; _SV; _SV; _SV; _SV; _SV; _SV; \ + _RS; _RS; _RS; _RS; _RS; _RS; _RS; + +/* Macro for romvec handlers */ +#define ROMVEC_HANDLER(type) \ + \ + .globl type##_handler; \ + \ +type##_handler: \ + \ + FLUSH_ALL_KERNEL_WINDOWS; \ + \ + save %sp, -STACKFRAME_SZ - 0x20, %sp; \ + \ + st %g1, [ %sp + STACKFRAME_SZ + 0x0]; \ + st %g2, [ %sp + STACKFRAME_SZ + 0x4]; \ + st %g3, [ %sp + STACKFRAME_SZ + 0x8]; \ + st %g4, [ %sp + STACKFRAME_SZ + 0xc]; \ + st %g5, [ %sp + STACKFRAME_SZ + 0x10]; \ + st %g6, [ %sp + STACKFRAME_SZ + 0x14]; \ + st %g7, [ %sp + STACKFRAME_SZ + 0x18]; \ + \ + mov %i0, %o0; \ + mov %i1, %o1; \ + mov %i2, %o2; \ + mov %i3, %o3; \ + mov %i4, %o4; \ + mov %i5, %o5; \ + \ + call type; \ + nop; \ + \ + mov %o0, %i0; \ + \ + ld [ %sp + STACKFRAME_SZ + 0x0], %g1; \ + ld [ %sp + STACKFRAME_SZ + 0x4], %g2; \ + ld [ %sp + STACKFRAME_SZ + 0x8], %g3; \ + ld [ %sp + STACKFRAME_SZ + 0xc], %g4; \ + ld [ %sp + STACKFRAME_SZ + 0x10], %g5; \ + ld [ %sp + STACKFRAME_SZ + 0x14], %g6; \ + ld [ %sp + STACKFRAME_SZ + 0x18], %g7; \ + \ + ret; \ + restore; \ + + +/* Generate handlers which are proxy functions to the + real C functions that correctly save the globals + and stack */ +ROMVEC_HANDLER(obp_devopen) +ROMVEC_HANDLER(obp_devclose) +ROMVEC_HANDLER(obp_rdblkdev) +ROMVEC_HANDLER(obp_nbgetchar) +ROMVEC_HANDLER(obp_nbputchar) +ROMVEC_HANDLER(obp_putstr) +ROMVEC_HANDLER(obp_printf) +ROMVEC_HANDLER(obp_reboot) +ROMVEC_HANDLER(obp_abort) +ROMVEC_HANDLER(obp_halt) +ROMVEC_HANDLER(obp_fortheval_v2) +ROMVEC_HANDLER(obp_inst2pkg) +ROMVEC_HANDLER(obp_dumb_memalloc) +ROMVEC_HANDLER(obp_dumb_memfree) +ROMVEC_HANDLER(obp_dumb_mmap) +ROMVEC_HANDLER(obp_dumb_munmap) +ROMVEC_HANDLER(obp_devread) +ROMVEC_HANDLER(obp_devwrite) +ROMVEC_HANDLER(obp_devseek) +ROMVEC_HANDLER(obp_cpustart) +ROMVEC_HANDLER(obp_cpustop) +ROMVEC_HANDLER(obp_cpuidle) +ROMVEC_HANDLER(obp_cpuresume) +ROMVEC_HANDLER(obp_nextnode) +ROMVEC_HANDLER(obp_child) +ROMVEC_HANDLER(obp_proplen) +ROMVEC_HANDLER(obp_getprop) +ROMVEC_HANDLER(obp_setprop) +ROMVEC_HANDLER(obp_nextprop) +ROMVEC_HANDLER(obp_memalloc) + diff --git a/qemu/roms/openbios/arch/sparc32/console.c b/qemu/roms/openbios/arch/sparc32/console.c new file mode 100644 index 000000000..61c2e238e --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/console.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "drivers/drivers.h" +#include "openbios.h" +#include "libopenbios/console.h" +#include "libopenbios/ofmem.h" +#include "libopenbios/video.h" + +#ifdef CONFIG_DEBUG_CONSOLE + +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +static int arch_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + escc_uart_putchar(c); +#endif + return c; +} + +static int arch_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VIDEO + if (keyboard_dataready()) + return 1; +#endif + return 0; +} + +static int arch_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (escc_uart_charav(CONFIG_SERIAL_PORT)) + return (escc_uart_getchar(CONFIG_SERIAL_PORT)); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VIDEO + if (keyboard_dataready()) + return (keyboard_readdata()); +#endif + return 0; +} + +struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + +#endif // CONFIG_DEBUG_CONSOLE diff --git a/qemu/roms/openbios/arch/sparc32/context.c b/qemu/roms/openbios/arch/sparc32/context.c new file mode 100644 index 000000000..d4d8530d4 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/context.c @@ -0,0 +1,113 @@ +/* + * context switching + * 2003-10 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "context.h" +#include "libopenbios/sys_info.h" +#include "boot.h" +#include "openbios.h" + +#define MAIN_STACK_SIZE 16384 +#define IMAGE_STACK_SIZE 4096*2 + +#define debug printk + +static void start_main(void); /* forward decl. */ +void __exit_context(void); /* assembly routine */ + +/* + * Main context structure + * It is placed at the bottom of our stack, and loaded by assembly routine + * to start us up. + */ +static struct context main_ctx = { + .regs[REG_SP] = (uint32_t) &_estack - 96, + .pc = (uint32_t) start_main, + .npc = (uint32_t) start_main + 4, + .return_addr = (uint32_t) __exit_context, +}; + +/* This is used by assembly routine to load/store the context which + * it is to switch/switched. */ +struct context *__context = &main_ctx; + +/* Stack for loaded ELF image */ +static uint8_t image_stack[IMAGE_STACK_SIZE]; + +/* Pointer to startup context (physical address) */ +unsigned long __boot_ctx; + +/* + * Main starter + * This is the C function that runs first. + */ +static void start_main(void) +{ + /* Save startup context, so we can refer to it later. + * We have to keep it in physical address since we will relocate. */ + __boot_ctx = virt_to_phys(__context); + + /* Start the real fun */ + openbios(); + + /* Returning from here should jump to __exit_context */ + __context = boot_ctx; +} + +/* Setup a new context using the given stack. + */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_params) +{ + struct context *ctx; + + ctx = (struct context *) + (stack + stack_size - (sizeof(*ctx) + num_params*sizeof(uint32_t))); + memset(ctx, 0, sizeof(*ctx)); + + /* Fill in reasonable default for flat memory model */ + ctx->regs[REG_SP] = virt_to_phys(SP_LOC(ctx)); + ctx->return_addr = virt_to_phys(__exit_context); + + return ctx; +} + +/* Switch to another context. */ +struct context *switch_to(struct context *ctx) +{ + volatile struct context *save; + struct context *ret; + + debug("switching to new context:\n"); + save = __context; + __context = ctx; + asm __volatile__ ("\n\tcall __switch_context" + "\n\tnop" ::: "g1", "g2", "g3", "g4", "g5", "g6", "g7", + "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7", + "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7", + "i0", "i1", "i2", "i3", "i4", "i5", "i7", + "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", + "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f17", "f18", "f19", + "f20", "f21", "f22", "f23", "f24", "f25", "f26", "f27", "f28", "f29", + "f30", "f31", + "memory"); + ret = __context; + __context = (struct context *)save; + return ret; +} + +/* Start ELF Boot image */ +unsigned int start_elf(unsigned long entry_point, unsigned long param) +{ + struct context *ctx; + + ctx = init_context(image_stack, sizeof image_stack, 1); + ctx->pc = entry_point; + ctx->param[0] = param; + + ctx = switch_to(ctx); + return ctx->regs[REG_O0]; +} diff --git a/qemu/roms/openbios/arch/sparc32/context.h b/qemu/roms/openbios/arch/sparc32/context.h new file mode 100644 index 000000000..8689d563e --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/context.h @@ -0,0 +1,31 @@ +#ifndef SPARC32_CONTEXT_H +#define SPARC32_CONTEXT_H + +struct context { + /* General registers */ + uint32_t regs[32]; + uint32_t pc; + uint32_t npc; +#define REG_O0 8 +#define REG_SP 14 +#define SP_LOC(ctx) (&(ctx)->regs[REG_SP]) + /* Flags */ + /* Optional stack contents */ + uint32_t return_addr; + uint32_t param[0]; +}; + +/* Create a new context in the given stack */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_param); + +/* Switch context */ +struct context *switch_to(struct context *); + +/* Holds physical address of boot context */ +extern unsigned long __boot_ctx; + +/* This can always be safely used to refer to the boot context */ +#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx)) + +#endif /* SPARC32_CONTEXT_H */ diff --git a/qemu/roms/openbios/arch/sparc32/crs.h b/qemu/roms/openbios/arch/sparc32/crs.h new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/crs.h diff --git a/qemu/roms/openbios/arch/sparc32/entry.S b/qemu/roms/openbios/arch/sparc32/entry.S new file mode 100644 index 000000000..72cb33863 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/entry.S @@ -0,0 +1,532 @@ +/** + ** Standalone startup code for Linux PROM emulator. + ** Copyright 1999 Pete A. Zaitcev + ** This code is licensed under GNU General Public License. + **/ +/* + * $Id: head.S,v 1.12 2002/07/23 05:47:09 zaitcev Exp $ + */ + +#define __ASSEMBLY +#include "psr.h" +#include "asm/asi.h" +#include "asm/crs.h" +#define NO_QEMU_PROTOS +#define NO_OPENBIOS_PROTOS +#include "arch/common/fw_cfg.h" + +#define CFG_ADDR 0x00000510 +#define CFG_ASI 0x2d + +#define PHYS_JJ_INTR0 0x71E00000 /* CPU0 interrupt control registers */ + +#define PHYS_SS10_INTR0 0xf1400000 + +#define PHYS_SS2_INTR0 0xf5000000 +#define SER_ADDR2 0xf1000004 + +#define PHYS_SS1000_SBI 0x02800000 +#define SER_ADDR1000 0x00200004 + +#define WRITE_PAUSE nop; nop; nop; /* Have to do this after %wim/%psr chg */ + + .globl entry, _entry + + .section ".text", "ax" + .align 8 + + /* Memory map: + * + * Top +-------------------------+ + * | SMP CPU table | + * | s + 0x1f00 ... 0x1f0f | + * | s + 0x1f0c valid | + * | s + 0x1f08 entry | + * | s + 0x1f04 ctxtbl | + * | s + 0x1f00 ctx | + * +-------------------------+ + * | Bootstrap | + * | MMU L3 tables 8 * 0x100 | + * | s + 0xa00 ... 0x11ff | + * +-------------------------+ + * | Bootstrap | + * | MMU L2 tables 2 * 0x100 | + * | s + 0x800 ... 0x9ff | + * +-------------------------+ + * | Bootstrap | + * | MMU L1 table 0x400 | + * | s + 0x400 ... 0x7ff | + * +-------------------------+ + * | Bootstrap | + * | MMU L0/ctx table 0x400 | + * | s + 0x000 ... 0x3ff | + * +-------------------------+ + * | | + * | ROM into RAM | + * | | + * +-------------------------+ + * : : + * Bottom + */ + +/* + * Entry point + * We start execution from here. + */ +_entry: +entry: + /* Switch to our main context. + * Main context is statically defined in C. + */ + + ! Check signature "QEMU" + set CFG_ADDR, %g5 + mov FW_CFG_SIGNATURE, %g2 + stha %g2, [%g5] CFG_ASI + add %g5, 2, %g5 + lduba [%g5] CFG_ASI, %g2 + cmp %g2, 'Q' + bne bad_conf + nop + lduba [%g5] CFG_ASI, %g2 + cmp %g2, 'E' + bne bad_conf + nop + lduba [%g5] CFG_ASI, %g2 + cmp %g2, 'M' + bne bad_conf + nop + lduba [%g5] CFG_ASI, %g2 + cmp %g2, 'U' + bne bad_conf + nop + + ! Get memory size from configuration device + ! NB: little endian format + mov FW_CFG_RAM_SIZE, %g2 + sub %g5, 2, %g5 + stha %g2, [%g5] CFG_ASI + add %g5, 2, %g5 + lduba [%g5] CFG_ASI, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 8, %g3 + or %g3, %g4, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 16, %g3 + or %g3, %g4, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 24, %g3 + or %g3, %g4, %g1 + ! %g1 contains end of memory + + ! Get kernel address from configuration device + ! NB: little endian format + mov FW_CFG_KERNEL_ADDR, %g2 + sub %g5, 2, %g5 + stha %g2, [%g5] CFG_ASI + add %g5, 2, %g5 + lduba [%g5] CFG_ASI, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 8, %g3 + or %g3, %g4, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 16, %g3 + or %g3, %g4, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 24, %g3 + or %g3, %g4, %g4 + + ! If kernel address is set, don't clear from base of RAM in order to + ! leave the kernel image intact + mov 0, %g6 + cmp %g4, 0 + beq clear_mem + nop + + ! Start from 16M + set 0x1000000, %g6 + +clear_mem: + sta %g0, [%g6] ASI_M_BYPASS + add %g6, 0x4, %g6 + cmp %g6, %g1 + bl clear_mem + nop + +clear_done: + ! Start of private memory in %g6 + set 0x2000, %g3 + sub %g1, %g3, %g6 + + ! Check if this is the boot CPU and skip SMP table check if yes + ! XXX: not all CPUs should have MXCC + set 0x1c00f00, %g2 + ldda [%g2] ASI_CONTROL, %g2 + srl %g3, 24, %g7 + sub %g7, 8, %g7 + tst %g7 + bz skip_table + nop + + ! Calculate SMP table location + set 0x1f0c, %g2 + add %g6, %g2, %g2 ! valid? + lda [%g2] ASI_M_BYPASS, %g7 + sta %g0, [%g2] ASI_M_BYPASS + +skip_table: + ! Get machine ID from configuration device + mov FW_CFG_MACHINE_ID, %g2 + sub %g5, 2, %g5 + stha %g2, [%g5] CFG_ASI + add %g5, 2, %g5 + lduba [%g5] CFG_ASI, %g4 + + lduba [%g5] CFG_ASI, %g3 + sll %g3, 8, %g3 + or %g3, %g4, %g4 + mov %g4, %y + + cmp %g4, 96 + bgeu ss1000 + cmp %g4, 64 + bgeu ss10 + cmp %g4, 32 + blu ss2 + nop + + ! Ok, this is SS-5 + + tst %g7 + bz first_cpu + nop + + ! Clear softints used for SMP CPU startup + set PHYS_JJ_INTR0 + 0x04, %g1 + sll %g2, 12, %g2 + add %g1, %g2, %g2 + set 0xffffffff, %g1 + sta %g1, [%g2] ASI_M_BYPASS ! clear softints + add %g2, 4, %g2 + sta %g0, [%g2] ASI_M_BYPASS ! clear softints + +load_ctx: + ! SMP init, jump to user specified address + set 0x1f04, %g5 + add %g6, %g5, %g5 ! ctxtbl + lda [%g5] ASI_M_BYPASS, %g2 + sta %g0, [%g5] ASI_M_BYPASS + set AC_M_CTPR, %g1 + sta %g2, [%g1] ASI_M_MMUREGS ! set ctx table ptr + set 0x1f00, %g5 + add %g6, %g5, %g5 ! ctx + lda [%g5] ASI_M_BYPASS, %g2 + sta %g0, [%g5] ASI_M_BYPASS + set AC_M_CXR, %g1 + sta %g2, [%g1] ASI_M_MMUREGS ! set context + set 0x1f08, %g5 + add %g6, %g5, %g5 ! entry + lda [%g5] ASI_M_BYPASS, %g2 + sta %g0, [%g5] ASI_M_BYPASS + set 1, %g1 + jmp %g2 ! jump to kernel + sta %g1, [%g0] ASI_M_MMUREGS ! enable mmu + +ss10: + ! Ok, this is SS-10 or SS-600MP + tst %g7 + bz first_cpu + nop + + ! Clear softints used for SMP CPU startup + set PHYS_SS10_INTR0 + 0x04, %g1 + sll %g2, 12, %g2 + add %g1, %g2, %g2 + set 0xffffffff, %g1 + sta %g1, [%g2] ASI_M_CTL ! clear softints + add %g2, 4, %g2 + b load_ctx + sta %g0, [%g2] ASI_M_CTL ! clear softints + +ss2: + ! Ok, this is SS-2 + set ss2_error, %o2 + b ss2_ss1000_halt + nop + +ss1000: + ! Ok, this is SS-1000 or SS-2000 + set ss1000_error, %o2 + b ss2_ss1000_halt + nop + +first_cpu: + /* Create temporary page tables and map the ROM area to end of + RAM. This will be done properly in iommu.c later. */ + ! Calculate start of page tables etc. to %g6 + set 0x2000, %g4 + sub %g1, %g4, %g6 ! start of private memory + + mov %g6, %g2 ! ctx table at s+0x0 + add %g2, 0x400, %g3 ! l1 table at s+0x400 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 0x400, %g2 ! s+0x400 + add %g2, 0x400, %g3 ! l2 table for ram (00xxxxxx) at s+0x800 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 0x500, %g3 ! l2 table for rom (ffxxxxxx) at s+0x900 + add %g2, 0x3fc, %g2 ! s+0x7fc + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 0x4, %g2 ! s+0x800 +#if 0 + set 0x40, %g6 + set ((7 << 2) | 2), %g3 ! 7 = U: --- S: RWX (main memory) +1: sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 + deccc %g6 + bne 1b + nop +#else + add %g2, 0x100, %g2 +#endif + ! s+0x900 + add %g2, 0xa00 - 0x900, %g3 ! l3 table for rom at s+0xa00 + add %g2, 0x0d0, %g2 ! s+0x9d0 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9d4 + add %g2, 0xb00 - 0x9d4, %g3 ! 2nd l3 table for rom at s+0xb00 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9d8 + add %g2, 0xc00 - 0x9d8, %g3 ! 3rd l3 table for rom at s+0xc00 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9dc + add %g2, 0xd00 - 0x9dc, %g3 ! 4th l3 table for rom at s+0xd00 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9e0 + add %g2, 0xe00 - 0x9e0, %g3 ! 5th l3 table for rom at s+0xe00 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9e4 + add %g2, 0xf00 - 0x9e4, %g3 ! 6th l3 table for rom at s+0xf00 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9e8 + add %g2, 0x1000 - 0x9e8, %g3 ! 7th l3 table for rom at s+0x1000 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 ! s+0x9ec + add %g2, 0x1100 - 0x9ec, %g3 ! 8th l3 table for rom at s+0x1100 + srl %g3, 0x4, %g3 + or %g3, 0x1, %g3 + sta %g3, [%g2] ASI_M_BYPASS + add %g2, 0xa00-0x9ec, %g2 ! s+0xa00 + + /* Use end of ram for code, rodata, data, and bss + sections. SunOS wants to write to trap table... */ + set _end, %g6 + set _start, %g4 + sub %g6, %g4, %g6 + sub %g1, %g6, %g3 + set 0x1000, %g5 + sub %g3, %g5, %g3 + sub %g3, %g5, %g3 ! start of ROM copy + mov %g3, %g7 ! save in %g7 + srl %g6, 12, %g6 ! # of all pages +1: srl %g3, 0x4, %g4 + or %g4, ((7 << 2) | 2), %g4 ! 7 = U: --- S: RWX + sta %g4, [%g2] ASI_M_BYPASS + add %g2, 4, %g2 + add %g3, %g5, %g3 + deccc %g6 + bne 1b + nop + + mov %g1, %g6 ! %g6 = memory size + + /* Copy the code, rodata and data sections from ROM. */ + sub %g7, 4, %g3 + set _start - 4, %g4 ! First address of TEXT - 4 + set _bss, %g5 ! Last address of DATA + ba 2f + nop +1: + lda [%g4] ASI_M_KERNELTXT, %g1 + sta %g1, [%g3] ASI_M_BYPASS +2: + cmp %g4, %g5 + add %g3, 0x4, %g3 + bl 1b + add %g4, 0x4, %g4 + + set 0x2000, %g3 + sub %g6, %g3, %g7 ! ctx table at s+0x0 + set AC_M_CTPR, %g2 + srl %g7, 4, %g7 + sta %g7, [%g2] ASI_M_MMUREGS ! set ctx table ptr + set AC_M_CXR, %g2 + sta %g0, [%g2] ASI_M_MMUREGS ! context 0 + set highmem, %g2 + set 1, %g1 + jmp %g2 + sta %g1, [%g0] ASI_M_MMUREGS ! enable mmu +highmem: + /* + * The code which enables traps is a simplified version of + * kernel head.S. + * + * We know number of windows as 8 so we do not calculate them. + * The deadwood is here for any case. + */ + + /* Turn on Supervisor, EnableFloating, and all the PIL bits. + * Also puts us in register window zero with traps off. + */ + set (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2 + wr %g2, 0x0, %psr + WRITE_PAUSE + + /* Zero out our BSS section. */ + set _bss - 4, %o0 ! First address of BSS + set _estack - 4, %o1 ! Last address of BSS + ba 2f + nop +1: + st %g0, [%o0] +2: + subcc %o0, %o1, %g0 + bl 1b + add %o0, 0x4, %o0 + + set trap_table, %g1 + wr %g1, 0x0, %tbr + + set qemu_mem_size, %g1 + st %g6, [%g1] + + set _end, %o0 ! Store va->pa conversion factor + set _start, %o2 + sub %o0, %o2, %o0 + sub %g6, %o0, %o0 + set 0x2000, %o1 + sub %o0, %o1, %o0 ! start of ROM copy + sub %o2, %o0, %o0 ! start of ROM copy + set va_shift, %g1 + st %o0, [%g1] + + set qemu_machine_type, %g1 + mov %y, %g2 + st %g2, [%g1] + + /* Compute NWINDOWS and stash it away. Now uses %wim trick explained + * in the V8 manual. Ok, this method seems to work, Sparc is cool... + * No, it doesn't work, have to play the save/readCWP/restore trick. + */ + + wr %g0, 0x0, %wim ! so we do not get a trap + WRITE_PAUSE + + save + + rd %psr, %g3 + + restore + + and %g3, 0x1f, %g3 + add %g3, 0x1, %g3 + + mov 2, %g1 + wr %g1, 0x0, %wim ! make window 1 invalid + WRITE_PAUSE + + cmp %g3, 0x7 + bne 1f + nop + + /* Adjust our window handling routines to + * do things correctly on 7 window Sparcs. + */ +#define PATCH_INSN(src, dest) \ + set src, %g5; \ + set dest, %g2; \ + ld [%g5], %g4; \ + st %g4, [%g2]; + + /* Patch for window spills... */ + PATCH_INSN(spnwin_patch1_7win, spnwin_patch1) + PATCH_INSN(spnwin_patch2_7win, spnwin_patch2) + + /* Patch for window fills... */ + PATCH_INSN(fnwin_patch1_7win, fnwin_patch1) + PATCH_INSN(fnwin_patch2_7win, fnwin_patch2) + +1: + /* Finally, turn on traps so that we can call c-code. */ + rd %psr, %g3 + wr %g3, 0x0, %psr + WRITE_PAUSE + + wr %g3, PSR_ET, %psr + WRITE_PAUSE + + set 0, %fp + call __switch_context_nosave + nop + + /* We get here when the main context switches back to + * the boot context. + * Return to previous bootloader. + */ + ret + nop + +ss2_ss1000_halt: + set SER_ADDR2, %o0 + set SER_ADDR1000, %o1 + mov 0x05, %o3 /* Reg 5, TXCTRL2 */ + stba %o3, [%o0] ASI_M_BYPASS + stba %o3, [%o1] ASI_M_CTL + mov 0x68, %o3 /* 8 bits, Tx enabled */ + stba %o3, [%o0] ASI_M_BYPASS + stba %o3, [%o1] ASI_M_CTL + add %o0, 2, %o0 + add %o1, 2, %o1 + +1: lduba [%o2] ASI_M_KERNELTXT, %o3 + cmp %o3, 0 + be 2f + nop + stba %o3, [%o0] ASI_M_BYPASS + stba %o3, [%o1] ASI_M_CTL + b 1b + inc %o2 +bad_conf: +2: b 2b + nop + + .section .rodata +ss2_error: + .string "Sun4c machines are not supported by OpenBIOS yet, freezing\r\n" +ss1000_error: + .string "Sun4d machines are not supported by OpenBIOS yet, freezing\r\n" diff --git a/qemu/roms/openbios/arch/sparc32/init.fs b/qemu/roms/openbios/arch/sparc32/init.fs new file mode 100644 index 000000000..814c720c9 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/init.fs @@ -0,0 +1,83 @@ +:noname + ." Type 'help' for detailed information" cr + \ ." boot secondary slave cdrom: " cr + \ ." 0 > boot hd:2,\boot\vmlinuz root=/dev/hda2" cr + ; DIAG-initializer + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +:noname + set-defaults +; PREPOST-initializer + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /virtual-memory" preopen +; SYSTEM-initializer + +device-end + +: rmap@ ( virt -- rmentry ) + drop 0 + ; + +\ D5.3 SBus specific on-board memory address space +: obmem ( -- space ) + 0 + ; + +\ (peek) and (poke) implementation +defer sfsr@ +defer ignore-dfault + +:noname + \ ( addr xt -- false | value true ) + sfsr@ drop \ Clear any existing MMU fault status + + -1 ignore-dfault ! \ Disable data fault trap + execute + 0 ignore-dfault ! \ Enable data fault trap + + sfsr@ 0= if + true + else + drop false \ Failed, drop the read value + then +; to (peek) + +:noname + \ ( value addr xt -- okay? ) + sfsr@ drop \ Clear any existing MMU fault status + + -1 ignore-dfault ! \ Disable data fault trap + execute + 0 ignore-dfault ! \ Enable data fault trap + + sfsr@ 0= \ true if no fault +; to (poke) + +\ Load TCX FCode driver blob +[IFDEF] CONFIG_DRIVER_SBUS + -1 value tcx-driver-fcode + " QEMU,tcx.bin" $encode-file to tcx-driver-fcode +[THEN] diff --git a/qemu/roms/openbios/arch/sparc32/ldscript b/qemu/roms/openbios/arch/sparc32/ldscript new file mode 100644 index 000000000..b543c1599 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/ldscript @@ -0,0 +1,73 @@ +OUTPUT_FORMAT(elf32-sparc) +OUTPUT_ARCH(sparc) + +/* QEMU ELF loader can't handle very complex files, so we put ELFBoot +info to rodata and put initctx to data.*/ + +ENTRY(trap_table) + +/* Initial load address + */ +BASE_ADDR = 0xffd00000; + +/* 16KB stack */ +STACK_SIZE = 16384; +VMEM_SIZE = 128 * 1024; +IOMEM_SIZE = 256 * 1024 + 768 * 1024; + +SECTIONS +{ + . = BASE_ADDR; + + /* Start of the program. + * Now the version string is in the note, we must include it + * in the program. Otherwise we lose the string after relocation. */ + _start = .; + + /* Normal sections */ + .text ALIGN(4096): { + *(.text.vectors) + *(.text) + *(.text.*) + } + .rodata ALIGN(4096): { + _rodata = .; + sound_drivers_start = .; + *(.rodata.sound_drivers) + sound_drivers_end = .; + *(.rodata) + *(.rodata.*) + *(.note.ELFBoot) + } + .data ALIGN(4096): { + _data = .; + *(.data) + *(.data.*) + } + + .bss ALIGN(4096): { + _bss = .; + *(.bss) + *(.bss.*) + *(COMMON) + + . = ALIGN(4096); + _vmem = .; + . += VMEM_SIZE; + _evmem = .; + + _stack = .; + . += STACK_SIZE; + . = ALIGN(16); + _estack = .; + } + + . = ALIGN(4096); + _end = .; + _iomem = _end + IOMEM_SIZE; + + /* We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + + /DISCARD/ : { *(.comment*) *(.note.*) } +} diff --git a/qemu/roms/openbios/arch/sparc32/lib.c b/qemu/roms/openbios/arch/sparc32/lib.c new file mode 100644 index 000000000..d27b604c9 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/lib.c @@ -0,0 +1,397 @@ +/* lib.c + * tag: simple function library + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "libc/vsprintf.h" +#include "libopenbios/bindings.h" +#include "arch/sparc32/ofmem_sparc32.h" +#include "asm/asi.h" +#include "pgtsrmmu.h" +#include "openprom.h" +#include "libopenbios/sys_info.h" +#include "boot.h" +#include "romvec.h" + +#define NCTX_SWIFT 0x100 +#define LOWMEMSZ 32 * 1024 * 1024 + +#ifdef CONFIG_DEBUG_MEM +#define DPRINTF(fmt, args...) \ + do { printk(fmt , ##args); } while (0) +#else +#define DPRINTF(fmt, args...) +#endif + +/* Format a string and print it on the screen, just like the libc + * function printf. + */ +int printk( const char *fmt, ... ) +{ + char *p, buf[512]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) + putchar(*p); + return i; +} + +/* + * Allocatable memory chunk. + */ +struct mem { + char *start, *uplim; + char *curp; +}; + +struct mem cdvmem; /* Current device virtual memory space */ + +unsigned int va_shift; +unsigned long *l1; +static unsigned long *context_table; + +struct linux_mlist_v0 *ptphys; +struct linux_mlist_v0 *ptmap; +struct linux_mlist_v0 *ptavail; + +/* Private functions for mapping between physical/virtual addresses */ +phys_addr_t +va2pa(unsigned long va) +{ + if ((va >= (unsigned long)&_start) && + (va < (unsigned long)&_end)) + return va - va_shift; + else + return va; +} + +unsigned long +pa2va(phys_addr_t pa) +{ + if ((pa + va_shift >= (unsigned long)&_start) && + (pa + va_shift < (unsigned long)&_end)) + return pa + va_shift; + else + return pa; +} + +void * +malloc(int size) +{ + return ofmem_malloc(size); +} + +void * +realloc( void *ptr, size_t size ) +{ + return ofmem_realloc(ptr, size); +} + +void +free(void *ptr) +{ + ofmem_free(ptr); +} + +/* + * Allocate memory. This is reusable. + */ +void +mem_init(struct mem *t, char *begin, char *limit) +{ + t->start = begin; + t->uplim = limit; + t->curp = begin; +} + +void * +mem_alloc(struct mem *t, int size, int align) +{ + char *p; + unsigned long pa; + + // The alignment restrictions refer to physical, not virtual + // addresses + pa = va2pa((unsigned long)t->curp) + (align - 1); + pa &= ~(align - 1); + p = (char *)pa2va(pa); + + if ((unsigned long)p >= (unsigned long)t->uplim || + (unsigned long)p + size > (unsigned long)t->uplim) + return NULL; + t->curp = p + size; + + return p; +} + +/* + * D5.3 pgmap@ ( va -- pte ) + */ +static void +pgmap_fetch(void) +{ + uint32_t pte; + unsigned long va, pa; + + va = POP(); + + pa = find_pte(va, 0); + if (pa == 1 || pa == 2) + goto error; + pte = *(uint32_t *)pa; + DPRINTF("pgmap@: va 0x%lx pa 0x%lx pte 0x%x\n", va, pa, pte); + + PUSH(pte); + return; + error: + PUSH(0); +} + +/* + * D5.3 pgmap! ( pte va -- ) + */ +static void +pgmap_store(void) +{ + uint32_t pte; + unsigned long va, pa; + + va = POP(); + pte = POP(); + + pa = find_pte(va, 1); + *(uint32_t *)pa = pte; + DPRINTF("pgmap!: va 0x%lx pa 0x%lx pte 0x%x\n", va, pa, pte); +} + +/* + * D5.3 map-pages ( pa space va size -- ) + */ +static void +ob_map_pages(void) +{ + unsigned long va; + int size; + uint64_t pa; + + size = POP(); + va = POP(); + pa = POP(); + pa <<= 32; + pa |= POP() & 0xffffffff; + + ofmem_arch_map_pages(pa, va, size, ofmem_arch_default_translation_mode(pa)); +} + +char *obp_dumb_mmap(char *va, int which_io, unsigned int pa, + unsigned int size) +{ + uint64_t mpa = ((uint64_t)which_io << 32) | (uint64_t)pa; + + ofmem_arch_map_pages(mpa, (unsigned long)va, size, ofmem_arch_default_translation_mode(mpa)); + return va; +} + +void obp_dumb_munmap(__attribute__((unused)) char *va, + __attribute__((unused)) unsigned int size) +{ + DPRINTF("obp_dumb_munmap: virta 0x%x, sz %d\n", (unsigned int)va, size); +} + +char *obp_memalloc(char *va, unsigned int size, unsigned int align) +{ + phys_addr_t phys; + ucell virt; + + DPRINTF("obp_memalloc: virta 0x%x, sz %d, align %d\n", (unsigned int)va, size, align); + + /* Claim physical memory */ + phys = ofmem_claim_phys(-1, size, align); + + /* Claim virtual memory */ + virt = ofmem_claim_virt(pointer2cell(va), size, 0); + + /* Map the memory */ + ofmem_map(phys, virt, size, ofmem_arch_default_translation_mode(phys)); + + return cell2pointer(virt); +} + +char *obp_dumb_memalloc(char *va, unsigned int size) +{ + unsigned long align = size; + phys_addr_t phys; + ucell virt; + + DPRINTF("obp_dumb_memalloc: virta 0x%x, sz %d\n", (unsigned int)va, size); + + /* Solaris seems to assume that the returned value is physically aligned to size. + e.g. it is used for setting up page tables. */ + + /* Claim physical memory */ + phys = ofmem_claim_phys(-1, size, align); + + /* Claim virtual memory - if va == NULL then we choose va address */ + if (va == NULL) { + virt = ofmem_claim_virt((ucell)-1, size, align); + } else { + virt = ofmem_claim_virt(pointer2cell(va), size, 0); + } + + /* Map the memory */ + ofmem_map(phys, virt, size, ofmem_arch_default_translation_mode(phys)); + + return cell2pointer(virt); +} + +void obp_dumb_memfree(char *va, unsigned size) +{ + phys_addr_t phys; + ucell cellmode; + + DPRINTF("obp_dumb_memfree: virta 0x%x, sz %d\n", (unsigned int)va, size); + + phys = ofmem_translate(pointer2cell(va), &cellmode); + + ofmem_unmap(pointer2cell(va), size); + ofmem_release_virt(pointer2cell(va), size); + ofmem_release_phys(phys, size); +} + +/* Data fault handling routines */ + +extern unsigned int ignore_dfault; + +/* ( -- reg ) */ +static void srmmu_get_sfsr(void) +{ + PUSH(srmmu_get_fstatus()); +} + +/* ( -- addr ) */ +static void ignore_dfault_addr(void) +{ + PUSH(pointer2cell(&ignore_dfault)); +} + +void +ob_init_mmu(void) +{ + ucell *memreg; + ucell *virtreg; + phys_addr_t virtregsize; + ofmem_t *ofmem = ofmem_arch_get_private(); + + /* Find the phandles for the /memory and /virtual-memory nodes */ + push_str("/memory"); + fword("find-package"); + POP(); + s_phandle_memory = POP(); + + push_str("/virtual-memory"); + fword("find-package"); + POP(); + s_phandle_mmu = POP(); + + ofmem_register(s_phandle_memory, s_phandle_mmu); + + /* Setup /memory:reg (totphys) property */ + memreg = malloc(3 * sizeof(ucell)); + ofmem_arch_encode_physaddr(memreg, 0); /* physical base */ + memreg[2] = (ucell)ofmem->ramsize; /* size */ + + push_str("/memory"); + fword("find-device"); + PUSH(pointer2cell(memreg)); + PUSH(3 * sizeof(ucell)); + push_str("reg"); + PUSH_ph(s_phandle_memory); + fword("encode-property"); + + /* Setup /virtual-memory:reg property */ + virtregsize = ((phys_addr_t)((ucell)-1) + 1) / 2; + + virtreg = malloc(6 * sizeof(ucell)); + ofmem_arch_encode_physaddr(virtreg, 0); + virtreg[2] = virtregsize; + ofmem_arch_encode_physaddr(&virtreg[3], virtregsize); + virtreg[5] = virtregsize; + + push_str("/virtual-memory"); + fword("find-device"); + PUSH(pointer2cell(virtreg)); + PUSH(6 * sizeof(ucell)); + push_str("reg"); + PUSH_ph(s_phandle_mmu); + fword("encode-property"); + + PUSH(0); + fword("active-package!"); + bind_func("pgmap@", pgmap_fetch); + bind_func("pgmap!", pgmap_store); + bind_func("map-pages", ob_map_pages); + + /* Install data fault handler words for cpeek etc. */ + PUSH_xt(bind_noname_func(srmmu_get_sfsr)); + feval("to sfsr@"); + PUSH_xt(bind_noname_func(ignore_dfault_addr)); + feval("to ignore-dfault"); +} + +/* + * Switch page tables. + */ +void +init_mmu_swift(void) +{ + unsigned int addr, i; + unsigned long pa, va; + int size; + + ofmem_posix_memalign((void *)&context_table, NCTX_SWIFT * sizeof(int), + NCTX_SWIFT * sizeof(int)); + ofmem_posix_memalign((void *)&l1, 256 * sizeof(int), 256 * sizeof(int)); + + context_table[0] = (((unsigned long)va2pa((unsigned long)l1)) >> 4) | + SRMMU_ET_PTD; + + for (i = 1; i < NCTX_SWIFT; i++) { + context_table[i] = SRMMU_ET_INVALID; + } + for (i = 0; i < 256; i++) { + l1[i] = SRMMU_ET_INVALID; + } + + // text, rodata, data, and bss mapped to end of RAM + va = (unsigned long)&_start; + size = (unsigned long)&_end - (unsigned long)&_start; + pa = va2pa(va); + ofmem_arch_map_pages(pa, va, size, ofmem_arch_default_translation_mode(pa)); + ofmem_map_page_range(pa, va, size, ofmem_arch_default_translation_mode(pa)); + + // 1:1 mapping for RAM (don't map page 0 to allow catching of NULL dereferences) + ofmem_arch_map_pages(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0)); + ofmem_map_page_range(PAGE_SIZE, PAGE_SIZE, LOWMEMSZ - PAGE_SIZE, ofmem_arch_default_translation_mode(0)); + + /* + * Flush cache + */ + for (addr = 0; addr < 0x2000; addr += 0x10) { + __asm__ __volatile__ ("sta %%g0, [%0] %1\n\t" : : + "r" (addr), "i" (ASI_M_DATAC_TAG)); + __asm__ __volatile__ ("sta %%g0, [%0] %1\n\t" : : + "r" (addr<<1), "i" (ASI_M_TXTC_TAG)); + } + srmmu_set_context(0); + srmmu_set_ctable_ptr(va2pa((unsigned long)context_table)); + srmmu_flush_whole_tlb(); +} diff --git a/qemu/roms/openbios/arch/sparc32/linux_load.c b/qemu/roms/openbios/arch/sparc32/linux_load.c new file mode 100644 index 000000000..26f7fc6bb --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/linux_load.c @@ -0,0 +1,648 @@ +/* + * Linux/i386 loader + * Supports bzImage, zImage and Image format. + * + * Based on work by Steve Gehlbach. + * Portions are taken from mkelfImage. + * + * 2003-09 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "libc/diskio.h" +#include "boot.h" + +#define printf printk +#define debug printk +#define strtoull_with_suffix strtol + +#define LINUX_PARAM_LOC 0x90000 +#define COMMAND_LINE_LOC 0x91000 +#define GDT_LOC 0x92000 +#define STACK_LOC 0x93000 + +#define E820MAX 32 /* number of entries in E820MAP */ +struct e820entry { + unsigned long long addr; /* start of memory segment */ + unsigned long long size; /* size of memory segment */ + unsigned long type; /* type of memory segment */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */ +#define E820_NVS 4 +}; + +/* The header of Linux/i386 kernel */ +struct linux_header { + uint8_t reserved1[0x1f1]; /* 0x000 */ + uint8_t setup_sects; /* 0x1f1 */ + uint16_t root_flags; /* 0x1f2 */ + uint8_t reserved2[6]; /* 0x1f4 */ + uint16_t vid_mode; /* 0x1fa */ + uint16_t root_dev; /* 0x1fc */ + uint16_t boot_sector_magic; /* 0x1fe */ + /* 2.00+ */ + uint8_t reserved3[2]; /* 0x200 */ + uint8_t header_magic[4]; /* 0x202 */ + uint16_t protocol_version; /* 0x206 */ + uint32_t realmode_swtch; /* 0x208 */ + uint16_t start_sys; /* 0x20c */ + uint16_t kver_addr; /* 0x20e */ + uint8_t type_of_loader; /* 0x210 */ + uint8_t loadflags; /* 0x211 */ + uint16_t setup_move_size; /* 0x212 */ + uint32_t code32_start; /* 0x214 */ + uint32_t ramdisk_image; /* 0x218 */ + uint32_t ramdisk_size; /* 0x21c */ + uint8_t reserved4[4]; /* 0x220 */ + /* 2.01+ */ + uint16_t heap_end_ptr; /* 0x224 */ + uint8_t reserved5[2]; /* 0x226 */ + /* 2.02+ */ + uint32_t cmd_line_ptr; /* 0x228 */ + /* 2.03+ */ + uint32_t initrd_addr_max; /* 0x22c */ +} __attribute__ ((packed)); + + +/* Paramters passed to 32-bit part of Linux + * This is another view of the structure above.. */ +struct linux_params { + uint8_t orig_x; /* 0x00 */ + uint8_t orig_y; /* 0x01 */ + uint16_t ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */ + uint16_t orig_video_page; /* 0x04 */ + uint8_t orig_video_mode; /* 0x06 */ + uint8_t orig_video_cols; /* 0x07 */ + uint16_t unused2; /* 0x08 */ + uint16_t orig_video_ega_bx; /* 0x0a */ + uint16_t unused3; /* 0x0c */ + uint8_t orig_video_lines; /* 0x0e */ + uint8_t orig_video_isVGA; /* 0x0f */ + uint16_t orig_video_points; /* 0x10 */ + + /* VESA graphic mode -- linear frame buffer */ + uint16_t lfb_width; /* 0x12 */ + uint16_t lfb_height; /* 0x14 */ + uint16_t lfb_depth; /* 0x16 */ + uint32_t lfb_base; /* 0x18 */ + uint32_t lfb_size; /* 0x1c */ + uint16_t cl_magic; /* 0x20 */ +#define CL_MAGIC_VALUE 0xA33F + uint16_t cl_offset; /* 0x22 */ + uint16_t lfb_linelength; /* 0x24 */ + uint8_t red_size; /* 0x26 */ + uint8_t red_pos; /* 0x27 */ + uint8_t green_size; /* 0x28 */ + uint8_t green_pos; /* 0x29 */ + uint8_t blue_size; /* 0x2a */ + uint8_t blue_pos; /* 0x2b */ + uint8_t rsvd_size; /* 0x2c */ + uint8_t rsvd_pos; /* 0x2d */ + uint16_t vesapm_seg; /* 0x2e */ + uint16_t vesapm_off; /* 0x30 */ + uint16_t pages; /* 0x32 */ + uint8_t reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */ + + //struct apm_bios_info apm_bios_info; /* 0x40 */ + uint8_t apm_bios_info[0x40]; + //struct drive_info_struct drive_info; /* 0x80 */ + uint8_t drive_info[0x20]; + //struct sys_desc_table sys_desc_table; /* 0xa0 */ + uint8_t sys_desc_table[0x140]; + uint32_t alt_mem_k; /* 0x1e0 */ + uint8_t reserved5[4]; /* 0x1e4 */ + uint8_t e820_map_nr; /* 0x1e8 */ + uint8_t reserved6[9]; /* 0x1e9 */ + uint16_t mount_root_rdonly; /* 0x1f2 */ + uint8_t reserved7[4]; /* 0x1f4 */ + uint16_t ramdisk_flags; /* 0x1f8 */ +#define RAMDISK_IMAGE_START_MASK 0x07FF +#define RAMDISK_PROMPT_FLAG 0x8000 +#define RAMDISK_LOAD_FLAG 0x4000 + uint8_t reserved8[2]; /* 0x1fa */ + uint16_t orig_root_dev; /* 0x1fc */ + uint8_t reserved9[1]; /* 0x1fe */ + uint8_t aux_device_info; /* 0x1ff */ + uint8_t reserved10[2]; /* 0x200 */ + uint8_t param_block_signature[4]; /* 0x202 */ + uint16_t param_block_version; /* 0x206 */ + uint8_t reserved11[8]; /* 0x208 */ + uint8_t loader_type; /* 0x210 */ +#define LOADER_TYPE_LOADLIN 1 +#define LOADER_TYPE_BOOTSECT_LOADER 2 +#define LOADER_TYPE_SYSLINUX 3 +#define LOADER_TYPE_ETHERBOOT 4 +#define LOADER_TYPE_KERNEL 5 + uint8_t loader_flags; /* 0x211 */ + uint8_t reserved12[2]; /* 0x212 */ + uint32_t kernel_start; /* 0x214 */ + uint32_t initrd_start; /* 0x218 */ + uint32_t initrd_size; /* 0x21c */ + uint8_t reserved12_5[8]; /* 0x220 */ + uint32_t cmd_line_ptr; /* 0x228 */ + uint8_t reserved13[164]; /* 0x22c */ + struct e820entry e820_map[E820MAX]; /* 0x2d0 */ + uint8_t reserved16[688]; /* 0x550 */ +#define COMMAND_LINE_SIZE 256 + /* Command line is copied here by 32-bit i386/kernel/head.S. + * So I will follow the boot protocol, rather than putting it + * directly here. --ts1 */ + uint8_t command_line[COMMAND_LINE_SIZE]; /* 0x800 */ + uint8_t reserved17[1792]; /* 0x900 - 0x1000 */ +}; + +static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + long long fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} + +/* Load the first part the file and check if it's Linux */ +static uint32_t load_linux_header(struct linux_header *hdr) +{ + int load_high; + uint32_t kern_addr; + + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { + debug("Can't read Linux header\n"); + return 0; + } + if (hdr->boot_sector_magic != 0xaa55) { + debug("Not a Linux kernel image\n"); + return 0; + } + + /* Linux is found. Print some information */ + if (memcmp(hdr->header_magic, "HdrS", 4) != 0) { + /* This may be floppy disk image or something. + * Perform a simple (incomplete) sanity check. */ + if (hdr->setup_sects >= 16 + || file_size() - (hdr->setup_sects<<9) >= 512<<10) { + debug("This looks like a bootdisk image but not like Linux...\n"); + return 0; + } + + printf("Possible very old Linux"); + /* This kernel does not even have a protocol version. + * Force the value. */ + hdr->protocol_version = 0; /* pre-2.00 */ + } else + printf("Found Linux"); + if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { + char kver[256]; + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { + kver[255] = 0; + printf(" version %s", kver); + } + } + debug(" (protocol %#x)", hdr->protocol_version); + load_high = 0; + if (hdr->protocol_version >= 0x200) { + debug(" (loadflags %#x)", hdr->loadflags); + load_high = hdr->loadflags & 1; + } + if (load_high) { + printf(" bzImage"); + kern_addr = 0x100000; + } else { + printf(" zImage or Image"); + kern_addr = 0x1000; + } + printf(".\n"); + + return kern_addr; +} + +/* Set up parameters for 32-bit kernel */ +static void +init_linux_params(struct linux_params *params, struct linux_header *hdr) +{ + debug("Setting up paramters at %#lx\n", virt_to_phys(params)); + memset(params, 0, sizeof *params); + + /* Copy some useful values from header */ + params->mount_root_rdonly = hdr->root_flags; + params->orig_root_dev = hdr->root_dev; + + /* Video parameters. + * This assumes we have VGA in standard 80x25 text mode, + * just like our vga.c does. + * Cursor position is filled later to allow some more printf's. */ + params->orig_video_mode = 3; + params->orig_video_cols = 80; + params->orig_video_lines = 25; + params->orig_video_isVGA = 1; + params->orig_video_points = 16; + + params->loader_type = 0xff; /* Unregistered Linux loader */ +} + +/* Memory map */ +static void +set_memory_size(struct linux_params *params, struct sys_info *info) +{ + int i; + uint64_t end; + uint32_t ramtop = 0; + struct e820entry *linux_map; + struct memrange *filo_map; + + linux_map = params->e820_map; + filo_map = info->memrange; + for (i = 0; i < info->n_memranges; i++, linux_map++, filo_map++) { + if (i < E820MAX) { + /* Convert to BIOS e820 style */ + linux_map->addr = filo_map->base; + linux_map->size = filo_map->size; + linux_map->type = E820_RAM; + debug("%016Lx - %016Lx\n", linux_map->addr, + linux_map->addr + linux_map->size); + params->e820_map_nr = i+1; + } + + /* Find out top of RAM. XXX This ignores hole above 1MB */ + end = filo_map->base + filo_map->size; + if (end < (1ULL << 32)) { /* don't count memory above 4GB */ + if (end > ramtop) + ramtop = (uint32_t) end; + } + } + debug("ramtop=%#x\n", ramtop); + /* Size of memory above 1MB in KB */ + params->alt_mem_k = (ramtop - (1<<20)) >> 10; + /* old style, 64MB max */ + if (ramtop >= (64<<20)) + params->ext_mem_k = (63<<10); + else + params->ext_mem_k = params->alt_mem_k; + debug("ext_mem_k=%d, alt_mem_k=%d\n", params->ext_mem_k, params->alt_mem_k); +} + +/* + * Parse command line + * Some parameters, like initrd=<file>, are not passed to kernel, + * we are responsible to process them. + * Parameters for kernel are copied to kern_cmdline. Returns name of initrd. + */ +static char *parse_command_line(const char *orig_cmdline, char *kern_cmdline) +{ + const char *start, *sep, *end, *val; + char name[64]; + unsigned long len; + int k_len; + int to_kern; + char *initrd = NULL; + int toolong = 0; + + forced_memsize = 0; + + if (!orig_cmdline) { + *kern_cmdline = '\0'; + return NULL; + } + + k_len = 0; + debug("original command line: \"%s\"\n", orig_cmdline); + debug("kernel command line at %#lx\n", virt_to_phys(kern_cmdline)); + + start = orig_cmdline; + while (*start == ' ') + start++; + while (*start) { + end = strchr(start, ' '); + if (!end) + end = start + strlen(start); + sep = strchr(start, '='); + if (!sep || sep > end) + sep = end; + len = sep - start; + if (len >= sizeof(name)) + len = sizeof(name) - 1; + memcpy(name, start, len); + name[len] = 0; + + if (*sep == '=') { + val = sep + 1; + len = end - val; + } else { + val = NULL; + len = 0; + } + + /* Only initrd= and mem= are handled here. vga= is not, + * which I believe is a paramter to the realmode part of Linux, + * which we don't execute. */ + if (strcmp(name, "initrd") == 0) { + if (!val) + printf("Missing filename to initrd parameter\n"); + else { + initrd = malloc(len + 1); + memcpy(initrd, val, len); + initrd[len] = 0; + debug("initrd=%s\n", initrd); + } + /* Don't pass this to kernel */ + to_kern = 0; + } else if (strcmp(name, "mem") == 0) { + if (!val) + printf("Missing value for mem parameter\n"); + else { + forced_memsize = strtoull_with_suffix(val, (char**)&val, 0); + if (forced_memsize == 0) + printf("Invalid mem option, ignored\n"); + if (val != end) { + printf("Garbage after mem=<size>, ignored\n"); + forced_memsize = 0; + } + debug("mem=%Lu\n", forced_memsize); + } + /* mem= is for both loader and kernel */ + to_kern = 1; + } else + to_kern = 1; + + if (to_kern) { + /* Copy to kernel command line buffer */ + if (k_len != 0) + kern_cmdline[k_len++] = ' '; /* put separator */ + len = end - start; + if (k_len + len >= COMMAND_LINE_SIZE) { + len = COMMAND_LINE_SIZE - k_len - 1; + if (!toolong) { + printf("Kernel command line is too long; truncated to " + "%d bytes\n", COMMAND_LINE_SIZE-1); + toolong = 1; + } + } + memcpy(kern_cmdline + k_len, start, len); + k_len += len; + } + + start = end; + while (*start == ' ') + start++; + } + kern_cmdline[k_len] = 0; + debug("kernel command line (%d bytes): \"%s\"\n", k_len, kern_cmdline); + + return initrd; +} + +/* Set command line location */ +static void set_command_line_loc(struct linux_params *params, + struct linux_header *hdr) +{ + if (hdr->protocol_version >= 0x202) { + /* new style */ + params->cmd_line_ptr = COMMAND_LINE_LOC; + } else { + /* old style */ + params->cl_magic = CL_MAGIC_VALUE; + params->cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC; + } +} + +/* Load 32-bit part of kernel */ +static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) +{ + uint32_t kern_offset, kern_size; + + if (hdr->setup_sects == 0) + hdr->setup_sects = 4; + kern_offset = (hdr->setup_sects + 1) * 512; + seek_io(fd, kern_offset); + kern_size = file_size() - kern_offset; + debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as kernel; " + "specify the image size\n"); + return 0; + } +#endif + + printf("Loading kernel... "); + if ((uint32_t)read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { + printf("Can't read kernel\n"); + return 0; + } + printf("ok\n"); + + return kern_size; +} + +static int load_initrd(struct linux_header *hdr, uint32_t kern_end, + struct linux_params *params, const char *initrd_file) +{ + uint32_t max; + uint32_t start, end, size; + uint64_t forced; + + fd = open_io(initrd_file); + if (fd == -1) { + printf("Can't open initrd: %s\n", initrd_file); + return -1; + } + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as initrd; " + "specify the image size\n"); + return -1; + } +#endif + + size = file_size(); + + + /* Find out the kernel's restriction on how high the initrd can be + * placed */ + if (hdr->protocol_version >= 0x203) + max = hdr->initrd_addr_max; + else + max = 0x38000000; /* Hardcoded value for older kernels */ + + /* FILO itself is at the top of RAM. (relocated) + * So, try putting initrd just below us. */ + end = virt_to_phys(_start); + if (end > max) + end = max; + + /* If "mem=" option is given, we have to put the initrd within + * the specified range. */ + if (forced_memsize) { + forced = forced_memsize; + if (forced > max) + forced = max; + /* If the "mem=" is lower, it's easy */ + if (forced <= end) + end = forced; + else { + /* Otherwise, see if we can put it above us */ + if (virt_to_phys(_end) + size <= forced) + end = forced; /* Ok */ + } + } + + start = end - size; + start &= ~0xfff; /* page align */ + end = start + size; + + debug("start=%#x end=%#x\n", start, end); + + if (start < kern_end) { + printf("Initrd is too big to fit in memory\n"); + return -1; + } + + printf("Loading initrd... "); + if ((uint32_t)read_io(fd, phys_to_virt(start), size) != size) { + printf("Can't read initrd\n"); + return -1; + } + printf("ok\n"); + + params->initrd_start = start; + params->initrd_size = size; + + close_io(fd); + + return 0; +} + +static void hardware_setup(void) +{ + /* Disable nmi */ + outb(0x80, 0x70); + + /* Make sure any coprocessor is properly reset.. */ + outb(0, 0xf0); + outb(0, 0xf1); + + /* we're getting screwed again and again by this problem of the 8259. + * so we're going to leave this lying around for inclusion into + * crt0.S on an as-needed basis. + * + * well, that went ok, I hope. Now we have to reprogram the interrupts :-( + * we put them right after the intel-reserved hardware interrupts, at + * int 0x20-0x2F. There they won't mess up anything. Sadly IBM really + * messed this up with the original PC, and they haven't been able to + * rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, + * which is used for the internal hardware interrupts as well. We just + * have to reprogram the 8259's, and it isn't fun. + */ + + outb(0x11, 0x20); /* initialization sequence to 8259A-1 */ + outb(0x11, 0xA0); /* and to 8259A-2 */ + + outb(0x20, 0x21); /* start of hardware int's (0x20) */ + outb(0x28, 0xA1); /* start of hardware int's 2 (0x28) */ + + outb(0x04, 0x21); /* 8259-1 is master */ + outb(0x02, 0xA1); /* 8259-2 is slave */ + + outb(0x01, 0x21); /* 8086 mode for both */ + outb(0x01, 0xA1); + + outb(0xFF, 0xA1); /* mask off all interrupts for now */ + outb(0xFB, 0x21); /* mask all irq's but irq2 which is cascaded */ +} + +/* Start Linux */ +static int start_linux(uint32_t kern_addr) +{ + struct context *ctx; + //extern int cursor_x, cursor_y; + + ctx = init_context(phys_to_virt(STACK_LOC), 4096, 0); + + /* Entry point */ + ctx->pc = kern_addr; + ctx->npc = kern_addr + 4; + + debug("pc=%#x\n", kern_addr); + printf("Jumping to entry point...\n"); + +#ifdef VGA_CONSOLE + /* Update VGA cursor position. + * This must be here because the printf changes the value! */ + params->orig_x = cursor_x; + params->orig_y = cursor_y; +#endif + + /* Go... */ + ctx = switch_to(ctx); + + /* It's impossible but... */ + printf("Returned with o0=%#x\n", ctx->regs[REG_O0]); + + return ctx->regs[REG_O0]; +} + +int linux_load(struct sys_info *info, const char *file, const char *cmdline) +{ + struct linux_header hdr; + struct linux_params *params; + uint32_t kern_addr, kern_size; + char *initrd_file = NULL; + + fd = open_io(file); + if (fd == -1) { + return -1; + } + + kern_addr = load_linux_header(&hdr); + if (kern_addr == 0) { + close_io(fd); + return LOADER_NOT_SUPPORT; + } + + params = phys_to_virt(LINUX_PARAM_LOC); + init_linux_params(params, &hdr); + set_memory_size(params, info); + initrd_file = parse_command_line(cmdline, phys_to_virt(COMMAND_LINE_LOC)); + set_command_line_loc(params, &hdr); + + kern_size = load_linux_kernel(&hdr, kern_addr); + if (kern_size == 0) { + if (initrd_file) + free(initrd_file); + return -1; + } + + if (initrd_file) { + if (load_initrd(&hdr, kern_addr+kern_size, params, initrd_file) + != 0) { + free(initrd_file); + return -1; + } + free(initrd_file); + } + + hardware_setup(); + + start_linux(kern_addr); + return 0; +} diff --git a/qemu/roms/openbios/arch/sparc32/multiboot.c b/qemu/roms/openbios/arch/sparc32/multiboot.c new file mode 100644 index 000000000..8514ca0a4 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/multiboot.c @@ -0,0 +1,125 @@ +/* Support for Multiboot */ + +#include "config.h" +#include "asm/io.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +struct mbheader { + unsigned int magic, flags, checksum; +}; +const struct mbheader multiboot_header + __attribute__((section (".hdr"))) = +{ + MULTIBOOT_HEADER_MAGIC, + MULTIBOOT_HEADER_FLAGS, + -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) +}; + +/* Multiboot information structure, provided by loader to us */ + +struct multiboot_mmap { + unsigned entry_size; + unsigned base_lo, base_hi; + unsigned size_lo, size_hi; + unsigned type; +}; + +#define MULTIBOOT_MEM_VALID 0x01 +#define MULTIBOOT_BOOT_DEV_VALID 0x02 +#define MULTIBOOT_CMDLINE_VALID 0x04 +#define MULTIBOOT_MODS_VALID 0x08 +#define MULTIBOOT_AOUT_SYMS_VALID 0x10 +#define MULTIBOOT_ELF_SYMS_VALID 0x20 +#define MULTIBOOT_MMAP_VALID 0x40 + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + struct multiboot_info *mbinfo; + struct multiboot_mmap *mbmem; + unsigned mbcount, mbaddr; + unsigned int i; + struct memrange *mmap; + int mmap_count; + module_t *mod; + + if (info->boot_type != 0x2BADB002) + return; + + debug("Using Multiboot information at %#lx\n", info->boot_data); + + mbinfo = phys_to_virt(info->boot_data); + + if (mbinfo->mods_count != 1) { + printf("Multiboot: no dictionary\n"); + return; + } + + mod = (module_t *) mbinfo->mods_addr; + info->dict_start=(unsigned long *)mod->mod_start; + info->dict_end=(unsigned long *)mod->mod_end; + + if (mbinfo->flags & MULTIBOOT_MMAP_VALID) { + /* convert mmap records */ + mbmem = phys_to_virt(mbinfo->mmap_addr); + mbcount = mbinfo->mmap_length / (mbmem->entry_size + 4); + mmap = malloc(mbcount * sizeof(struct memrange)); + mmap_count = 0; + mbaddr = mbinfo->mmap_addr; + for (i = 0; i < mbcount; i++) { + mbmem = phys_to_virt(mbaddr); + debug("%08x%08x %08x%08x (%d)\n", + mbmem->base_hi, + mbmem->base_lo, + mbmem->size_hi, + mbmem->size_lo, + mbmem->type); + if (mbmem->type == 1) { /* Only normal RAM */ + mmap[mmap_count].base = mbmem->base_lo + + (((unsigned long long) mbmem->base_hi) << 32); + mmap[mmap_count].size = mbmem->size_lo + + (((unsigned long long) mbmem->size_hi) << 32); + mmap_count++; + } + mbaddr += mbmem->entry_size + 4; + if (mbaddr >= mbinfo->mmap_addr + mbinfo->mmap_length) + break; + } + /* simple sanity check - there should be at least 2 RAM segments + * (base 640k and extended) */ + if (mmap_count >= 2) + goto got_it; + + printf("Multiboot mmap is broken\n"); + free(mmap); + /* fall back to mem_lower/mem_upper */ + } + + if (mbinfo->flags & MULTIBOOT_MEM_VALID) { + /* use mem_lower and mem_upper */ + mmap_count = 2; + mmap = malloc(2 * sizeof(*mmap)); + mmap[0].base = 0; + mmap[0].size = mbinfo->mem_lower << 10; + mmap[1].base = 1 << 20; /* 1MB */ + mmap[1].size = mbinfo->mem_upper << 10; + goto got_it; + } + + printf("Can't get memory information from Multiboot\n"); + return; + +got_it: + info->memrange = mmap; + info->n_memranges = mmap_count; + + return; +} diff --git a/qemu/roms/openbios/arch/sparc32/multiboot.h b/qemu/roms/openbios/arch/sparc32/multiboot.h new file mode 100644 index 000000000..17cf202ec --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/multiboot.h @@ -0,0 +1,96 @@ +/* multiboot.h + * tag: header for multiboot + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* magic number for multiboot header */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* flags for multiboot header */ +#define MULTIBOOT_HEADER_FLAGS 0x00010003 + +/* magic number passed by multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (8KB). */ +#define STACK_SIZE 0x2000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* We don't want these declarations in boot.S */ + +/* multiboot header */ +typedef struct multiboot_header { + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* symbol table for a.out */ +typedef struct aout_symbol_table { + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* section header table for ELF */ +typedef struct elf_section_header_table { + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* multiboot information */ +typedef struct multiboot_info { + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* module structure */ +typedef struct module { + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map { + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +#endif /* ! ASM */ diff --git a/qemu/roms/openbios/arch/sparc32/ofmem_sparc32.c b/qemu/roms/openbios/arch/sparc32/ofmem_sparc32.c new file mode 100644 index 000000000..f7af75366 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/ofmem_sparc32.c @@ -0,0 +1,253 @@ +/* + * <ofmem_sparc32.c> + * + * OF Memory manager + * + * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "arch/sparc32/ofmem_sparc32.h" +#include "asm/asi.h" +#include "pgtsrmmu.h" + +#define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8)) + +#define MEMSIZE (256 * 1024) +static union { + char memory[MEMSIZE]; + ofmem_t ofmem; +} s_ofmem_data; + +#define OFMEM (&s_ofmem_data.ofmem) +#define TOP_OF_RAM (s_ofmem_data.memory + MEMSIZE) + +#define OFMEM_PHYS_RESERVED 0x1000000 + +translation_t **g_ofmem_translations = &s_ofmem_data.ofmem.trans; + +extern uint32_t qemu_mem_size; + +static inline size_t ALIGN_SIZE(size_t x, size_t a) +{ + return (x + a - 1) & ~(a-1); +} + +static ucell get_heap_top( void ) +{ + return (ucell)TOP_OF_RAM; +} + +ofmem_t* ofmem_arch_get_private(void) +{ + return OFMEM; +} + +void* ofmem_arch_get_malloc_base(void) +{ + return OF_MALLOC_BASE; +} + +ucell ofmem_arch_get_heap_top(void) +{ + return get_heap_top(); +} + +ucell ofmem_arch_get_virt_top(void) +{ + return (ucell)OFMEM_VIRT_TOP; +} + +ucell ofmem_arch_get_iomem_base(void) +{ + return pointer2cell(&_end); +} + +ucell ofmem_arch_get_iomem_top(void) +{ + return pointer2cell(&_iomem); +} + +retain_t *ofmem_arch_get_retained(void) +{ + /* Not used */ + return 0; +} + +int ofmem_arch_get_physaddr_cellsize(void) +{ + return 2; +} + +int ofmem_arch_encode_physaddr(ucell *p, phys_addr_t value) +{ + int n = 0; + + p[n++] = value >> 32; + p[n++] = value; + + return n; +} + +int ofmem_arch_get_translation_entry_size(void) +{ + /* Return size of a single MMU package translation property entry in cells */ + return 3; +} + +void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t) +{ + /* Generate translation property entry for SPARC. While there is no + formal documentation for this, both Linux kernel and OpenSolaris sources + expect a translation property entry to have the following layout: + + virtual address + length + mode + */ + + transentry[0] = t->virt; + transentry[1] = t->size; + transentry[2] = t->mode; +} + +/* Return the size of a memory available entry given the phandle in cells */ +int ofmem_arch_get_available_entry_size(phandle_t ph) +{ + return 1 + ofmem_arch_get_physaddr_cellsize(); +} + +/* Generate memory available property entry for Sparc32 */ +void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size) +{ + int i = 0; + + i += ofmem_arch_encode_physaddr(availentry, start); + availentry[i] = size; +} + +/* Unmap a set of pages */ +void ofmem_arch_unmap_pages(ucell virt, ucell size) +{ + unsigned long pa; + ucell i; + + for (i = 0; i < size; i += PAGE_SIZE) { + pa = find_pte(virt, 0); + *(uint32_t *)pa = 0; + virt += PAGE_SIZE; + } + + srmmu_flush_whole_tlb(); +} + +/* Map a set of pages */ +void ofmem_arch_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) +{ + unsigned long npages, off; + uint32_t pte; + unsigned long pa; + + off = phys & (PAGE_SIZE - 1); + npages = (off + (size - 1) + (PAGE_SIZE - 1)) / PAGE_SIZE; + phys &= ~(uint64_t)(PAGE_SIZE - 1); + + while (npages-- != 0) { + pa = find_pte(virt, 1); + + pte = SRMMU_ET_PTE | ((phys & PAGE_MASK) >> 4); + pte |= mode; + + *(uint32_t *)pa = pte; + + virt += PAGE_SIZE; + phys += PAGE_SIZE; + } +} + +/* Architecture-specific OFMEM helpers */ +unsigned long +find_pte(unsigned long va, int alloc) +{ + uint32_t pte; + void *p; + unsigned long pa; + int ret; + + pte = l1[(va >> SRMMU_PGDIR_SHIFT) & (SRMMU_PTRS_PER_PGD - 1)]; + if ((pte & SRMMU_ET_MASK) == SRMMU_ET_INVALID) { + if (alloc) { + ret = ofmem_posix_memalign(&p, SRMMU_PTRS_PER_PMD * sizeof(int), + SRMMU_PTRS_PER_PMD * sizeof(int)); + if (ret != 0) + return ret; + pte = SRMMU_ET_PTD | ((va2pa((unsigned long)p)) >> 4); + l1[(va >> SRMMU_PGDIR_SHIFT) & (SRMMU_PTRS_PER_PGD - 1)] = pte; + /* barrier() */ + } else { + return -1; + } + } + + pa = (pte & 0xFFFFFFF0) << 4; + pa += ((va >> SRMMU_PMD_SHIFT) & (SRMMU_PTRS_PER_PMD - 1)) << 2; + pte = *(uint32_t *)pa2va(pa); + if ((pte & SRMMU_ET_MASK) == SRMMU_ET_INVALID) { + if (alloc) { + ret = ofmem_posix_memalign(&p, SRMMU_PTRS_PER_PTE * sizeof(void *), + SRMMU_PTRS_PER_PTE * sizeof(void *)); + if (ret != 0) + return ret; + pte = SRMMU_ET_PTD | ((va2pa((unsigned int)p)) >> 4); + *(uint32_t *)pa2va(pa) = pte; + } else { + return -2; + } + } + + pa = (pte & 0xFFFFFFF0) << 4; + pa += ((va >> PAGE_SHIFT) & (SRMMU_PTRS_PER_PTE - 1)) << 2; + + return pa2va(pa); +} + +/************************************************************************/ +/* misc */ +/************************************************************************/ + +ucell ofmem_arch_default_translation_mode( phys_addr_t phys ) +{ + return SRMMU_REF | SRMMU_CACHE | SRMMU_PRIV; +} + +ucell ofmem_arch_io_translation_mode( phys_addr_t phys ) +{ + return SRMMU_REF | SRMMU_PRIV; +} + +/************************************************************************/ +/* init / cleanup */ +/************************************************************************/ + +void ofmem_init( void ) +{ + memset(&s_ofmem_data, 0, sizeof(s_ofmem_data)); + s_ofmem_data.ofmem.ramsize = qemu_mem_size; + + /* Mark the first page as non-free */ + ofmem_claim_virt(0, PAGE_SIZE, 0); + + /* Claim reserved physical addresses at top of RAM */ + ofmem_claim_phys(s_ofmem_data.ofmem.ramsize - OFMEM_PHYS_RESERVED, OFMEM_PHYS_RESERVED, 0); + + /* Claim OpenBIOS reserved space */ + ofmem_claim_virt(0xffd00000, 0x200000, 0); +} diff --git a/qemu/roms/openbios/arch/sparc32/openbios.c b/qemu/roms/openbios/arch/sparc32/openbios.c new file mode 100644 index 000000000..6f4ee454e --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/openbios.c @@ -0,0 +1,1005 @@ +/* tag: openbios forth environment, executable code + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "drivers/drivers.h" +#include "asm/types.h" +#include "dict.h" +#include "kernel/kernel.h" +#include "kernel/stack.h" +#include "arch/common/nvram.h" +#include "packages/nvram.h" +#include "../../drivers/timer.h" // XXX +#include "libopenbios/sys_info.h" +#include "openbios.h" +#include "boot.h" +#include "romvec.h" +#include "openprom.h" +#include "psr.h" +#include "libopenbios/video.h" +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h" +#include "arch/sparc32/ofmem_sparc32.h" + +#define MEMORY_SIZE (128*1024) /* 128K ram for hosted system */ +#define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" +#define FW_CFG_SUN4M_DEPTH (FW_CFG_ARCH_LOCAL + 0x00) + +int qemu_machine_type; + +struct hwdef { + uint64_t iommu_base, slavio_base; + uint64_t intctl_base, counter_base, nvram_base, ms_kb_base, serial_base; + unsigned long fd_offset, counter_offset, intr_offset; + unsigned long aux1_offset, aux2_offset; + uint64_t dma_base, esp_base, le_base; + uint64_t tcx_base; + int intr_ncpu; + int mid_offset; + int machine_id_low, machine_id_high; +}; + +static const struct hwdef hwdefs[] = { + /* SS-5 */ + { + .iommu_base = 0x10000000, + .tcx_base = 0x50000000, + .slavio_base = 0x71000000, + .ms_kb_base = 0x71000000, + .serial_base = 0x71100000, + .nvram_base = 0x71200000, + .fd_offset = 0x00400000, + .counter_offset = 0x00d00000, + .intr_offset = 0x00e00000, + .intr_ncpu = 1, + .aux1_offset = 0x00900000, + .aux2_offset = 0x00910000, + .dma_base = 0x78400000, + .esp_base = 0x78800000, + .le_base = 0x78c00000, + .mid_offset = 0, + .machine_id_low = 32, + .machine_id_high = 63, + }, + /* SS-10, SS-20 */ + { + .iommu_base = 0xfe0000000ULL, + .tcx_base = 0xe20000000ULL, + .slavio_base = 0xff1000000ULL, + .ms_kb_base = 0xff1000000ULL, + .serial_base = 0xff1100000ULL, + .nvram_base = 0xff1200000ULL, + .fd_offset = 0x00700000, // 0xff1700000ULL, + .counter_offset = 0x00300000, // 0xff1300000ULL, + .intr_offset = 0x00400000, // 0xff1400000ULL, + .intr_ncpu = 4, + .aux1_offset = 0x00800000, // 0xff1800000ULL, + .aux2_offset = 0x00a01000, // 0xff1a01000ULL, + .dma_base = 0xef0400000ULL, + .esp_base = 0xef0800000ULL, + .le_base = 0xef0c00000ULL, + .mid_offset = 8, + .machine_id_low = 64, + .machine_id_high = 65, + }, + /* SS-600MP */ + { + .iommu_base = 0xfe0000000ULL, + .tcx_base = 0xe20000000ULL, + .slavio_base = 0xff1000000ULL, + .ms_kb_base = 0xff1000000ULL, + .serial_base = 0xff1100000ULL, + .nvram_base = 0xff1200000ULL, + .fd_offset = -1, + .counter_offset = 0x00300000, // 0xff1300000ULL, + .intr_offset = 0x00400000, // 0xff1400000ULL, + .intr_ncpu = 4, + .aux1_offset = 0x00800000, // 0xff1800000ULL, + .aux2_offset = 0x00a01000, // 0xff1a01000ULL, XXX should not exist + .dma_base = 0xef0081000ULL, + .esp_base = 0xef0080000ULL, + .le_base = 0xef0060000ULL, + .mid_offset = 8, + .machine_id_low = 66, + .machine_id_high = 66, + }, +}; + +static const struct hwdef *hwdef; + +void setup_timers(void) +{ +} + +void udelay(unsigned int usecs) +{ +} + +void mdelay(unsigned int msecs) +{ +} + +static void mb86904_init(void) +{ + PUSH(32); + fword("encode-int"); + push_str("cache-line-size"); + fword("property"); + + PUSH(512); + fword("encode-int"); + push_str("cache-nlines"); + fword("property"); + + PUSH(0x23); + fword("encode-int"); + push_str("mask_rev"); + fword("property"); +} + +static void tms390z55_init(void) +{ + push_str(""); + fword("encode-string"); + push_str("ecache-parity?"); + fword("property"); + + push_str(""); + fword("encode-string"); + push_str("bfill?"); + fword("property"); + + push_str(""); + fword("encode-string"); + push_str("bcopy?"); + fword("property"); + + push_str(""); + fword("encode-string"); + push_str("cache-physical?"); + fword("property"); + + PUSH(0xf); + fword("encode-int"); + PUSH(0xf8fffffc); + fword("encode-int"); + fword("encode+"); + PUSH(4); + fword("encode-int"); + fword("encode+"); + + PUSH(0xf); + fword("encode-int"); + fword("encode+"); + PUSH(0xf8c00000); + fword("encode-int"); + fword("encode+"); + PUSH(0x1000); + fword("encode-int"); + fword("encode+"); + + PUSH(0xf); + fword("encode-int"); + fword("encode+"); + PUSH(0xf8000000); + fword("encode-int"); + fword("encode+"); + PUSH(0x1000); + fword("encode-int"); + fword("encode+"); + + PUSH(0xf); + fword("encode-int"); + fword("encode+"); + PUSH(0xf8800000); + fword("encode-int"); + fword("encode+"); + PUSH(0x1000); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); +} + +static void rt625_init(void) +{ + PUSH(32); + fword("encode-int"); + push_str("cache-line-size"); + fword("property"); + + PUSH(512); + fword("encode-int"); + push_str("cache-nlines"); + fword("property"); + +} + +static void bad_cpu_init(void) +{ + printk("This CPU is not supported yet, freezing.\n"); + for(;;); +} + +struct cpudef { + unsigned long iu_version; + const char *name; + int psr_impl, psr_vers, impl, vers; + int dcache_line_size, dcache_lines, dcache_assoc; + int icache_line_size, icache_lines, icache_assoc; + int ecache_line_size, ecache_lines, ecache_assoc; + int mmu_nctx; + void (*initfn)(void); +}; + +static const struct cpudef sparc_defs[] = { + { + .iu_version = 0x00 << 24, /* Impl 0, ver 0 */ + .name = "FMI,MB86900", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x04 << 24, /* Impl 0, ver 4 */ + .name = "FMI,MB86904", + .psr_impl = 0, + .psr_vers = 4, + .impl = 0, + .vers = 4, + .dcache_line_size = 0x10, + .dcache_lines = 0x200, + .dcache_assoc = 1, + .icache_line_size = 0x20, + .icache_lines = 0x200, + .icache_assoc = 1, + .ecache_line_size = 0x20, + .ecache_lines = 0x4000, + .ecache_assoc = 1, + .mmu_nctx = 0x100, + .initfn = mb86904_init, + }, + { + .iu_version = 0x05 << 24, /* Impl 0, ver 5 */ + .name = "FMI,MB86907", + .psr_impl = 0, + .psr_vers = 5, + .impl = 0, + .vers = 5, + .dcache_line_size = 0x20, + .dcache_lines = 0x200, + .dcache_assoc = 1, + .icache_line_size = 0x20, + .icache_lines = 0x200, + .icache_assoc = 1, + .ecache_line_size = 0x20, + .ecache_lines = 0x4000, + .ecache_assoc = 1, + .mmu_nctx = 0x100, + .initfn = mb86904_init, + }, + { + .iu_version = 0x10 << 24, /* Impl 1, ver 0 */ + .name = "LSI,L64811", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x11 << 24, /* Impl 1, ver 1 */ + .name = "CY,CY7C601", + .psr_impl = 1, + .psr_vers = 1, + .impl = 1, + .vers = 1, + .mmu_nctx = 0x10, + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x13 << 24, /* Impl 1, ver 3 */ + .name = "CY,CY7C611", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x40000000, + .name = "TI,TMS390Z55", + .psr_impl = 4, + .psr_vers = 0, + .impl = 0, + .vers = 4, + .dcache_line_size = 0x20, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x40, + .icache_lines = 0x40, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = tms390z55_init, + }, + { + .iu_version = 0x41000000, + .name = "TI,TMS390S10", + .psr_impl = 4, + .psr_vers = 1, + .impl = 4, + .vers = 1, + .dcache_line_size = 0x10, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x20, + .icache_lines = 0x80, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = tms390z55_init, + }, + { + .iu_version = 0x42000000, + .name = "TI,TMS390S10", + .psr_impl = 4, + .psr_vers = 2, + .impl = 4, + .vers = 2, + .dcache_line_size = 0x10, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x20, + .icache_lines = 0x80, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = tms390z55_init, + }, + { + .iu_version = 0x43000000, + .name = "TI,TMS390S10", + .psr_impl = 4, + .psr_vers = 3, + .impl = 4, + .vers = 3, + .dcache_line_size = 0x10, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x20, + .icache_lines = 0x80, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = tms390z55_init, + }, + { + .iu_version = 0x44000000, + .name = "TI,TMS390S10", + .psr_impl = 4, + .psr_vers = 4, + .impl = 4, + .vers = 4, + .dcache_line_size = 0x10, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x20, + .icache_lines = 0x80, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = tms390z55_init, + }, + { + .iu_version = 0x1e000000, + .name = "Ross,RT625", + .psr_impl = 1, + .psr_vers = 14, + .impl = 1, + .vers = 7, + .dcache_line_size = 0x20, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x40, + .icache_lines = 0x40, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = rt625_init, + }, + { + .iu_version = 0x1f000000, + .name = "Ross,RT620", + .psr_impl = 1, + .psr_vers = 15, + .impl = 1, + .vers = 7, + .dcache_line_size = 0x20, + .dcache_lines = 0x80, + .dcache_assoc = 4, + .icache_line_size = 0x40, + .icache_lines = 0x40, + .icache_assoc = 5, + .ecache_line_size = 0x20, + .ecache_lines = 0x8000, + .ecache_assoc = 1, + .mmu_nctx = 0x10000, + .initfn = rt625_init, + }, + { + .iu_version = 0x20000000, + .name = "BIT,B5010", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x50000000, + .name = "MC,MN10501", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0x90 << 24, /* Impl 9, ver 0 */ + .name = "Weitek,W8601", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0xf2000000, + .name = "GR,LEON2", + .initfn = bad_cpu_init, + }, + { + .iu_version = 0xf3000000, + .name = "GR,LEON3", + .initfn = bad_cpu_init, + }, +}; + +static const struct cpudef * +id_cpu(void) +{ + unsigned long iu_version; + unsigned int i; + + asm("rd %%psr, %0\n" + : "=r"(iu_version) :); + iu_version &= 0xff000000; + + for (i = 0; i < sizeof(sparc_defs)/sizeof(struct cpudef); i++) { + if (iu_version == sparc_defs[i].iu_version) + return &sparc_defs[i]; + } + printk("Unknown cpu (psr %lx), freezing!\n", iu_version); + for (;;); +} + +static void setup_cpu(int mid_offset) +{ + uint32_t temp; + unsigned int i; + const struct cpudef *cpu; + + // Add cpus + temp = fw_cfg_read_i32(FW_CFG_NB_CPUS); + + printk("CPUs: %x", temp); + cpu = id_cpu(); + printk(" x %s\n", cpu->name); + for (i = 0; i < temp; i++) { + push_str("/"); + fword("find-device"); + + fword("new-device"); + + push_str(cpu->name); + fword("device-name"); + + push_str("cpu"); + fword("device-type"); + + PUSH(cpu->psr_impl); + fword("encode-int"); + push_str("psr-implementation"); + fword("property"); + + PUSH(cpu->psr_vers); + fword("encode-int"); + push_str("psr-version"); + fword("property"); + + PUSH(cpu->impl); + fword("encode-int"); + push_str("implementation"); + fword("property"); + + PUSH(cpu->vers); + fword("encode-int"); + push_str("version"); + fword("property"); + + PUSH(4096); + fword("encode-int"); + push_str("page-size"); + fword("property"); + + PUSH(cpu->dcache_line_size); + fword("encode-int"); + push_str("dcache-line-size"); + fword("property"); + + PUSH(cpu->dcache_lines); + fword("encode-int"); + push_str("dcache-nlines"); + fword("property"); + + PUSH(cpu->dcache_assoc); + fword("encode-int"); + push_str("dcache-associativity"); + fword("property"); + + PUSH(cpu->icache_line_size); + fword("encode-int"); + push_str("icache-line-size"); + fword("property"); + + PUSH(cpu->icache_lines); + fword("encode-int"); + push_str("icache-nlines"); + fword("property"); + + PUSH(cpu->icache_assoc); + fword("encode-int"); + push_str("icache-associativity"); + fword("property"); + + PUSH(cpu->ecache_line_size); + fword("encode-int"); + push_str("ecache-line-size"); + fword("property"); + + PUSH(cpu->ecache_lines); + fword("encode-int"); + push_str("ecache-nlines"); + fword("property"); + + PUSH(cpu->ecache_assoc); + fword("encode-int"); + push_str("ecache-associativity"); + fword("property"); + + PUSH(2); + fword("encode-int"); + push_str("ncaches"); + fword("property"); + + PUSH(cpu->mmu_nctx); + fword("encode-int"); + push_str("mmu-nctx"); + fword("property"); + + PUSH(8); + fword("encode-int"); + push_str("sparc-version"); + fword("property"); + + push_str(""); + fword("encode-string"); + push_str("cache-coherence?"); + fword("property"); + + PUSH(i + mid_offset); + fword("encode-int"); + push_str("mid"); + fword("property"); + + cpu->initfn(); + + fword("finish-device"); + } +} + +static void dummy_mach_init(uint64_t base) +{ +} + +struct machdef { + uint16_t machine_id; + const char *banner_name; + const char *model; + const char *name; + void (*initfn)(uint64_t base); +}; + +static const struct machdef sun4m_defs[] = { + { + .machine_id = 32, + .banner_name = "SPARCstation 5", + .model = "SUNW,501-3059", + .name = "SUNW,SPARCstation-5", + .initfn = ss5_init, + }, + { + .machine_id = 33, + .banner_name = "SPARCstation Voyager", + .model = "SUNW,501-2581", + .name = "SUNW,SPARCstation-Voyager", + .initfn = dummy_mach_init, + }, + { + .machine_id = 34, + .banner_name = "SPARCstation LX", + .model = "SUNW,501-2031", + .name = "SUNW,SPARCstation-LX", + .initfn = dummy_mach_init, + }, + { + .machine_id = 35, + .banner_name = "SPARCstation 4", + .model = "SUNW,501-2572", + .name = "SUNW,SPARCstation-4", + .initfn = ss5_init, + }, + { + .machine_id = 36, + .banner_name = "SPARCstation Classic", + .model = "SUNW,501-2326", + .name = "SUNW,SPARCstation-Classic", + .initfn = dummy_mach_init, + }, + { + .machine_id = 37, + .banner_name = "Tadpole S3 GX", + .model = "S3", + .name = "Tadpole_S3GX", + .initfn = ss5_init, + }, + { + .machine_id = 64, + .banner_name = "SPARCstation 10 (1 X 390Z55)", + .model = "SUNW,S10,501-2365", + .name = "SUNW,SPARCstation-10", + .initfn = ob_eccmemctl_init, + }, + { + .machine_id = 65, + .banner_name = "SPARCstation 20 (1 X 390Z55)", + .model = "SUNW,S20,501-2324", + .name = "SUNW,SPARCstation-20", + .initfn = ob_eccmemctl_init, + }, + { + .machine_id = 66, + .banner_name = "SPARCsystem 600(1 X 390Z55)", + .model = NULL, + .name = "SUNW,SPARCsystem-600", + .initfn = ob_eccmemctl_init, + }, +}; + +static const struct machdef * +id_machine(uint16_t machine_id) +{ + unsigned int i; + + for (i = 0; i < sizeof(sun4m_defs)/sizeof(struct machdef); i++) { + if (machine_id == sun4m_defs[i].machine_id) + return &sun4m_defs[i]; + } + printk("Unknown machine (ID %d), freezing!\n", machine_id); + for (;;); +} + +static void setup_machine(uint64_t base) +{ + uint16_t machine_id; + const struct machdef *mach; + + machine_id = fw_cfg_read_i16(FW_CFG_MACHINE_ID); + mach = id_machine(machine_id); + + push_str("/"); + fword("find-device"); + push_str(mach->banner_name); + fword("encode-string"); + push_str("banner-name"); + fword("property"); + + if (mach->model) { + push_str(mach->model); + fword("encode-string"); + push_str("model"); + fword("property"); + } + push_str(mach->name); + fword("encode-string"); + push_str("name"); + fword("property"); + + mach->initfn(base); +} + +/* Add /uuid */ +static void setup_uuid(void) +{ + static uint8_t qemu_uuid[16]; + + fw_cfg_read(FW_CFG_UUID, (char *)qemu_uuid, 16); + + printk("UUID: " UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], + qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], + qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], + qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], + qemu_uuid[15]); + + push_str("/"); + fword("find-device"); + + PUSH((long)&qemu_uuid); + PUSH(16); + fword("encode-bytes"); + push_str("uuid"); + fword("property"); +} + +static void setup_stdio(void) +{ + char nographic; + const char *stdin, *stdout; + + fw_cfg_read(FW_CFG_NOGRAPHIC, &nographic, 1); + if (nographic) { + obp_stdin = PROMDEV_TTYA; + obp_stdout = PROMDEV_TTYA; + stdin = "ttya"; + stdout = "ttya"; + } else { + obp_stdin = PROMDEV_KBD; + obp_stdout = PROMDEV_SCREEN; + stdin = "keyboard"; + stdout = "screen"; + } + + push_str(stdin); + push_str("input-device"); + fword("$setenv"); + + push_str(stdout); + push_str("output-device"); + fword("$setenv"); + + obp_stdin_path = stdin; + obp_stdout_path = stdout; +} + +static void init_memory(void) +{ + phys_addr_t phys; + ucell virt; + + /* Claim the memory from OFMEM */ + phys = ofmem_claim_phys(-1, MEMORY_SIZE, PAGE_SIZE); + if (!phys) + printk("panic: not enough physical memory on host system.\n"); + + virt = ofmem_claim_virt(OF_CODE_START - MEMORY_SIZE, MEMORY_SIZE, 0); + if (!virt) + printk("panic: not enough virtual memory on host system.\n"); + + /* Generate the mapping (and lock translation into the TLBs) */ + ofmem_map(phys, virt, MEMORY_SIZE, ofmem_arch_default_translation_mode(phys)); + + /* we push start and end of memory to the stack + * so that it can be used by the forth word QUIT + * to initialize the memory allocator + */ + + PUSH(virt); + PUSH(virt + MEMORY_SIZE); +} + +static void +arch_init( void ) +{ + char *cmdline; + const char *kernel_cmdline; + uint32_t temp; + uint16_t machine_id; + char buf[256]; + unsigned long mem_size; + + fw_cfg_init(); + + fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); + buf[4] = '\0'; + + printk("Configuration device id %s", buf); + + temp = fw_cfg_read_i32(FW_CFG_ID); + machine_id = fw_cfg_read_i16(FW_CFG_MACHINE_ID); + + printk(" version %d machine id %d\n", temp, machine_id); + + if (temp != 1) { + printk("Incompatible configuration device version, freezing\n"); + for(;;); + } + + graphic_depth = fw_cfg_read_i16(FW_CFG_SUN4M_DEPTH); + + openbios_init(); + modules_init(); + ob_init_mmu(); + ob_init_iommu(hwdef->iommu_base); +#ifdef CONFIG_DRIVER_OBIO + mem_size = fw_cfg_read_i32(FW_CFG_RAM_SIZE); + ob_obio_init(hwdef->slavio_base, hwdef->fd_offset, + hwdef->counter_offset, hwdef->intr_offset, hwdef->intr_ncpu, + hwdef->aux1_offset, hwdef->aux2_offset, + mem_size); + + setup_machine(hwdef->slavio_base); + + nvconf_init(); +#endif +#ifdef CONFIG_DRIVER_SBUS +#ifdef CONFIG_DEBUG_CONSOLE_VIDEO + setup_video(); +#endif + ob_sbus_init(hwdef->iommu_base + 0x1000ULL, qemu_machine_type); +#endif + device_end(); + + setup_cpu(hwdef->mid_offset); + + setup_stdio(); + /* Initialiase openprom romvec */ + romvec = init_openprom(); + + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); + if (kernel_size) { + kernel_image = fw_cfg_read_i32(FW_CFG_KERNEL_ADDR); + + /* Mark the kernel memory as in use */ + ofmem_claim_phys(PAGE_ALIGN(kernel_image), PAGE_ALIGN(kernel_size), 0); + ofmem_claim_virt(PAGE_ALIGN(kernel_image), PAGE_ALIGN(kernel_size), 0); + } + + kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE); + if (kernel_cmdline) { + cmdline = strdup(kernel_cmdline); + obp_arg.argv[1] = cmdline; + } else { + cmdline = strdup(""); + } + qemu_cmdline = (uint32_t)cmdline; + + /* Setup nvram variables */ + push_str("/options"); + fword("find-device"); + push_str(cmdline); + fword("encode-string"); + push_str("boot-file"); + fword("property"); + + boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE); + + switch (boot_device) { + case 'a': + push_str("floppy"); + break; + case 'c': + push_str("disk"); + break; + default: + case 'd': + push_str("cdrom:d cdrom"); + break; + case 'n': + push_str("net"); + break; + } + + fword("encode-string"); + push_str("boot-device"); + fword("property"); + + device_end(); + + bind_func("platform-boot", boot ); + bind_func("(go)", go ); + + /* Set up other properties */ + push_str("/chosen"); + fword("find-device"); + + setup_uuid(); + + /* Enable interrupts */ + temp = get_psr(); + temp = (temp & ~PSR_PIL) | (13 << 8); /* Enable CPU timer interrupt (level 14) */ + put_psr(temp); +} + +extern struct _console_ops arch_console_ops; + +int openbios(void) +{ + unsigned int i; + + for (i = 0; i < sizeof(hwdefs) / sizeof(struct hwdef); i++) { + if (hwdefs[i].machine_id_low <= qemu_machine_type && + hwdefs[i].machine_id_high >= qemu_machine_type) { + hwdef = &hwdefs[i]; + break; + } + } + if (!hwdef) + for(;;); // Internal inconsistency, hang + +#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); +#endif + /* Make sure we setup OFMEM before the MMU as we need malloc() to setup page tables */ + ofmem_init(); + +#ifdef CONFIG_DRIVER_SBUS + init_mmu_swift(); +#endif +#ifdef CONFIG_DEBUG_CONSOLE +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + escc_uart_init(hwdef->serial_base | (CONFIG_SERIAL_PORT? 0ULL: 4ULL), + CONFIG_SERIAL_SPEED); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VIDEO + kbd_init(hwdef->ms_kb_base); +#endif +#endif + + collect_sys_info(&sys_info); + + dict = (unsigned char *)sys_info.dict_start; + dicthead = (cell)sys_info.dict_end; + last = sys_info.dict_last; + dictlimit = sys_info.dict_limit; + + forth_init(); + +#ifdef CONFIG_DEBUG_BOOT + printk("forth started.\n"); + printk("initializing memory..."); +#endif + + init_memory(); + +#ifdef CONFIG_DEBUG_BOOT + printk("done\n"); +#endif + + PUSH_xt( bind_noname_func(arch_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + + if (!PC) { + printk("panic: no dictionary entry point.\n"); + return -1; + } +#ifdef CONFIG_DEBUG_DICTIONARY + printk("done (%d bytes).\n", dicthead); + printk("Jumping to dictionary...\n"); +#endif + + enterforth((xt_t)PC); + + free(dict); + return 0; +} diff --git a/qemu/roms/openbios/arch/sparc32/openbios.h b/qemu/roms/openbios/arch/sparc32/openbios.h new file mode 100644 index 000000000..f7d47eab4 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/openbios.h @@ -0,0 +1,28 @@ +/* + * Creation Date: <2004/01/15 16:14:05 samuel> + * Time-stamp: <2004/01/15 16:14:05 samuel> + * + * <openbios.h> + * + * + * + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_OPENBIOS +#define _H_OPENBIOS + +int openbios(void); + +/* console.c */ +extern unsigned char *vmem; +#ifdef CONFIG_DEBUG_CONSOLE +extern void video_init(void); +#endif + +#endif /* _H_OPENBIOS */ diff --git a/qemu/roms/openbios/arch/sparc32/openprom.h b/qemu/roms/openbios/arch/sparc32/openprom.h new file mode 100644 index 000000000..0676be843 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/openprom.h @@ -0,0 +1,260 @@ +#ifndef __SPARC_OPENPROM_H +#define __SPARC_OPENPROM_H + +/* openprom.h: Prom structures and defines for access to the OPENBOOT + * prom routines and data areas. + * + * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) + */ + +// #include <asm/vaddrs.h> + +/* Empirical constants... */ +#define LINUX_OPPROM_MAGIC 0x10010407 + +#ifndef __ASSEMBLY__ +/* V0 prom device operations. */ +struct linux_dev_v0_funcs { + int (*v0_devopen)(char *device_str); + int (*v0_devclose)(int dev_desc); + int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf); + int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf); + int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf); + int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf); + int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf); + int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf); + int (*v0_seekdev)(int dev_desc, long logical_offst, int from); +}; + +/* V2 and later prom device operations. */ +struct linux_dev_v2_funcs { + int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */ + char * (*v2_dumb_mem_alloc)(char *va, unsigned sz); + void (*v2_dumb_mem_free)(char *va, unsigned sz); + + /* To map devices into virtual I/O space. */ + char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz); + void (*v2_dumb_munmap)(char *virta, unsigned size); + + int (*v2_dev_open)(char *devpath); + void (*v2_dev_close)(int d); + int (*v2_dev_read)(int d, char *buf, int nbytes); + int (*v2_dev_write)(int d, char *buf, int nbytes); + int (*v2_dev_seek)(int d, int hi, int lo); + + /* Never issued (multistage load support) */ + void (*v2_wheee2)(void); + void (*v2_wheee3)(void); +}; + +struct linux_mlist_v0 { + struct linux_mlist_v0 *theres_more; + char *start_adr; + unsigned num_bytes; +}; + +struct linux_mem_v0 { + struct linux_mlist_v0 * const *v0_totphys; + struct linux_mlist_v0 * const *v0_prommap; + struct linux_mlist_v0 * const *v0_available; /* What we can use */ +}; + +/* Arguments sent to the kernel from the boot prompt. */ +struct linux_arguments_v0 { + const char *argv[8]; + char args[100]; + char boot_dev[2]; + int boot_dev_ctrl; + int boot_dev_unit; + int dev_partition; + const char *kernel_file_name; + void *aieee1; /* XXX */ +}; + +/* V2 and up boot things. */ +struct linux_bootargs_v2 { + const char **bootpath; + const char **bootargs; + const int *fd_stdin; + const int *fd_stdout; +}; + +/* The top level PROM vector. */ +struct linux_romvec { + /* Version numbers. */ + unsigned int pv_magic_cookie; + unsigned int pv_romvers; + unsigned int pv_plugin_revision; + unsigned int pv_printrev; + + /* Version 0 memory descriptors. */ + struct linux_mem_v0 pv_v0mem; + + /* Node operations. */ + const struct linux_nodeops *pv_nodeops; + + char **pv_bootstr; + struct linux_dev_v0_funcs pv_v0devops; + + const char *pv_stdin; + const char *pv_stdout; +#define PROMDEV_KBD 0 /* input from keyboard */ +#define PROMDEV_SCREEN 0 /* output to screen */ +#define PROMDEV_TTYA 1 /* in/out to ttya */ +#define PROMDEV_TTYB 2 /* in/out to ttyb */ + + /* Blocking getchar/putchar. NOT REENTRANT! (grr) */ + int (*pv_getchar)(void); + void (*pv_putchar)(int ch); + + /* Non-blocking variants. */ + int (*pv_nbgetchar)(void); + int (*pv_nbputchar)(int ch); + + void (*pv_putstr)(char *str, int len); + + /* Miscellany. */ + void (*pv_reboot)(char *bootstr); + void (*pv_printf)(__const__ char *fmt, ...); + void (*pv_abort)(void); + __volatile__ unsigned int *pv_ticks; + void (*pv_halt)(void); + void (**pv_synchook)(void); + + /* Evaluate a forth string, not different proto for V0 and V2->up. */ + union { + void (*v0_eval)(int len, char *str); + void (*v2_eval)(char *str, int arg0, int arg1, int arg2, int arg3, int arg4); + } pv_fortheval; + + const struct linux_arguments_v0 * const *pv_v0bootargs; + + /* Get ether address. */ + unsigned int (*pv_enaddr)(int d, char *enaddr); + + struct linux_bootargs_v2 pv_v2bootargs; + struct linux_dev_v2_funcs pv_v2devops; + + /* Prom version 3 memory allocation */ + char * (*v3_memalloc)(char *va, unsigned int size, unsigned int align); + + int filler[14]; + + /* This one is sun4c/sun4 only. */ + void (*pv_setctxt)(int ctxt, char *va, int pmeg); + + /* Prom version 3 Multiprocessor routines. This stuff is crazy. + * No joke. Calling these when there is only one cpu probably + * crashes the machine, have to test this. :-) + */ + + /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context + * 'thiscontext' executing at address 'prog_counter' + */ + int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr, + int thiscontext, char *prog_counter); + + /* v3_cpustop() will cause cpu 'whichcpu' to stop executing + * until a resume cpu call is made. + */ + int (*v3_cpustop)(unsigned int whichcpu); + + /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or + * resume cpu call is made. + */ + int (*v3_cpuidle)(unsigned int whichcpu); + + /* v3_cpuresume() will resume processor 'whichcpu' executing + * starting with whatever 'pc' and 'npc' were left at the + * last 'idle' or 'stop' call. + */ + int (*v3_cpuresume)(unsigned int whichcpu); +}; + +/* Routines for traversing the prom device tree. */ +struct linux_nodeops { + int (*no_nextnode)(int node); + int (*no_child)(int node); + int (*no_proplen)(int node, const char *name); + int (*no_getprop)(int node, const char *name, char *val); + int (*no_setprop)(int node, const char *name, char *val, int len); + const char * (*no_nextprop)(int node, const char *name); +}; + +/* More fun PROM structures for device probing. */ +#define PROMREG_MAX 16 +#define PROMVADDR_MAX 16 +#define PROMINTR_MAX 15 + +struct linux_prom_registers { + unsigned int which_io; /* is this in OBIO space? */ + unsigned int phys_addr; /* The physical address of this register */ + unsigned int reg_size; /* How many bytes does this register take up? */ +}; + +struct linux_prom_irqs { + int pri; /* IRQ priority */ + int vector; /* This is foobar, what does it do? */ +}; + +/* Element of the "ranges" vector */ +struct linux_prom_ranges { + unsigned int ot_child_space; + unsigned int ot_child_base; /* Bus feels this */ + unsigned int ot_parent_space; + unsigned int ot_parent_base; /* CPU looks from here */ + unsigned int or_size; +}; + +/* Ranges and reg properties are a bit different for PCI. */ +struct linux_prom_pci_registers { + /* + * We don't know what information this field contain. + * We guess, PCI device function is in bits 15:8 + * So, ... + */ + unsigned int which_io; /* Let it be which_io */ + + unsigned int phys_hi; + unsigned int phys_lo; + + unsigned int size_hi; + unsigned int size_lo; +}; + +struct linux_prom_pci_ranges { + unsigned int child_phys_hi; /* Only certain bits are encoded here. */ + unsigned int child_phys_mid; + unsigned int child_phys_lo; + + unsigned int parent_phys_hi; + unsigned int parent_phys_lo; + + unsigned int size_hi; + unsigned int size_lo; +}; + +struct linux_prom_pci_assigned_addresses { + unsigned int which_io; + + unsigned int phys_hi; + unsigned int phys_lo; + + unsigned int size_hi; + unsigned int size_lo; +}; + +struct linux_prom_ebus_ranges { + unsigned int child_phys_hi; + unsigned int child_phys_lo; + + unsigned int parent_phys_hi; + unsigned int parent_phys_mid; + unsigned int parent_phys_lo; + + unsigned int size; +}; + +#endif /* !(__ASSEMBLY__) */ + +#endif /* !(__SPARC_OPENPROM_H) */ diff --git a/qemu/roms/openbios/arch/sparc32/pgtsrmmu.h b/qemu/roms/openbios/arch/sparc32/pgtsrmmu.h new file mode 100644 index 000000000..64dbaa657 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/pgtsrmmu.h @@ -0,0 +1,223 @@ +/* + * Taken from kernel for decoupling from <asm/page.h>. --zaitcev + * + * $Id: pgtsrmmu.h,v 1.2 1999/04/19 01:04:31 zaitcev Exp $ + * pgtsrmmu.h: SRMMU page table defines and code. + * + * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) + */ + +#ifndef _PGTSRMMU_H +#define _PGTSRMMU_H + +/* PMD_SHIFT determines the size of the area a second-level page table can map */ +#define SRMMU_PMD_SHIFT 18 +#define SRMMU_PMD_SIZE (1UL << SRMMU_PMD_SHIFT) +#define SRMMU_PMD_MASK (~(SRMMU_PMD_SIZE-1)) +#define SRMMU_PMD_ALIGN(addr) (((addr)+SRMMU_PMD_SIZE-1)&SRMMU_PMD_MASK) + +/* PGDIR_SHIFT determines what a third-level page table entry can map */ +#define SRMMU_PGDIR_SHIFT 24 +#define SRMMU_PGDIR_SIZE (1UL << SRMMU_PGDIR_SHIFT) +#define SRMMU_PGDIR_MASK (~(SRMMU_PGDIR_SIZE-1)) +#define SRMMU_PGDIR_ALIGN(addr) (((addr)+SRMMU_PGDIR_SIZE-1)&SRMMU_PGDIR_MASK) + +#define SRMMU_PTRS_PER_PTE 64 +#define SRMMU_PTRS_PER_PMD 64 +#define SRMMU_PTRS_PER_PGD 256 + +#define SRMMU_PTE_TABLE_SIZE 0x100 /* 64 entries, 4 bytes a piece */ +#define SRMMU_PMD_TABLE_SIZE 0x100 /* 64 entries, 4 bytes a piece */ +#define SRMMU_PGD_TABLE_SIZE 0x400 /* 256 entries, 4 bytes a piece */ + +#define SRMMU_VMALLOC_START (0xfe300000) +#define SRMMU_VMALLOC_END ~0x0UL + +/* Definition of the values in the ET field of PTD's and PTE's */ +#define SRMMU_ET_MASK 0x3 +#define SRMMU_ET_INVALID 0x0 +#define SRMMU_ET_PTD 0x1 +#define SRMMU_ET_PTE 0x2 +#define SRMMU_ET_REPTE 0x3 /* AIEEE, SuperSparc II reverse endian page! */ + +/* Physical page extraction from PTP's and PTE's. */ +#define SRMMU_CTX_PMASK 0xfffffff0 +#define SRMMU_PTD_PMASK 0xfffffff0 +#define SRMMU_PTE_PMASK 0xffffff00 + +/* The pte non-page bits. Some notes: + * 1) cache, dirty, valid, and ref are frobbable + * for both supervisor and user pages. + * 2) exec and write will only give the desired effect + * on user pages + * 3) use priv and priv_readonly for changing the + * characteristics of supervisor ptes + */ +#define SRMMU_CACHE 0x80 +#define SRMMU_DIRTY 0x40 +#define SRMMU_REF 0x20 +#define SRMMU_EXEC 0x08 +#define SRMMU_WRITE 0x04 +#define SRMMU_VALID 0x02 /* SRMMU_ET_PTE */ +#define SRMMU_PRIV 0x1c +#define SRMMU_PRIV_RDONLY 0x18 + +#define SRMMU_CHG_MASK (0xffffff00 | SRMMU_REF | SRMMU_DIRTY) + +/* SRMMU Register addresses in ASI 0x4. These are valid for all + * current SRMMU implementations that exist. + */ +#define SRMMU_CTRL_REG 0x00000000 +#define SRMMU_CTXTBL_PTR 0x00000100 +#define SRMMU_CTX_REG 0x00000200 +#define SRMMU_FAULT_STATUS 0x00000300 +#define SRMMU_FAULT_ADDR 0x00000400 + +#ifndef __ASSEMBLY__ + +/* Accessing the MMU control register. */ +static __inline__ unsigned int srmmu_get_mmureg(void) +{ + unsigned int retval; + __asm__ __volatile__("lda [%%g0] %1, %0\n\t" : + "=r" (retval) : + "i" (ASI_M_MMUREGS)); + return retval; +} + +static __inline__ void srmmu_set_mmureg(unsigned long regval) +{ + __asm__ __volatile__("sta %0, [%%g0] %1\n\t" : : + "r" (regval), "i" (ASI_M_MMUREGS) : "memory"); + +} + +static __inline__ void srmmu_set_ctable_ptr(unsigned long paddr) +{ + paddr = ((paddr >> 4) & SRMMU_CTX_PMASK); + __asm__ __volatile__("sta %0, [%1] %2\n\t" : : + "r" (paddr), "r" (SRMMU_CTXTBL_PTR), + "i" (ASI_M_MMUREGS) : + "memory"); +} + +static __inline__ unsigned long srmmu_get_ctable_ptr(void) +{ + unsigned int retval; + + __asm__ __volatile__("lda [%1] %2, %0\n\t" : + "=r" (retval) : + "r" (SRMMU_CTXTBL_PTR), + "i" (ASI_M_MMUREGS)); + return (retval & SRMMU_CTX_PMASK) << 4; +} + +static __inline__ void srmmu_set_context(int context) +{ + __asm__ __volatile__("sta %0, [%1] %2\n\t" : : + "r" (context), "r" (SRMMU_CTX_REG), + "i" (ASI_M_MMUREGS) : "memory"); +} + +static __inline__ int srmmu_get_context(void) +{ + register int retval; + __asm__ __volatile__("lda [%1] %2, %0\n\t" : + "=r" (retval) : + "r" (SRMMU_CTX_REG), + "i" (ASI_M_MMUREGS)); + return retval; +} + +static __inline__ unsigned int srmmu_get_fstatus(void) +{ + unsigned int retval; + + __asm__ __volatile__("lda [%1] %2, %0\n\t" : + "=r" (retval) : + "r" (SRMMU_FAULT_STATUS), "i" (ASI_M_MMUREGS)); + return retval; +} + +static __inline__ unsigned int srmmu_get_faddr(void) +{ + unsigned int retval; + + __asm__ __volatile__("lda [%1] %2, %0\n\t" : + "=r" (retval) : + "r" (SRMMU_FAULT_ADDR), "i" (ASI_M_MMUREGS)); + return retval; +} + +/* This is guaranteed on all SRMMU's. */ +static __inline__ void srmmu_flush_whole_tlb(void) +{ + __asm__ __volatile__("sta %%g0, [%0] %1\n\t": : + "r" (0x400), /* Flush entire TLB!! */ + "i" (ASI_M_FLUSH_PROBE) : "memory"); + +} + +/* These flush types are not available on all chips... */ +static __inline__ void srmmu_flush_tlb_ctx(void) +{ + __asm__ __volatile__("sta %%g0, [%0] %1\n\t": : + "r" (0x300), /* Flush TLB ctx.. */ + "i" (ASI_M_FLUSH_PROBE) : "memory"); + +} + +static __inline__ void srmmu_flush_tlb_region(unsigned long addr) +{ + addr &= SRMMU_PGDIR_MASK; + __asm__ __volatile__("sta %%g0, [%0] %1\n\t": : + "r" (addr | 0x200), /* Flush TLB region.. */ + "i" (ASI_M_FLUSH_PROBE) : "memory"); + +} + + +static __inline__ void srmmu_flush_tlb_segment(unsigned long addr) +{ + addr &= SRMMU_PMD_MASK; + __asm__ __volatile__("sta %%g0, [%0] %1\n\t": : + "r" (addr | 0x100), /* Flush TLB segment.. */ + "i" (ASI_M_FLUSH_PROBE) : "memory"); + +} + +static __inline__ void srmmu_flush_tlb_page(unsigned long page) +{ + page &= PAGE_MASK; + __asm__ __volatile__("sta %%g0, [%0] %1\n\t": : + "r" (page), /* Flush TLB page.. */ + "i" (ASI_M_FLUSH_PROBE) : "memory"); + +} + +static __inline__ unsigned long srmmu_hwprobe(unsigned long vaddr) +{ + unsigned long retval; + + vaddr &= PAGE_MASK; + __asm__ __volatile__("lda [%1] %2, %0\n\t" : + "=r" (retval) : + "r" (vaddr | 0x400), "i" (ASI_M_FLUSH_PROBE)); + + return retval; +} + +static __inline__ int +srmmu_get_pte (unsigned long addr) +{ + register unsigned long entry; + + __asm__ __volatile__("\n\tlda [%1] %2,%0\n\t" : + "=r" (entry): + "r" ((addr & 0xfffff000) | 0x400), "i" (ASI_M_FLUSH_PROBE)); + return entry; +} + +#endif /* !(__ASSEMBLY__) */ + +#endif /* !(_SPARC_PGTSRMMU_H) */ diff --git a/qemu/roms/openbios/arch/sparc32/plainboot.c b/qemu/roms/openbios/arch/sparc32/plainboot.c new file mode 100644 index 000000000..08dab2d12 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/plainboot.c @@ -0,0 +1,21 @@ +/* tag: openbios fixed address forth starter + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define FIXED_DICTSTART 0xfffe0000 +#define FIXED_DICTEND 0xfffeffff + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)FIXED_DICTSTART; + info->dict_end=(unsigned long *)FIXED_DICTEND; +} diff --git a/qemu/roms/openbios/arch/sparc32/psr.h b/qemu/roms/openbios/arch/sparc32/psr.h new file mode 100644 index 000000000..0f6cfabb5 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/psr.h @@ -0,0 +1,88 @@ +/* $Id: psr.h,v 1.1 2002/07/12 17:12:03 zaitcev Exp $ + * psr.h: This file holds the macros for masking off various parts of + * the processor status register on the Sparc. This is valid + * for Version 8. On the V9 this is renamed to the PSTATE + * register and its members are accessed as fields like + * PSTATE.PRIV for the current CPU privilege level. + * + * Copyright (C) 1994 David S. Miller (davem@caip.rutgers.edu) + */ + +#ifndef __LINUX_SPARC_PSR_H +#define __LINUX_SPARC_PSR_H + +/* The Sparc PSR fields are laid out as the following: + * + * ------------------------------------------------------------------------ + * | impl | vers | icc | resv | EC | EF | PIL | S | PS | ET | CWP | + * | 31-28 | 27-24 | 23-20 | 19-14 | 13 | 12 | 11-8 | 7 | 6 | 5 | 4-0 | + * ------------------------------------------------------------------------ + */ +#define PSR_CWP 0x0000001f /* current window pointer */ +#define PSR_ET 0x00000020 /* enable traps field */ +#define PSR_PS 0x00000040 /* previous privilege level */ +#define PSR_S 0x00000080 /* current privilege level */ +#define PSR_PIL 0x00000f00 /* processor interrupt level */ +#define PSR_EF 0x00001000 /* enable floating point */ +#define PSR_EC 0x00002000 /* enable co-processor */ +#define PSR_LE 0x00008000 /* SuperSparcII little-endian */ +#define PSR_ICC 0x00f00000 /* integer condition codes */ +#define PSR_C 0x00100000 /* carry bit */ +#define PSR_V 0x00200000 /* overflow bit */ +#define PSR_Z 0x00400000 /* zero bit */ +#define PSR_N 0x00800000 /* negative bit */ +#define PSR_VERS 0x0f000000 /* cpu-version field */ +#define PSR_IMPL 0xf0000000 /* cpu-implementation field */ + +#ifndef __ASSEMBLY +/* Get the %psr register. */ +static __inline__ unsigned int get_psr(void) +{ + unsigned int psr; + __asm__ __volatile__( + "rd %%psr, %0\n\t" + "nop\n\t" + "nop\n\t" + "nop\n\t" + : "=r" (psr) + : /* no inputs */ + : "memory"); + + return psr; +} + +static __inline__ void put_psr(unsigned int new_psr) +{ + __asm__ __volatile__( + "wr %0, 0x0, %%psr\n\t" + "nop\n\t" + "nop\n\t" + "nop\n\t" + : /* no outputs */ + : "r" (new_psr) + : "memory", "cc"); +} + +/* Get the %fsr register. Be careful, make sure the floating point + * enable bit is set in the %psr when you execute this or you will + * incur a trap. + */ + +static unsigned int fsr_storage; + +static __inline__ unsigned int get_fsr(void) +{ + unsigned int fsr = 0; + + __asm__ __volatile__( + "st %%fsr, %1\n\t" + "ld %1, %0\n\t" + : "=r" (fsr) + : "m" (fsr_storage)); + + return fsr; +} + +#endif /* !(__ASSEMBLY__) */ + +#endif /* !(__LINUX_SPARC_PSR_H) */ diff --git a/qemu/roms/openbios/arch/sparc32/romvec.c b/qemu/roms/openbios/arch/sparc32/romvec.c new file mode 100644 index 000000000..8757c28f2 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/romvec.c @@ -0,0 +1,524 @@ +/* + * PROM interface support + * Copyright 1996 The Australian National University. + * Copyright 1996 Fujitsu Laboratories Limited + * Copyright 1999 Pete A. Zaitcev + * This software may be distributed under the terms of the Gnu + * Public License version 2 or later + */ + +#include <stdarg.h> + +#include "openprom.h" +#include "config.h" +#include "libopenbios/bindings.h" +#include "drivers/drivers.h" +#include "libopenbios/sys_info.h" +#include "boot.h" +#include "romvec.h" + +#ifdef CONFIG_DEBUG_OBP +#define DPRINTF(fmt, args...) \ + do { printk(fmt , ##args); } while (0) +#else +#define DPRINTF(fmt, args...) +#endif + +char obp_stdin, obp_stdout; +const char *obp_stdin_path, *obp_stdout_path; + +struct linux_arguments_v0 obp_arg; +const char *bootpath; +static const struct linux_arguments_v0 * const obp_argp = &obp_arg; + +static void (*sync_hook)(void); + +static struct linux_romvec romvec0; + +static void doublewalk(__attribute__((unused)) unsigned int ptab1, + __attribute__((unused)) unsigned int va) +{ +} + +int obp_nextnode(int node) +{ + int peer; + + PUSH(node); + fword("peer"); + peer = POP(); + DPRINTF("obp_nextnode(0x%x) = 0x%x\n", node, peer); + + return peer; +} + +int obp_child(int node) +{ + int child; + + PUSH(node); + fword("child"); + child = POP(); + DPRINTF("obp_child(0x%x) = 0x%x\n", node, child); + + return child; +} + +int obp_proplen(int node, const char *name) +{ + int notfound; + + if (!node) { + DPRINTF("obp_proplen(0x0, %s) = -1\n", name); + return -1; + } + + push_str(name); + PUSH(node); + fword("get-package-property"); + notfound = POP(); + + if (notfound) { + DPRINTF("obp_proplen(0x%x, %s) (not found)\n", node, name); + + return -1; + } else { + int len; + + len = POP(); + (void) POP(); + DPRINTF("obp_proplen(0x%x, %s) = %d\n", node, name, len); + + return len; + } +} + +#ifdef CONFIG_DEBUG_OBP +static int looks_like_string(const char *str, int len) +{ + int i; + int ret = (str[len-1] == '\0'); + for (i = 0; i < len-1 && ret; i++) + { + int ch = str[i] & 0xFF; + if (ch < 0x20 || ch > 0x7F) + ret = 0; + } + return ret; +} +#endif + +int obp_getprop(int node, const char *name, char *value) +{ + int notfound, found; + int len; + const char *str; + + if (!node) { + DPRINTF("obp_getprop(0x0, %s) = -1\n", name); + return -1; + } + + if (!name) { + // NULL name means get first property + push_str(""); + PUSH(node); + fword("next-property"); + found = POP(); + if (found) { + len = POP(); + str = (char *) POP(); + DPRINTF("obp_getprop(0x%x, NULL) = %s\n", node, str); + + return (int)str; + } + DPRINTF("obp_getprop(0x%x, NULL) (not found)\n", node); + + return -1; + } else { + push_str(name); + PUSH(node); + fword("get-package-property"); + notfound = POP(); + } + if (notfound) { + DPRINTF("obp_getprop(0x%x, %s) (not found)\n", node, name); + + return -1; + } else { + len = POP(); + str = (char *) POP(); + if (len > 0) + memcpy(value, str, len); + else + str = "NULL"; + +#ifdef CONFIG_DEBUG_OBP + if (looks_like_string(str, len)) { + DPRINTF("obp_getprop(0x%x, %s) = %s\n", node, name, str); + } else { + int i; + DPRINTF("obp_getprop(0x%x, %s) = ", node, name); + for (i = 0; i < len; i++) { + DPRINTF("%02x%s", str[i] & 0xFF, + (len == 4 || i == len-1) ? "" : " "); + } + DPRINTF("\n"); + } +#endif + + return len; + } +} + +const char *obp_nextprop(int node, const char *name) +{ + int found; + + if (!name || *name == '\0') { + // NULL name means get first property + push_str(""); + name = "NULL"; + } else { + push_str(name); + } + PUSH(node); + fword("next-property"); + found = POP(); + if (!found) { + DPRINTF("obp_nextprop(0x%x, %s) (not found)\n", node, name); + + return ""; + } else { + char *str; + + POP(); /* len */ + str = (char *) POP(); + + DPRINTF("obp_nextprop(0x%x, %s) = %s\n", node, name, str); + + return str; + } +} + +int obp_setprop(__attribute__((unused)) int node, + __attribute__((unused)) const char *name, + __attribute__((unused)) char *value, + __attribute__((unused)) int len) +{ + DPRINTF("obp_setprop(0x%x, %s) = %s (%d)\n", node, name, value, len); + + return -1; +} + +static const struct linux_nodeops nodeops0 = { + obp_nextnode_handler, /* int (*no_nextnode)(int node); */ + obp_child_handler, /* int (*no_child)(int node); */ + obp_proplen_handler, /* int (*no_proplen)(int node, char *name); */ + obp_getprop_handler, /* int (*no_getprop)(int node,char *name,char *val); */ + obp_setprop_handler, /* int (*no_setprop)(int node, char *name, + char *val, int len); */ + obp_nextprop_handler /* char * (*no_nextprop)(int node, char *name); */ +}; + +int obp_nbgetchar(void) +{ + return getchar(); +} + +int obp_nbputchar(int ch) +{ + putchar(ch); + + return 0; +} + +void obp_putstr(char *str, int len) +{ + PUSH(pointer2cell(str)); + PUSH(len); + fword("type"); +} + +void obp_printf(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + printk(fmt, ap); + va_end(ap); +} + +void obp_reboot(char *str) +{ + printk("rebooting (%s)\n", str); + *reset_reg = 1; + printk("reboot failed\n"); + for (;;) {} +} + +void obp_abort(void) +{ + printk("abort, power off\n"); + *power_reg = 1; + printk("power off failed\n"); + for (;;) {} +} + +void obp_halt(void) +{ + printk("halt, power off\n"); + *power_reg = 1; + printk("power off failed\n"); + for (;;) {} +} + +int obp_devopen(char *str) +{ + int ret; + + push_str(str); + fword("open-dev"); + ret = POP(); + DPRINTF("obp_devopen(%s) = 0x%x\n", str, ret); + + return ret; +} + +int obp_devclose(int dev_desc) +{ + int ret = 1; + + PUSH(dev_desc); + fword("close-dev"); + + DPRINTF("obp_devclose(0x%x) = %d\n", dev_desc, ret); + + return ret; +} + +int obp_rdblkdev(int dev_desc, int num_blks, int offset, char *buf) +{ + int ret, hi, lo, bs; + + bs = 512; + hi = ((uint64_t)offset * bs) >> 32; + lo = ((uint64_t)offset * bs) & 0xffffffff; + + ret = obp_devseek(dev_desc, hi, lo); + + ret = obp_devread(dev_desc, buf, num_blks * bs) / bs; + + DPRINTF("obp_rdblkdev(fd 0x%x, num_blks %d, offset %d (hi %d lo %d), buf 0x%x) = %d\n", dev_desc, num_blks, offset, hi, lo, (int)buf, ret); + + return ret; +} + +int obp_devread(int dev_desc, char *buf, int nbytes) +{ + int ret; + + PUSH((int)buf); + PUSH(nbytes); + push_str("read"); + PUSH(dev_desc); + fword("$call-method"); + ret = POP(); + + DPRINTF("obp_devread(fd 0x%x, buf 0x%x, nbytes %d) = %d\n", dev_desc, (int)buf, nbytes, ret); + + return ret; +} + +int obp_devwrite(int dev_desc, char *buf, int nbytes) +{ +#ifdef CONFIG_DEBUG_OBP_DEVWRITE /* disabled, makes too much noise */ + int ret; +#endif + + PUSH((int)buf); + PUSH(nbytes); + push_str("write"); + PUSH(dev_desc); + fword("$call-method"); +#ifdef CONFIG_DEBUG_OBP_DEVWRITE + ret = POP(); + DPRINTF("obp_devwrite(fd 0x%x, buf %s, nbytes %d) = %d\n", dev_desc, buf, nbytes, ret); +#else + POP(); +#endif + + return nbytes; +} + +int obp_devseek(int dev_desc, int hi, int lo) +{ + int ret; + + PUSH(lo); + PUSH(hi); + push_str("seek"); + PUSH(dev_desc); + fword("$call-method"); + ret = POP(); + + DPRINTF("obp_devseek(fd 0x%x, hi %d, lo %d) = %d\n", dev_desc, hi, lo, ret); + + return ret; +} + +int obp_inst2pkg(int dev_desc) +{ + int ret; + + PUSH(dev_desc); + fword("ihandle>non-interposed-phandle"); + ret = POP(); + + DPRINTF("obp_inst2pkg(fd 0x%x) = 0x%x\n", dev_desc, ret); + + return ret; +} + +int obp_cpustart(__attribute__((unused))unsigned int whichcpu, + __attribute__((unused))int ctxtbl_ptr, + __attribute__((unused))int thiscontext, + __attribute__((unused))char *prog_counter) +{ + int cpu, found; + struct linux_prom_registers *smp_ctable = (void *)ctxtbl_ptr; + + DPRINTF("obp_cpustart: cpu %d, ctxptr 0x%x, ctx %d, pc 0x%x\n", whichcpu, + smp_ctable->phys_addr, thiscontext, (unsigned int)prog_counter); + + found = obp_getprop(whichcpu, "mid", (char *)&cpu); + if (found == -1) + return -1; + DPRINTF("cpu found, id %d -> cpu %d\n", whichcpu, cpu); + + return start_cpu((unsigned int)prog_counter, ((unsigned int)smp_ctable->phys_addr) >> 4, + thiscontext, cpu); +} + +int obp_cpustop(__attribute__((unused)) unsigned int whichcpu) +{ + DPRINTF("obp_cpustop: cpu %d\n", whichcpu); + + return 0; +} + +int obp_cpuidle(__attribute__((unused)) unsigned int whichcpu) +{ + DPRINTF("obp_cpuidle: cpu %d\n", whichcpu); + + return 0; +} + +int obp_cpuresume(__attribute__((unused)) unsigned int whichcpu) +{ + DPRINTF("obp_cpuresume: cpu %d\n", whichcpu); + + return 0; +} + +void obp_fortheval_v2(char *str, int arg0, int arg1, int arg2, int arg3, int arg4) +{ + int dstacktmp = 0; + + // It seems Solaris passes up to 5 arguments which should be pushed onto the Forth + // stack for execution. However the API doesn't provide for a way to specify the number + // of arguments actually being passed. Hence we preserve the state of the Forth stack + // before, push all the arguments, execute the Forth, then restore the stack to its + // previous state. This enables us to have a variable number of arguments and still + // preserve stack state between subsequent calls. + + // Preserve stack state + dstacktmp = dstackcnt; + + PUSH(arg4); + PUSH(arg3); + PUSH(arg2); + PUSH(arg1); + PUSH(arg0); + + DPRINTF("obp_fortheval_v2(%x %x %x %x %x %s)\n", arg4, arg3, arg2, arg1, arg0, str); + push_str(str); + fword("eval"); + + // Restore stack state + dstackcnt = dstacktmp; +} + +volatile uint32_t *obp_ticks; + +void * +init_openprom(void) +{ + /* Setup the openprom vector. Note that all functions should be invoked + via their handler (see call-romvec.S) which acts as a proxy to save + the globals and setup the stack correctly */ + + // Linux wants a R/W romvec table + romvec0.pv_magic_cookie = LINUX_OPPROM_MAGIC; + romvec0.pv_romvers = 3; + romvec0.pv_plugin_revision = 2; + romvec0.pv_printrev = 0x20019; + romvec0.pv_v0mem.v0_totphys = NULL; + romvec0.pv_v0mem.v0_prommap = NULL; + romvec0.pv_v0mem.v0_available = NULL; + romvec0.pv_nodeops = &nodeops0; + romvec0.pv_bootstr = (void *)doublewalk; + romvec0.pv_v0devops.v0_devopen = &obp_devopen_handler; + romvec0.pv_v0devops.v0_devclose = &obp_devclose_handler; + romvec0.pv_v0devops.v0_rdblkdev = &obp_rdblkdev_handler; + romvec0.pv_stdin = &obp_stdin; + romvec0.pv_stdout = &obp_stdout; + romvec0.pv_getchar = obp_nbgetchar_handler; + romvec0.pv_putchar = (void (*)(int))obp_nbputchar_handler; + romvec0.pv_nbgetchar = obp_nbgetchar_handler; + romvec0.pv_nbputchar = obp_nbputchar_handler; + romvec0.pv_putstr = obp_putstr_handler; + romvec0.pv_reboot = obp_reboot_handler; + romvec0.pv_printf = obp_printf_handler; + romvec0.pv_abort = obp_abort_handler; + + /* Point to the Forth obp-ticks variable and reset */ + fword("obp-ticks"); + obp_ticks = cell2pointer(POP()); + *obp_ticks = 0; + romvec0.pv_ticks = obp_ticks; + + romvec0.pv_halt = obp_halt_handler; + romvec0.pv_synchook = &sync_hook; + romvec0.pv_v0bootargs = &obp_argp; + romvec0.pv_fortheval.v2_eval = obp_fortheval_v2_handler; + romvec0.pv_v2devops.v2_inst2pkg = obp_inst2pkg_handler; + romvec0.pv_v2devops.v2_dumb_mem_alloc = obp_dumb_memalloc_handler; + romvec0.pv_v2devops.v2_dumb_mem_free = obp_dumb_memfree_handler; + romvec0.pv_v2devops.v2_dumb_mmap = obp_dumb_mmap_handler; + romvec0.pv_v2devops.v2_dumb_munmap = obp_dumb_munmap_handler; + romvec0.pv_v2devops.v2_dev_open = obp_devopen_handler; + romvec0.pv_v2devops.v2_dev_close = (void (*)(int))obp_devclose_handler; + romvec0.pv_v2devops.v2_dev_read = obp_devread_handler; + romvec0.pv_v2devops.v2_dev_write = obp_devwrite_handler; + romvec0.pv_v2devops.v2_dev_seek = obp_devseek_handler; + + romvec0.pv_v2bootargs.bootpath = &bootpath; + + romvec0.pv_v2bootargs.bootargs = &obp_arg.argv[1]; + + /* Point fd_stdin/fd_stdout to the Forth stdin/stdout variables */ + fword("stdin"); + romvec0.pv_v2bootargs.fd_stdin = cell2pointer(POP()); + fword("stdout"); + romvec0.pv_v2bootargs.fd_stdout = cell2pointer(POP()); + + romvec0.v3_memalloc = obp_memalloc_handler; + + romvec0.v3_cpustart = obp_cpustart_handler; + romvec0.v3_cpustop = obp_cpustop_handler; + romvec0.v3_cpuidle = obp_cpuidle_handler; + romvec0.v3_cpuresume = obp_cpuresume_handler; + + return &romvec0; +} diff --git a/qemu/roms/openbios/arch/sparc32/romvec.h b/qemu/roms/openbios/arch/sparc32/romvec.h new file mode 100644 index 000000000..4375f06f3 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/romvec.h @@ -0,0 +1,79 @@ +/* + * romvec main C function and handler declarations + */ + +extern volatile uint32_t *obp_ticks; +void *init_openprom(void); + +int obp_devopen(char *str); +int obp_devopen_handler(char *str); +int obp_devclose(int dev_desc); +int obp_devclose_handler(int dev_desc); +int obp_rdblkdev(int dev_desc, int num_blks, int offset, char *buf); +int obp_rdblkdev_handler(int dev_desc, int num_blks, int offset, char *buf); +int obp_nbgetchar(void); +int obp_nbgetchar_handler(void); +int obp_nbputchar(int ch); +int obp_nbputchar_handler(int ch); +void obp_putstr(char *str, int len); +void obp_putstr_handler(char *str, int len); +void obp_printf(__const__ char *fmt, ...); +void obp_printf_handler(__const__ char *fmt, ...); +void obp_reboot(char *str); +void obp_reboot_handler(char *str); +void obp_abort(void); +void obp_abort_handler(void); +void obp_halt(void); +void obp_halt_handler(void); +void obp_fortheval_v2(char *str, int arg0, int arg1, int arg2, int arg3, int arg4); +void obp_fortheval_v2_handler(char *str, int arg0, int arg1, int arg2, int arg3, int arg4); +int obp_inst2pkg(int dev_desc); +int obp_inst2pkg_handler(int dev_desc); +char *obp_dumb_memalloc(char *va, unsigned int size); +char *obp_dumb_memalloc_handler(char *va, unsigned int size); +void obp_dumb_memfree(char *va, unsigned size); +void obp_dumb_memfree_handler(char *va, unsigned size); +char *obp_dumb_mmap(char *va, int which_io, unsigned int pa, unsigned int size); +char *obp_dumb_mmap_handler(char *va, int which_io, unsigned int pa, unsigned int size); +void obp_dumb_munmap(__attribute__((unused)) char *va, __attribute__((unused)) unsigned int size); +void obp_dumb_munmap_handler(__attribute__((unused)) char *va, __attribute__((unused)) unsigned int size); +int obp_devread(int dev_desc, char *buf, int nbytes); +int obp_devread_handler(int dev_desc, char *buf, int nbytes); +int obp_devwrite(int dev_desc, char *buf, int nbytes); +int obp_devwrite_handler(int dev_desc, char *buf, int nbytes); +int obp_devseek(int dev_desc, int hi, int lo); +int obp_devseek_handler(int dev_desc, int hi, int lo); +int obp_cpustart(__attribute__((unused))unsigned int whichcpu, + __attribute__((unused))int ctxtbl_ptr, + __attribute__((unused))int thiscontext, + __attribute__((unused))char *prog_counter); +int obp_cpustart_handler(__attribute__((unused))unsigned int whichcpu, + __attribute__((unused))int ctxtbl_ptr, + __attribute__((unused))int thiscontext, + __attribute__((unused))char *prog_counter); +int obp_cpustop(__attribute__((unused)) unsigned int whichcpu); +int obp_cpustop_handler(__attribute__((unused)) unsigned int whichcpu); +int obp_cpuidle(__attribute__((unused)) unsigned int whichcpu); +int obp_cpuidle_handler(__attribute__((unused)) unsigned int whichcpu); +int obp_cpuresume(__attribute__((unused)) unsigned int whichcpu); +int obp_cpuresume_handler(__attribute__((unused)) unsigned int whichcpu); +int obp_nextnode(int node); +int obp_nextnode_handler(int node); +int obp_child(int node); +int obp_child_handler(int node); +int obp_proplen(int node, const char *name); +int obp_proplen_handler(int node, const char *name); +int obp_getprop(int node, const char *name, char *value); +int obp_getprop_handler(int node, const char *name, char *value); +int obp_setprop(__attribute__((unused)) int node, + __attribute__((unused)) const char *name, + __attribute__((unused)) char *value, + __attribute__((unused)) int len); +int obp_setprop_handler(__attribute__((unused)) int node, + __attribute__((unused)) const char *name, + __attribute__((unused)) char *value, + __attribute__((unused)) int len); +const char *obp_nextprop(int node, const char *name); +const char *obp_nextprop_handler(int node, const char *name); +char *obp_memalloc(char *va, unsigned int size, unsigned int align); +char *obp_memalloc_handler(char *va, unsigned int size, unsigned int align); diff --git a/qemu/roms/openbios/arch/sparc32/switch.S b/qemu/roms/openbios/arch/sparc32/switch.S new file mode 100644 index 000000000..d5b1b659d --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/switch.S @@ -0,0 +1,154 @@ +#define __ASSEMBLY +#include "psr.h" +#include "asm/asi.h" +#define ASI_BP ASI_M_BYPASS +#define REGWIN_SZ 0x40 + + .globl __switch_context, __switch_context_nosave, __exit_context, halt + + .text + .align 4 + +#define STACKFRAME_SZ 0x60 + +/* These are just handy. */ +#define _SV save %sp, -STACKFRAME_SZ, %sp +#define _RS restore + +#define FLUSH_ALL_KERNEL_WINDOWS \ + _SV; _SV; _SV; _SV; _SV; _SV; _SV; \ + _RS; _RS; _RS; _RS; _RS; _RS; _RS; + +/* + * Switch execution context + * This saves registers in the stack, then + * switches the stack, and restores everything from the new stack. + * This function takes no argument. New stack pointer is + * taken from global variable __context, and old stack pointer + * is also saved to __context. This way we can just jump to + * this routine to get back to the original context. + */ + +__switch_context: + FLUSH_ALL_KERNEL_WINDOWS + /* Save everything in stack */ + st %fp, [%fp + 120 -144] + add %fp, -144, %fp + st %g1, [%fp + 4] + st %g2, [%fp + 8] + st %g3, [%fp + 12] + st %g4, [%fp + 16] + st %g5, [%fp + 20] + st %g6, [%fp + 24] + st %g7, [%fp + 28] + + st %o0, [%fp + 32] + st %o1, [%fp + 36] + st %o2, [%fp + 40] + st %o3, [%fp + 44] + st %o4, [%fp + 48] + st %o5, [%fp + 52] + st %sp, [%fp + 56] + st %o7, [%fp + 60] + + st %l0, [%fp + 64] + st %l1, [%fp + 68] + st %l2, [%fp + 72] + st %l3, [%fp + 76] + st %l4, [%fp + 80] + st %l5, [%fp + 84] + st %l6, [%fp + 88] + st %l7, [%fp + 92] + + st %i0, [%fp + 96] + st %i1, [%fp + 100] + st %i2, [%fp + 104] + st %i3, [%fp + 108] + st %i4, [%fp + 112] + st %i5, [%fp + 116] + st %i7, [%fp + 124] + + /* ctx->return_address: Return to caller */ + st %o7, [%fp + 128] + + /* Interrupts are not allowed... */ + + /* Turn on Supervisor, EnableFloating, and all the PIL bits. + * Also puts us in register window zero with traps off. + */ +#if 0 + set (PSR_PS | PSR_S | PSR_PIL | PSR_EF), %g2 + wr %g2, 0x0, %psr +#endif + set __context, %g1 + /* Swap ctx pointer with %fp and jump*/ + ba __set_context + swap [%g1], %fp +__switch_context_nosave: + set __context, %g1 + /* load %fp from ctx pointer */ + ld [%g1], %fp +__set_context: + /* Load all registers */ + /* offset 0: %g0, no need to load */ + ld [%fp + 4], %g1 + ld [%fp + 8], %g2 + ld [%fp + 12], %g3 + ld [%fp + 16], %g4 + ld [%fp + 20], %g5 + ld [%fp + 24], %g6 + ld [%fp + 28], %g7 + + /* offset 32: %o0, loaded from ctx->param */ + ld [%fp + 36], %o1 + ld [%fp + 40], %o2 + ld [%fp + 44], %o3 + ld [%fp + 48], %o4 + ld [%fp + 52], %o5 + ld [%fp + 56], %sp + /* offset 60: %o7, loaded from ctx->return_addr */ + + ld [%fp + 64], %l0 + ld [%fp + 68], %l1 + ld [%fp + 72], %l2 + ld [%fp + 76], %l3 + ld [%fp + 80], %l4 + ld [%fp + 84], %l5 + ld [%fp + 88], %l6 + ld [%fp + 92], %l7 + + ld [%fp + 96], %i0 + ld [%fp + 100], %i1 + ld [%fp + 104], %i2 + ld [%fp + 108], %i3 + ld [%fp + 112], %i4 + ld [%fp + 116], %i5 + ld [%fp + 124], %i7 + + /* ctx->return_addr */ + ld [%fp + 136], %o7 + + /* ctx->param */ + ld [%fp + 140], %o0 + + /* ctx->pc, save %g1 to %y and load to %g1 */ + mov %g1, %y + ld [%fp + 128], %g1 + /* %fp last */ + ld [%fp + 120], %fp + /* Finally, get the new %pc from %g1 and restore %g1*/ + jmp %g1 + mov %y, %g1 + + FLUSH_ALL_KERNEL_WINDOWS +__exit_context: + /* Get back to the original context */ + call __switch_context + nop + + /* We get here if the other context attempt to switch to this + * dead context. This should not happen. */ + +halt: + b halt + nop diff --git a/qemu/roms/openbios/arch/sparc32/sys_info.c b/qemu/roms/openbios/arch/sparc32/sys_info.c new file mode 100644 index 000000000..719537d47 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/sys_info.c @@ -0,0 +1,58 @@ +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/elf_boot.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "boot.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +unsigned int qemu_mem_size; + +void collect_multiboot_info(struct sys_info *); + +void collect_sys_info(struct sys_info *info) +{ + int i; + unsigned long long total = 0; + struct memrange *mmap; + + /* Pick up paramters given by bootloader to us */ + //info->boot_type = boot_ctx->eax; + //info->boot_data = boot_ctx->ebx; + info->boot_arg = boot_ctx->param[0]; + //debug("boot eax = %#lx\n", info->boot_type); + //debug("boot ebx = %#lx\n", info->boot_data); + info->boot_type = ELF_BHDR_MAGIC; + info->boot_data = virt_to_phys(&elf_image_notes); + debug("boot arg = %#lx\n", info->boot_arg); + + collect_elfboot_info(info); +#ifdef CONFIG_LINUXBIOS + collect_linuxbios_info(info); +#endif +#ifdef CONFIG_IMAGE_ELF_MULTIBOOT + collect_multiboot_info(info); +#endif + + if (!info->memrange) { + info->n_memranges = 1; + info->memrange = malloc(1 * sizeof(struct memrange)); + info->memrange[0].base = 0; + info->memrange[0].size = qemu_mem_size; + } + + debug("\n"); + mmap=info->memrange; + for (i = 0; i < info->n_memranges; i++) { + debug("%08lx-", (long)mmap[i].base); + debug("%08lx\n", (long)mmap[i].base + (long)mmap[i].size); + total += mmap[i].size; + } + debug("RAM %ld MB\n", (long)total >> 20); +} diff --git a/qemu/roms/openbios/arch/sparc32/tree.fs b/qemu/roms/openbios/arch/sparc32/tree.fs new file mode 100644 index 000000000..c82bb1718 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/tree.fs @@ -0,0 +1,114 @@ +include config.fs + +" /" find-device + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + + " sun4m" encode-string " compatible" property + h# 0a21fe80 encode-int " clock-frequency" property + + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; + +new-device + " memory" device-name + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " virtual-memory" device-name + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " iommu" device-name + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + h# 1000 encode-int " page-size" property + 0 encode-int " cache-coherence?" property + external + : open ( cr ." opening iommu" cr) true ; + : close ; + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; +finish-device + +" /iommu" find-device +new-device + " sbus" device-name + " hierarchical" device-type + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + h# 01443fd0 encode-int " clock-frequency" property + h# 1c encode-int " slot-address-bits" property + h# 3f encode-int " burst-sizes" property + external + : open ( cr ." opening SBus" cr) true ; + : close ; + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; + : map-in map-in-sbus ; + : map-out map-out-sbus ; +finish-device + +[IFDEF] CONFIG_BPP +" /iommu/sbus" find-device +new-device + " SUNW,bpp" device-name + h# 4 encode-int h# 0c800000 encode-int encode+ h# 0000001c encode-int encode+ " reg" property + h# 33 encode-int 0 encode-int encode+ " intr" property +finish-device +[THEN] + +" /iommu/sbus" find-device +new-device + " espdma" device-name + external + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; +finish-device + +" /iommu/sbus" find-device +new-device + " ledma" device-name + h# 3f encode-int " burst-sizes" property + external + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; +finish-device + +" /iommu/sbus/ledma" find-device +new-device + " le" device-name + " network" device-type + h# 7 encode-int " busmaster-regval" property + h# 26 encode-int 0 encode-int encode+ " intr" property +finish-device + +\ obio (on-board IO) +" /" find-device +new-device + " obio" device-name + " hierarchical" device-type + 2 encode-int " #address-cells" property + 1 encode-int " #size-cells" property + external + : open ( cr ." opening obio" cr) true ; + : close ; + : encode-unit encode-unit-sbus ; + : decode-unit decode-unit-sbus ; +finish-device + +" /options" find-device + " disk" encode-string " boot-from" property + +" /openprom" find-device + 0 0 " aligned-allocator" property diff --git a/qemu/roms/openbios/arch/sparc32/udiv.S b/qemu/roms/openbios/arch/sparc32/udiv.S new file mode 100644 index 000000000..327534187 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/udiv.S @@ -0,0 +1,357 @@ +/* $Id: udiv.S,v 1.4 1996/09/30 02:22:38 davem Exp $ + * udiv.S: This routine was taken from glibc-1.09 and is covered + * by the GNU Library General Public License Version 2. + */ + + +/* This file is generated from divrem.m4; DO NOT EDIT! */ +/* + * Division and remainder, from Appendix E of the Sparc Version 8 + * Architecture Manual, with fixes from Gordon Irlam. + */ + +/* + * Input: dividend and divisor in %o0 and %o1 respectively. + * + * m4 parameters: + * .udiv name of function to generate + * div div=div => %o0 / %o1; div=rem => %o0 % %o1 + * false false=true => signed; false=false => unsigned + * + * Algorithm parameters: + * N how many bits per iteration we try to get (4) + * WORDSIZE total number of bits (32) + * + * Derived constants: + * TOPBITS number of bits in the top decade of a number + * + * Important variables: + * Q the partial quotient under development (initially 0) + * R the remainder so far, initially the dividend + * ITER number of main division loop iterations required; + * equal to ceil(log2(quotient) / N). Note that this + * is the log base (2^N) of the quotient. + * V the current comparand, initially divisor*2^(ITER*N-1) + * + * Cost: + * Current estimate for non-large dividend is + * ceil(log2(quotient) / N) * (10 + 7N/2) + C + * A large dividend is one greater than 2^(31-TOPBITS) and takes a + * different path, as the upper bits of the quotient must be developed + * one bit at a time. + */ + + + .globl .udiv + .globl _Udiv +.udiv: +_Udiv: /* needed for export */ + + ! Ready to divide. Compute size of quotient; scale comparand. + orcc %o1, %g0, %o5 + bne 1f + mov %o0, %o3 + + ! Divide by zero trap. If it returns, return 0 (about as + ! wrong as possible, but that is what SunOS does...). + ta 0x2 + retl + clr %o0 + +1: + cmp %o3, %o5 ! if %o1 exceeds %o0, done + blu Lgot_result ! (and algorithm fails otherwise) + clr %o2 + + sethi %hi(1 << (32 - 4 - 1)), %g1 + + cmp %o3, %g1 + blu Lnot_really_big + clr %o4 + + ! Here the dividend is >= 2**(31-N) or so. We must be careful here, + ! as our usual N-at-a-shot divide step will cause overflow and havoc. + ! The number of bits in the result here is N*ITER+SC, where SC <= N. + ! Compute ITER in an unorthodox manner: know we need to shift V into + ! the top decade: so do not even bother to compare to R. + 1: + cmp %o5, %g1 + bgeu 3f + mov 1, %g7 + + sll %o5, 4, %o5 + + b 1b + add %o4, 1, %o4 + + ! Now compute %g7. + 2: + addcc %o5, %o5, %o5 + bcc Lnot_too_big + add %g7, 1, %g7 + + ! We get here if the %o1 overflowed while shifting. + ! This means that %o3 has the high-order bit set. + ! Restore %o5 and subtract from %o3. + sll %g1, 4, %g1 ! high order bit + srl %o5, 1, %o5 ! rest of %o5 + add %o5, %g1, %o5 + + b Ldo_single_div + sub %g7, 1, %g7 + + Lnot_too_big: + 3: + cmp %o5, %o3 + blu 2b + nop + + be Ldo_single_div + nop + /* NB: these are commented out in the V8-Sparc manual as well */ + /* (I do not understand this) */ + ! %o5 > %o3: went too far: back up 1 step + ! srl %o5, 1, %o5 + ! dec %g7 + ! do single-bit divide steps + ! + ! We have to be careful here. We know that %o3 >= %o5, so we can do the + ! first divide step without thinking. BUT, the others are conditional, + ! and are only done if %o3 >= 0. Because both %o3 and %o5 may have the high- + ! order bit set in the first step, just falling into the regular + ! division loop will mess up the first time around. + ! So we unroll slightly... + Ldo_single_div: + subcc %g7, 1, %g7 + bl Lend_regular_divide + nop + + sub %o3, %o5, %o3 + mov 1, %o2 + + b Lend_single_divloop + nop + Lsingle_divloop: + sll %o2, 1, %o2 + bl 1f + srl %o5, 1, %o5 + ! %o3 >= 0 + sub %o3, %o5, %o3 + b 2f + add %o2, 1, %o2 + 1: ! %o3 < 0 + add %o3, %o5, %o3 + sub %o2, 1, %o2 + 2: + Lend_single_divloop: + subcc %g7, 1, %g7 + bge Lsingle_divloop + tst %o3 + + b,a Lend_regular_divide + +Lnot_really_big: +1: + sll %o5, 4, %o5 + + cmp %o5, %o3 + bleu 1b + addcc %o4, 1, %o4 + + be Lgot_result + sub %o4, 1, %o4 + + tst %o3 ! set up for initial iteration +Ldivloop: + sll %o2, 4, %o2 + ! depth 1, accumulated bits 0 + bl L.1.16 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 2, accumulated bits 1 + bl L.2.17 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 3, accumulated bits 3 + bl L.3.19 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 4, accumulated bits 7 + bl L.4.23 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (7*2+1), %o2 + +L.4.23: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (7*2-1), %o2 + +L.3.19: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 4, accumulated bits 5 + bl L.4.21 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (5*2+1), %o2 + +L.4.21: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (5*2-1), %o2 + +L.2.17: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 3, accumulated bits 1 + bl L.3.17 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 4, accumulated bits 3 + bl L.4.19 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (3*2+1), %o2 + +L.4.19: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (3*2-1), %o2 + +L.3.17: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 4, accumulated bits 1 + bl L.4.17 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (1*2+1), %o2 + +L.4.17: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (1*2-1), %o2 + +L.1.16: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 2, accumulated bits -1 + bl L.2.15 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 3, accumulated bits -1 + bl L.3.15 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 4, accumulated bits -1 + bl L.4.15 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (-1*2+1), %o2 + +L.4.15: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (-1*2-1), %o2 + +L.3.15: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 4, accumulated bits -3 + bl L.4.13 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (-3*2+1), %o2 + +L.4.13: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (-3*2-1), %o2 + +L.2.15: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 3, accumulated bits -3 + bl L.3.13 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + ! depth 4, accumulated bits -5 + bl L.4.11 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (-5*2+1), %o2 + +L.4.11: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (-5*2-1), %o2 + +L.3.13: + ! remainder is negative + addcc %o3,%o5,%o3 + ! depth 4, accumulated bits -7 + bl L.4.9 + srl %o5,1,%o5 + ! remainder is positive + subcc %o3,%o5,%o3 + b 9f + add %o2, (-7*2+1), %o2 + +L.4.9: + ! remainder is negative + addcc %o3,%o5,%o3 + b 9f + add %o2, (-7*2-1), %o2 + + 9: +Lend_regular_divide: + subcc %o4, 1, %o4 + bge Ldivloop + tst %o3 + + bl,a Lgot_result + ! non-restoring fixup here (one instruction only!) + sub %o2, 1, %o2 + +Lgot_result: + + retl + mov %o2, %o0 + + .globl .udiv_patch +.udiv_patch: + wr %g0, 0x0, %y + nop + nop + retl + udiv %o0, %o1, %o0 + nop diff --git a/qemu/roms/openbios/arch/sparc32/vectors.S b/qemu/roms/openbios/arch/sparc32/vectors.S new file mode 100644 index 000000000..e812cecb9 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/vectors.S @@ -0,0 +1,254 @@ +/* + * <vectors.S> + * + * Sparc V9 Trap Table(s) with SpitFire/Cheetah extensions. + * + * Copyright (C) 1996, 2001 David S. Miller (davem@caip.rutgers.edu) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License V2 + * as published by the Free Software Foundation + */ + +#define __ASSEMBLY +#include "psr.h" +#include "asm/asi.h" +#define SER_ADDR5 0x71100004 +#define SER_ADDR10 0xf1100004 + + .section ".text.vectors", "ax" + .align 4 /* Should be 16384, but alignment is handled by the ldscript */ +/* Sparc32 trap table */ + .globl trap_table, t_zero, t_wovf, t_wunf, __divide_error +trap_table: + +#define WINDOW_SPILL \ + rd %psr, %l0; rd %wim, %l3; b spill_window_entry; nop; + +#define WINDOW_FILL \ + rd %psr, %l0; rd %wim, %l3; b fill_window_entry; nop; + +#define TRAP_DFAULT(lvl) \ + rd %psr, %l0; rd %wim, %l3; b handle_dfault; mov lvl, %l7; + +#define BTRAP(lvl) ba bug; mov lvl, %g1; nop; nop; +#define BTRAPS(x) BTRAP(x) BTRAP(x+1) BTRAP(x+2) BTRAP(x+3) BTRAP(x+4) BTRAP(x+5) BTRAP(x+6) BTRAP(x+7) +#define TRAP_ENTRY_INTERRUPT(int_level) \ + sethi %hi(irq_entry ## int_level), %l7; \ + or %l7, %lo(irq_entry ## int_level), %l7; \ + jmp %l7; \ + nop + +t_zero: b entry; nop; nop; nop; + BTRAP(0x1) BTRAP(0x2) BTRAP(0x3) BTRAP(0x4) +t_wovf: WINDOW_SPILL /* Window Overflow */ +t_wunf: WINDOW_FILL /* Window Underflow */ + BTRAP(0x7) + BTRAP(0x8) + TRAP_DFAULT(0x9) + BTRAP(0xa) BTRAP(0xb) BTRAP(0xc) BTRAP(0xd) BTRAP(0xe) BTRAP(0xf) +#if 0 + BAD_TRAP(0x10) +t_irq1: TRAP_ENTRY_INTERRUPT(1) /* IRQ Software/SBUS Level 1 */ +t_irq2: TRAP_ENTRY_INTERRUPT(2) /* IRQ SBUS Level 2 */ +t_irq3: TRAP_ENTRY_INTERRUPT(3) /* IRQ SCSI/DMA/SBUS Level 3 */ +t_irq4: TRAP_ENTRY_INTERRUPT(4) /* IRQ Software Level 4 */ +t_irq5: TRAP_ENTRY_INTERRUPT(5) /* IRQ SBUS/Ethernet Level 5 */ +t_irq6: TRAP_ENTRY_INTERRUPT(6) /* IRQ Software Level 6 */ +t_irq7: TRAP_ENTRY_INTERRUPT(7) /* IRQ Video/SBUS Level 5 */ +t_irq8: TRAP_ENTRY_INTERRUPT(8) /* IRQ SBUS Level 6 */ +t_irq9: TRAP_ENTRY_INTERRUPT(9) /* IRQ SBUS Level 7 */ +t_irq10: TRAP_ENTRY_INTERRUPT(10) /* IRQ Timer #1 (one we use) */ +t_irq11: TRAP_ENTRY_INTERRUPT(11) /* IRQ Floppy Intr. */ +t_irq12: TRAP_ENTRY_INTERRUPT(12) /* IRQ Zilog serial chip */ +t_irq13: TRAP_ENTRY_INTERRUPT(13) /* IRQ Audio Intr. */ +t_irq14: TRAP_ENTRY_INTERRUPT(14) /* IRQ Timer #2 */ +t_nmi: BAD_TRAP(0x1f) /* Level 15 (NMI) */ +#else + BTRAPS(0x10) + BTRAP(0x18) BTRAP(0x19) +t_irq10: TRAP_ENTRY_INTERRUPT(10) /* IRQ Timer #1 (one we use) */ + BTRAP(0x1b) BTRAP(0x1c) BTRAP(0x1d) +t_irq14: TRAP_ENTRY_INTERRUPT(14) /* IRQ Timer #2 */ + BTRAP(0x1f) +#endif + BTRAPS(0x20) + BTRAP(0x28) + TRAP_DFAULT(0x29) + BTRAP(0x2a) BTRAP(0x2b) BTRAP(0x2c) BTRAP(0x2d) BTRAP(0x2e) BTRAP(0x2f) + BTRAPS(0x30) BTRAPS(0x38) + BTRAPS(0x40) BTRAPS(0x48) + BTRAPS(0x50) BTRAPS(0x58) + BTRAPS(0x60) BTRAPS(0x68) + BTRAPS(0x70) BTRAPS(0x78) + BTRAPS(0x80) BTRAPS(0x88) + BTRAPS(0x90) BTRAPS(0x98) + BTRAPS(0xa0) BTRAPS(0xa8) + BTRAPS(0xb0) BTRAPS(0xb8) + BTRAPS(0xc0) BTRAPS(0xc8) + BTRAPS(0xd0) BTRAPS(0xd8) + BTRAPS(0xe0) BTRAPS(0xe8) + BTRAPS(0xf0) BTRAPS(0xf8) + + .section ".text", "ax" + .align 4 +__divide_error: +bug: + /* Dump the exception and its context */ + ! Set up CPU state + rd %psr, %g2 + andn %g2, PSR_ET, %g2 + wr %g2, %psr + ! Disable mmu, re-enable boot mode + set _start, %g3 + set dump_exception, %g2 + sub %g2, %g3, %g3 + set 3 << 13, %g2 + jmp %g3 + sta %g2, [%g0] ASI_M_MMUREGS + +outstr: + /* void outstr (unsigned long port5, unsigned long port10, + * const unsigned char *str); + * Writes a string on an IO port. + */ +1: lduba [%o2] ASI_M_KERNELTXT, %o3 + cmp %o3, 0 + be 2f + nop + stba %o3, [%o0] ASI_M_BYPASS + stba %o3, [%o1] ASI_M_CTL + b 1b + inc %o2 +2: retl + nop + +outhex: + /* void outhex (unsigned long port5, unsigned long port10, + * uint32_t value); + * Dumps a 32 bits hex number on serial port + */ + mov %o2, %o4 + set 28, %o3 + srl %o4, %o3, %o2 +1: and %o2, 0xf, %o2 + cmp %o2, 9 + bgt 2f + nop + b 3f + add %o2, '0', %o2 +2: add %o2, 'a' - 10, %o2 +3: stba %o2, [%o0] ASI_M_BYPASS + stba %o2, [%o1] ASI_M_CTL + subcc %o3, 4, %o3 + bge 1b + srl %o4, %o3, %o2 + retl + nop + + /* void dump_exception (); + * + * Dump a message when catching an exception + */ +dump_exception: + set SER_ADDR5 + 2, %o0 + set SER_ADDR10 + 2, %o1 + set (_BUG_message_0), %o2 + call outstr + nop + + call outhex + mov %g1, %o2 + + set (_BUG_message_1), %o2 + call outstr + nop + + call outhex + mov %l1, %o2 + + set (_BUG_message_2), %o2 + call outstr + nop + + call outhex + mov %l2, %o2 + + set (_BUG_message_3), %o2 + call outstr + nop +_forever: + /* Loop forever */ + b _forever ; + nop + +irq_entry10: + sethi %hi(counter_regs), %l7 + ld [%l7 + %lo(counter_regs)], %l7 + sethi 0x10000, %l6 + ld [%l7 + %l6], %g0 + jmp %l1 + rett %l2 + +irq_entry14: + sethi %hi(counter_regs), %l7 + ld [%l7 + %lo(counter_regs)], %l7 + ld [%l7], %g0 + sethi %hi(obp_ticks), %l7 + ld [%l7 + %lo(obp_ticks)], %l7 + ld [%l7], %l6 + add %l6, 10, %l6 + st %l6, [%l7] + jmp %l1 + rett %l2 + +/* Register window handlers */ +#include "wof.S" +#include "wuf.S" + +/* Data fault handler */ + .data + .align 4 + .global ignore_dfault + +ignore_dfault: + .word 0 + + .text + .align 4 + +handle_dfault: + /* If ignore_dfault is 0, fall through to normal exception handler */ + sethi %hi(ignore_dfault), %l4 + ld [%l4 + %lo(ignore_dfault)], %l4 + tst %l4 + bz,a bug + mov %l7, %g1 + + /* Otherwise skip the faulting instruction and return */ + jmp %l2 + rett %l2 + 4 + + + .section .rodata +_BUG_message_0: + .string "Unhandled Exception 0x" +_BUG_message_1: + .string "\r\nPC = 0x" +_BUG_message_2: + .string " NPC = 0x" +_BUG_message_3: + .string "\r\nStopping execution\r\n" diff --git a/qemu/roms/openbios/arch/sparc32/wof.S b/qemu/roms/openbios/arch/sparc32/wof.S new file mode 100644 index 000000000..8d6bb7314 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/wof.S @@ -0,0 +1,133 @@ +/* + * Proll takes this from Sparclinux kernel, ruthlessly truncated + * because we have no user windows. + * + * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License V2 + * as published by the Free Software Foundation + */ + +// #include <asm/winmacro.h> +// #include <asm/asmmacro.h> + +/* Reg_window offsets */ +#define RW_L0 0x00 +#define RW_L1 0x04 +#define RW_L2 0x08 +#define RW_L3 0x0c +#define RW_L4 0x10 +#define RW_L5 0x14 +#define RW_L6 0x18 +#define RW_L7 0x1c +#define RW_I0 0x20 +#define RW_I1 0x24 +#define RW_I2 0x28 +#define RW_I3 0x2c +#define RW_I4 0x30 +#define RW_I5 0x34 +#define RW_I6 0x38 +#define RW_I7 0x3c + +/* Store the register window onto the 8-byte aligned area starting + * at %reg. It might be %sp, it might not, we don't care. + */ +#define STORE_WINDOW(reg) \ + std %l0, [%reg + RW_L0]; \ + std %l2, [%reg + RW_L2]; \ + std %l4, [%reg + RW_L4]; \ + std %l6, [%reg + RW_L6]; \ + std %i0, [%reg + RW_I0]; \ + std %i2, [%reg + RW_I2]; \ + std %i4, [%reg + RW_I4]; \ + std %i6, [%reg + RW_I6]; + +/* We define macro's for registers which have a fixed + * meaning throughout this entire routine. The 'T' in + * the comments mean that the register can only be + * accessed when in the 'trap' window, 'G' means + * accessible in any window. Do not change these registers + * after they have been set, until you are ready to return + * from the trap. + */ +#define t_psr l0 /* %psr at trap time T */ +#define t_pc l1 /* PC for trap return T */ +#define t_npc l2 /* NPC for trap return T */ +#define t_wim l3 /* %wim at trap time T */ +#define saved_g5 l5 /* Global save register T */ +#define saved_g6 l6 /* Global save register T */ + +/* Now registers whose values can change within the handler. */ +#define twin_tmp l4 /* Temp reg, only usable in trap window T */ +#define glob_tmp g5 /* Global temporary reg, usable anywhere G */ + + .text + .align 4 + + /* BEGINNING OF PATCH INSTRUCTIONS */ + /* On a 7-window Sparc the boot code patches spnwin_* + * instructions with the following ones. + */ + .globl spnwin_patch1_7win, spnwin_patch2_7win, spnwin_patch3_7win +spnwin_patch1_7win: sll %t_wim, 6, %glob_tmp +spnwin_patch2_7win: and %glob_tmp, 0x7f, %glob_tmp +spnwin_patch3_7win: and %twin_tmp, 0x7f, %twin_tmp + /* END OF PATCH INSTRUCTIONS */ + + /* The trap entry point has done the following: + * + * rd %psr, %l0 + * rd %wim, %l3 + * b spill_window_entry + * nop + */ + + .globl spill_window_entry + .globl spnwin_patch1, spnwin_patch2 +spill_window_entry: + /* LOCATION: Trap Window */ + + mov %g5, %saved_g5 ! save away global temp register + mov %g6, %saved_g6 ! save away 'current' ptr register + + /* Compute what the new %wim will be if we save the + * window properly in this trap handler. + * + * newwim = ((%wim>>1) | (%wim<<(nwindows - 1))); + */ + srl %t_wim, 0x1, %twin_tmp +spnwin_patch1: sll %t_wim, 7, %glob_tmp + or %glob_tmp, %twin_tmp, %glob_tmp +spnwin_patch2: and %glob_tmp, 0xff, %glob_tmp + + /* Save into the window which must be saved and do it. + */ + save %g0, %g0, %g0 ! save into the window to stash away + wr %glob_tmp, 0x0, %wim ! set new %wim, this is safe now + + /* LOCATION: Window to be saved */ + + STORE_WINDOW(sp) ! stash the window + restore %g0, %g0, %g0 ! go back into trap window + + /* LOCATION: Trap window */ + mov %saved_g5, %g5 ! restore %glob_tmp + mov %saved_g6, %g6 ! restore %curptr + wr %t_psr, 0x0, %psr ! restore condition codes in %psr + nop; nop; nop ! waste some time + jmp %t_pc ! Return from trap + rett %t_npc ! we are done diff --git a/qemu/roms/openbios/arch/sparc32/wuf.S b/qemu/roms/openbios/arch/sparc32/wuf.S new file mode 100644 index 000000000..853fc7322 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc32/wuf.S @@ -0,0 +1,154 @@ +/* + * Window fill (underflow) trap, based on code from Sparclinux. + * + * Copyright (C) 1995 David S. Miller + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +// #include <psr.h> +// #include <asi.h> + +/* Reg_window offsets */ +#define RW_L0 0x00 +#define RW_L1 0x04 +#define RW_L2 0x08 +#define RW_L3 0x0c +#define RW_L4 0x10 +#define RW_L5 0x14 +#define RW_L6 0x18 +#define RW_L7 0x1c +#define RW_I0 0x20 +#define RW_I1 0x24 +#define RW_I2 0x28 +#define RW_I3 0x2c +#define RW_I4 0x30 +#define RW_I5 0x34 +#define RW_I6 0x38 +#define RW_I7 0x3c + +/* Load a register window from the area beginning at %reg. */ +#define LOAD_WINDOW(reg) \ + ldd [%reg + RW_L0], %l0; \ + ldd [%reg + RW_L2], %l2; \ + ldd [%reg + RW_L4], %l4; \ + ldd [%reg + RW_L6], %l6; \ + ldd [%reg + RW_I0], %i0; \ + ldd [%reg + RW_I2], %i2; \ + ldd [%reg + RW_I4], %i4; \ + ldd [%reg + RW_I6], %i6; + +#define WRITE_PAUSE nop; nop; nop; /* Have to do this after %wim/%psr chg */ + +/* Just like the overflow handler we define macros for registers + * with fixed meanings in this routine. + */ +#define t_psr l0 +#define t_pc l1 +#define t_npc l2 +#define t_wim l3 +/* Don't touch the above registers or else you die horribly... */ + +/* Now macros for the available scratch registers in this routine. */ +#define twin_tmp1 l4 +#define twin_tmp2 l5 + + .text + .align 4 + + /* The trap entry point has executed the following: + * + * rd %psr, %l0 + * rd %wim, %l3 + * b fill_window_entry + * andcc %l0, PSR_PS, %g0 + */ + + /* To get an idea of what has just happened to cause this + * trap take a look at this diagram: + * + * 1 2 3 4 <-- Window number + * ---------- + * T O W I <-- Symbolic name + * + * O == the window that execution was in when + * the restore was attempted + * + * T == the trap itself has save'd us into this + * window + * + * W == this window is the one which is now invalid + * and must be made valid plus loaded from the + * stack + * + * I == this window will be the invalid one when we + * are done and return from trap if successful + */ + + /* BEGINNING OF PATCH INSTRUCTIONS */ + + /* On 7-window Sparc the boot code patches fnwin_patch1 + * with the following instruction. + */ + .globl fnwin_patch1_7win, fnwin_patch2_7win +fnwin_patch1_7win: srl %t_wim, 6, %twin_tmp2 +fnwin_patch2_7win: and %twin_tmp1, 0x7f, %twin_tmp1 + /* END OF PATCH INSTRUCTIONS */ + + + .globl fill_window_entry, fnwin_patch1, fnwin_patch2 +fill_window_entry: + /* LOCATION: Window 'T' */ + + /* Compute what the new %wim is going to be if we retrieve + * the proper window off of the stack. + */ + sll %t_wim, 1, %twin_tmp1 +fnwin_patch1: srl %t_wim, 7, %twin_tmp2 + or %twin_tmp1, %twin_tmp2, %twin_tmp1 +fnwin_patch2: and %twin_tmp1, 0xff, %twin_tmp1 + + wr %twin_tmp1, 0x0, %wim /* Make window 'I' invalid */ + + restore %g0, %g0, %g0 /* Restore to window 'O' */ + + /* Trapped from kernel, we trust that the kernel does not + * 'over restore' sorta speak and just grab the window + * from the stack and return. Easy enough. + */ + /* LOCATION: Window 'O' */ + + restore %g0, %g0, %g0 + WRITE_PAUSE + + /* LOCATION: Window 'W' */ + + LOAD_WINDOW(sp) /* Load it up */ + + /* Spin the wheel... */ + save %g0, %g0, %g0 + save %g0, %g0, %g0 + /* I'd like to buy a vowel please... */ + + /* LOCATION: Window 'T' */ + + /* Now preserve the condition codes in %psr, pause, and + * return from trap. This is the simplest case of all. + */ + wr %t_psr, 0x0, %psr + WRITE_PAUSE + + jmp %t_pc + rett %t_npc diff --git a/qemu/roms/openbios/arch/sparc64/boot.c b/qemu/roms/openbios/arch/sparc64/boot.c new file mode 100644 index 000000000..5107be6ca --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/boot.c @@ -0,0 +1,130 @@ +/* + * + */ +#undef BOOTSTRAP +#include "config.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libc/vsprintf.h" +#include "libopenbios/sys_info.h" +#include "boot.h" + +uint64_t kernel_image; +uint64_t kernel_size; +uint64_t qemu_cmdline; +uint64_t cmdline_size; +char boot_device; + +extern int sparc64_of_client_interface( int *params ); + + +void go(void) +{ + ucell address, type, size; + int image_retval = 0; + + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + image_retval = start_elf(address, (uint64_t)&elf_boot_notes); + break; + + case 0x1: + /* Start ELF image */ + image_retval = start_client_image(address, (uint64_t)&sparc64_of_client_interface); + break; + + case 0x5: + /* Start a.out image */ + image_retval = start_client_image(address, (uint64_t)&sparc64_of_client_interface); + break; + + case 0x10: + /* Start Fcode image */ + printk("Evaluating FCode...\n"); + PUSH(address); + PUSH(1); + fword("byte-load"); + image_retval = 0; + break; + + case 0x11: + /* Start Forth image */ + PUSH(address); + PUSH(size); + fword("eval2"); + image_retval = 0; + break; + } + + printk("Image returned with return value %#x\n", image_retval); +} + +/* ( path len -- path len ) */ + +void boot(void) +{ + char *path, *param; + + /* Copy the incoming path */ + fword("2dup"); + path = pop_fstr_copy(); + + /* Boot preloaded kernel */ + if (kernel_size) { + void (*entry)(unsigned long p1, unsigned long p2, unsigned long p3, + unsigned long p4, unsigned long p5); + + printk("[sparc64] Kernel already loaded\n"); + entry = (void *) (unsigned long)kernel_image; + entry(0, 0, 0, 0, (unsigned long)&sparc64_of_client_interface); + } + + /* Invoke Linux directly -- probably not supported */ + if(!path) { + /* No path specified, so grab defaults from /chosen */ + push_str("bootpath"); + push_str("/chosen"); + fword("(find-dev)"); + POP(); + fword("get-package-property"); + POP(); + /* Update our local copy of path as well as the one on the stack */ + fword("2dup"); + path = pop_fstr_copy(); + } + + if (path) { + param = strchr(path, ' '); + if(param) { + *param = '\0'; + param++; + } else if (cmdline_size) { + param = (char *)qemu_cmdline; + } else { + push_str("boot-args"); + push_str("/options"); + fword("(find-dev)"); + POP(); + fword("get-package-property"); + POP(); + param = pop_fstr_copy(); + } + + /* Invoke platform-specific Linux loader */ + linux_load(&sys_info, path, param); + + free(path); + } +} diff --git a/qemu/roms/openbios/arch/sparc64/boot.h b/qemu/roms/openbios/arch/sparc64/boot.h new file mode 100644 index 000000000..3ab05e0a3 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/boot.h @@ -0,0 +1,35 @@ +/* tag: openbios loader prototypes for sparc64 + * + * Copyright (C) 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +// linux_load.c +int linux_load(struct sys_info *info, const char *file, const char *cmdline); + +// context.c +extern struct context * volatile __context; +uint64_t start_elf(uint64_t entry_point, uint64_t param); +uint64_t start_client_image(uint64_t entry_point, uint64_t cif_handler); + +// boot.c +extern uint64_t kernel_image; +extern uint64_t kernel_size; +extern uint64_t qemu_cmdline; +extern uint64_t cmdline_size; +extern char boot_device; +extern void boot(void); +extern void go(void); + +// sys_info.c +extern uint64_t qemu_mem_size; +extern void collect_sys_info(struct sys_info *info); + +// console.c +void ob_su_init(uint64_t base, uint64_t offset, int intr); +void cls(void); + +// lib.c +void ob_mmu_init(const char *cpuname, uint64_t ram_size); diff --git a/qemu/roms/openbios/arch/sparc64/build.xml b/qemu/roms/openbios/arch/sparc64/build.xml new file mode 100644 index 000000000..3a1cd346a --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/build.xml @@ -0,0 +1,72 @@ +<build condition="SPARC64"> + + <dictionary name="openbios-sparc64" init="openbios"> + <object source="tree.fs" target="forth"/> + <object source="init.fs" target="forth"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <library name="sparc64" type="static" target="target"> + <object source="openbios.c"/> + <object source="console.c"/> + <object source="lib.c"/> + <object source="boot.c"/> + <object source="context.c"/> + <object source="switch.S"/> + <object source="linux_load.c"/> + <object source="sys_info.c"/> + <object source="ofmem_sparc64.c"/> + <object source="entry.S"/> + <object source="vectors.S"/> + <object source="call-client.S"/> + </library> + + <executable name="openbios-plain.elf" target="target" condition="IMAGE_ELF"> + <rule> + $(call quiet-command,$(LD) --warn-common -T $(SRCDIR)/arch/sparc64/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-plain.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="plainboot.c"/> + <external-object source="libsparc64.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + <external-object source="libgcc.a"/> + </executable> + + <!-- HACK ALERT --> + + <executable name="target/include/static-dict.h" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ + $(call quiet-command,$(ODIR)/forthstrap -x -D $@ -d $< </dev/null, " GEN $(TARGET_DIR)$@")]]></rule> + <external-object source="openbios-sparc64.dict"/> + </executable> + + <executable name="target/arch/sparc64/builtin.o" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ $(SRCDIR)/arch/sparc64/builtin.c $(ODIR)/target/include/static-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/sparc64/builtin.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + <!-- END OF HACK ALERT --> + + <executable name="openbios-builtin.elf" target="target" condition="IMAGE_ELF_EMBEDDED"> + <!-- We use -N to reduce the file size by 1M --> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/sparc64/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-builtin.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <external-object source="target/arch/sparc64/builtin.o"/> + <external-object source="libsparc64.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + <external-object source="libgcc.a"/> + </executable> + +</build> diff --git a/qemu/roms/openbios/arch/sparc64/builtin.c b/qemu/roms/openbios/arch/sparc64/builtin.c new file mode 100644 index 000000000..864da7971 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/builtin.c @@ -0,0 +1,33 @@ +/* tag: openbios forth starter for builtin dictionary for sparc64 + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "asm/types.h" +#include "libopenbios/sys_info.h" + +/* + * wrap an array around the hex'ed dictionary file + */ + +/* 512K for the dictionary */ +#define DICTIONARY_SIZE (512 * 1024 / sizeof(ucell)) +#define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary)) + +static ucell forth_dictionary[DICTIONARY_SIZE] = { +#include "static-dict.h" +}; + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)forth_dictionary; + info->dict_end = (unsigned long *)FORTH_DICTIONARY_END; + info->dict_last = (ucell *)((unsigned char *)forth_dictionary + + FORTH_DICTIONARY_LAST); + info->dict_limit = sizeof(forth_dictionary); +} diff --git a/qemu/roms/openbios/arch/sparc64/call-client.S b/qemu/roms/openbios/arch/sparc64/call-client.S new file mode 100644 index 000000000..f365e3cb1 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/call-client.S @@ -0,0 +1,236 @@ + .globl sparc64_of_client_interface, client_tba + + +/* + * SAVE_WINDOW_STATE and RESTORE_WINDOW_STATE are used to ensure + * that the CPU window state is preserved across CIF calls. This is + * to workaround a *BSD restriction that window fill/spill traps must + * be minimised during trap table takeover, and likely emulates the + * behaviour of OBP. + */ + +#define SAVE_WINDOW_STATE(type) \ + setx client_window, %g6, %g1; \ + rdpr %cwp, %g7; \ + stx %g7, [%g1]; \ + rdpr %cansave, %g7; \ + stx %g7, [%g1 + 0x8]; \ + rdpr %canrestore, %g7; \ + stx %g7, [%g1 + 0x10]; \ + rdpr %otherwin, %g7; \ + stx %g7, [%g1 + 0x18]; \ + rdpr %wstate, %g7; \ + stx %g7, [%g1 + 0x20]; \ + rdpr %cleanwin, %g7; \ + stx %g7, [%g1 + 0x28]; \ + \ + stx %o0, [%g1 + 0x30]; \ + stx %o1, [%g1 + 0x38]; \ + stx %o2, [%g1 + 0x40]; \ + stx %o3, [%g1 + 0x48]; \ + stx %o4, [%g1 + 0x50]; \ + stx %o5, [%g1 + 0x58]; \ + stx %o6, [%g1 + 0x60]; \ + stx %o7, [%g1 + 0x68]; \ + \ + rdpr %pstate, %g7; \ + stx %g7, [%g1 + 0x70]; \ + rd %y, %g7; \ + stx %g7, [%g1 + 0x78]; \ + rd %fprs, %g7; \ + stx %g7, [%g1 + 0x80]; \ + \ + /* Now iterate through all of the windows saving all l and i registers */ \ + add %g1, 0x90, %g5; \ + \ + /* Get the number of windows in %g6 */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + inc %g6; \ + \ +save_cpu_window_##type: \ + deccc %g6; \ + wrpr %g6, %cwp; \ + stx %l0, [%g5]; \ + stx %l1, [%g5 + 0x8]; \ + stx %l2, [%g5 + 0x10]; \ + stx %l3, [%g5 + 0x18]; \ + stx %l4, [%g5 + 0x20]; \ + stx %l5, [%g5 + 0x28]; \ + stx %l6, [%g5 + 0x30]; \ + stx %l7, [%g5 + 0x38]; \ + stx %i0, [%g5 + 0x40]; \ + stx %i1, [%g5 + 0x48]; \ + stx %i2, [%g5 + 0x50]; \ + stx %i3, [%g5 + 0x58]; \ + stx %i4, [%g5 + 0x60]; \ + stx %i5, [%g5 + 0x68]; \ + stx %i6, [%g5 + 0x70]; \ + stx %i7, [%g5 + 0x78]; \ + bne save_cpu_window_##type; \ + add %g5, 0x80, %g5; \ + \ + /* For 8 windows with 16 registers to save in the window, memory required \ + is 16*8*8 = 0x400 bytes */ \ + \ + /* Now we should be in window 0 so update the other window registers */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + dec %g6; \ + wrpr %g6, %cansave; \ + \ + wrpr %g0, %cleanwin; \ + wrpr %g0, %canrestore; \ + wrpr %g0, %otherwin; + + +#define RESTORE_WINDOW_STATE(type) \ + setx client_window, %g6, %g1; \ + \ + /* Get the number of windows in %g6 */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + inc %g6; \ + \ + /* Now iterate through all of the windows restoring all l and i registers */ \ + add %g1, 0x90, %g5; \ + \ +restore_cpu_window_##type: \ + deccc %g6; \ + wrpr %g6, %cwp; \ + ldx [%g5], %l0; \ + ldx [%g5 + 0x8], %l1; \ + ldx [%g5 + 0x10], %l2; \ + ldx [%g5 + 0x18], %l3; \ + ldx [%g5 + 0x20], %l4; \ + ldx [%g5 + 0x28], %l5; \ + ldx [%g5 + 0x30], %l6; \ + ldx [%g5 + 0x38], %l7; \ + ldx [%g5 + 0x40], %i0; \ + ldx [%g5 + 0x48], %i1; \ + ldx [%g5 + 0x50], %i2; \ + ldx [%g5 + 0x58], %i3; \ + ldx [%g5 + 0x60], %i4; \ + ldx [%g5 + 0x68], %i5; \ + ldx [%g5 + 0x70], %i6; \ + ldx [%g5 + 0x78], %i7; \ + bne restore_cpu_window_##type; \ + add %g5, 0x80, %g5; \ + \ + /* Restore the window registers to their original value */ \ + ldx [%g1], %g7; \ + wrpr %g7, %cwp; \ + ldx [%g1 + 0x8], %g7; \ + wrpr %g7, %cansave; \ + ldx [%g1 + 0x10], %g7; \ + wrpr %g7, %canrestore; \ + ldx [%g1 + 0x18], %g7; \ + wrpr %g7, %otherwin; \ + ldx [%g1 + 0x20], %g7; \ + wrpr %g7, %wstate; \ + ldx [%g1 + 0x28], %g7; \ + wrpr %g7, %cleanwin; \ + \ + ldx [%g1 + 0x30], %o0; \ + ldx [%g1 + 0x38], %o1; \ + ldx [%g1 + 0x40], %o2; \ + ldx [%g1 + 0x48], %o3; \ + ldx [%g1 + 0x50], %o4; \ + ldx [%g1 + 0x58], %o5; \ + ldx [%g1 + 0x60], %o6; \ + ldx [%g1 + 0x68], %o7; \ + \ + ldx [%g1 + 0x70], %g7; \ + wrpr %g7, %pstate; \ + ldx [%g1 + 0x78], %g7; \ + wr %g7, 0, %y; \ + ldx [%g1 + 0x80], %g7; \ + wr %g7, 0, %fprs + + + .data + .align 8 + + .skip 16384 +openbios_stack: + +client_stack: + .xword 0 +client_tba: + .xword 0 +client_window: + .skip 2048 + + + .text + .align 4 + .register %g2, #scratch + .register %g3, #scratch + .register %g6, #scratch + .register %g7, #scratch +/* + make some more space on stack since linux kernel only provides 128 bytes + without memory to spill registers (used by gcc in -O0 mode) +*/ + +sparc64_of_client_interface: + + /* Save globals on callers stack */ + add %sp, -56, %sp + + stx %g1, [%sp + 2047 + 0] + stx %g2, [%sp + 2047 + 8] + stx %g3, [%sp + 2047 + 16] + stx %g4, [%sp + 2047 + 24] + stx %g5, [%sp + 2047 + 32] + stx %g6, [%sp + 2047 + 40] + stx %g7, [%sp + 2047 + 48] + + /* Save client trap table */ + setx client_tba, %g6, %g7 + rdpr %tba, %g6 + stx %g6, [%g7] + + /* Save existing stack */ + setx client_stack, %g6, %g7 + stx %sp, [%g7] + + /* Save windows */ + SAVE_WINDOW_STATE(cif) + + /* Move to OpenBIOS stack */ + setx openbios_stack - 2047 - 192, %g6, %g7 + mov %g7, %sp + + /* Call client inteface */ + call of_client_interface + ldx [%g1 + 0x30], %o0 + + setx client_window, %g6, %g1 + stx %o0, [%g1 + 0x30] + + /* Restore windows */ + RESTORE_WINDOW_STATE(cif) + + /* Restore stack */ + setx client_stack, %g6, %g7 + ldx [%g7], %sp + + /* Restore client trap table */ + setx client_tba, %g6, %g7 + ldx [%g7], %g6 + wrpr %g6, %tba + + /* Restore globals */ + ldx [%sp + 2047 + 0], %g1 + ldx [%sp + 2047 + 8], %g2 + ldx [%sp + 2047 + 16], %g3 + ldx [%sp + 2047 + 24], %g4 + ldx [%sp + 2047 + 32], %g5 + ldx [%sp + 2047 + 40], %g6 + ldx [%sp + 2047 + 48], %g7 + + add %sp, 56, %sp + + jmp %o7+8 + nop diff --git a/qemu/roms/openbios/arch/sparc64/console.c b/qemu/roms/openbios/arch/sparc64/console.c new file mode 100644 index 000000000..6ab5cba4d --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/console.c @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "kernel/kernel.h" +#include "drivers/drivers.h" +#include "libopenbios/fontdata.h" +#include "openbios.h" +#include "libc/vsprintf.h" +#include "libopenbios/sys_info.h" +#include "boot.h" + +/* ****************************************************************** + * simple polling video/keyboard console functions + * ****************************************************************** */ + +#ifdef CONFIG_DEBUG_CONSOLE +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +static int arch_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_putchar(c); +#endif + return c; +} + +static int arch_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (pc_kbd_dataready()) + return 1; +#endif + return 0; +} + +static int arch_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return (uart_getchar(CONFIG_SERIAL_PORT)); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (pc_kbd_dataready()) + return (pc_kbd_readdata()); +#endif + return 0; +} + +struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + +#endif // CONFIG_DEBUG_CONSOLE diff --git a/qemu/roms/openbios/arch/sparc64/const.h b/qemu/roms/openbios/arch/sparc64/const.h new file mode 100644 index 000000000..8ad902b2c --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/const.h @@ -0,0 +1,19 @@ +/* const.h: Macros for dealing with constants. */ + +#ifndef _SPARC64_CONST_H +#define _SPARC64_CONST_H + +/* Some constant macros are used in both assembler and + * C code. Therefore we cannot annotate them always with + * 'UL' and other type specificers unilaterally. We + * use the following macros to deal with this. + */ + +#ifdef __ASSEMBLY__ +#define _AC(X,Y) X +#else +#define _AC(X,Y) (X##Y) +#endif + + +#endif /* !(_SPARC64_CONST_H) */ diff --git a/qemu/roms/openbios/arch/sparc64/context.c b/qemu/roms/openbios/arch/sparc64/context.c new file mode 100644 index 000000000..2e7668958 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/context.c @@ -0,0 +1,129 @@ +/* + * context switching + * 2003-10 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "context.h" +#include "libopenbios/sys_info.h" +#include "boot.h" +#include "openbios.h" + +#define MAIN_STACK_SIZE 16384 +#define IMAGE_STACK_SIZE 4096*4 + +#define debug printk + +static void start_main(void); /* forward decl. */ +void __exit_context(void); /* assembly routine */ + +/* + * Main context structure + * It is placed at the bottom of our stack, and loaded by assembly routine + * to start us up. + */ +static struct context main_ctx = { + .regs[REG_SP] = (uint64_t) &_estack - STACK_BIAS - 96, + .pc = (uint64_t) start_main, + .npc = (uint64_t) start_main + 4, + .return_addr = (uint64_t) __exit_context, +}; + +/* This is used by assembly routine to load/store the context which + * it is to switch/switched. */ +struct context * volatile __context = &main_ctx; + +/* Stack for loaded ELF image */ +static uint8_t image_stack[IMAGE_STACK_SIZE]; + +/* Pointer to startup context (physical address) */ +unsigned long __boot_ctx; + +/* + * Main starter + * This is the C function that runs first. + */ +static void start_main(void) +{ + /* Save startup context, so we can refer to it later. + * We have to keep it in physical address since we will relocate. */ + __boot_ctx = virt_to_phys(__context); + + /* Start the real fun */ + openbios(); + + /* Returning from here should jump to __exit_context */ + __context = boot_ctx; +} + +static uint64_t ALIGN_SIZE(uint64_t x, uint64_t a) +{ + return (x + a - 1) & ~(a-1); +} + +/* Setup a new context using the given stack. + */ +struct context * +init_context(uint8_t *stack, uint64_t stack_size, int num_params) +{ + struct context *ctx; + uint8_t *stack_top = stack + stack_size; + + ctx = (struct context *) + (stack_top - ALIGN_SIZE(sizeof(*ctx) + num_params*sizeof(uint64_t), sizeof(uint64_t))); + memset(ctx, 0, sizeof(*ctx)); + + /* Fill in reasonable default for flat memory model */ + ctx->regs[REG_SP] = virt_to_phys(stack_top - STACK_BIAS - 192); + ctx->return_addr = virt_to_phys(__exit_context); + + return ctx; +} + +/* Switch to another context. */ +struct context *switch_to(struct context *ctx) +{ + struct context *save, *ret; + + debug("switching to new context: entry point %#llx stack 0x%016llx\n", ctx->pc, ctx->regs[REG_SP]); + save = __context; + __context = ctx; + //asm ("pushl %cs; call __switch_context"); + asm ("call __switch_context_nosave; nop"); + ret = __context; + __context = save; + return ret; +} + +/* Start ELF Boot image */ +uint64_t start_elf(uint64_t entry_point, uint64_t param) +{ + struct context *ctx; + + ctx = init_context(image_stack, sizeof image_stack, 1); + ctx->pc = entry_point; + ctx->param[0] = param; + //ctx->eax = 0xe1fb007; + //ctx->ebx = param; + + ctx = switch_to(ctx); + //return ctx->eax; + return 0; +} + +/* Start client image */ +uint64_t start_client_image(uint64_t entry_point, uint64_t cif_handler) +{ + struct context *ctx; + + ctx = init_context(image_stack, sizeof image_stack, 0); + ctx->pc = entry_point; + ctx->npc = entry_point+4; + ctx->regs[REG_O0] = 0; + ctx->regs[REG_O0+4] = cif_handler; + + ctx = switch_to(ctx); + + return 0; +} diff --git a/qemu/roms/openbios/arch/sparc64/context.h b/qemu/roms/openbios/arch/sparc64/context.h new file mode 100644 index 000000000..2756fa15f --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/context.h @@ -0,0 +1,33 @@ +#ifndef SPARC64_CONTEXT_H +#define SPARC64_CONTEXT_H + +#define STACK_BIAS 2047 + +struct context { + /* General registers */ + uint64_t regs[32]; + uint64_t pc; + uint64_t npc; +#define REG_O0 8 +#define REG_SP 14 +#define SP_LOC(ctx) (&(ctx)->regs[REG_SP]) + /* Flags */ + /* Optional stack contents */ + uint64_t return_addr; + uint64_t param[0]; +}; + +/* Create a new context in the given stack */ +struct context * +init_context(uint8_t *stack, uint64_t stack_size, int num_param); + +/* Switch context */ +struct context *switch_to(struct context *); + +/* Holds physical address of boot context */ +extern unsigned long __boot_ctx; + +/* This can always be safely used to refer to the boot context */ +#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx)) + +#endif /* SPARC64_CONTEXT_H */ diff --git a/qemu/roms/openbios/arch/sparc64/entry.S b/qemu/roms/openbios/arch/sparc64/entry.S new file mode 100644 index 000000000..d03128af5 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/entry.S @@ -0,0 +1,287 @@ +/** + ** Standalone startup code for Linux PROM emulator. + ** Copyright 1999 Pete A. Zaitcev + ** This code is licensed under GNU General Public License. + **/ +/* + * $Id: head.S,v 1.12 2002/07/23 05:47:09 zaitcev Exp $ + */ + +#define __ASSEMBLY__ +#include <asm/asi.h> +#include "pstate.h" +#include "lsu.h" +#define NO_QEMU_PROTOS +#define NO_OPENBIOS_PROTOS +#include "arch/common/fw_cfg.h" + +#define PROM_ADDR 0x1fff0000000 +#define CFG_ADDR 0x1fe02000510 +#define HZ 1 * 1000 * 1000 +#define TICK_INT_DIS 0x8000000000000000 + + .globl entry, _entry + + .section ".text", "ax" + .align 8 + .register %g2, #scratch + .register %g3, #scratch + .register %g6, #scratch + .register %g7, #scratch + +/* + * Entry point + * We start execution from here. + */ +_entry: +entry: + ! Set up CPU state + wrpr %g0, PSTATE_PRIV, %pstate + wr %g0, 0, %fprs + wrpr %g0, 0x0, %tl + + ! Extract NWINDOWS from %ver + rdpr %ver, %g1 + and %g1, 0xf, %g1 + dec %g1 + wrpr %g1, 0, %cleanwin + wrpr %g1, 0, %cansave + wrpr %g0, 0, %canrestore + wrpr %g0, 0, %otherwin + wrpr %g0, 0, %wstate + ! disable timer now + setx TICK_INT_DIS, %g2, %g1 + wr %g1, 0, %tick_cmpr + + ! Disable I/D MMUs and caches + stxa %g0, [%g0] ASI_LSU_CONTROL + + ! Check signature "QEMU" + setx CFG_ADDR, %g2, %g5 + mov FW_CFG_SIGNATURE, %g2 + stha %g2, [%g5] ASI_PHYS_BYPASS_EC_E_L + inc %g5 + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g2 + cmp %g2, 'Q' + bne bad_conf + nop + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g2 + cmp %g2, 'E' + bne bad_conf + nop + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g2 + cmp %g2, 'M' + bne bad_conf + nop + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g2 + cmp %g2, 'U' + bne bad_conf + nop + + ! Clear ITLB + mov 6 << 3, %g1 + stxa %g0, [%g1] ASI_IMMU + stxa %g0, [%g1] ASI_DMMU + mov 63 << 3, %g1 +1: stxa %g0, [%g1] ASI_ITLB_DATA_ACCESS + subcc %g1, 1 << 3, %g1 + bpos 1b + nop + + ! Clear DTLB + mov 63 << 3, %g1 +1: stxa %g0, [%g1] ASI_DTLB_DATA_ACCESS + subcc %g1, 1 << 3, %g1 + bpos 1b + nop + + ! Get memory size from configuration device + ! NB: little endian format + mov FW_CFG_RAM_SIZE, %g2 + dec %g5 + stha %g2, [%g5] ASI_PHYS_BYPASS_EC_E_L + inc %g5 + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 8, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 16, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 24, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 32, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 40, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 48, %g3 + or %g3, %g4, %g4 + + lduba [%g5] ASI_PHYS_BYPASS_EC_E, %g3 + sllx %g3, 56, %g3 + or %g3, %g4, %g1 + ! %g1 contains end of memory + + setx _end, %g7, %g3 + set 0x7ffff, %g2 + add %g3, %g2, %g3 + andn %g3, %g2, %g3 + setx _data, %g7, %g2 + sub %g3, %g2, %g2 + sub %g1, %g2, %g2 ! %g2 = start of private memory + mov %g2, %l0 + + ! setup .data & .bss + setx _data, %g7, %g4 + sub %g3, %g4, %g5 + srlx %g5, 19, %g6 ! %g6 = # of 512k .bss pages + set 0xc0000000, %g3 + sllx %g3, 32, %g3 + or %g3, 0x76, %g3 + ! valid, 512k, locked, cacheable(I/E/C), priv, writable + set 48, %g7 +1: stxa %g4, [%g7] ASI_DMMU ! vaddr = _data + N * 0x80000, ctx=0 + or %g2, %g3, %g5 + ! paddr = start_mem + N * 0x80000 + stxa %g5, [%g0] ASI_DTLB_DATA_IN + set 0x80000, %g5 + add %g2, %g5, %g2 + add %g4, %g5, %g4 + deccc %g6 + bne 1b + nop + + ! setup .rodata, also make .text readable + setx _data, %g7, %g5 + setx _start, %g7, %g4 + sub %g5, %g4, %g5 + srlx %g5, 19, %g6 ! %g6 = # of 512k .rodata pages + set 48, %g7 + set 0x80000, %g5 + setx PROM_ADDR, %l1, %l2 +1: stxa %g4, [%g7] ASI_DMMU ! vaddr = _rodata, ctx=0 + set 0xc0000000, %g3 + sllx %g3, 32, %g3 + or %g3, 0x74, %g3 + or %l2, %g3, %g3 + ! valid, 512k, locked, cacheable(I/E/C), priv + ! paddr = _rodata + N * 0x10000 + stxa %g3, [%g0] ASI_DTLB_DATA_IN + add %g4, %g5, %g4 + deccc %g6 + bne 1b + add %l2, %g5, %l2 + + membar #Sync + + setx _start, %g7, %g4 + setx _rodata, %g7, %g5 + sub %g5, %g4, %g5 + set 0x7ffff, %g7 + add %g5, %g7, %g5 ! round to 512k + srlx %g5, 19, %g6 ! %g6 = # of 512k .text pages + set 0x80000, %g5 + set 48, %g7 + setx PROM_ADDR, %l1, %l2 +1: stxa %g4, [%g7] ASI_IMMU ! vaddr = _start, ctx=0 + set 0xc0000000, %g3 + sllx %g3, 32, %g3 + or %g3, 0x74, %g3 + or %l2, %g3, %g3 + ! valid, 512k, locked, cacheable(I/E/C), priv + ! paddr = _start + N * 0x80000 + stxa %g3, [%g0] ASI_ITLB_DATA_IN + add %g4, %g5, %g4 + deccc %g6 + bne 1b + add %l2, %g5, %l2 + + flush %g4 + + mov %g1, %g3 + + set 8, %g2 + sta %g0, [%g2] ASI_DMMU ! set primary ctx=0 + + ! Enable I/D MMUs and caches + setx lowmem, %g2, %g1 + set LSU_CONTROL_DM|LSU_CONTROL_IM|LSU_CONTROL_DC|LSU_CONTROL_IC, %g2 + jmp %g1 + stxa %g2, [%g0] ASI_LSU_CONTROL + +lowmem: + /* Copy the DATA section from ROM. */ + setx _data - 8, %o7, %o0 ! First address of DATA + setx _bss, %o7, %o1 ! Last address of DATA + setx _start, %o7, %o2 + sub %o0, %o2, %o2 ! _data - _start + setx PROM_ADDR, %o7, %o3 + add %o3, %o2, %o2 ! PROM_ADDR + (_data - _start) + ba 2f + nop +1: + ldxa [%o2] ASI_PHYS_BYPASS_EC_E, %g1 + stx %g1, [%o0] +2: + add %o2, 0x8, %o2 + subcc %o0, %o1, %g0 + bl 1b + add %o0, 0x8, %o0 + + /* Zero out our BSS section. */ + setx _bss - 8, %o7, %o0 ! First address of BSS + setx _end - 8, %o7, %o1 ! Last address of BSS + ba 2f + nop +1: + stx %g0, [%o0] +2: + subcc %o0, %o1, %g0 + bl 1b + add %o0, 0x8, %o0 + + setx trap_table, %g2, %g1 + wrpr %g1, %tba + + setx qemu_mem_size, %g7, %g1 + stx %g3, [%g1] + + setx _data, %g7, %g1 ! Store va->pa conversion factor + sub %g1, %l0, %g2 + setx va_shift, %g7, %g1 + stx %g2, [%g1] + + /* Finally, turn on traps so that we can call c-code. */ + wrpr %g0, (PSTATE_PRIV|PSTATE_PEF|PSTATE_IE), %pstate + + ! 100 Hz timer + setx TICK_INT_DIS, %g2, %g1 + rd %tick, %g2 + andn %g2, %g1, %g2 + set HZ, %g1 + add %g1, %g2, %g1 + wr %g1, 0, %tick_cmpr + + /* Switch to our main context. + * Main context is statically defined in C. + */ + + call __switch_context_nosave + nop + + /* We get here when the main context switches back to + * the boot context. + */ +bad_conf: + b bad_conf + nop diff --git a/qemu/roms/openbios/arch/sparc64/init.fs b/qemu/roms/openbios/arch/sparc64/init.fs new file mode 100644 index 000000000..eb6c9da52 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/init.fs @@ -0,0 +1,61 @@ +\ va>tte-data defer MMU virtual to physical address hook for Solaris +\ We need to make sure this is in the global wordlist +active-package 0 active-package! +defer va>tte-data +0 to va>tte-data +active-package! + +:noname + ." Type 'help' for detailed information" cr + \ ." boot secondary slave cdrom: " cr + \ ." 0 > boot hd:2,\boot\vmlinuz root=/dev/hda2" cr + ; DIAG-initializer + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +:noname + set-defaults +; PREPOST-initializer + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + +; SYSTEM-initializer + +\ use the tty interface if available +: activate-tty-interface + " /packages/terminal-emulator" find-dev if drop + then +; + +device-end + +: rmap@ ( virt -- rmentry ) + drop 0 + ; + +\ Load VGA FCode driver blob +[IFDEF] CONFIG_DRIVER_VGA + -1 value vga-driver-fcode + " QEMU,VGA.bin" $encode-file to vga-driver-fcode +[THEN] diff --git a/qemu/roms/openbios/arch/sparc64/ldscript b/qemu/roms/openbios/arch/sparc64/ldscript new file mode 100644 index 000000000..54288e825 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/ldscript @@ -0,0 +1,67 @@ +OUTPUT_FORMAT(elf64-sparc) +OUTPUT_ARCH(sparc:v9) + +/* QEMU ELF loader can't handle very complex files, so we put ELFBoot +info to rodata and put initctx to data.*/ + +ENTRY(trap_table) + +/* Initial load address + */ +BASE_ADDR = 0x00000000ffd00000; + +/* 16KB stack */ +STACK_SIZE = 16384; +IOMEM_SIZE = 256 * 1024 + 768 * 1024; + +SECTIONS +{ + . = BASE_ADDR; + + /* Start of the program. + * Now the version string is in the note, we must include it + * in the program. Otherwise we lose the string after relocation. */ + _start = .; + + /* Normal sections */ + .text ALIGN(524288): { + *(.text.vectors) + *(.text) + *(.text.*) + } + .rodata ALIGN(524288): { + _rodata = .; + sound_drivers_start = .; + *(.rodata.sound_drivers) + sound_drivers_end = .; + *(.rodata) + *(.rodata.*) + *(.note.ELFBoot) + } + .data ALIGN(524288): { + _data = .; + *(.data) + *(.data.*) + } + + .bss ALIGN(4096): { + _bss = .; + *(.bss) + *(.bss.*) + *(COMMON) + + _stack = .; + . += STACK_SIZE; + . = ALIGN(16); + _estack = .; + } + + . = ALIGN(4096); + _end = .; + _iomem = _end + IOMEM_SIZE; + + /* We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + + /DISCARD/ : { *(.comment*) *(.note.*) } +} diff --git a/qemu/roms/openbios/arch/sparc64/lib.c b/qemu/roms/openbios/arch/sparc64/lib.c new file mode 100644 index 000000000..e9101af52 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/lib.c @@ -0,0 +1,508 @@ +/* lib.c + * tag: simple function library + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libc/vsprintf.h" +#include "libopenbios/bindings.h" +#include "spitfire.h" +#include "libopenbios/sys_info.h" +#include "boot.h" + +#include "arch/sparc64/ofmem_sparc64.h" + +/* Format a string and print it on the screen, just like the libc + * function printf. + */ +int printk( const char *fmt, ... ) +{ + char *p, buf[512]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) + putchar(*p); + return i; +} + +/* Private functions for mapping between physical/virtual addresses */ +phys_addr_t +va2pa(unsigned long va) +{ + if ((va >= (unsigned long)&_start) && + (va < (unsigned long)&_end)) + return va - va_shift; + else + return va; +} + +unsigned long +pa2va(phys_addr_t pa) +{ + if ((pa + va_shift >= (unsigned long)&_start) && + (pa + va_shift < (unsigned long)&_end)) + return pa + va_shift; + else + return pa; +} + +void *malloc(int size) +{ + return ofmem_malloc(size); +} + +void* realloc( void *ptr, size_t size ) +{ + return ofmem_realloc(ptr, size); +} + +void free(void *ptr) +{ + ofmem_free(ptr); +} + +static void +mmu_open(void) +{ + RET(-1); +} + +static void +mmu_close(void) +{ +} + +void ofmem_walk_boot_map(translation_entry_cb cb) +{ + unsigned long phys, virt, size, mode, data, mask; + unsigned int i; + + for (i = 0; i < 64; i++) { + data = spitfire_get_dtlb_data(i); + if (data & SPITFIRE_TTE_VALID) { + switch ((data >> 61) & 3) { + default: + case 0x0: /* 8k */ + mask = 0xffffffffffffe000ULL; + size = PAGE_SIZE_8K; + break; + case 0x1: /* 64k */ + mask = 0xffffffffffff0000ULL; + size = PAGE_SIZE_64K; + break; + case 0x2: /* 512k */ + mask = 0xfffffffffff80000ULL; + size = PAGE_SIZE_512K; + break; + case 0x3: /* 4M */ + mask = 0xffffffffffc00000ULL; + size = PAGE_SIZE_4M; + break; + } + + virt = spitfire_get_dtlb_tag(i); + virt &= mask; + + /* extract 41bit physical address */ + phys = data & 0x000001fffffff000ULL; + phys &= mask; + + mode = data & 0xfff; + + cb(phys, virt, size, mode); + } + } +} + +/* + 3.6.5 translate + ( virt -- false | phys.lo ... phys.hi mode true ) +*/ +static void +mmu_translate(void) +{ + ucell virt, mode; + phys_addr_t phys; + + virt = POP(); + + phys = ofmem_translate(virt, &mode); + + if (phys != -1UL) { + PUSH(phys & 0xffffffff); + PUSH(phys >> 32); + PUSH(mode); + PUSH(-1); + } + else { + PUSH(0); + } +} + +/* + * D5.3 pgmap@ ( va -- tte ) + */ +static void +pgmap_fetch(void) +{ + unsigned long va, tte_data; + + va = POP(); + + tte_data = find_tte(va); + if (tte_data == -1) + goto error; + + /* return tte_data */ + PUSH(tte_data); + return; + +error: + /* If we get here, there was no entry */ + PUSH(0); +} + +/* + ( index tte_data vaddr -- ? ) +*/ +static void +dtlb_load(void) +{ + unsigned long vaddr, tte_data, idx; + + vaddr = POP(); + tte_data = POP(); + idx = POP(); + dtlb_load3(vaddr, tte_data, idx); +} + +/* MMU D-TLB miss handler */ +void +dtlb_miss_handler(void) +{ + unsigned long faultva, tte_data = 0; + + /* Grab fault address from MMU and round to nearest 8k page */ + faultva = dtlb_faultva(); + faultva >>= 13; + faultva <<= 13; + + /* If a valid va>tte-data routine has been set, invoke that Forth xt instead */ + if (va2ttedata && *va2ttedata != 0) { + + /* va>tte-data ( addr cnum -- false | tte-data true ) */ + PUSH(faultva); + PUSH(0); + enterforth(*va2ttedata); + + /* Check the result first... */ + tte_data = POP(); + if (!tte_data) { + bug(); + } else { + /* Grab the real data */ + tte_data = POP(); + } + } else { + /* Search the ofmem linked list for this virtual address */ + tte_data = find_tte(faultva); + } + + if (tte_data) { + /* Update MMU */ + dtlb_load2(faultva, tte_data); + } else { + /* If we got here, there was no translation so fail */ + bug(); + } + +} + +/* + ( index tte_data vaddr -- ? ) +*/ +static void +itlb_load(void) +{ + unsigned long vaddr, tte_data, idx; + + vaddr = POP(); + tte_data = POP(); + idx = POP(); + itlb_load3(vaddr, tte_data, idx); +} + +/* MMU I-TLB miss handler */ +void +itlb_miss_handler(void) +{ + unsigned long faultva, tte_data = 0; + + /* Grab fault address from MMU and round to nearest 8k page */ + faultva = itlb_faultva(); + faultva >>= 13; + faultva <<= 13; + + /* If a valid va>tte-data routine has been set, invoke that Forth xt instead */ + if (va2ttedata && *va2ttedata != 0) { + + /* va>tte-data ( addr cnum -- false | tte-data true ) */ + PUSH(faultva); + PUSH(0); + enterforth(*va2ttedata); + + /* Check the result first... */ + tte_data = POP(); + if (!tte_data) { + bug(); + } else { + /* Grab the real data */ + tte_data = POP(); + } + } else { + /* Search the ofmem linked list for this virtual address */ + tte_data = find_tte(faultva); + } + + if (tte_data) { + /* Update MMU */ + itlb_load2(faultva, tte_data); + } else { + /* If we got here, there was no translation so fail */ + bug(); + } +} + +/* + 3.6.5 map + ( phys.lo ... phys.hi virt size mode -- ) +*/ +static void +mmu_map(void) +{ + ucell virt, size, mode; + phys_addr_t phys; + + mode = POP(); + size = POP(); + virt = POP(); + phys = POP(); + phys <<= 32; + phys |= POP(); + + ofmem_map(phys, virt, size, mode); +} + +/* + 3.6.5 unmap + ( virt size -- ) +*/ +static void +mmu_unmap(void) +{ + ucell virt, size; + + size = POP(); + virt = POP(); + ofmem_unmap(virt, size); +} + +/* + 3.6.5 claim + ( virt size align -- base ) +*/ +static void +mmu_claim(void) +{ + ucell virt=-1UL, size, align; + + align = POP(); + size = POP(); + if (!align) { + virt = POP(); + } + + virt = ofmem_claim_virt(virt, size, align); + + PUSH(virt); +} + +/* + 3.6.5 release + ( virt size -- ) +*/ +static void +mmu_release(void) +{ + ucell virt, size; + + size = POP(); + virt = POP(); + + ofmem_release_virt(virt, size); +} + +/* ( phys size align --- base ) */ +static void +mem_claim( void ) +{ + ucell size, align; + phys_addr_t phys=-1UL; + + align = POP(); + size = POP(); + if (!align) { + phys = POP(); + phys <<= 32; + phys |= POP(); + } + + phys = ofmem_claim_phys(phys, size, align); + + PUSH(phys & 0xffffffffUL); + PUSH(phys >> 32); +} + +/* ( phys size --- ) */ +static void +mem_release( void ) +{ + phys_addr_t phys; + ucell size; + + size = POP(); + phys = POP(); + phys <<= 32; + phys |= POP(); + + ofmem_release_phys(phys, size); +} + +/* ( name-cstr phys size align --- phys ) */ +static void +mem_retain ( void ) +{ + ucell size, align; + phys_addr_t phys=-1UL; + + align = POP(); + size = POP(); + if (!align) { + phys = POP(); + phys <<= 32; + phys |= POP(); + } + + /* Currently do nothing with the name */ + POP(); + + phys = ofmem_retain(phys, size, align); + + PUSH(phys & 0xffffffffUL); + PUSH(phys >> 32); +} + +/* ( virt size align -- baseaddr|-1 ) */ +static void +ciface_claim( void ) +{ + ucell align = POP(); + ucell size = POP(); + ucell virt = POP(); + ucell ret = ofmem_claim( virt, size, align ); + + /* printk("ciface_claim: %08x %08x %x\n", virt, size, align ); */ + PUSH( ret ); +} + +/* ( virt size -- ) */ +static void +ciface_release( void ) +{ + ucell size = POP(); + ucell virt = POP(); + ofmem_release(virt, size); +} + +DECLARE_NODE(memory, INSTALL_OPEN, 0, "/memory"); + +NODE_METHODS( memory ) = { + { "claim", mem_claim }, + { "release", mem_release }, + { "SUNW,retain", mem_retain }, +}; + +DECLARE_NODE(mmu, INSTALL_OPEN, 0, "/virtual-memory"); + +NODE_METHODS(mmu) = { + { "open", mmu_open }, + { "close", mmu_close }, + { "translate", mmu_translate }, + { "SUNW,dtlb-load", dtlb_load }, + { "SUNW,itlb-load", itlb_load }, + { "map", mmu_map }, + { "unmap", mmu_unmap }, + { "claim", mmu_claim }, + { "release", mmu_release }, +}; + +void ob_mmu_init(const char *cpuname, uint64_t ram_size) +{ + /* memory node */ + REGISTER_NODE_METHODS(memory, "/memory"); + + /* MMU node */ + REGISTER_NODE_METHODS(mmu, "/virtual-memory"); + + ofmem_register(find_dev("/memory"), find_dev("/virtual-memory")); + + push_str("/chosen"); + fword("find-device"); + + push_str("/virtual-memory"); + fword("open-dev"); + fword("encode-int"); + push_str("mmu"); + fword("property"); + + push_str("/memory"); + fword("find-device"); + + /* All memory: 0 to RAM_size */ + PUSH(0); + fword("encode-int"); + PUSH(0); + fword("encode-int"); + fword("encode+"); + PUSH((int)(ram_size >> 32)); + fword("encode-int"); + fword("encode+"); + PUSH((int)(ram_size & 0xffffffff)); + fword("encode-int"); + fword("encode+"); + push_str("reg"); + fword("property"); + + push_str("/openprom/client-services"); + fword("find-device"); + bind_func("cif-claim", ciface_claim); + bind_func("cif-release", ciface_release); + + /* Other MMU functions */ + PUSH(0); + fword("active-package!"); + bind_func("pgmap@", pgmap_fetch); + + /* Find address of va2ttedata defer word contents for MMU miss handlers */ + va2ttedata = (ucell *)findword("va>tte-data"); + va2ttedata++; +} diff --git a/qemu/roms/openbios/arch/sparc64/linux_load.c b/qemu/roms/openbios/arch/sparc64/linux_load.c new file mode 100644 index 000000000..e3afc2db8 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/linux_load.c @@ -0,0 +1,653 @@ +/* + * Linux/i386 loader + * Supports bzImage, zImage and Image format. + * + * Based on work by Steve Gehlbach. + * Portions are taken from mkelfImage. + * + * 2003-09 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "libc/diskio.h" +#include "boot.h" + +#define printf printk +#define debug printk +#define strtoull_with_suffix strtol + +#define LINUX_PARAM_LOC 0x90000 +#define COMMAND_LINE_LOC 0x91000 +#define GDT_LOC 0x92000 +#define STACK_LOC 0x93000 + +#define E820MAX 32 /* number of entries in E820MAP */ +struct e820entry { + unsigned long long addr; /* start of memory segment */ + unsigned long long size; /* size of memory segment */ + unsigned long type; /* type of memory segment */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */ +#define E820_NVS 4 +}; + +/* The header of Linux/i386 kernel */ +struct linux_header { + uint8_t reserved1[0x1f1]; /* 0x000 */ + uint8_t setup_sects; /* 0x1f1 */ + uint16_t root_flags; /* 0x1f2 */ + uint8_t reserved2[6]; /* 0x1f4 */ + uint16_t vid_mode; /* 0x1fa */ + uint16_t root_dev; /* 0x1fc */ + uint16_t boot_sector_magic; /* 0x1fe */ + /* 2.00+ */ + uint8_t reserved3[2]; /* 0x200 */ + uint8_t header_magic[4]; /* 0x202 */ + uint16_t protocol_version; /* 0x206 */ + uint32_t realmode_swtch; /* 0x208 */ + uint16_t start_sys; /* 0x20c */ + uint16_t kver_addr; /* 0x20e */ + uint8_t type_of_loader; /* 0x210 */ + uint8_t loadflags; /* 0x211 */ + uint16_t setup_move_size; /* 0x212 */ + uint32_t code32_start; /* 0x214 */ + uint32_t ramdisk_image; /* 0x218 */ + uint32_t ramdisk_size; /* 0x21c */ + uint8_t reserved4[4]; /* 0x220 */ + /* 2.01+ */ + uint16_t heap_end_ptr; /* 0x224 */ + uint8_t reserved5[2]; /* 0x226 */ + /* 2.02+ */ + uint32_t cmd_line_ptr; /* 0x228 */ + /* 2.03+ */ + uint32_t initrd_addr_max; /* 0x22c */ +} __attribute__ ((packed)); + + +/* Paramters passed to 32-bit part of Linux + * This is another view of the structure above.. */ +struct linux_params { + uint8_t orig_x; /* 0x00 */ + uint8_t orig_y; /* 0x01 */ + uint16_t ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */ + uint16_t orig_video_page; /* 0x04 */ + uint8_t orig_video_mode; /* 0x06 */ + uint8_t orig_video_cols; /* 0x07 */ + uint16_t unused2; /* 0x08 */ + uint16_t orig_video_ega_bx; /* 0x0a */ + uint16_t unused3; /* 0x0c */ + uint8_t orig_video_lines; /* 0x0e */ + uint8_t orig_video_isVGA; /* 0x0f */ + uint16_t orig_video_points; /* 0x10 */ + + /* VESA graphic mode -- linear frame buffer */ + uint16_t lfb_width; /* 0x12 */ + uint16_t lfb_height; /* 0x14 */ + uint16_t lfb_depth; /* 0x16 */ + uint32_t lfb_base; /* 0x18 */ + uint32_t lfb_size; /* 0x1c */ + uint16_t cl_magic; /* 0x20 */ +#define CL_MAGIC_VALUE 0xA33F + uint16_t cl_offset; /* 0x22 */ + uint16_t lfb_linelength; /* 0x24 */ + uint8_t red_size; /* 0x26 */ + uint8_t red_pos; /* 0x27 */ + uint8_t green_size; /* 0x28 */ + uint8_t green_pos; /* 0x29 */ + uint8_t blue_size; /* 0x2a */ + uint8_t blue_pos; /* 0x2b */ + uint8_t rsvd_size; /* 0x2c */ + uint8_t rsvd_pos; /* 0x2d */ + uint16_t vesapm_seg; /* 0x2e */ + uint16_t vesapm_off; /* 0x30 */ + uint16_t pages; /* 0x32 */ + uint8_t reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */ + + //struct apm_bios_info apm_bios_info; /* 0x40 */ + uint8_t apm_bios_info[0x40]; + //struct drive_info_struct drive_info; /* 0x80 */ + uint8_t drive_info[0x20]; + //struct sys_desc_table sys_desc_table; /* 0xa0 */ + uint8_t sys_desc_table[0x140]; + uint32_t alt_mem_k; /* 0x1e0 */ + uint8_t reserved5[4]; /* 0x1e4 */ + uint8_t e820_map_nr; /* 0x1e8 */ + uint8_t reserved6[9]; /* 0x1e9 */ + uint16_t mount_root_rdonly; /* 0x1f2 */ + uint8_t reserved7[4]; /* 0x1f4 */ + uint16_t ramdisk_flags; /* 0x1f8 */ +#define RAMDISK_IMAGE_START_MASK 0x07FF +#define RAMDISK_PROMPT_FLAG 0x8000 +#define RAMDISK_LOAD_FLAG 0x4000 + uint8_t reserved8[2]; /* 0x1fa */ + uint16_t orig_root_dev; /* 0x1fc */ + uint8_t reserved9[1]; /* 0x1fe */ + uint8_t aux_device_info; /* 0x1ff */ + uint8_t reserved10[2]; /* 0x200 */ + uint8_t param_block_signature[4]; /* 0x202 */ + uint16_t param_block_version; /* 0x206 */ + uint8_t reserved11[8]; /* 0x208 */ + uint8_t loader_type; /* 0x210 */ +#define LOADER_TYPE_LOADLIN 1 +#define LOADER_TYPE_BOOTSECT_LOADER 2 +#define LOADER_TYPE_SYSLINUX 3 +#define LOADER_TYPE_ETHERBOOT 4 +#define LOADER_TYPE_KERNEL 5 + uint8_t loader_flags; /* 0x211 */ + uint8_t reserved12[2]; /* 0x212 */ + uint32_t kernel_start; /* 0x214 */ + uint32_t initrd_start; /* 0x218 */ + uint32_t initrd_size; /* 0x21c */ + uint8_t reserved12_5[8]; /* 0x220 */ + uint32_t cmd_line_ptr; /* 0x228 */ + uint8_t reserved13[164]; /* 0x22c */ + struct e820entry e820_map[E820MAX]; /* 0x2d0 */ + uint8_t reserved16[688]; /* 0x550 */ +#define COMMAND_LINE_SIZE 256 + /* Command line is copied here by 32-bit i386/kernel/head.S. + * So I will follow the boot protocol, rather than putting it + * directly here. --ts1 */ + uint8_t command_line[COMMAND_LINE_SIZE]; /* 0x800 */ + uint8_t reserved17[1792]; /* 0x900 - 0x1000 */ +}; + +static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + long long fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} + +/* Load the first part the file and check if it's Linux */ +static uint32_t load_linux_header(struct linux_header *hdr) +{ + int load_high; + uint32_t kern_addr; + + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { + debug("Can't read Linux header\n"); + return 0; + } + if (hdr->boot_sector_magic != 0xaa55) { + debug("Not a Linux kernel image\n"); + return 0; + } + + /* Linux is found. Print some information */ + if (memcmp(hdr->header_magic, "HdrS", 4) != 0) { + /* This may be floppy disk image or something. + * Perform a simple (incomplete) sanity check. */ + if (hdr->setup_sects >= 16 + || file_size() - (hdr->setup_sects<<9) >= 512<<10) { + debug("This looks like a bootdisk image but not like Linux...\n"); + return 0; + } + + printf("Possible very old Linux"); + /* This kernel does not even have a protocol version. + * Force the value. */ + hdr->protocol_version = 0; /* pre-2.00 */ + } else + printf("Found Linux"); + if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { + char kver[256]; + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { + kver[255] = 0; + printf(" version %s", kver); + } + } + debug(" (protocol %#x)", hdr->protocol_version); + load_high = 0; + if (hdr->protocol_version >= 0x200) { + debug(" (loadflags %#x)", hdr->loadflags); + load_high = hdr->loadflags & 1; + } + if (load_high) { + printf(" bzImage"); + kern_addr = 0x100000; + } else { + printf(" zImage or Image"); + kern_addr = 0x1000; + } + printf(".\n"); + + return kern_addr; +} + +/* Set up parameters for 32-bit kernel */ +static void +init_linux_params(struct linux_params *params, struct linux_header *hdr) +{ + debug("Setting up paramters at %#lx\n", virt_to_phys(params)); + memset(params, 0, sizeof *params); + + /* Copy some useful values from header */ + params->mount_root_rdonly = hdr->root_flags; + params->orig_root_dev = hdr->root_dev; + + /* Video parameters. + * This assumes we have VGA in standard 80x25 text mode, + * just like our vga.c does. + * Cursor position is filled later to allow some more printf's. */ + params->orig_video_mode = 3; + params->orig_video_cols = 80; + params->orig_video_lines = 25; + params->orig_video_isVGA = 1; + params->orig_video_points = 16; + + params->loader_type = 0xff; /* Unregistered Linux loader */ +} + +/* Memory map */ +static void +set_memory_size(struct linux_params *params, struct sys_info *info) +{ + int i; + uint64_t end; + uint32_t ramtop = 0; + struct e820entry *linux_map; + struct memrange *filo_map; + + linux_map = params->e820_map; + filo_map = info->memrange; + for (i = 0; i < info->n_memranges; i++, linux_map++, filo_map++) { + if (i < E820MAX) { + /* Convert to BIOS e820 style */ + linux_map->addr = filo_map->base; + linux_map->size = filo_map->size; + linux_map->type = E820_RAM; + debug("%016Lx - %016Lx\n", linux_map->addr, + linux_map->addr + linux_map->size); + params->e820_map_nr = i+1; + } + + /* Find out top of RAM. XXX This ignores hole above 1MB */ + end = filo_map->base + filo_map->size; + if (end < (1ULL << 32)) { /* don't count memory above 4GB */ + if (end > ramtop) + ramtop = (uint32_t) end; + } + } + debug("ramtop=%#x\n", ramtop); + /* Size of memory above 1MB in KB */ + params->alt_mem_k = (ramtop - (1<<20)) >> 10; + /* old style, 64MB max */ + if (ramtop >= (64<<20)) + params->ext_mem_k = (63<<10); + else + params->ext_mem_k = params->alt_mem_k; + debug("ext_mem_k=%d, alt_mem_k=%d\n", params->ext_mem_k, params->alt_mem_k); +} + +/* + * Parse command line + * Some parameters, like initrd=<file>, are not passed to kernel, + * we are responsible to process them. + * Parameters for kernel are copied to kern_cmdline. Returns name of initrd. + */ +static char *parse_command_line(const char *orig_cmdline, char *kern_cmdline) +{ + const char *start, *sep, *end, *val; + char name[64]; + unsigned long len; + int k_len; + int to_kern; + char *initrd = NULL; + int toolong = 0; + + forced_memsize = 0; + + if (!orig_cmdline) { + *kern_cmdline = '\0'; + return NULL; + } + + k_len = 0; + debug("original command line: \"%s\"\n", orig_cmdline); + debug("kernel command line at %#lx\n", virt_to_phys(kern_cmdline)); + + start = orig_cmdline; + while (*start == ' ') + start++; + while (*start) { + end = strchr(start, ' '); + if (!end) + end = start + strlen(start); + sep = strchr(start, '='); + if (!sep || sep > end) + sep = end; + len = sep - start; + if (len >= sizeof(name)) + len = sizeof(name) - 1; + memcpy(name, start, len); + name[len] = 0; + + if (*sep == '=') { + val = sep + 1; + len = end - val; + } else { + val = NULL; + len = 0; + } + + /* Only initrd= and mem= are handled here. vga= is not, + * which I believe is a paramter to the realmode part of Linux, + * which we don't execute. */ + if (strcmp(name, "initrd") == 0) { + if (!val) + printf("Missing filename to initrd parameter\n"); + else { + initrd = malloc(len + 1); + memcpy(initrd, val, len); + initrd[len] = 0; + debug("initrd=%s\n", initrd); + } + /* Don't pass this to kernel */ + to_kern = 0; + } else if (strcmp(name, "mem") == 0) { + if (!val) + printf("Missing value for mem parameter\n"); + else { + forced_memsize = strtoull_with_suffix(val, (char**)&val, 0); + if (forced_memsize == 0) + printf("Invalid mem option, ignored\n"); + if (val != end) { + printf("Garbage after mem=<size>, ignored\n"); + forced_memsize = 0; + } + debug("mem=%llu\n", (unsigned long long)forced_memsize); + } + /* mem= is for both loader and kernel */ + to_kern = 1; + } else + to_kern = 1; + + if (to_kern) { + /* Copy to kernel command line buffer */ + if (k_len != 0) + kern_cmdline[k_len++] = ' '; /* put separator */ + len = end - start; + if (k_len + len >= COMMAND_LINE_SIZE) { + len = COMMAND_LINE_SIZE - k_len - 1; + if (!toolong) { + printf("Kernel command line is too long; truncated to " + "%d bytes\n", COMMAND_LINE_SIZE-1); + toolong = 1; + } + } + memcpy(kern_cmdline + k_len, start, len); + k_len += len; + } + + start = end; + while (*start == ' ') + start++; + } + kern_cmdline[k_len] = 0; + debug("kernel command line (%d bytes): \"%s\"\n", k_len, kern_cmdline); + + return initrd; +} + +/* Set command line location */ +static void set_command_line_loc(struct linux_params *params, + struct linux_header *hdr) +{ + if (hdr->protocol_version >= 0x202) { + /* new style */ + params->cmd_line_ptr = COMMAND_LINE_LOC; + } else { + /* old style */ + params->cl_magic = CL_MAGIC_VALUE; + params->cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC; + } +} + +/* Load 32-bit part of kernel */ +static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) +{ + uint32_t kern_offset, kern_size; + + if (hdr->setup_sects == 0) + hdr->setup_sects = 4; + kern_offset = (hdr->setup_sects + 1) * 512; + seek_io(fd, kern_offset); + kern_size = file_size() - kern_offset; + debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as kernel; " + "specify the image size\n"); + return 0; + } +#endif + + printf("Loading kernel... "); + if ((uint32_t)read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { + printf("Can't read kernel\n"); + return 0; + } + printf("ok\n"); + + return kern_size; +} + +static int load_initrd(struct linux_header *hdr, uint32_t kern_end, + struct linux_params *params, const char *initrd_file) +{ + uint32_t max; + uint32_t start, end, size; + uint64_t forced; + + fd = open_io(initrd_file); + if (fd == -1) { + printf("Can't open initrd: %s\n", initrd_file); + return -1; + } + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as initrd; " + "specify the image size\n"); + return -1; + } +#endif + + size = file_size(); + + + /* Find out the kernel's restriction on how high the initrd can be + * placed */ + if (hdr->protocol_version >= 0x203) + max = hdr->initrd_addr_max; + else + max = 0x38000000; /* Hardcoded value for older kernels */ + + /* FILO itself is at the top of RAM. (relocated) + * So, try putting initrd just below us. */ + end = virt_to_phys(_start); + if (end > max) + end = max; + + /* If "mem=" option is given, we have to put the initrd within + * the specified range. */ + if (forced_memsize) { + forced = forced_memsize; + if (forced > max) + forced = max; + /* If the "mem=" is lower, it's easy */ + if (forced <= end) + end = forced; + else { + /* Otherwise, see if we can put it above us */ + if (virt_to_phys(_end) + size <= forced) + end = forced; /* Ok */ + } + } + + start = end - size; + start &= ~0xfff; /* page align */ + end = start + size; + + debug("start=%#x end=%#x\n", start, end); + + if (start < kern_end) { + printf("Initrd is too big to fit in memory\n"); + return -1; + } + + printf("Loading initrd... "); + if ((uint32_t)read_io(fd, phys_to_virt(start), size) != size) { + printf("Can't read initrd\n"); + return -1; + } + printf("ok\n"); + + params->initrd_start = start; + params->initrd_size = size; + + close_io(fd); + + return 0; +} + +static void hardware_setup(void) +{ + /* Disable nmi */ + outb(0x80, 0x70); + + /* Make sure any coprocessor is properly reset.. */ + outb(0, 0xf0); + outb(0, 0xf1); + + /* we're getting screwed again and again by this problem of the 8259. + * so we're going to leave this lying around for inclusion into + * crt0.S on an as-needed basis. + * + * well, that went ok, I hope. Now we have to reprogram the interrupts :-( + * we put them right after the intel-reserved hardware interrupts, at + * int 0x20-0x2F. There they won't mess up anything. Sadly IBM really + * messed this up with the original PC, and they haven't been able to + * rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, + * which is used for the internal hardware interrupts as well. We just + * have to reprogram the 8259's, and it isn't fun. + */ + + outb(0x11, 0x20); /* initialization sequence to 8259A-1 */ + outb(0x11, 0xA0); /* and to 8259A-2 */ + + outb(0x20, 0x21); /* start of hardware int's (0x20) */ + outb(0x28, 0xA1); /* start of hardware int's 2 (0x28) */ + + outb(0x04, 0x21); /* 8259-1 is master */ + outb(0x02, 0xA1); /* 8259-2 is slave */ + + outb(0x01, 0x21); /* 8086 mode for both */ + outb(0x01, 0xA1); + + outb(0xFF, 0xA1); /* mask off all interrupts for now */ + outb(0xFB, 0x21); /* mask all irq's but irq2 which is cascaded */ +} + +/* Start Linux */ +static int start_linux(uint32_t kern_addr) +{ + struct context *ctx; + //extern int cursor_x, cursor_y; + + ctx = init_context(phys_to_virt(STACK_LOC), 4096, 0); + + /* Entry point */ + ctx->pc = kern_addr; + ctx->npc = kern_addr + 4; + + debug("pc=%#x\n", kern_addr); + printf("Jumping to entry point...\n"); + +#ifdef VGA_CONSOLE + /* Update VGA cursor position. + * This must be here because the printf changes the value! */ + params->orig_x = cursor_x; + params->orig_y = cursor_y; +#endif + + /* Go... */ + ctx = switch_to(ctx); + + /* It's impossible but... */ + printf("Returned with o0=%#llx\n", ctx->regs[REG_O0]); + + return ctx->regs[REG_O0]; +} + +int linux_load(struct sys_info *info, const char *file, const char *cmdline) +{ + struct linux_header hdr; + struct linux_params *params; + uint32_t kern_addr, kern_size; + char *initrd_file = NULL; + + fd = open_io(file); + if (fd == -1) + return -1; + + kern_addr = load_linux_header(&hdr); + if (kern_addr == 0) { + close_io(fd); + return LOADER_NOT_SUPPORT; + } + + debug("[sparc64] Booting kernel '%s' ", file); + if (cmdline) + debug("with parameters '%s'\n", cmdline); + else + debug("without parameters.\n"); + + params = phys_to_virt(LINUX_PARAM_LOC); + init_linux_params(params, &hdr); + set_memory_size(params, info); + initrd_file = parse_command_line(cmdline, phys_to_virt(COMMAND_LINE_LOC)); + set_command_line_loc(params, &hdr); + + kern_size = load_linux_kernel(&hdr, kern_addr); + if (kern_size == 0) { + if (initrd_file) + free(initrd_file); + return -1; + } + + if (initrd_file) { + if (load_initrd(&hdr, kern_addr+kern_size, params, initrd_file) + != 0) { + free(initrd_file); + return -1; + } + free(initrd_file); + } + + hardware_setup(); + + start_linux(kern_addr); + return 0; +} diff --git a/qemu/roms/openbios/arch/sparc64/lsu.h b/qemu/roms/openbios/arch/sparc64/lsu.h new file mode 100644 index 000000000..d85c33f24 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/lsu.h @@ -0,0 +1,20 @@ +/* $Id: lsu.h,v 1.2 1997/04/04 00:50:22 davem Exp $ */ +#ifndef _SPARC64_LSU_H +#define _SPARC64_LSU_H + +#include "const.h" + +/* LSU Control Register */ +#define LSU_CONTROL_PM _AC(0x000001fe00000000,UL) /* Phys-watchpoint byte mask*/ +#define LSU_CONTROL_VM _AC(0x00000001fe000000,UL) /* Virt-watchpoint byte mask*/ +#define LSU_CONTROL_PR _AC(0x0000000001000000,UL) /* Phys-rd watchpoint enable*/ +#define LSU_CONTROL_PW _AC(0x0000000000800000,UL) /* Phys-wr watchpoint enable*/ +#define LSU_CONTROL_VR _AC(0x0000000000400000,UL) /* Virt-rd watchpoint enable*/ +#define LSU_CONTROL_VW _AC(0x0000000000200000,UL) /* Virt-wr watchpoint enable*/ +#define LSU_CONTROL_FM _AC(0x00000000000ffff0,UL) /* Parity mask enables. */ +#define LSU_CONTROL_DM _AC(0x0000000000000008,UL) /* Data MMU enable. */ +#define LSU_CONTROL_IM _AC(0x0000000000000004,UL) /* Instruction MMU enable. */ +#define LSU_CONTROL_DC _AC(0x0000000000000002,UL) /* Data cache enable. */ +#define LSU_CONTROL_IC _AC(0x0000000000000001,UL) /* Instruction cache enable.*/ + +#endif /* !(_SPARC64_LSU_H) */ diff --git a/qemu/roms/openbios/arch/sparc64/multiboot.c b/qemu/roms/openbios/arch/sparc64/multiboot.c new file mode 100644 index 000000000..8514ca0a4 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/multiboot.c @@ -0,0 +1,125 @@ +/* Support for Multiboot */ + +#include "config.h" +#include "asm/io.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +struct mbheader { + unsigned int magic, flags, checksum; +}; +const struct mbheader multiboot_header + __attribute__((section (".hdr"))) = +{ + MULTIBOOT_HEADER_MAGIC, + MULTIBOOT_HEADER_FLAGS, + -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) +}; + +/* Multiboot information structure, provided by loader to us */ + +struct multiboot_mmap { + unsigned entry_size; + unsigned base_lo, base_hi; + unsigned size_lo, size_hi; + unsigned type; +}; + +#define MULTIBOOT_MEM_VALID 0x01 +#define MULTIBOOT_BOOT_DEV_VALID 0x02 +#define MULTIBOOT_CMDLINE_VALID 0x04 +#define MULTIBOOT_MODS_VALID 0x08 +#define MULTIBOOT_AOUT_SYMS_VALID 0x10 +#define MULTIBOOT_ELF_SYMS_VALID 0x20 +#define MULTIBOOT_MMAP_VALID 0x40 + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + struct multiboot_info *mbinfo; + struct multiboot_mmap *mbmem; + unsigned mbcount, mbaddr; + unsigned int i; + struct memrange *mmap; + int mmap_count; + module_t *mod; + + if (info->boot_type != 0x2BADB002) + return; + + debug("Using Multiboot information at %#lx\n", info->boot_data); + + mbinfo = phys_to_virt(info->boot_data); + + if (mbinfo->mods_count != 1) { + printf("Multiboot: no dictionary\n"); + return; + } + + mod = (module_t *) mbinfo->mods_addr; + info->dict_start=(unsigned long *)mod->mod_start; + info->dict_end=(unsigned long *)mod->mod_end; + + if (mbinfo->flags & MULTIBOOT_MMAP_VALID) { + /* convert mmap records */ + mbmem = phys_to_virt(mbinfo->mmap_addr); + mbcount = mbinfo->mmap_length / (mbmem->entry_size + 4); + mmap = malloc(mbcount * sizeof(struct memrange)); + mmap_count = 0; + mbaddr = mbinfo->mmap_addr; + for (i = 0; i < mbcount; i++) { + mbmem = phys_to_virt(mbaddr); + debug("%08x%08x %08x%08x (%d)\n", + mbmem->base_hi, + mbmem->base_lo, + mbmem->size_hi, + mbmem->size_lo, + mbmem->type); + if (mbmem->type == 1) { /* Only normal RAM */ + mmap[mmap_count].base = mbmem->base_lo + + (((unsigned long long) mbmem->base_hi) << 32); + mmap[mmap_count].size = mbmem->size_lo + + (((unsigned long long) mbmem->size_hi) << 32); + mmap_count++; + } + mbaddr += mbmem->entry_size + 4; + if (mbaddr >= mbinfo->mmap_addr + mbinfo->mmap_length) + break; + } + /* simple sanity check - there should be at least 2 RAM segments + * (base 640k and extended) */ + if (mmap_count >= 2) + goto got_it; + + printf("Multiboot mmap is broken\n"); + free(mmap); + /* fall back to mem_lower/mem_upper */ + } + + if (mbinfo->flags & MULTIBOOT_MEM_VALID) { + /* use mem_lower and mem_upper */ + mmap_count = 2; + mmap = malloc(2 * sizeof(*mmap)); + mmap[0].base = 0; + mmap[0].size = mbinfo->mem_lower << 10; + mmap[1].base = 1 << 20; /* 1MB */ + mmap[1].size = mbinfo->mem_upper << 10; + goto got_it; + } + + printf("Can't get memory information from Multiboot\n"); + return; + +got_it: + info->memrange = mmap; + info->n_memranges = mmap_count; + + return; +} diff --git a/qemu/roms/openbios/arch/sparc64/multiboot.h b/qemu/roms/openbios/arch/sparc64/multiboot.h new file mode 100644 index 000000000..17cf202ec --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/multiboot.h @@ -0,0 +1,96 @@ +/* multiboot.h + * tag: header for multiboot + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* magic number for multiboot header */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* flags for multiboot header */ +#define MULTIBOOT_HEADER_FLAGS 0x00010003 + +/* magic number passed by multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (8KB). */ +#define STACK_SIZE 0x2000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* We don't want these declarations in boot.S */ + +/* multiboot header */ +typedef struct multiboot_header { + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* symbol table for a.out */ +typedef struct aout_symbol_table { + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* section header table for ELF */ +typedef struct elf_section_header_table { + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* multiboot information */ +typedef struct multiboot_info { + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* module structure */ +typedef struct module { + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map { + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +#endif /* ! ASM */ diff --git a/qemu/roms/openbios/arch/sparc64/ofmem_sparc64.c b/qemu/roms/openbios/arch/sparc64/ofmem_sparc64.c new file mode 100644 index 000000000..bdfaf5636 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/ofmem_sparc64.c @@ -0,0 +1,381 @@ +/* + * <ofmem_sparc64.c> + * + * OF Memory manager + * + * Copyright (C) 1999-2004 Samuel Rydh (samuel@ibrium.se) + * Copyright (C) 2004 Stefan Reinauer + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +#include "arch/sparc64/ofmem_sparc64.h" +#include "spitfire.h" + +#define OF_MALLOC_BASE ((char*)OFMEM + ALIGN_SIZE(sizeof(ofmem_t), 8)) + +#define MEMSIZE (128 * 1024) +static union { + char memory[MEMSIZE]; + ofmem_t ofmem; +} s_ofmem_data; + +#define OFMEM (&s_ofmem_data.ofmem) +#define TOP_OF_RAM (s_ofmem_data.memory + MEMSIZE) + +static retain_t s_retained; +translation_t **g_ofmem_translations = &s_ofmem_data.ofmem.trans; + +ucell *va2ttedata = 0; +extern uint64_t qemu_mem_size; + +static inline size_t ALIGN_SIZE(size_t x, size_t a) +{ + return (x + a - 1) & ~(a-1); +} + +static ucell get_heap_top( void ) +{ + return (ucell)TOP_OF_RAM; +} + +ofmem_t* ofmem_arch_get_private(void) +{ + return OFMEM; +} + +void* ofmem_arch_get_malloc_base(void) +{ + return OF_MALLOC_BASE; +} + +ucell ofmem_arch_get_heap_top(void) +{ + return get_heap_top(); +} + +ucell ofmem_arch_get_virt_top(void) +{ + return (ucell)TOP_OF_RAM; +} + +ucell ofmem_arch_get_iomem_base(void) +{ + /* Currently unused */ + return 0; +} + +ucell ofmem_arch_get_iomem_top(void) +{ + /* Currently unused */ + return 0; +} + +retain_t *ofmem_arch_get_retained(void) +{ + return (&s_retained); +} + +int ofmem_arch_get_translation_entry_size(void) +{ + /* Return size of a single MMU package translation property entry in cells */ + return 3; +} + +void ofmem_arch_create_translation_entry(ucell *transentry, translation_t *t) +{ + /* Generate translation property entry for SPARC. While there is no + formal documentation for this, both Linux kernel and OpenSolaris sources + expect a translation property entry to have the following layout: + + virtual address + length + mode (valid TTE for start of translation region) + */ + + transentry[0] = t->virt; + transentry[1] = t->size; + transentry[2] = t->phys | t->mode | SPITFIRE_TTE_VALID; +} + +/* Return the size of a memory available entry given the phandle in cells */ +int ofmem_arch_get_available_entry_size(phandle_t ph) +{ + if (ph == s_phandle_memory) { + return 1 + ofmem_arch_get_physaddr_cellsize(); + } else { + return 1 + 1; + } +} + +/* Generate memory available property entry for Sparc64 */ +void ofmem_arch_create_available_entry(phandle_t ph, ucell *availentry, phys_addr_t start, ucell size) +{ + int i = 0; + + if (ph == s_phandle_memory) { + i += ofmem_arch_encode_physaddr(availentry, start); + } else { + availentry[i++] = start; + } + + availentry[i] = size; +} + +/* Unmap a set of pages */ +void ofmem_arch_unmap_pages(ucell virt, ucell size) +{ + ucell va; + + /* align address to 8k */ + virt &= ~PAGE_MASK_8K; + + /* align size to 8k */ + size = (size + PAGE_MASK_8K) & ~PAGE_MASK_8K; + + for (va = virt; va < virt + size; va += PAGE_SIZE_8K) { + itlb_demap(va); + dtlb_demap(va); + } +} + +/* Map a set of pages */ +void ofmem_arch_map_pages(phys_addr_t phys, ucell virt, ucell size, ucell mode) +{ + unsigned long tte_data, currsize; + + /* Install locked tlb entries now */ + if (mode & SPITFIRE_TTE_LOCKED) { + + /* aligned to 8k page */ + size = (size + PAGE_MASK_8K) & ~PAGE_MASK_8K; + + while (size > 0) { + currsize = size; + if (currsize >= PAGE_SIZE_4M && + (virt & PAGE_MASK_4M) == 0 && + (phys & PAGE_MASK_4M) == 0) { + currsize = PAGE_SIZE_4M; + tte_data = 6ULL << 60; + } else if (currsize >= PAGE_SIZE_512K && + (virt & PAGE_MASK_512K) == 0 && + (phys & PAGE_MASK_512K) == 0) { + currsize = PAGE_SIZE_512K; + tte_data = 4ULL << 60; + } else if (currsize >= PAGE_SIZE_64K && + (virt & PAGE_MASK_64K) == 0 && + (phys & PAGE_MASK_64K) == 0) { + currsize = PAGE_SIZE_64K; + tte_data = 2ULL << 60; + } else { + currsize = PAGE_SIZE_8K; + tte_data = 0; + } + + tte_data |= phys | mode | SPITFIRE_TTE_VALID; + + itlb_load2(virt, tte_data); + dtlb_load2(virt, tte_data); + + size -= currsize; + phys += currsize; + virt += currsize; + } + } +} + +/************************************************************************/ +/* misc */ +/************************************************************************/ + +int ofmem_arch_get_physaddr_cellsize(void) +{ + return 1; +} + +int ofmem_arch_encode_physaddr(ucell *p, phys_addr_t value) +{ + p[0] = value; + return 1; +} + +ucell ofmem_arch_default_translation_mode( phys_addr_t phys ) +{ + /* Writable, cacheable */ + /* Privileged and not locked */ + return SPITFIRE_TTE_CP | SPITFIRE_TTE_CV | SPITFIRE_TTE_WRITABLE | SPITFIRE_TTE_PRIVILEGED; +} + +ucell ofmem_arch_io_translation_mode( phys_addr_t phys ) +{ + /* Writable, privileged and not locked */ + return SPITFIRE_TTE_CV | SPITFIRE_TTE_WRITABLE | SPITFIRE_TTE_PRIVILEGED; +} + +/* Architecture-specific OFMEM helpers */ +unsigned long +find_tte(unsigned long va) +{ + translation_t *t = *g_ofmem_translations; + unsigned long tte_data; + + /* Search the ofmem linked list for this virtual address */ + while (t != NULL) { + /* Find the correct range */ + if (va >= t->virt && va < (t->virt + t->size)) { + + /* valid tte, 8k size */ + tte_data = SPITFIRE_TTE_VALID; + + /* mix in phys address mode */ + tte_data |= t->mode; + + /* mix in page physical address = t->phys + offset */ + tte_data |= t->phys + (va - t->virt); + + /* return tte_data */ + return tte_data; + } + t = t->next; + } + + /* Couldn't find tte */ + return -1; +} + +/* ITLB handlers */ +void +itlb_load2(unsigned long vaddr, unsigned long tte_data) +{ + asm("stxa %0, [%1] %2\n" + "stxa %3, [%%g0] %4\n" + : : "r" (vaddr), "r" (48), "i" (ASI_IMMU), + "r" (tte_data), "i" (ASI_ITLB_DATA_IN)); +} + +void +itlb_load3(unsigned long vaddr, unsigned long tte_data, + unsigned long tte_index) +{ + asm("stxa %0, [%1] %2\n" + "stxa %3, [%4] %5\n" + : : "r" (vaddr), "r" (48), "i" (ASI_IMMU), + "r" (tte_data), "r" (tte_index << 3), "i" (ASI_ITLB_DATA_ACCESS)); +} + +unsigned long +itlb_faultva(void) +{ + unsigned long faultva; + + asm("ldxa [%1] %2, %0\n" + : "=r" (faultva) + : "r" (48), "i" (ASI_IMMU)); + + return faultva; +} + +void +itlb_demap(unsigned long vaddr) +{ + asm("stxa %0, [%0] %1\n" + : : "r" (vaddr), "i" (ASI_IMMU_DEMAP)); +} + +/* DTLB handlers */ +void +dtlb_load2(unsigned long vaddr, unsigned long tte_data) +{ + asm("stxa %0, [%1] %2\n" + "stxa %3, [%%g0] %4\n" + : : "r" (vaddr), "r" (48), "i" (ASI_DMMU), + "r" (tte_data), "i" (ASI_DTLB_DATA_IN)); +} + +void +dtlb_load3(unsigned long vaddr, unsigned long tte_data, + unsigned long tte_index) +{ + asm("stxa %0, [%1] %2\n" + "stxa %3, [%4] %5\n" + : : "r" (vaddr), "r" (48), "i" (ASI_DMMU), + "r" (tte_data), "r" (tte_index << 3), "i" (ASI_DTLB_DATA_ACCESS)); +} + +unsigned long +dtlb_faultva(void) +{ + unsigned long faultva; + + asm("ldxa [%1] %2, %0\n" + : "=r" (faultva) + : "r" (48), "i" (ASI_DMMU)); + + return faultva; +} + +void +dtlb_demap(unsigned long vaddr) +{ + asm("stxa %0, [%0] %1\n" + : : "r" (vaddr), "i" (ASI_DMMU_DEMAP)); +} + +/************************************************************************/ +/* init / cleanup */ +/************************************************************************/ + +static int remap_page_range( phys_addr_t phys, ucell virt, ucell size, ucell mode ) +{ + ofmem_claim_phys(phys, size, 0); + ofmem_claim_virt(virt, size, 0); + ofmem_map_page_range(phys, virt, size, mode); + if (!(mode & SPITFIRE_TTE_LOCKED)) { + OFMEM_TRACE("remap_page_range clearing translation " FMT_ucellx + " -> " FMT_ucellx " " FMT_ucellx " mode " FMT_ucellx "\n", + virt, phys, size, mode ); + ofmem_arch_unmap_pages(virt, size); + } + return 0; +} + +#define RETAIN_MAGIC 0x1100220033004400 + +void ofmem_init( void ) +{ + retain_t *retained = ofmem_arch_get_retained(); + int i; + + memset(&s_ofmem_data, 0, sizeof(s_ofmem_data)); + s_ofmem_data.ofmem.ramsize = qemu_mem_size; + + /* inherit translations set up by entry.S */ + ofmem_walk_boot_map(remap_page_range); + + /* Map the memory */ + ofmem_map_page_range(PAGE_SIZE, PAGE_SIZE, 0x800000, 0x36); + + if (!(retained->magic == RETAIN_MAGIC)) { + OFMEM_TRACE("ofmem_init: no retained magic found, creating\n"); + retained->magic = RETAIN_MAGIC; + retained->numentries = 0; + } else { + OFMEM_TRACE("ofmem_init: retained magic found, total %lld mappings\n", retained->numentries); + + /* Mark physical addresses as used so they are not reallocated */ + for (i = 0; i < retained->numentries; i++) { + ofmem_claim_phys(retained->retain_phys_range[i].start, + retained->retain_phys_range[i].size, 0); + } + + /* Reset retained area for next reset */ + retained->magic = RETAIN_MAGIC; + retained->numentries = 0; + } +} diff --git a/qemu/roms/openbios/arch/sparc64/openbios.c b/qemu/roms/openbios/arch/sparc64/openbios.c new file mode 100644 index 000000000..4557f7f9f --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/openbios.c @@ -0,0 +1,664 @@ +/* tag: openbios forth environment, executable code + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "drivers/drivers.h" +#include "dict.h" +#include "arch/common/nvram.h" +#include "packages/nvram.h" +#include "libopenbios/sys_info.h" +#include "openbios.h" +#include "drivers/pci.h" +#include "asm/pci.h" +#include "boot.h" +#include "../../drivers/timer.h" // XXX +#define NO_QEMU_PROTOS +#include "arch/common/fw_cfg.h" +#include "arch/sparc64/ofmem_sparc64.h" +#include "spitfire.h" + +#define UUID_FMT "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" + +#define APB_SPECIAL_BASE 0x1fe00000000ULL +#define APB_MEM_BASE 0x1ff00000000ULL + +#define MEMORY_SIZE (512*1024) /* 512K ram for hosted system */ + +// XXX +#define NVRAM_BASE 0x2000 +#define NVRAM_SIZE 0x2000 +#define NVRAM_IDPROM 0x1fd8 +#define NVRAM_IDPROM_SIZE 32 +#define NVRAM_OB_START (0) +#define NVRAM_OB_SIZE ((NVRAM_IDPROM - NVRAM_OB_START) & ~15) + +static uint8_t idprom[NVRAM_IDPROM_SIZE]; + +struct hwdef { + pci_arch_t pci; + uint16_t machine_id_low, machine_id_high; +}; + +static const struct hwdef hwdefs[] = { + { + .pci = { + .name = "SUNW,sabre", + .vendor_id = PCI_VENDOR_ID_SUN, + .device_id = PCI_DEVICE_ID_SUN_SABRE, + .cfg_addr = APB_SPECIAL_BASE + 0x1000000ULL, // PCI bus configuration space + .cfg_data = APB_MEM_BASE, // PCI bus memory space + .cfg_base = APB_SPECIAL_BASE, + .cfg_len = 0x2000000, + .host_pci_base = APB_MEM_BASE, + .pci_mem_base = 0x100000, /* avoid VGA at 0xa0000 */ + .mem_len = 0x10000000, + .io_base = APB_SPECIAL_BASE + 0x2000000ULL, // PCI Bus I/O space + .io_len = 0x10000, + .irqs = { 0, 1, 2, 3 }, + }, + .machine_id_low = 0, + .machine_id_high = 255, + }, +}; + +struct cpudef { + unsigned long iu_version; + const char *name; + unsigned long ecache_associativity; + unsigned long ecache_line_size; + unsigned long ecache_size; + unsigned long num_dtlb_entries; + unsigned long dcache_associativity; + unsigned long dcache_line_size; + unsigned long dcache_size; + unsigned long num_itlb_entries; + unsigned long icache_associativity; + unsigned long icache_line_size; + unsigned long icache_size; +}; + +/* + ( addr -- ? ) +*/ + +extern volatile uint64_t client_tba; + +static void +set_trap_table(void) +{ + unsigned long addr; + + addr = POP(); + + /* Update client_tba to be updated on CIF exit */ + client_tba = addr; +} + +/* Reset control register is defined in 17.2.7.3 of US IIi User Manual */ +static void +sparc64_reset_all(void) +{ + unsigned long addr = 0x1fe0000f020ULL; + unsigned long val = 1 << 29; + + asm("stxa %0, [%1] 0x15\n\t" + : : "r" (val), "r" (addr) : "memory"); +} + +/* PCI Target Address Space Register (see UltraSPARC IIi User's Manual + section 19.3.0.4) */ +#define PBM_PCI_TARGET_AS 0x2028 +#define PBM_PCI_TARGET_AS_CD_ENABLE 0x40 + +static void +sparc64_set_tas_register(unsigned long val) +{ + unsigned long addr = APB_SPECIAL_BASE + PBM_PCI_TARGET_AS; + + asm("stxa %0, [%1] 0x15\n\t" + : : "r" (val), "r" (addr) : "memory"); +} + +static void cpu_generic_init(const struct cpudef *cpu, uint32_t clock_frequency) +{ + unsigned long iu_version; + + push_str("/"); + fword("find-device"); + + fword("new-device"); + + push_str(cpu->name); + fword("device-name"); + + push_str("cpu"); + fword("device-type"); + + asm("rdpr %%ver, %0\n" + : "=r"(iu_version) :); + + PUSH((iu_version >> 48) & 0xff); + fword("encode-int"); + push_str("manufacturer#"); + fword("property"); + + PUSH((iu_version >> 32) & 0xff); + fword("encode-int"); + push_str("implementation#"); + fword("property"); + + PUSH((iu_version >> 24) & 0xff); + fword("encode-int"); + push_str("mask#"); + fword("property"); + + PUSH(9); + fword("encode-int"); + push_str("sparc-version"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("cpuid"); + fword("property"); + + PUSH(0); + fword("encode-int"); + push_str("upa-portid"); + fword("property"); + + PUSH(clock_frequency); + fword("encode-int"); + push_str("clock-frequency"); + fword("property"); + + PUSH(cpu->ecache_associativity); + fword("encode-int"); + push_str("ecache-associativity"); + fword("property"); + + PUSH(cpu->ecache_line_size); + fword("encode-int"); + push_str("ecache-line-size"); + fword("property"); + + PUSH(cpu->ecache_size); + fword("encode-int"); + push_str("ecache-size"); + fword("property"); + + PUSH(cpu->dcache_associativity); + fword("encode-int"); + push_str("dcache-associativity"); + fword("property"); + + PUSH(cpu->dcache_line_size); + fword("encode-int"); + push_str("dcache-line-size"); + fword("property"); + + PUSH(cpu->dcache_size); + fword("encode-int"); + push_str("dcache-size"); + fword("property"); + + PUSH(cpu->icache_associativity); + fword("encode-int"); + push_str("icache-associativity"); + fword("property"); + + PUSH(cpu->ecache_line_size); + fword("encode-int"); + push_str("icache-line-size"); + fword("property"); + + PUSH(cpu->ecache_size); + fword("encode-int"); + push_str("icache-size"); + fword("property"); + + PUSH(cpu->num_itlb_entries); + fword("encode-int"); + push_str("#itlb-entries"); + fword("property"); + + PUSH(cpu->num_dtlb_entries); + fword("encode-int"); + push_str("#dtlb-entries"); + fword("property"); + + fword("finish-device"); + + // Trap table + push_str("/openprom/client-services"); + fword("find-device"); + bind_func("SUNW,set-trap-table", set_trap_table); + + // Reset + bind_func("sparc64-reset-all", sparc64_reset_all); + push_str("' sparc64-reset-all to reset-all"); + fword("eval"); +} + +static const struct cpudef sparc_defs[] = { + { + .iu_version = (0x04ULL << 48) | (0x02ULL << 32), + .name = "FJSV,GP", + }, + { + .iu_version = (0x04ULL << 48) | (0x03ULL << 32), + .name = "FJSV,GPUSK", + }, + { + .iu_version = (0x04ULL << 48) | (0x04ULL << 32), + .name = "FJSV,GPUSC", + }, + { + .iu_version = (0x04ULL << 48) | (0x05ULL << 32), + .name = "FJSV,GPUZC", + }, + { + .iu_version = (0x17ULL << 48) | (0x10ULL << 32), + .name = "SUNW,UltraSPARC", + .ecache_associativity = 1, .ecache_line_size = 0x40, .ecache_size = 0x100000, + .dcache_associativity = 1, .dcache_line_size = 0x20, .dcache_size = 0x4000, + .icache_associativity = 2, .icache_line_size = 0x20, .icache_size = 0x4000, + .num_dtlb_entries = 0x40, .num_itlb_entries = 0x40, + }, + { + .iu_version = (0x17ULL << 48) | (0x11ULL << 32), + .name = "SUNW,UltraSPARC-II", + .ecache_associativity = 1, .ecache_line_size = 0x40, .ecache_size = 0x100000, + .dcache_associativity = 1, .dcache_line_size = 0x20, .dcache_size = 0x4000, + .icache_associativity = 2, .icache_line_size = 0x20, .icache_size = 0x4000, + .num_dtlb_entries = 0x40, .num_itlb_entries = 0x40, + }, + { + .iu_version = (0x17ULL << 48) | (0x12ULL << 32), + .name = "SUNW,UltraSPARC-IIi", + .ecache_associativity = 1, .ecache_line_size = 0x40, .ecache_size = 0x40000, + .dcache_associativity = 1, .dcache_line_size = 0x20, .dcache_size = 0x4000, + .icache_associativity = 2, .icache_line_size = 0x20, .icache_size = 0x4000, + .num_dtlb_entries = 0x40, .num_itlb_entries = 0x40, + }, + { + .iu_version = (0x17ULL << 48) | (0x13ULL << 32), + .name = "SUNW,UltraSPARC-IIe", + }, + { + .iu_version = (0x3eULL << 48) | (0x14ULL << 32), + .name = "SUNW,UltraSPARC-III", + }, + { + .iu_version = (0x3eULL << 48) | (0x15ULL << 32), + .name = "SUNW,UltraSPARC-III+", + }, + { + .iu_version = (0x3eULL << 48) | (0x16ULL << 32), + .name = "SUNW,UltraSPARC-IIIi", + }, + { + .iu_version = (0x3eULL << 48) | (0x18ULL << 32), + .name = "SUNW,UltraSPARC-IV", + }, + { + .iu_version = (0x3eULL << 48) | (0x19ULL << 32), + .name = "SUNW,UltraSPARC-IV+", + }, + { + .iu_version = (0x3eULL << 48) | (0x22ULL << 32), + .name = "SUNW,UltraSPARC-IIIi+", + }, + { + .iu_version = (0x3eULL << 48) | (0x23ULL << 32), + .name = "SUNW,UltraSPARC-T1", + }, + { + .iu_version = (0x3eULL << 48) | (0x24ULL << 32), + .name = "SUNW,UltraSPARC-T2", + }, + { + .iu_version = (0x22ULL << 48) | (0x10ULL << 32), + .name = "SUNW,UltraSPARC", + }, +}; + +static const struct cpudef * +id_cpu(void) +{ + unsigned long iu_version; + unsigned int i; + + asm("rdpr %%ver, %0\n" + : "=r"(iu_version) :); + iu_version &= 0xffffffff00000000ULL; + + for (i = 0; i < sizeof(sparc_defs)/sizeof(struct cpudef); i++) { + if (iu_version == sparc_defs[i].iu_version) + return &sparc_defs[i]; + } + printk("Unknown cpu (psr %lx), freezing!\n", iu_version); + for (;;); +} + +static void nvram_read(uint16_t offset, char *buf, unsigned int nbytes) +{ + unsigned int i; + + for (i = 0; i < nbytes; i++) { + buf[i] = inb(NVRAM_BASE + offset + i); + } +} + +static void nvram_write(uint16_t offset, const char *buf, unsigned int nbytes) +{ + unsigned int i; + + for (i = 0; i < nbytes; i++) { + outb(buf[i], NVRAM_BASE + offset + i); + } +} + +static uint8_t qemu_uuid[16]; + +void arch_nvram_get(char *data) +{ + char *obio_cmdline; + uint32_t size = 0; + const struct cpudef *cpu; + char buf[256]; + uint32_t temp; + uint64_t ram_size; + uint32_t clock_frequency; + uint16_t machine_id; + const char *stdin_path, *stdout_path; + + fw_cfg_init(); + + fw_cfg_read(FW_CFG_SIGNATURE, buf, 4); + buf[4] = '\0'; + + printk("Configuration device id %s", buf); + + temp = fw_cfg_read_i32(FW_CFG_ID); + machine_id = fw_cfg_read_i16(FW_CFG_MACHINE_ID); + + printk(" version %d machine id %d\n", temp, machine_id); + + if (temp != 1) { + printk("Incompatible configuration device version, freezing\n"); + for(;;); + } + + kernel_size = fw_cfg_read_i32(FW_CFG_KERNEL_SIZE); + if (kernel_size) + kernel_image = fw_cfg_read_i64(FW_CFG_KERNEL_ADDR); + + size = fw_cfg_read_i32(FW_CFG_CMDLINE_SIZE); + if (size) { + obio_cmdline = (char *)malloc(size + 1); + fw_cfg_read(FW_CFG_CMDLINE_DATA, obio_cmdline, size); + obio_cmdline[size] = '\0'; + } else { + obio_cmdline = strdup(""); + } + qemu_cmdline = (uint64_t)obio_cmdline; + cmdline_size = size; + boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE); + + if (kernel_size) + printk("kernel addr %llx size %llx\n", kernel_image, kernel_size); + if (size) + printk("kernel cmdline %s\n", obio_cmdline); + + nvram_read(NVRAM_OB_START, data, NVRAM_OB_SIZE); + + temp = fw_cfg_read_i32(FW_CFG_NB_CPUS); + + printk("CPUs: %x", temp); + + clock_frequency = 100000000; + + cpu = id_cpu(); + //cpu->initfn(); + cpu_generic_init(cpu, clock_frequency); + printk(" x %s\n", cpu->name); + + // Add /uuid + fw_cfg_read(FW_CFG_UUID, (char *)qemu_uuid, 16); + + printk("UUID: " UUID_FMT "\n", qemu_uuid[0], qemu_uuid[1], qemu_uuid[2], + qemu_uuid[3], qemu_uuid[4], qemu_uuid[5], qemu_uuid[6], + qemu_uuid[7], qemu_uuid[8], qemu_uuid[9], qemu_uuid[10], + qemu_uuid[11], qemu_uuid[12], qemu_uuid[13], qemu_uuid[14], + qemu_uuid[15]); + + push_str("/"); + fword("find-device"); + + PUSH((long)&qemu_uuid); + PUSH(16); + fword("encode-bytes"); + push_str("uuid"); + fword("property"); + + // Add /idprom + nvram_read(NVRAM_IDPROM, (char *)idprom, NVRAM_IDPROM_SIZE); + + PUSH((long)&idprom); + PUSH(32); + fword("encode-bytes"); + push_str("idprom"); + fword("property"); + + PUSH(500 * 1000 * 1000); + fword("encode-int"); + push_str("clock-frequency"); + fword("property"); + + ram_size = fw_cfg_read_i64(FW_CFG_RAM_SIZE); + + ob_mmu_init(cpu->name, ram_size); + + /* Setup nvram variables */ + push_str("/options"); + fword("find-device"); + + switch (boot_device) { + case 'a': + push_str("/obio/SUNW,fdtwo"); + break; + case 'c': + push_str("disk:a"); + break; + default: + case 'd': + push_str("cdrom:f cdrom"); + break; + case 'n': + push_str("net"); + break; + } + + fword("encode-string"); + push_str("boot-device"); + fword("property"); + + push_str(obio_cmdline); + fword("encode-string"); + push_str("boot-file"); + fword("property"); + + /* Set up other properties */ + push_str("/chosen"); + fword("find-device"); + + if (fw_cfg_read_i16(FW_CFG_NOGRAPHIC)) { + stdin_path = stdout_path = "ttya"; + } else { + stdin_path = "keyboard"; + stdout_path = "screen"; + } + + push_str(stdin_path); + push_str("input-device"); + fword("$setenv"); + + push_str(stdout_path); + push_str("output-device"); + fword("$setenv"); +} + +void arch_nvram_put(char *data) +{ + nvram_write(0, data, NVRAM_OB_SIZE); +} + +int arch_nvram_size(void) +{ + return NVRAM_OB_SIZE; +} + +void setup_timers(void) +{ +} + +void udelay(unsigned int usecs) +{ + volatile int i; + + for (i = 0; i < usecs * 100; i++); +} + +static void init_memory(void) +{ + phys_addr_t phys; + ucell virt; + + /* Claim the memory from OFMEM (align to 512K so we only take 1 TLB slot) */ + phys = ofmem_claim_phys(-1, MEMORY_SIZE, PAGE_SIZE_512K); + if (!phys) + printk("panic: not enough physical memory on host system.\n"); + + virt = ofmem_claim_virt(-1, MEMORY_SIZE, PAGE_SIZE_512K); + if (!virt) + printk("panic: not enough virtual memory on host system.\n"); + + /* Generate the mapping (and lock translation into the TLBs) */ + ofmem_map(phys, virt, MEMORY_SIZE, ofmem_arch_default_translation_mode(phys) | SPITFIRE_TTE_LOCKED); + + /* we push start and end of memory to the stack + * so that it can be used by the forth word QUIT + * to initialize the memory allocator + */ + + PUSH(virt); + PUSH(virt + MEMORY_SIZE); +} + +extern volatile uint64_t *obp_ticks_pointer; + +static void +arch_init( void ) +{ + openbios_init(); + modules_init(); +#ifdef CONFIG_DRIVER_PCI + ob_pci_init(); + + /* Set TAS register to match the virtual-dma properties + set during sabre configure */ + sparc64_set_tas_register(PBM_PCI_TARGET_AS_CD_ENABLE); +#endif + nvconf_init(); + device_end(); + + /* Point to the Forth obp-ticks variable */ + fword("obp-ticks"); + obp_ticks_pointer = cell2pointer(POP()); + + bind_func("platform-boot", boot ); + bind_func("(go)", go); +} + +unsigned long isa_io_base; + +extern struct _console_ops arch_console_ops; + +int openbios(void) +{ + unsigned int i; + uint16_t machine_id; + const struct hwdef *hwdef = NULL; + + + for (i = 0; i < sizeof(hwdefs) / sizeof(struct hwdef); i++) { + isa_io_base = hwdefs[i].pci.io_base; + machine_id = fw_cfg_read_i16(FW_CFG_MACHINE_ID); + if (hwdefs[i].machine_id_low <= machine_id && + hwdefs[i].machine_id_high >= machine_id) { + hwdef = &hwdefs[i]; + arch = &hwdefs[i].pci; + break; + } + } + if (!hwdef) + for(;;); // Internal inconsistency, hang + +#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); +#endif + printk("OpenBIOS for Sparc64\n"); +#endif + + ofmem_init(); + + collect_sys_info(&sys_info); + + dict = (unsigned char *)sys_info.dict_start; + dicthead = (cell)sys_info.dict_end; + last = sys_info.dict_last; + dictlimit = sys_info.dict_limit; + + forth_init(); + +#ifdef CONFIG_DEBUG_BOOT + printk("forth started.\n"); + printk("initializing memory..."); +#endif + + init_memory(); + +#ifdef CONFIG_DEBUG_BOOT + printk("done\n"); +#endif + + PUSH_xt( bind_noname_func(arch_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + + if (!PC) { + printk("panic: no dictionary entry point.\n"); + return -1; + } +#ifdef CONFIG_DEBUG_DICTIONARY + printk("done (%d bytes).\n", dicthead); + printk("Jumping to dictionary...\n"); +#endif + + enterforth((xt_t)PC); + printk("falling off...\n"); + free(dict); + return 0; +} diff --git a/qemu/roms/openbios/arch/sparc64/openbios.h b/qemu/roms/openbios/arch/sparc64/openbios.h new file mode 100644 index 000000000..2146300d9 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/openbios.h @@ -0,0 +1,27 @@ +/* + * Creation Date: <2004/01/15 16:14:05 samuel> + * Time-stamp: <2004/01/15 16:14:05 samuel> + * + * <openbios.h> + * + * + * + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_OPENBIOS +#define _H_OPENBIOS + +int openbios(void); + +/* console.c */ +#ifdef CONFIG_DEBUG_CONSOLE +extern void video_init(void); +#endif + +#endif /* _H_OPENBIOS */ diff --git a/qemu/roms/openbios/arch/sparc64/openprom.h b/qemu/roms/openbios/arch/sparc64/openprom.h new file mode 100644 index 000000000..0a336901d --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/openprom.h @@ -0,0 +1,281 @@ +/* $Id: openprom.h,v 1.9 2001/03/16 10:22:02 davem Exp $ */ +#ifndef __SPARC64_OPENPROM_H +#define __SPARC64_OPENPROM_H + +/* openprom.h: Prom structures and defines for access to the OPENBOOT + * prom routines and data areas. + * + * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) + */ + +#ifndef __ASSEMBLY__ +/* V0 prom device operations. */ +struct linux_dev_v0_funcs { + int (*v0_devopen)(char *device_str); + int (*v0_devclose)(int dev_desc); + int (*v0_rdblkdev)(int dev_desc, int num_blks, int blk_st, char *buf); + int (*v0_wrblkdev)(int dev_desc, int num_blks, int blk_st, char *buf); + int (*v0_wrnetdev)(int dev_desc, int num_bytes, char *buf); + int (*v0_rdnetdev)(int dev_desc, int num_bytes, char *buf); + int (*v0_rdchardev)(int dev_desc, int num_bytes, int dummy, char *buf); + int (*v0_wrchardev)(int dev_desc, int num_bytes, int dummy, char *buf); + int (*v0_seekdev)(int dev_desc, long logical_offst, int from); +}; + +/* V2 and later prom device operations. */ +struct linux_dev_v2_funcs { + int (*v2_inst2pkg)(int d); /* Convert ihandle to phandle */ + char * (*v2_dumb_mem_alloc)(char *va, unsigned sz); + void (*v2_dumb_mem_free)(char *va, unsigned sz); + + /* To map devices into virtual I/O space. */ + char * (*v2_dumb_mmap)(char *virta, int which_io, unsigned paddr, unsigned sz); + void (*v2_dumb_munmap)(char *virta, unsigned size); + + int (*v2_dev_open)(char *devpath); + void (*v2_dev_close)(int d); + int (*v2_dev_read)(int d, char *buf, int nbytes); + int (*v2_dev_write)(int d, char *buf, int nbytes); + int (*v2_dev_seek)(int d, int hi, int lo); + + /* Never issued (multistage load support) */ + void (*v2_wheee2)(void); + void (*v2_wheee3)(void); +}; + +struct linux_mlist_v0 { + struct linux_mlist_v0 *theres_more; + unsigned start_adr; + unsigned num_bytes; +}; + +struct linux_mem_v0 { + struct linux_mlist_v0 **v0_totphys; + struct linux_mlist_v0 **v0_prommap; + struct linux_mlist_v0 **v0_available; /* What we can use */ +}; + +/* Arguments sent to the kernel from the boot prompt. */ +struct linux_arguments_v0 { + char *argv[8]; + char args[100]; + char boot_dev[2]; + int boot_dev_ctrl; + int boot_dev_unit; + int dev_partition; + char *kernel_file_name; + void *aieee1; /* XXX */ +}; + +/* V2 and up boot things. */ +struct linux_bootargs_v2 { + char **bootpath; + char **bootargs; + int *fd_stdin; + int *fd_stdout; +}; + +/* The top level PROM vector. */ +struct linux_romvec { + /* Version numbers. */ + unsigned int pv_magic_cookie; + unsigned int pv_romvers; + unsigned int pv_plugin_revision; + unsigned int pv_printrev; + + /* Version 0 memory descriptors. */ + struct linux_mem_v0 pv_v0mem; + + /* Node operations. */ + struct linux_nodeops *pv_nodeops; + + char **pv_bootstr; + struct linux_dev_v0_funcs pv_v0devops; + + char *pv_stdin; + char *pv_stdout; +#define PROMDEV_KBD 0 /* input from keyboard */ +#define PROMDEV_SCREEN 0 /* output to screen */ +#define PROMDEV_TTYA 1 /* in/out to ttya */ +#define PROMDEV_TTYB 2 /* in/out to ttyb */ + + /* Blocking getchar/putchar. NOT REENTRANT! (grr) */ + int (*pv_getchar)(void); + void (*pv_putchar)(int ch); + + /* Non-blocking variants. */ + int (*pv_nbgetchar)(void); + int (*pv_nbputchar)(int ch); + + void (*pv_putstr)(char *str, int len); + + /* Miscellany. */ + void (*pv_reboot)(char *bootstr); + void (*pv_printf)(__const__ char *fmt, ...); + void (*pv_abort)(void); + __volatile__ int *pv_ticks; + void (*pv_halt)(void); + void (**pv_synchook)(void); + + /* Evaluate a forth string, not different proto for V0 and V2->up. */ + union { + void (*v0_eval)(int len, char *str); + void (*v2_eval)(char *str); + } pv_fortheval; + + struct linux_arguments_v0 **pv_v0bootargs; + + /* Get ether address. */ + unsigned int (*pv_enaddr)(int d, char *enaddr); + + struct linux_bootargs_v2 pv_v2bootargs; + struct linux_dev_v2_funcs pv_v2devops; + + int filler[15]; + + /* This one is sun4c/sun4 only. */ + void (*pv_setctxt)(int ctxt, char *va, int pmeg); + + /* Prom version 3 Multiprocessor routines. This stuff is crazy. + * No joke. Calling these when there is only one cpu probably + * crashes the machine, have to test this. :-) + */ + + /* v3_cpustart() will start the cpu 'whichcpu' in mmu-context + * 'thiscontext' executing at address 'prog_counter' + */ + int (*v3_cpustart)(unsigned int whichcpu, int ctxtbl_ptr, + int thiscontext, char *prog_counter); + + /* v3_cpustop() will cause cpu 'whichcpu' to stop executing + * until a resume cpu call is made. + */ + int (*v3_cpustop)(unsigned int whichcpu); + + /* v3_cpuidle() will idle cpu 'whichcpu' until a stop or + * resume cpu call is made. + */ + int (*v3_cpuidle)(unsigned int whichcpu); + + /* v3_cpuresume() will resume processor 'whichcpu' executing + * starting with whatever 'pc' and 'npc' were left at the + * last 'idle' or 'stop' call. + */ + int (*v3_cpuresume)(unsigned int whichcpu); +}; + +/* Routines for traversing the prom device tree. */ +struct linux_nodeops { + int (*no_nextnode)(int node); + int (*no_child)(int node); + int (*no_proplen)(int node, char *name); + int (*no_getprop)(int node, char *name, char *val); + int (*no_setprop)(int node, char *name, char *val, int len); + char * (*no_nextprop)(int node, char *name); +}; + +/* More fun PROM structures for device probing. */ +#define PROMREG_MAX 16 +#define PROMVADDR_MAX 16 +#define PROMINTR_MAX 15 + +struct linux_prom_registers { + unsigned which_io; /* hi part of physical address */ + unsigned phys_addr; /* The physical address of this register */ + int reg_size; /* How many bytes does this register take up? */ +}; + +struct linux_prom64_registers { + long phys_addr; + long reg_size; +}; + +struct linux_prom_irqs { + int pri; /* IRQ priority */ + int vector; /* This is foobar, what does it do? */ +}; + +/* Element of the "ranges" vector */ +struct linux_prom_ranges { + unsigned int ot_child_space; + unsigned int ot_child_base; /* Bus feels this */ + unsigned int ot_parent_space; + unsigned int ot_parent_base; /* CPU looks from here */ + unsigned int or_size; +}; + +struct linux_prom64_ranges { + unsigned long ot_child_base; /* Bus feels this */ + unsigned long ot_parent_base; /* CPU looks from here */ + unsigned long or_size; +}; + +/* Ranges and reg properties are a bit different for PCI. */ +struct linux_prom_pci_registers { + unsigned int phys_hi; + unsigned int phys_mid; + unsigned int phys_lo; + + unsigned int size_hi; + unsigned int size_lo; +}; + +struct linux_prom_pci_ranges { + unsigned int child_phys_hi; /* Only certain bits are encoded here. */ + unsigned int child_phys_mid; + unsigned int child_phys_lo; + + unsigned int parent_phys_hi; + unsigned int parent_phys_lo; + + unsigned int size_hi; + unsigned int size_lo; +}; + +struct linux_prom_pci_intmap { + unsigned int phys_hi; + unsigned int phys_mid; + unsigned int phys_lo; + + unsigned int interrupt; + + int cnode; + unsigned int cinterrupt; +}; + +struct linux_prom_pci_intmask { + unsigned int phys_hi; + unsigned int phys_mid; + unsigned int phys_lo; + unsigned int interrupt; +}; + +struct linux_prom_ebus_ranges { + unsigned int child_phys_hi; + unsigned int child_phys_lo; + + unsigned int parent_phys_hi; + unsigned int parent_phys_mid; + unsigned int parent_phys_lo; + + unsigned int size; +}; + +struct linux_prom_ebus_intmap { + unsigned int phys_hi; + unsigned int phys_lo; + + unsigned int interrupt; + + int cnode; + unsigned int cinterrupt; +}; + +struct linux_prom_ebus_intmask { + unsigned int phys_hi; + unsigned int phys_lo; + unsigned int interrupt; +}; +#endif /* !(__ASSEMBLY__) */ + +#endif /* !(__SPARC64_OPENPROM_H) */ diff --git a/qemu/roms/openbios/arch/sparc64/plainboot.c b/qemu/roms/openbios/arch/sparc64/plainboot.c new file mode 100644 index 000000000..08dab2d12 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/plainboot.c @@ -0,0 +1,21 @@ +/* tag: openbios fixed address forth starter + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define FIXED_DICTSTART 0xfffe0000 +#define FIXED_DICTEND 0xfffeffff + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)FIXED_DICTSTART; + info->dict_end=(unsigned long *)FIXED_DICTEND; +} diff --git a/qemu/roms/openbios/arch/sparc64/pstate.h b/qemu/roms/openbios/arch/sparc64/pstate.h new file mode 100644 index 000000000..f32d6f7db --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/pstate.h @@ -0,0 +1,90 @@ +/* $Id: pstate.h,v 1.6 1997/06/25 07:39:45 jj Exp $ */ +#ifndef _SPARC64_PSTATE_H +#define _SPARC64_PSTATE_H + +#include "const.h" + +/* The V9 PSTATE Register (with SpitFire extensions). + * + * ----------------------------------------------------------------------- + * | Resv | IG | MG | CLE | TLE | MM | RED | PEF | AM | PRIV | IE | AG | + * ----------------------------------------------------------------------- + * 63 12 11 10 9 8 7 6 5 4 3 2 1 0 + */ +#define PSTATE_IG _AC(0x0000000000000800,UL) /* Interrupt Globals. */ +#define PSTATE_MG _AC(0x0000000000000400,UL) /* MMU Globals. */ +#define PSTATE_CLE _AC(0x0000000000000200,UL) /* Current Little Endian.*/ +#define PSTATE_TLE _AC(0x0000000000000100,UL) /* Trap Little Endian. */ +#define PSTATE_MM _AC(0x00000000000000c0,UL) /* Memory Model. */ +#define PSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TotalStoreOrder */ +#define PSTATE_PSO _AC(0x0000000000000040,UL) /* MM: PartialStoreOrder */ +#define PSTATE_RMO _AC(0x0000000000000080,UL) /* MM: RelaxedMemoryOrder*/ +#define PSTATE_RED _AC(0x0000000000000020,UL) /* Reset Error Debug. */ +#define PSTATE_PEF _AC(0x0000000000000010,UL) /* Floating Point Enable.*/ +#define PSTATE_AM _AC(0x0000000000000008,UL) /* Address Mask. */ +#define PSTATE_PRIV _AC(0x0000000000000004,UL) /* Privilege. */ +#define PSTATE_IE _AC(0x0000000000000002,UL) /* Interrupt Enable. */ +#define PSTATE_AG _AC(0x0000000000000001,UL) /* Alternate Globals. */ + +/* The V9 TSTATE Register (with SpitFire and Linux extensions). + * + * --------------------------------------------------------------- + * | Resv | CCR | ASI | %pil | PSTATE | Resv | CWP | + * --------------------------------------------------------------- + * 63 40 39 32 31 24 23 20 19 8 7 5 4 0 + */ +#define TSTATE_CCR _AC(0x000000ff00000000,UL) /* Condition Codes. */ +#define TSTATE_XCC _AC(0x000000f000000000,UL) /* Condition Codes. */ +#define TSTATE_XNEG _AC(0x0000008000000000,UL) /* %xcc Negative. */ +#define TSTATE_XZERO _AC(0x0000004000000000,UL) /* %xcc Zero. */ +#define TSTATE_XOVFL _AC(0x0000002000000000,UL) /* %xcc Overflow. */ +#define TSTATE_XCARRY _AC(0x0000001000000000,UL) /* %xcc Carry. */ +#define TSTATE_ICC _AC(0x0000000f00000000,UL) /* Condition Codes. */ +#define TSTATE_INEG _AC(0x0000000800000000,UL) /* %icc Negative. */ +#define TSTATE_IZERO _AC(0x0000000400000000,UL) /* %icc Zero. */ +#define TSTATE_IOVFL _AC(0x0000000200000000,UL) /* %icc Overflow. */ +#define TSTATE_ICARRY _AC(0x0000000100000000,UL) /* %icc Carry. */ +#define TSTATE_ASI _AC(0x00000000ff000000,UL) /* AddrSpace ID. */ +#define TSTATE_PIL _AC(0x0000000000f00000,UL) /* %pil (Linux traps)*/ +#define TSTATE_PSTATE _AC(0x00000000000fff00,UL) /* PSTATE. */ +#define TSTATE_IG _AC(0x0000000000080000,UL) /* Interrupt Globals.*/ +#define TSTATE_MG _AC(0x0000000000040000,UL) /* MMU Globals. */ +#define TSTATE_CLE _AC(0x0000000000020000,UL) /* CurrLittleEndian. */ +#define TSTATE_TLE _AC(0x0000000000010000,UL) /* TrapLittleEndian. */ +#define TSTATE_MM _AC(0x000000000000c000,UL) /* Memory Model. */ +#define TSTATE_TSO _AC(0x0000000000000000,UL) /* MM: TSO */ +#define TSTATE_PSO _AC(0x0000000000004000,UL) /* MM: PSO */ +#define TSTATE_RMO _AC(0x0000000000008000,UL) /* MM: RMO */ +#define TSTATE_RED _AC(0x0000000000002000,UL) /* Reset Error Debug.*/ +#define TSTATE_PEF _AC(0x0000000000001000,UL) /* FPU Enable. */ +#define TSTATE_AM _AC(0x0000000000000800,UL) /* Address Mask. */ +#define TSTATE_PRIV _AC(0x0000000000000400,UL) /* Privilege. */ +#define TSTATE_IE _AC(0x0000000000000200,UL) /* Interrupt Enable. */ +#define TSTATE_AG _AC(0x0000000000000100,UL) /* Alternate Globals.*/ +#define TSTATE_CWP _AC(0x000000000000001f,UL) /* Curr Win-Pointer. */ + +/* Floating-Point Registers State Register. + * + * -------------------------------- + * | Resv | FEF | DU | DL | + * -------------------------------- + * 63 3 2 1 0 + */ +#define FPRS_FEF _AC(0x0000000000000004,UL) /* FPU Enable. */ +#define FPRS_DU _AC(0x0000000000000002,UL) /* Dirty Upper. */ +#define FPRS_DL _AC(0x0000000000000001,UL) /* Dirty Lower. */ + +/* Version Register. + * + * ------------------------------------------------------ + * | MANUF | IMPL | MASK | Resv | MAXTL | Resv | MAXWIN | + * ------------------------------------------------------ + * 63 48 47 32 31 24 23 16 15 8 7 5 4 0 + */ +#define VERS_MANUF _AC(0xffff000000000000,UL) /* Manufacturer. */ +#define VERS_IMPL _AC(0x0000ffff00000000,UL) /* Implementation. */ +#define VERS_MASK _AC(0x00000000ff000000,UL) /* Mask Set Revision.*/ +#define VERS_MAXTL _AC(0x000000000000ff00,UL) /* Max Trap Level. */ +#define VERS_MAXWIN _AC(0x000000000000001f,UL) /* Max RegWindow Idx.*/ + +#endif /* !(_SPARC64_PSTATE_H) */ diff --git a/qemu/roms/openbios/arch/sparc64/spitfire.h b/qemu/roms/openbios/arch/sparc64/spitfire.h new file mode 100644 index 000000000..4a951b1fb --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/spitfire.h @@ -0,0 +1,510 @@ +/* $Id: spitfire.h,v 1.18 2001/11/29 16:42:10 kanoj Exp $ + * spitfire.h: SpitFire/BlackBird/Cheetah inline MMU operations. + * + * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) + */ + +#ifndef _SPARC64_SPITFIRE_H +#define _SPARC64_SPITFIRE_H + +#include <asm/asi.h> + +/* The following register addresses are accessible via ASI_DMMU + * and ASI_IMMU, that is there is a distinct and unique copy of + * each these registers for each TLB. + */ +#define TSB_TAG_TARGET 0x0000000000000000 /* All chips */ +#define TLB_SFSR 0x0000000000000018 /* All chips */ +#define TSB_REG 0x0000000000000028 /* All chips */ +#define TLB_TAG_ACCESS 0x0000000000000030 /* All chips */ +#define VIRT_WATCHPOINT 0x0000000000000038 /* All chips */ +#define PHYS_WATCHPOINT 0x0000000000000040 /* All chips */ +#define TSB_EXTENSION_P 0x0000000000000048 /* Ultra-III and later */ +#define TSB_EXTENSION_S 0x0000000000000050 /* Ultra-III and later, D-TLB only */ +#define TSB_EXTENSION_N 0x0000000000000058 /* Ultra-III and later */ +#define TLB_TAG_ACCESS_EXT 0x0000000000000060 /* Ultra-III+ and later */ + +/* These registers only exist as one entity, and are accessed + * via ASI_DMMU only. + */ +#define PRIMARY_CONTEXT 0x0000000000000008 +#define SECONDARY_CONTEXT 0x0000000000000010 +#define DMMU_SFAR 0x0000000000000020 +#define VIRT_WATCHPOINT 0x0000000000000038 +#define PHYS_WATCHPOINT 0x0000000000000040 + +#define SPITFIRE_HIGHEST_LOCKED_TLBENT (64 - 1) + +/* translation table entry bits */ +#define SPITFIRE_TTE_WRITABLE 0x02 +#define SPITFIRE_TTE_PRIVILEGED 0x04 +#define SPITFIRE_TTE_CV 0x10 +#define SPITFIRE_TTE_CP 0x20 +#define SPITFIRE_TTE_LOCKED 0x40 +#define SPITFIRE_TTE_VALID 0x8000000000000000ULL + +#ifndef __ASSEMBLY__ + +enum ultra_tlb_layout { + spitfire = 0, + cheetah = 1, + cheetah_plus = 2, +}; + +extern enum ultra_tlb_layout tlb_type; + +#define CHEETAH_HIGHEST_LOCKED_TLBENT (16 - 1) + +#define L1DCACHE_SIZE 0x4000 + +#define sparc64_highest_locked_tlbent() \ + (tlb_type == spitfire ? \ + SPITFIRE_HIGHEST_LOCKED_TLBENT : \ + CHEETAH_HIGHEST_LOCKED_TLBENT) + +static __inline__ unsigned long spitfire_get_isfsr(void) +{ + unsigned long ret; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (ret) + : "r" (TLB_SFSR), "i" (ASI_IMMU)); + return ret; +} + +static __inline__ unsigned long spitfire_get_dsfsr(void) +{ + unsigned long ret; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (ret) + : "r" (TLB_SFSR), "i" (ASI_DMMU)); + return ret; +} + +static __inline__ unsigned long spitfire_get_sfar(void) +{ + unsigned long ret; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (ret) + : "r" (DMMU_SFAR), "i" (ASI_DMMU)); + return ret; +} + +static __inline__ void spitfire_put_isfsr(unsigned long sfsr) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* no outputs */ + : "r" (sfsr), "r" (TLB_SFSR), "i" (ASI_IMMU)); +} + +static __inline__ void spitfire_put_dsfsr(unsigned long sfsr) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* no outputs */ + : "r" (sfsr), "r" (TLB_SFSR), "i" (ASI_DMMU)); +} + +static __inline__ unsigned long spitfire_get_primary_context(void) +{ + unsigned long ctx; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (ctx) + : "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); + return ctx; +} + +static __inline__ void spitfire_set_primary_context(unsigned long ctx) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (ctx & 0x3ff), + "r" (PRIMARY_CONTEXT), "i" (ASI_DMMU)); + __asm__ __volatile__ ("membar #Sync" : : : "memory"); +} + +static __inline__ unsigned long spitfire_get_secondary_context(void) +{ + unsigned long ctx; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (ctx) + : "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU)); + return ctx; +} + +static __inline__ void spitfire_set_secondary_context(unsigned long ctx) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (ctx & 0x3ff), + "r" (SECONDARY_CONTEXT), "i" (ASI_DMMU)); + __asm__ __volatile__ ("membar #Sync" : : : "memory"); +} + +/* The data cache is write through, so this just invalidates the + * specified line. + */ +static __inline__ void spitfire_put_dcache_tag(unsigned long addr, unsigned long tag) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (tag), "r" (addr), "i" (ASI_DCACHE_TAG)); + __asm__ __volatile__ ("membar #Sync" : : : "memory"); +} + +/* The instruction cache lines are flushed with this, but note that + * this does not flush the pipeline. It is possible for a line to + * get flushed but stale instructions to still be in the pipeline, + * a flush instruction (to any address) is sufficient to handle + * this issue after the line is invalidated. + */ +static __inline__ void spitfire_put_icache_tag(unsigned long addr, unsigned long tag) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (tag), "r" (addr), "i" (ASI_IC_TAG)); +} + +static __inline__ unsigned long spitfire_get_dtlb_data(int entry) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (data) + : "r" (entry << 3), "i" (ASI_DTLB_DATA_ACCESS)); + + /* Clear TTE diag bits. */ + data &= ~0x0003fe0000000000UL; + + return data; +} + +static __inline__ unsigned long spitfire_get_dtlb_tag(int entry) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" (entry << 3), "i" (ASI_DTLB_TAG_READ)); + return tag; +} + +static __inline__ void spitfire_put_dtlb_data(int entry, unsigned long data) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), "r" (entry << 3), + "i" (ASI_DTLB_DATA_ACCESS)); +} + +static __inline__ unsigned long spitfire_get_itlb_data(int entry) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (data) + : "r" (entry << 3), "i" (ASI_ITLB_DATA_ACCESS)); + + /* Clear TTE diag bits. */ + data &= ~0x0003fe0000000000UL; + + return data; +} + +static __inline__ unsigned long spitfire_get_itlb_tag(int entry) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" (entry << 3), "i" (ASI_ITLB_TAG_READ)); + return tag; +} + +static __inline__ void spitfire_put_itlb_data(int entry, unsigned long data) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), "r" (entry << 3), + "i" (ASI_ITLB_DATA_ACCESS)); +} + +/* Spitfire hardware assisted TLB flushes. */ + +/* Context level flushes. */ +static __inline__ void spitfire_flush_dtlb_primary_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x40), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_primary_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x40), "i" (ASI_IMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_dtlb_secondary_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x50), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_secondary_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x50), "i" (ASI_IMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_dtlb_nucleus_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x60), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_nucleus_context(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x60), "i" (ASI_IMMU_DEMAP)); +} + +/* Page level flushes. */ +static __inline__ void spitfire_flush_dtlb_primary_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_primary_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page), "i" (ASI_IMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_dtlb_secondary_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page | 0x10), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_secondary_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page | 0x10), "i" (ASI_IMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_dtlb_nucleus_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page | 0x20), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void spitfire_flush_itlb_nucleus_page(unsigned long page) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (page | 0x20), "i" (ASI_IMMU_DEMAP)); +} + +/* Cheetah has "all non-locked" tlb flushes. */ +static __inline__ void cheetah_flush_dtlb_all(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x80), "i" (ASI_DMMU_DEMAP)); +} + +static __inline__ void cheetah_flush_itlb_all(void) +{ + __asm__ __volatile__("stxa %%g0, [%0] %1\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (0x80), "i" (ASI_IMMU_DEMAP)); +} + +/* Cheetah has a 4-tlb layout so direct access is a bit different. + * The first two TLBs are fully assosciative, hold 16 entries, and are + * used only for locked and >8K sized translations. One exists for + * data accesses and one for instruction accesses. + * + * The third TLB is for data accesses to 8K non-locked translations, is + * 2 way assosciative, and holds 512 entries. The fourth TLB is for + * instruction accesses to 8K non-locked translations, is 2 way + * assosciative, and holds 128 entries. + * + * Cheetah has some bug where bogus data can be returned from + * ASI_{D,I}TLB_DATA_ACCESS loads, doing the load twice fixes + * the problem for me. -DaveM + */ +static __inline__ unsigned long cheetah_get_ldtlb_data(int entry) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t" + "ldxa [%1] %2, %0" + : "=r" (data) + : "r" ((0 << 16) | (entry << 3)), + "i" (ASI_DTLB_DATA_ACCESS)); + + return data; +} + +static __inline__ unsigned long cheetah_get_litlb_data(int entry) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t" + "ldxa [%1] %2, %0" + : "=r" (data) + : "r" ((0 << 16) | (entry << 3)), + "i" (ASI_ITLB_DATA_ACCESS)); + + return data; +} + +static __inline__ unsigned long cheetah_get_ldtlb_tag(int entry) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" ((0 << 16) | (entry << 3)), + "i" (ASI_DTLB_TAG_READ)); + + return tag; +} + +static __inline__ unsigned long cheetah_get_litlb_tag(int entry) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" ((0 << 16) | (entry << 3)), + "i" (ASI_ITLB_TAG_READ)); + + return tag; +} + +static __inline__ void cheetah_put_ldtlb_data(int entry, unsigned long data) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), + "r" ((0 << 16) | (entry << 3)), + "i" (ASI_DTLB_DATA_ACCESS)); +} + +static __inline__ void cheetah_put_litlb_data(int entry, unsigned long data) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), + "r" ((0 << 16) | (entry << 3)), + "i" (ASI_ITLB_DATA_ACCESS)); +} + +static __inline__ unsigned long cheetah_get_dtlb_data(int entry, int tlb) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t" + "ldxa [%1] %2, %0" + : "=r" (data) + : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_DATA_ACCESS)); + + return data; +} + +static __inline__ unsigned long cheetah_get_dtlb_tag(int entry, int tlb) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" ((tlb << 16) | (entry << 3)), "i" (ASI_DTLB_TAG_READ)); + return tag; +} + +static __inline__ void cheetah_put_dtlb_data(int entry, unsigned long data, int tlb) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), + "r" ((tlb << 16) | (entry << 3)), + "i" (ASI_DTLB_DATA_ACCESS)); +} + +static __inline__ unsigned long cheetah_get_itlb_data(int entry) +{ + unsigned long data; + + __asm__ __volatile__("ldxa [%1] %2, %%g0\n\t" + "ldxa [%1] %2, %0" + : "=r" (data) + : "r" ((2 << 16) | (entry << 3)), + "i" (ASI_ITLB_DATA_ACCESS)); + + return data; +} + +static __inline__ unsigned long cheetah_get_itlb_tag(int entry) +{ + unsigned long tag; + + __asm__ __volatile__("ldxa [%1] %2, %0" + : "=r" (tag) + : "r" ((2 << 16) | (entry << 3)), "i" (ASI_ITLB_TAG_READ)); + return tag; +} + +static __inline__ void cheetah_put_itlb_data(int entry, unsigned long data) +{ + __asm__ __volatile__("stxa %0, [%1] %2\n\t" + "membar #Sync" + : /* No outputs */ + : "r" (data), "r" ((2 << 16) | (entry << 3)), + "i" (ASI_ITLB_DATA_ACCESS)); +} + +#endif /* !(__ASSEMBLY__) */ + +#endif /* !(_SPARC64_SPITFIRE_H) */ diff --git a/qemu/roms/openbios/arch/sparc64/switch.S b/qemu/roms/openbios/arch/sparc64/switch.S new file mode 100644 index 000000000..d2cc7bedb --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/switch.S @@ -0,0 +1,124 @@ +#include "pstate.h" +#include <asm/asi.h> +#define ASI_BP ASI_M_BYPASS +#define REGWIN_SZ 0x40 + + .globl __switch_context, __switch_context_nosave, __exit_context, halt + + .text + .align 4 + .register %g2, #scratch + .register %g3, #scratch + .register %g6, #scratch + .register %g7, #scratch + +/* + * Switch execution context + * This saves registers in the stack, then + * switches the stack, and restores everything from the new stack. + * This function takes no argument. New stack pointer is + * taken from global variable __context, and old stack pointer + * is also saved to __context. This way we can just jump to + * this routine to get back to the original context. + */ + +/* XXX: totally bogus for sparc, need to save and restore all windows */ +__switch_context: + + /* make sure caller's windows are on caller's stack */ + flushw; + + /* Save everything in current stack */ + + setx __context, %g2, %g1 + stx %g3, [%g1 + 24] + stx %g4, [%g1 + 32] + stx %g5, [%g1 + 40] + stx %g6, [%g1 + 48] + stx %g7, [%g1 + 56] + + stx %o0, [%g1 + 64] + stx %o1, [%g1 + 72] + stx %o2, [%g1 + 80] + stx %o3, [%g1 + 88] + stx %o4, [%g1 + 96] + stx %o5, [%g1 + 104] + stx %o6, [%g1 + 112] + stx %o7, [%g1 + 120] + + stx %l0, [%g1 + 128] + stx %l1, [%g1 + 136] + stx %l2, [%g1 + 144] + stx %l3, [%g1 + 152] + stx %l4, [%g1 + 160] + stx %l5, [%g1 + 168] + stx %l6, [%g1 + 176] + stx %l7, [%g1 + 184] + + stx %i0, [%g1 + 192] + stx %i1, [%g1 + 200] + stx %i2, [%g1 + 208] + stx %i3, [%g1 + 216] + stx %i4, [%g1 + 224] + stx %i5, [%g1 + 232] + stx %i6, [%g1 + 240] + stx %i7, [%g1 + 248] + +__switch_context_nosave: + /* Interrupts are not allowed... */ + /* make sure caller's windows are on caller's stack */ + flushw + /* Load all registers + */ + setx __context, %g2, %g1 + ldx [%g1], %g1 + ldx [%g1 + 16], %g2 + ldx [%g1 + 24], %g3 + ldx [%g1 + 32], %g4 + ldx [%g1 + 40], %g5 + ldx [%g1 + 48], %g6 + ldx [%g1 + 56], %g7 + + ldx [%g1 + 64], %o0 + ldx [%g1 + 72], %o1 + ldx [%g1 + 80], %o2 + ldx [%g1 + 88], %o3 + ldx [%g1 + 96], %o4 + ldx [%g1 + 104], %o5 + ldx [%g1 + 112], %o6 + ldx [%g1 + 120], %o7 + + ldx [%g1 + 128], %l0 + ldx [%g1 + 136], %l1 + ldx [%g1 + 144], %l2 + ldx [%g1 + 152], %l3 + ldx [%g1 + 160], %l4 + ldx [%g1 + 168], %l5 + ldx [%g1 + 176], %l6 + ldx [%g1 + 184], %l7 + + ldx [%g1 + 192], %i0 + ldx [%g1 + 200], %i1 + ldx [%g1 + 208], %i2 + ldx [%g1 + 216], %i3 + ldx [%g1 + 224], %i4 + ldx [%g1 + 232], %i5 + ldx [%g1 + 240], %i6 + ldx [%g1 + 248], %i7 + + ldx [%g1 + 256], %g1 + /* Finally, load new %pc */ + jmp %g1 + clr %g1 + +__exit_context: + /* Get back to the original context */ + call __switch_context + nop + + /* We get here if the other context attempt to switch to this + * dead context. This should not happen. */ + +halt: + b halt + nop diff --git a/qemu/roms/openbios/arch/sparc64/sys_info.c b/qemu/roms/openbios/arch/sparc64/sys_info.c new file mode 100644 index 000000000..f70aa0270 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/sys_info.c @@ -0,0 +1,59 @@ +#include "config.h" +#include "kernel/kernel.h" +#include "arch/common/elf_boot.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "boot.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +uint64_t qemu_mem_size; +unsigned long va_shift; + +void collect_multiboot_info(struct sys_info *); + +void collect_sys_info(struct sys_info *info) +{ + int i; + unsigned long long total = 0; + struct memrange *mmap; + + /* Pick up paramters given by bootloader to us */ + //info->boot_type = boot_ctx->eax; + //info->boot_data = boot_ctx->ebx; + info->boot_arg = boot_ctx->param[0]; + //debug("boot eax = %#lx\n", info->boot_type); + //debug("boot ebx = %#lx\n", info->boot_data); + info->boot_type = ELF_BHDR_MAGIC; + info->boot_data = virt_to_phys(&elf_image_notes); + debug("boot arg = %#lx\n", info->boot_arg); + + collect_elfboot_info(info); +#ifdef CONFIG_LINUXBIOS + collect_linuxbios_info(info); +#endif +#ifdef CONFIG_IMAGE_ELF_MULTIBOOT + collect_multiboot_info(info); +#endif + + if (!info->memrange) { + info->n_memranges = 1; + info->memrange = malloc(1 * sizeof(struct memrange)); + info->memrange[0].base = 0; + info->memrange[0].size = qemu_mem_size; + } + + debug("\n"); + mmap=info->memrange; + for (i = 0; i < info->n_memranges; i++) { + debug("%08lx-", (long)mmap[i].base); + debug("%08lx\n", (long)mmap[i].base + (long)mmap[i].size); + total += mmap[i].size; + } + debug("RAM %ld MB\n", (long)total >> 20); +} diff --git a/qemu/roms/openbios/arch/sparc64/tree.fs b/qemu/roms/openbios/arch/sparc64/tree.fs new file mode 100644 index 000000000..e034b5931 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/tree.fs @@ -0,0 +1,49 @@ +include config.fs + +\ ------------------------------------------------------------------------- +\ UPA encode/decode unit +\ ------------------------------------------------------------------------- + +: decode-unit-upa ( str len -- id lun ) + ascii , left-split + ( addr-R len-R addr-L len-L ) + parse-hex + -rot parse-hex + swap +; + +: encode-unit-upa ( id lun -- str len) + swap + pocket tohexstr + " ," pocket tmpstrcat >r + rot pocket tohexstr r> tmpstrcat drop +; + +" /" find-device + 2 encode-int " #address-cells" property + 2 encode-int " #size-cells" property + " sun4u" encode-string " compatible" property + + : encode-unit encode-unit-upa ; + : decode-unit decode-unit-upa ; + +new-device + " memory" device-name + " memory" device-type + external + : open true ; + : close ; + \ see arch/sparc64/lib.c for methods +finish-device + +new-device + " virtual-memory" device-name + external + \ see arch/sparc64/lib.c for methods +finish-device + +" /options" find-device + " disk" encode-string " boot-from" property + +" /openprom" find-device + " OBP 3.10.24 1999/01/01 01:01" encode-string " version" property diff --git a/qemu/roms/openbios/arch/sparc64/vectors.S b/qemu/roms/openbios/arch/sparc64/vectors.S new file mode 100644 index 000000000..927c1cdc7 --- /dev/null +++ b/qemu/roms/openbios/arch/sparc64/vectors.S @@ -0,0 +1,765 @@ +/* + * <vectors.S> + * + * Sparc V9 Trap Table(s) with SpitFire/Cheetah extensions. + * + * Copyright (C) 1996, 2001 David S. Miller (davem@caip.rutgers.edu) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License V2 + * as published by the Free Software Foundation + */ + +#define __ASSEMBLY__ +#include "pstate.h" +#include <asm/asi.h> +#define ASI_BP ASI_PHYS_BYPASS_EC_E +#define PROM_ADDR 0x1fff0000000 +#define SER_ADDR 0x1fe020003f8 +#define TICK_INT_DIS 0x8000000000000000 +#define TICK_INTERVAL 1*1000*1000 + + .section ".text.vectors", "ax" + .align 16384 +/* Sparc64 trap table */ + .globl trap_table, __divide_error, softint_irq, softint_irq_tl1 + .register %g2, #scratch + .register %g3, #scratch + .register %g6, #scratch + .register %g7, #scratch +trap_table: +#define SPILL_WINDOW \ + btst 1, %sp; \ + be spill_32bit; \ + nop; \ + stx %l0, [%sp + STACK_BIAS + 0x00]; \ + stx %l1, [%sp + STACK_BIAS + 0x08]; \ + stx %l2, [%sp + STACK_BIAS + 0x10]; \ + stx %l3, [%sp + STACK_BIAS + 0x18]; \ + stx %l4, [%sp + STACK_BIAS + 0x20]; \ + stx %l5, [%sp + STACK_BIAS + 0x28]; \ + stx %l6, [%sp + STACK_BIAS + 0x30]; \ + stx %l7, [%sp + STACK_BIAS + 0x38]; \ + stx %i0, [%sp + STACK_BIAS + 0x40]; \ + stx %i1, [%sp + STACK_BIAS + 0x48]; \ + stx %i2, [%sp + STACK_BIAS + 0x50]; \ + stx %i3, [%sp + STACK_BIAS + 0x58]; \ + stx %i4, [%sp + STACK_BIAS + 0x60]; \ + stx %i5, [%sp + STACK_BIAS + 0x68]; \ + stx %i6, [%sp + STACK_BIAS + 0x70]; \ + stx %i7, [%sp + STACK_BIAS + 0x78]; \ + saved; retry; nop; nop; nop; nop; nop; nop; \ + nop; nop; nop; nop; nop; + +#define FILL_WINDOW \ + btst 1, %sp; \ + be fill_32bit; \ + nop; \ + ldx [%sp + STACK_BIAS + 0x00], %l0; \ + ldx [%sp + STACK_BIAS + 0x08], %l1; \ + ldx [%sp + STACK_BIAS + 0x10], %l2; \ + ldx [%sp + STACK_BIAS + 0x18], %l3; \ + ldx [%sp + STACK_BIAS + 0x20], %l4; \ + ldx [%sp + STACK_BIAS + 0x28], %l5; \ + ldx [%sp + STACK_BIAS + 0x30], %l6; \ + ldx [%sp + STACK_BIAS + 0x38], %l7; \ + ldx [%sp + STACK_BIAS + 0x40], %i0; \ + ldx [%sp + STACK_BIAS + 0x48], %i1; \ + ldx [%sp + STACK_BIAS + 0x50], %i2; \ + ldx [%sp + STACK_BIAS + 0x58], %i3; \ + ldx [%sp + STACK_BIAS + 0x60], %i4; \ + ldx [%sp + STACK_BIAS + 0x68], %i5; \ + ldx [%sp + STACK_BIAS + 0x70], %i6; \ + ldx [%sp + STACK_BIAS + 0x78], %i7; \ + restored; retry; nop; nop; nop; nop; nop; nop; \ + nop; nop; nop; nop; nop; + +#define CLEAN_WINDOW \ + rdpr %cleanwin, %l0; add %l0, 1, %l0; \ + wrpr %l0, 0x0, %cleanwin; \ + clr %o0; clr %o1; clr %o2; clr %o3; \ + clr %o4; clr %o5; clr %o6; clr %o7; \ + clr %l0; clr %l1; clr %l2; clr %l3; \ + clr %l4; clr %l5; clr %l6; clr %l7; \ + retry; \ + nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop;nop; + +#define TRAP_IRQ(routine, level) \ + ba routine; mov level, %g1; nop; nop; nop; nop; nop; nop; +#define BTRAP(lvl) \ + ba bug; mov lvl, %g1; nop; nop; nop; nop; nop; nop; +#define BTRAPTL1(lvl) BTRAP(lvl) +#define BTRAPS(x) BTRAP(x) BTRAP(x+1) BTRAP(x+2) BTRAP(x+3) BTRAP(x+4) BTRAP(x+5) BTRAP(x+6) BTRAP(x+7) +#define BTRAPS4(x) BTRAP(x) BTRAP(x+1) BTRAP(x+2) BTRAP(x+3) +#define TRAP_HANDLER(routine) ba routine; nop; nop; nop; nop; nop; nop; nop; + +#define STACK_BIAS 2047 + .globl sparc64_ttable_tl0, sparc64_ttable_tl1 +sparc64_ttable_tl0: + ba entry; nop; nop; nop; nop; nop; nop; nop;! XXX remove + ba entry; nop; nop; nop; nop; nop; nop; nop;! Power-on reset + ba entry; nop; nop; nop; nop; nop; nop; nop;! Watchdog reset + ba entry; nop; nop; nop; nop; nop; nop; nop;! External reset + ba entry; nop; nop; nop; nop; nop; nop; nop;! Software reset + ba entry; nop; nop; nop; nop; nop; nop; nop;! RED state + BTRAP(0x06) BTRAP(0x07) BTRAPS(0x08) + BTRAPS(0x10) BTRAPS(0x18) + BTRAP(0x20) BTRAP(0x21) BTRAP(0x22) BTRAP(0x23) + CLEAN_WINDOW ! 24-27 + BTRAPS(0x28) + BTRAPS(0x30) BTRAPS(0x38) + BTRAP(0x40) BTRAP(0x41) BTRAP(0x42) BTRAP(0x43) +tl0_irq4: TRAP_IRQ(handler_irq, 4) +tl0_irq5: TRAP_IRQ(handler_irq, 5) TRAP_IRQ(handler_irq, 6) +tl0_irq7: TRAP_IRQ(handler_irq, 7) TRAP_IRQ(handler_irq, 8) +tl0_irq9: TRAP_IRQ(handler_irq, 9) TRAP_IRQ(handler_irq, 10) +tl0_irq11: TRAP_IRQ(handler_irq, 11) TRAP_IRQ(handler_irq, 12) +tl0_irq13: TRAP_IRQ(handler_irq, 13) +tl0_irq14: TRAP_IRQ(softint_irq, 14) +tl0_irq15: TRAP_IRQ(handler_irq, 15) + BTRAPS(0x50) BTRAPS(0x58) + BTRAPS4(0x60) + TRAP_HANDLER(reload_IMMU_tlb) ! 0x64 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x65 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x66 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x67 : instruction_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x68 : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x69 : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x6A : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x6B : data_access_MMU_miss + BTRAPS4(0x6C) ! data_access_protection + BTRAPS(0x70) BTRAPS(0x78) +tl0_s0n: SPILL_WINDOW +tl0_s1n: SPILL_WINDOW +tl0_s2n: SPILL_WINDOW +tl0_s3n: SPILL_WINDOW +tl0_s4n: SPILL_WINDOW +tl0_s5n: SPILL_WINDOW +tl0_s6n: SPILL_WINDOW +tl0_s7n: SPILL_WINDOW +tl0_s0o: SPILL_WINDOW +tl0_s1o: SPILL_WINDOW +tl0_s2o: SPILL_WINDOW +tl0_s3o: SPILL_WINDOW +tl0_s4o: SPILL_WINDOW +tl0_s5o: SPILL_WINDOW +tl0_s6o: SPILL_WINDOW +tl0_s7o: SPILL_WINDOW +tl0_f0n: FILL_WINDOW +tl0_f1n: FILL_WINDOW +tl0_f2n: FILL_WINDOW +tl0_f3n: FILL_WINDOW +tl0_f4n: FILL_WINDOW +tl0_f5n: FILL_WINDOW +tl0_f6n: FILL_WINDOW +tl0_f7n: FILL_WINDOW +tl0_f0o: FILL_WINDOW +tl0_f1o: FILL_WINDOW +tl0_f2o: FILL_WINDOW +tl0_f3o: FILL_WINDOW +tl0_f4o: FILL_WINDOW +tl0_f5o: FILL_WINDOW +tl0_f6o: FILL_WINDOW +tl0_f7o: FILL_WINDOW +tl0_resv100: BTRAPS(0x100) BTRAPS(0x108) +tl0_resv110: BTRAPS(0x110) BTRAPS(0x118) +tl0_resv120: BTRAPS(0x120) BTRAPS(0x128) +tl0_resv130: BTRAPS(0x130) BTRAPS(0x138) +tl0_resv140: BTRAPS(0x140) BTRAPS(0x148) +tl0_resv150: BTRAPS(0x150) BTRAPS(0x158) +tl0_resv160: BTRAPS(0x160) BTRAPS(0x168) +tl0_resv170: BTRAPS(0x170) BTRAPS(0x178) +tl0_resv180: BTRAPS(0x180) BTRAPS(0x188) +tl0_resv190: BTRAPS(0x190) BTRAPS(0x198) +tl0_resv1a0: BTRAPS(0x1a0) BTRAPS(0x1a8) +tl0_resv1b0: BTRAPS(0x1b0) BTRAPS(0x1b8) +tl0_resv1c0: BTRAPS(0x1c0) BTRAPS(0x1c8) +tl0_resv1d0: BTRAPS(0x1d0) BTRAPS(0x1d8) +tl0_resv1e0: BTRAPS(0x1e0) BTRAPS(0x1e8) +tl0_resv1f0: BTRAPS(0x1f0) BTRAPS(0x1f8) + +#undef BTRAPS +#define BTRAPS(x) BTRAPTL1(x) BTRAPTL1(x+1) BTRAPTL1(x+2) BTRAPTL1(x+3) BTRAPTL1(x+4) BTRAPTL1(x+5) BTRAPTL1(x+6) BTRAPTL1(x+7) + +#define SKIP_IRQ(routine, level) \ + retry; nop; nop; nop; nop; nop; nop; nop; + +sparc64_ttable_tl1: + BTRAPS(0x00) BTRAPS(0x08) + BTRAPS(0x10) BTRAPS(0x18) + BTRAPTL1(0x20) BTRAPTL1(0x21) BTRAPTL1(0x22) BTRAPTL1(0x23) + CLEAN_WINDOW ! 24-27 + BTRAPS(0x28) + BTRAPS(0x30) BTRAPS(0x38) + BTRAPTL1(0x40) BTRAPTL1(0x41) BTRAPTL1(0x42) BTRAPTL1(0x43) +tl1_irq4: TRAP_IRQ(handler_irq, 4) +tl1_irq5: TRAP_IRQ(handler_irq, 5) TRAP_IRQ(handler_irq, 6) +tl1_irq7: TRAP_IRQ(handler_irq, 7) TRAP_IRQ(handler_irq, 8) +tl1_irq9: TRAP_IRQ(handler_irq, 9) TRAP_IRQ(handler_irq, 10) +tl1_irq11: TRAP_IRQ(handler_irq, 11) TRAP_IRQ(handler_irq, 12) +tl1_irq13: TRAP_IRQ(handler_irq, 13) +tl1_irq14: SKIP_IRQ(softint_irq, 14) +tl1_irq15: TRAP_IRQ(handler_irq, 15) + BTRAPS(0x50) BTRAPS(0x58) + BTRAPS4(0x60) + TRAP_HANDLER(reload_IMMU_tlb) ! 0x64 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x65 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x66 : instruction_access_MMU_miss + TRAP_HANDLER(reload_IMMU_tlb) ! 0x67 : instruction_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x68 : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x69 : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x6A : data_access_MMU_miss + TRAP_HANDLER(reload_DMMU_tlb) ! 0x6B : data_access_MMU_miss + BTRAPS4(0x6C) ! data_access_protection + BTRAPS(0x70) BTRAPS(0x78) +tl1_s0n: SPILL_WINDOW +tl1_s1n: SPILL_WINDOW +tl1_s2n: SPILL_WINDOW +tl1_s3n: SPILL_WINDOW +tl1_s4n: SPILL_WINDOW +tl1_s5n: SPILL_WINDOW +tl1_s6n: SPILL_WINDOW +tl1_s7n: SPILL_WINDOW +tl1_s0o: SPILL_WINDOW +tl1_s1o: SPILL_WINDOW +tl1_s2o: SPILL_WINDOW +tl1_s3o: SPILL_WINDOW +tl1_s4o: SPILL_WINDOW +tl1_s5o: SPILL_WINDOW +tl1_s6o: SPILL_WINDOW +tl1_s7o: SPILL_WINDOW +tl1_f0n: FILL_WINDOW +tl1_f1n: FILL_WINDOW +tl1_f2n: FILL_WINDOW +tl1_f3n: FILL_WINDOW +tl1_f4n: FILL_WINDOW +tl1_f5n: FILL_WINDOW +tl1_f6n: FILL_WINDOW +tl1_f7n: FILL_WINDOW +tl1_f0o: FILL_WINDOW +tl1_f1o: FILL_WINDOW +tl1_f2o: FILL_WINDOW +tl1_f3o: FILL_WINDOW +tl1_f4o: FILL_WINDOW +tl1_f5o: FILL_WINDOW +tl1_f6o: FILL_WINDOW +tl1_f7o: FILL_WINDOW +tl1_resv100: BTRAPS(0x100) BTRAPS(0x108) +tl1_resv110: BTRAPS(0x110) BTRAPS(0x118) +tl1_resv120: BTRAPS(0x120) BTRAPS(0x128) +tl1_resv130: BTRAPS(0x130) BTRAPS(0x138) +tl1_resv140: BTRAPS(0x140) BTRAPS(0x148) +tl1_resv150: BTRAPS(0x150) BTRAPS(0x158) +tl1_resv160: BTRAPS(0x160) BTRAPS(0x168) +tl1_resv170: BTRAPS(0x170) BTRAPS(0x178) +tl1_resv180: BTRAPS(0x180) BTRAPS(0x188) +tl1_resv190: BTRAPS(0x190) BTRAPS(0x198) +tl1_resv1a0: BTRAPS(0x1a0) BTRAPS(0x1a8) +tl1_resv1b0: BTRAPS(0x1b0) BTRAPS(0x1b8) +tl1_resv1c0: BTRAPS(0x1c0) BTRAPS(0x1c8) +tl1_resv1d0: BTRAPS(0x1d0) BTRAPS(0x1d8) +tl1_resv1e0: BTRAPS(0x1e0) BTRAPS(0x1e8) +tl1_resv1f0: BTRAPS(0x1f0) BTRAPS(0x1f8) + + .section ".data" + .align 8 + .globl tlb_handler_stack_top, tlb_handler_stack_pointer, obp_ticks_pointer + + ! Stack for the tlb MMU trap handlers +tlb_handler_stack_bottom: + .skip 8192 +tlb_handler_stack_top: + .skip 8 + + ! MMU trap handler stack pointer +tlb_handler_stack_pointer: + .xword tlb_handler_stack_top + + ! Pointer to current tick value +obp_ticks_pointer: + .xword 0 + + .section ".text", "ax" + +spill_32bit: + srl %sp, 0, %sp + stw %l0, [%sp + 0x00] + stw %l1, [%sp + 0x04] + stw %l2, [%sp + 0x08] + stw %l3, [%sp + 0x0c] + stw %l4, [%sp + 0x10] + stw %l5, [%sp + 0x14] + stw %l6, [%sp + 0x18] + stw %l7, [%sp + 0x1c] + stw %i0, [%sp + 0x20] + stw %i1, [%sp + 0x24] + stw %i2, [%sp + 0x28] + stw %i3, [%sp + 0x2c] + stw %i4, [%sp + 0x30] + stw %i5, [%sp + 0x34] + stw %i6, [%sp + 0x38] + stw %i7, [%sp + 0x3c] + saved + retry + +fill_32bit: + srl %sp, 0, %sp + lduw [%sp + 0x00], %l0 + lduw [%sp + 0x04], %l1 + lduw [%sp + 0x08], %l2 + lduw [%sp + 0x0c], %l3 + lduw [%sp + 0x10], %l4 + lduw [%sp + 0x14], %l5 + lduw [%sp + 0x18], %l6 + lduw [%sp + 0x1c], %l7 + lduw [%sp + 0x20], %i0 + lduw [%sp + 0x24], %i1 + lduw [%sp + 0x28], %i2 + lduw [%sp + 0x2c], %i3 + lduw [%sp + 0x30], %i4 + lduw [%sp + 0x34], %i5 + lduw [%sp + 0x38], %i6 + lduw [%sp + 0x3c], %i7 + restored + retry + +/* + * SAVE_CPU_STATE and RESTORE_CPU_STATE are macros used to enable a context switch + * to C to occur within the MMU I/D TLB miss handlers. + * + * Because these handlers are called on a TLB miss, we cannot use flushw to store + * processor window state on the stack, as the memory areas used by each window's + * stack pointer may not be in the TLB, causing recursive TLB miss traps. + * + * For this reason, we save window state by manually rotating the window registers + * and saving their contents (along with other vital registers) into a special + * tlb_handler_stack defined above which is guaranteed to be locked in the TLB, and + * so won't cause issues with trap recursion. + * + * Once this process is complete, we remain in a TL=0, CWP=0 state (with IE=1 to allow + * window fill/spill traps if required), switch to our safe tlb_handler_stack and + * invoke the miss handler. + */ + +#define SAVE_CPU_STATE(type) \ + /* Set up our exception stack pointer in %g1 */ \ + setx tlb_handler_stack_pointer, %g7, %g6; \ + ldx [%g6], %g1; \ + add %g1, -0x510, %g1; \ + \ + /* First save the various state registers */ \ + rdpr %cwp, %g7; \ + stx %g7, [%g1]; \ + rdpr %cansave, %g7; \ + stx %g7, [%g1 + 0x8]; \ + rdpr %canrestore, %g7; \ + stx %g7, [%g1 + 0x10]; \ + rdpr %otherwin, %g7; \ + stx %g7, [%g1 + 0x18]; \ + rdpr %wstate, %g7; \ + stx %g7, [%g1 + 0x20]; \ + rdpr %cleanwin, %g7; \ + stx %g7, [%g1 + 0x28]; \ + rdpr %pstate, %g7; \ + stx %g7, [%g1 + 0x30]; \ + \ + rd %y, %g7; \ + stx %g7, [%g1 + 0x38]; \ + rd %fprs, %g7; \ + stx %g7, [%g1 + 0x40]; \ + \ + rdpr %tl, %g7; \ + stx %g7, [%g1 + 0x48]; \ + \ + /* Trap state */ \ + add %g1, 0x50, %g5; \ + mov 4, %g6; \ + \ +save_trap_state_##type: \ + deccc %g6; \ + wrpr %g6, %tl; \ + rdpr %tpc, %g7; \ + stx %g7, [%g5]; \ + rdpr %tnpc, %g7; \ + stx %g7, [%g5 + 0x8]; \ + rdpr %tstate, %g7; \ + stx %g7, [%g5 + 0x10]; \ + rdpr %tt, %g7; \ + stx %g7, [%g5 + 0x18]; \ + bne save_trap_state_##type; \ + add %g5, 0x20, %g5; \ + \ + /* For 4 trap levels with 4 registers, memory required is + 4*8*4 = 0x80 bytes */ \ + \ + /* Save the o registers */ \ + stx %o0, [%g1 + 0xd0]; \ + stx %o1, [%g1 + 0xd8]; \ + stx %o2, [%g1 + 0xe0]; \ + stx %o3, [%g1 + 0xe8]; \ + stx %o4, [%g1 + 0xf0]; \ + stx %o5, [%g1 + 0xf8]; \ + stx %o6, [%g1 + 0x100]; \ + stx %o7, [%g1 + 0x108]; \ + \ + /* Now iterate through all of the windows saving all l and i registers */ \ + add %g1, 0x110, %g5; \ + \ + /* Get the number of windows in %g6 */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + inc %g6; \ + \ +save_cpu_window_##type: \ + deccc %g6; \ + wrpr %g6, %cwp; \ + stx %l0, [%g5]; \ + stx %l1, [%g5 + 0x8]; \ + stx %l2, [%g5 + 0x10]; \ + stx %l3, [%g5 + 0x18]; \ + stx %l4, [%g5 + 0x20]; \ + stx %l5, [%g5 + 0x28]; \ + stx %l6, [%g5 + 0x30]; \ + stx %l7, [%g5 + 0x38]; \ + stx %i0, [%g5 + 0x40]; \ + stx %i1, [%g5 + 0x48]; \ + stx %i2, [%g5 + 0x50]; \ + stx %i3, [%g5 + 0x58]; \ + stx %i4, [%g5 + 0x60]; \ + stx %i5, [%g5 + 0x68]; \ + stx %i6, [%g5 + 0x70]; \ + stx %i7, [%g5 + 0x78]; \ + bne save_cpu_window_##type; \ + add %g5, 0x80, %g5; \ + \ + /* For 8 windows with 16 registers to save in the window, memory required + is 16*8*8 = 0x400 bytes */ \ + \ + /* Now we should be in window 0 so update the other window registers */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + dec %g6; \ + wrpr %g6, %cansave; \ + \ + wrpr %g0, %cleanwin; \ + wrpr %g0, %canrestore; \ + wrpr %g0, %otherwin; \ + \ + /* Update our exception stack pointer */ \ + setx tlb_handler_stack_pointer, %g7, %g6; \ + stx %g1, [%g6]; + + +#define RESTORE_CPU_STATE(type) \ + /* Set up our exception stack pointer in %g1 */ \ + setx tlb_handler_stack_pointer, %g7, %g6; \ + ldx [%g6], %g1; \ + \ + /* Get the number of windows in %g6 */ \ + rdpr %ver, %g6; \ + and %g6, 0xf, %g6; \ + inc %g6; \ + \ + /* Now iterate through all of the windows restoring all l and i registers */ \ + add %g1, 0x110, %g5; \ + \ +restore_cpu_window_##type: \ + deccc %g6; \ + wrpr %g6, %cwp; \ + ldx [%g5], %l0; \ + ldx [%g5 + 0x8], %l1; \ + ldx [%g5 + 0x10], %l2; \ + ldx [%g5 + 0x18], %l3; \ + ldx [%g5 + 0x20], %l4; \ + ldx [%g5 + 0x28], %l5; \ + ldx [%g5 + 0x30], %l6; \ + ldx [%g5 + 0x38], %l7; \ + ldx [%g5 + 0x40], %i0; \ + ldx [%g5 + 0x48], %i1; \ + ldx [%g5 + 0x50], %i2; \ + ldx [%g5 + 0x58], %i3; \ + ldx [%g5 + 0x60], %i4; \ + ldx [%g5 + 0x68], %i5; \ + ldx [%g5 + 0x70], %i6; \ + ldx [%g5 + 0x78], %i7; \ + bne restore_cpu_window_##type; \ + add %g5, 0x80, %g5; \ + \ + /* Restore the window registers to their original value */ \ + ldx [%g1], %g7; \ + wrpr %g7, %cwp; \ + ldx [%g1 + 0x8], %g7; \ + wrpr %g7, %cansave; \ + ldx [%g1 + 0x10], %g7; \ + wrpr %g7, %canrestore; \ + ldx [%g1 + 0x18], %g7; \ + wrpr %g7, %otherwin; \ + ldx [%g1 + 0x20], %g7; \ + wrpr %g7, %wstate; \ + ldx [%g1 + 0x28], %g7; \ + wrpr %g7, %cleanwin; \ + ldx [%g1 + 0x30], %g7; \ + wrpr %g7, %pstate; \ + \ + /* Restore the o registers */ \ + ldx [%g1 + 0xd0], %o0; \ + ldx [%g1 + 0xd8], %o1; \ + ldx [%g1 + 0xe0], %o2; \ + ldx [%g1 + 0xe8], %o3; \ + ldx [%g1 + 0xf0], %o4; \ + ldx [%g1 + 0xf8], %o5; \ + ldx [%g1 + 0x100], %o6; \ + ldx [%g1 + 0x108], %o7; \ + \ + /* Restore the trap state */ \ + add %g1, 0x50, %g5; \ + mov 4, %g6; \ + \ +restore_trap_state_##type: \ + deccc %g6; \ + wrpr %g6, %tl; \ + ldx [%g5], %g7; \ + wrpr %g7, %tpc; \ + ldx [%g5 + 0x8], %g7; \ + wrpr %g7, %tnpc; \ + ldx [%g5 + 0x10], %g7; \ + wrpr %g7, %tstate; \ + ldx [%g5 + 0x18], %g7; \ + wrpr %g7, %tt; \ + bne restore_trap_state_##type; \ + add %g5, 0x20, %g5; \ + \ + ldx [%g1 + 0x38], %g7; \ + wr %g7, 0, %y; \ + ldx [%g1 + 0x40], %g7; \ + wr %g7, 0, %fprs; \ + ldx [%g1 + 0x48], %g7; \ + wrpr %g7, %tl; \ + \ + /* Restore exception stack pointer to previous value */ \ + setx tlb_handler_stack_pointer, %g7, %g6; \ + add %g1, 0x510, %g1; \ + stx %g1, [%g6]; + + + .globl reload_DMMU_tlb, reload_IMMU_tlb, bug + +reload_DMMU_tlb: + + SAVE_CPU_STATE(dtlb) + + /* Switch to TLB locked stack space (note we add an additional 192 bytes required for + gcc to save its arguments when building with -O0) */ + add %g1, -STACK_BIAS - 192, %sp + + /* Enable interrupts for window spill/fill traps */ + rdpr %pstate, %g7 + or %g7, PSTATE_IE, %g7 + wrpr %g7, %pstate + + call dtlb_miss_handler + nop + + /* Disable interrupts */ + rdpr %pstate, %g7 + andn %g7, PSTATE_IE, %g7 + wrpr %g7, %pstate + + RESTORE_CPU_STATE(dtlb) + + retry + +reload_IMMU_tlb: + + SAVE_CPU_STATE(itlb) + + /* Switch to TLB locked stack space (note we add an additional 192 bytes required for + gcc to save its arguments when building with -O0) */ + add %g1, -STACK_BIAS - 192, %sp + + /* Enable interrupts for window spill/fill traps */ + rdpr %pstate, %g7 + or %g7, PSTATE_IE, %g7 + wrpr %g7, %pstate + + call itlb_miss_handler + nop + + /* Disable interrupts */ + rdpr %pstate, %g7 + andn %g7, PSTATE_IE, %g7 + wrpr %g7, %pstate + + RESTORE_CPU_STATE(itlb) + + retry + +softint_irq_tl1: +softint_irq: + mov 1, %g2 + /* clear tick interrupt */ + wr %g2, 0x0, %clear_softint + sll %g2, %g1, %g2 + sra %g2, 0, %g2 + /* clear softint interrupt */ + wr %g2, 0x0, %clear_softint + + setx TICK_INT_DIS, %g2, %g1 + rd %tick, %g2 + and %g1, %g2, %g1 + brnz,pn %g1, tick_compare_disabled + nop + + /* update tick value if pointer set */ + setx obp_ticks_pointer, %g3, %g1 + ldx [%g1], %g3 + brz %g3, tick_rearm + nop + + ldx [%g3], %g1 + add %g1, 10, %g1 ! 100Hz = 10ms + stx %g1, [%g3] + +tick_rearm: + set TICK_INTERVAL, %g1 + add %g1, %g2, %g1 + wr %g1, 0, %tick_cmpr +tick_compare_disabled: + retry + +handler_irq: +__divide_error: +bug: + /* Dump the exception and its context */ + ! Set up CPU state + ! Don't change the global register set or we lose %g1 (exception level) + rdpr %pstate, %g2 + or %g2, PSTATE_PRIV, %g2 + wrpr %g2, %pstate + wr %g0, 0, %fprs + + ! Jump to ROM ... + setx _start, %g2, %g3 + setx highmem, %g2, %g4 + sub %g4, %g3, %g4 + setx PROM_ADDR, %g2, %g3 + add %g4, %g3, %g3 + jmp %g3 + ! ... while disabling I/D MMUs and caches + stxa %g0, [%g0] ASI_LSU_CONTROL + +highmem: + ! Extract NWINDOWS from %ver + rdpr %ver, %g2 + and %g2, 0xf, %g2 + wrpr %g2, 0, %cleanwin + wrpr %g2, 0, %cansave + wrpr %g0, 0, %canrestore + wrpr %g0, 0, %otherwin + wrpr %g0, 0, %wstate + + b dump_exception + nop + +outstr: + /* void outstr (unsigned long port, const unsigned char *str); + * Writes a string on an IO port. + */ +1: ldub [%o1], %o3 + cmp %o3, 0 + be 2f + nop + stba %o3, [%o0] ASI_BP + b 1b + inc %o1 +2: retl + nop + +outdigit: + /* void outdigit (unsigned long port, uint8_t digit); + * Dumps a single digit on serial port. + */ + add %o1, '0', %o1 + retl + stba %o1, [%o0] ASI_BP + +outhex: + /* void outhex (unsigned long port, uint64_t value); + * Dumps a 64 bits hex number on serial port + */ + mov %o1, %o2 + set 60, %o3 + srlx %o2, %o3, %o1 +1: and %o1, 0xf, %o1 + cmp %o1, 9 + bgt 2f + nop + b 3f + add %o1, '0', %o1 +2: add %o1, 'a' - 10, %o1 +3: stba %o1, [%o0] ASI_BP + subcc %o3, 4, %o3 + bge 1b + srlx %o2, %o3, %o1 + retl + nop + + /* void dump_exception (); + * + * Dump a message when catching an exception + */ +dump_exception: + setx SER_ADDR, %o3, %o0 + set _start, %g3 + set (_BUG_message_0), %o1 + sub %o1, %g3, %g4 + setx PROM_ADDR, %g2, %g3 + add %g4, %g3, %g3 + call outstr + mov %g3, %o1 + + call outhex + mov %g1, %o1 + + call outstr + add %g3, (_BUG_message_1 - _BUG_message_0), %o1 + + call outhex + rdpr %tpc, %o1 + + call outstr + add %g3, (_BUG_message_2 - _BUG_message_0), %o1 + + call outhex + rdpr %tnpc, %o1 + + call outstr + add %g3, (_BUG_message_3 - _BUG_message_0), %o1 + +_forever: + /* Loop forever */ + b _forever ; + nop + + .section .rodata +_BUG_message_0: + .string "Unhandled Exception 0x" +_BUG_message_1: + .string "\nPC = 0x" +_BUG_message_2: + .string " NPC = 0x" +_BUG_message_3: + .string "\nStopping execution\n" diff --git a/qemu/roms/openbios/arch/unix/Kconfig b/qemu/roms/openbios/arch/unix/Kconfig new file mode 100644 index 000000000..8faafc0af --- /dev/null +++ b/qemu/roms/openbios/arch/unix/Kconfig @@ -0,0 +1,18 @@ + +config HOST_UNIX + bool "Build Hosted Unix binary" + default y + help + Build a version of the OpenBIOS kernel that runs in a + Unix-like operating system. + +config UNIX_QT + depends HOST_UNIX + bool "QT frontend for Unix binary" + default n + help + Enable this option if you wish to add a graphical user + interface to the openbios hosted unix binary. This option + needs the QT library installed. + +source "arch/unix/plugins/Kconfig" diff --git a/qemu/roms/openbios/arch/unix/Makefile b/qemu/roms/openbios/arch/unix/Makefile new file mode 100644 index 000000000..a8c6565e9 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/Makefile @@ -0,0 +1,29 @@ +# + +include ../../config/Makefile.top + +SUBDIRS-$(CONFIG_PLUGINS) = plugins +SUBDIRS-$(CONFIG_UNIX_QT) = gui_qt + +DICTIONARIES = unix +unix-SRC = tree.fs $(ARCHDICT_SRC) + +PROGRAMS = unix + +unix-OBJS = $(unix-y) +unix-y += blk.o +unix-y += boot.o +unix-y += unix.o +unix-y += $(KOBJS) +unix-y += $(MODULE_LIBS) $(FS_LIBS) $(DRIVER_LIBS) $(LIBC_LIBS) +unix-$(CONFIG_PLUGINS) += plugins.o + +unix-LDFLAGS = $(unix-LDFLAGS-$(CONFIG_PLUGINS)) +unix-LDFLAGS-y = -rdynamic $(LIBDL_LDFLAGS) +unix-LDFLAGS-n = +unix-LDADD = + +INCLUDES = -I../../kernel -I../../kernel/include -DBOOTSTRAP + +include $(rules)/Rules.forth +include $(rules)/Rules.make diff --git a/qemu/roms/openbios/arch/unix/blk.c b/qemu/roms/openbios/arch/unix/blk.c new file mode 100644 index 000000000..d0f5c6a42 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/blk.c @@ -0,0 +1,115 @@ +/* + * <arch/unix/blk.c> + * + * block device emulation for unix hosts + * + * Copyright (C) 2004 Stefan Reinauer <stepan@openbios.org> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "blk.h" + +typedef struct { + int unit; + int channel; +} blk_data_t; + + +DECLARE_NODE( blk, INSTALL_OPEN, sizeof(blk_data_t), "+/unix/block/disk" ); + +static void +blk_open( blk_data_t *pb ) +{ + phandle_t ph; + + fword("my-unit"); + + pb->unit = POP(); + pb->channel = 0; /* FIXME */ + + selfword("open-deblocker"); + + /* interpose disk-label */ + ph = find_dev("/packages/disk-label"); + fword("my-args"); + PUSH_ph( ph ); + fword("interpose"); + + /* printk("osi-blk: open %d\n", pb->unit ); */ + + PUSH( -1 ); +} + +static void +blk_close( __attribute__((unused)) blk_data_t *pb ) +{ + selfword("close-deblocker"); +} + + +/* ( buf blk nblks -- actual ) */ +static void +blk_read_blocks( blk_data_t *pb ) +{ + cell i, n = POP(); + cell blk = POP(); + char *dest = (char*)POP(); + + // printk("blk_read_blocks %x block=%d n=%d\n", (ucell)dest, blk, n ); + + for( i=0; i<n; ) { + char buf[4096]; + ucell m = MIN( n-i, sizeof(buf)/512 ); + + if( read_from_disk(pb->channel, pb->unit, blk+i, (ucell)buf, m*512) < 0 ) { + printk("read_from_disk: error\n"); + RET(0); + } + memcpy( dest, buf, m * 512 ); + i += m; + dest += m * 512; + } + PUSH( n ); +} + +/* ( -- bs ) */ +static void +blk_block_size( __attribute__((unused)) blk_data_t *pb ) +{ + PUSH( 512 ); +} + +/* ( -- maxbytes ) */ +static void +blk_max_transfer( __attribute__((unused)) blk_data_t *pb ) +{ + PUSH( 1024*1024 ); +} + +static void +blk_initialize( __attribute__((unused)) blk_data_t *pb ) +{ + fword("is-deblocker"); +} + + +NODE_METHODS( blk ) = { + { NULL, blk_initialize }, + { "open", blk_open }, + { "close", blk_close }, + { "read-blocks", blk_read_blocks }, + { "block-size", blk_block_size }, + { "max-transfer", blk_max_transfer}, +}; + +void +blk_init( void ) +{ + REGISTER_NODE( blk ); +} diff --git a/qemu/roms/openbios/arch/unix/blk.h b/qemu/roms/openbios/arch/unix/blk.h new file mode 100644 index 000000000..aa3b96560 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/blk.h @@ -0,0 +1,8 @@ + +#ifndef _H_BLK +#define _H_BLK + +extern void blk_init( void ); +extern int read_from_disk( int channel, int unit, int blk, unsigned long mphys, int size ); + +#endif /* _H_BLK */ diff --git a/qemu/roms/openbios/arch/unix/boot.c b/qemu/roms/openbios/arch/unix/boot.c new file mode 100644 index 000000000..f4a29428b --- /dev/null +++ b/qemu/roms/openbios/arch/unix/boot.c @@ -0,0 +1,84 @@ +/* + * + */ +#undef BOOTSTRAP +#include "config.h" +#include "libopenbios/bindings.h" +#include "libopenbios/elf_load.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" + +void boot(void); +void *load_elf(char *spec); + +void +*load_elf(char *spec) +{ +#if 0 + int fd; + void *entry=NULL; + int i, lszz_offs, elf_offs; + char buf[128]; // , *addr; + Elf_ehdr ehdr; + Elf_phdr *phdr; + size_t s; + + if( (fd=open_io(spec)) == -1 ) + return NULL; + + if( (elf_offs=find_elf(fd)) < 0 ) { + printk("----> %s is not an ELF image\n", buf ); + return NULL; + } + + if( !(phdr=elf_readhdrs(fd, 0, &ehdr)) ) { + printk("elf32_readhdrs failed\n"); + return NULL; + } + + (unsigned long long *)entry = ehdr.e_entry; + + lszz_offs = elf_offs; + for( i=0; i<ehdr.e_phnum; i++ ) { + s = MIN( phdr[i].p_filesz, phdr[i].p_memsz ); + seek_io( fd, elf_offs + phdr[i].p_offset ); + /* printk("filesz: %08lX memsz: %08lX p_offset: %08lX p_vaddr %08lX\n", + phdr[i].p_filesz, phdr[i].p_memsz, phdr[i].p_offset, + phdr[i].p_vaddr ); */ + if( phdr[i].p_vaddr != phdr[i].p_paddr ) + printk("WARNING: ELF segment virtual addr != physical addr\n"); + lszz_offs = MAX( lszz_offs, elf_offs + phdr[i].p_offset + phdr[i].p_filesz ); + if( !s ) + continue; + + printk("ELF ROM-section loaded at %08lX (size %08lX)\n", + (unsigned long)phdr[i].p_vaddr, (unsigned long)phdr[i].p_memsz); + } + free( phdr ); + return entry; +#else + return NULL; +#endif +} + +void +boot( void ) +{ + char *path; + void *entry; + + /* Copy the incoming path */ + fword("2dup"); + path = pop_fstr_copy(); + + if(!path) { + printk("[unix] Booting default not supported.\n"); + return; + } + printk("[unix] Booting '%s'\n",path); + entry=load_elf(path); + if(entry) + printk("successfully loaded client at %llx.\n", (unsigned long long)(ucell)entry); + else + printk("failed.\n"); +} diff --git a/qemu/roms/openbios/arch/unix/build.xml b/qemu/roms/openbios/arch/unix/build.xml new file mode 100644 index 000000000..bc0cf9e74 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/build.xml @@ -0,0 +1,23 @@ +<build condition="HOST_UNIX"> + + <dictionary name="openbios-unix" init="openbios" target="forth"> + <object source="tree.fs"/> + </dictionary> + + <executable name="openbios-unix" target="target"> + <rule> + $(call quiet-command,$(CC) $(CFLAGS) -rdynamic $(LIBDL_LDFLAGS) -o $@ $^," LINK $(TARGET_DIR)$@") + </rule> + <object source="unix.c" flags="-DBOOTSTRAP"/> + <object source="boot.c" flags="-DBOOTSTRAP"/> + <object source="blk.c" flags="-DBOOTSTRAP"/> + <object source="plugins.c" flags="-DBOOTSTRAP" condition="PLUGINS"/> + <external-object source="libbootstrap.a"/> + <external-object source="libpackages.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libdrivers.a"/> + <external-object source="libfs.a"/> + <external-object source="liblibc.a"/> + </executable> + +</build> diff --git a/qemu/roms/openbios/arch/unix/gui_qt/Makefile b/qemu/roms/openbios/arch/unix/gui_qt/Makefile new file mode 100644 index 000000000..20eb15809 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/Makefile @@ -0,0 +1,42 @@ +# +# Makefile of QT user interface for OpenBIOS +# +# (C) 2004 Stefan Reinauer <stepan@openbios.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# version 2 +# + +include ../../../config/Makefile.top + +XTARGETS = qt + +qt-OBJS = $(obj-y) +obj-y += gui_qt.o + +QMAKE = qmake +UIDIR = $(shell pwd ) +TOPDIR = $(shell cd $(top_srcdir) ; pwd) +ABSOINC = $(shell cd $(ARCHINCLUDES) 2> /dev/null ; pwd ) + +export UIDIR TOPDIR ABSOINC + +$(ODIR)/makefile.qmake: gui-qt.pro Makefile + @echo "ODIR: $(ODIR)" + @test -d $(ODIR) || $(INSTALL) -d $(ODIR) + @test -d $(ODIR)/qbuild || $(INSTALL) -d $(ODIR)/qbuild + @install -m 644 gui-qt.pro $(ODIR)/ + cd $(ODIR) ; $(QMAKE) -o makefile.qmake + +$(ODIR)/libgui_qt.a: $(ODIR)/makefile.qmake $(wildcard *.cpp) + cd $(ODIR) ; $(MAKE) -f makefile.qmake + @ln -f $(ODIR)/qbuild/libgui_qt.a $@ + +clean-local: + @rm -f $(ODIR)/makefile.qmake + @rm -rf $(QBUILDDIR) + +INCLUDES = -I$(top_srcdir)/include -DBOOTSTRAP + +include $(rules)/Rules.make diff --git a/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.cpp b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.cpp new file mode 100644 index 000000000..24c084283 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.cpp @@ -0,0 +1,128 @@ +/* tag: qt user interface fb class + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "gui-qt.h" +#include "logo.xpm" + +#include <iostream> + +static const int sizex=640; +static const int sizey=480; +static const int depth=8; + +static unsigned char color[256][3]={ + { 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0xaa }, + { 0x00, 0xaa, 0x00 }, + { 0x00, 0xaa, 0xaa }, + { 0xaa, 0x00, 0x00 }, + { 0xaa, 0x00, 0xaa }, + { 0xaa, 0x55, 0x00 }, + { 0xaa, 0xaa, 0xaa }, + { 0x55, 0x55, 0x55 }, + { 0x55, 0x55, 0xff }, + { 0x55, 0xff, 0x55 }, + { 0x55, 0xff, 0xff }, + { 0xff, 0x55, 0x55 }, + { 0xff, 0x55, 0xff }, + { 0xff, 0xff, 0x55 }, + { 0xff, 0xff, 0xff }, +}; + +FrameBufferWidget::FrameBufferWidget(QWidget *parent, const char * name) +: QWidget(parent, name, Qt::WType_TopLevel) +{ + setCaption ("OpenBIOS"); + setIcon(QPixmap(logo)); + + QPopupMenu *file = new QPopupMenu (this); + + file->insertItem( "E&xit", this, SLOT(quit()), CTRL+Key_Q ); + + QPopupMenu *help = new QPopupMenu( this ); + help->insertItem("&About OpenBIOS", this, SLOT(about()), CTRL+Key_H ); + help->insertItem( "About &Qt", this, SLOT(aboutQt()) ); + + menu = new QMenuBar( this ); + Q_CHECK_PTR( menu ); + menu->insertItem( "&File", file ); + menu->insertSeparator(); + menu->insertItem( "&Help", help ); + menu->setSeparator( QMenuBar::InWindowsStyle ); + + setFixedSize(sizex,sizey+menu->heightForWidth(sizex)); + + buffer.create(sizex, sizey, depth, 256); + + for (int i=16; i < 256; i++) { + color[i][0]=i; + color[i][1]=i; + color[i][2]=i; + } + + for (int i=0; i< 256; i++) + buffer.setColor(i, qRgb(color[i][0], color[i][1], color[i][2])); + + buffer.fill( 0 ); + + updatetimer=new QTimer(this); + connect( updatetimer, SIGNAL(timeout()), this, SLOT(update()) ); + updatetimer->start(200,FALSE); + + setMouseTracking( TRUE ); +} + +unsigned char * FrameBufferWidget::getFrameBuffer(void) +{ + return buffer.bits(); +} + +void FrameBufferWidget::paintEvent ( QPaintEvent * ) +{ + QPainter p( this ); + p.drawImage(0,menu->heightForWidth(sizex),buffer, 0,0, sizex, sizey); +} + +void FrameBufferWidget::about() +{ + QMessageBox::about( this, "About OpenBIOS", + " Welcome to OpenBIOS 1.01\n" + " IEEE 1275-1994 Open Firmware implementation\n\n" + "written by Stefan Reinauer <stepan@openbios.org>\n\n" + " http://www.openbios.org/\n"); +} + +void FrameBufferWidget::aboutQt() +{ + QMessageBox::aboutQt( this, "OpenBIOS" ); +} + +void FrameBufferWidget::quit() +{ + extern volatile int gui_running; + extern volatile int runforth; + + gui_running=0; + interruptforth=1; + + qApp->quit(); +} + +void FrameBufferWidget::update() +{ + QPainter p( this ); + p.drawImage(0,menu->heightForWidth(sizex),buffer, 0,0, sizex, sizey); +} + +void FrameBufferWidget::keyPressEvent(QKeyEvent * e) +{ + int a=e->ascii(); + if (a) { + std::cout << " key '" << e->text() << "' pressed" << std::endl; + } +} diff --git a/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.h b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.h new file mode 100644 index 000000000..202619f7e --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.h @@ -0,0 +1,44 @@ +/* tag: qt user interface fb class description + * + * Copyright (C) 2003-2004 Stefan Reinauer <stepan@openbios.org> + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#ifndef __framebufferwidget_h +#define __framebufferwidget_h + +#include <qapplication.h> +#include <qwidget.h> +#include <qimage.h> +#include <qpainter.h> +#include <qmenubar.h> +#include <qpopupmenu.h> +#include <qmessagebox.h> +#include <qstatusbar.h> +#include <qtimer.h> + +class FrameBufferWidget : public QWidget { + Q_OBJECT + public: + FrameBufferWidget(QWidget *parent=0, const char *name=0); + unsigned char *getFrameBuffer(void); + + public slots: + void quit(); + void about(); + void aboutQt(); + void update(); + + private: + QImage buffer; + QMenuBar *menu; + QStatusBar *status; + QTimer *updatetimer; + void paintEvent ( QPaintEvent * ); + protected: + void keyPressEvent(QKeyEvent * e); +}; + +#endif diff --git a/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.pro b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.pro new file mode 100644 index 000000000..f58baecff --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/gui-qt.pro @@ -0,0 +1,18 @@ +# tag: qmake project file for OpenBIOS QT user interface +# +# Copyright (C) 2003-2004 Stefan Reinauer <stepan@openbios.org> +# +# See the file "COPYING" for further information about +# the copyright and warranty status of this work. +# + +TEMPLATE = lib +CONFIG += qt thread warn_on release staticlib +LIBS = +INCLUDEPATH = qbuild $(ABSOINC) $(TOPDIR)/include +DESTDIR = qbuild +OBJECTS_DIR = qbuild +MOC_DIR = qbuild +TARGET = gui_qt +HEADERS = $(UIDIR)/gui-qt.h +SOURCES = $(UIDIR)/gui-qt.cpp $(UIDIR)/qt-main.cpp diff --git a/qemu/roms/openbios/arch/unix/gui_qt/logo.xpm b/qemu/roms/openbios/arch/unix/gui_qt/logo.xpm new file mode 100644 index 000000000..9e2ac60b4 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/logo.xpm @@ -0,0 +1,132 @@ +/* This logo was created by Stephan Lau, + * created to xpm by Stefan Reinauer + */ +static char *logo[] = { +/* columns rows colors chars-per-pixel */ +"300 80 44 1", +" c #010101", +". c #070709", +"X c #0B0B0B", +"o c #0F0F11", +"O c #121212", +"+ c #1B1B1B", +"@ c #1F1F21", +"# c #232323", +"$ c #262628", +"% c #2B2B2C", +"& c #2E2E30", +"* c #333333", +"= c #373739", +"- c #3B3B3B", +"; c #434343", +": c #464648", +"> c #4B4B4B", +", c #4E4E50", +"< c #535353", +"1 c #5B5B5B", +"2 c #5E5E60", +"3 c #646464", +"4 c #666668", +"5 c #6B6B6B", +"6 c #747474", +"7 c #767678", +"8 c #7B7B7B", +"9 c #838383", +"0 c #8A8A8A", +"q c #939394", +"w c #979799", +"e c #9B9B9B", +"r c #A3A3A3", +"t c #ABABAB", +"y c #B4B4B4", +"u c #BBBBBB", +"i c #C3C3C3", +"p c #CBCBCB", +"a c #D3D3D3", +"s c #DBDBDB", +"d c #E3E3E3", +"f c #EBEBEB", +"g c #F3F3F3", +"h c #FEFEFE", +/* pixels */ +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfdssaapuuuytteeewq0009998867666555555555555565666778899000qwwerttyyuuppassdfghhhhhhhhhhgfgggghhhgfgfghhhhggffghhhhggffghhhhgfggghhhhgfggghhhhgfgfghhhhfgfgghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfdsapuytrwq0986555554455555555555555555555555555555555555555555555555555555555555555555555555556790qertyiuuuafhhhfpiishhhhfipidhhhhfiiidhhhhdiiifhhhhsiiifhhhhsiipghhhhaiipghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfdaiuttq0976555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555558iuue5579wuuuuiasfduuishhhhduuudhhhhduuudhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfdaittw086555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555558yuur55549uuiw55569uuutyiadsuuudhhhhsuuudhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfapyrw975555555555555555555555555555555555555555555555555555555555555555555555555555555554555555555555555555554455555555555555555555558uuue54559uuuw55559uuuq55550uiutypafduuufhhhhsuuufhhhhsuuufhhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdautw965555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555679qqerttuuppaasdddffgghghhhhhhhhhghhggfduuupaappuuuuyeq090uuuq55559uyi05555quuuuadghsuuufhhhhauuufhhhhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfsite0655555555555555555555555555555555555555555555555555555555555555555555555455555555555555555690wrtiiaddghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfuuuahhhhfuuushhhhfuuuaaiittuuuq55550uuu95560tuuudhhhhsuuughhhhauuufhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhgsite955555555555555555555555555455555555555555555555555555555555555555555555555545555555555570wryiadfhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhguuuahhhhfuuuahhhhfuuushhhhduuudfsaiuuuuq5555qiuu99etipuuifhhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaut0655555555555555555555555555555555555555555555556555555555555555555555555555555555554559qruisfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdsdfhhhhgdddfhhhhfddsfhhhhgdddfhhhhfddsffspyteeq755559qetisfhgfdddghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgsir065555555555555555555555555555455555555555555555554555555555555555555555555555555555580rupsghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsuudhhhhhhhhhhhhfuuphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgspyt085555560tudghhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaue9555555555555555554<----=---=---==-==<555555---:3:--=--=-*--==--<55555545<;------==->135890phhhhhy009tfq0009009090909wshhhhhhg<;;:;;;:<9fhhhhhhhf$ rhhhhhs3# ;phhhhhhhf0# Owghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdpue0655559wuaghhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgsue855555455555555555555:O. *5455- *. &44555>O 6ghhh+ 5O ehghhh9 . Xighhhhh9 -gfggf3 +sddffd8O rddffffffffgffffgffffffffggffffffffgffffgffdaute09868eusghhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfpr955555555555555555555555% .%=************& +2555o +=************% +3343% X-<3568888787884. ;dggq. O19888888888888, 8fgghsO . 1fggghsO ysdfiO 9ttuu> . 1rtuyuuuuuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuuuuuuuiiuuuut06449rpdhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhduw85555555555555555555555555* .,111<1111111111< #113- #<<111111111111< #123- Xtssaaaaaaaaaaaaa <sdf@ Otaaaaasaaaaaaaae 9sdgg, =sdggh< 2ipa0 7etr# <etttuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuighfauw857wudhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhfie7555555555555555555555554555: =1<<<<<<<<<<<<<<& -<<3X X<<><<<<1,,<<<<<& ;7e8 9apiiiiiipiiiiii6 0ia9 8uuuiipipiiiiiii> oyisdt X%% 2iadgy Xrty6 @69& X90e; *3% 49wttuuuuuuuuuuuuuuuuuuuuuuuuuuuyuyyyuuyuuuuuuuuuuihhhhhhgayw86eifhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhar8555555555555555555555555555543. +<,>>>,>><>>>>,,:. O;:<& -:;>>><>,,<><>,:. $eytO -puuyuuuuuuuuuiutX %rytO *ytrtyuuiuuuuuuu9 1ruis%. 108- . 8tisd% <qw9X #tre> *59, -86* O47qetuuuuuuuuuuuuuuuuuuuuuuuuuuuiasddsaiuuuuuuuuuuighhhhhhhhhgatq9tahhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhgiq55555555555555555555555555555555- ;>:>:,<<<,<<<<<<# . %-;: . O:;;;>>,<<>,,<38; 5qr3 eutttuuiiiipiiii1 5wr< qreeryuiipiiipii$ X0wru8 O976& +9wya0 O999O qeq9O >3< +751. &159wtyuuuuuuuuuuuuuuuuuuuuuuuuisfhhhhhhgdpuuuuuiuuihhhhhhhhhhhhhhdierighhhhhhh", +"hhhhhhhhhhhhhhhhhfi05555555555555555555555555555555552 #>;;:,,<<<11<11<> +--;+ ;;--;><<1116qtpy -009 ,ttrrtuppaaaaaaay -q09 ;ewqrtupaaaaaaap9 10qrtX .3754X . >60tuX 387% 3w09: +3<O. 153% O:159wtyuuuuiuuuuuuuuuuuuuuuuuuaghhhhhhhhhhhdiuuuuuuighhhhhhhhhhhhhhhhfaupghhhhh", +"hhhhhhhhhhhhhhhhiq55555555555555555555555555555555555+ X;:;;><<112311212+ .---& $;-;;><138eusddd- X000% oerrrtuaadsdddddd- o090$ Xwqqetypadddsddsao .%q9qr3 $856- +160t5 $761 X9097X ;1& &54< *;159wtyuuuuuuuuuuuuuuuuuuuuuushhhhhhhhhhhhhhdpyuuuuihhhhhhhhhhhhhhhhhhhhgsdhhhh", +"hhhhhhhhhhhhhhsr555555545555555555555555555555555555, %;;-:><123333535> %---O .;--;;<5wifgfgfgt 1w04 2ewerupsffgffggft 1w05 1wqqeyasffgfgggg9 7q0wq 6665 ,360w 666O <999= %32. . <31+. +>>160rtuuuuuuuuuuuuuuuuuuuuuyshhhhhhhhhhhhhhhhfuuuuuighhhhhhhhhhhhhhhhhhhhhhhghh", +"hhhhhhhhhhhhhi05555555555555555555555555555555555555o .X;;-::<1335555454X X:--$ &:--,6rsfghhghgh# Orq0O <<<<156999090999# +rqqO +qqqetisgghhghhha >rqqe* >867# *358e* >76; #9994 . .44- o2<>++++O>><48qrtuuuuuuuuuuuuiuuuuuuuuphhhhhhhhhhhhhhhhhhsyuiuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhu65555555555555555555555555555555555555- *;-->>1355555554- *;--. O;-<5rpdfhhhhhhh9 7rq< 6eq, 5w0wtisdgghhhhhh< Oqwqw8 X7773 X45608 X666. 3779% ;55X. %<1356651<<369etyuuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhhhhhgpyuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhi755555555555555555555555555555555555553. +;--;><2555555553. O:--$ *16qtiafhghhhhhgO *rq9X @,>:><356787888787653rq9X %wqqryadfghhhhhhy 3rqqrO <669O >569q+ <66* =8781 O953 &<24698533359qryuuuuuuuuuuuiuuuuuuuuuphhhhhhhhhhhhhhhhhhhhsyuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhs955555555555555555555555555555555555555% -;;;><1335555555$ -;;* %9wweypdfhhhhhhh4 eeq- 90990rtupaaaaaaaapiutee- 9qqerusfhhhhhhhh# +twqr1 @868= $867q1 @873 o5689O 166; &<36999865690etyyuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhhhhhhhfiuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhy55555555555555555555555555555555555555< #;--:,<3355555551 #;;-+ Xqwqetisfhghhhhhp 1eq7 >q999qrtuuipipuippuytrr8 :wqqruadfhhhhhhh9 6ewweX 363% #6689qX 276# >769, $867* +13800q9999qrtyuuuuuuuuuuuuuuuuuuuuuufhhhhhhhhhhhhhhhhhhhhhpuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh955555555555555555555555555555555555555@ .:-;;:<1335555554+ .;:-* 1wqqrupfghhhhhhh; Oeeq$ ..q0990qrtuuuuuuuuuuuuttr& XqqqetpdfghhhhhhfO *tewe> %8869q< *76< O6687X 4669$ .X159qeeeqqqrryuuuuuuuuuuuuuuuuuuuiuuighhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh55555555555555555555555555555555555555: $;-;;,<335555554: $:-2+ +qqqeyidgghhhhhhr 1rq3 1q000rryuipiiipiiiiiuuu7 1wqwtuadghhhhhhh6 qwww0 =20979q9 X566X <679= . -8680- . >69errtrrrtyyuuuuuuuuuuuuuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh95555555555555555555555555555555555555O X:--;><2355555553O O:162 3eqerusdghhhhhhf# $tqqO +qqqwrtipaaaaaaaaaaaaapp+ Oeqqetpsgghhhhhhs >ewqr&. ;q0998qe* >86; #7685 O6680e1 *50ettyyyyyuuuuuuuuuuuuuuuuuuuuuuuuuhhhhhhhhhhhhhhhhhhhhhhpuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhht655555555555555555555555555555555555: %;-;:<1335555555& .:500X +eqerypsghhhhhhh6 Oqeq3 1qqwryiasddddddddddddsd7 8wqqtuafghhhhhhh; Oreqw7 -999qw7. +665X 4679@ :789wt6 O50etyyuuuuuuuuuuuuuuuuuuuuuuuuuiuuughhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhs955555555555555555555555555555555555% --;;>1135555553- ,0eq> =wqerisfghhhhhf9 8rwq- 9qqetpsdffgfgffgfdttgfa *rqqryadghhhhhhhq 4rqwrO *-@ 79qeu+ ,76* . *7681 O8680ruy X49etyuuuuuuuuuuuuuuuuuuuuiuuuuuuuuudhhhhhhhhhhhhhhhhhhhhgiuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhu65555555555555555555555555555555554# .4eew9 X Oqteww= #dgg; 9wqwtisfghhhhhhfX Xewqe3 %63< @70ey5 #961 X6678X 3679ruip& 48wryuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuphhhhhhhhhhhhhhhhhhhhduuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhu7555555555555555554555555555555545,@X . .+>qyrre& X8O O-7utreer9=X ufg5 +ewqruadghhhhhhf; >eqweX . 451> -6qyyO 366# ;769< $769wtpaa3 O36qrtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuighhhhhhhhhhhhhhhhhhhpyuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhp95455555555555555555555555555555331:;---;><1111111117tutre8 1q999wtipaaasssaaaiutrrrruyrq09qruiasasasasassssddddaitrwetisfhghhhhhhgfautewr; -654% o56eu< =86: . O8687 6669ruada4 @160ryuuuuuuuuuuuuuuuuuuiuuuuuuuuuuuuahhhhhhhhhhhhhhhhhhsuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhde555555555555555555555555555555331,;---;;,<<<<<1<<8tutrtt+ Or099qwtuipppppppiiuytrtyiiiteq0qryupppppppppppppssdspurreriafghhhhhhhhgdaueee8 X665< ;38e9 X765X 1679% >669wyadfd5 *150rtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuushhghhhhhhhhhhhhhgiyuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhiq555555555555555555555555555533<<:;-;;>>,>,>,,,6ttyttt3 5q9990rttuuuuuuyuuyyttyupaapurewertyyuuuuuuuuuuuipasaputttypsgghhhhhhhggsautrt* ,667# .+159e* >86;. $6695 .8680tisfgd3 X:160rtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhgiuiuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhfi055555555555555555555555555332<>>:;:>>>,<>,>6tuuuiiuX *eq00wrryyuuuuyuuuuuyuiiasdsaputrtttuuyuyuuuuyyuupaassaiuyupsfghhhhhhhhhgdaiuy6 O967< 146q3 O865 5679O ,769wuafggfX #:150rtuuuuuuuuuuuuuuuuuuuuuuiuuuuuuuuuuushhhhhhhhhhhhfiuuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhfiq5555555555555555555554555431<<<,<<<<<<<15tippppa<. 0wqqetyippppppppppippaasdfgfdsapiipipppppppppppppaadddsaapasfghhhhhhhhhggfsapi+ 1678O -5589+ 176% -679, +85O rgg0 X-,36qrtuuuuuuuuuuuuiuuuuuuuuuuuuuuuuiuuuuupfghhhhhhhfauuuuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhat85555555555555555555555433221111111113tsssssdr >eqqetupaasaaasaasssasddfgggggfdssasassaassasaasssddffffddddfgghhhhhhhhhhhgfdd8 $878> X55601 $761 X5788o 37- -dfd@ &>,39qryuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuypsdffdspuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhfiw6555555555555555555555333332322331efffdffs+ qqwetiadfffdfddfffdfffffgghhhgggfffdfdffdfdfdfdfdfffggfggfggghhhhhhhhhhhhggggp 6666 >6699 676+ >679- =73 .yss8 .O,,159etyuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyuyuuuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhfiw7545555555555555555555545353350dgggghg4 -rqqruadfggghghhggghgghhhhhhhhhhghghhghgghghghghghghhhhhhhhghghhhhhhhhhhhhhhhg< ;669& +666q* -76, . O8686 X66$ <uiuO . -><57qryuuuuuuuuuuuuuuuuuuuuuuuuuiuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuughhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdir955555555555555555555555555uhhhhhhhgfsuteqrtpdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhu X7764 . 15696 .766# . <679$. <7< oqty- %<<149etyuuuuuuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuiuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsue85555455555555555555559dhhhhhhhgfauteeriadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh* >865X -667q# >765 668= =86% -0q1 +4357qtiasdddddddddddddddsdddddddsddddddsddddddddddddsddddddddddddshhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfaue755555555555555555ehhhhhhhhgdautrtuadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhq ;-% +76703 O868: . >>% +975 %2* X6669wuadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsit06553555555555phhhhhhhggfaiuuupsfghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfO . +76680X 3869- . %986> . . X5877qtpsgghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaur065455555dhhhhhhhhgfdaapadfghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh6 . -8767q> *7699* . . -0989; +98669qusfggfffghhhhgfffghhhhgfffghhhhgdfdghhhhgfffghhhhgfffghhhhdfffghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgspte955fhhhhhhhhggfddddfghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhs . O3987800 5760e4 O3099997 X;996136qpdfhfuuuahhhhduuushhhhduuudhhhhduuufhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfahhhhhhhhhhggffggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh- X%>688780r& ,869qry< #;89999qwr3o O=58887559rdghhguuushhhhfuuishhhhduuudhhhhduuufhhhhsuuufhhhhauuufhhhhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdauq841<15566890ryupute9880ruuur3<;1156889qrtyyr41>,145670979qyfgghfuuuahhhhfuuushhhhdiuudhhhhduuudhhhhsuuufhhhhauiughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhggdptq8433356789qrupaaite990ruppitq85345790wtypiitw84335680qe0qrugghhfuuushhhhfuuushhhhduuudhhhhsuuudhhhhauuufhhhhsuuufhhhhpuuighhhhhhhhhhhhhghhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhg7-&508666880qrtipssaiyeqqrtpsspue076699qetipsaaurq866790ettwrtphhhhfuuuahhhhfuuudhhhhduuudhhhhduuidhhhhsuuufhhhhauuifsfhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhg9O550eqq0qwertuisdffsauyttupsddsayrqqqqrtupaddfdpureq0qeryiprtyahhhhfuuushhhhfuuushhhhfuuudhhhhduuudhhhhsuuufhhhhauuug;0hhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh;8saiuuttuyuipaddgggfsaiiiasffgfaaiytyuupaddgggfdpuuyyuupadauuuahhhhfiuiahhhhfiuudhhhhduuidhhhhduuufhhhhsiiufhhhhauuug>0hhpiuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhO ysaaaOt3 4dggp% %usssu& *ifssaaaasdffghOpggsOtaat- -ufggXahhpOfggOp7 .5fgfgghhhgggf9 6gggOphhhXigg9 6gggX 9gggi* *pghhO; 4@+dhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhp*4tgffdf %&er phh+;yu&&gfg+:uu*%hgffddfffghhh uhgd tdd@%yy:+hhh uhhu hhh **tr ahhhhhhhhhhh 0uut<hhh uhhf uhh 0uut<hhhp*4uufhhh$;uu**hhh *0 7*0hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:9hhgghg 3ggh<shh uhhu hgh uhhu hghggghgghhhh<5hhwOggg uhhy hhh thhu hhh 4hhh<shhhhhhhhhhh4 5uhhhhh<5hheOhhh4 5uhhhhhh;0hhhhhh uhhu hhh uu h;0hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh00phhhhhhhhhhhhhhh90phhhhhhhhhhhhhhh00phhhhhhhhhhhhhh:0hhhhhh uhhhhhhh *;;* hhh *;;* hhhhhhhhhhhhht fh@9hhh uhhu hhh;9hhu hhh uhhhhhhhhhhhhhhhghu< *phhhr fh#0hhhhu< *phhhh;0hhhhhh &>;* hhh uu h>9hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh 0hhhhhhhhhhhhhhh 0hhhhhhhhhhhhhhh 0hhhhhhhhhhhhhh;0hhhhhh uhhhhhhh 40900hhh 40900hhhhhhhhhhhhhh@0r fhhh uhhu hhh;0hht hhh uhhhhhhhhhhhhhhhhhhhs<#hhhh#0t fhhhhhhs<#hhhh;0hhuhhh 39000hhh uy h9>hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh00phhhhhhhhhhhhhhh90phhhhhhhhhhhhhhh00phhhhhhhhhhhhhh;9hhhhhh uhhhhhhh@<uuuphhh@1uuuphhhhghhhhhhhhh0O#5hhhh*%uu*&hhh<<u4 hhh uhhhhhhhhhhhhhhhh<tuu0Ohhhh0O#4hhhh<ruu0Ohhhh1<u9 uhh@1uuuphhh uu h0;hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<0hhhhhhXphhhhhhhs;. Xhhhs> Ohhhhhhhhhhhhhhg3 shhhhp; ;ahhha+ ;wOhhhXahhhhhhhhhhhhhhhh6 Owhhhhf4 shhhh6 Oqhhhhp$ 6hhhs; OhhhXpaOh0<hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhh3;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh4;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh09 uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhh09 uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<:5hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<:4hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +}; diff --git a/qemu/roms/openbios/arch/unix/gui_qt/qt-main.cpp b/qemu/roms/openbios/arch/unix/gui_qt/qt-main.cpp new file mode 100644 index 000000000..8311fe632 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/gui_qt/qt-main.cpp @@ -0,0 +1,97 @@ +/* tag: openbios qt user interface + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + + +extern "C" { +#include <pthread.h> +#include <unistd.h> +#include "unix/plugins.h" +#include "unix/plugin_pci.h" +} +#include "gui-qt.h" + +#define DEBUG + +volatile unsigned char * fb=0; +volatile int gui_running=0; + +typedef struct { + int argc; + char **argv; +} threaddata; + +void *gui_thread(void *ptr) +{ + threaddata *td=(threaddata *)ptr; + + QApplication a(td->argc, td->argv); + FrameBufferWidget w; + + a.setMainWidget(&w); + w.show(); + + fb=w.getFrameBuffer(); + + gui_running=-1; + a.exec(); + gui_running=0; + + return 0; +} + +extern "C" { +extern int plugin_qt_init(void); +int plugin_qt_init(void) +{ + pthread_t mythread; + char *args[]={ "plugin_qt" }; + threaddata mytd = { 1, args }; + +#ifdef DEBUG + printf("Initializing \"framebuffer\" plugin..."); +#endif + pthread_create(&mythread, NULL, gui_thread, &mytd); + while (!fb) + usleep(20); + +#if 0 + + /* now we have the framebuffer start address. + * updating pci config space to reflect this + */ +#if (BITS > 32) + *(u32 *)(pci_config_space+0x14)=(u32)((unsigned long)fb>>32); +#else + *(u32 *)(pci_config_space+0x14)=0; +#endif + *(u32 *)(pci_config_space+0x10)=(u32)((unsigned long)fb&0xffffffff); + + /* next is to write the rom address. We write that at a random + * address in pci config space for now. + */ +#if (BITS > 32) + *(u32 *)(pci_config_space+0x34)=(u32)((unsigned long)qt_fcode>>32); +#else + *(u32 *)(pci_config_space+0x34)=0; +#endif + *(u32 *)(pci_config_space+0x30)=(u32)((unsigned long)qt_fcode&0xffffffff); + + /* FIXME: we need to put the fcode image for this + * device to the rom resource, once it exists + */ + + /* register pci device to be available to beginagain */ + pci_register_device(0, 2, 0, pci_config_space); +#endif +#ifdef DEBUG + printf("done.\n"); +#endif + return 0; +} + +} diff --git a/qemu/roms/openbios/arch/unix/plugins.c b/qemu/roms/openbios/arch/unix/plugins.c new file mode 100644 index 000000000..855454b0e --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins.c @@ -0,0 +1,197 @@ +/* tag: plugin interface for openbios forth kernel + * + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "sysinclude.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> + +#include "unix/plugins.h" + +unsigned char *plugindir = "/usr/share/OpenBIOS/plugins"; +#define PLUGINDIR plugindir +#define PATHSIZE 256 + +#define CONFIG_DEBUG_PLUGINS + +typedef struct iorange iorange_t; +struct iorange { + const char *name; + unsigned int start; + unsigned int end; + io_ops_t *ops; + iorange_t *next; +}; + +static iorange_t *ioranges = NULL; + +typedef struct plugin plugin_t; +struct plugin { + const char *name; + plugin_t *next; +}; + +static plugin_t *plugins = NULL; + +io_ops_t *find_iorange(u32 reg) +{ + iorange_t *range = ioranges; + while (range) { + if (range->start <= reg && range->end >= reg) + return range->ops; + range = range->next; + } + return NULL; +} + +int register_iorange(const char *name, io_ops_t * ops, unsigned int rstart, + unsigned int rend) +{ + iorange_t *newrange; + + /* intersection check */ + newrange = ioranges; + while (newrange) { + int fail = 0; + /* new section swallows old section */ + if (newrange->start >= rstart && newrange->end <= rend) + fail = -1; + /* new section start or end point are within range */ + if (newrange->start <= rstart && newrange->end >= rstart) + fail = -1; + if (newrange->start <= rend && newrange->end >= rend) + fail = -1; + if (fail) { + printf("Error: overlapping IO regions: %s and %s\n", + newrange->name, name); + return -1; + } + newrange = newrange->next; + } + + newrange = malloc(sizeof(iorange_t)); + + newrange->name = name; + newrange->ops = ops; + newrange->start = rstart; + newrange->end = rend; + newrange->next = ioranges; + + ioranges = newrange; + + return 0; +} + +int is_loaded(const char *plugin_name) +{ + plugin_t *p = plugins; + while (p) { + if (!strcmp(plugin_name, p->name)) + return -1; + p = p->next; + } + return 0; +} + +int load_plugin(const char *plugin_name) +{ + void *handle; + char *error; + char path[PATHSIZE]; + + int (*init_plugin) (void); + char **deps; + char **plugin_info; + plugin_t *p; + + if (is_loaded(plugin_name)) { + printf("Plugin %s already loaded.\n", plugin_name); + return 0; + } + + strncpy(path, PLUGINDIR, PATHSIZE); + strncat(path, "/plugin_", PATHSIZE); + strncat(path, plugin_name, PATHSIZE); + strncat(path, ".so", PATHSIZE); + +#if DEBUG + printf("Opening plugin %s\n", path); +#endif + + handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + if (!handle) { + error = dlerror(); + printf("Error: Could not open plugin \"%s\": %s\n", + plugin_name, error); + exit(1); + } +#ifdef CONFIG_DEBUG_PLUGINS + plugin_info = dlsym(handle, "plugin_author"); + if ((error = dlerror()) == NULL) + printf("Plugin %s author: %s\n", plugin_name, *plugin_info); + plugin_info = dlsym(handle, "plugin_license"); + if ((error = dlerror()) == NULL) + printf("Plugin %s license: %s\n", plugin_name, *plugin_info); + plugin_info = dlsym(handle, "plugin_description"); + if ((error = dlerror()) == NULL) + printf("Plugin %s descr.: %s\n", plugin_name, *plugin_info); +#endif + p = malloc(sizeof(plugin_t)); + p->next = plugins; + p->name = plugin_name; + plugins = p; + + deps = dlsym(handle, "plugin_deps"); + if ((error = dlerror()) != NULL) + deps = NULL; + + + strncpy(path, "plugin_", PATHSIZE); + strncat(path, plugin_name, PATHSIZE); + strncat(path, "_init", PATHSIZE); + + init_plugin = dlsym(handle, path); + if ((error = dlerror()) != NULL) { + printf("error: %s\n", error); + exit(1); + } + + if (deps) { + int i = 0; + char *walk = deps[0]; +#ifdef CONFIG_DEBUG_PLUGINS + printf("\nPlugin %s dependencies:", plugin_name); +#endif + while (walk) { + printf(" %s", walk); + if (!is_loaded(walk)) { +#ifdef CONFIG_DEBUG_PLUGINS + printf("(loading)\n"); +#endif + load_plugin(walk); + } +#ifdef CONFIG_DEBUG_PLUGINS + else { + printf("(loaded)"); + } +#endif + walk = deps[++i]; + } + } + + printf("\n"); +#if DEBUG + printf("Initializing module:\n"); +#endif + + return init_plugin(); + + // We don't dlclose the handle here since + // we want to keep our symbols for later use. +} diff --git a/qemu/roms/openbios/arch/unix/plugins/Kconfig b/qemu/roms/openbios/arch/unix/plugins/Kconfig new file mode 100644 index 000000000..43237bf99 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/Kconfig @@ -0,0 +1,16 @@ +config PLUGINS + depends HOST_UNIX + bool "Plugin system (obsolete)" + default n + +config PLUGIN_PCI + depends HOST_UNIX && PLUGINS + bool "PCI Emulation" + default n + +config PLUGIN_QT + bool "QT Display Emulation" + depends HOST_UNIX && PLUGINS && PLUGIN_PCI + default n + help + This plugin needs qt installed. Disable if you don't have qt. diff --git a/qemu/roms/openbios/arch/unix/plugins/Makefile b/qemu/roms/openbios/arch/unix/plugins/Makefile new file mode 100644 index 000000000..c6b9a6519 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/Makefile @@ -0,0 +1,13 @@ + +include ../../../config/Makefile.top + +SUBDIRS-$(CONFIG_PLUGIN_PCI) += plugin_pci +SUBDIRS-$(CONFIG_PLUGIN_QT) += plugin_qt + +PROGRAMS = # loader +loader-OBJS = loader.o +loader-LDFLAGS = -dynamic $(LIBDL_LDFLAGS) + +INCLUDES = -DBOOTSTRAP + +include $(rules)/Rules.make diff --git a/qemu/roms/openbios/arch/unix/plugins/Rules.plugin b/qemu/roms/openbios/arch/unix/plugins/Rules.plugin new file mode 100644 index 000000000..9e9b6255d --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/Rules.plugin @@ -0,0 +1,15 @@ +# -*- makefile -*- + +INCLUDES = -I$(top_srcdir)/include -DBOOTSTRAP +CFLAGS = -fPIC + +%.so: %.o + $(CC) -shared $(CFLAGS) $(filter %.o,$^) -o $@ + +THISDIR := $(notdir $(shell pwd)) + +all-local: $(addprefix $(ODIR)/../,$(PLUGINS)) + +$(ODIR)/../%.so: $(ODIR)/%.so + install -d ../$(ODIR) + ln -f "../$(THISDIR)"/$< $@ diff --git a/qemu/roms/openbios/arch/unix/plugins/loader.c b/qemu/roms/openbios/arch/unix/plugins/loader.c new file mode 100644 index 000000000..d3781de79 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/loader.c @@ -0,0 +1,209 @@ +/* tag: openbios plugin loader + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* This is a simple plugin loader. OpenBIOS duplicates some + * of this code in kernel/arch/unix/plugins.c. This code is + * here for reference and simple testing. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <dlfcn.h> +#include <unistd.h> // sleep + +#include "unix/plugins.h" + +#define PLUGINDIR "/usr/share/OpenBIOS/plugins" +#define PATHSIZE 256 + +#define DEBUG_PLUGINS + +typedef struct iorange iorange_t; +struct iorange { + const char *name; + unsigned int start; + unsigned int end; + io_ops_t *ops; + iorange_t *next; +}; + +iorange_t *ioranges = NULL; + +typedef struct plugin plugin_t; +struct plugin { + const char *name; + plugin_t *next; +}; + +plugin_t *plugins = NULL; + +int register_iorange(const char *name, io_ops_t * ops, unsigned int rstart, + unsigned int rend) +{ + iorange_t *newrange; + + /* intersection check */ + newrange = ioranges; + while (newrange) { + int fail = 0; + /* new section swallows old section */ + if (newrange->start >= rstart && newrange->end <= rend) + fail = -1; + /* new section start or end point are within range */ + if (newrange->start <= rstart && newrange->end >= rstart) + fail = -1; + if (newrange->start <= rend && newrange->end >= rend) + fail = -1; + if (fail) { + printf("Error: overlapping IO regions: %s and %s\n", + newrange->name, name); + return -1; + } + newrange = newrange->next; + } + + newrange = malloc(sizeof(iorange_t)); + + newrange->name = name; + newrange->ops = ops; + newrange->start = rstart; + newrange->end = rend; + newrange->next = ioranges; + + ioranges = newrange; + + return 0; +} + +int is_loaded(const char *plugin_name) +{ + plugin_t *p = plugins; + while (p) { + if (!strcmp(plugin_name, p->name)) + return -1; + p = p->next; + } + return 0; +} + +int load_plugin(const char *plugin_name) +{ + void *handle; + char *error; + char path[PATHSIZE]; + + int (*init_plugin) (void); + char **deps; + char **plugin_info; + plugin_t *p; + + if (is_loaded(plugin_name)) { + printf("Plugin %s already loaded.\n", plugin_name); + return 0; + } + + strncpy(path, PLUGINDIR, PATHSIZE); + strncat(path, "/plugin_", PATHSIZE); + strncat(path, plugin_name, PATHSIZE); + strncat(path, ".so", PATHSIZE); + +#if DEBUG + printf("Opening plugin %s\n", path); +#endif + + handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); + if (!handle) { + error = dlerror(); + printf("Error: Could not open plugin \"%s\": %s\n", + plugin_name, error); + exit(1); + } +#ifdef DEBUG_PLUGINS + plugin_info = dlsym(handle, "plugin_author"); + if ((error = dlerror()) == NULL) + printf("Plugin %s author: %s\n", plugin_name, *plugin_info); + plugin_info = dlsym(handle, "plugin_license"); + if ((error = dlerror()) == NULL) + printf("Plugin %s license: %s\n", plugin_name, *plugin_info); + plugin_info = dlsym(handle, "plugin_description"); + if ((error = dlerror()) == NULL) + printf("Plugin %s descr.: %s\n", plugin_name, *plugin_info); +#endif + p = malloc(sizeof(plugin_t)); + p->next = plugins; + p->name = plugin_name; + plugins = p; + + deps = dlsym(handle, "plugin_deps"); + if ((error = dlerror()) != NULL) + deps = NULL; + + + strncpy(path, "plugin_", PATHSIZE); + strncat(path, plugin_name, PATHSIZE); + strncat(path, "_init", PATHSIZE); + + init_plugin = dlsym(handle, path); + if ((error = dlerror()) != NULL) { + printf("error: %s\n", error); + exit(1); + } + + if (deps) { + int i = 0; + char *walk = deps[0]; +#ifdef DEBUG_PLUGINS + printf("\nPlugin %s dependencies:", plugin_name); +#endif + while (walk) { + printf(" %s", walk); + if (!is_loaded(walk)) { +#ifdef DEBUG_PLUGINS + printf("(loading)\n"); +#endif + load_plugin(walk); + } +#ifdef DEBUG_PLUGINS + else { + printf("(loaded)"); + } +#endif + walk = deps[++i]; + } + } + + printf("\n"); +#if DEBUG + printf("Initializing module:\n"); +#endif + + return init_plugin(); + + // We don't dlclose the handle here since + // we want to keep our symbols for later use. +} + +int main(void) +{ + iorange_t *r; + + // load_plugin("kbd"); + // load_plugin("pci"); + load_plugin("qt"); + + printf("\nRegistered IO Ranges:\n"); + r = ioranges; + while (r) { + printf(" %s: %x-%x\n", r->name, r->start, r->end); + r = r->next; + } + + sleep(10); + return 0; +} diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile new file mode 100644 index 000000000..e46a6cdae --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile @@ -0,0 +1,7 @@ + +include ../../../../config/Makefile.top + +PLUGINS = plugin_pci.so + +include ../Rules.plugin +include $(rules)/Rules.make diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile.old b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile.old new file mode 100644 index 000000000..10d0555d9 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/Makefile.old @@ -0,0 +1,21 @@ +# tag: Makefile for OpenBIOS PCI plugin +# +# Copyright (C) 2003 Stefan Reinauer +# +# See the file "COPYING" for further information about +# the copyright and warranty status of this work. +# + +PLUGIN_SOURCES = plugin_pci.c +PLUGIN_NAME = plugin_pci.so + +INCLUDES := -I$(TOPDIR)/include -I$(BUILDDIR) -I.. +VPATH := $(VPATH):. + +all: $(PLUGIN_NAME) + +$(PLUGIN_NAME): $(PLUGIN_SOURCES) + $(CC) -shared -Wall -Os -fPIC $(INCLUDES) $< -o $(BUILDDIR)/$@ + +clean: + rm -f plugin_*.so diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_pci/plugin_pci.c b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/plugin_pci.c new file mode 100644 index 000000000..586ea2aaf --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_pci/plugin_pci.c @@ -0,0 +1,221 @@ +/* tag: openbios pci plugin + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include <stdio.h> +#include <stdlib.h> +#include "unix/plugins.h" +#include "unix/plugin_pci.h" + +#define DEBUG + +u32 pci_conf_addr = 0; +pci_dev_t *pci_devices = NULL; + +static pci_dev_t *find_device(u32 conf_addr) +{ + pci_dev_t *devs = pci_devices; + unsigned bus = (conf_addr >> 16) & 0xff; + unsigned dev = (conf_addr >> 11) & 0x1f; + unsigned fn = (conf_addr >> 8) & 0x7; + + // printf("Looking for device %x\n",conf_addr); + + while (devs) { + if (devs->bus == bus && devs->dev == dev && devs->fn == fn) + return devs; + devs = devs->next; + } + return NULL; +} + +/* + * IO functions. These manage all the magic of providing a PCI + * compatible interface to OpenBIOS' unix version of the kernel. + */ + +static u8 pci_inb(u32 reg) +{ + u32 basereg = (reg & 0xfffc); + u32 basepos = (reg & 0x03); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + return (pci_conf_addr >> (basepos << 3)); + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return 0xff; + + return dev->config[(pci_conf_addr + basepos) & 0xff]; +} + +static u16 pci_inw(u32 reg) +{ + u32 basereg = (reg & 0xfffc); + u32 basepos = (reg & 0x02); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + return (pci_conf_addr >> (basepos << 3)); + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return 0xffff; + + return *(u16 *) (dev->config + ((pci_conf_addr + basepos) & 0xff)); +} + +static u32 pci_inl(u32 reg) +{ + u32 basereg = (reg & 0xfffc); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + return pci_conf_addr; + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return 0xffffffff; + + return *(u32 *) (dev->config + (pci_conf_addr & 0xff)); +} + +static void pci_outb(u32 reg, u8 val) +{ + u32 basereg = (reg & 0xfffc); + u32 basepos = (reg & 0x03); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + pci_conf_addr &= (~(0xff << (basepos << 3))); + pci_conf_addr |= (val << (basepos << 3)); + return; + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return; + + dev->config[pci_conf_addr & 0xff] = val; +} + +static void pci_outw(u32 reg, u16 val) +{ + u32 basereg = (reg & 0xfffc); + u32 basepos = (reg & 0x02); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + pci_conf_addr &= (~(0xffff << (basepos << 3))); + pci_conf_addr |= (val << (basepos << 3)); + return; + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return; + + *(u16 *) (dev->config + (pci_conf_addr & 0xff)) = val; +} + +static void pci_outl(u32 reg, u32 val) +{ + u32 basereg = (reg & 0xfffc); + pci_dev_t *dev; + + if (basereg == 0xcf8) { + pci_conf_addr = val; + return; + } + + /* still here? so we're 0xCFC */ + dev = find_device(pci_conf_addr); + if (!dev || !dev->config) + return; + + *(u32 *) (dev->config + (pci_conf_addr & 0xff)) = val; +} + +static io_ops_t pci_io_ops = { + inb:pci_inb, + inw:pci_inw, + inl:pci_inl, + outb:pci_outb, + outw:pci_outw, + outl:pci_outl +}; + +/* + * Functions visible to modules depending on this module. + */ + +int pci_register_device(unsigned bus, unsigned dev, unsigned fn, + u8 * config) +{ + pci_dev_t *newdev; + u32 caddr = (1 << 31) | (bus << 16) | (dev << 11) | (fn << 8); + + if (find_device(caddr)) { + printf("Error: pci device %02x:%02x.%01x already exists\n", + bus, dev, fn); + return -1; + } + + newdev = malloc(sizeof(pci_dev_t)); + + if (!newdev) { + printf("Out of memory\n"); + return -1; + } + + newdev->bus = bus; + newdev->dev = dev; + newdev->fn = fn; + newdev->config = config; + newdev->next = pci_devices; + + pci_devices = newdev; + + return 0; +} + +/* + * Initialization is really simple. We just grab the + * PCI conf1 io range for our emulation functions. + */ +extern int plugin_pci_init( void ); + +int plugin_pci_init(void) +{ +#ifdef DEBUG + printf("Plugin \"pci\" initializing... "); +#endif + register_iorange("pci", &pci_io_ops, 0xcf8, 0xcff); +#ifdef DEBUG + printf("done.\n"); +#endif + return 0; +} + +/* plugin meta information available for the plugin loader */ +PLUGIN_AUTHOR ("Stefan Reinauer <stepan@openbios.org>") +PLUGIN_DESCRIPTION ("Generic PCI Device Emulation") +PLUGIN_LICENSE ("GPL v2") + +/* This plugin has no dependencies. Otherwise the following + * macro would be uncommented: + * PLUGIN_DEPENDENCIES ("this", "that") + */ diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/Makefile b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/Makefile new file mode 100644 index 000000000..371dc2f0b --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/Makefile @@ -0,0 +1,37 @@ + +include ../../../../config/Makefile.top + +PLUGINS = plugin_qt.so + +QMAKE = qmake +PLUGINDIR = $(shell cd .. ; pwd ) +TOPDIR = $(shell cd $(top_srcdir) ; pwd) +ABSOINC = $(shell cd $(ARCHINCLUDES) 2> /dev/null ; pwd ) + +export PLUGINDIR TOPDIR ABSOINC + +qt_rom.fc: qt_rom.fs + $(TOKE) -v qt_rom.fs + +fcode.h: qt_rom.fc + @echo "static const u8 qt_fcode[] = {" > $@ + @cat $< | hexdump -ve '1/0 "\t" 8/1 "0x%02x, " 1/0 "\n"' \ + | sed 's/0x ,//g' >> $@ + @echo "};" >> $@ + +$(ODIR)/makefile.qmake: plugin_qt.pro Makefile + @test -d $(ODIR) || $(INSTALL) -d $(ODIR) + @test -d $(ODIR)/qbuild || $(INSTALL) -d $(ODIR)/qbuild + @cp plugin_qt.pro $(ODIR)/ + cd $(ODIR) ; $(QMAKE) -o makefile.qmake + +$(ODIR)/plugin_qt.so: fcode.h $(ODIR)/makefile.qmake $(wildcard *.cpp) + cd $(ODIR) ; $(MAKE) -f makefile.qmake + @ln -f $(ODIR)/qbuild/plugin_qt.so $@ + +clean-local: + @rm -f $(ODIR)/makefile.qmake + @rm -rf $(QBUILDDIR) $(ODIR)/*.fc $(ODIR)/fcode.h + +include ../Rules.plugin +include $(rules)/Rules.make diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/logo.xpm b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/logo.xpm new file mode 100644 index 000000000..9e2ac60b4 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/logo.xpm @@ -0,0 +1,132 @@ +/* This logo was created by Stephan Lau, + * created to xpm by Stefan Reinauer + */ +static char *logo[] = { +/* columns rows colors chars-per-pixel */ +"300 80 44 1", +" c #010101", +". c #070709", +"X c #0B0B0B", +"o c #0F0F11", +"O c #121212", +"+ c #1B1B1B", +"@ c #1F1F21", +"# c #232323", +"$ c #262628", +"% c #2B2B2C", +"& c #2E2E30", +"* c #333333", +"= c #373739", +"- c #3B3B3B", +"; c #434343", +": c #464648", +"> c #4B4B4B", +", c #4E4E50", +"< c #535353", +"1 c #5B5B5B", +"2 c #5E5E60", +"3 c #646464", +"4 c #666668", +"5 c #6B6B6B", +"6 c #747474", +"7 c #767678", +"8 c #7B7B7B", +"9 c #838383", +"0 c #8A8A8A", +"q c #939394", +"w c #979799", +"e c #9B9B9B", +"r c #A3A3A3", +"t c #ABABAB", +"y c #B4B4B4", +"u c #BBBBBB", +"i c #C3C3C3", +"p c #CBCBCB", +"a c #D3D3D3", +"s c #DBDBDB", +"d c #E3E3E3", +"f c #EBEBEB", +"g c #F3F3F3", +"h c #FEFEFE", +/* pixels */ +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfdssaapuuuytteeewq0009998867666555555555555565666778899000qwwerttyyuuppassdfghhhhhhhhhhgfgggghhhgfgfghhhhggffghhhhggffghhhhgfggghhhhgfggghhhhgfgfghhhhfgfgghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfdsapuytrwq0986555554455555555555555555555555555555555555555555555555555555555555555555555555556790qertyiuuuafhhhfpiishhhhfipidhhhhfiiidhhhhdiiifhhhhsiiifhhhhsiipghhhhaiipghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfdaiuttq0976555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555558iuue5579wuuuuiasfduuishhhhduuudhhhhduuudhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfdaittw086555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555558yuur55549uuiw55569uuutyiadsuuudhhhhsuuudhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgfapyrw975555555555555555555555555555555555555555555555555555555555555555555555555555555554555555555555555555554455555555555555555555558uuue54559uuuw55559uuuq55550uiutypafduuufhhhhsuuufhhhhsuuufhhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdautw965555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555679qqerttuuppaasdddffgghghhhhhhhhhghhggfduuupaappuuuuyeq090uuuq55559uyi05555quuuuadghsuuufhhhhauuufhhhhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfsite0655555555555555555555555555555555555555555555555555555555555555555555555455555555555555555690wrtiiaddghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfuuuahhhhfuuushhhhfuuuaaiittuuuq55550uuu95560tuuudhhhhsuuughhhhauuufhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhgsite955555555555555555555555555455555555555555555555555555555555555555555555555545555555555570wryiadfhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhguuuahhhhfuuuahhhhfuuushhhhduuudfsaiuuuuq5555qiuu99etipuuifhhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaut0655555555555555555555555555555555555555555555556555555555555555555555555555555555554559qruisfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdsdfhhhhgdddfhhhhfddsfhhhhgdddfhhhhfddsffspyteeq755559qetisfhgfdddghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgsir065555555555555555555555555555455555555555555555554555555555555555555555555555555555580rupsghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsuudhhhhhhhhhhhhfuuphhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgspyt085555560tudghhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaue9555555555555555554<----=---=---==-==<555555---:3:--=--=-*--==--<55555545<;------==->135890phhhhhy009tfq0009009090909wshhhhhhg<;;:;;;:<9fhhhhhhhf$ rhhhhhs3# ;phhhhhhhf0# Owghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdpue0655559wuaghhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgsue855555455555555555555:O. *5455- *. &44555>O 6ghhh+ 5O ehghhh9 . Xighhhhh9 -gfggf3 +sddffd8O rddffffffffgffffgffffffffggffffffffgffffgffdaute09868eusghhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfpr955555555555555555555555% .%=************& +2555o +=************% +3343% X-<3568888787884. ;dggq. O19888888888888, 8fgghsO . 1fggghsO ysdfiO 9ttuu> . 1rtuyuuuuuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuuuuuuuiiuuuut06449rpdhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhduw85555555555555555555555555* .,111<1111111111< #113- #<<111111111111< #123- Xtssaaaaaaaaaaaaa <sdf@ Otaaaaasaaaaaaaae 9sdgg, =sdggh< 2ipa0 7etr# <etttuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuighfauw857wudhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhfie7555555555555555555555554555: =1<<<<<<<<<<<<<<& -<<3X X<<><<<<1,,<<<<<& ;7e8 9apiiiiiipiiiiii6 0ia9 8uuuiipipiiiiiii> oyisdt X%% 2iadgy Xrty6 @69& X90e; *3% 49wttuuuuuuuuuuuuuuuuuuuuuuuuuuuyuyyyuuyuuuuuuuuuuihhhhhhgayw86eifhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhar8555555555555555555555555555543. +<,>>>,>><>>>>,,:. O;:<& -:;>>><>,,<><>,:. $eytO -puuyuuuuuuuuuiutX %rytO *ytrtyuuiuuuuuuu9 1ruis%. 108- . 8tisd% <qw9X #tre> *59, -86* O47qetuuuuuuuuuuuuuuuuuuuuuuuuuuuiasddsaiuuuuuuuuuuighhhhhhhhhgatq9tahhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhgiq55555555555555555555555555555555- ;>:>:,<<<,<<<<<<# . %-;: . O:;;;>>,<<>,,<38; 5qr3 eutttuuiiiipiiii1 5wr< qreeryuiipiiipii$ X0wru8 O976& +9wya0 O999O qeq9O >3< +751. &159wtyuuuuuuuuuuuuuuuuuuuuuuuuisfhhhhhhgdpuuuuuiuuihhhhhhhhhhhhhhdierighhhhhhh", +"hhhhhhhhhhhhhhhhhfi05555555555555555555555555555555552 #>;;:,,<<<11<11<> +--;+ ;;--;><<1116qtpy -009 ,ttrrtuppaaaaaaay -q09 ;ewqrtupaaaaaaap9 10qrtX .3754X . >60tuX 387% 3w09: +3<O. 153% O:159wtyuuuuiuuuuuuuuuuuuuuuuuuaghhhhhhhhhhhdiuuuuuuighhhhhhhhhhhhhhhhfaupghhhhh", +"hhhhhhhhhhhhhhhhiq55555555555555555555555555555555555+ X;:;;><<112311212+ .---& $;-;;><138eusddd- X000% oerrrtuaadsdddddd- o090$ Xwqqetypadddsddsao .%q9qr3 $856- +160t5 $761 X9097X ;1& &54< *;159wtyuuuuuuuuuuuuuuuuuuuuuushhhhhhhhhhhhhhdpyuuuuihhhhhhhhhhhhhhhhhhhhgsdhhhh", +"hhhhhhhhhhhhhhsr555555545555555555555555555555555555, %;;-:><123333535> %---O .;--;;<5wifgfgfgt 1w04 2ewerupsffgffggft 1w05 1wqqeyasffgfgggg9 7q0wq 6665 ,360w 666O <999= %32. . <31+. +>>160rtuuuuuuuuuuuuuuuuuuuuuyshhhhhhhhhhhhhhhhfuuuuuighhhhhhhhhhhhhhhhhhhhhhhghh", +"hhhhhhhhhhhhhi05555555555555555555555555555555555555o .X;;-::<1335555454X X:--$ &:--,6rsfghhghgh# Orq0O <<<<156999090999# +rqqO +qqqetisgghhghhha >rqqe* >867# *358e* >76; #9994 . .44- o2<>++++O>><48qrtuuuuuuuuuuuuiuuuuuuuuphhhhhhhhhhhhhhhhhhsyuiuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhu65555555555555555555555555555555555555- *;-->>1355555554- *;--. O;-<5rpdfhhhhhhh9 7rq< 6eq, 5w0wtisdgghhhhhh< Oqwqw8 X7773 X45608 X666. 3779% ;55X. %<1356651<<369etyuuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhhhhhgpyuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhi755555555555555555555555555555555555553. +;--;><2555555553. O:--$ *16qtiafhghhhhhgO *rq9X @,>:><356787888787653rq9X %wqqryadfghhhhhhy 3rqqrO <669O >569q+ <66* =8781 O953 &<24698533359qryuuuuuuuuuuuiuuuuuuuuuphhhhhhhhhhhhhhhhhhhhsyuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhs955555555555555555555555555555555555555% -;;;><1335555555$ -;;* %9wweypdfhhhhhhh4 eeq- 90990rtupaaaaaaaapiutee- 9qqerusfhhhhhhhh# +twqr1 @868= $867q1 @873 o5689O 166; &<36999865690etyyuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhhhhhhhfiuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhy55555555555555555555555555555555555555< #;--:,<3355555551 #;;-+ Xqwqetisfhghhhhhp 1eq7 >q999qrtuuipipuippuytrr8 :wqqruadfhhhhhhh9 6ewweX 363% #6689qX 276# >769, $867* +13800q9999qrtyuuuuuuuuuuuuuuuuuuuuuufhhhhhhhhhhhhhhhhhhhhhpuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh955555555555555555555555555555555555555@ .:-;;:<1335555554+ .;:-* 1wqqrupfghhhhhhh; Oeeq$ ..q0990qrtuuuuuuuuuuuuttr& XqqqetpdfghhhhhhfO *tewe> %8869q< *76< O6687X 4669$ .X159qeeeqqqrryuuuuuuuuuuuuuuuuuuuiuuighhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh55555555555555555555555555555555555555: $;-;;,<335555554: $:-2+ +qqqeyidgghhhhhhr 1rq3 1q000rryuipiiipiiiiiuuu7 1wqwtuadghhhhhhh6 qwww0 =20979q9 X566X <679= . -8680- . >69errtrrrtyyuuuuuuuuuuuuuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhh95555555555555555555555555555555555555O X:--;><2355555553O O:162 3eqerusdghhhhhhf# $tqqO +qqqwrtipaaaaaaaaaaaaapp+ Oeqqetpsgghhhhhhs >ewqr&. ;q0998qe* >86; #7685 O6680e1 *50ettyyyyyuuuuuuuuuuuuuuuuuuuuuuuuuhhhhhhhhhhhhhhhhhhhhhhpuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhht655555555555555555555555555555555555: %;-;:<1335555555& .:500X +eqerypsghhhhhhh6 Oqeq3 1qqwryiasddddddddddddsd7 8wqqtuafghhhhhhh; Oreqw7 -999qw7. +665X 4679@ :789wt6 O50etyyuuuuuuuuuuuuuuuuuuuuuuuuuiuuughhhhhhhhhhhhhhhhhhhhhpyuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhs955555555555555555555555555555555555% --;;>1135555553- ,0eq> =wqerisfghhhhhf9 8rwq- 9qqetpsdffgfgffgfdttgfa *rqqryadghhhhhhhq 4rqwrO *-@ 79qeu+ ,76* . *7681 O8680ruy X49etyuuuuuuuuuuuuuuuuuuuuiuuuuuuuuudhhhhhhhhhhhhhhhhhhhhgiuuuhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhu65555555555555555555555555555555554# .4eew9 X Oqteww= #dgg; 9wqwtisfghhhhhhfX Xewqe3 %63< @70ey5 #961 X6678X 3679ruip& 48wryuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuphhhhhhhhhhhhhhhhhhhhduuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhu7555555555555555554555555555555545,@X . .+>qyrre& X8O O-7utreer9=X ufg5 +ewqruadghhhhhhf; >eqweX . 451> -6qyyO 366# ;769< $769wtpaa3 O36qrtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuighhhhhhhhhhhhhhhhhhhpyuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhp95455555555555555555555555555555331:;---;><1111111117tutre8 1q999wtipaaasssaaaiutrrrruyrq09qruiasasasasassssddddaitrwetisfhghhhhhhgfautewr; -654% o56eu< =86: . O8687 6669ruada4 @160ryuuuuuuuuuuuuuuuuuuiuuuuuuuuuuuuahhhhhhhhhhhhhhhhhhsuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhde555555555555555555555555555555331,;---;;,<<<<<1<<8tutrtt+ Or099qwtuipppppppiiuytrtyiiiteq0qryupppppppppppppssdspurreriafghhhhhhhhgdaueee8 X665< ;38e9 X765X 1679% >669wyadfd5 *150rtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuushhghhhhhhhhhhhhhgiyuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhiq555555555555555555555555555533<<:;-;;>>,>,>,,,6ttyttt3 5q9990rttuuuuuuyuuyyttyupaapurewertyyuuuuuuuuuuuipasaputttypsgghhhhhhhggsautrt* ,667# .+159e* >86;. $6695 .8680tisfgd3 X:160rtuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuudhhhhhhhhhhhhhhgiuiuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhfi055555555555555555555555555332<>>:;:>>>,<>,>6tuuuiiuX *eq00wrryyuuuuyuuuuuyuiiasdsaputrtttuuyuyuuuuyyuupaassaiuyupsfghhhhhhhhhgdaiuy6 O967< 146q3 O865 5679O ,769wuafggfX #:150rtuuuuuuuuuuuuuuuuuuuuuuiuuuuuuuuuuushhhhhhhhhhhhfiuuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhfiq5555555555555555555554555431<<<,<<<<<<<15tippppa<. 0wqqetyippppppppppippaasdfgfdsapiipipppppppppppppaadddsaapasfghhhhhhhhhggfsapi+ 1678O -5589+ 176% -679, +85O rgg0 X-,36qrtuuuuuuuuuuuuiuuuuuuuuuuuuuuuuiuuuuupfghhhhhhhfauuuuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhat85555555555555555555555433221111111113tsssssdr >eqqetupaasaaasaasssasddfgggggfdssasassaassasaasssddffffddddfgghhhhhhhhhhhgfdd8 $878> X55601 $761 X5788o 37- -dfd@ &>,39qryuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuypsdffdspuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhfiw6555555555555555555555333332322331efffdffs+ qqwetiadfffdfddfffdfffffgghhhgggfffdfdffdfdfdfdfdfffggfggfggghhhhhhhhhhhhggggp 6666 >6699 676+ >679- =73 .yss8 .O,,159etyuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuyuyuuuuuuuuuuuuihhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhfiw7545555555555555555555545353350dgggghg4 -rqqruadfggghghhggghgghhhhhhhhhhghghhghgghghghghghghhhhhhhhghghhhhhhhhhhhhhhhg< ;669& +666q* -76, . O8686 X66$ <uiuO . -><57qryuuuuuuuuuuuuuuuuuuuuuuuuuiuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuughhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhdir955555555555555555555555555uhhhhhhhgfsuteqrtpdfhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhu X7764 . 15696 .766# . <679$. <7< oqty- %<<149etyuuuuuuuuuuuuuiuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuiuuuuuighhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsue85555455555555555555559dhhhhhhhgfauteeriadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh* >865X -667q# >765 668= =86% -0q1 +4357qtiasdddddddddddddddsdddddddsddddddsddddddddddddsddddddddddddshhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfaue755555555555555555ehhhhhhhhgdautrtuadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhq ;-% +76703 O868: . >>% +975 %2* X6669wuadghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhsit06553555555555phhhhhhhggfaiuuupsfghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfO . +76680X 3869- . %986> . . X5877qtpsgghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgaur065455555dhhhhhhhhgfdaapadfghghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh6 . -8767q> *7699* . . -0989; +98669qusfggfffghhhhgfffghhhhgfffghhhhgdfdghhhhgfffghhhhgfffghhhhdfffghhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgspte955fhhhhhhhhggfddddfghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhs . O3987800 5760e4 O3099997 X;996136qpdfhfuuuahhhhduuushhhhduuudhhhhduuufhhhhsuuufhhhhauuughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhfahhhhhhhhhhggffggghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh- X%>688780r& ,869qry< #;89999qwr3o O=58887559rdghhguuushhhhfuuishhhhduuudhhhhduuufhhhhsuuufhhhhauuufhhhhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhgdauq841<15566890ryupute9880ruuur3<;1156889qrtyyr41>,145670979qyfgghfuuuahhhhfuuushhhhdiuudhhhhduuudhhhhsuuufhhhhauiughhhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhggdptq8433356789qrupaaite990ruppitq85345790wtypiitw84335680qe0qrugghhfuuushhhhfuuushhhhduuudhhhhsuuudhhhhauuufhhhhsuuufhhhhpuuighhhhhhhhhhhhhghhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhg7-&508666880qrtipssaiyeqqrtpsspue076699qetipsaaurq866790ettwrtphhhhfuuuahhhhfuuudhhhhduuudhhhhduuidhhhhsuuufhhhhauuifsfhhauuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhg9O550eqq0qwertuisdffsauyttupsddsayrqqqqrtupaddfdpureq0qeryiprtyahhhhfuuushhhhfuuushhhhfuuudhhhhduuudhhhhsuuufhhhhauuug;0hhauuighhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh;8saiuuttuyuipaddgggfsaiiiasffgfaaiytyuupaddgggfdpuuyyuupadauuuahhhhfiuiahhhhfiuudhhhhduuidhhhhduuufhhhhsiiufhhhhauuug>0hhpiuughhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhO ysaaaOt3 4dggp% %usssu& *ifssaaaasdffghOpggsOtaat- -ufggXahhpOfggOp7 .5fgfgghhhgggf9 6gggOphhhXigg9 6gggX 9gggi* *pghhO; 4@+dhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhp*4tgffdf %&er phh+;yu&&gfg+:uu*%hgffddfffghhh uhgd tdd@%yy:+hhh uhhu hhh **tr ahhhhhhhhhhh 0uut<hhh uhhf uhh 0uut<hhhp*4uufhhh$;uu**hhh *0 7*0hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:9hhgghg 3ggh<shh uhhu hgh uhhu hghggghgghhhh<5hhwOggg uhhy hhh thhu hhh 4hhh<shhhhhhhhhhh4 5uhhhhh<5hheOhhh4 5uhhhhhh;0hhhhhh uhhu hhh uu h;0hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh00phhhhhhhhhhhhhhh90phhhhhhhhhhhhhhh00phhhhhhhhhhhhhh:0hhhhhh uhhhhhhh *;;* hhh *;;* hhhhhhhhhhhhht fh@9hhh uhhu hhh;9hhu hhh uhhhhhhhhhhhhhhhghu< *phhhr fh#0hhhhu< *phhhh;0hhhhhh &>;* hhh uu h>9hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh 0hhhhhhhhhhhhhhh 0hhhhhhhhhhhhhhh 0hhhhhhhhhhhhhh;0hhhhhh uhhhhhhh 40900hhh 40900hhhhhhhhhhhhhh@0r fhhh uhhu hhh;0hht hhh uhhhhhhhhhhhhhhhhhhhs<#hhhh#0t fhhhhhhs<#hhhh;0hhuhhh 39000hhh uy h9>hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh00phhhhhhhhhhhhhhh90phhhhhhhhhhhhhhh00phhhhhhhhhhhhhh;9hhhhhh uhhhhhhh@<uuuphhh@1uuuphhhhghhhhhhhhh0O#5hhhh*%uu*&hhh<<u4 hhh uhhhhhhhhhhhhhhhh<tuu0Ohhhh0O#4hhhh<ruu0Ohhhh1<u9 uhh@1uuuphhh uu h0;hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<0hhhhhhXphhhhhhhs;. Xhhhs> Ohhhhhhhhhhhhhhg3 shhhhp; ;ahhha+ ;wOhhhXahhhhhhhhhhhhhhhh6 Owhhhhf4 shhhh6 Oqhhhhp$ 6hhhs; OhhhXpaOh0<hhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhh3;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh4;hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh09 uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhh09 uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhghhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<:5hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh<:4hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", +"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +}; diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/pciconfig.h b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/pciconfig.h new file mode 100644 index 000000000..88b0e1aa8 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/pciconfig.h @@ -0,0 +1,42 @@ +/* tag: pci config space dump for qt plugin's pci device. + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +static unsigned char pci_config_space[256]={ + 0x02, 0x10, 0x36, 0x43, 0x87, 0x02, 0xb0, 0x02, + 0x00, 0x00, 0x00, 0x03, 0x10, 0x42, 0x00, 0x00, + 0x08, 0x00, 0x00, 0xf0, 0x01, 0xb0, 0x00, 0x00, + 0x00, 0x00, 0x50, 0xe8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x34, 0x17, 0x0a, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x05, 0x01, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x34, 0x17, 0x0a, 0x10, + 0x01, 0x00, 0x02, 0x06, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x50, 0x20, 0x00, 0x07, 0x02, 0x00, 0x2f, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 +}; diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.cpp b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.cpp new file mode 100644 index 000000000..07234dc0a --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.cpp @@ -0,0 +1,128 @@ +/* tag: qt plugin framebuffer class + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "plugin_qt.h" +#include "logo.xpm" + +#include <iostream> + +static const int sizex=640; +static const int sizey=480; +static const int depth=8; + +static unsigned char color[256][3]={ + { 0x00, 0x00, 0x00 }, + { 0x00, 0x00, 0xaa }, + { 0x00, 0xaa, 0x00 }, + { 0x00, 0xaa, 0xaa }, + { 0xaa, 0x00, 0x00 }, + { 0xaa, 0x00, 0xaa }, + { 0xaa, 0x55, 0x00 }, + { 0xaa, 0xaa, 0xaa }, + { 0x55, 0x55, 0x55 }, + { 0x55, 0x55, 0xff }, + { 0x55, 0xff, 0x55 }, + { 0x55, 0xff, 0xff }, + { 0xff, 0x55, 0x55 }, + { 0xff, 0x55, 0xff }, + { 0xff, 0xff, 0x55 }, + { 0xff, 0xff, 0xff }, +}; + +FrameBufferWidget::FrameBufferWidget(QWidget *parent, const char * name) +: QWidget(parent, name, Qt::WType_TopLevel) +{ + setCaption ("OpenBIOS"); + setIcon(QPixmap(logo)); + + QPopupMenu *file = new QPopupMenu (this); + + file->insertItem( "E&xit", this, SLOT(quit()), CTRL+Key_Q ); + + QPopupMenu *help = new QPopupMenu( this ); + help->insertItem("&About OpenBIOS", this, SLOT(about()), CTRL+Key_H ); + help->insertItem( "About &Qt", this, SLOT(aboutQt()) ); + + menu = new QMenuBar( this ); + Q_CHECK_PTR( menu ); + menu->insertItem( "&File", file ); + menu->insertSeparator(); + menu->insertItem( "&Help", help ); + menu->setSeparator( QMenuBar::InWindowsStyle ); + + setFixedSize(sizex,sizey+menu->heightForWidth(sizex)); + + buffer.create(sizex, sizey, depth, 256); + + for (int i=16; i < 256; i++) { + color[i][0]=i; + color[i][1]=i; + color[i][2]=i; + } + + for (int i=0; i< 256; i++) + buffer.setColor(i, qRgb(color[i][0], color[i][1], color[i][2])); + + buffer.fill( 0 ); + + updatetimer=new QTimer(this); + connect( updatetimer, SIGNAL(timeout()), this, SLOT(update()) ); + updatetimer->start(200,FALSE); + + setMouseTracking( TRUE ); +} + +unsigned char * FrameBufferWidget::getFrameBuffer(void) +{ + return buffer.bits(); +} + +void FrameBufferWidget::paintEvent ( QPaintEvent * ) +{ + QPainter p( this ); + p.drawImage(0,menu->heightForWidth(sizex),buffer, 0,0, sizex, sizey); +} + +void FrameBufferWidget::about() +{ + QMessageBox::about( this, "About OpenBIOS", + " Welcome to OpenBIOS 1.01\n" + " IEEE 1275-1994 Open Firmware implementation\n\n" + "written by Stefan Reinauer <stepan@openbios.org>\n\n" + " http://www.openbios.org/\n"); +} + +void FrameBufferWidget::aboutQt() +{ + QMessageBox::aboutQt( this, "OpenBIOS" ); +} + +void FrameBufferWidget::quit() +{ + extern volatile int gui_running; + extern volatile int interruptforth; + + gui_running=0; + interruptforth=1; + + qApp->quit(); +} + +void FrameBufferWidget::update() +{ + QPainter p( this ); + p.drawImage(0,menu->heightForWidth(sizex),buffer, 0,0, sizex, sizey); +} + +void FrameBufferWidget::keyPressEvent(QKeyEvent * e) +{ + int a=e->ascii(); + if (a) { + std::cout << " key '" << e->text() << "' pressed" << std::endl; + } +} diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.h b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.h new file mode 100644 index 000000000..a1ed76fe5 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.h @@ -0,0 +1,44 @@ +/* tag: qt plugin framebuffer class description + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#ifndef __framebufferwidget_h +#define __framebufferwidget_h + +#include <qapplication.h> +#include <qwidget.h> +#include <qimage.h> +#include <qpainter.h> +#include <qmenubar.h> +#include <qpopupmenu.h> +#include <qmessagebox.h> +#include <qstatusbar.h> +#include <qtimer.h> + +class FrameBufferWidget : public QWidget { + Q_OBJECT + public: + FrameBufferWidget(QWidget *parent=0, const char *name=0); + unsigned char *getFrameBuffer(void); + + public slots: + void quit(); + void about(); + void aboutQt(); + void update(); + + private: + QImage buffer; + QMenuBar *menu; + QStatusBar *status; + QTimer *updatetimer; + void paintEvent ( QPaintEvent * ); + protected: + void keyPressEvent(QKeyEvent * e); +}; + +#endif diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.pro b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.pro new file mode 100644 index 000000000..96accd36b --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/plugin_qt.pro @@ -0,0 +1,18 @@ +# tag: qmake project file for OpenBIOS QT plugin +# +# Copyright (C) 2003 Stefan Reinauer +# +# See the file "COPYING" for further information about +# the copyright and warranty status of this work. +# + +TEMPLATE = app +CONFIG += qt thread warn_on release +LIBS = -shared +INCLUDEPATH = qbuild $(ABSOINC) $(TOPDIR)/include $(PLUGINDIR)/plugin_pci +DESTDIR = qbuild +OBJECTS_DIR = qbuild +MOC_DIR = qbuild +TARGET = plugin_qt.so +HEADERS = $(PLUGINDIR)/plugin_qt/plugin_qt.h +SOURCES = $(PLUGINDIR)/plugin_qt/plugin_qt.cpp $(PLUGINDIR)/plugin_qt/qt_main.cpp diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_main.cpp b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_main.cpp new file mode 100644 index 000000000..ea558d319 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_main.cpp @@ -0,0 +1,102 @@ +/* tag: openbios qt plugin skeleton + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + + +extern "C" { +#include <pthread.h> +#include <unistd.h> +#include "unix/plugins.h" +#include "unix/plugin_pci.h" +} +#include "plugin_qt.h" +#include "pciconfig.h" +#include "fcode.h" + +#define DEBUG + +volatile unsigned char * fb=0; +volatile int gui_running=0; + +typedef struct { + int argc; + char **argv; +} threaddata; + +void *gui_thread(void *ptr) +{ + threaddata *td=(threaddata *)ptr; + + QApplication a(td->argc, td->argv); + FrameBufferWidget w; + + a.setMainWidget(&w); + w.show(); + + fb=w.getFrameBuffer(); + + gui_running=-1; + a.exec(); + gui_running=0; + + return 0; +} + +extern "C" { +extern int plugin_qt_init(void); +int plugin_qt_init(void) +{ + pthread_t mythread; + char *args[]={ "plugin_qt" }; + threaddata mytd = { 1, args }; + +#ifdef DEBUG + printf("Initializing \"framebuffer\" plugin..."); +#endif + pthread_create(&mythread, NULL, gui_thread, &mytd); + while (!fb) + usleep(20); + + /* now we have the framebuffer start address. + * updating pci config space to reflect this + */ +#if (BITS > 32) + *(u32 *)(pci_config_space+0x14)=(u32)((unsigned long)fb>>32); +#else + *(u32 *)(pci_config_space+0x14)=0; +#endif + *(u32 *)(pci_config_space+0x10)=(u32)((unsigned long)fb&0xffffffff); + + /* next is to write the rom address. We write that at a random + * address in pci config space for now. + */ +#if (BITS > 32) + *(u32 *)(pci_config_space+0x34)=(u32)((unsigned long)qt_fcode>>32); +#else + *(u32 *)(pci_config_space+0x34)=0; +#endif + *(u32 *)(pci_config_space+0x30)=(u32)((unsigned long)qt_fcode&0xffffffff); + + /* FIXME: we need to put the fcode image for this + * device to the rom resource, once it exists + */ + + /* register pci device to be available to beginagain */ + pci_register_device(0, 2, 0, pci_config_space); + +#ifdef DEBUG + printf("done.\n"); +#endif + return 0; +} + +PLUGIN_AUTHOR("Stefan Reinauer <stepan@openbios.org>") +PLUGIN_DESCRIPTION("QT gui plugin emulating framebuffer device") +PLUGIN_LICENSE("GPL v2") +PLUGIN_DEPENDENCIES("pci") + +} diff --git a/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_rom.fs b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_rom.fs new file mode 100644 index 000000000..1879c3654 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/plugins/plugin_qt/qt_rom.fs @@ -0,0 +1,85 @@ +\ tag: Property management +\ +\ this code implements an IEEE 1275-1994 fcode driver +\ for the OpenBIOS qt interface +\ +\ Copyright (C) 2003 Stefan Reinauer +\ +\ See the file "COPYING" for further information about +\ the copyright and warranty status of this work. +\ + +hex + +tokenizer[ 1002 4336 0300 23 ]tokenizer ( -- vid did classid revision ) + +pci-revision + +pci-header + +fcode-version2 +headers + +" dev /pci" evaluate +new-device + + " ATY,QTEMU" device-name + " display" device-type + + " iso8859-1" encode-string + " character-set" property + + true encode-int + " iso6429-1983-colors" property + + : qt-open + \ [..] + ." opening framebuffer device." cr + 10 10 " pci-l@" evaluate + /n 8 = if + 10 14 " pci-l@" evaluate + 20 << or + then + ." framebuffer pointer is at 0x" dup . cr + to frame-buffer-adr + default-font set-font + d# 640 d# 480 d# 80 d# 30 fb8-install + true + ; + + : qt-close + ." QT Interface closed." cr + 0 to frame-buffer-adr + ; + + : qt-selftest + ." QT Interface selftest" cr + 0 + ; + + ['] qt-open is-install + ['] qt-close is-remove + ['] qt-selftest is-selftest + + external + +\ the following words will be defined by fb8-install +\ + +\ : open ( -- true ) +\ ; + +\ : write ( addr len -- actual ) +\ ; + +\ : draw-logo ( line# addr width height -- ) +\ ; + +\ : restore ( -- ) +\ ; + +finish-device + +fcode-end + +pci-end diff --git a/qemu/roms/openbios/arch/unix/tree.fs b/qemu/roms/openbios/arch/unix/tree.fs new file mode 100644 index 000000000..a7529b006 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/tree.fs @@ -0,0 +1,116 @@ +:noname + ." Type 'help' for detailed information" cr + ; DIAG-initializer + +" /" find-device + +new-device + " memory" device-name + \ 12230 encode-int " reg" property + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " cpus" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +finish-device + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then +; + +:noname + set-defaults +; SYSTEM-initializer + + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /cpus/@0" preopen + " stdout" " /builtin/console" preopen + " stdin" " /builtin/console" preopen + device-end +; SYSTEM-initializer + +\ use the tty interface if available +:noname + " /builtin/console" find-dev if drop + " /builtin/console" " input-device" $setenv + " /builtin/console" " output-device" $setenv + then +; SYSTEM-initializer + +:noname + " keyboard" input +; CONSOLE-IN-initializer + +dev / + +\ node suitable for non-PCI devices +new-device + " unix" device-name + 0 encode-int " #address-cells" property + 0 encode-int " #size-cells" property + + external + : open true ; + : close ; + +\ block device node +new-device + " block" device-name + " unix-block" device-type + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +\ testnode +\ new-device +\ " kappa" device-name +\ +\ 1 encode-int " reg" property +\ external +\ : open true ; +\ : close ; +\ finish-device + +finish-device +finish-device + +dev /aliases +" /unix/block/disk" encode-string " hd" property + +device-end diff --git a/qemu/roms/openbios/arch/unix/unix.c b/qemu/roms/openbios/arch/unix/unix.c new file mode 100644 index 000000000..1f628eb78 --- /dev/null +++ b/qemu/roms/openbios/arch/unix/unix.c @@ -0,0 +1,611 @@ +/* tag: hosted forth environment, executable code + * + * Copyright (C) 2003-2005 Patrick Mauritz, Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <signal.h> +#define __USE_LARGEFILE64 +#include <fcntl.h> +#include <unistd.h> +#include <termios.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <stdarg.h> + +#ifdef __GLIBC__ +#define _GNU_SOURCE +#include <getopt.h> +#endif + +#include "sysinclude.h" +#include "mconfig.h" +#include "config.h" +#include "kernel/kernel.h" +#include "dict.h" +#include "kernel/stack.h" +#include "arch/unix/plugins.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "libopenbios/openbios.h" +#include "openbios-version.h" + +#include "blk.h" +#include "libopenbios/ofmem.h" + +#define MEMORY_SIZE (4*1024*1024) /* 4M ram for hosted system */ +#define DICTIONARY_SIZE (256*1024) /* 256k for the dictionary */ + +#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64) +#define lseek lseek64 +#define __LFS O_LARGEFILE +#else +#define __LFS 0 +#endif + +/* prototypes */ +static void exit_terminal(void); +void boot(void); + +unsigned long virt_offset = 0; + +/* local variables */ + +static ucell *memory; + +static int diskemu; + +static int segfault = 0; +static int verbose = 0; + +#if defined(CONFIG_PPC) || defined(CONFIG_SPARC64) +unsigned long isa_io_base; +#endif + +int errno_int; /* implement for fs drivers, needed to build on Mac OS X */ + +ucell ofmem_claim(ucell addr, ucell size, ucell align) +{ + return 0; +} + +#ifdef CONFIG_PPC +extern void flush_icache_range(char *start, char *stop); + +void flush_icache_range(char *start, char *stop) +{ +} +#endif + +#ifdef CONFIG_PPC +/* Expose system level is_machine helpers to make generic code easier */ + +#include "drivers/drivers.h" +int is_apple(void) +{ + return 0; +} + +int is_oldworld(void) +{ + return 0; +} + +int is_newworld(void) +{ + return 0; +} +#endif + +#if 0 +static void write_dictionary(char *filename) +{ + FILE *f; + xt_t initxt; + + initxt = findword("initialize-of"); + if (!initxt) + printk("warning: dictionary needs word called initialize-of\n"); + + f = fopen(filename, "w"); + if (!f) { + printk("panic: can't open dictionary.\n"); + exit_terminal(); + exit(1); + } + + fwrite(DICTID, 16, 1, f); + fwrite(dict, dicthead, 1, f); + + /* Write start address and last to relocate on load */ + fwrite(&dict, sizeof(ucell), 1, f); + fwrite(&last, sizeof(ucell), 1, f); + + fclose(f); + +#ifdef CONFIG_DEBUG_DICTIONARY + printk("wrote dictionary to file %s.\n", filename); +#endif +} +#endif + +static ucell read_dictionary(char *fil) +{ + int ilen; + ucell ret; + char *mem; + FILE *f; + struct stat finfo; + + if (stat(fil, &finfo)) + return 0; + + ilen = finfo.st_size; + + if ((mem = malloc(ilen)) == NULL) { + printk("panic: not enough memory.\n"); + exit_terminal(); + exit(1); + } + + f = fopen(fil, "r"); + if (!f) { + printk("panic: can't open dictionary.\n"); + exit_terminal(); + exit(1); + } + + if (fread(mem, ilen, 1, f) != 1) { + printk("panic: can't read dictionary.\n"); + fclose(f); + exit_terminal(); + exit(1); + } + fclose(f); + + ret = load_dictionary(mem, ilen); + + free(mem); + return ret; +} + + +/* + * functions used by primitives + */ + +static int unix_availchar(void) +{ + int tmp = getc(stdin); + if (tmp != EOF) { + ungetc(tmp, stdin); + return -1; + } + return 0; +} + +static int unix_putchar(int c) +{ + putc(c, stdout); + return c; +} + +static int unix_getchar(void) +{ + return getc(stdin); +} + +static struct _console_ops unix_console_ops = { + .putchar = unix_putchar, + .availchar = unix_availchar, + .getchar = unix_getchar +}; + +u8 inb(u32 reg) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) + return ior->inb(reg); +#endif + + printk("TRAP: io byte read @0x%x", reg); + return 0xff; +} + +u16 inw(u32 reg) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) + return ior->inw(reg); +#endif + + printk("TRAP: io word read @0x%x", reg); + return 0xffff; +} + +u32 inl(u32 reg) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) + return ior->inl(reg); +#endif + + printk("TRAP: io long read @0x%x", reg); + return 0xffffffff; +} + +void outb(u32 reg, u8 val) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) { + ior->outb(reg, val); + return; + } +#endif + + printk("TRAP: io byte write 0x%x -> 0x%x", val, reg); +} + +void outw(u32 reg, u16 val) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) { + ior->outw(reg, val); + return; + } +#endif + printk("TRAP: io word write 0x%x -> 0x%x", val, reg); +} + +void outl(u32 reg, u32 val) +{ +#ifdef CONFIG_PLUGINS + io_ops_t *ior = find_iorange(reg); + if (ior) { + ior->outl(reg, val); + return; + } +#endif + printk("TRAP: io long write 0x%x -> 0x%x", val, reg); +} + +/* + * terminal initialization and cleanup. + */ + +static struct termios saved_termios; + +static void init_terminal(void) +{ + struct termios termios; + + tcgetattr(0, &saved_termios); + tcgetattr(0, &termios); + termios.c_lflag &= ~(ICANON | ECHO); + termios.c_cc[VMIN] = 1; + termios.c_cc[VTIME] = 3; // 300 ms + tcsetattr(0, 0, &termios); +} + +static void exit_terminal(void) +{ + tcsetattr(0, 0, &saved_termios); +} + +/* + * segmentation fault handler. linux specific? + */ + +static void +segv_handler(int signo __attribute__ ((unused)), + siginfo_t * si, void *context __attribute__ ((unused))) +{ + static int count = 0; + ucell addr = 0xdeadbeef; + + if (count) { + printk("Died while dumping forth dictionary core.\n"); + goto out; + } + + count++; + + if (PC >= (ucell) dict && PC <= (ucell) dict + dicthead) + addr = *(ucell *) PC; + + printk("panic: segmentation violation at %x\n", (ucell)si->si_addr); + printk("dict=0x%x here=0x%x(dict+0x%x) pc=0x%x(dict+0x%x)\n", + (ucell)dict, (ucell)dict + dicthead, dicthead, PC, PC - (ucell) dict); + printk("dstackcnt=%d rstackcnt=%d instruction=%x\n", + dstackcnt, rstackcnt, addr); + +#ifdef CONFIG_DEBUG_DSTACK + printdstack(); +#endif +#ifdef CONFIG_DEBUG_RSTACK + printrstack(); +#endif +#if 0 + printk("Writing dictionary core file\n"); + write_dictionary("forth.dict.core"); +#endif + + out: + exit_terminal(); + exit(1); +} + +/* + * Interrupt handler. linux specific? + * Restore terminal state on ctrl-C. + */ + +static void +int_handler(int signo __attribute__ ((unused)), + siginfo_t * si __attribute__ ((unused)), + void *context __attribute__ ((unused))) +{ + printk("\n"); + exit_terminal(); + exit(1); +} + +/* + * allocate memory and prepare engine for memory management. + */ + +static void init_memory(void) +{ + memory = malloc(MEMORY_SIZE); + if (!memory) { + printk("panic: not enough memory on host system.\n"); + exit_terminal(); + exit(1); + } + + memset (memory, 0, MEMORY_SIZE); + /* we push start and end of memory to the stack + * so that it can be used by the forth word QUIT + * to initialize the memory allocator + */ + + PUSH((ucell) memory); + PUSH((ucell) memory + MEMORY_SIZE); +} + +void exception(__attribute__((unused)) cell no) +{ + /* + * this is a noop since the dictionary has to take care + * itself of errors it generates outside of the bootstrap + */ +} + +static void +arch_init( void ) +{ + openbios_init(); + modules_init(); + if(diskemu!=-1) + blk_init(); + + device_end(); + bind_func("platform-boot", boot); +} + +int +read_from_disk( int channel, int unit, int blk, unsigned long mphys, int size ) +{ + // channels and units not supported yet. + unsigned char *buf=(unsigned char *)mphys; + + if(diskemu==-1) + return -1; + + //printk("read: ch=%d, unit=%d, blk=%ld, phys=%lx, size=%d\n", + // channel, unit, blk, mphys, size); + + lseek(diskemu, (ducell)blk*512, SEEK_SET); + read(diskemu, buf, size); + + return 0; +} + +/* + * main loop + */ + +#define BANNER "OpenBIOS core. (C) 2003-2006 Patrick Mauritz, Stefan Reinauer\n"\ + "This software comes with absolutely no warranty. "\ + "All rights reserved.\n\n" + + +#define USAGE "usage: %s [options] [dictionary file|source file]\n\n" + +int main(int argc, char *argv[]) +{ + struct sigaction sa; +#if 0 + unsigned char *dictname = NULL; +#endif + int c; + + const char *optstring = "VvhsD:P:p:f:?"; + + while (1) { +#ifdef __GLIBC__ + int option_index = 0; + static struct option long_options[] = { + {"version", 0, NULL, 'V'}, + {"verbose", 0, NULL, 'v'}, + {"help", 0, NULL, 'h'}, +// {"dictionary", 1, NULL, 'D'}, + {"segfault", 0, NULL, 's'}, +#ifdef CONFIG_PLUGINS + {"plugin-path", 1, NULL, 'P'}, + {"plugin", 1, NULL, 'p'}, +#endif + {"file", 1, NULL, 'f'} + }; + + c = getopt_long(argc, argv, optstring, long_options, + &option_index); +#else + c = getopt(argc, argv, optstring); +#endif + if (c == -1) + break; + + switch (c) { + case 'V': + printk(BANNER "Version " OPENBIOS_VERSION_STR "\n"); + return 0; + case 'h': + case '?': + printk(BANNER "Version " OPENBIOS_VERSION_STR "\n" + USAGE, argv[0]); + return 0; + case 'v': + verbose = 1; + break; + case 's': + segfault = 1; + break; +#if 0 + case 'D': + printk("Dumping final dictionary to '%s'\n", optarg); + dictname = optarg; + break; +#endif +#ifdef CONFIG_PLUGINS + case 'P': + printk("Plugin search path is now '%s'\n", optarg); + plugindir = optarg; + break; + case 'p': + printk("Loading plugin %s\n", optarg); + load_plugin(optarg); + break; +#endif + case 'f': + diskemu=open(optarg, O_RDONLY|__LFS); + if(diskemu!=-1) + printk("Using %s as harddisk.\n", optarg); + else + printk("%s not found. no harddisk node.\n", + optarg); + break; + default: + return 1; + } + } + + if (argc < optind + 1) { + printk(USAGE, argv[0]); + return 1; + } + + /* Initialise console */ + init_console(unix_console_ops); + + if ((dict = (unsigned char *) malloc(DICTIONARY_SIZE)) == NULL) { + printk("panic: not enough memory.\n"); + return 1; + } + + dictlimit = DICTIONARY_SIZE; + memset(dict, 0, DICTIONARY_SIZE); + + if (!segfault) { + if (verbose) + printk("Installing SIGSEGV handler..."); + + sa.sa_sigaction = segv_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO | SA_NODEFER; + sigaction(SIGSEGV, &sa, NULL); + + if (verbose) + printk("done.\n"); + } + + /* set terminal to do non blocking reads */ + init_terminal(); + + if (verbose) + printk("Installing SIGINT handler..."); + + sa.sa_sigaction = int_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO | SA_NODEFER; + sigaction(SIGINT, &sa, NULL); + + if (verbose) + printk("done.\n"); + + read_dictionary(argv[optind]); + forth_init(); + + PUSH_xt( bind_noname_func(arch_init) ); + fword("PREPOST-initializer"); + + PC = (cell)findword("initialize-of"); + if (PC) { + if (verbose) { + if (optind + 1 != argc) + printk("Warning: only first dictionary used.\n"); + + printk("dictionary loaded (%d bytes).\n", dicthead); + printk("Initializing memory..."); + } + init_memory(); + + if (verbose) { + printk("done\n"); + + printk("Jumping to dictionary..."); + } + + enterforth((xt_t)PC); +#if 0 + if (dictname != NULL) + write_dictionary(dictname); +#endif + + free(memory); + + } else { /* input file is not a dictionary */ + printk("not supported.\n"); + } + + exit_terminal(); + if (diskemu!=-1) + close(diskemu); + + free(dict); + return 0; +} + +#undef printk +int +printk( const char *fmt, ... ) +{ + int i; + + va_list args; + va_start( args, fmt ); + i = vprintf(fmt, args ); + va_end( args ); + return i; +} diff --git a/qemu/roms/openbios/arch/x86/Kconfig b/qemu/roms/openbios/arch/x86/Kconfig new file mode 100644 index 000000000..eac958287 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/Kconfig @@ -0,0 +1,47 @@ +mainmenu "OpenBIOS Configuration" + +config X86 + bool + default y + help + Building for X86 hardware. + +config LITTLE_ENDIAN + bool + default y + help + X86 is little endian + +menu "Kernel binaries (x86)" + +config IMAGE_ELF + bool "ELF image (for LinuxBIOS)" + default y + help + Build a simple elf image that can be used with LinuxBIOS + This image will be called openbios.elf + +config IMAGE_ELF_EMBEDDED + bool "ELF image with embedded dictionary" + default y + help + Build an elf image with embedded dictionary. This image + can easily be used with etherboot. + The image filename is openbios.full + +config IMAGE_ELF_MULTIBOOT + bool "Multiboot image" + default y + help + Build a multiboot image for booting with grub + +endmenu + +menu "Build hosted UNIX Binary" +source "arch/unix/Kconfig" +endmenu + +source "kernel/Kconfig" +source "forth/Kconfig" +source "libopenbios/Kconfig" +source "drivers/Kconfig" diff --git a/qemu/roms/openbios/arch/x86/boot.c b/qemu/roms/openbios/arch/x86/boot.c new file mode 100644 index 000000000..d40ab8c5b --- /dev/null +++ b/qemu/roms/openbios/arch/x86/boot.c @@ -0,0 +1,74 @@ +/* tag: openbios boot command for x86 + * + * Copyright (C) 2003-2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#undef BOOTSTRAP +#include "config.h" +#include "libopenbios/bindings.h" +#include "arch/common/nvram.h" +#include "libc/diskio.h" +#include "libopenbios/sys_info.h" +#include "boot.h" + +void go(void) +{ + ucell address, type, size; + int image_retval = 0; + + /* Get the entry point and the type (see forth/debugging/client.fs) */ + feval("saved-program-state >sps.entry @"); + address = POP(); + feval("saved-program-state >sps.file-type @"); + type = POP(); + feval("saved-program-state >sps.file-size @"); + size = POP(); + + printk("\nJumping to entry point " FMT_ucellx " for type " FMT_ucellx "...\n", address, type); + + switch (type) { + case 0x0: + /* Start ELF boot image */ + image_retval = start_elf(address, (uint32_t)&elf_boot_notes); + break; + + case 0x1: + /* Start ELF image */ + image_retval = start_elf(address, (uint32_t)NULL); + break; + + case 0x5: + /* Start a.out image */ + image_retval = start_elf(address, (uint32_t)NULL); + break; + + case 0x10: + /* Start Fcode image */ + printk("Evaluating FCode...\n"); + PUSH(address); + PUSH(1); + fword("byte-load"); + image_retval = 0; + break; + + case 0x11: + /* Start Forth image */ + PUSH(address); + PUSH(size); + fword("eval2"); + image_retval = 0; + break; + } + + printk("Image returned with return value %#x\n", image_retval); +} + + +void boot(void) +{ + /* No platform-specific boot code */ + return; +} diff --git a/qemu/roms/openbios/arch/x86/boot.h b/qemu/roms/openbios/arch/x86/boot.h new file mode 100644 index 000000000..749c608b3 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/boot.h @@ -0,0 +1,18 @@ +/* tag: openbios loader prototypes for x86 + * + * Copyright (C) 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* linux_load.c */ +int linux_load(struct sys_info *info, const char *file, const char *cmdline); + +/* context.c */ +extern struct context *__context; +unsigned int start_elf(unsigned long entry_point, unsigned long param); + +/* boot.c */ +extern void boot(void); +extern void go(void); diff --git a/qemu/roms/openbios/arch/x86/build.xml b/qemu/roms/openbios/arch/x86/build.xml new file mode 100644 index 000000000..260a33258 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/build.xml @@ -0,0 +1,86 @@ +<build condition="X86"> + + <dictionary name="openbios-x86" init="openbios"> + <object source="init.fs" target="forth"/> + <object source="QEMU,VGA.bin" target="fcode" condition="DRIVER_VGA"/> + </dictionary> + + <library name="x86" type="static" target="target"> + <object source="openbios.c"/> + <object source="exception.c"/> + <object source="console.c"/> + <object source="lib.c"/> + <object source="boot.c"/> + <object source="context.c"/> + <object source="linux_load.c"/> + <object source="segment.c"/> + <object source="sys_info.c"/> + <object source="entry.S"/> + <object source="xbox/console.c" condition="XBOX"/> + <object source="xbox/methods.c" condition="XBOX"/> + </library> + + <executable name="openbios.multiboot" target="target" condition="IMAGE_ELF_MULTIBOOT"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/x86/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-multiboot.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="multiboot.c"/> + <external-object source="libx86.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="liblibc.a"/> + <external-object source="libfs.a"/> + <external-object source="libgcc.a"/> + </executable> + + <executable name="openbios-plain.elf" target="target" condition="IMAGE_ELF"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/x86/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-plain.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <object source="plainboot.c"/> + <external-object source="libx86.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="liblibc.a"/> + <external-object source="libfs.a"/> + <external-object source="libgcc.a"/> + </executable> + + <!-- HACK ALERT --> + + <executable name="target/include/static-dict.h" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ + $(call quiet-command,$(ODIR)/forthstrap -x -D $@ -d $< </dev/null, " GEN $(TARGET_DIR)$@")]]></rule> + <external-object source="openbios-x86.dict"/> + </executable> + + <executable name="target/arch/x86/builtin.o" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule><![CDATA[ $(SRCDIR)/arch/x86/builtin.c $(ODIR)/target/include/static-dict.h + $(call quiet-command,$(CC) $$EXTRACFLAGS $(CFLAGS) $(INCLUDES) -c -o $@ $(SRCDIR)/arch/x86/builtin.c, " CC $(TARGET_DIR)$@")]]></rule> + </executable> + + <!-- END OF HACK ALERT --> + + <executable name="openbios-builtin.elf" target="target" condition="IMAGE_ELF_EMBEDDED"> + <rule> + $(call quiet-command,$(LD) --warn-common -N -T $(SRCDIR)/arch/x86/ldscript -o $@.nostrip --whole-archive $^," LINK $(TARGET_DIR)$@") + $(call quiet-command,$(NM) $@.nostrip | sort > $(ODIR)/openbios-builtin.syms," GEN $(TARGET_DIR)$@.syms") + $(call quiet-command,$(STRIP) $@.nostrip -o $@," STRIP $(TARGET_DIR)$@")</rule> + <external-object source="target/arch/x86/builtin.o"/> + <external-object source="libx86.a"/> + <external-object source="libbootstrap.a"/> + <external-object source="libopenbios.a"/> + <external-object source="libpackages.a"/> + <external-object source="libdrivers.a"/> + <external-object source="liblibc.a"/> + <external-object source="libfs.a"/> + <external-object source="libgcc.a"/> + </executable> + +</build> diff --git a/qemu/roms/openbios/arch/x86/builtin.c b/qemu/roms/openbios/arch/x86/builtin.c new file mode 100644 index 000000000..f7d8aba6d --- /dev/null +++ b/qemu/roms/openbios/arch/x86/builtin.c @@ -0,0 +1,32 @@ +/* tag: openbios forth starter for builtin dictionary + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/sys_info.h" + +/* + * wrap an array around the hex'ed dictionary file + */ + +/* 256K for the dictionary */ +#define DICTIONARY_SIZE (256 * 1024 / sizeof(ucell)) +#define DICTIONARY_BASE ((ucell)((char *)&forth_dictionary)) + +static ucell forth_dictionary[DICTIONARY_SIZE] = { +#include "static-dict.h" +}; + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)forth_dictionary; + info->dict_end = (unsigned long *)FORTH_DICTIONARY_END; + info->dict_last = (ucell *)((unsigned char *)forth_dictionary + + FORTH_DICTIONARY_LAST); + info->dict_limit = sizeof(forth_dictionary); +} diff --git a/qemu/roms/openbios/arch/x86/console.c b/qemu/roms/openbios/arch/x86/console.c new file mode 100644 index 000000000..906e69c25 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/console.c @@ -0,0 +1,418 @@ +/* + * Copyright (C) 2003, 2004 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "openbios.h" +#include "libopenbios/console.h" + +#ifdef CONFIG_DEBUG_CONSOLE + +/* ****************************************************************** + * serial console functions + * ****************************************************************** */ + +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + +#define RBR(x) x==2?0x2f8:0x3f8 +#define THR(x) x==2?0x2f8:0x3f8 +#define IER(x) x==2?0x2f9:0x3f9 +#define IIR(x) x==2?0x2fa:0x3fa +#define LCR(x) x==2?0x2fb:0x3fb +#define MCR(x) x==2?0x2fc:0x3fc +#define LSR(x) x==2?0x2fd:0x3fd +#define MSR(x) x==2?0x2fe:0x3fe +#define SCR(x) x==2?0x2ff:0x3ff +#define DLL(x) x==2?0x2f8:0x3f8 +#define DLM(x) x==2?0x2f9:0x3f9 + +static int uart_charav(int port) +{ + if (!port) + return -1; + return ((inb(LSR(port)) & 1) != 0); +} + +static char uart_getchar(int port) +{ + if (!port) + return -1; + while (!uart_charav(port)); + return ((char) inb(RBR(port)) & 0177); +} + +static void uart_putchar(int port, unsigned char c) +{ + if (!port) + return; + if (c == '\n') + uart_putchar(port, '\r'); + while (!(inb(LSR(port)) & 0x20)); + outb(c, THR(port)); +} + +static void uart_init_line(int port, unsigned long baud) +{ + int i, baudconst; + + if (!port) + return; + + switch (baud) { + case 115200: + baudconst = 1; + break; + case 57600: + baudconst = 2; + break; + case 38400: + baudconst = 3; + break; + case 19200: + baudconst = 6; + break; + case 9600: + default: + baudconst = 12; + break; + } + + outb(0x87, LCR(port)); + outb(0x00, DLM(port)); + outb(baudconst, DLL(port)); + outb(0x07, LCR(port)); + outb(0x0f, MCR(port)); + + for (i = 10; i > 0; i--) { + if (inb(LSR(port)) == (unsigned int) 0) + break; + inb(RBR(port)); + } +} + +int uart_init(int port, unsigned long speed) +{ + if (port) + uart_init_line(port, speed); + return -1; +} + +static void serial_putchar(int c) +{ + uart_putchar(CONFIG_SERIAL_PORT, (unsigned char) (c & 0xff)); +} + +static void serial_cls(void) +{ + serial_putchar(27); + serial_putchar('['); + serial_putchar('H'); + serial_putchar(27); + serial_putchar('['); + serial_putchar('J'); +} + +#endif + +/* ****************************************************************** + * simple polling video/keyboard console functions + * ****************************************************************** */ + +#ifdef CONFIG_DEBUG_CONSOLE_VGA + +/* raw vga text mode */ +#define COLUMNS 80 /* The number of columns. */ +#define LINES 25 /* The number of lines. */ +#define ATTRIBUTE 7 /* The attribute of an character. */ + +#define VGA_BASE 0xB8000 /* The video memory address. */ + +/* VGA Index and Data Registers */ +#define VGA_REG_INDEX 0x03D4 /* VGA index register */ +#define VGA_REG_DATA 0x03D5 /* VGA data register */ + +#define VGA_IDX_CURMSL 0x09 /* cursor maximum scan line */ +#define VGA_IDX_CURSTART 0x0A /* cursor start */ +#define VGA_IDX_CUREND 0x0B /* cursor end */ +#define VGA_IDX_CURLO 0x0F /* cursor position (low 8 bits) */ +#define VGA_IDX_CURHI 0x0E /* cursor position (high 8 bits) */ + +/* Save the X and Y position. */ +static int xpos, ypos; +/* Point to the video memory. */ +static volatile unsigned char *video = (unsigned char *) VGA_BASE; + +static void video_initcursor(void) +{ + u8 val; + outb(VGA_IDX_CURMSL, VGA_REG_INDEX); + val = inb(VGA_REG_DATA) & 0x1f; /* maximum scan line -1 */ + + outb(VGA_IDX_CURSTART, VGA_REG_INDEX); + outb(0, VGA_REG_DATA); + + outb(VGA_IDX_CUREND, VGA_REG_INDEX); + outb(val, VGA_REG_DATA); +} + + + +static void video_poscursor(unsigned int x, unsigned int y) +{ + unsigned short pos; + + /* Calculate new cursor position as a function of x and y */ + pos = (y * COLUMNS) + x; + + /* Output the new position to VGA card */ + outb(VGA_IDX_CURLO, VGA_REG_INDEX); /* output low 8 bits */ + outb((u8) (pos), VGA_REG_DATA); + outb(VGA_IDX_CURHI, VGA_REG_INDEX); /* output high 8 bits */ + outb((u8) (pos >> 8), VGA_REG_DATA); + +}; + + +static void video_newline(void) +{ + xpos = 0; + + if (ypos < LINES - 1) { + ypos++; + } else { + int i; + memmove((void *) video, (void *) (video + 2 * COLUMNS), + (LINES - 1) * COLUMNS * 2); + + for (i = ((LINES - 1) * 2 * COLUMNS); + i < 2 * COLUMNS * LINES;) { + video[i++] = 0; + video[i++] = ATTRIBUTE; + } + } + +} + +/* Put the character C on the screen. */ +static void video_putchar(int c) +{ + int p=1; + + if (c == '\n' || c == '\r') { + video_newline(); + return; + } + + if (c == '\b') { + if (xpos) xpos--; + c=' '; + p=0; + } + + + if (xpos >= COLUMNS) + video_newline(); + + *(video + (xpos + ypos * COLUMNS) * 2) = c & 0xFF; + *(video + (xpos + ypos * COLUMNS) * 2 + 1) = ATTRIBUTE; + + if (p) + xpos++; + + video_poscursor(xpos, ypos); +} + +static void video_cls(void) +{ + int i; + + for (i = 0; i < 2 * COLUMNS * LINES;) { + video[i++] = 0; + video[i++] = ATTRIBUTE; + } + + + xpos = 0; + ypos = 0; + + video_initcursor(); + video_poscursor(xpos, ypos); +} + +void video_init(void) +{ + video=phys_to_virt((unsigned char*)VGA_BASE); +} + +/* + * keyboard driver + */ + +static const char normal[] = { + 0x0, 0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', + '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', + 'p', '[', ']', 0xa, 0x0, 'a', 's', 'd', 'f', 'g', 'h', 'j', + 'k', 'l', ';', 0x27, 0x60, 0x0, 0x5c, 'z', 'x', 'c', 'v', 'b', + 'n', 'm', ',', '.', '/', 0x0, '*', 0x0, ' ', 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, '0', 0x7f +}; + +static const char shifted[] = { + 0x0, 0x1b, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', + '+', '\b', '\t', 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', + 'P', '{', '}', 0xa, 0x0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', + 'K', 'L', ':', 0x22, '~', 0x0, '|', 'Z', 'X', 'C', 'V', 'B', + 'N', 'M', '<', '>', '?', 0x0, '*', 0x0, ' ', 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, '7', '8', + '9', 0x0, '4', '5', '6', 0x0, '1', '2', '3', '0', 0x7f +}; + +static int key_ext; +static int key_lshift = 0, key_rshift = 0, key_caps = 0; + +static char last_key; + +static void keyboard_cmd(unsigned char cmd, unsigned char val) +{ + outb(cmd, 0x60); + /* wait until keyboard controller accepts cmds: */ + while (inb(0x64) & 2); + outb(val, 0x60); + while (inb(0x64) & 2); +} + +static char keyboard_poll(void) +{ + unsigned int c; + if (inb(0x64) & 1) { + c = inb(0x60); + switch (c) { + case 0xe0: + key_ext = 1; + return 0; + case 0x2a: + key_lshift = 1; + return 0; + case 0x36: + key_rshift = 1; + return 0; + case 0xaa: + key_lshift = 0; + return 0; + case 0xb6: + key_rshift = 0; + return 0; + case 0x3a: + if (key_caps) { + key_caps = 0; + keyboard_cmd(0xed, 0); + } else { + key_caps = 1; + keyboard_cmd(0xed, 4); /* set caps led */ + } + return 0; + } + + if (key_ext) { + // void printk(const char *format, ...); + printk("extended keycode: %x\n", c); + + key_ext = 0; + return 0; + } + + if (c & 0x80) /* unhandled key release */ + return 0; + + if (key_lshift || key_rshift) + return key_caps ? normal[c] : shifted[c]; + else + return key_caps ? shifted[c] : normal[c]; + } + return 0; +} + +static int keyboard_dataready(void) +{ + if (last_key) + return 1; + + last_key = keyboard_poll(); + + return (last_key != 0); +} + +static unsigned char keyboard_readdata(void) +{ + char tmp; + while (!keyboard_dataready()); + tmp = last_key; + last_key = 0; + return tmp; +} +#endif + + +/* ****************************************************************** + * common functions, implementing simple concurrent console + * ****************************************************************** */ + +static int arch_putchar(int c) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + serial_putchar(c); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + video_putchar(c); +#endif + return c; +} + +static int arch_availchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return 1; +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (keyboard_dataready()) + return 1; +#endif + return 0; +} + +static int arch_getchar(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + if (uart_charav(CONFIG_SERIAL_PORT)) + return (uart_getchar(CONFIG_SERIAL_PORT)); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + if (keyboard_dataready()) + return (keyboard_readdata()); +#endif + return 0; +} + +void cls(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + serial_cls(); +#endif +#ifdef CONFIG_DEBUG_CONSOLE_VGA + video_cls(); +#endif +} + +struct _console_ops arch_console_ops = { + .putchar = arch_putchar, + .availchar = arch_availchar, + .getchar = arch_getchar +}; + +#endif // CONFIG_DEBUG_CONSOLE diff --git a/qemu/roms/openbios/arch/x86/context.c b/qemu/roms/openbios/arch/x86/context.c new file mode 100644 index 000000000..d543f748a --- /dev/null +++ b/qemu/roms/openbios/arch/x86/context.c @@ -0,0 +1,130 @@ +/* tag: x86 context switching + * + * 2003-10 by SONE Takeshi + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "segment.h" +#include "context.h" +#include "libopenbios/sys_info.h" +#include "boot.h" +#include "openbios.h" + +#define MAIN_STACK_SIZE 16384 +#define IMAGE_STACK_SIZE 4096 + +#define debug printk + +static void start_main(void); /* forward decl. */ +void __exit_context(void); /* assembly routine */ + +/* + * Main context structure + * It is placed at the bottom of our stack, and loaded by assembly routine + * to start us up. + */ +static struct context main_ctx __attribute__((section (".initctx"))) = { + .gdt_base = (uint32_t) gdt, + .gdt_limit = GDT_LIMIT, + .cs = FLAT_CS, + .ds = FLAT_DS, + .es = FLAT_DS, + .fs = FLAT_DS, + .gs = FLAT_DS, + .ss = FLAT_DS, + .esp = (uint32_t) ESP_LOC(&main_ctx), + .eip = (uint32_t) start_main, + .return_addr = (uint32_t) __exit_context, +}; + +/* This is used by assembly routine to load/store the context which + * it is to switch/switched. */ +struct context *__context = &main_ctx; + +/* Stack for loaded ELF image */ +static uint8_t image_stack[IMAGE_STACK_SIZE]; + +/* Pointer to startup context (physical address) */ +unsigned long __boot_ctx; + +/* + * Main starter + * This is the C function that runs first. + */ +static void start_main(void) +{ + int retval; + + /* Save startup context, so we can refer to it later. + * We have to keep it in physical address since we will relocate. */ + __boot_ctx = virt_to_phys(__context); + + init_exceptions(); + /* Start the real fun */ + retval = openbios(); + + /* Pass return value to startup context. Bootloader may see it. */ + boot_ctx->eax = retval; + + /* Returning from here should jump to __exit_context */ + __context = boot_ctx; +} + +/* Setup a new context using the given stack. + */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_params) +{ + struct context *ctx; + + ctx = (struct context *) + (stack + stack_size - (sizeof(*ctx) + num_params*sizeof(uint32_t))); + memset(ctx, 0, sizeof(*ctx)); + + /* Fill in reasonable default for flat memory model */ + ctx->gdt_base = virt_to_phys(gdt); + ctx->gdt_limit = GDT_LIMIT; + ctx->cs = FLAT_CS; + ctx->ds = FLAT_DS; + ctx->es = FLAT_DS; + ctx->fs = FLAT_DS; + ctx->gs = FLAT_DS; + ctx->ss = FLAT_DS; + ctx->esp = virt_to_phys(ESP_LOC(ctx)); + ctx->return_addr = virt_to_phys(__exit_context); + + return ctx; +} + +/* Switch to another context. */ +struct context *switch_to(struct context *ctx) +{ + struct context *save, *ret; + + debug("switching to new context:\n"); + save = __context; + __context = ctx; + asm ("pushl %cs; call __switch_context"); + ret = __context; + __context = save; + return ret; +} + +/* Start ELF Boot image */ +unsigned int start_elf(unsigned long entry_point, unsigned long param) +{ + struct context *ctx; + + ctx = init_context(image_stack, sizeof image_stack, 1); + ctx->eip = entry_point; + ctx->param[0] = param; + ctx->eax = 0xe1fb007; + ctx->ebx = param; + + ctx = switch_to(ctx); + return ctx->eax; +} diff --git a/qemu/roms/openbios/arch/x86/context.h b/qemu/roms/openbios/arch/x86/context.h new file mode 100644 index 000000000..6a1c5adbc --- /dev/null +++ b/qemu/roms/openbios/arch/x86/context.h @@ -0,0 +1,48 @@ +#ifndef i386_CONTEXT_H +#define i386_CONTEXT_H + +struct context { + /* Stack Segment, placed here because of the alignment issue... */ + uint16_t ss; + /* Used with sgdt/lgdt */ + uint16_t gdt_limit; + uint32_t gdt_base; + /* General registers, accessed with pushal/popal */ + uint32_t edi; + uint32_t esi; + uint32_t ebp; + uint32_t esp; /* points just below eax */ + uint32_t ebx; + uint32_t edx; + uint32_t ecx; + uint32_t eax; +#define ESP_LOC(ctx) (&(ctx)->gs) + /* Segment registers */ + uint32_t gs; + uint32_t fs; + uint32_t es; + uint32_t ds; + /* Flags */ + uint32_t eflags; + /* Code segment:offset */ + uint32_t eip; + uint32_t cs; + /* Optional stack contents */ + uint32_t return_addr; + uint32_t param[0]; +}; + +/* Create a new context in the given stack */ +struct context * +init_context(uint8_t *stack, uint32_t stack_size, int num_param); + +/* Switch context */ +struct context *switch_to(struct context *); + +/* Holds physical address of boot context */ +extern unsigned long __boot_ctx; + +/* This can always be safely used to refer to the boot context */ +#define boot_ctx ((struct context *) phys_to_virt(__boot_ctx)) + +#endif /* i386_CONTEXT_H */ diff --git a/qemu/roms/openbios/arch/x86/defconfig b/qemu/roms/openbios/arch/x86/defconfig new file mode 100644 index 000000000..b0a02ab3c --- /dev/null +++ b/qemu/roms/openbios/arch/x86/defconfig @@ -0,0 +1,65 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_X86=y +CONFIG_LITTLE_ENDIAN=y + +# +# Kernel binaries (x86) +# +CONFIG_IMAGE_ELF=y +CONFIG_IMAGE_ELF_EMBEDDED=y +CONFIG_IMAGE_ELF_MULTIBOOT=y + +# +# Build hosted UNIX Binary +# +CONFIG_HOST_UNIX=y +# CONFIG_PLUGIN_PCI is not set + +# +# Kernel Debugging +# +# CONFIG_DEBUG is not set +CONFIG_DEBUG_CONSOLE=y +CONFIG_DEBUG_CONSOLE_SERIAL=y +CONFIG_SERIAL_PORT=1 +CONFIG_SERIAL_SPEED=115200 +CONFIG_DEBUG_CONSOLE_VGA=y + +# +# Module Configuration +# +CONFIG_CMDLINE=y +CONFIG_DEBLOCKER=y + +# +# Filesystem Configuration +# +CONFIG_DISK_LABEL=y +CONFIG_PART_SUPPORT=y +CONFIG_PC_PARTS=y +CONFIG_FS=y +CONFIG_GRUBFS=y +CONFIG_FSYS_EXT2FS=y +CONFIG_FSYS_FAT=y +CONFIG_FSYS_JFS=y +# CONFIG_FSYS_MINIX is not set +CONFIG_FSYS_REISERFS=y +CONFIG_FSYS_XFS=y +CONFIG_FSYS_ISO9660=y +# CONFIG_FSYS_FFS is not set +# CONFIG_FSYS_VSTAFS is not set +# CONFIG_DEBUG_FS is not set + +# +# Miscellaneous +# +CONFIG_LINUXBIOS=y + +# +# Drivers +# +CONFIG_DRIVER_PCI=y +CONFIG_DRIVER_IDE=y +# CONFIG_DEBUG_IDE is not set diff --git a/qemu/roms/openbios/arch/x86/entry.S b/qemu/roms/openbios/arch/x86/entry.S new file mode 100644 index 000000000..8f1e42eed --- /dev/null +++ b/qemu/roms/openbios/arch/x86/entry.S @@ -0,0 +1,315 @@ + .globl entry, __switch_context, __exit_context, halt, init_exceptions + + .text + .align 4 + +/* + * Entry point + * We start execution from here. + * It is assumed that CPU is in 32-bit protected mode and + * all segments are 4GB and base zero (flat model). + */ +entry: + /* Save boot context and switch to our main context. + * Main context is statically defined in C. + */ + pushl %cs + call __switch_context + + /* We get here when the main context switches back to + * the boot context. + * Return to previous bootloader. + */ + ret + +/* + * Switch execution context + * This saves registers, segments, and GDT in the stack, then + * switches the stack, and restores everything from the new stack. + * This function takes no argument. New stack pointer is + * taken from global variable __context, and old stack pointer + * is also saved to __context. This way we can just jump to + * this routine to get back to the original context. + * + * Call this routine with lcall or pushl %cs; call. + */ +__switch_context: + /* Save everything in current stack */ + pushfl /* 56 */ + pushl %ds /* 52 */ + pushl %es /* 48 */ + pushl %fs /* 44 */ + pushl %gs /* 40 */ + pushal /* 8 */ + subl $8, %esp + movw %ss, (%esp) /* 0 */ + sgdt 2(%esp) /* 2 */ + +#if 0 + /* Swap %cs and %eip on the stack, so lret will work */ + movl 60(%esp), %eax + xchgl %eax, 64(%esp) + movl %eax, 60(%esp) +#endif + + /* At this point we don't know if we are on flat segment + * or relocated. So compute the address offset from %eip. + * Assuming CS.base==DS.base==SS.base. + */ + call 1f +1: popl %ebx + subl $1b, %ebx + + /* Interrupts are not allowed... */ + cli + + /* Current context pointer is our stack pointer */ + movl %esp, %esi + + /* Normalize the ctx pointer */ + subl %ebx, %esi + + /* Swap it with new value */ + xchgl %esi, __context(%ebx) + + /* Adjust new ctx pointer for current address offset */ + addl %ebx, %esi + + /* Load new %ss and %esp to temporary */ + movzwl (%esi), %edx + movl 20(%esi), %eax + + /* Load new GDT */ + lgdt 2(%esi) + + /* Load new stack segment with new GDT */ + movl %edx, %ss + + /* Set new stack pointer, but we have to adjust it because + * pushal saves %esp value before pushal, and we want the value + * after pushal. + */ + leal -32(%eax), %esp + + /* Load the rest from new stack */ + popal + popl %gs + popl %fs + popl %es + popl %ds + popfl + + /* Finally, load new %cs and %eip */ + lret + +__exit_context: + /* Get back to the original context */ + pushl %cs + call __switch_context + + /* We get here if the other context attempt to switch to this + * dead context. This should not happen. */ + +halt: + cli + hlt + jmp halt + +/* + * initialize exception handler. All exceptions end up in the same + * C function. + */ + +init_exceptions: + pushl %ebx + pushl %edi + + /* Initialize the Interrupt Descriptor table */ + leal _idt, %edi + leal vec0, %ebx + movl $(0x08 << 16), %eax /* cs selector */ + +1: movw %bx, %ax + movl %ebx, %edx + movw $0x8E00, %dx /* Interrupt gate - dpl=0, present */ + movl %eax, 0(%edi) + movl %edx, 4(%edi) + addl $6, %ebx + addl $8, %edi + cmpl $_idt_end, %edi + jne 1b + + /* Load the Interrupt descriptor table */ + lidt idtarg + + movl $0, %eax + popl %edi + popl %ebx + ret + +vec0: + pushl $0 /* error code */ + pushl $0 /* vector */ + jmp int_hand +vec1: + pushl $0 /* error code */ + pushl $1 /* vector */ + jmp int_hand + +vec2: + pushl $0 /* error code */ + pushl $2 /* vector */ + jmp int_hand + +vec3: + pushl $0 /* error code */ + pushl $3 /* vector */ + jmp int_hand + +vec4: + pushl $0 /* error code */ + pushl $4 /* vector */ + jmp int_hand + +vec5: + pushl $0 /* error code */ + pushl $5 /* vector */ + jmp int_hand + +vec6: + pushl $0 /* error code */ + pushl $6 /* vector */ + jmp int_hand +vec7: + pushl $0 /* error code */ + pushl $7 /* vector */ + jmp int_hand + +vec8: + /* error code */ + pushl $8 /* vector */ + jmp int_hand + .word 0x9090 + +vec9: + pushl $0 /* error code */ + pushl $9 /* vector */ + jmp int_hand + +vec10: + /* error code */ + pushl $10 /* vector */ + jmp int_hand + .word 0x9090 + +vec11: + /* error code */ + pushl $11 /* vector */ + jmp int_hand + .word 0x9090 + +vec12: + /* error code */ + pushl $12 /* vector */ + jmp int_hand + .word 0x9090 + +vec13: + /* error code */ + pushl $13 /* vector */ + jmp int_hand + .word 0x9090 + +vec14: + /* error code */ + pushl $14 /* vector */ + jmp int_hand + .word 0x9090 + +vec15: + pushl $0 /* error code */ + pushl $15 /* vector */ + jmp int_hand + +vec16: + pushl $0 /* error code */ + pushl $16 /* vector */ + jmp int_hand + +vec17: + /* error code */ + pushl $17 /* vector */ + jmp int_hand + .word 0x9090 + +vec18: + pushl $0 /* error code */ + pushl $18 /* vector */ + jmp int_hand + +vec19: + pushl $0 /* error code */ + pushl $19 /* vector */ + jmp int_hand + +__divide_error: + pushl $0 /* error code */ + pushl $20 /* vector */ + jmp int_hand + .global __divide_error + +int_hand: + /* At this point on the stack there is: + * 0(%esp) vector + * 4(%esp) error code + * 8(%esp) eip + * 12(%esp) cs + * 16(%esp) eflags + */ + pushl %edi + pushl %esi + pushl %ebp + /* Original stack pointer */ + leal 32(%esp), %ebp + pushl %ebp + pushl %ebx + pushl %edx + pushl %ecx + pushl %eax + + pushl %esp /* Pointer to structure on the stack */ + + call x86_exception + pop %eax /* Drop the pointer */ + + popl %eax + popl %ecx + popl %edx + popl %ebx + popl %ebp /* Ignore saved %esp value */ + popl %ebp + popl %esi + popl %edi + + addl $8, %esp /* pop of the vector and error code */ + + iret + +idtarg: + .word _idt_end - _idt - 1 /* limit */ + .long _idt + .word 0 +_idt: + .fill 20, 8, 0 # idt is unitiailzed +_idt_end: + + .globl arch_nvram_size, arch_nvram_get, arch_nvram_put +arch_nvram_size: + xor %eax, %eax + ret + +arch_nvram_get: + ret + +arch_nvram_put: + ret diff --git a/qemu/roms/openbios/arch/x86/exception.c b/qemu/roms/openbios/arch/x86/exception.c new file mode 100644 index 000000000..fa07242c5 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/exception.c @@ -0,0 +1,92 @@ +#include "config.h" +#include "libopenbios/bindings.h" +#include "asm/types.h" + + + +/* program counter */ +extern ucell PC; + +extern unsigned char *dict; +extern cell dicthead; +extern ucell *last; + + + +struct eregs { + uint32_t eax, ecx, edx, ebx, esp, ebp, esi, edi; + uint32_t vector; + uint32_t error_code; + uint32_t eip; + uint32_t cs; + uint32_t eflags; +}; + +static const char * const exception_names[]= { + "division by zero", + "single step", + "NMI", + "breakpoint", + "interrupt overflow", + "bound range exceeded", + "invalid opcode", + "device unavailable", + "double fault", + "FPU segment overrun", + "invalid TSS", + "segment not present", + "stack exception", + "general protection fault", + "page fault", + "reserved", + "floating point exception", + "alignment check", + "machine check exception", +}; + +void do_nothing(void); +void do_nothing(void) +{ + printk("Doing nothing\n"); +} + +void x86_exception(struct eregs *info); +void x86_exception(struct eregs *info) +{ + if(info->vector <= 18) { + printk("\nUnexpected Exception: %s", + exception_names[info->vector]); + } else { + printk("\nUnexpected Exception: %d", info->vector); + } + + printk( + " @ %02x:%08lx - Halting\n" + "Code: %d eflags: %08lx\n" + "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n" + "edi: %08lx esi: %08lx ebp: %08lx esp: %08lx\n", + info->cs, (unsigned long)info->eip, + info->error_code, (unsigned long)info->eflags, + (unsigned long)info->eax, (unsigned long)info->ebx, + (unsigned long)info->ecx, (unsigned long)info->edx, + (unsigned long)info->edi, (unsigned long)info->esi, + (unsigned long)info->ebp, (unsigned long)info->esp); + + printk("\ndict=0x%x here=0x%x(dict+0x%x) pc=0x%x(dict+0x%x)\n", + (ucell)dict, (ucell)dict + dicthead, dicthead, PC, PC - (ucell) dict); + printk("dstackcnt=%d rstackcnt=%d\n", + dstackcnt, rstackcnt); + + rstackcnt=0; + dstackcnt=0; + + PC=findword("outer-interpreter"); + + info->eip=(uint32_t)&do_nothing; + +/* + for (;;) + asm("hlt;"); + ; +*/ +} diff --git a/qemu/roms/openbios/arch/x86/init.fs b/qemu/roms/openbios/arch/x86/init.fs new file mode 100644 index 000000000..eef72e9b2 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/init.fs @@ -0,0 +1,84 @@ +include config.fs + +:noname + ." Type 'help' for detailed information" cr + \ ." boot secondary slave cdrom: " cr + \ ." 0 > boot hd:2,\boot\vmlinuz root=/dev/hda2" cr + ; DIAG-initializer + +" /" find-device + +new-device + " memory" device-name + \ 12230 encode-int " reg" property + external + : open true ; + : close ; + \ claim ( phys size align -- base ) + \ release ( phys size -- ) +finish-device + +new-device + " cpus" device-name + 1 " #address-cells" int-property + 0 " #size-cells" int-property + + external + : open true ; + : close ; + : decode-unit parse-hex ; + +finish-device + +: make-openable ( path ) + find-dev if + begin ?dup while + \ install trivial open and close methods + dup active-package! is-open + parent + repeat + then +; + +: preopen ( chosen-str node-path ) + 2dup make-openable + + " /chosen" find-device + open-dev ?dup if + encode-int 2swap property + else + 2drop + then + device-end +; + +:noname + set-defaults +; SYSTEM-initializer + +\ preopen device nodes (and store the ihandles under /chosen) +:noname + " memory" " /memory" preopen + " mmu" " /cpus/@0" preopen + " stdout" " /builtin/console" preopen + " stdin" " /builtin/console" preopen + +; SYSTEM-initializer + +\ use the tty interface if available +:noname + " /builtin/console" find-dev if drop + " /builtin/console" " input-device" $setenv + " /builtin/console" " output-device" $setenv + then +; SYSTEM-initializer + +:noname + " keyboard" input +; CONSOLE-IN-initializer + +\ Load VGA FCode driver blob +[IFDEF] CONFIG_DRIVER_VGA + -1 value vga-driver-fcode + " QEMU,VGA.bin" $encode-file to vga-driver-fcode +[THEN] diff --git a/qemu/roms/openbios/arch/x86/ldscript b/qemu/roms/openbios/arch/x86/ldscript new file mode 100644 index 000000000..8976c7af0 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/ldscript @@ -0,0 +1,73 @@ +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386) + +ENTRY(entry) + +/* Initial load address + * To be loaded by GRUB, this must be >= 1MB + */ +BASE_ADDR = 0x100000; + +/* 16KB heap and stack */ +HEAP_SIZE = 16384; +STACK_SIZE = 16384; + +SECTIONS +{ + . = BASE_ADDR; + + /* Put Multiboot header near beginning of file, if any. */ + .hdr : { *(.hdr) *(.hdr.*) } + + /* Start of the program. + * Now the version string is in the note, we must include it + * in the program. Otherwise we lose the string after relocation. */ + . = ALIGN(16); + _start = .; + + /* Putting ELF notes near beginning of file might help bootloaders. + * We discard .note sections other than .note.ELFBoot, + * because some versions of GCC generates useless ones. */ + .note : { *(.note.ELFBoot) } + + /* Normal sections */ + .text : { *(.text) *(.text.*) } + .rodata : { + . = ALIGN(4); + sound_drivers_start = .; + *(.rodata.sound_drivers) + sound_drivers_end = .; + *(.rodata) + *(.rodata.*) + } + .data : { *(.data) *(.data.*) } + + .bss : { + *(.bss) + *(.bss.*) + *(COMMON) + + /* Put heap and stack here, so they are included in PT_LOAD segment + * and the bootloader is aware of it. */ + + . = ALIGN(16); + _heap = .; + . += HEAP_SIZE; + . = ALIGN(16); + _eheap = .; + + _stack = .; + . += STACK_SIZE; + . = ALIGN(16); + _estack = .; + } + + .initctx : { + /* Initial contents of stack. This MUST BE just after the stack. */ + *(.initctx) + } + + _end = .; + + /DISCARD/ : { *(.comment) *(.note) } +} diff --git a/qemu/roms/openbios/arch/x86/lib.c b/qemu/roms/openbios/arch/x86/lib.c new file mode 100644 index 000000000..eeb901b4a --- /dev/null +++ b/qemu/roms/openbios/arch/x86/lib.c @@ -0,0 +1,56 @@ +/* lib.c + * tag: simple function library + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "asm/types.h" +#include <stdarg.h> +#include "libc/stdlib.h" +#include "libc/vsprintf.h" +#include "kernel/kernel.h" + +/* Format a string and print it on the screen, just like the libc + * function printf. + */ +int printk( const char *fmt, ... ) +{ + char *p, buf[512]; + va_list args; + int i; + + va_start(args, fmt); + i = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + for( p=buf; *p; p++ ) + putchar(*p); + return i; +} + +// dumb quick memory allocator until we get a decent thing here. + +#define MEMSIZE 128*1024 +static char memory[MEMSIZE]; +static void *memptr=memory; +static int memsize=MEMSIZE; + +void *malloc(int size) +{ + void *ret=(void *)0; + if(memsize>=size) { + memsize-=size; + ret=memptr; + memptr = (void *)((unsigned long)memptr + size); + } + return ret; +} + +void free(void *ptr) +{ + /* Nothing yet */ +} diff --git a/qemu/roms/openbios/arch/x86/linux_load.c b/qemu/roms/openbios/arch/x86/linux_load.c new file mode 100644 index 000000000..e06326b09 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/linux_load.c @@ -0,0 +1,671 @@ +/* + * Linux/i386 loader + * Supports bzImage, zImage and Image format. + * + * Based on work by Steve Gehlbach. + * Portions are taken from mkelfImage. + * + * 2003-09 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/bindings.h" +#include "libopenbios/sys_info.h" +#include "context.h" +#include "segment.h" +#include "libc/diskio.h" +#include "boot.h" + +#define printf printk +#define debug printk +#define strtoull_with_suffix strtol + +#define LINUX_PARAM_LOC 0x90000 +#define COMMAND_LINE_LOC 0x91000 +#define GDT_LOC 0x92000 +#define STACK_LOC 0x93000 + +#define E820MAX 32 /* number of entries in E820MAP */ +struct e820entry { + unsigned long long addr; /* start of memory segment */ + unsigned long long size; /* size of memory segment */ + unsigned long type; /* type of memory segment */ +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 /* usable as RAM once ACPI tables have been read */ +#define E820_NVS 4 +}; + +/* The header of Linux/i386 kernel */ +struct linux_header { + uint8_t reserved1[0x1f1]; /* 0x000 */ + uint8_t setup_sects; /* 0x1f1 */ + uint16_t root_flags; /* 0x1f2 */ + uint8_t reserved2[6]; /* 0x1f4 */ + uint16_t vid_mode; /* 0x1fa */ + uint16_t root_dev; /* 0x1fc */ + uint16_t boot_sector_magic; /* 0x1fe */ + /* 2.00+ */ + uint8_t reserved3[2]; /* 0x200 */ + uint8_t header_magic[4]; /* 0x202 */ + uint16_t protocol_version; /* 0x206 */ + uint32_t realmode_swtch; /* 0x208 */ + uint16_t start_sys; /* 0x20c */ + uint16_t kver_addr; /* 0x20e */ + uint8_t type_of_loader; /* 0x210 */ + uint8_t loadflags; /* 0x211 */ + uint16_t setup_move_size; /* 0x212 */ + uint32_t code32_start; /* 0x214 */ + uint32_t ramdisk_image; /* 0x218 */ + uint32_t ramdisk_size; /* 0x21c */ + uint8_t reserved4[4]; /* 0x220 */ + /* 2.01+ */ + uint16_t heap_end_ptr; /* 0x224 */ + uint8_t reserved5[2]; /* 0x226 */ + /* 2.02+ */ + uint32_t cmd_line_ptr; /* 0x228 */ + /* 2.03+ */ + uint32_t initrd_addr_max; /* 0x22c */ +} __attribute__ ((packed)); + + +/* Paramters passed to 32-bit part of Linux + * This is another view of the structure above.. */ +struct linux_params { + uint8_t orig_x; /* 0x00 */ + uint8_t orig_y; /* 0x01 */ + uint16_t ext_mem_k; /* 0x02 -- EXT_MEM_K sits here */ + uint16_t orig_video_page; /* 0x04 */ + uint8_t orig_video_mode; /* 0x06 */ + uint8_t orig_video_cols; /* 0x07 */ + uint16_t unused2; /* 0x08 */ + uint16_t orig_video_ega_bx; /* 0x0a */ + uint16_t unused3; /* 0x0c */ + uint8_t orig_video_lines; /* 0x0e */ + uint8_t orig_video_isVGA; /* 0x0f */ + uint16_t orig_video_points; /* 0x10 */ + + /* VESA graphic mode -- linear frame buffer */ + uint16_t lfb_width; /* 0x12 */ + uint16_t lfb_height; /* 0x14 */ + uint16_t lfb_depth; /* 0x16 */ + uint32_t lfb_base; /* 0x18 */ + uint32_t lfb_size; /* 0x1c */ + uint16_t cl_magic; /* 0x20 */ +#define CL_MAGIC_VALUE 0xA33F + uint16_t cl_offset; /* 0x22 */ + uint16_t lfb_linelength; /* 0x24 */ + uint8_t red_size; /* 0x26 */ + uint8_t red_pos; /* 0x27 */ + uint8_t green_size; /* 0x28 */ + uint8_t green_pos; /* 0x29 */ + uint8_t blue_size; /* 0x2a */ + uint8_t blue_pos; /* 0x2b */ + uint8_t rsvd_size; /* 0x2c */ + uint8_t rsvd_pos; /* 0x2d */ + uint16_t vesapm_seg; /* 0x2e */ + uint16_t vesapm_off; /* 0x30 */ + uint16_t pages; /* 0x32 */ + uint8_t reserved4[12]; /* 0x34 -- 0x3f reserved for future expansion */ + + //struct apm_bios_info apm_bios_info; /* 0x40 */ + uint8_t apm_bios_info[0x40]; + //struct drive_info_struct drive_info; /* 0x80 */ + uint8_t drive_info[0x20]; + //struct sys_desc_table sys_desc_table; /* 0xa0 */ + uint8_t sys_desc_table[0x140]; + uint32_t alt_mem_k; /* 0x1e0 */ + uint8_t reserved5[4]; /* 0x1e4 */ + uint8_t e820_map_nr; /* 0x1e8 */ + uint8_t reserved6[9]; /* 0x1e9 */ + uint16_t mount_root_rdonly; /* 0x1f2 */ + uint8_t reserved7[4]; /* 0x1f4 */ + uint16_t ramdisk_flags; /* 0x1f8 */ +#define RAMDISK_IMAGE_START_MASK 0x07FF +#define RAMDISK_PROMPT_FLAG 0x8000 +#define RAMDISK_LOAD_FLAG 0x4000 + uint8_t reserved8[2]; /* 0x1fa */ + uint16_t orig_root_dev; /* 0x1fc */ + uint8_t reserved9[1]; /* 0x1fe */ + uint8_t aux_device_info; /* 0x1ff */ + uint8_t reserved10[2]; /* 0x200 */ + uint8_t param_block_signature[4]; /* 0x202 */ + uint16_t param_block_version; /* 0x206 */ + uint8_t reserved11[8]; /* 0x208 */ + uint8_t loader_type; /* 0x210 */ +#define LOADER_TYPE_LOADLIN 1 +#define LOADER_TYPE_BOOTSECT_LOADER 2 +#define LOADER_TYPE_SYSLINUX 3 +#define LOADER_TYPE_ETHERBOOT 4 +#define LOADER_TYPE_KERNEL 5 + uint8_t loader_flags; /* 0x211 */ + uint8_t reserved12[2]; /* 0x212 */ + uint32_t kernel_start; /* 0x214 */ + uint32_t initrd_start; /* 0x218 */ + uint32_t initrd_size; /* 0x21c */ + uint8_t reserved12_5[8]; /* 0x220 */ + uint32_t cmd_line_ptr; /* 0x228 */ + uint8_t reserved13[164]; /* 0x22c */ + struct e820entry e820_map[E820MAX]; /* 0x2d0 */ + uint8_t reserved16[688]; /* 0x550 */ +#define COMMAND_LINE_SIZE 256 + /* Command line is copied here by 32-bit i386/kernel/head.S. + * So I will follow the boot protocol, rather than putting it + * directly here. --ts1 */ + uint8_t command_line[COMMAND_LINE_SIZE]; /* 0x800 */ + uint8_t reserved17[1792]; /* 0x900 - 0x1000 */ +}; + +static uint64_t forced_memsize; +static int fd; + +static unsigned long file_size(void) +{ + long long fpos, fsize; + + /* Save current position */ + fpos = tell(fd); + + /* Go to end of file and get position */ + seek_io(fd, -1); + fsize = tell(fd); + + /* Go back to old position */ + seek_io(fd, 0); + seek_io(fd, fpos); + + return fsize; +} + +/* Load the first part the file and check if it's Linux */ +static uint32_t load_linux_header(struct linux_header *hdr) +{ + int load_high; + uint32_t kern_addr; + + if (read_io(fd, hdr, sizeof *hdr) != sizeof *hdr) { + debug("Can't read Linux header\n"); + return 0; + } + if (hdr->boot_sector_magic != 0xaa55) { + debug("Not a Linux kernel image\n"); + return 0; + } + + /* Linux is found. Print some information */ + if (memcmp(hdr->header_magic, "HdrS", 4) != 0) { + /* This may be floppy disk image or something. + * Perform a simple (incomplete) sanity check. */ + if (hdr->setup_sects >= 16 + || file_size() - (hdr->setup_sects<<9) >= 512<<10) { + debug("This looks like a bootdisk image but not like Linux...\n"); + return 0; + } + + printf("Possible very old Linux"); + /* This kernel does not even have a protocol version. + * Force the value. */ + hdr->protocol_version = 0; /* pre-2.00 */ + } else + printf("Found Linux"); + if (hdr->protocol_version >= 0x200 && hdr->kver_addr) { + char kver[256]; + seek_io(fd, hdr->kver_addr + 0x200); + if (read_io(fd, kver, sizeof kver) != 0) { + kver[255] = 0; + printf(" version %s", kver); + } + } + debug(" (protocol %#x)", hdr->protocol_version); + load_high = 0; + if (hdr->protocol_version >= 0x200) { + debug(" (loadflags %#x)", hdr->loadflags); + load_high = hdr->loadflags & 1; + } + if (load_high) { + printf(" bzImage"); + kern_addr = 0x100000; + } else { + printf(" zImage or Image"); + kern_addr = 0x1000; + } + printf(".\n"); + + return kern_addr; +} + +/* Set up parameters for 32-bit kernel */ +static void +init_linux_params(struct linux_params *params, struct linux_header *hdr) +{ + debug("Setting up paramters at %#lx\n", virt_to_phys(params)); + memset(params, 0, sizeof *params); + + /* Copy some useful values from header */ + params->mount_root_rdonly = hdr->root_flags; + params->orig_root_dev = hdr->root_dev; + + /* Video parameters. + * This assumes we have VGA in standard 80x25 text mode, + * just like our vga.c does. + * Cursor position is filled later to allow some more printf's. */ + params->orig_video_mode = 3; + params->orig_video_cols = 80; + params->orig_video_lines = 25; + params->orig_video_isVGA = 1; + params->orig_video_points = 16; + + params->loader_type = 0xff; /* Unregistered Linux loader */ +} + +/* Memory map */ +static void +set_memory_size(struct linux_params *params, struct sys_info *info) +{ + int i; + uint64_t end; + uint32_t ramtop = 0; + struct e820entry *linux_map; + struct memrange *filo_map; + + linux_map = params->e820_map; + filo_map = info->memrange; + for (i = 0; i < info->n_memranges; i++, linux_map++, filo_map++) { + if (i < E820MAX) { + /* Convert to BIOS e820 style */ + linux_map->addr = filo_map->base; + linux_map->size = filo_map->size; + linux_map->type = E820_RAM; + debug("%016Lx - %016Lx\n", linux_map->addr, + linux_map->addr + linux_map->size); + params->e820_map_nr = i+1; + } + + /* Find out top of RAM. XXX This ignores hole above 1MB */ + end = filo_map->base + filo_map->size; + if (end < (1ULL << 32)) { /* don't count memory above 4GB */ + if (end > ramtop) + ramtop = (uint32_t) end; + } + } + debug("ramtop=%#x\n", ramtop); + /* Size of memory above 1MB in KB */ + params->alt_mem_k = (ramtop - (1<<20)) >> 10; + /* old style, 64MB max */ + if (ramtop >= (64<<20)) + params->ext_mem_k = (63<<10); + else + params->ext_mem_k = params->alt_mem_k; + debug("ext_mem_k=%d, alt_mem_k=%d\n", params->ext_mem_k, params->alt_mem_k); +} + +/* + * Parse command line + * Some parameters, like initrd=<file>, are not passed to kernel, + * we are responsible to process them. + * Parameters for kernel are copied to kern_cmdline. Returns name of initrd. + */ +static char *parse_command_line(const char *orig_cmdline, char *kern_cmdline) +{ + const char *start, *sep, *end, *val; + char name[64]; + int len; + int k_len; + int to_kern; + char *initrd = NULL; + int toolong = 0; + + forced_memsize = 0; + + if (!orig_cmdline) { + *kern_cmdline = 0; + return NULL; + } + + k_len = 0; + debug("original command line: \"%s\"\n", orig_cmdline); + debug("kernel command line at %#lx\n", virt_to_phys(kern_cmdline)); + + start = orig_cmdline; + while (*start == ' ') + start++; + while (*start) { + end = strchr(start, ' '); + if (!end) + end = start + strlen(start); + sep = strchr(start, '='); + if (!sep || sep > end) + sep = end; + len = sep - start; + if (len >= sizeof(name)) + len = sizeof(name) - 1; + memcpy(name, start, len); + name[len] = 0; + + if (*sep == '=') { + val = sep + 1; + len = end - val; + } else { + val = NULL; + len = 0; + } + + /* Only initrd= and mem= are handled here. vga= is not, + * which I believe is a paramter to the realmode part of Linux, + * which we don't execute. */ + if (strcmp(name, "initrd") == 0) { + if (!val) + printf("Missing filename to initrd parameter\n"); + else { + initrd = malloc(len + 1); + memcpy(initrd, val, len); + initrd[len] = 0; + debug("initrd=%s\n", initrd); + } + /* Don't pass this to kernel */ + to_kern = 0; + } else if (strcmp(name, "mem") == 0) { + if (!val) + printf("Missing value for mem parameter\n"); + else { + forced_memsize = strtoull_with_suffix(val, (char**)&val, 0); + if (forced_memsize == 0) + printf("Invalid mem option, ignored\n"); + if (val != end) { + printf("Garbage after mem=<size>, ignored\n"); + forced_memsize = 0; + } + debug("mem=%Lu\n", forced_memsize); + } + /* mem= is for both loader and kernel */ + to_kern = 1; + } else + to_kern = 1; + + if (to_kern) { + /* Copy to kernel command line buffer */ + if (k_len != 0) + kern_cmdline[k_len++] = ' '; /* put separator */ + len = end - start; + if (k_len + len >= COMMAND_LINE_SIZE) { + len = COMMAND_LINE_SIZE - k_len - 1; + if (!toolong) { + printf("Kernel command line is too long; truncated to " + "%d bytes\n", COMMAND_LINE_SIZE-1); + toolong = 1; + } + } + memcpy(kern_cmdline + k_len, start, len); + k_len += len; + } + + start = end; + while (*start == ' ') + start++; + } + kern_cmdline[k_len] = 0; + debug("kernel command line (%d bytes): \"%s\"\n", k_len, kern_cmdline); + + return initrd; +} + +/* Set command line location */ +static void set_command_line_loc(struct linux_params *params, + struct linux_header *hdr) +{ + if (hdr->protocol_version >= 0x202) { + /* new style */ + params->cmd_line_ptr = COMMAND_LINE_LOC; + } else { + /* old style */ + params->cl_magic = CL_MAGIC_VALUE; + params->cl_offset = COMMAND_LINE_LOC - LINUX_PARAM_LOC; + } +} + +/* Load 32-bit part of kernel */ +static int load_linux_kernel(struct linux_header *hdr, uint32_t kern_addr) +{ + uint32_t kern_offset, kern_size; + + if (hdr->setup_sects == 0) + hdr->setup_sects = 4; + kern_offset = (hdr->setup_sects + 1) * 512; + seek_io(fd, kern_offset); + kern_size = file_size() - kern_offset; + debug("offset=%#x addr=%#x size=%#x\n", kern_offset, kern_addr, kern_size); + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as kernel; " + "specify the image size\n"); + return 0; + } +#endif + + printf("Loading kernel... "); + if (read_io(fd, phys_to_virt(kern_addr), kern_size) != kern_size) { + printf("Can't read kernel\n"); + return 0; + } + printf("ok\n"); + + return kern_size; +} + +static int load_initrd(struct linux_header *hdr, struct sys_info *info, + uint32_t kern_end, struct linux_params *params, const char *initrd_file) +{ + uint32_t max; + uint32_t start, end, size; + uint64_t forced; + + fd = open_io(initrd_file); + if (fd == -1) { + printf("Can't open initrd: %s\n", initrd_file); + return -1; + } + +#if 0 + if (using_devsize) { + printf("Attempt to load up to end of device as initrd; " + "specify the image size\n"); + return -1; + } +#endif + + size = file_size(); + + + /* Find out the kernel's restriction on how high the initrd can be + * placed */ + if (hdr->protocol_version >= 0x203) + max = hdr->initrd_addr_max; + else + max = 0x38000000; /* Hardcoded value for older kernels */ + + /* FILO itself is at the top of RAM. (relocated) + * So, try putting initrd just below us. */ + end = virt_to_phys(_start); + if (end > max) + end = max; + + /* If "mem=" option is given, we have to put the initrd within + * the specified range. */ + if (forced_memsize) { + forced = forced_memsize; + if (forced > max) + forced = max; + /* If the "mem=" is lower, it's easy */ + if (forced <= end) + end = forced; + else { + /* Otherwise, see if we can put it above us */ + if (virt_to_phys(_end) + size <= forced) + end = forced; /* Ok */ + } + } + + start = end - size; + start &= ~0xfff; /* page align */ + end = start + size; + + debug("start=%#x end=%#x\n", start, end); + + if (start < kern_end) { + printf("Initrd is too big to fit in memory\n"); + return -1; + } + + printf("Loading initrd... "); + if (read_io(fd, phys_to_virt(start), size) != size) { + printf("Can't read initrd\n"); + return -1; + } + printf("ok\n"); + + params->initrd_start = start; + params->initrd_size = size; + + close_io(fd); + + return 0; +} + +static void hardware_setup(void) +{ + /* Disable nmi */ + outb(0x80, 0x70); + + /* Make sure any coprocessor is properly reset.. */ + outb(0, 0xf0); + outb(0, 0xf1); + + /* we're getting screwed again and again by this problem of the 8259. + * so we're going to leave this lying around for inclusion into + * crt0.S on an as-needed basis. + * + * well, that went ok, I hope. Now we have to reprogram the interrupts :-( + * we put them right after the intel-reserved hardware interrupts, at + * int 0x20-0x2F. There they won't mess up anything. Sadly IBM really + * messed this up with the original PC, and they haven't been able to + * rectify it afterwards. Thus the bios puts interrupts at 0x08-0x0f, + * which is used for the internal hardware interrupts as well. We just + * have to reprogram the 8259's, and it isn't fun. + */ + + outb(0x11, 0x20); /* initialization sequence to 8259A-1 */ + outb(0x11, 0xA0); /* and to 8259A-2 */ + + outb(0x20, 0x21); /* start of hardware int's (0x20) */ + outb(0x28, 0xA1); /* start of hardware int's 2 (0x28) */ + + outb(0x04, 0x21); /* 8259-1 is master */ + outb(0x02, 0xA1); /* 8259-2 is slave */ + + outb(0x01, 0x21); /* 8086 mode for both */ + outb(0x01, 0xA1); + + outb(0xFF, 0xA1); /* mask off all interrupts for now */ + outb(0xFB, 0x21); /* mask all irq's but irq2 which is cascaded */ +} + +/* Start Linux */ +static int start_linux(uint32_t kern_addr, struct linux_params *params) +{ + struct segment_desc *linux_gdt; + struct context *ctx; + //extern int cursor_x, cursor_y; + + ctx = init_context(phys_to_virt(STACK_LOC), 4096, 0); + + /* Linux expects GDT being in low memory */ + linux_gdt = phys_to_virt(GDT_LOC); + memset(linux_gdt, 0, 13*sizeof(struct segment_desc)); + /* Normal kernel code/data segments */ + linux_gdt[2] = gdt[FLAT_CODE]; + linux_gdt[3] = gdt[FLAT_DATA]; + /* 2.6 kernel uses 12 and 13, but head.S uses backward-compatible + * segments (2 and 3), so it SHOULD not be a problem. + * However, some distro kernels (eg. RH9) with backported threading + * patch use 12 and 13 also when booting... */ + linux_gdt[12] = gdt[FLAT_CODE]; + linux_gdt[13] = gdt[FLAT_DATA]; + ctx->gdt_base = GDT_LOC; + ctx->gdt_limit = 14*8-1; + ctx->cs = 0x10; + ctx->ds = 0x18; + ctx->es = 0x18; + ctx->fs = 0x18; + ctx->gs = 0x18; + ctx->ss = 0x18; + + /* Parameter location */ + ctx->esi = virt_to_phys(params); + + /* Entry point */ + ctx->eip = kern_addr; + + debug("eip=%#x\n", kern_addr); + printf("Jumping to entry point...\n"); + +#ifdef VGA_CONSOLE + /* Update VGA cursor position. + * This must be here because the printf changes the value! */ + params->orig_x = cursor_x; + params->orig_y = cursor_y; +#endif + + /* Go... */ + ctx = switch_to(ctx); + + /* It's impossible but... */ + printf("Returned with eax=%#x\n", ctx->eax); + + return ctx->eax; +} + +int linux_load(struct sys_info *info, const char *file, const char *cmdline) +{ + struct linux_header hdr; + struct linux_params *params; + uint32_t kern_addr, kern_size; + char *initrd_file = NULL; + + fd = open_io(file); + if (fd == -1) { + return -1; + } + + kern_addr = load_linux_header(&hdr); + if (kern_addr == 0) + return LOADER_NOT_SUPPORT; + + params = phys_to_virt(LINUX_PARAM_LOC); + init_linux_params(params, &hdr); + set_memory_size(params, info); + initrd_file = parse_command_line(cmdline, phys_to_virt(COMMAND_LINE_LOC)); + set_command_line_loc(params, &hdr); + + kern_size = load_linux_kernel(&hdr, kern_addr); + if (kern_size == 0) { + if (initrd_file) + free(initrd_file); + return -1; + } + + if (initrd_file) { + if (load_initrd(&hdr, info, kern_addr+kern_size, params, initrd_file) + != 0) { + free(initrd_file); + return -1; + } + free(initrd_file); + } + + hardware_setup(); + + start_linux(kern_addr, params); + return 0; +} diff --git a/qemu/roms/openbios/arch/x86/multiboot.c b/qemu/roms/openbios/arch/x86/multiboot.c new file mode 100644 index 000000000..6f6b23dce --- /dev/null +++ b/qemu/roms/openbios/arch/x86/multiboot.c @@ -0,0 +1,127 @@ +/* Support for Multiboot */ + +#include "config.h" +#include "asm/io.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +struct mbheader { + unsigned int magic, flags, checksum; +}; + +static const struct mbheader multiboot_header + __attribute__((section (".hdr"))) = +{ + MULTIBOOT_HEADER_MAGIC, + MULTIBOOT_HEADER_FLAGS, + -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) +}; + +/* Multiboot information structure, provided by loader to us */ + +struct multiboot_mmap { + unsigned entry_size; + unsigned base_lo, base_hi; + unsigned size_lo, size_hi; + unsigned type; +}; + +#define MULTIBOOT_MEM_VALID 0x01 +#define MULTIBOOT_BOOT_DEV_VALID 0x02 +#define MULTIBOOT_CMDLINE_VALID 0x04 +#define MULTIBOOT_MODS_VALID 0x08 +#define MULTIBOOT_AOUT_SYMS_VALID 0x10 +#define MULTIBOOT_ELF_SYMS_VALID 0x20 +#define MULTIBOOT_MMAP_VALID 0x40 + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + struct multiboot_info *mbinfo; + struct multiboot_mmap *mbmem; + unsigned mbcount, mbaddr; + int i; + struct memrange *mmap; + int mmap_count; + module_t *mod; + + if (info->boot_type != 0x2BADB002) + return; + + debug("Using Multiboot information at %#lx\n", info->boot_data); + + mbinfo = phys_to_virt(info->boot_data); + + if (mbinfo->mods_count != 1) { + printk("multiboot: no dictionary\n"); + return; + } + + mod = (module_t *) mbinfo->mods_addr; + info->dict_start=(unsigned long *)mod->mod_start; + info->dict_end=(unsigned long *)mod->mod_end; + debug("multiboot: dictionary at %p-%p\n", + info->dict_start, info->dict_end); + + if (mbinfo->flags & MULTIBOOT_MMAP_VALID) { + /* convert mmap records */ + mbmem = phys_to_virt(mbinfo->mmap_addr); + mbcount = mbinfo->mmap_length / (mbmem->entry_size + 4); + mmap = malloc(mbcount * sizeof(struct memrange)); + mmap_count = 0; + mbaddr = mbinfo->mmap_addr; + for (i = 0; i < mbcount; i++) { + mbmem = phys_to_virt(mbaddr); + debug("%08x%08x %08x%08x (%d)\n", + mbmem->base_hi, + mbmem->base_lo, + mbmem->size_hi, + mbmem->size_lo, + mbmem->type); + if (mbmem->type == 1) { /* Only normal RAM */ + mmap[mmap_count].base = mbmem->base_lo + + (((unsigned long long) mbmem->base_hi) << 32); + mmap[mmap_count].size = mbmem->size_lo + + (((unsigned long long) mbmem->size_hi) << 32); + mmap_count++; + } + mbaddr += mbmem->entry_size + 4; + if (mbaddr >= mbinfo->mmap_addr + mbinfo->mmap_length) + break; + } + /* simple sanity check - there should be at least 2 RAM segments + * (base 640k and extended) */ + if (mmap_count >= 2) + goto got_it; + + printk("Multiboot mmap is broken\n"); + free(mmap); + /* fall back to mem_lower/mem_upper */ + } + + if (mbinfo->flags & MULTIBOOT_MEM_VALID) { + /* use mem_lower and mem_upper */ + mmap_count = 2; + mmap = malloc(2 * sizeof(*mmap)); + mmap[0].base = 0; + mmap[0].size = mbinfo->mem_lower << 10; + mmap[1].base = 1 << 20; /* 1MB */ + mmap[1].size = mbinfo->mem_upper << 10; + goto got_it; + } + + printk("Can't get memory information from Multiboot\n"); + return; + +got_it: + info->memrange = mmap; + info->n_memranges = mmap_count; + + return; +} diff --git a/qemu/roms/openbios/arch/x86/multiboot.h b/qemu/roms/openbios/arch/x86/multiboot.h new file mode 100644 index 000000000..fd0fe9739 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/multiboot.h @@ -0,0 +1,96 @@ +/* multiboot.h + * tag: header for multiboot + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +/* magic number for multiboot header */ +#define MULTIBOOT_HEADER_MAGIC 0x1BADB002 + +/* flags for multiboot header */ +#define MULTIBOOT_HEADER_FLAGS 0x00010003 + +/* magic number passed by multiboot-compliant boot loader. */ +#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002 + +/* The size of our stack (8KB). */ +#define STACK_SIZE 0x2000 + +/* C symbol format. HAVE_ASM_USCORE is defined by configure. */ +#ifdef HAVE_ASM_USCORE +# define EXT_C(sym) _ ## sym +#else +# define EXT_C(sym) sym +#endif + +#ifndef ASM +/* We don't want these declarations in boot.S */ + +/* multiboot header */ +typedef struct multiboot_header { + unsigned long magic; + unsigned long flags; + unsigned long checksum; + unsigned long header_addr; + unsigned long load_addr; + unsigned long load_end_addr; + unsigned long bss_end_addr; + unsigned long entry_addr; +} multiboot_header_t; + +/* symbol table for a.out */ +typedef struct aout_symbol_table { + unsigned long tabsize; + unsigned long strsize; + unsigned long addr; + unsigned long reserved; +} aout_symbol_table_t; + +/* section header table for ELF */ +typedef struct elf_section_header_table { + unsigned long num; + unsigned long size; + unsigned long addr; + unsigned long shndx; +} elf_section_header_table_t; + +/* multiboot information */ +typedef struct multiboot_info { + unsigned long flags; + unsigned long mem_lower; + unsigned long mem_upper; + unsigned long boot_device; + unsigned long cmdline; + unsigned long mods_count; + unsigned long mods_addr; + union { + aout_symbol_table_t aout_sym; + elf_section_header_table_t elf_sec; + } u; + unsigned long mmap_length; + unsigned long mmap_addr; +} multiboot_info_t; + +/* module structure */ +typedef struct module { + unsigned long mod_start; + unsigned long mod_end; + unsigned long string; + unsigned long reserved; +} module_t; + +/* memory map. Be careful that the offset 0 is base_addr_low + but no size. */ +typedef struct memory_map { + unsigned long size; + unsigned long base_addr_low; + unsigned long base_addr_high; + unsigned long length_low; + unsigned long length_high; + unsigned long type; +} memory_map_t; + +#endif /* ! ASM */ diff --git a/qemu/roms/openbios/arch/x86/openbios.c b/qemu/roms/openbios/arch/x86/openbios.c new file mode 100644 index 000000000..6145436f4 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/openbios.c @@ -0,0 +1,134 @@ +/* tag: openbios forth environment, executable code + * + * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/openbios.h" +#include "libopenbios/bindings.h" +#include "libopenbios/console.h" +#include "asm/types.h" +#include "dict.h" +#include "kernel/kernel.h" +#include "kernel/stack.h" +#include "drivers/drivers.h" +#include "drivers/pci.h" +#include "libopenbios/sys_info.h" +#include "libopenbios/video.h" +#include "openbios.h" +#include "relocate.h" +#include "boot.h" + +void collect_sys_info(struct sys_info *info); + +#ifdef CONFIG_DRIVER_PCI +static const pci_arch_t default_pci_host = { + .name = "Intel,i440FX", + .vendor_id = PCI_VENDOR_ID_INTEL, + .device_id = PCI_DEVICE_ID_INTEL_82441, + .io_base = 0x1000, +}; +#endif + +static void init_memory(void) +{ + /* push start and end of available memory to the stack + * so that the forth word QUIT can initialize memory + * management. For now we use hardcoded memory between + * 0x10000 and 0x9ffff (576k). If we need more memory + * than that we have serious bloat. + */ + + PUSH(0x10000); + PUSH(0x9FFFF); +} + +static void +arch_init( void ) +{ + openbios_init(); + modules_init(); +#ifdef CONFIG_DRIVER_PCI + arch = &default_pci_host; + ob_pci_init(); +#endif +#ifdef CONFIG_DRIVER_IDE + setup_timers(); + ob_ide_init("/pci/isa", 0x1f0, 0x3f6, 0x170, 0x376); +#endif +#ifdef CONFIG_DRIVER_FLOPPY + ob_floppy_init("/isa", "floppy0", 0x3f0, 0); +#endif +#ifdef CONFIG_XBOX + setup_video(); + + /* Force video to 32-bit depth */ + VIDEO_DICT_VALUE(video.depth) = 32; + + init_video(); + node_methods_init(); +#endif + device_end(); + bind_func("platform-boot", boot ); + bind_func("(go)", go ); +} + +extern struct _console_ops arch_console_ops; + +int openbios(void) +{ +#ifdef CONFIG_DEBUG_CONSOLE + init_console(arch_console_ops); +#ifdef CONFIG_DEBUG_CONSOLE_SERIAL + uart_init(CONFIG_SERIAL_PORT, CONFIG_SERIAL_SPEED); +#endif + /* Clear the screen. */ + cls(); +#endif + + collect_sys_info(&sys_info); + + dict = (unsigned char *)sys_info.dict_start; + dicthead = (cell)sys_info.dict_end; + last = sys_info.dict_last; + dictlimit = sys_info.dict_limit; + + forth_init(); + + relocate(&sys_info); + +#ifdef CONFIG_DEBUG_CONSOLE_VGA + video_init(); +#endif +#ifdef CONFIG_DEBUG_BOOT + printk("forth started.\n"); + printk("initializing memory..."); +#endif + + init_memory(); + +#ifdef CONFIG_DEBUG_BOOT + printk("done\n"); +#endif + + PUSH_xt( bind_noname_func(arch_init) ); + fword("PREPOST-initializer"); + + PC = (ucell)findword("initialize-of"); + + if (!PC) { + printk("panic: no dictionary entry point.\n"); + return -1; + } +#ifdef CONFIG_DEBUG_DICTIONARY + printk("done (%d bytes).\n", dicthead); + printk("Jumping to dictionary...\n"); +#endif + + enterforth((xt_t)PC); + + return 0; +} diff --git a/qemu/roms/openbios/arch/x86/openbios.h b/qemu/roms/openbios/arch/x86/openbios.h new file mode 100644 index 000000000..a13082276 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/openbios.h @@ -0,0 +1,32 @@ +/* + * Creation Date: <2004/01/15 16:14:05 samuel> + * Time-stamp: <2004/01/15 16:14:05 samuel> + * + * <openbios.h> + * + * + * + * Copyright (C) 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#ifndef _H_OPENBIOS +#define _H_OPENBIOS + +int openbios(void); + +/* entry.S */ +void init_exceptions(void); + +/* console.c */ +extern void cls(void); +#ifdef CONFIG_DEBUG_CONSOLE +extern int uart_init(int port, unsigned long speed); +extern void video_init(void); +#endif + +#endif /* _H_OPENBIOS */ diff --git a/qemu/roms/openbios/arch/x86/plainboot.c b/qemu/roms/openbios/arch/x86/plainboot.c new file mode 100644 index 000000000..08dab2d12 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/plainboot.c @@ -0,0 +1,21 @@ +/* tag: openbios fixed address forth starter + * + * Copyright (C) 2003 Stefan Reinauer + * + * See the file "COPYING" for further information about + * the copyright and warranty status of this work. + */ + +#include "config.h" +#include "libopenbios/sys_info.h" +#include "multiboot.h" + +#define FIXED_DICTSTART 0xfffe0000 +#define FIXED_DICTEND 0xfffeffff + +void collect_multiboot_info(struct sys_info *info); +void collect_multiboot_info(struct sys_info *info) +{ + info->dict_start=(unsigned long *)FIXED_DICTSTART; + info->dict_end=(unsigned long *)FIXED_DICTEND; +} diff --git a/qemu/roms/openbios/arch/x86/relocate.h b/qemu/roms/openbios/arch/x86/relocate.h new file mode 100644 index 000000000..d91160a03 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/relocate.h @@ -0,0 +1 @@ +void relocate(struct sys_info *); diff --git a/qemu/roms/openbios/arch/x86/segment.c b/qemu/roms/openbios/arch/x86/segment.c new file mode 100644 index 000000000..5146cd302 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/segment.c @@ -0,0 +1,133 @@ +/* Segmentation of the i386 architecture. + * + * 2003-07 by SONE Takeshi + */ + +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/sys_info.h" +#include "relocate.h" +#include "segment.h" + +#define printf printk +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +/* i386 lgdt argument */ +struct gdtarg { + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +/* How far the virtual address (used in C) is different from physical + * address. Since we start in flat mode, the initial value is zero. */ +unsigned long virt_offset = 0; + +/* GDT, the global descriptor table */ +struct segment_desc gdt[NUM_SEG] = { + /* 0x00: null segment */ + {0, 0, 0, 0, 0, 0}, + /* 0x08: flat code segment */ + {0xffff, 0, 0, 0x9f, 0xcf, 0}, + /* 0x10: flat data segment */ + {0xffff, 0, 0, 0x93, 0xcf, 0}, + /* 0x18: code segment for relocated execution */ + {0xffff, 0, 0, 0x9f, 0xcf, 0}, + /* 0x20: data segment for relocated execution */ + {0xffff, 0, 0, 0x93, 0xcf, 0}, +}; + + +void relocate(struct sys_info *info) +{ + int i; + unsigned long prog_addr; + unsigned long prog_size; + unsigned long addr, new_base; + unsigned long long segsize; + unsigned long new_offset; + unsigned d0, d1, d2; + struct gdtarg gdtarg; +#define ALIGNMENT 16 + + prog_addr = virt_to_phys(&_start); + prog_size = virt_to_phys(&_end) - virt_to_phys(&_start); + debug("Current location: %#lx-%#lx\n", prog_addr, prog_addr+prog_size-1); + + new_base = 0; + for (i = 0; i < info->n_memranges; i++) { + if (info->memrange[i].base >= 1ULL<<32) + continue; + segsize = info->memrange[i].size; + if (info->memrange[i].base + segsize > 1ULL<<32) + segsize = (1ULL<<32) - info->memrange[i].base; + if (segsize < prog_size+ALIGNMENT) + continue; + addr = info->memrange[i].base + segsize - prog_size; + addr &= ~(ALIGNMENT-1); + if (addr >= prog_addr && addr < prog_addr + prog_size) + continue; + if (prog_addr >= addr && prog_addr < addr + prog_size) + continue; + if (addr > new_base) + new_base = addr; + } + if (new_base == 0) { + printf("Can't find address to relocate\n"); + return; + } + + debug("Relocating to %#lx-%#lx... ", + new_base, new_base + prog_size - 1); + + /* New virtual address offset */ + new_offset = new_base - (unsigned long) &_start; + + /* Tweak the GDT */ + gdt[RELOC_CODE].base_0 = (unsigned short) new_offset; + gdt[RELOC_CODE].base_16 = (unsigned char) (new_offset>>16); + gdt[RELOC_CODE].base_24 = (unsigned char) (new_offset>>24); + gdt[RELOC_DATA].base_0 = (unsigned short) new_offset; + gdt[RELOC_DATA].base_16 = (unsigned char) (new_offset>>16); + gdt[RELOC_DATA].base_24 = (unsigned char) (new_offset>>24); + + /* Load new GDT and reload segments */ + gdtarg.base = new_offset + (unsigned long) gdt; + gdtarg.limit = GDT_LIMIT; + __asm__ __volatile__ ( + "rep; movsb\n\t" /* copy everything */ + "lgdt %3\n\t" + "ljmp %4, $1f\n1:\t" + "movw %5, %%ds\n\t" + "movw %5, %%es\n\t" + "movw %5, %%fs\n\t" + "movw %5, %%gs\n\t" + "movw %5, %%ss\n" + : "=&S" (d0), "=&D" (d1), "=&c" (d2) + : "m" (gdtarg), "n" (RELOC_CS), "q" ((unsigned short) RELOC_DS), + "0" (&_start), "1" (new_base), "2" (prog_size)); + + virt_offset = new_offset; + debug("ok\n"); +} + +#if 0 +/* Copy GDT to new location and reload it */ +void move_gdt(unsigned long newgdt) +{ + struct gdtarg gdtarg; + + debug("Moving GDT to %#lx...", newgdt); + memcpy(phys_to_virt(newgdt), gdt, sizeof gdt); + gdtarg.base = newgdt; + gdtarg.limit = GDT_LIMIT; + debug("reloading GDT..."); + __asm__ __volatile__ ("lgdt %0\n\t" : : "m" (gdtarg)); + debug("reloading CS for fun..."); + __asm__ __volatile__ ("ljmp %0, $1f\n1:" : : "n" (RELOC_CS)); + debug("ok\n"); +} +#endif diff --git a/qemu/roms/openbios/arch/x86/segment.h b/qemu/roms/openbios/arch/x86/segment.h new file mode 100644 index 000000000..0371a80ae --- /dev/null +++ b/qemu/roms/openbios/arch/x86/segment.h @@ -0,0 +1,30 @@ + +/* Segment indexes. Must match the gdt definition in segment.c. */ +enum { + NULL_SEG, + FLAT_CODE, + FLAT_DATA, + RELOC_CODE, + RELOC_DATA, + NUM_SEG, +}; + +/* Values for segment selector register */ +#define FLAT_CS (FLAT_CODE << 3) +#define FLAT_DS (FLAT_DATA << 3) +#define RELOC_CS (RELOC_CODE << 3) +#define RELOC_DS (RELOC_DATA << 3) + +/* i386 segment descriptor */ +struct segment_desc { + unsigned short limit_0; + unsigned short base_0; + unsigned char base_16; + unsigned char types; + unsigned char flags; + unsigned char base_24; +}; + +extern struct segment_desc gdt[NUM_SEG]; + +#define GDT_LIMIT ((NUM_SEG << 3) - 1) diff --git a/qemu/roms/openbios/arch/x86/sys_info.c b/qemu/roms/openbios/arch/x86/sys_info.c new file mode 100644 index 000000000..9361c9d63 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/sys_info.c @@ -0,0 +1,57 @@ +#include "config.h" +#include "kernel/kernel.h" +#include "libopenbios/sys_info.h" +#include "context.h" + +#ifdef CONFIG_DEBUG_BOOT +#define debug printk +#else +#define debug(x...) +#endif + +void collect_multiboot_info(struct sys_info *); +void collect_sys_info(struct sys_info *info); + +void collect_sys_info(struct sys_info *info) +{ + int i; + unsigned long long total = 0; + struct memrange *mmap; + + /* Pick up paramters given by bootloader to us */ + info->boot_type = boot_ctx->eax; + info->boot_data = boot_ctx->ebx; + info->boot_arg = boot_ctx->param[0]; + debug("boot eax = %#lx\n", info->boot_type); + debug("boot ebx = %#lx\n", info->boot_data); + debug("boot arg = %#lx\n", info->boot_arg); + + collect_elfboot_info(info); +#ifdef CONFIG_LINUXBIOS + collect_linuxbios_info(info); +#endif +#ifdef CONFIG_IMAGE_ELF_MULTIBOOT + collect_multiboot_info(info); +#endif + + if (!info->memrange) { + printk("Can't get memory map from firmware. " + "Using hardcoded default.\n"); + info->n_memranges = 2; + info->memrange = malloc(2 * sizeof(struct memrange)); + info->memrange[0].base = 0; + info->memrange[0].size = 640*1024; + info->memrange[1].base = 1024*1024; + info->memrange[1].size = 32*1024*1024 + - info->memrange[1].base; + } + + debug("\n"); + mmap=info->memrange; + for (i = 0; i < info->n_memranges; i++) { + debug("%016Lx-", mmap[i].base); + debug("%016Lx\n", mmap[i].base+mmap[i].size); + total += mmap[i].size; + } + debug("RAM %Ld MB\n", (total + 512*1024) >> 20); +} diff --git a/qemu/roms/openbios/arch/x86/xbox/console.c b/qemu/roms/openbios/arch/x86/xbox/console.c new file mode 100644 index 000000000..e96e04f07 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/xbox/console.c @@ -0,0 +1,23 @@ +/* + * Xbox framebuffer - Video + Console + * + * Copyright (C) 2005 Ed Schouten <ed@fxq.nl>, + * Stefan Reinauer <stepan@openbios.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation + */ + + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/diskio.h" + +typedef struct osi_fb_info { + unsigned long mphys; + int rb, w, h, depth; +} osi_fb_info_t; + +#include "../../../packages/video.c" +#include "../../../libopenbios/console_common.c" diff --git a/qemu/roms/openbios/arch/x86/xbox/methods.c b/qemu/roms/openbios/arch/x86/xbox/methods.c new file mode 100644 index 000000000..741d15c08 --- /dev/null +++ b/qemu/roms/openbios/arch/x86/xbox/methods.c @@ -0,0 +1,102 @@ +/* + * Creation Date: <2004/08/28 18:38:22 greg> + * Time-stamp: <2004/08/28 18:38:22 greg> + * + * <methods.c> + * + * Misc device node methods + * + * Copyright (C) 2004 Greg Watson + * + * Based on MOL specific code which is + * + * Copyright (C) 2003, 2004 Samuel Rydh (samuel@ibrium.se) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 + * + */ + +#include "config.h" +#include "libopenbios/bindings.h" +#include "libc/string.h" +// #include "libopenbios/ofmem.h" + +/************************************************************************/ +/* stdout */ +/************************************************************************/ + +DECLARE_NODE( video_stdout, INSTALL_OPEN, 0, "Tdisplay" ); + +/* ( addr len -- actual ) */ +static void +stdout_write( void ) +{ + int len = POP(); + char *addr = (char*)POP(); + + printk( "%s", s ); + //vfd_draw_str( s ); + console_draw_fstr(addr, len); + + PUSH( len ); +} + +NODE_METHODS( video_stdout ) = { + { "write", stdout_write }, +}; + + +/************************************************************************/ +/* tty */ +/************************************************************************/ + +DECLARE_NODE( tty, INSTALL_OPEN, 0, "/packages/terminal-emulator" ); + +/* ( addr len -- actual ) */ +static void +tty_read( void ) +{ + int ch, len = POP(); + char *p = (char*)POP(); + int ret=0; + + if( len > 0 ) { + ret = 1; + ch = getchar(); + if( ch >= 0 ) { + *p = ch; + } else { + ret = 0; + } + } + PUSH( ret ); +} + +/* ( addr len -- actual ) */ +static void +tty_write( void ) +{ + int i, len = POP(); + char *p = (char*)POP(); + for( i=0; i<len; i++ ) + putchar( *p++ ); + RET( len ); +} + +NODE_METHODS( tty ) = { + { "read", tty_read }, + { "write", tty_write }, +}; + +/************************************************************************/ +/* init */ +/************************************************************************/ + +void +node_methods_init( void ) +{ + REGISTER_NODE( video_stdout ); + REGISTER_NODE( tty ); +} |