From 71396c5cd460890c52e348687e6e7c864e2dfeed Mon Sep 17 00:00:00 2001 From: Aleksa Vuckovic Date: Sun, 7 Aug 2022 16:39:28 +0200 Subject: types.h; libk and heap begining --- kernel/include/debug.h | 2 -- kernel/include/font.h | 18 +++++++++--------- kernel/include/graphics.h | 2 +- kernel/include/heap.h | 14 ++++++++++++++ kernel/include/idt.h | 16 ++++++++-------- kernel/include/io.h | 2 +- kernel/include/irq.h | 2 +- kernel/include/keyboard.h | 7 ++++--- kernel/include/keymap.h | 2 +- kernel/include/libk/math.h | 8 ++++++++ kernel/include/libk/string.h | 11 +++++++++++ kernel/include/multiboot2.h | 2 +- kernel/include/types.h | 8 ++++++++ 13 files changed, 67 insertions(+), 27 deletions(-) create mode 100644 kernel/include/heap.h create mode 100644 kernel/include/libk/math.h create mode 100644 kernel/include/libk/string.h create mode 100644 kernel/include/types.h (limited to 'kernel/include') diff --git a/kernel/include/debug.h b/kernel/include/debug.h index ebe3a52..74648b9 100644 --- a/kernel/include/debug.h +++ b/kernel/include/debug.h @@ -1,8 +1,6 @@ #ifndef DEBUG_H #define DEBUG_H -#include - void bochs_breakpoint(void); #endif diff --git a/kernel/include/font.h b/kernel/include/font.h index 2bb00fa..f405a90 100644 --- a/kernel/include/font.h +++ b/kernel/include/font.h @@ -1,19 +1,19 @@ #ifndef FONT_H #define FONT_H -#include +#include #define PSF_FONT_MAGIC 0x864ab572 typedef struct { - uint32_t magic; /* magic bytes to identify PSF */ - uint32_t version; /* zero */ - uint32_t headersize; /* offset of bitmaps in file, 32 */ - uint32_t flags; /* 0 if there's no unicode table */ - uint32_t numglyph; /* number of glyphs */ - uint32_t bytesperglyph; /* size of each glyph */ - uint32_t height; /* height in pixels */ - uint32_t width; /* width in pixels */ + uint32_t magic; /* magic bytes to identify PSF */ + uint32_t version; /* zero */ + uint32_t headersize; /* offset of bitmaps in file, 32 */ + uint32_t flags; /* 0 if there's no unicode table */ + uint32_t numglyph; /* number of glyphs */ + uint32_t bytesperglyph; /* size of each glyph */ + uint32_t height; /* height in pixels */ + uint32_t width; /* width in pixels */ } PSF_font; /* font i used: /usr/share/kbd/consolefonts/lat9-16.psf.gz */ diff --git a/kernel/include/graphics.h b/kernel/include/graphics.h index 84505d8..2714f62 100644 --- a/kernel/include/graphics.h +++ b/kernel/include/graphics.h @@ -1,7 +1,7 @@ #ifndef GRAPHICS_H #define GRAPHICS_H -#include +#include struct fb_t { uint64_t addr; diff --git a/kernel/include/heap.h b/kernel/include/heap.h new file mode 100644 index 0000000..ae846bd --- /dev/null +++ b/kernel/include/heap.h @@ -0,0 +1,14 @@ +#ifndef HEAP_H +#define HEAP_H + +#include + +#define HEAP_START_ADDR 0x00200000 +#define HEAP_SIZE 0x00100000 +#define HEAP_BLOCK_SIZE 0x00000100 + +void init_heap(uint64_t addr, uint64_t size, uint64_t block_size); +void* kmalloc(uint32_t size); +void kfree(void *addr); + +#endif diff --git a/kernel/include/idt.h b/kernel/include/idt.h index 9ca9c3a..cc2278a 100644 --- a/kernel/include/idt.h +++ b/kernel/include/idt.h @@ -1,7 +1,7 @@ #ifndef IDT_H #define IDT_H -#include +#include #define GDT_CODE_SEG 0x08 @@ -9,13 +9,13 @@ #define TRAP_GATE 0x8F struct idt_entry { - uint16_t offset_1; // offset bits 0..15 - uint16_t selector; // a code segment selector in GDT or LDT - uint8_t ist; // bits 0..2 holds Interrupt Stack Table offset, rest of bits zero. - uint8_t type_attributes; // gate type, dpl, and p fields - uint16_t offset_2; // offset bits 16..31 - uint32_t offset_3; // offset bits 32..63 - uint32_t zero; // reserved + uint16_t offset_1; // offset bits 0..15 + uint16_t selector; // a code segment selector in GDT or LDT + uint8_t ist; // bits 0..2 holds Interrupt Stack Table offset, rest of bits zero. + uint8_t type_attributes; // gate type, dpl, and p fields + uint16_t offset_2; // offset bits 16..31 + uint32_t offset_3; // offset bits 32..63 + uint32_t zero; // reserved } __attribute__((packed)); typedef struct idt_entry idt_entry; diff --git a/kernel/include/io.h b/kernel/include/io.h index 76c401d..d47abb3 100644 --- a/kernel/include/io.h +++ b/kernel/include/io.h @@ -1,7 +1,7 @@ #ifndef IO_H #define IO_H -#include +#include uint8_t inb(uint32_t port); void outb(uint32_t port, uint8_t value); diff --git a/kernel/include/irq.h b/kernel/include/irq.h index f0e38d6..2f22aff 100644 --- a/kernel/include/irq.h +++ b/kernel/include/irq.h @@ -1,7 +1,7 @@ #ifndef IRQ_H #define IRQ_H -#include +#include // exceptions void isr0(void); diff --git a/kernel/include/keyboard.h b/kernel/include/keyboard.h index 050507d..5d7acd0 100644 --- a/kernel/include/keyboard.h +++ b/kernel/include/keyboard.h @@ -1,15 +1,16 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#include +#include #define KEYBOARD_DATA_PORT 0x60 #define KEYBOARD_STATUS_PORT 0x64 -uint32_t stoi(const char *s); -void itos(uint32_t num, char** s); +uint64_t stoi(const char *s); +void itos(uint64_t num, char* s); void print_char(char c); void print_string(char* s); void keyboard_handler(void); +void print_int(uint64_t num); #endif diff --git a/kernel/include/keymap.h b/kernel/include/keymap.h index c027146..c9b8697 100644 --- a/kernel/include/keymap.h +++ b/kernel/include/keymap.h @@ -1,7 +1,7 @@ #ifndef KEYMAP_H #define KEYMAP_H -#include +#include #define KEY_ESCAPE 0x01 #define KEY_1 0x02 diff --git a/kernel/include/libk/math.h b/kernel/include/libk/math.h new file mode 100644 index 0000000..83ac7fe --- /dev/null +++ b/kernel/include/libk/math.h @@ -0,0 +1,8 @@ +#ifndef MATH_H +#define MATH_H + +#include + +int64_t abs(int64_t val); + +#endif diff --git a/kernel/include/libk/string.h b/kernel/include/libk/string.h new file mode 100644 index 0000000..64a7f81 --- /dev/null +++ b/kernel/include/libk/string.h @@ -0,0 +1,11 @@ +#ifndef STRING_H +#define STRING_H + +#include + +size_t strlen(const char* s); +uint64_t stoi(const char *s); +void itos(uint64_t num, char* s); +void strrev(char *s); + +#endif diff --git a/kernel/include/multiboot2.h b/kernel/include/multiboot2.h index f22fd8e..e7935a6 100644 --- a/kernel/include/multiboot2.h +++ b/kernel/include/multiboot2.h @@ -1,7 +1,7 @@ #ifndef MULTIBOOT2_H #define MULTIBOOT2_H -#include +#include struct mb2_tag_header { uint32_t type; diff --git a/kernel/include/types.h b/kernel/include/types.h new file mode 100644 index 0000000..b5f54be --- /dev/null +++ b/kernel/include/types.h @@ -0,0 +1,8 @@ +#ifndef TYPES_H +#define TYPES_H + +#include +#include +#include + +#endif -- cgit v1.2.3