Skip to content

Commit

Permalink
Map structures
Browse files Browse the repository at this point in the history
  • Loading branch information
phaubertin committed Jan 24, 2025
1 parent bf663d5 commit 73bd3ad
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 15 deletions.
2 changes: 2 additions & 0 deletions include/kernel/infrastructure/acpi/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <stdbool.h>
#include <stddef.h>

bool verify_acpi_checksum(const void *buffer, size_t buflen);

bool verify_acpi_rsdp(const acpi_rsdp_t *rsdp);

void map_acpi_tables(kern_paddr_t rsdp_paddr, const acpi_table_def_t *table_defs);
Expand Down
2 changes: 1 addition & 1 deletion include/kernel/infrastructure/acpi/tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ typedef PACKED_STRUCT {
acpi_table_header_t header;
uint32_t local_intr_controller_addr;
uint32_t flags;
char entries[];
const char entries[];
} acpi_madt_t;

typedef PACKED_STRUCT {
Expand Down
2 changes: 2 additions & 0 deletions include/kernel/infrastructure/i686/firmware/asm/bios.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@

#define BIOS_BDA_EBDA_SEGMENT 0x40e

#define BIOS_BDA_MEMORY_SIZE 0x413

#endif
4 changes: 4 additions & 0 deletions include/kernel/infrastructure/i686/firmware/asm/mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

#define MP_CONF_TABLE_SIGNATURE "PCMP"

#define MP_REVISION_V1_1 1

#define MP_REVISION_V1_4 4

/* Multiprocessor Specification 1.4 Table 4-3 Base MP Configuration Table Entry
* Types */

Expand Down
5 changes: 4 additions & 1 deletion include/kernel/infrastructure/i686/firmware/bios.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
#define JINUE_KERNEL_INFRASTRUCTURE_I686_FIRMWARE_BIOS_H

#include <kernel/infrastructure/i686/firmware/asm/bios.h>
#include <stddef.h>
#include <stdint.h>

uintptr_t get_bios_ebda_addr(void);
uint32_t get_bios_ebda_addr(void);

size_t get_bios_base_memory_size(void);

#endif
9 changes: 7 additions & 2 deletions include/kernel/infrastructure/i686/firmware/mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#ifndef JINUE_KERNEL_INFRASTRUCTURE_I686_FIRMWARE_MP_H
#define JINUE_KERNEL_INFRASTRUCTURE_I686_FIRMWARE_MP_H

#include <kernel/infrastructure/i686/firmware/asm/mp.h>
#include <stdint.h>

/* Multiprocessor Specification 1.4 section 4.1 MP Floating Pointer
Expand All @@ -46,7 +47,7 @@ typedef struct {
uint8_t feature1;
uint8_t feature2;
uint8_t feature_reserved[3];
} mp_floating_ptr_t;
} mp_ptr_struct_t;

/* Multiprocessor Specification 1.4 section 4.2 MP Configuration Table
* Header */
Expand All @@ -65,7 +66,7 @@ typedef struct {
uint16_t ext_table_length;
uint8_t ext_table_checksum;
uint8_t reserved;
char entries[];
const char entries[];
} mp_conf_table_t;

/* Multiprocessor Specification 1.4 section 4.3.1 Processor Entries */
Expand Down Expand Up @@ -112,4 +113,8 @@ typedef struct {
uint8_t dest_apic_intn;
} mp_entry_intr_t;

void find_mp(void);

void init_mp(void);

#endif
1 change: 1 addition & 0 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ sources.kernel.c = \
infrastructure/i686/drivers/vga.c \
infrastructure/i686/firmware/acpi.c \
infrastructure/i686/firmware/bios.c \
infrastructure/i686/firmware/mp.c \
infrastructure/i686/pmap/nopae.c \
infrastructure/i686/pmap/pmap.c \
infrastructure/i686/pmap/pae.c \
Expand Down
16 changes: 10 additions & 6 deletions kernel/infrastructure/acpi/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@
#include <string.h>

/**
* Verify the checksum of an ACPI data structure
* Verify the checksum of an ACPI data structure (RSDP, RSDT, ACPI table)
*
* On x86, this function is also used to verify the checksum of the floating
* pointer structure and MP configuration table header from Intel's
* Multiprocessor Specification since the checksum algorithm is the same.
*
* @param buffer pointer to ACPI data structure
* @param buffer pointer to ACPI (or MP) data structure
* @param buflen size of ACPI data structure
* @return true for correct checksum, false for checksum mismatch
*/
static bool verify_checksum(const void *buffer, size_t buflen) {
bool verify_acpi_checksum(const void *buffer, size_t buflen) {
uint8_t sum = 0;

for(int idx = 0; idx < buflen; ++idx) {
Expand All @@ -64,7 +68,7 @@ bool verify_acpi_rsdp(const acpi_rsdp_t *rsdp) {
return false;
}

if(!verify_checksum(rsdp, ACPI_V1_RSDP_SIZE)) {
if(!verify_acpi_checksum(rsdp, ACPI_V1_RSDP_SIZE)) {
return false;
}

Expand All @@ -76,7 +80,7 @@ bool verify_acpi_rsdp(const acpi_rsdp_t *rsdp) {
return false;
}

return verify_checksum(rsdp, sizeof(acpi_rsdp_t));
return verify_acpi_checksum(rsdp, sizeof(acpi_rsdp_t));
}

/**
Expand Down Expand Up @@ -123,7 +127,7 @@ static const void *map_table(const acpi_table_header_t *header) {

resize_map_in_kernel(header->length);

if(! verify_checksum(header, header->length)) {
if(! verify_acpi_checksum(header, header->length)) {
return NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions kernel/infrastructure/i686/firmware/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <kernel/infrastructure/i686/firmware/acpi.h>
#include <kernel/infrastructure/i686/firmware/bios.h>
#include <kernel/infrastructure/i686/types.h>
#include <kernel/utils/asm/utils.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -79,14 +80,14 @@ static const acpi_rsdp_t *find_rsdp(void) {
}

/* TODO define some PC address map somewhere, use in VGA driver as well */
const char *top = (const char *)(0xa0000 - 1024);
const char *top = (const char *)(0xa0000 - KB);
const char *ebda = (const char *)get_bios_ebda_addr();

if(ebda == NULL || ebda > top) {
return NULL;
}

for(const char *addr = ebda; addr < ebda + 1024; addr += 16) {
for(const char *addr = ebda; addr < ebda + KB; addr += 16) {
const acpi_rsdp_t *rsdp = (const acpi_rsdp_t *)addr;

if(verify_acpi_rsdp(rsdp)) {
Expand Down
17 changes: 15 additions & 2 deletions kernel/infrastructure/i686/firmware/bios.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2024-2025 Philippe Aubertin.
* Copyright (C) 2025 Philippe Aubertin.
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -30,9 +30,11 @@
*/

#include <kernel/infrastructure/i686/firmware/bios.h>
#include <kernel/utils/asm/utils.h>
#include <stdlib.h>

uintptr_t get_bios_ebda_addr(void) {
/* The return value must be aligned on 16 bytes. */
uint32_t get_bios_ebda_addr(void) {
uintptr_t ebda = 16 * (*(uint16_t *)BIOS_BDA_EBDA_SEGMENT);

/* TODO define some PC address map somewhere, use in VGA driver as well */
Expand All @@ -42,3 +44,14 @@ uintptr_t get_bios_ebda_addr(void) {

return ebda;
}

/* The return value must be aligned on 16 bytes */
size_t get_bios_base_memory_size(void) {
size_t size_kb = *(uint16_t *)BIOS_BDA_MEMORY_SIZE;

if(size_kb < 512 || size_kb > 640) {
return 0;
}

return size_kb * KB;
}
Loading

0 comments on commit 73bd3ad

Please sign in to comment.