mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 02:16:58 +00:00
DOC: small user manual
This commit is contained in:
@@ -15,7 +15,7 @@ static uint32_t text_color = 0xFFFFFFFF; // White
|
||||
void kconsole_init(void) {
|
||||
cursor_x = 10;
|
||||
cursor_y = 10;
|
||||
kconsole_active = true;
|
||||
kconsole_active = false;
|
||||
|
||||
// Initial clear screen during boot
|
||||
graphics_clear_back_buffer(0x00000000);
|
||||
|
||||
@@ -155,3 +155,17 @@ void k_beep_process(void) {
|
||||
}
|
||||
}
|
||||
|
||||
char *k_strstr(const char *haystack, const char *needle) {
|
||||
if (!*needle) return (char *)haystack;
|
||||
for (; *haystack; haystack++) {
|
||||
const char *h = haystack;
|
||||
const char *n = needle;
|
||||
while (*h && *n && *h == *n) {
|
||||
h++;
|
||||
n++;
|
||||
}
|
||||
if (!*n) return (char *)haystack;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,5 +26,6 @@ void k_reboot(void);
|
||||
void k_shutdown(void);
|
||||
void k_beep(int freq, int ms);
|
||||
void k_beep_process(void);
|
||||
char *k_strstr(const char *haystack, const char *needle);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -70,6 +70,7 @@ static volatile struct limine_bootloader_info_request bootloader_info_request =
|
||||
.revision = 0
|
||||
};
|
||||
|
||||
__attribute__((used, section(".requests")))
|
||||
static volatile struct limine_kernel_file_request kernel_file_request = {
|
||||
.id = LIMINE_KERNEL_FILE_REQUEST,
|
||||
.revision = 0
|
||||
@@ -229,6 +230,15 @@ void kmain(void) {
|
||||
struct limine_framebuffer *fb = framebuffer_request.response->framebuffers[0];
|
||||
graphics_init(fb);
|
||||
kconsole_init();
|
||||
|
||||
// Check for verbose boot flag
|
||||
if (kernel_file_request.response != NULL && kernel_file_request.response->kernel_file != NULL) {
|
||||
const char *cmdline = kernel_file_request.response->kernel_file->cmdline;
|
||||
if (cmdline != NULL && k_strstr(cmdline, "-v") != NULL) {
|
||||
kconsole_set_active(true);
|
||||
}
|
||||
}
|
||||
|
||||
log_ok("Graphics and Console ready");
|
||||
|
||||
if (memmap_request.response != NULL) {
|
||||
|
||||
@@ -140,12 +140,12 @@ static void pic_remap(void) {
|
||||
static void pit_setup(void) {
|
||||
uint16_t divisor = 1193182 / 60; // ~60Hz
|
||||
|
||||
// Send command byte
|
||||
outb(0x43, 0x36); // Channel 0, lobyte/hibyte, mode 3 (square wave), binary
|
||||
// Mode 2: Rate Generator (more appropriate for periodic interrupts)
|
||||
outb(0x43, 0x34); io_wait(); // Channel 0, lobyte/hibyte, mode 2, binary
|
||||
|
||||
// Send divisor
|
||||
outb(0x40, divisor & 0xFF);
|
||||
outb(0x40, (divisor >> 8) & 0xFF);
|
||||
outb(0x40, divisor & 0xFF); io_wait();
|
||||
outb(0x40, (divisor >> 8) & 0xFF); io_wait();
|
||||
}
|
||||
|
||||
void idt_init(void) {
|
||||
|
||||
@@ -31,27 +31,24 @@ static inline void wrmsr(uint32_t msr, uint64_t value) {
|
||||
}
|
||||
|
||||
static uint32_t read_lapic_id(void) {
|
||||
uint32_t eax, ebx, ecx, edx;
|
||||
asm volatile("cpuid" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(1));
|
||||
return (ebx >> 24) & 0xFF;
|
||||
extern uint64_t hhdm_offset;
|
||||
volatile uint32_t *lapic = (volatile uint32_t *)(hhdm_offset + 0xFEE00000ULL);
|
||||
return (lapic[0x020 / 4] >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
uint32_t smp_this_cpu_id(void) {
|
||||
if (total_cpus <= 1 || !cpu_states) return 0;
|
||||
|
||||
// Use GS-based self-pointer to get the structure first
|
||||
cpu_state_t *state = NULL;
|
||||
// Safely check GS:0. If GS is not set or base is 0, this should be handled carefully.
|
||||
// In BoredOS, if GS is not set, this might still fault depending on address space.
|
||||
// However, the cpu_states check above covers the most likely early-boot failure.
|
||||
asm volatile("movq %%gs:0, %0" : "=r"(state) : : "memory");
|
||||
if (state) return state->cpu_id;
|
||||
if (!cpu_states || total_cpus == 0) return 0;
|
||||
|
||||
uint32_t lapic = read_lapic_id();
|
||||
if (lapic == bsp_lapic_id) return 0;
|
||||
cpu_state_t *state = NULL;
|
||||
asm volatile("movq %%gs:0, %0" : "=r"(state) : : "memory");
|
||||
if (state && state->lapic_id == lapic) return state->cpu_id;
|
||||
for (uint32_t i = 0; i < total_cpus; i++) {
|
||||
if (cpu_states[i].lapic_id == lapic) return i;
|
||||
if (cpu_states[i].online && cpu_states[i].lapic_id == lapic) return i;
|
||||
}
|
||||
return 0; // Fallback to BSP
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t smp_cpu_count(void) {
|
||||
@@ -126,7 +123,8 @@ static void ap_entry(struct limine_smp_info *info) {
|
||||
void smp_init_bsp(void) {
|
||||
static cpu_state_t bsp_state_static = {0};
|
||||
bsp_state_static.cpu_id = 0;
|
||||
bsp_state_static.lapic_id = read_lapic_id();
|
||||
bsp_lapic_id = read_lapic_id();
|
||||
bsp_state_static.lapic_id = bsp_lapic_id;
|
||||
bsp_state_static.self = &bsp_state_static;
|
||||
bsp_state_static.online = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user