diff --git a/usr/src/head/stdbool.h b/usr/src/head/stdbool.h index 5e07e38..25cb95a 100644 --- a/usr/src/head/stdbool.h +++ b/usr/src/head/stdbool.h @@ -9,7 +9,7 @@ * consent from Mirocom Laboratories. */ -#ifndef _STDBOOL_H_ 1 +#ifndef _STDBOOL_H_ #define _STDBOOL_H_ 1 #ifndef _HAVE_bool diff --git a/usr/src/sp1/amd64/Makefile b/usr/src/sp1/amd64/Makefile index 9aaf090..dde9951 100644 --- a/usr/src/sp1/amd64/Makefile +++ b/usr/src/sp1/amd64/Makefile @@ -10,7 +10,10 @@ # ASMFILES = $(shell find . -name "*.S") +CFILES = $(shell find . -name "*.c") + ASMOFILES = $(ASMFILES:.S=.S.o) +OFILES = $(CFILES:.c=.o) MISC_OFILES = $(shell find ../ -name "*.o") LIB_OFILES = $(shell find ../../lib/ -name "*.o") @@ -22,15 +25,21 @@ LD = \ ../../../../$(SYS_LD) CFLAGS = \ - $(SYS_CFLAGS) + $(SYS_CFLAGS) \ + -I../../head \ + -I../../sp1/head\ + -D_KERNEL .PHONY: all -all: $(ASMOFILES) +all: $(OFILES) $(ASMOFILES) $(LD) \ -Tconf/link.ld \ $(MISC_OFILES) \ $(LIB_OFILES) \ -o ../../../../sp1.sys +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + %.S.o: %.S $(CC) -c $(CFLAGS) $< -o $@ diff --git a/usr/src/sp1/amd64/cpu/cpu_init.c b/usr/src/sp1/amd64/cpu/cpu_init.c new file mode 100644 index 0000000..c6e260a --- /dev/null +++ b/usr/src/sp1/amd64/cpu/cpu_init.c @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#include +#include +#include + +#define pr_trace(fmt, ...) \ + printf("cpu: " fmt, ##__VA_ARGS__) + +/* From locore.S - low level processor init */ +extern void md_cpu_init(void); + +/* + * Print information about the bootstrap + * processor on early startup + */ +static void +cpu_print_info(void) +{ + static bool once = false; + + if (once) { + return; + } + + pr_trace("pg.nx : yes\n"); + once = true; +} + +void +mu_cpu_preinit(struct cpu_info *ci) +{ + if (ci == NULL) { + return; + } + + /* Default to an ID of zero [BSP] */ + ci->id = 0; + + /* Initialize control registers and such */ + md_cpu_init(); + + /* Log out some information */ + cpu_print_info(); +} diff --git a/usr/src/sp1/amd64/cpu/locore.S b/usr/src/sp1/amd64/cpu/locore.S index dcea44c..e64ffe1 100644 --- a/usr/src/sp1/amd64/cpu/locore.S +++ b/usr/src/sp1/amd64/cpu/locore.S @@ -22,3 +22,24 @@ _start: cli 1: hlt jmp 1b + + .globl md_cpu_init + .set IA32_EFER, 0xC0000080 +md_cpu_init: + push %r12 + push %r13 + push %r14 + push %r15 + push %rbx + + mov $IA32_EFER, %ecx // IA32_EFER + rdmsr // -> EDX:EAX + or $1<<11, %eax // Set NXE + wrmsr // Write it back + + pop %rbx + pop %r15 + pop %r14 + pop %r13 + pop %r12 + retq diff --git a/usr/src/sp1/common/os/main.c b/usr/src/sp1/common/os/main.c index 460dfe4..e400a56 100644 --- a/usr/src/sp1/common/os/main.c +++ b/usr/src/sp1/common/os/main.c @@ -11,11 +11,15 @@ #include #include +#include #define KERNEL_VERSION "0.0.1" +/* Bootstrap processor */ +static struct cpu_info bsp; + /* Root console attribute */ -struct cons_attr cons_attr = { +static struct cons_attr cons_attr = { .fg = 0x808080, .bg = 0x000000 }; @@ -35,4 +39,7 @@ main(void) /* Write the boot console */ boot_banner(); + + /* Pre-init the processor */ + mu_cpu_preinit(&bsp); } diff --git a/usr/src/sp1/head/mu/cpu.h b/usr/src/sp1/head/mu/cpu.h new file mode 100644 index 0000000..4c51c69 --- /dev/null +++ b/usr/src/sp1/head/mu/cpu.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2026, Mirocom Laboratories + * All rights reserved. + * + * The following sources are CONFIDENTIAL and PROPRIETARY + * property of Mirocom Laboratories. Unauthorized copying, + * use, distribution or modification of this file, in whole + * and in part, is strictly prohibited without the prior written + * consent from Mirocom Laboratories. + */ + +#ifndef _MU_CPU_H_ +#define _MU_CPU_H_ 1 + +#include + +/* + * MI processor specific information + * + * @id: Processor ID + */ +struct cpu_info { + uint8_t id; +}; + +/* + * Routine used early on to initialize critical processor + * features and gather information about the processor so + * that your machine is OwOing smoothly. + */ +void mu_cpu_preinit(struct cpu_info *ci); + +#endif /* !_MU_CPU_H_ */