summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-19 19:25:17 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-19 19:25:17 -0400
commit419cd19c986d1e6507cc96e8beba429df1be5b48 (patch)
tree842a1ccc66681f52a3185a9cd57b87a19986f744 /kernel
parentremove invalid includes (diff)
downloadcomus-419cd19c986d1e6507cc96e8beba429df1be5b48.tar.gz
comus-419cd19c986d1e6507cc96e8beba429df1be5b48.tar.bz2
comus-419cd19c986d1e6507cc96e8beba429df1be5b48.zip
rollback mem_map_memory
Diffstat (limited to 'kernel')
-rw-r--r--kernel/entry.S6
-rw-r--r--kernel/include/efi.h4
-rw-r--r--kernel/mboot/mmap.c3
-rw-r--r--kernel/memory/paging.c31
4 files changed, 29 insertions, 15 deletions
diff --git a/kernel/entry.S b/kernel/entry.S
index fdb8a5a..d16370d 100644
--- a/kernel/entry.S
+++ b/kernel/entry.S
@@ -22,10 +22,14 @@ mb_start:
.align 8
.short 1
.short 1
- .long 20
+ .long 36
.long 1 # cmdline
.long 6 # mmap
.long 9 # elf section
+ .long 12 # efi64
+ .long 14 # rsdp
+ .long 15 # xsdp
+ .long 20 # efi64 IH
# bios entry
.align 8
.short 3
diff --git a/kernel/include/efi.h b/kernel/include/efi.h
index 784b5fb..28a9dfa 100644
--- a/kernel/include/efi.h
+++ b/kernel/include/efi.h
@@ -1003,7 +1003,7 @@ typedef struct {
//
EFI_IMAGE_LOAD LoadImage; // EFI 1.0+
EFI_IMAGE_START
- StartImage; // EFI 1.0+UEFI Specification, Version 2.8 EFI System Table
+ StartImage; // EFI 1.0+UEFI Specification, Version 2.8 EFI System Table
EFI_EXIT Exit; // EFI 1.0+
EFI_IMAGE_UNLOAD UnloadImage; // EFI 1.0+
EFI_EXIT_BOOT_SERVICES ExitBootServices; // EFI 1.0+
@@ -1049,7 +1049,7 @@ typedef struct {
//
EFI_COPY_MEM CopyMem; // EFI 1.1+
EFI_SET_MEM
- SetMem; // EFI 1.1+UEFI Specification, Version 2.8 EFI System Table
+ SetMem; // EFI 1.1+UEFI Specification, Version 2.8 EFI System Table
EFI_CREATE_EVENT_EX CreateEventEx; // UEFI 2.0+
} EFI_BOOT_SERVICES;
diff --git a/kernel/mboot/mmap.c b/kernel/mboot/mmap.c
index d72cf87..34b6a44 100644
--- a/kernel/mboot/mmap.c
+++ b/kernel/mboot/mmap.c
@@ -59,7 +59,8 @@ int mboot_get_mmap(struct memory_map *res)
res->entries[idx].type = SEG_TYPE_DEFECTIVE;
break;
default:
- continue;
+ res->entries[idx].type = SEG_TYPE_RESERVED;
+ break;
}
idx++;
}
diff --git a/kernel/memory/paging.c b/kernel/memory/paging.c
index 838f6fd..2709050 100644
--- a/kernel/memory/paging.c
+++ b/kernel/memory/paging.c
@@ -522,31 +522,40 @@ void paging_init(void)
__asm__ volatile("mov %0, %%cr3" ::"r"(kernel_pml4) : "memory");
}
+static inline void *page_align(void *addr)
+{
+ uintptr_t a = (uintptr_t)addr;
+ a /= PAGE_SIZE;
+ a *= PAGE_SIZE;
+ return (void *)a;
+}
+
void *mem_mapaddr(mem_ctx_t ctx, void *phys, void *virt, size_t len,
unsigned int flags)
{
long pages;
- int alloc = 0;
+ ptrdiff_t error;
+ void *aligned_phys;
- pages = (len + PAGE_SIZE - 1) / PAGE_SIZE;
- len += (PAGE_SIZE - len) % PAGE_SIZE;
+ // get length and physical page aligned address
+ aligned_phys = page_align(phys);
+ error = (char *)phys - (char *)aligned_phys;
+ len += error;
+ pages = len / PAGE_SIZE + 1;
- if (virt == NULL) {
+ // get page aligned (or allocate) vitural address
+ if (virt == NULL)
virt = virtaddr_alloc(ctx->virtctx, pages);
- alloc = 1;
- }
-
if (virt == NULL)
return NULL;
- if (map_pages((volatile struct pml4e *)ctx->pml4, virt, phys,
+ if (map_pages((volatile struct pml4e *)ctx->pml4, virt, aligned_phys,
F_WRITEABLE | flags, pages)) {
- if (alloc)
- virtaddr_free(ctx->virtctx, virt);
+ virtaddr_free(ctx->virtctx, virt);
return NULL;
}
- return (char *)virt;
+ return (char *)virt + error;
}
void mem_unmapaddr(mem_ctx_t ctx, void *virt)