diff --git a/arch/microblaze/arch.c b/arch/microblaze/arch.c index e69de29b..1b0ba91e 100644 --- a/arch/microblaze/arch.c +++ b/arch/microblaze/arch.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include + +void arch_early_init(void) +{ + TRACE; +} + +void arch_init(void) +{ + TRACE; +} + +void arch_idle(void) +{ +} + diff --git a/arch/microblaze/asm.S b/arch/microblaze/asm.S index e69de29b..1ba867f6 100644 --- a/arch/microblaze/asm.S +++ b/arch/microblaze/asm.S @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include + +/* void microblaze_context_switch( + struct microblaze_context_switch_frame *oldcs, + struct microblaze_context_switch_frame *newcs); */ +FUNCTION(microblaze_context_switch) + # r5 = oldcs + # r6 = newcs + swi r1, r5, 0x0 + swi r2, r5, 0x4 + swi r13, r5, 0x8 + swi r14, r5, 0xc + swi r15, r5, 0x10 + swi r16, r5, 0x14 + swi r17, r5, 0x18 + swi r18, r5, 0x1c + swi r19, r5, 0x20 + swi r20, r5, 0x24 + swi r21, r5, 0x28 + swi r22, r5, 0x2c + swi r23, r5, 0x30 + swi r24, r5, 0x34 + swi r25, r5, 0x38 + swi r26, r5, 0x3c + swi r27, r5, 0x40 + swi r28, r5, 0x44 + swi r29, r5, 0x48 + swi r30, r5, 0x4c + mfs r11, rmsr + swi r11, r5, 0x50 + mfs r11, rear + swi r11, r5, 0x54 + mfs r11, resr + swi r11, r5, 0x58 + mfs r11, rfsr + swi r11, r5, 0x5c + + # restore the new context + lwi r11, r6, 0x5c + mts rfsr, r11 + lwi r11, r6, 0x58 + mts resr, r11 + lwi r11, r6, 0x54 + mts rear, r11 + lwi r11, r6, 0x50 + mts rmsr, r11 + lwi r30, r6, 0x4c + lwi r29, r6, 0x48 + lwi r28, r6, 0x44 + lwi r27, r6, 0x40 + lwi r26, r6, 0x3c + lwi r25, r6, 0x38 + lwi r24, r6, 0x34 + lwi r23, r6, 0x30 + lwi r22, r6, 0x2c + lwi r21, r6, 0x28 + lwi r20, r6, 0x24 + lwi r19, r6, 0x20 + lwi r18, r6, 0x1c + lwi r17, r6, 0x18 + lwi r16, r6, 0x14 + lwi r15, r6, 0x10 + lwi r14, r6, 0xc + lwi r13, r6, 0x8 + lwi r2, r6, 0x4 + lwi r1, r6, 0x0 + + rtsd r15, 8 + nop + diff --git a/arch/microblaze/exceptions.c b/arch/microblaze/exceptions.c new file mode 100644 index 00000000..7795dd8d --- /dev/null +++ b/arch/microblaze/exceptions.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include + +void microblaze_irq(void) __attribute__((interrupt_handler)); + +void microblaze_irq(void) +{ + + +} + diff --git a/arch/microblaze/include/arch/arch_ops.h b/arch/microblaze/include/arch/arch_ops.h index 33d94fe0..c674c108 100644 --- a/arch/microblaze/include/arch/arch_ops.h +++ b/arch/microblaze/include/arch/arch_ops.h @@ -36,4 +36,17 @@ static inline void arch_disable_ints(void) CF; } +/* use a global pointer to store the current_thread */ +extern struct thread *_current_thread; + +static inline struct thread *get_current_thread(void) +{ + return _current_thread; +} + +static inline void set_current_thread(struct thread *t) +{ + _current_thread = t; +} + diff --git a/arch/microblaze/include/arch/arch_thread.h b/arch/microblaze/include/arch/arch_thread.h index 559b4f63..60a285d7 100644 --- a/arch/microblaze/include/arch/arch_thread.h +++ b/arch/microblaze/include/arch/arch_thread.h @@ -24,7 +24,43 @@ #include -struct arch_thread { - vaddr_t sp; +struct microblaze_context_switch_frame { + uint32_t r1; // stack pointer + uint32_t r2; // read-only small data base pointer + + uint32_t r13; // read-write small data base pointer + uint32_t r14; + uint32_t r15; // link register + uint32_t r16; + uint32_t r17; + uint32_t r18; + + /* callee saved */ + uint32_t r19; + uint32_t r20; + uint32_t r21; + uint32_t r22; + uint32_t r23; + uint32_t r24; + uint32_t r25; + uint32_t r26; + uint32_t r27; + uint32_t r28; + uint32_t r29; + uint32_t r30; + uint32_t r31; + + /* special purpose */ + uint32_t msr; + uint32_t ear; + uint32_t esr; + uint32_t fsr; }; +struct arch_thread { + struct microblaze_context_switch_frame cs_frame; +}; + +void microblaze_context_switch(struct microblaze_context_switch_frame *oldcs, + struct microblaze_context_switch_frame *newcs); + diff --git a/arch/microblaze/include/arch/microblaze.h b/arch/microblaze/include/arch/microblaze.h new file mode 100644 index 00000000..a23b4988 --- /dev/null +++ b/arch/microblaze/include/arch/microblaze.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + + + diff --git a/arch/microblaze/linker.ld b/arch/microblaze/linker.ld index fd1399e3..e437aee0 100644 --- a/arch/microblaze/linker.ld +++ b/arch/microblaze/linker.ld @@ -4,97 +4,111 @@ OUTPUT_ARCH(microblaze) ENTRY(_start) SECTIONS { - . = 0; /* %KERNEL_BASE% + %KERNEL_LOAD_OFFSET%; */ + . = %KERNEL_BASE% + %KERNEL_LOAD_OFFSET%; - _start = .; + _start = .; - /* text/read-only data */ - /* set the load address to physical MEMBASE */ - /* .text : AT(%MEMBASE% + %KERNEL_LOAD_OFFSET%) { */ - .text : { - KEEP(*(.text.boot.vectab)) - KEEP(*(.text.boot)) - *(.text* .sram.text.glue_7* .gnu.linkonce.t.*) - } + /* text/read-only data */ + /* set the load address to physical MEMBASE */ + .text : AT(%MEMBASE% + %KERNEL_LOAD_OFFSET%) { + KEEP(*(.vectors)) + KEEP(*(.text.boot)) + *(.text* .gnu.linkonce.t.*) + } - .interp : { *(.interp) } - .hash : { *(.hash) } - .dynsym : { *(.dynsym) } - .dynstr : { *(.dynstr) } - .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } - .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } - .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } - .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } - .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } - .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } - .rel.got : { *(.rel.got) } - .rela.got : { *(.rela.got) } - .rel.ctors : { *(.rel.ctors) } - .rela.ctors : { *(.rela.ctors) } - .rel.dtors : { *(.rel.dtors) } - .rela.dtors : { *(.rela.dtors) } - .rel.init : { *(.rel.init) } - .rela.init : { *(.rela.init) } - .rel.fini : { *(.rel.fini) } - .rela.fini : { *(.rela.fini) } - .rel.bss : { *(.rel.bss) } - .rela.bss : { *(.rela.bss) } - .rel.plt : { *(.rel.plt) } - .rela.plt : { *(.rela.plt) } - .init : { *(.init) } =0x9090 - .plt : { *(.plt) } + .interp : { *(.interp) } + .hash : { *(.hash) } + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .rel.text : { *(.rel.text) *(.rel.gnu.linkonce.t*) } + .rela.text : { *(.rela.text) *(.rela.gnu.linkonce.t*) } + .rel.data : { *(.rel.data) *(.rel.gnu.linkonce.d*) } + .rela.data : { *(.rela.data) *(.rela.gnu.linkonce.d*) } + .rel.rodata : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) } + .rela.rodata : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) } + .rel.got : { *(.rel.got) } + .rela.got : { *(.rela.got) } + .rel.ctors : { *(.rel.ctors) } + .rela.ctors : { *(.rela.ctors) } + .rel.dtors : { *(.rel.dtors) } + .rela.dtors : { *(.rela.dtors) } + .rel.init : { *(.rel.init) } + .rela.init : { *(.rela.init) } + .rel.fini : { *(.rel.fini) } + .rela.fini : { *(.rela.fini) } + .rel.bss : { *(.rel.bss) } + .rela.bss : { *(.rela.bss) } + .rel.plt : { *(.rel.plt) } + .rela.plt : { *(.rela.plt) } + .init : { *(.init) } + .plt : { *(.plt) } - .rodata : ALIGN(4) { - __rodata_start = .; - *(.rodata .rodata.* .gnu.linkonce.r.*) + .rodata : ALIGN(4) { + __rodata_start = .; + *(.rodata .rodata.* .gnu.linkonce.r.*) INCLUDE "arch/shared_rodata_sections.ld" - . = ALIGN(4); - __rodata_end = .; - } + . = ALIGN(4); + _SDATA2_START__ = .; + *(.sdata2) + _SDATA2_END__ = .; + __rodata_end = .; + } - .data : ALIGN(4) { - /* writable data */ - __data_start_rom = .; - /* in one segment binaries, the rom data address is on top of the ram data address */ - __data_start = .; - *(.data .data.* .gnu.linkonce.d.*) + .data : ALIGN(4) { + /* writable data */ + __data_start_rom = .; + /* in one segment binaries, the rom data address is on top of the ram data address */ + __data_start = .; + *(.data .data.* .gnu.linkonce.d.*) INCLUDE "arch/shared_data_sections.ld" - } + __ctor_list = .; + KEEP(*(.ctors .init_array)) + __ctor_end = .; + __dtor_list = .; + KEEP(*(.dtors .fini_array)) + __dtor_end = .; + *(.got*) + *(.dynamic) - .ctors : ALIGN(4) { - __ctor_list = .; - KEEP(*(.ctors .init_array)) - __ctor_end = .; - } - .dtors : ALIGN(4) { - __dtor_list = .; - KEEP(*(.dtors .fini_array)) - __dtor_end = .; - } - .got : { *(.got.plt) *(.got) } - .dynamic : { *(.dynamic) } + /* read-write small data with initial value */ + _SDATA_START__ = .; + *(.sdata) + _SDATA_END__ = .; - __data_end = .; + __data_end = .; + } - /* unintialized data (in same segment as writable data) */ - .bss : ALIGN(4) { - KEEP(*(.bss.prebss.*)) - . = ALIGN(4); - __bss_start = .; - *(.bss .bss.*) - *(.gnu.linkonce.b.*) - *(COMMON) - . = ALIGN(4); - __bss_end = .; - } - _end = .; + /* unintialized data (in same segment as writable data) */ + .bss : ALIGN(4) { + __bss_start = .; - /* . = %KERNEL_BASE% + %MEMSIZE%; */ - _end_of_ram = .; + /* read only small variables without initial value */ + _SBSS2_START__ = .; + *(.sbss2*) + _SBSS2_END__ = .; - /* Strip unnecessary stuff */ - /DISCARD/ : { *(.comment .note .eh_frame) } + /* read-write small variables without initial value */ + _sbss_start__ = .; + *(.sbss*) + _sbss_end__ = .; + + /* regular bss */ + *(.bss .bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + + . = ALIGN(4); + __bss_end = .; + } + + _end = .; + + . = %KERNEL_BASE% + %MEMSIZE%; + _end_of_ram = .; + + /* Strip unnecessary stuff */ + /DISCARD/ : { *(.comment .note .eh_frame) } } diff --git a/arch/microblaze/rules.mk b/arch/microblaze/rules.mk index abb2b204..6a890ed1 100644 --- a/arch/microblaze/rules.mk +++ b/arch/microblaze/rules.mk @@ -9,11 +9,12 @@ MODULE_SRCS += \ $(LOCAL_DIR)/start.S \ $(LOCAL_DIR)/arch.c \ $(LOCAL_DIR)/asm.S \ + $(LOCAL_DIR)/exceptions.c \ + $(LOCAL_DIR)/thread.c \ # $(LOCAL_DIR)/cache.c \ $(LOCAL_DIR)/cache-ops.S \ $(LOCAL_DIR)/ops.S \ - $(LOCAL_DIR)/thread.c \ $(LOCAL_DIR)/mmu.c \ $(LOCAL_DIR)/faults.c \ $(LOCAL_DIR)/descriptor.c @@ -31,6 +32,11 @@ cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc /dev/null 2>&1`"; ARCH_OPTFLAGS := -O2 +GLOBAL_LDFLAGS += -relax + +KERNEL_BASE ?= 0 +KERNEL_LOAD_OFFSET ?= 0 + # potentially generated files that should be cleaned out with clean make rule GENERATED += \ $(BUILDDIR)/linker.ld @@ -39,7 +45,7 @@ GENERATED += \ $(BUILDDIR)/linker.ld: $(LOCAL_DIR)/linker.ld $(wildcard arch/*.ld) @echo generating $@ @$(MKDIR) - $(NOECHO)cp $< $@ + $(NOECHO)sed "s/%MEMBASE%/$(MEMBASE)/;s/%MEMSIZE%/$(MEMSIZE)/;s/%KERNEL_BASE%/$(KERNEL_BASE)/;s/%KERNEL_LOAD_OFFSET%/$(KERNEL_LOAD_OFFSET)/" < $< > $@ LINKER_SCRIPT += $(BUILDDIR)/linker.ld diff --git a/arch/microblaze/start.S b/arch/microblaze/start.S index e69de29b..c31f09fc 100644 --- a/arch/microblaze/start.S +++ b/arch/microblaze/start.S @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include + +.section ".vectors" +.globl _start +_start: +/* vector table here */ + # start vector + bri start + # user exception + bri unhandled_exception + # interrupt + bri microblaze_irq + # break + bri unhandled_exception + # hardware exception + bri unhandled_exception + + # reserved for future +.fill (0x50 - 0x28) + +.section ".text.boot" +start: + # set the default stack + addik r1, r0, default_stack_top + + # set up small data pointers + addik r2, r0, _SDATA2_START__ + addik r13, r0, _SDATA_START__ + + # TODO: make sure irqs are disabled and any other cpu specific setup + + # zero out bss sections + addik r5, r0, __bss_start + addik r6, r0, 0 + brlid r15, memset + rsubik r7, r5, __bss_end + + # arguments to main + addik r5, r0, 1 + addik r6, r0, 2 + addik r7, r0, 3 + brlid r15, lk_main + addik r8, r0, 4 + + # shouldn't be here + bri . + +unhandled_exception: + bri . + +.bss +.align 3 +LOCAL_DATA(default_stack) + .skip 4096 +LOCAL_DATA(default_stack_top) + +/* vim: set ts=4 sw=4 expandtab: */ + diff --git a/arch/microblaze/thread.c b/arch/microblaze/thread.c new file mode 100644 index 00000000..979be52b --- /dev/null +++ b/arch/microblaze/thread.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include + +#define LOCAL_TRACE 0 + +struct thread *_current_thread; + +static void initial_thread_func(void) __NO_RETURN; +static void initial_thread_func(void) +{ + thread_t *ct = get_current_thread(); + +#if LOCAL_TRACE + LTRACEF("thread %p calling %p with arg %p\n", ct, ct->entry, ct->arg); + dump_thread(ct); +#endif + + /* exit the implicit critical section we're within */ + exit_critical_section(); + + int ret = ct->entry(ct->arg); + + LTRACEF("thread %p exiting with %d\n", ct, ret); + + thread_exit(ret); +} + +void arch_thread_initialize(thread_t *t) +{ + LTRACEF("t %p (%s)\n", t, t->name); + + /* some registers we want to clone for the new thread */ + register uint32_t r2 asm("r2"); + register uint32_t r13 asm("r13"); + register uint32_t r14 asm("r14"); + register uint32_t r16 asm("r16"); + register uint32_t r17 asm("r17"); + + /* zero out the thread context */ + memset(&t->arch.cs_frame, 0, sizeof(t->arch.cs_frame)); + + t->arch.cs_frame.r1 = (vaddr_t)t->stack + t->stack_size; + t->arch.cs_frame.r2 = r2; + t->arch.cs_frame.r13 = r13; + t->arch.cs_frame.r14 = r14; + t->arch.cs_frame.r15 = (vaddr_t)initial_thread_func - 8; // rtsd in context switch expects this + t->arch.cs_frame.r16 = r16; + t->arch.cs_frame.r17 = r17; +} + +void arch_context_switch(thread_t *oldthread, thread_t *newthread) +{ + LTRACEF("old %p (%s), new %p (%s)\n", oldthread, oldthread->name, newthread, newthread->name); + + microblaze_context_switch(&oldthread->arch.cs_frame, &newthread->arch.cs_frame); +} + diff --git a/platform/microblaze/platform.c b/platform/microblaze/platform.c index e69de29b..3b5f97ae 100644 --- a/platform/microblaze/platform.c +++ b/platform/microblaze/platform.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include +#include +#include +#include +#include +#include +#include + +lk_bigtime_t current_time_hires(void) +{ + return 0; +} + +lk_time_t current_time(void) +{ + return 0; +} + +status_t platform_set_periodic_timer(platform_timer_callback callback, void *arg, lk_time_t interval) +{ + return 0; +} + +static void _dputc(char c) +{ + *REG32(UARTLITE_BASEADDR + 0x4) = c; +} + +void platform_dputc(char c) +{ + if (c == '\n') + _dputc('\r'); + _dputc(c); +} + +int platform_dgetc(char *c, bool wait) +{ +#if 0 + int ret = uart_getc(DEBUG_UART, wait); + if (ret == -1) + return -1; + *c = ret; + return 0; +#endif + return -1; + +} + + diff --git a/platform/microblaze/rules.mk b/platform/microblaze/rules.mk index 33d538ea..64f07814 100644 --- a/platform/microblaze/rules.mk +++ b/platform/microblaze/rules.mk @@ -3,7 +3,6 @@ LOCAL_DIR := $(GET_LOCAL_DIR) MODULE := $(LOCAL_DIR) ARCH := microblaze -#ARM_CPU := cortex-a9-neon GLOBAL_INCLUDES += \ $(LOCAL_DIR)/include @@ -12,7 +11,7 @@ MODULE_SRCS += \ $(LOCAL_DIR)/platform.c MEMBASE := 0x0 -MEMSIZE := 0x20000000 # 512MB +MEMSIZE := 0x08000000 # 128MB MODULE_DEPS += \ diff --git a/project/qemu-microblaze.mk b/project/qemu-microblaze.mk index f615ada8..06d07761 100644 --- a/project/qemu-microblaze.mk +++ b/project/qemu-microblaze.mk @@ -1,3 +1,4 @@ TARGET := qemu-microblaze MODULES += \ + app/shell \ diff --git a/scripts/do-qemumicroblaze b/scripts/do-qemumicroblaze new file mode 100755 index 00000000..45d49c80 --- /dev/null +++ b/scripts/do-qemumicroblaze @@ -0,0 +1,4 @@ +#!/bin/sh + +make qemu-microblaze -j4 && +qemu-system-microblaze -kernel build-qemu-microblaze/lk.elf -nographic $@ diff --git a/target/qemu-microblaze/include/target/qemu-microblaze.h b/target/qemu-microblaze/include/target/qemu-microblaze.h new file mode 100644 index 00000000..637588e0 --- /dev/null +++ b/target/qemu-microblaze/include/target/qemu-microblaze.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +/* qemu emulates a petalogix s3adsp1800 */ +#define LMB_BRAM_SIZE (128 * 1024) +#define FLASH_SIZE (16 * 1024 * 1024) + +#define ETHLITE_BASEADDR 0x81000000 +#define INTC_BASEADDR 0x81800000 +#define TIMER_BASEADDR 0x83c00000 +#define UARTLITE_BASEADDR 0x84000000 +#define MEMORY_BASEADDR 0x90000000 +#define FLASH_BASEADDR 0xa0000000 + +#define TIMER_IRQ 0 +#define ETHLITE_IRQ 1 +#define UARTLITE_IRQ 3