diff options
Diffstat (limited to 'emux64')
-rw-r--r-- | emux64/src/cpu/cpu_subr.c | 90 | ||||
-rw-r--r-- | emux64/src/include/cpu/cpu.h | 33 | ||||
-rw-r--r-- | emux64/src/main.c | 11 |
3 files changed, 129 insertions, 5 deletions
diff --git a/emux64/src/cpu/cpu_subr.c b/emux64/src/cpu/cpu_subr.c new file mode 100644 index 0000000..a7be333 --- /dev/null +++ b/emux64/src/cpu/cpu_subr.c @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and the Osmora Team. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Hyra nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <cpu/cpu.h> +#include <stdio.h> +#include <errno.h> + +void +cpu_dump(struct osmx_core *core) +{ + if (core == NULL) { + return; + } + + /* General purpose registers */ + for (int i = 0; i < N_GPREG; ++i) { + printf("X%d=0x%016llx ", i, core->xn[i]); + if ((i & 1) != 0) + printf("\n"); + } + + for (int i = 0; i < N_FLOATREG; ++i) { + printf("F%d=0x%016llx ", i, core->fn[i]); + if ((i & 1) != 0) + printf("\n"); + } + + /* Double precision registers */ + for (int i = 0; i < N_DUBREG; ++i) { + printf("D%d=0x%016llx ", i, core->dn[i]); + if ((i & 1) == 0) + printf("\n"); + } + + printf("PC=0x%016llx\n", core->pc); +} + +int +cpu_reset(struct osmx_core *core) +{ + if (core == NULL) { + return -EINVAL; + } + + core->pc = CPU_BUA_PBASE; + core->xn[0] = 0; + + /* Initialize float registers */ + for (int i = 0; i < N_FLOATREG; ++i) { + core->fn[i] = 0; + } + + /* Initialize double registers */ + for (int i = 0; i < N_DUBREG; ++i) { + core->dn[i] = 0; + } + + /* Initialize other gp regs */ + for (int i = 1; i < N_GPREG; ++i) { + core->xn[i] = 0xFFFFFFFFFFFFFFFF; + } + + return 0; +} diff --git a/emux64/src/include/cpu/cpu.h b/emux64/src/include/cpu/cpu.h index 04b2a9f..9b045c9 100644 --- a/emux64/src/include/cpu/cpu.h +++ b/emux64/src/include/cpu/cpu.h @@ -38,6 +38,14 @@ #include <stdint.h> #include <stddef.h> +/* Bring up area physical base */ +#define CPU_BUA_PBASE 0xFFF00000 + +/* Register type counts */ +#define N_GPREG 16 +#define N_FLOATREG 7 +#define N_DUBREG 7 + /* * Represents a single unit of execution * @@ -47,9 +55,9 @@ * @pc: Program counter */ struct osmx_core { - uint64_t xn[16]; - float fn[7]; - double dn[7]; + uint64_t xn[N_GPREG]; + float fn[N_FLOATREG]; + double dn[N_DUBREG]; uintptr_t pc; }; @@ -60,7 +68,24 @@ struct osmx_core { * TODO: Dynamically allocate cores */ struct osmx_cpu { - struct osmx_core[1]; + struct osmx_core cores[1]; }; +/* + * Bring the CPU to an initial reset state + * + * @core: Core to bring to reset state + * + * Returns zero on success + */ +int cpu_reset(struct osmx_core *core); + +/* + * Dump the registers to the console for debugging + * purposes + * + * @core: Core to dump + */ +void cpu_dump(struct osmx_core *core); + #endif /* !CPU_CPU_H */ diff --git a/emux64/src/main.c b/emux64/src/main.c index a9a3a7f..cacd6b3 100644 --- a/emux64/src/main.c +++ b/emux64/src/main.c @@ -29,10 +29,19 @@ #include <stdio.h> #include <stdlib.h> +#include <cpu/cpu.h> int main(void) { - printf("Hello emux64!\n"); + struct osmx_core core; + int error; + + if ((error = cpu_reset(&core)) < 0) { + printf("error: failed to power up vcore\n"); + return error; + } + + cpu_dump(&core); return 0; } |