aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Borner2021-05-19 00:43:40 +0200
committerMarvin Borner2021-05-19 00:43:40 +0200
commit98df498e8e8a07e33cc77a059876b940cb9b3c6a (patch)
tree57a2ff0fab411c91fba5512827c18124b092aa5d
parent45bfdffcb2e00fda595b3f9318469f6b0d29cbe4 (diff)
Smashed some bugs
-rw-r--r--.build.mk2
-rw-r--r--kernel/drivers/fb.c10
-rw-r--r--kernel/features/mm.c16
-rw-r--r--kernel/features/proc.c6
-rw-r--r--kernel/multiboot.c13
-rw-r--r--libs/libc/alloc.c2
-rw-r--r--libs/libc/inc/def.h3
-rw-r--r--libs/libc/sys.c3
-rwxr-xr-xrun3
9 files changed, 36 insertions, 22 deletions
diff --git a/.build.mk b/.build.mk
index 489d8fa..32e4086 100644
--- a/.build.mk
+++ b/.build.mk
@@ -9,7 +9,7 @@ ALL_PREPROCESSOR_FLAGS = \
ALL_CONFIGS = \
CONFIG_CACHE \
CONFIG_EXTRA_CFLAGS \
- CONFIG_USE_PIE
+ CONFIG_USER_PIE
# Specific config groups
ifeq ($(CONFIG), debug)
diff --git a/kernel/drivers/fb.c b/kernel/drivers/fb.c
index 6a81434..7ef1088 100644
--- a/kernel/drivers/fb.c
+++ b/kernel/drivers/fb.c
@@ -31,14 +31,12 @@ static u32 fb_map_buffer(struct page_dir *dir)
assert(vbe);
struct memory_range r =
virtual_alloc(dir, memory_range_around((u32)vbe->fb, FB_SIZE), MEMORY_USER);
- printf("FB: %x+%x\n", r.base, r.size);
return r.base;
}
static u32 fb_owner = 0;
static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3)
{
- UNUSED(arg2);
UNUSED(arg3);
switch (request) {
@@ -55,8 +53,12 @@ static res fb_ioctl(u32 request, void *arg1, void *arg2, void *arg3)
fb_owner = proc_current()->pid;
u32 fb = fb_map_buffer(proc_current()->page_dir);
- vbe->fb = (u8 *)fb;
- memcpy_user(arg1, vbe, size);
+
+ stac();
+ memcpy(arg1, vbe, size);
+ ((struct vbe_basic *)arg1)->fb = (u8 *)fb;
+ clac();
+
return EOK;
}
default:
diff --git a/kernel/features/mm.c b/kernel/features/mm.c
index 7a39b33..eca1aae 100644
--- a/kernel/features/mm.c
+++ b/kernel/features/mm.c
@@ -137,6 +137,7 @@ static void physical_page_set_free(u32 address)
CLEAR void physical_set_total(u32 total)
{
assert(total > 0);
+ memory_used = 0;
memory_total = total;
}
@@ -670,7 +671,7 @@ struct memory_range memory_range_from(u32 base, u32 size)
base += align;
size -= align;
- size -= size % PAGE_SIZE;
+ size = ALIGN_DOWN(size, PAGE_SIZE);
return memory_range(base, size);
}
@@ -682,7 +683,7 @@ struct memory_range memory_range_around(u32 base, u32 size)
base -= align;
size += align;
- size += PAGE_SIZE - size % PAGE_SIZE;
+ size = ALIGN_UP(size, PAGE_SIZE);
return memory_range(base, size);
}
@@ -728,8 +729,15 @@ void memory_user_hook(void)
CLEAR void memory_install(void)
{
+ // Set all memory 'used'
+ for (u32 i = 0; i < 1024 * 1024 / 8; i++) {
+ memory[i] = 0xff;
+ }
+
+ // Free memory using mmap
multiboot_mmap();
+ // Initialize kernel page directory
for (u32 i = 0; i < PAGE_KERNEL_COUNT; i++) {
union page_dir_entry *dir_entry = &kernel_dir.entries[i];
dir_entry->bits.present = 1;
@@ -738,16 +746,12 @@ CLEAR void memory_install(void)
dir_entry->bits.address = (u32)&kernel_tables[i] / PAGE_SIZE;
}
- memory_used = 0;
printf("Detected memory: %dKiB (%dMiB)\n", memory_total >> 10, memory_total >> 20);
// Map kernel
memory_map_identity(&kernel_dir, kernel_ro_memory_range(), MEMORY_READONLY);
memory_map_identity(&kernel_dir, kernel_rw_memory_range(), MEMORY_NONE);
- // Map framebuffer
- memory_map_identity(&kernel_dir, memory_range_around(multiboot_vbe(), 0x1000), MEMORY_NONE);
-
// Unmap NULL byte/page
struct memory_range zero = memory_range(0, PAGE_SIZE);
virtual_free(&kernel_dir, zero);
diff --git a/kernel/features/proc.c b/kernel/features/proc.c
index 574df68..4dd90c8 100644
--- a/kernel/features/proc.c
+++ b/kernel/features/proc.c
@@ -279,7 +279,7 @@ struct procfs_message {
static res procfs_read(const char *path, void *buf, u32 offset, u32 count, struct vfs_dev *dev)
{
- (void)dev;
+ UNUSED(dev);
u32 pid = 0;
procfs_parse_path(&path, &pid);
@@ -314,8 +314,8 @@ static res procfs_read(const char *path, void *buf, u32 offset, u32 count, struc
static res procfs_perm(const char *path, enum vfs_perm perm, struct vfs_dev *dev)
{
- (void)path;
- (void)dev;
+ UNUSED(path);
+ UNUSED(dev);
if (perm == VFS_EXEC)
return -EACCES;
diff --git a/kernel/multiboot.c b/kernel/multiboot.c
index 12d2475..4c3e3d0 100644
--- a/kernel/multiboot.c
+++ b/kernel/multiboot.c
@@ -8,6 +8,7 @@
#include <serial.h>
PROTECTED static struct multiboot_info *info = NULL;
+PROTECTED static char vbe[256] = { 0 };
CLEAR static void multiboot_parse_cmdline(const char *line)
{
@@ -21,6 +22,9 @@ CLEAR static void multiboot_parse_cmdline(const char *line)
start += 3;
}
}
+
+ assert(info->flags & MULTIBOOT_INFO_VBE_INFO);
+ memcpy(vbe, (void *)info->vbe_mode_info, sizeof(vbe));
}
CLEAR void multiboot_init(u32 magic, u32 addr)
@@ -36,9 +40,7 @@ CLEAR void multiboot_init(u32 magic, u32 addr)
CLEAR u32 multiboot_vbe(void)
{
- assert(info->flags & MULTIBOOT_INFO_VBE_INFO);
-
- return info->vbe_mode_info;
+ return (u32)vbe;
}
CLEAR void multiboot_mmap(void)
@@ -55,12 +57,11 @@ CLEAR void multiboot_mmap(void)
/* printf("Memory region 0x%x-0x%x\n", mmap->addr, mmap->addr + mmap->len); */
if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) {
total += mmap->len;
- physical_set_free(memory_range_around(mmap->addr, mmap->len));
+ physical_set_free(memory_range_from(mmap->addr, mmap->len));
} else if (mmap->type == MULTIBOOT_MEMORY_BADRAM) {
printf("Defect memory at 0x%x-0x%x\n", mmap->addr, mmap->addr + mmap->len);
- physical_set_used(memory_range_around(mmap->addr, mmap->len));
} else {
- physical_set_used(memory_range_around(mmap->addr, mmap->len));
+ // Memory is set to 'used' by default
}
mmap++;
diff --git a/libs/libc/alloc.c b/libs/libc/alloc.c
index ea01a38..6663a0e 100644
--- a/libs/libc/alloc.c
+++ b/libs/libc/alloc.c
@@ -50,8 +50,6 @@ static int liballoc_unlock(void)
}
#define ALIGNMENT 16
-#define ALIGN_UP(__addr, __align) (((__addr) + (__align)-1) & ~((__align)-1))
-#define ALIGN_DOWN(__addr, __align) ((__addr) & ~((__align)-1))
#define USE_CASE1
#define USE_CASE2
diff --git a/libs/libc/inc/def.h b/libs/libc/inc/def.h
index 7338242..c9c89fd 100644
--- a/libs/libc/inc/def.h
+++ b/libs/libc/inc/def.h
@@ -41,6 +41,9 @@ typedef unsigned long long u64;
#define __STRINGIFY(a) #a
#define STRINGIFY(a) __STRINGIFY(a)
+#define ALIGN_UP(addr, align) (((addr) + (align)-1) & ~((align)-1))
+#define ALIGN_DOWN(addr, align) ((addr) & ~((align)-1))
+
/**
* Compiler attribute wrappers
*/
diff --git a/libs/libc/sys.c b/libs/libc/sys.c
index cf2165a..8d0a9b8 100644
--- a/libs/libc/sys.c
+++ b/libs/libc/sys.c
@@ -186,6 +186,9 @@ static void (*funcs[ATEXIT_MAX])(void) = { 0 };
static void atexit_trigger(void)
{
+ if (!slot)
+ return;
+
while (slot-- > 0) {
if (funcs[slot]) {
funcs[slot]();
diff --git a/run b/run
index 87a3817..ca40fd1 100755
--- a/run
+++ b/run
@@ -84,6 +84,9 @@ make_cross() {
cd "${DIR}/opt/libexec/gcc/i686-elf/11.1.0/" && ln -sf liblto_plugin.so.0.0 liblto_plugin.so
fi
+ # Remove sources
+ rm -rf "${dir}/src/"
+
cd "${DIR}/.."
fi
}