diff --git a/arch/vax/arch.c b/arch/vax/arch.c index 11c48fde..e08ce3ac 100644 --- a/arch/vax/arch.c +++ b/arch/vax/arch.c @@ -14,6 +14,8 @@ #define LOCAL_TRACE 0 +extern uint8_t irq_stack[1024]; + void arch_early_init(void) { // set the top level exception handler //riscv_csr_write(mtvec, (uintptr_t)&riscv_exception_entry); @@ -38,8 +40,6 @@ void arch_init(void) { } void arch_idle(void) { - // disabled for now, QEMU seems to have some trouble emulating wfi properly - // also have trouble breaking into sifive-e board with openocd when wfi // __asm__ volatile("wfi"); } diff --git a/arch/vax/include/arch/vax.h b/arch/vax/include/arch/vax.h index dc1c7a88..db1f9908 100644 --- a/arch/vax/include/arch/vax.h +++ b/arch/vax/include/arch/vax.h @@ -5,4 +5,6 @@ * license that can be found in the LICENSE file or at * https://opensource.org/licenses/MIT */ +#pragma once + #include diff --git a/arch/vax/start.S b/arch/vax/start.S index 29c9c77e..851b35e7 100644 --- a/arch/vax/start.S +++ b/arch/vax/start.S @@ -37,18 +37,21 @@ _start: sobgtr %r2,1b // branch to our new spot + // TODO: use a REI to make sure the cpu dumps the pipeline movl $relocated, %r0 jmp (%r0) relocated: // set the stack to the end of us - moval stack_end,%sp + moval irq_stack_end,%sp // branch into main and we're done calls $0, lk_main halt .section .data +// declare bootargs here to make sure it goes in the data segment, since it's +// saved before the bss is zeroed out. .align 4 .globl bootargs bootargs: @@ -57,6 +60,6 @@ bootargs_end: .section .bss .align 4 -stack: +irq_stack: .skip 1024 -stack_end: +irq_stack_end: diff --git a/platform/vax/console.c b/platform/vax/console.c index c93ee5c5..abe5698b 100644 --- a/platform/vax/console.c +++ b/platform/vax/console.c @@ -9,12 +9,24 @@ #include #include -// todo: move to .S file -unsigned int rom_putchar_addr = 0x20040068; -extern int rom_putchar(int c); +#include "platform_p.h" + +// Console io via rom routine +unsigned int rom_putchar_addr; +extern void rom_putchar(int c); + +// PR version +void putchar_mtfr(int c) { + // wait until ready + while ((mfpr(PR_TXCS) & 0x80) == 0) + ; + + // output char + mtpr((char)c, PR_TXDB); +} // select the above routine -int (*putchar_func)(int c) = &rom_putchar; +void (*putchar_func)(int c); void platform_dputc(char c) { if (c == '\n') @@ -35,5 +47,19 @@ int platform_pgetc(char *c, bool wait) { return platform_dgetc(c, wait); } +void platform_early_console_init(void) { + // TODO: decide what type of console to use based on vax machine + + // Only understand a few at the moment + switch (vax_boardtype) { + case 0x14000004: // Microvax 3100/40 + rom_putchar_addr = 0x20040068; + putchar_func = &rom_putchar; + break; + default: + // default is to use the pr routines + putchar_func = &putchar_mtfr; + } +} diff --git a/platform/vax/init.c b/platform/vax/init.c index 3685da6d..4f8c7bc6 100644 --- a/platform/vax/init.c +++ b/platform/vax/init.c @@ -8,6 +8,39 @@ #include #include #include +#include + +#include "platform_p.h" + +uint32_t vax_cputype; +uint32_t vax_boardtype; + +void platform_early_init(void) { + // decode what kind of vax we are so we can make a few platform decisions + // generally follows logic in netbsd sys/arch/vax/... + uint32_t sid = mfpr(PR_SID); + vax_cputype = sid >> 24; + vax_boardtype = vax_cputype << 24; + + switch (vax_cputype) { + case 10: // CVAX + case 11: // RIGEL + case 18: // MARIAH + case 19: // NVAX + case 20: { // SOC + uint32_t sie = *(uint32_t *)(0x20040004); + vax_boardtype |= sie >> 24; + break; + } + } + + platform_early_console_init(); + + printf("\n"); + printf("VAX: sid %#x\n", sid); + printf("VAX: cputype %#x\n", vax_cputype); + printf("VAX: boardtype %#x\n", vax_boardtype); +} // stubbed out time static lk_time_t t = 0; diff --git a/platform/vax/platform_p.h b/platform/vax/platform_p.h new file mode 100644 index 00000000..f7c0b1f4 --- /dev/null +++ b/platform/vax/platform_p.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2019 Travis Geiselbrecht + * + * Use of this source code is governed by a MIT-style + * license that can be found in the LICENSE file or at + * https://opensource.org/licenses/MIT + */ +#pragma once + +#include + +// super simple cheesy system detection mechanism +// mostly cribbed from netbsd +extern uint32_t vax_cputype; +extern uint32_t vax_boardtype; + +void platform_early_console_init(void);