Skip to content

Commit

Permalink
Fix up PC port a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
robotman2412 committed Aug 29, 2024
1 parent fc82cd6 commit ccbecf0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
7 changes: 7 additions & 0 deletions kernel/port/generic/src/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "assertions.h"
#include "cpu/mmu.h"
#include "cpu/panic.h"
#include "interrupt.h"
#include "isr_ctx.h"
#include "limine.h"
#include "memprotect.h"
Expand Down Expand Up @@ -198,6 +199,12 @@ void port_init() {
}
}

// Power off.
void port_poweroff(bool restart) {
irq_disable();
while (1);
}

// Send a single character to the log output.
void port_putc(char msg) {
register char a0 asm("a0") = msg;
Expand Down
1 change: 1 addition & 0 deletions kernel/port/generic/src/smp.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ int smp_cur_cpu() {

// Get the SMP CPU index from the CPU ID value.
int smp_get_cpu(size_t cpuid) {
return 0;
smp_map_t dummy = {.cpuid = cpuid};
array_binsearch_t res = array_binsearch(smp_map, sizeof(smp_map_t), smp_map_len, &dummy, smp_cpuid_cmp);
if (res.found) {
Expand Down
1 change: 1 addition & 0 deletions kernel/src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

// SPDX-License-Identifier: MIT

#include "assertions.h"
#include "cpu/panic.h"
#include "filesystem.h"
#include "housekeeping.h"
Expand Down
37 changes: 33 additions & 4 deletions kernel/src/process/proc_memmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,39 @@ size_t proc_map_raw(

// Release memory allocated to a process.
void proc_unmap_raw(badge_err_t *ec, process_t *proc, size_t base) {
(void)ec;
(void)proc;
(void)base;
logk(LOG_WARN, "TODO: proc_unmap_raw");
// Search the memory map for the specified region.
proc_memmap_ent_t dummy = {.vaddr = base};
array_binsearch_t res = array_binsearch(
proc->memmap.regions,
sizeof(proc_memmap_ent_t),
proc->memmap.regions_len,
&dummy,
proc_memmap_cmp
);
if (!res.found) {
badge_err_set(ec, ELOC_PROCESS, ECAUSE_NOTFOUND);
return;
}

// Remove the region from the memory map.
proc_memmap_ent_t removed;
array_lencap_remove(
&proc->memmap.regions,
sizeof(proc_memmap_ent_t),
&proc->memmap.regions_len,
&proc->memmap.regions_cap,
&removed,
res.index
);

// Remove it from the MMU.
assert_dev_keep(memprotect_u(&proc->memmap, &proc->memmap.mpu_ctx, removed.vaddr, 0, removed.size, 0));
memprotect_commit(&proc->memmap.mpu_ctx);

// Free the memory from PMM.
phys_page_free(removed.paddr / MEMMAP_PAGE_SIZE);

badge_err_set_ok(ec);
}

// Whether the process owns this range of virtual memory.
Expand Down

0 comments on commit ccbecf0

Please sign in to comment.