aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/boot.h21
-rw-r--r--src/kernel.c9
-rw-r--r--src/mem/vmm.c12
-rw-r--r--src/mmap.c18
-rw-r--r--src/multiboot2.c7
5 files changed, 31 insertions, 36 deletions
diff --git a/src/boot.h b/src/boot.h
index 8d62bdc..646fb4c 100644
--- a/src/boot.h
+++ b/src/boot.h
@@ -1,24 +1,21 @@
-#pragma once
+/* *** glitch kernel ***
+ * spdx-license-identifier: ISC
+ * description: kernel boot information
+ * */
-#ifdef __cplusplus
-extern "C" {
-#endif
+#pragma once
typedef struct {
- // kernel command line
+ /* kernel command line */
char cmdline[64];
- // memory map
+ /* memory map */
unsigned bitmap[1024 * 32];
- // module
+ /* module */
unsigned module_start;
unsigned module_end;
char module_cmdline[64];
} boot_info_t;
-_Static_assert((1024 * 32 * sizeof(unsigned) * 8) == (1024 * 1024), "bitmap size check");
-
-#ifdef __cplusplus
-}
-#endif
+/* TODO _Static_assert((1024 * 32 * sizeof(unsigned) * 8) == (1024 * 1024), "bitmap size check"); */
diff --git a/src/kernel.c b/src/kernel.c
index 3ee231e..8d7560b 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1,8 +1,7 @@
-//=====================================================================
-// glitch kernel
-// spdx-license-identifier: ISC
-// description: kernel entry point
-//=====================================================================
+/* *** glitch kernel ***
+ * spdx-license-identifier: ISC
+ * description: kernel entry point
+ * */
#include "conf.h"
#include "mem.h"
diff --git a/src/mem/vmm.c b/src/mem/vmm.c
index 77b06a8..f62eadf 100644
--- a/src/mem/vmm.c
+++ b/src/mem/vmm.c
@@ -18,8 +18,8 @@ vmm_map(unsigned int paddr, unsigned int vaddr)
{
if (paddr & 0xfff || vaddr & 0xfff) return 0;
- const unsigned table_idx = vaddr >> 22; // high 10 bits
- const unsigned entry_idx = (vaddr >> 12) & 0x3ff; // low 10 bits
+ const unsigned table_idx = vaddr >> 22; /* high 10 bits */
+ const unsigned entry_idx = (vaddr >> 12) & 0x3ff; /* low 10 bits */
if (k_pagedir[table_idx].present == 0) return 0;
struct TableEntry *table = (struct TableEntry *)to_vaddr(k_pagedir[table_idx].address << 12);
@@ -34,12 +34,8 @@ vmm_map(unsigned int paddr, unsigned int vaddr)
void
alloc4M()
{
- // enable pse in cr4
- asm volatile(R"(
- movl %cr4, %eax
- orl $0x10, %eax
- movl %eax, %cr4
-)");
+ /* enable pse in cr4 */
+ __asm__("movl %cr4, %eax; orl $0x10, %eax; movl %eax, %cr4");
struct DirectoryEntry4MB *directory = (struct DirectoryEntry4MB *)&k_pagedir[0x301];
directory->address_low = 0x1;
diff --git a/src/mmap.c b/src/mmap.c
index 3fe35b5..c28ce79 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -6,15 +6,17 @@
__attribute__((section(".multiboot.text"))) unsigned
multiboot2_mmap(const struct multiboot_mmap_entry entries[], unsigned entry_count, unsigned bitmap[1024 * 32])
{
- // clear out the bitmap
- for (unsigned i = 0; i < 1024 * 32; ++i) bitmap[i] = 0;
+ unsigned i, l;
+
+ /* clear out the bitmap */
+ for (i = 0; i < 1024 * 32; ++i) bitmap[i] = 0;
unsigned avail_frames = 0;
- // loop through all the mmap_entry structures where type is MULTIBOOT_MEMORY_AVAILABLE
- for (unsigned i = 0; i < entry_count; ++i) {
+ /* loop through all the mmap_entry structures where type is MULTIBOOT_MEMORY_AVAILABLE */
+ for (i = 0; i < entry_count; ++i) {
if (entries[i].type != MULTIBOOT_MEMORY_AVAILABLE) continue;
- // number of frames in this entry
+ /* number of frames in this entry */
unsigned n_frames = entries[i].len / 4096;
avail_frames += n_frames;
@@ -23,8 +25,8 @@ multiboot2_mmap(const struct multiboot_mmap_entry entries[], unsigned entry_coun
n_frames / 32, n_frames % 32);
#endif
- // the bitmap is an array of blocks, each holding 32 (2^5) values
- unsigned table_idx = (entries[i].addr >> 17); // get the upper 15 bits
+ /* the bitmap is an array of blocks, each holding 32 (2^5) values */
+ unsigned table_idx = (entries[i].addr >> 17); /* get the upper 15 bits */
while (n_frames != 0) {
if (n_frames >= 32) {
@@ -34,7 +36,7 @@ multiboot2_mmap(const struct multiboot_mmap_entry entries[], unsigned entry_coun
}
else {
unsigned block = bitmap[table_idx];
- for (unsigned l = 0; l < n_frames; ++l) block |= (1 << l);
+ for (l = 0; l < n_frames; ++l) block |= (1 << l);
bitmap[table_idx] = block;
n_frames = 0;
}
diff --git a/src/multiboot2.c b/src/multiboot2.c
index ea06e96..bd6250f 100644
--- a/src/multiboot2.c
+++ b/src/multiboot2.c
@@ -7,7 +7,8 @@ boot_info_t info __attribute__((section(".init")));
__attribute__((section(".multiboot.text"))) void
multiboot_strncpy(char *dest, const char *src, unsigned n)
{
- for (unsigned i = 0; i < n && src[i] != '\0'; ++i) dest[i] = src[i];
+ unsigned i;
+ for (i = 0; i < n && src[i] != '\0'; ++i) dest[i] = src[i];
}
__attribute__((section(".multiboot.text"))) void
@@ -44,6 +45,6 @@ __multiboot2(multiboot_uint32_t addr)
break;
default:
break;
- } // switch
- } // for
+ }
+ }
}