sp1/amd64: cpu: Add CPU preinit helper
Signed-off-by: Ian Moffett <ian@mirocom.org>
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
* consent from Mirocom Laboratories.
|
* consent from Mirocom Laboratories.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _STDBOOL_H_ 1
|
#ifndef _STDBOOL_H_
|
||||||
#define _STDBOOL_H_ 1
|
#define _STDBOOL_H_ 1
|
||||||
|
|
||||||
#ifndef _HAVE_bool
|
#ifndef _HAVE_bool
|
||||||
|
|||||||
@@ -10,7 +10,10 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
ASMFILES = $(shell find . -name "*.S")
|
ASMFILES = $(shell find . -name "*.S")
|
||||||
|
CFILES = $(shell find . -name "*.c")
|
||||||
|
|
||||||
ASMOFILES = $(ASMFILES:.S=.S.o)
|
ASMOFILES = $(ASMFILES:.S=.S.o)
|
||||||
|
OFILES = $(CFILES:.c=.o)
|
||||||
|
|
||||||
MISC_OFILES = $(shell find ../ -name "*.o")
|
MISC_OFILES = $(shell find ../ -name "*.o")
|
||||||
LIB_OFILES = $(shell find ../../lib/ -name "*.o")
|
LIB_OFILES = $(shell find ../../lib/ -name "*.o")
|
||||||
@@ -22,15 +25,21 @@ LD = \
|
|||||||
../../../../$(SYS_LD)
|
../../../../$(SYS_LD)
|
||||||
|
|
||||||
CFLAGS = \
|
CFLAGS = \
|
||||||
$(SYS_CFLAGS)
|
$(SYS_CFLAGS) \
|
||||||
|
-I../../head \
|
||||||
|
-I../../sp1/head\
|
||||||
|
-D_KERNEL
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: $(ASMOFILES)
|
all: $(OFILES) $(ASMOFILES)
|
||||||
$(LD) \
|
$(LD) \
|
||||||
-Tconf/link.ld \
|
-Tconf/link.ld \
|
||||||
$(MISC_OFILES) \
|
$(MISC_OFILES) \
|
||||||
$(LIB_OFILES) \
|
$(LIB_OFILES) \
|
||||||
-o ../../../../sp1.sys
|
-o ../../../../sp1.sys
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
%.S.o: %.S
|
%.S.o: %.S
|
||||||
$(CC) -c $(CFLAGS) $< -o $@
|
$(CC) -c $(CFLAGS) $< -o $@
|
||||||
|
|||||||
@@ -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 <mu/cpu.h>
|
||||||
|
#include <lib/printf.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
}
|
||||||
@@ -22,3 +22,24 @@ _start:
|
|||||||
cli
|
cli
|
||||||
1: hlt
|
1: hlt
|
||||||
jmp 1b
|
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
|
||||||
|
|||||||
@@ -11,11 +11,15 @@
|
|||||||
|
|
||||||
#include <io/cons/cons.h>
|
#include <io/cons/cons.h>
|
||||||
#include <lib/printf.h>
|
#include <lib/printf.h>
|
||||||
|
#include <mu/cpu.h>
|
||||||
|
|
||||||
#define KERNEL_VERSION "0.0.1"
|
#define KERNEL_VERSION "0.0.1"
|
||||||
|
|
||||||
|
/* Bootstrap processor */
|
||||||
|
static struct cpu_info bsp;
|
||||||
|
|
||||||
/* Root console attribute */
|
/* Root console attribute */
|
||||||
struct cons_attr cons_attr = {
|
static struct cons_attr cons_attr = {
|
||||||
.fg = 0x808080,
|
.fg = 0x808080,
|
||||||
.bg = 0x000000
|
.bg = 0x000000
|
||||||
};
|
};
|
||||||
@@ -35,4 +39,7 @@ main(void)
|
|||||||
|
|
||||||
/* Write the boot console */
|
/* Write the boot console */
|
||||||
boot_banner();
|
boot_banner();
|
||||||
|
|
||||||
|
/* Pre-init the processor */
|
||||||
|
mu_cpu_preinit(&bsp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 <sys/types.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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_ */
|
||||||
Reference in New Issue
Block a user