greatbridf пре 2 година
родитељ
комит
12f53f49eb
5 измењених фајлова са 43 додато и 0 уклоњено
  1. 2 0
      CMakeLists.txt
  2. 16 0
      include/types/bitmap.h
  3. 1 0
      include/types/types.h
  4. 1 0
      src/kernel_main.c
  5. 23 0
      src/types/bitmap.c

+ 2 - 0
CMakeLists.txt

@@ -50,6 +50,7 @@ set(KERNEL_MAIN_SOURCES src/kernel_main.c
                         src/kernel/hw/serial.c
                         src/kernel/hw/timer.c
                         src/kernel/event/event.cpp
+                        src/types/bitmap.c
                         src/types/buffer.c
                         include/asm/boot.h
                         include/asm/port_io.h
@@ -66,6 +67,7 @@ set(KERNEL_MAIN_SOURCES src/kernel_main.c
                         include/kernel/hw/timer.h
                         include/kernel/input/keycodes.h
                         include/kernel/input/input_event.h
+                        include/types/bitmap.h
                         include/types/buffer.h
                         include/types/types.h
                         include/types/size.h

+ 16 - 0
include/types/bitmap.h

@@ -0,0 +1,16 @@
+#pragma once
+
+#include <types/stdint.h>
+
+#define BITMAP_UNDERLYING_TYPE char
+
+struct bitmap {
+    size_t size;
+    BITMAP_UNDERLYING_TYPE v[];
+};
+
+size_t make_bm_size(size_t n);
+
+int bm_test(struct bitmap* bm, size_t n);
+void bm_set(struct bitmap* bm, size_t n);
+void bm_clear(struct bitmap* bm, size_t n);

+ 1 - 0
include/types/types.h

@@ -1,5 +1,6 @@
 #pragma once
 
+#include "bitmap.h"
 #include "buffer.h"
 #include "size.h"
 #include "status.h"

+ 1 - 0
src/kernel_main.c

@@ -11,6 +11,7 @@
 #include <kernel/mem.h>
 #include <kernel/stdio.h>
 #include <kernel/vga.h>
+#include <types/bitmap.h>
 
 typedef void (*constructor)(void);
 extern constructor start_ctors;

+ 23 - 0
src/types/bitmap.c

@@ -0,0 +1,23 @@
+#include <types/bitmap.h>
+
+#define B_TYPE BITMAP_UNDERLYING_TYPE
+#define SZ (sizeof(B_TYPE) * 8)
+
+size_t make_bm_size(size_t n)
+{
+    return sizeof(size_t) + (n / SZ) + ((n % SZ) ? 1 : 0);
+}
+
+int bm_test(struct bitmap* bm, size_t n)
+{
+    return (bm->v[n / SZ] & (1 << (n % SZ))) != 0;
+}
+
+void bm_set(struct bitmap* bm, size_t n)
+{
+    bm->v[n / SZ] |= (1 << (n % SZ));
+}
+void bm_clear(struct bitmap* bm, size_t n)
+{
+    bm->v[n / SZ] &= (~(1 << (n % SZ)));
+}