Compare commits

...

19 Commits

Author SHA1 Message Date
44f5d687b0 changed main to a signal demo 2025-04-21 20:50:39 +02:00
1f5a358b19 fix: make iso 2025-04-21 13:29:56 +02:00
e15f0af292 fix: kpanic clearing registers and hlt correctly 2025-04-21 13:23:56 +02:00
8e2017bd29 clean 2025-04-18 17:31:08 +02:00
11125325ca Merge branch 'main' of git.chauvet.pro:starnakin/42_KFS 2025-04-18 17:20:43 +02:00
81c54647d2 feature: clear registers when kpanic is called 2025-04-18 17:19:56 +02:00
fc79a47957 add signal api 2025-04-18 17:07:56 +02:00
6c8c158a1f core: add physical allocator (not supposed to work but smh kinda does) 2025-04-18 14:42:07 +02:00
65f08e3887 feature: layout command to change between us and fr layouts 2025-04-18 13:56:11 +02:00
a14cc5df28 clean: remove physical memory utils 2025-04-17 17:12:03 +02:00
2e09db2dd1 fix: memory is now working completely (size issue)
fix: reboot with invalid opcode
2025-04-17 15:09:22 +02:00
5e561bfa15 wip: multiple pds and switch to kernel pd when needed 2025-02-10 13:25:19 +01:00
8dd5373e7f wip: start to add multiple pd for each task 2025-02-07 15:48:13 +01:00
3b798e5daa core: remove bozo typedef for types 2025-02-07 12:35:32 +01:00
70739744ac fix: fault address always display 2025-02-07 11:30:12 +01:00
1e981755de fix: do not edit task if it's the current 2025-02-07 11:29:39 +01:00
3766464c47 add: zombify task 2025-02-07 11:28:22 +01:00
a9ed5947a8 clean: add '\n' 2025-02-04 11:57:54 +01:00
db4ed04dd6 fix: kpanic print address of the fault only when page fault occured 2025-02-04 11:57:43 +01:00
74 changed files with 60600 additions and 1946 deletions

View File

@ -33,7 +33,9 @@ $(NAME): $(OBJ)
run: $(NAME) run: $(NAME)
qemu-system-i386 -kernel build/$(NAME).bin -vga std qemu-system-i386 -kernel build/$(NAME).bin -vga std
iso: $(NAME) mkdir -p isodir/boot/grub cp build/$(NAME).bin isodir/boot/$(NAME).bin iso: $(NAME)
mkdir -p isodir/boot/grub
cp build/$(NAME).bin isodir/boot/$(NAME).bin
cp config/grub.cfg isodir/boot/grub/grub.cfg cp config/grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o build/$(NAME).iso --compress=xz --locales=en@quot --themes= isodir grub-mkrescue -o build/$(NAME).iso --compress=xz --locales=en@quot --themes= isodir
rm -rf isodir rm -rf isodir

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@ -62,8 +61,8 @@ typedef struct Zone {
* For TINY and SMALL, the zone will be divided in blocks. * For TINY and SMALL, the zone will be divided in blocks.
* For LARGE, it will be entire page(s). * For LARGE, it will be entire page(s).
*/ */
extern Zone *vzones[3];
extern Zone *kzones[3]; extern Zone *kzones[3];
extern Zone *zones[3];
/*----------- UTILS ----------*/ /*----------- UTILS ----------*/
block_type_t get_type(size_t size); block_type_t get_type(size_t size);
@ -72,17 +71,17 @@ size_t align_mem(size_t addr);
/*----------------------------*/ /*----------------------------*/
/*-------- ALLOCATOR ---------*/ /*-------- ALLOCATOR ---------*/
int new_kzone(block_type_t type, size_t size);
int new_vzone(block_type_t type, size_t size); int new_vzone(block_type_t type, size_t size);
int new_kzone(block_type_t type, size_t size);
/*----------------------------*/ /*----------------------------*/
void *kmalloc(size_t size);
void kfree(void *ptr);
void *krealloc(void *ptr, size_t size);
void *vmalloc(size_t size); void *vmalloc(size_t size);
void vfree(void *ptr); void vfree(void *ptr);
void *vrealloc(void *ptr, size_t size); void *vrealloc(void *ptr, size_t size);
void show_kalloc_mem(void);
void show_valloc_mem(void); void show_valloc_mem(void);
size_t ksize(void *virt_addr);
size_t vsize(void *virt_addr); size_t vsize(void *virt_addr);
void *kmalloc(size_t size);
void kfree(void *ptr);
void *krealloc(void *ptr, size_t size);
void show_kalloc_mem(void);
size_t ksize(void *phys_addr);

View File

@ -1,13 +1,12 @@
#pragma once #pragma once
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
// MSR // MSR
bool cpu_has_msr(); bool cpu_has_msr();
void cpu_set_msr(u32 msr, u32 lo, u32 hi); void cpu_set_msr(uint32_t msr, uint32_t lo, uint32_t hi);
void cpu_get_msr(u32 msr, u32 *lo, u32 *hi); void cpu_get_msr(uint32_t msr, uint32_t *lo, uint32_t *hi);
// 8259 PIC // 8259 PIC
void pic_disable(void); void pic_disable(void);

View File

@ -10,3 +10,4 @@ void reboot_cmd(char* arg);
void heap_cmd(char *arg); void heap_cmd(char *arg);
void clear_cmd(char *arg); void clear_cmd(char *arg);
void merdella_cmd(char *arg); void merdella_cmd(char *arg);
void layout_cmd(char *arg);

View File

@ -2,7 +2,7 @@
#include "kpanic.h" #include "kpanic.h"
#include "kprintf.h" #include "kprintf.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define PRINT_PTR(X) kprintf("%s:%u %s: %p\n", __FILE__, __LINE__, #X, X) #define PRINT_PTR(X) kprintf("%s:%u %s: %p\n", __FILE__, __LINE__, #X, X)
@ -18,13 +18,13 @@
} while (0) } while (0)
struct function_entry { struct function_entry {
u32 addr; uint32_t addr;
char name[64]; char name[64];
}; };
struct stackframe { struct stackframe {
struct stackframe *ebp; struct stackframe *ebp;
u32 eip; uint32_t eip;
}; };
void print_stack(void); void print_stack(void);

View File

@ -1,11 +1,10 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct font { struct font {
u32 height; uint32_t height;
u32 width; uint32_t width;
u32 yoffset; uint32_t yoffset;
char *bitmap; char *bitmap;
}; };

View File

@ -4,7 +4,7 @@
#include "font.h" #include "font.h"
struct font consolas_regular_13_font[] = {\ struct font consolas_regular_13_font[] = {
{ {
.width = 0, .width = 0,
.height = 0, .height = 0,
@ -219,25 +219,33 @@ struct font consolas_regular_13_font[] = {\
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " ## ## ## ## ## ## #################### ## ## ## ## #################### ## ## ## ## ## ## ", .bitmap =
" ## ## ## ## ## ## #################### ## ## ## "
"## #################### ## ## ## ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 15, .height = 15,
.yoffset = 0, .yoffset = 0,
.bitmap = " ### ## ##### ###### ## ## ## ## ##### ###### ##### ### ## ### ######### ###### ## ## ", .bitmap =
" ### ## ##### ###### ## ## ## ## ##### ###### "
" ##### ### ## ### ######### ###### ## ## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = " ### ## ##### ### ## ## ## ## ## ## ######## ### ## ## ###### ####### ## ## ## ### ## ## ## ##### ## ### ", .bitmap = " ### ## ##### ### ## ## ## ## ## ## ######## ### "
"## ## ###### ####### ## ## ## ### ## "
"## ## ##### ## ### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = " #### ###### ## ## ## ## ###### #### #### ## ###### ## ## ##### ## #### ## #### ######## #### ### ", .bitmap = " #### ###### ## ## ## ## ###### "
"#### #### ## ###### ## ## ##### ## #### ## "
"#### ######## #### ### ",
}, },
{ {
.width = 3, .width = 3,
@ -249,25 +257,29 @@ struct font consolas_regular_13_font[] = {\
.width = 5, .width = 5,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ", .bitmap = " # ### ## ## ## ## ## ## ## ## ## ## "
" ## ## ### # ",
}, },
{ {
.width = 5, .width = 5,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## ## ## ### # ", .bitmap = " # ### ## ## ## ## ## ## ## ## ## ## "
" ## ## ### # ",
}, },
{ {
.width = 8, .width = 8,
.height = 8, .height = 8,
.yoffset = 0, .yoffset = 0,
.bitmap = " ## # ## # ######## ###### ###### ######## # ## # ## ", .bitmap =
" ## # ## # ######## ###### ###### ######## # ## # ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 8, .height = 8,
.yoffset = 4, .yoffset = 4,
.bitmap = " ## ## ## ################ ## ## ## ", .bitmap =
" ## ## ## ################ ## ## ## ",
}, },
{ {
.width = 5, .width = 5,
@ -291,67 +303,80 @@ struct font consolas_regular_13_font[] = {\
.width = 9, .width = 9,
.height = 15, .height = 15,
.yoffset = 0, .yoffset = 0,
.bitmap = " ## ## ### ## ### ## ### ## ## ### ## ### ## ### ## ", .bitmap = " ## ## ### ## ### ## "
"### ## ## ### ## ### ## "
"### ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### ## ## ## ##### ###### ########## ###### ##### ## ## ## ###### #### ", .bitmap = " #### ###### ## ## ## ##### ###### ########## "
"###### ##### ## ## ## ###### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " ## #### ##### ## ## ## ## ## ## ## ## ################", .bitmap = " ## #### ##### ## ## ## ## ## "
"## ## ## ################",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### # ## ## ## ### ## ### ### ### ################", .bitmap = " #### ###### # ## ## ## ### ## "
"### ### ### ################",
}, },
{ {
.width = 7, .width = 7,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "##### ####### ## ## ## ##### ##### ## ## ######## ##### ", .bitmap = "##### ####### ## ## ## ##### ##### ## "
" ## ######## ##### ",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " ### ### #### ##### ## ## ### ## ### ## ## ## #################### ## ## ", .bitmap =
" ### ### #### ##### ## ## ### ## ### "
"## ## ## #################### ## ## ",
}, },
{ {
.width = 7, .width = 7,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "###### ###### ## ## ##### ###### ## ## ## ######### ##### ", .bitmap = "###### ###### ## ## ##### ###### ## ## "
" ## ######### ##### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ##### ## ## ###### ####### ## #### #### ##### ### ###### #### ", .bitmap = " #### ##### ## ## ###### ####### ## #### "
" #### ##### ### ###### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ### ## ### ## ### ## ### ### ### ### ", .bitmap = "################ ### ## ### ## ### "
"## ### ### ### ### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ######### #### ##### ### ###### ###### ### ##### #### ######### #### ", .bitmap = " #### ######### #### ##### ### ###### ###### ### "
" ##### #### ######### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### ### ##### #### #### ## ####### ###### ## ## ##### #### ", .bitmap = " #### ###### ### ##### #### #### ## ####### "
"###### ## ## ##### #### ",
}, },
{ {
.width = 3, .width = 3,
@ -363,13 +388,15 @@ struct font consolas_regular_13_font[] = {\
.width = 5, .width = 5,
.height = 12, .height = 12,
.yoffset = 4, .yoffset = 4,
.bitmap = " ### ### ### ### #### ### ####### ### ", .bitmap =
" ### ### ### ### #### ### ####### ### ",
}, },
{ {
.width = 7, .width = 7,
.height = 10, .height = 10,
.yoffset = 3, .yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### ### # ", .bitmap = " # ### ### #### #### #### #### ### "
"### # ",
}, },
{ {
.width = 8, .width = 8,
@ -381,199 +408,244 @@ struct font consolas_regular_13_font[] = {\
.width = 7, .width = 7,
.height = 10, .height = 10,
.yoffset = 3, .yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### ### # ", .bitmap = " # ### ### #### #### #### #### ### ### "
" # ",
}, },
{ {
.width = 6, .width = 6,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = "### ##### ### ## ## ##### #### ## ## ## ### ### ### ", .bitmap = "### ##### ### ## ## ##### #### ## ## ## "
" ### ### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = " #### ####### ## ## ## ## ## ##################### ######## ######## ######## ############## ## ###### ## ## ## ####### ##### ", .bitmap =
" #### ####### ## ## ## ## ## ##################### "
"######## ######## ######## ############## ## ###### ## "
"## ## ####### ##### ",
}, },
{ {
.width = 12, .width = 12,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " ### #### #### ###### ## ## ## ## ### ### ######## ######## ### ### ## ## ### ###", .bitmap = " ### #### #### ###### ## ## "
" ## ## ### ### ######## ######## ### ### "
" ## ## ### ###",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "###### ########## #### #### ########## ####### ## #### #### ######### ###### ", .bitmap = "###### ########## #### #### ########## ####### ## "
" #### #### ######### ###### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### ## ### ## ## ## ## ## ## # ####### #### ", .bitmap = " #### ###### ## ### ## ## ## ## "
" ## ## # ####### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "##### ####### ## ## ## #### #### #### #### #### ##### ## ####### ##### ", .bitmap = "##### ####### ## ## ## #### #### #### #### "
" #### ##### ## ####### ##### ",
}, },
{ {
.width = 7, .width = 7,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ## ## ################ ## ## ##############", .bitmap = "################ ## ## ################ ## "
" ## ##############",
}, },
{ {
.width = 7, .width = 7,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ## ## ################ ## ## ## ## ", .bitmap = "################ ## ## ################ ## "
" ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### ## #### ## ## ###### ###### #### ## ## ## ####### #### ", .bitmap = " #### ###### ## #### ## ## ###### ###### "
" #### ## ## ## ####### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "## #### #### #### #### #################### #### #### #### #### ##", .bitmap = "## #### #### #### #### #################### "
" #### #### #### #### ##",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ## ## ## ## ## ## ## ## ################", .bitmap = "################ ## ## ## ## ## "
"## ## ## ################",
}, },
{ {
.width = 6, .width = 6,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "############ ## ## ## ## ## ## ### ####### ### ", .bitmap = "############ ## ## ## ## ## ## ### "
"####### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "## ### ## ### ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ## ### ", .bitmap =
"## ### ## ### ## ### ## ### ##### #### #### "
" ##### ## ### ## ### ## ### ## ### ",
}, },
{ {
.width = 7, .width = 7,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "## ## ## ## ## ## ## ## ## ## ##############", .bitmap = "## ## ## ## ## ## ## ## ## "
" ## ##############",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "### ####### ######## ######## ############################## ###### ## ###### ###### ###### ###### ###", .bitmap = "### ####### ######## ######## "
"############################## ###### ## ###### ###### "
" ###### ###### ###",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "### ##### ###### ###### ###### #### ## #### ## #### ###### ###### ###### ##### ###", .bitmap = "### ##### ###### ###### ###### #### ## #### ## #### "
"###### ###### ###### ##### ###",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ######## ## ## ### #### #### #### #### #### ### ## ## ######## #### ", .bitmap =
" #### ######## ## ## ### #### #### #### "
" #### #### ### ## ## ######## #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "###### ####### ## ##### #### #### ########## ###### ## ## ## ## ", .bitmap = "###### ####### ## ##### #### #### ########## "
"###### ## ## ## ## ",
}, },
{ {
.width = 9, .width = 9,
.height = 15, .height = 15,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ####### ## ## ## #### #### #### #### #### ## ## ## ####### ##### ## # ##### ### ", .bitmap = " #### ####### ## ## ## #### #### #### "
" #### #### ## ## ## ####### ##### ## # "
" ##### ### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "##### ####### ## ## ## ## ## ## ###### ##### ## ### ## ### ## ### ## ##### ###", .bitmap = "##### ####### ## ## ## ## ## ## ###### ##### ## "
"### ## ### ## ### ## ##### ###",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " #### ###### ## # ## ### ##### ##### ### #### ######### ##### ", .bitmap = " #### ###### ## # ## ### ##### ##### "
" ### #### ######### ##### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ## ## ## ## ## ## ## ## ## ## ", .bitmap = "################ ## ## ## ## ## "
"## ## ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "## #### #### #### #### #### #### #### #### #### ### ###### #### ", .bitmap = "## #### #### #### #### #### #### #### "
" #### #### ### ###### #### ",
}, },
{ {
.width = 12, .width = 12,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "### ### ### ## ### ### ## ## ### ### ### ### ## ## ###### ###### #### #### ### ", .bitmap = "### ### ### ## ### ### ## ## ### ### "
" ### ### ## ## ###### ###### #### "
" #### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " ## # ## ## ## ## ## ## ## ## ## ## ## ## ######## ######## ######## ######## ### ### ### ### ", .bitmap =
" ## # ## ## ## ## ## ## ## ## ## ## ## ## "
"######## ######## ######## ######## ### ### ### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "### ### ## ## ### ### ###### #### #### #### #### ###### ### ### ### ### ### ###", .bitmap =
"### ### ## ## ### ### ###### #### #### "
"#### #### ###### ### ### ### ### ### ###",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "## ##### ### ## ## ## ## ###### #### #### ## ## ## ## ## ", .bitmap =
"## ##### ### ## ## ## ## ###### #### "
"#### ## ## ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = "################ ## ### ## ### ### ### ### ## ################", .bitmap = "################ ## ### ## ### ### "
"### ### ## ################",
}, },
{ {
.width = 5, .width = 5,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = "############ ## ## ## ## ## ## ## ## ## ## ## ##########", .bitmap = "############ ## ## ## ## ## ## ## ## ## "
"## ## ##########",
}, },
{ {
.width = 9, .width = 9,
.height = 15, .height = 15,
.yoffset = 0, .yoffset = 0,
.bitmap = "## ### ## ### ## ### ## ## ### ## ### ## ### ## ## ", .bitmap = "## ### ## ### ## ### ## "
" ## ### ## ### ## ### "
" ## ## ",
}, },
{ {
.width = 5, .width = 5,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = "########## ## ## ## ## ## ## ## ## ## ## ## ############", .bitmap = "########## ## ## ## ## ## ## ## ## ## "
"## ## ############",
}, },
{ {
.width = 10, .width = 10,
.height = 6, .height = 6,
.yoffset = 1, .yoffset = 1,
.bitmap = " ## #### ###### ## ## ## ## ### ###", .bitmap =
" ## #### ###### ## ## ## ## ### ###",
}, },
{ {
.width = 10, .width = 10,
@ -591,163 +663,192 @@ struct font consolas_regular_13_font[] = {\
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " #### ###### # ## ############## #### ########## ######", .bitmap =
" #### ###### # ## ############## #### ########## ######",
}, },
{ {
.width = 8, .width = 8,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = "## ## ## ## ###### ####### ### #### #### #### #### ########## ##### ", .bitmap = "## ## ## ## ###### ####### ### #### "
" #### #### #### ########## ##### ",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " #### ######### ### ## ## ### # ###### #### ", .bitmap =
" #### ######### ### ## ## ### # ###### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = " ## ## ## ## ###### ########## #### #### #### #### ### ####### ### ##", .bitmap = " ## ## ## ## ###### ########## #### "
" #### #### #### ### ####### ### ##",
}, },
{ {
.width = 8, .width = 8,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " #### ###### ### #################### ### ####### ######", .bitmap = " #### ###### ### #################### ### "
"####### ######",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = " #### ##### ## ## ## ####### ####### ## ## ## ## ## ## ", .bitmap =
" #### ##### ## ## ## ####### ####### "
"## ## ## ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 4, .yoffset = 4,
.bitmap = " ################ ## ## ## ####### ###### ## ####### ########## ########## ##### ", .bitmap = " ################ ## ## ## ####### ###### ## "
"####### ########## ########## ##### ",
}, },
{ {
.width = 7, .width = 7,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = "## ## ## ## ###### ########## #### #### #### #### #### #### ##", .bitmap = "## ## ## ## ###### ########## #### #### "
" #### #### #### #### ##",
}, },
{ {
.width = 8, .width = 8,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = " ### ### ### ##### ##### ## ## ## ## ## ################", .bitmap = " ### ### ### ##### ##### ## "
"## ## ## ## ################",
}, },
{ {
.width = 7, .width = 7,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = " ### ### ### ############## ## ## ## ## ## ## ### ######## #### ", .bitmap = " ### ### ### ############## ## ## "
" ## ## ## ## ### ######## #### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = "## ## ## ## ## ### ## ### ##### #### #### ##### ## ### ## ### ## ### ", .bitmap = "## ## ## ## ## ### ## ### ##### "
" #### #### ##### ## ### ## ### ## ### ",
}, },
{ {
.width = 8, .width = 8,
.height = 13, .height = 13,
.yoffset = 0, .yoffset = 0,
.bitmap = "##### ##### ## ## ## ## ## ## ## ## ## ################", .bitmap = "##### ##### ## ## ## ## ## "
"## ## ## ## ################",
}, },
{ {
.width = 8, .width = 8,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "#### ## ################## ## #### ## #### ## #### ## #### ## #### ## ##", .bitmap = "#### ## ################## ## #### ## #### ## #### ## #### "
"## #### ## ##",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "###### ########## #### #### #### #### #### #### ##", .bitmap =
"###### ########## #### #### #### #### #### #### ##",
}, },
{ {
.width = 8, .width = 8,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " #### ###### ### ##### #### #### ##### ### ###### #### ", .bitmap = " #### ###### ### ##### #### #### ##### ### "
"###### #### ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 4, .yoffset = 4,
.bitmap = "###### ####### ### #### #### #### #### ########## ###### ## ## ## ", .bitmap = "###### ####### ### #### #### #### #### "
"########## ###### ## ## ## ",
}, },
{ {
.width = 8, .width = 8,
.height = 12, .height = 12,
.yoffset = 4, .yoffset = 4,
.bitmap = " ###### ########## #### #### #### #### ### ####### ###### ## ## ##", .bitmap = " ###### ########## #### #### #### #### ### "
"####### ###### ## ## ##",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "###### ########## #### #### ## ## ## ## ", .bitmap =
"###### ########## #### #### ## ## ## ## ",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " ##### ###### ## #### ##### #### ############### ", .bitmap =
" ##### ###### ## #### ##### #### ############### ",
}, },
{ {
.width = 9, .width = 9,
.height = 12, .height = 12,
.yoffset = 1, .yoffset = 1,
.bitmap = " # ## ## ################## ## ## ## ## ## ###### #####", .bitmap = " # ## ## ################## ## ## "
" ## ## ## ###### #####",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "## #### #### #### #### #### #### ########## ######", .bitmap =
"## #### #### #### #### #### #### ########## ######",
}, },
{ {
.width = 10, .width = 10,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "### ### ## ## ### ### ## ## ## ## ###### #### #### ## ", .bitmap = "### ### ## ## ### ### ## ## ## ## ###### "
" #### #### ## ",
}, },
{ {
.width = 10, .width = 10,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "### ### ## ## ## ## ## ## ## ## ######## ######## ######## ### #### ### ### ", .bitmap = "### ### ## ## ## ## ## ## ## ## ######## ######## "
" ######## ### #### ### ### ",
}, },
{ {
.width = 11, .width = 11,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = " ### ### ### ### ### ### ##### #### #### ###### ###### ### ### ", .bitmap = " ### ### ### ### ### ### ##### #### "
"#### ###### ###### ### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 12, .height = 12,
.yoffset = 4, .yoffset = 4,
.bitmap = "### ### ### ## ### ### ## ## ###### ##### #### ### ## ### ##### #### ", .bitmap =
"### ### ### ## ### ### ## ## ###### ##### "
"#### ### ## ### ##### #### ",
}, },
{ {
.width = 7, .width = 7,
.height = 9, .height = 9,
.yoffset = 4, .yoffset = 4,
.bitmap = "############## ## ## ### ## ### ##############", .bitmap =
"############## ## ## ### ## ### ##############",
}, },
{ {
.width = 7, .width = 7,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = " ### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### ####", .bitmap = " ### #### ## ## ## ## ## ### "
"#### ## ## ## ## ## ##### ####",
}, },
{ {
.width = 2, .width = 2,
@ -759,7 +860,8 @@ struct font consolas_regular_13_font[] = {\
.width = 7, .width = 7,
.height = 16, .height = 16,
.yoffset = 0, .yoffset = 0,
.bitmap = "### #### ## ## ## ## ## ### #### ## ## ## ## ## ##### #### ", .bitmap = "### #### ## ## ## ## ## ### "
"#### ## ## ## ## ## ##### #### ",
}, },
{ {
.width = 9, .width = 9,

View File

@ -4,7 +4,7 @@
#include "font.h" #include "font.h"
struct font minecraft_medium_13_font[] = {\ struct font minecraft_medium_13_font[] = {
{ {
.width = 0, .width = 0,
.height = 0, .height = 0,
@ -178,27 +178,36 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 9, .width = 9,
.height = 7, .height = 7,
.bitmap = " ## ### ## ### ## ### ## ############## ## ## ## ", .bitmap =
" ## ### ## ### ## ### ## ############## ## ## ## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = " ## ### ## ### ## ### ################################# ## ### ## ### ###################### ## ### ## ### ## ### ", .bitmap = " ## ### ## ### ## ### "
"################################# ## ### ## ### "
"###################### ## ### ## ### ## ### ",
}, },
{ {
.width = 9, .width = 9,
.height = 15, .height = 15,
.bitmap = " ## ## ####### ################## ## ## ## ## ## ################## ## ## ", .bitmap = " ## ## ####### ################## ## "
" ## ## ## ## ################## "
" ## ## ",
}, },
{ {
.width = 13, .width = 13,
.height = 13, .height = 13,
.bitmap = " ## # # # # # # # # # ## # # ## # # ## ## ## # ## # # # # # # # # # # # # # ## ", .bitmap = " ## # # # # # # # # # ## # # "
"## # # ## ## ## # ## # # # "
" # # # # # # # # # # ## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = " ## ## ## ### ## ### ######### #### ### #### ##### ### ## ### ## ### ## ### #### ### #### ###", .bitmap = " ## ## ## ### ## ### ######### "
"#### ### #### ##### ### ## ### ## ### ## "
"### #### ### #### ###",
}, },
{ {
.width = 2, .width = 2,
@ -208,12 +217,14 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 6, .width = 6,
.height = 13, .height = 13,
.bitmap = " #### ###### ## ## ## ## ## ## ## ## #### ####", .bitmap = " #### ###### ## ## ## ## ## ## ## "
"## #### ####",
}, },
{ {
.width = 6, .width = 6,
.height = 13, .height = 13,
.bitmap = "#### #### ## ## ## ## ## ## ## ## ###### #### ", .bitmap = "#### #### ## ## ## ## ## ## ## "
"## ###### #### ",
}, },
{ {
.width = 6, .width = 6,
@ -223,7 +234,8 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 9, .width = 9,
.height = 9, .height = 9,
.bitmap = " ## ## ## ## ################## ## ## ## ", .bitmap = " ## ## ## ## ################## ## "
" ## ## ",
}, },
{ {
.width = 2, .width = 2,
@ -243,57 +255,72 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " ## ## # # # # # # # # # # # ", .bitmap = " ## ## # # # # # "
" # # # # # # ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ###### ###### ###### ## ##### ## ###### ###### ##### ### #### #### ", .bitmap = " #### #### ## ##### ###### ###### ###### ## "
"##### ## ###### ###### ##### ### #### #### ",
}, },
{ {
.width = 6, .width = 6,
.height = 13, .height = 13,
.bitmap = " ## ## #### #### #### ## ## ## ## ## ## ############", .bitmap = " ## ## #### #### #### ## ## ## ## ## "
" ## ############",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ##### ##### ## ## ## ## ## ## ##################", .bitmap = " #### #### ## ##### ##### ##### ## "
"## ## ## ## ## ##################",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ##### ### ### ## ## ##### ##### ### #### #### ", .bitmap = " #### #### ## ##### ##### ### ### "
"## ## ##### ##### ### #### #### ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = " ### ### ##### ##### ####### ## ### ## ### ## ### ## ### #################### ### ### ", .bitmap =
" ### ### ##### ##### ####### ## ### ## "
"### ## ### ## ### #################### ### ### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "######### ######### ## ## ## ## ## ####### ####### # #### ### ######## ######## ", .bitmap = "######### ######### ## ## ## ## "
" ## ####### ####### # #### "
"### ######## ######## ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = " ##### ##### ## ## #### ## ## ####### ####### ## ##### ### ##### ##### ", .bitmap =
" ##### ##### ## ## #### ## ## "
" ####### ####### ## ##### ### ##### ##### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = "#################### ##### ##### ##### ## ## ## ## ## ## ## ## ", .bitmap = "#################### ##### ##### ##### ## "
"## ## ## ## ## ## ## ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ##### ##### ### #### #### ## ##### ##### ### #### #### ", .bitmap =
" #### #### ## ##### ##### ##### ### #### "
"#### ## ##### ##### ### #### #### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ##### ##### ##### ### ####### ####### ### ### #### #### ", .bitmap = " #### #### ## ##### ##### ##### ##### "
"### ####### ####### ### ### #### #### ",
}, },
{ {
.width = 2, .width = 2,
@ -313,7 +340,8 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 9, .width = 9,
.height = 7, .height = 7,
.bitmap = "########################### ##################", .bitmap =
"########################### ##################",
}, },
{ {
.width = 6, .width = 6,
@ -323,52 +351,73 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " #### #### ## ##### ##### ### ### ## ## ## ## ## ## ", .bitmap = " #### #### ## ##### ##### ### ### "
"## ## ## ## ## ## ",
}, },
{ {
.width = 15, .width = 15,
.height = 16, .height = 16,
.bitmap = " ########### ############# ## #### #### ###### #### ###### #### ###### #### ## ## #### ## ## #### ## ## #### ## ## #### ############# ######### ## ## ############# ########### ", .bitmap =
" ########### ############# ## #### #### "
"###### #### ###### #### ###### #### ## ## #### ## "
"## #### ## ## #### ## ## #### ############# ######### "
"## ## ############# ########### ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = " ##### ##### ## ##### ################################### ##### ##### ##### ##### ##### ###", .bitmap = " ##### ##### ## ##### "
"################################### ##### ##### "
"##### ##### ##### ###",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "######### ######### ## ##### ##### ##### ############ ######### ## ##### ##### ############ ######### ", .bitmap = "######### ######### ## ##### ##### ##### "
" ############ ######### ## ##### ##### "
"############ ######### ",
}, },
{ {
.width = 12, .width = 12,
.height = 13, .height = 13,
.bitmap = " ######### ######### ## #### #### #### ## ## ## ## #### ## ######### ######### ", .bitmap = " ######### ######### ## #### #### "
"#### ## ## ## ## "
"#### ## ######### ######### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "######### ######### ## ##### ##### ##### ##### ##### ##### ##### ##### ############ ######### ", .bitmap = "######### ######### ## ##### ##### ##### "
" ##### ##### ##### ##### ##### "
"############ ######### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "######################## ## ##### ##### ##### ## ## ## ## ######################", .bitmap = "######################## ## ##### "
"##### ##### ## ## ## ## "
" ######################",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = "###################### ## ###### ###### ###### ## ## ## ## ## ## ", .bitmap = "###################### ## ###### ###### "
"###### ## ## ## ## ## "
"## ",
}, },
{ {
.width = 12, .width = 12,
.height = 13, .height = 13,
.bitmap = " ########## ############ ## ## ####### ####### ####### #### #### #### ## ######## ######## ", .bitmap = " ########## ############ ## ## "
"####### ####### ####### #### #### "
" #### ## ######## ######## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ##### ##### ##### ##### ########################### ##### ##### ##### ##### ###", .bitmap = "## ##### ##### ##### ##### ##### "
" ########################### ##### ##### "
"##### ##### ###",
}, },
{ {
.width = 4, .width = 4,
@ -378,107 +427,144 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 7, .width = 7,
.height = 13, .height = 13,
.bitmap = " ## ## ## ## ## ## ## ## #### #### ## ### ### ", .bitmap = " ## ## ## ## ## ## ## ## "
" #### #### ## ### ### ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = "## ## ##### ##### ## ## ## ## ## ##### ##### ## ## ## ## ## ##### ##### ###", .bitmap =
"## ## ##### ##### ## ## ## ## ## ##### "
" ##### ## ## ## ## ## ##### ##### ###",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = "## ## ## ## ## ## ## ## ## ## ## ####################", .bitmap =
"## ## ## ## ## ## ## "
" ## ## ## ## ####################",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ####### ######### ################## ## ##### ## ##### ##### ##### ##### ##### ##### ###", .bitmap = "## ##### ####### ######### ################## "
"## ##### ## ##### ##### ##### ##### "
"##### ##### ###",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ####### ####### ##### ## ##### ## ##### ## ##### ####### ####### ##### ##### ##### ##### ###", .bitmap = "## ####### ####### ##### ## ##### ## ##### "
"## ##### ####### ####### ##### ##### "
"##### ##### ###",
}, },
{ {
.width = 13, .width = 13,
.height = 13, .height = 13,
.bitmap = " ######### ######### ## #### #### #### #### #### #### #### #### ## ######### ######### ", .bitmap = " ######### ######### ## #### #### "
" #### #### #### #### #### "
" #### ## ######### ######### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "######### ######### ## ##### ####################### ######### ## ## ## ## ## ## ", .bitmap = "######### ######### ## ##### "
"####################### ######### ## ## "
"## ## ## ## ",
}, },
{ {
.width = 13, .width = 13,
.height = 13, .height = 13,
.bitmap = " ######### ######### ## #### #### #### #### #### #### #### #### ### ## ######### ###########", .bitmap = " ######### ######### ## #### #### "
" #### #### #### #### #### "
" #### ### ## ######### ###########",
}, },
{ {
.width = 13, .width = 13,
.height = 13, .height = 13,
.bitmap = "########## ########## ## ## ## ## ############ ########## ########## ## ### ## ### ## ### ## ### ## #### ##", .bitmap = "########## ########## ## ## ## ## "
"############ ########## ########## ## ### ## "
"### ## ### ## ### ## #### ##",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = " ######## ########## ## ####### ##### ##### ### ### ### ########## ####### ", .bitmap = " ######## ########## ## ####### ##### "
" ##### ### ### ### ########## "
"####### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "###################### ## ## ## ## ## ## ## ## ## ## ## ", .bitmap = "###################### ## ## ## "
"## ## ## ## ## ## "
" ## ## ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = "## ##### ##### ##### ##### ##### ##### ##### ##### ##### ##### ### ###### ###### ", .bitmap =
"## ##### ##### ##### ##### ##### ##### "
" ##### ##### ##### ##### ### ###### ###### ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ##### ##### ##### ##### ### ## ### ## ### ## ### ## ## ## ## ", .bitmap = "## ##### ##### ##### ##### ##### "
" ### ## ### ## ### ## ### ## ## "
" ## ## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ##### ##### ##### ##### ##### ##### ## ##### ## ####### ######### ####### ##### ###", .bitmap = "## ##### ##### ##### ##### ##### "
" ##### ##### ## ##### ## ####### ######### "
"####### ##### ###",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ### ## ### ## ### ####### ## ## ## ### ## ### ## ##### ##### ##### ###", .bitmap = "## ##### ### ## ### ## ### ####### "
"## ## ## ### ## ### ## ##### "
"##### ##### ###",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ##### ### ## ### ## ### ####### ## ## ## ## ## ## ## ## ", .bitmap = "## ##### ### ## ### ## ### ####### "
"## ## ## ## ## ## "
" ## ## ",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "###################### ### ### ##### ### ### ## ## ## ## ######################", .bitmap = "###################### ### ### ##### "
" ### ### ## ## ## ## "
" ######################",
}, },
{ {
.width = 4, .width = 4,
.height = 16, .height = 16,
.bitmap = "########## ## ## ## ## ## ## ## ## ## ## ## ########", .bitmap =
"########## ## ## ## ## ## ## ## ## ## ## ## ########",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = "# # # # # # # # # # # # ##", .bitmap = "# # # # # # # "
" # # # # # ##",
}, },
{ {
.width = 4, .width = 4,
.height = 16, .height = 16,
.bitmap = "######## ## ## ## ## ## ## ## ## ## ## ## ##########", .bitmap =
"######## ## ## ## ## ## ## ## ## ## ## ## ##########",
}, },
{ {
.width = 9, .width = 9,
.height = 7, .height = 7,
.bitmap = " ## ## ## ## ## ## ### ##### ### ##", .bitmap =
" ## ## ## ## ## ## ### ##### ### ##",
}, },
{ {
.width = 10, .width = 10,
@ -493,42 +579,52 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 10, .width = 10,
.height = 10, .height = 10,
.bitmap = "####### ####### ####### ### ######## ########## ##### ### ######## ########", .bitmap = "####### ####### ####### ### ######## "
"########## ##### ### ######## ########",
}, },
{ {
.width = 11, .width = 11,
.height = 13, .height = 13,
.bitmap = "## ## ## ## ## ##### ## ##### ## ##### #### ####### ##### ##### ############ ######### ", .bitmap = "## ## ## ## ## ##### ## "
"##### ## ##### #### ####### ##### ##### "
"############ ######### ",
}, },
{ {
.width = 10, .width = 10,
.height = 10, .height = 10,
.bitmap = " ##### ##### ##### ## ##### ##### ## ##### ### ##### ##### ", .bitmap = " ##### ##### ##### ## ##### ##### "
"## ##### ### ##### ##### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " ### ### ### ####### ####### ######### ##### ##### ##### ##### #####################", .bitmap = " ### ### ### ####### ####### ######### "
"##### ##### ##### ##### #####################",
}, },
{ {
.width = 9, .width = 9,
.height = 10, .height = 10,
.bitmap = " ####### ####### ######### ################## ## ## ### ####### #######", .bitmap = " ####### ####### ######### ################## ## "
" ## ### ####### #######",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " ##### ##### ## ########################### ## ## ## ## ## ## ## ", .bitmap = " ##### ##### ## ########################### ## "
" ## ## ## ## ## ## ",
}, },
{ {
.width = 9, .width = 9,
.height = 14, .height = 14,
.bitmap = " ####### ####### ######### ##### ### ####### ####### ### ### ##### ##### ### #### #### ", .bitmap =
" ####### ####### ######### ##### ### ####### ####### "
" ### ### ##### ##### ### #### #### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = "## ## ## ## ## ## ## ## ## ## #### ####### ##### ##### ##### ##### ###", .bitmap = "## ## ## ## ## ## ## ## ## "
"## #### ####### ##### ##### ##### ##### ###",
}, },
{ {
.width = 2, .width = 2,
@ -538,12 +634,14 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 7, .width = 7,
.height = 13, .height = 13,
.bitmap = " ## ## ## ## ## ## ## #### #### ## ### ### ", .bitmap = " ## ## ## ## ## ## ## "
" #### #### ## ### ### ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = "## ## ## ##### ##### ####### ## ## ## #### #### ## ## ## ## ## ##### ###", .bitmap = "## ## ## ##### ##### ####### ## ## "
"## #### #### ## ## ## ## ## ##### ###",
}, },
{ {
.width = 2, .width = 2,
@ -553,77 +651,95 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 15, .width = 15,
.height = 10, .height = 10,
.bitmap = "###### ##### ###### ##### ###### ##### ## ### #### ### #### ### #### ### #### ### #### ### #### ### ##", .bitmap = "###### ##### ###### ##### ###### ##### ## ### "
"#### ### #### ### #### ### #### ### "
"#### ### #### ### ##",
}, },
{ {
.width = 10, .width = 10,
.height = 10, .height = 10,
.bitmap = "####### ####### ####### ## ##### ##### ##### ##### ##### ##### ###", .bitmap = "####### ####### ####### ## ##### ##### "
"##### ##### ##### ##### ###",
}, },
{ {
.width = 9, .width = 9,
.height = 10, .height = 10,
.bitmap = " #### #### #### ## ##### ##### ##### ##### ### #### #### ", .bitmap = " #### #### #### ## ##### ##### ##### "
"##### ### #### #### ",
}, },
{ {
.width = 10, .width = 10,
.height = 13, .height = 13,
.bitmap = "## ### ## ### ## ### #### ####### ##### ##### ########## ####### ## ## ## ## ", .bitmap =
"## ### ## ### ## ### #### ####### ##### ##### "
" ########## ####### ## ## ## ## ",
}, },
{ {
.width = 9, .width = 9,
.height = 13, .height = 13,
.bitmap = " ### ### ####### ######### ###### ##### ##### ##### ### ####### ####### ### ### ###", .bitmap = " ### ### ####### ######### ###### ##### ##### "
"##### ### ####### ####### ### ### ###",
}, },
{ {
.width = 7, .width = 7,
.height = 10, .height = 10,
.bitmap = "## ### ################# ### ## ## ## ## ## ", .bitmap = "## ### ################# ### ## ## ## ## "
" ## ",
}, },
{ {
.width = 7, .width = 7,
.height = 11, .height = 11,
.bitmap = " ##### ############## ## ### ### ## ####### ##### ", .bitmap = " ##### ############## ## ### ### ## "
" ####### ##### ",
}, },
{ {
.width = 5, .width = 5,
.height = 12, .height = 12,
.bitmap = " ## ## #### #### #### ## ## ## ## ## ## ##", .bitmap =
" ## ## #### #### #### ## ## ## ## ## ## ##",
}, },
{ {
.width = 9, .width = 9,
.height = 10, .height = 10,
.bitmap = "## ##### ##### ##### ##### ##### ##### ##### ### ####### #######", .bitmap = "## ##### ##### ##### ##### ##### ##### "
"##### ### ####### #######",
}, },
{ {
.width = 11, .width = 11,
.height = 7, .height = 7,
.bitmap = "## ##### ##### ### ## ### ## ### ## ## ", .bitmap = "## ##### ##### ### ## ### ## ### "
"## ## ",
}, },
{ {
.width = 12, .width = 12,
.height = 9, .height = 9,
.bitmap = "## #### #### #### #### ## #### ## #### ## ## ########## ##########", .bitmap = "## #### #### #### #### ## "
"#### ## #### ## ## ########## ##########",
}, },
{ {
.width = 11, .width = 11,
.height = 11, .height = 11,
.bitmap = "## ##### ####### ##### ## ### ## ### ## ## ## ### ## ### ## ##### ###", .bitmap =
"## ##### ####### ##### ## ### ## ### ## "
" ## ## ### ## ### ## ##### ###",
}, },
{ {
.width = 9, .width = 9,
.height = 12, .height = 12,
.bitmap = "## ##### ##### ##### ##### ##### ### ####### ####### ### ######### ###### ", .bitmap = "## ##### ##### ##### ##### ##### ### "
"####### ####### ### ######### ###### ",
}, },
{ {
.width = 9, .width = 9,
.height = 11, .height = 11,
.bitmap = "########################### ## ## ## ## ## ## ##################", .bitmap = "########################### ## ## ## ## "
" ## ## ##################",
}, },
{ {
.width = 5, .width = 5,
.height = 17, .height = 17,
.bitmap = " ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##", .bitmap = " ## ## ## ## ## ## ## ## ## ## ## ## "
" ## ## ## ## ##",
}, },
{ {
.width = 2, .width = 2,
@ -633,7 +749,8 @@ struct font minecraft_medium_13_font[] = {\
{ {
.width = 5, .width = 5,
.height = 17, .height = 17,
.bitmap = "## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ", .bitmap = "## ## ## ## ## ## ## ## ## ## ## ## "
" ## ## ## ## ## ",
}, },
{ {
.width = 11, .width = 11,

View File

@ -1,15 +1,15 @@
#pragma once #pragma once
#include "tss.h" #include "tss.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define GDT_SIZE 8 #define GDT_SIZE 8
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR // https://wiki.osdev.org/Global_Descriptor_Table#GDTR
struct gdt_descriptor { struct gdt_descriptor {
u16 size; uint16_t size;
u32 base; uint32_t base;
} __attribute__((packed)); } __attribute__((packed));
extern struct tss TSS; extern struct tss TSS;
@ -34,7 +34,7 @@ void init_gdt();
#define GDT_ACCESS_A_ACCESSED 0b00000001 #define GDT_ACCESS_A_ACCESSED 0b00000001
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000 #define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
extern u8 gdt_entries[GDT_SIZE * 8]; extern uint8_t gdt_entries[GDT_SIZE * 8];
#define GDT_OFFSET_KERNEL_CODE 0x08 #define GDT_OFFSET_KERNEL_CODE 0x08
#define GDT_OFFSET_KERNEL_DATA 0x10 #define GDT_OFFSET_KERNEL_DATA 0x10

View File

@ -1,10 +1,9 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct icon { struct icon {
u32 height; uint32_t height;
u32 width; uint32_t width;
u32 *pixels; uint32_t *pixels;
}; };

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,20 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
// doc : https://wiki.osdev.org/Interrupt_Descriptor_Table#IDTR // doc : https://wiki.osdev.org/Interrupt_Descriptor_Table#IDTR
struct idt_descriptor { struct idt_descriptor {
u16 size; uint16_t size;
u32 offset; uint32_t offset;
} __attribute__((packed)); } __attribute__((packed));
struct idt_entry { struct idt_entry {
u16 isr_low; // The lower 16 bits of the ISR's address uint16_t isr_low; // The lower 16 bits of the ISR's address
u16 kernel_cs; // The GDT segment selector that the CPU will load uint16_t kernel_cs; // The GDT segment selector that the CPU will load
// into CS before calling the ISR // into CS before calling the ISR
u8 reserved; // Set to zero uint8_t reserved; // Set to zero
u8 attributes; // Type and attributes; see the IDT page uint8_t attributes; // Type and attributes; see the IDT page
u16 isr_high; // The higher 16 bits of the ISR's address uint16_t isr_high; // The higher 16 bits of the ISR's address
} __attribute__((packed)); } __attribute__((packed));
#define IDT_SIZE 256 #define IDT_SIZE 256

View File

@ -1,23 +1,22 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct registers { struct registers {
// data segment selector // data segment selector
u32 ds; uint32_t ds;
// general purpose registers pushed by pusha // general purpose registers pushed by pusha
u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
// pushed by isr procedure // pushed by isr procedure
u32 int_no, err_code; uint32_t int_no, err_code;
// pushed by CPU automatically // pushed by CPU automatically
u32 eip, cs, eflags, useresp, ss; uint32_t eip, cs, eflags, useresp, ss;
}; };
typedef void (*isr_t)(struct registers *); typedef void (*isr_t)(struct registers *);
void isr_handler(struct registers *regs); void isr_handler(struct registers *regs);
void pic_send_eoi(u8 irq); void pic_send_eoi(uint8_t irq);
void register_interrupt_handler(int index, isr_t handler); void register_interrupt_handler(int index, isr_t handler);
static inline void cli(void) static inline void cli(void)

View File

@ -1,10 +1,37 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
[[__maybe_unused__]] static const char *keymap[128] = { [[__maybe_unused__]] static const char *azerty_keymap[128] = {
[2] = "&1", [3] = "é2", [4] = "\"3", [5] = "'4", [6] = "(5",
[7] = "-6", [8] = "è7", [9] = "_8", [10] = "ç9", [11] = "à0",
[12] = "", [13] = "=+", [14] = NULL, [15] = NULL, [16] = "aA",
[17] = "zZ", [18] = "eE", [19] = "rR", [20] = "tT", [21] = "yY",
[22] = "uU", [23] = "iI", [24] = "oO", [25] = "pP", [26] = "",
[27] = "", [28] = "\n\n", [30] = "qQ", [31] = "sS", [32] = "dD",
[33] = "fF", [34] = "gG", [35] = "hH", [36] = "jJ", [37] = "kK",
[38] = "lL", [39] = "mM", [40] = "ù%", [41] = NULL, [42] = NULL,
[43] = "", [44] = "wW", [45] = "xX", [46] = "cC", [47] = "vV",
[48] = "bB", [49] = "nN", [50] = ",?", [51] = ";.", [52] = ":/",
[53] = "", [54] = NULL, [55] = NULL, [56] = NULL, [57] = " ",
[58] = NULL, [59] = NULL, [60] = NULL, [61] = NULL, [62] = NULL,
[63] = NULL, [64] = NULL, [65] = NULL, [66] = NULL, [67] = NULL,
[68] = NULL, [69] = NULL, [70] = NULL, [71] = NULL, [72] = NULL,
[73] = NULL, [74] = NULL, [75] = NULL, [76] = NULL, [77] = NULL,
[78] = NULL, [79] = NULL, [80] = NULL, [81] = NULL, [82] = NULL,
[83] = NULL, [84] = NULL, [85] = NULL, [86] = NULL, [87] = NULL,
[88] = NULL, [89] = NULL, [90] = NULL, [91] = NULL, [92] = NULL,
[93] = NULL, [94] = NULL, [95] = NULL, [96] = NULL, [97] = NULL,
[98] = NULL, [99] = NULL, [100] = NULL, [101] = NULL, [102] = NULL,
[103] = NULL, [104] = NULL, [105] = NULL, [106] = NULL, [107] = NULL,
[108] = NULL, [109] = NULL, [110] = NULL, [111] = NULL, [112] = NULL,
[113] = NULL, [114] = NULL, [115] = NULL, [116] = NULL, [117] = NULL,
[118] = NULL, [119] = NULL, [120] = NULL, [121] = NULL, [122] = NULL,
[123] = NULL, [124] = NULL, [125] = NULL, [126] = NULL, [127] = NULL,
};
[[__maybe_unused__]] static const char *qwerty_keymap[128] = {
[2] = "1!", [3] = "2@", [4] = "3#", [5] = "4$", [6] = "5%", [2] = "1!", [3] = "2@", [4] = "3#", [5] = "4$", [6] = "5%",
[7] = "6^", [8] = "7&", [9] = "8*", [10] = "9(", [11] = "0)", [7] = "6^", [8] = "7&", [9] = "8*", [10] = "9(", [11] = "0)",
[12] = "-_", [13] = "=+", [14] = NULL, [15] = NULL, [16] = "qQ", [12] = "-_", [13] = "=+", [14] = NULL, [15] = NULL, [16] = "qQ",
@ -117,8 +144,8 @@
#define KEY_CAPSLOCK 0x3A #define KEY_CAPSLOCK 0x3A
struct key_event { struct key_event {
u8 c; uint8_t c;
u8 scan_code; uint8_t scan_code;
}; };
struct key_event get_key(void); struct key_event get_key(void);

View File

@ -1,7 +1,7 @@
#pragma once #pragma once
#include "multiboot.h" #include "multiboot.h"
#include "types.h" #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -16,13 +16,13 @@
#define PD_SIZE 1024 #define PD_SIZE 1024
#define PAGE_MASK 0xFFFFF000 #define PAGE_MASK 0xFFFFF000
#define HEAP_END 0xC0000000 #define HEAP_END 0xC0000000
#define HEAP_START ((u32) & _kernel_end - HEAP_END) #define HEAP_START ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_START ((u32) & _kernel_start) #define KERNEL_START ((uint32_t)&_kernel_start)
#define KERNEL_END ((u32) & _kernel_end - HEAP_END) #define KERNEL_END ((uint32_t)&_kernel_end - HEAP_END)
#define PT_START 256 #define PT_START 256
#define GET_PAGE_ADDR(pd_index, pt_index) \ #define GET_PAGE_ADDR(pd_index, pt_index) \
((((u32)pd_index * 1024) + (u32)pt_index) * 4096) ((((uint32_t)pd_index * 1024) + (uint32_t)pt_index) * 4096)
#define GET_FRAME(frame_table, i) (frame_table[i / 8] & (1 << (i % 8))) #define GET_FRAME(frame_table, i) (frame_table[i / 8] & (1 << (i % 8)))
#define SET_FRAME(frame_table, i, used) \ #define SET_FRAME(frame_table, i, used) \
@ -35,29 +35,32 @@
struct frame_zone { struct frame_zone {
void *addr; void *addr;
u32 first_free_frame; uint32_t first_free_frame;
u8 *frame_table; uint8_t *frame_table;
u32 total_frames; uint32_t total_frames;
u32 remaining_frames; uint32_t remaining_frames;
struct frame_zone *next; struct frame_zone *next;
}; };
extern u32 _kernel_end; extern uint32_t _kernel_end;
extern u32 _kernel_start; extern uint32_t _kernel_start;
extern u32 boot_page_directory; extern uint32_t boot_page_directory;
extern u32 *page_directory; extern uint32_t boot_page_table1;
extern u32 page_table_default[1024]; extern uint32_t *kernel_pd;
extern u32 mem_size; extern uint32_t *current_pd;
extern uint32_t page_table_default[1024];
extern uint32_t mem_size;
extern multiboot_memory_map_t *mmap_addr; extern multiboot_memory_map_t *mmap_addr;
extern multiboot_u32 mmap_length; extern multiboot_uint32_t mmap_length;
extern struct frame_zone *head; extern struct frame_zone *head;
u32 *virt_to_phys(u32 *virt_addr); uint32_t *virt_to_phys(uint32_t *virt_addr);
void init_memory(multiboot_info_t *mbd, u32 magic); void init_memory(multiboot_info_t *mbd, uint32_t magic);
void *alloc_frame(void); void *alloc_frame(void);
int free_frame(void *frame_ptr); int free_frame(void *frame_ptr);
i8 add_single_page(void *frame); int8_t add_single_page(void *frame);
void *alloc_pages(size_t size, void **phys_addr); void *alloc_pages(size_t size, void **phys_addr);
int free_pages(void *page_ptr, size_t size); int free_pages(void *page_ptr, size_t size);
void init_page_table(u32 page_table[1024], u16 start); void init_page_table(uint32_t page_table[1024], uint16_t start);
int16_t add_page_table(u16 pd_index); int16_t add_page_table(uint16_t pd_index);
void switch_pd(uint32_t *pd, uint32_t *cr3);

View File

@ -93,71 +93,71 @@
#ifndef ASM_FILE #ifndef ASM_FILE
typedef unsigned char multiboot_u8; typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_u16; typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_u32; typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_u64; typedef unsigned long long multiboot_uint64_t;
struct multiboot_header { struct multiboot_header {
/* Must be MULTIBOOT_MAGIC - see above. */ /* Must be MULTIBOOT_MAGIC - see above. */
multiboot_u32 magic; multiboot_uint32_t magic;
/* Feature flags. */ /* Feature flags. */
multiboot_u32 flags; multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */ /* The above fields plus this one must equal 0 mod 2^32. */
multiboot_u32 checksum; multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_u32 header_addr; multiboot_uint32_t header_addr;
multiboot_u32 load_addr; multiboot_uint32_t load_addr;
multiboot_u32 load_end_addr; multiboot_uint32_t load_end_addr;
multiboot_u32 bss_end_addr; multiboot_uint32_t bss_end_addr;
multiboot_u32 entry_addr; multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_u32 mode_type; multiboot_uint32_t mode_type;
multiboot_u32 width; multiboot_uint32_t width;
multiboot_u32 height; multiboot_uint32_t height;
multiboot_u32 depth; multiboot_uint32_t depth;
}; };
/* The symbol table for a.out. */ /* The symbol table for a.out. */
struct multiboot_aout_symbol_table { struct multiboot_aout_symbol_table {
multiboot_u32 tabsize; multiboot_uint32_t tabsize;
multiboot_u32 strsize; multiboot_uint32_t strsize;
multiboot_u32 addr; multiboot_uint32_t addr;
multiboot_u32 reserved; multiboot_uint32_t reserved;
}; };
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */ /* The section header table for ELF. */
struct multiboot_elf_section_header_table { struct multiboot_elf_section_header_table {
multiboot_u32 num; multiboot_uint32_t num;
multiboot_u32 size; multiboot_uint32_t size;
multiboot_u32 addr; multiboot_uint32_t addr;
multiboot_u32 shndx; multiboot_uint32_t shndx;
}; };
typedef struct multiboot_elf_section_header_table typedef struct multiboot_elf_section_header_table
multiboot_elf_section_header_table_t; multiboot_elf_section_header_table_t;
struct multiboot_info { struct multiboot_info {
/* Multiboot info version number */ /* Multiboot info version number */
multiboot_u32 flags; multiboot_uint32_t flags;
/* Available memory from BIOS */ /* Available memory from BIOS */
multiboot_u32 mem_lower; multiboot_uint32_t mem_lower;
multiboot_u32 mem_upper; multiboot_uint32_t mem_upper;
/* "root" partition */ /* "root" partition */
multiboot_u32 boot_device; multiboot_uint32_t boot_device;
/* Kernel command line */ /* Kernel command line */
multiboot_u32 cmdline; multiboot_uint32_t cmdline;
/* Boot-Module list */ /* Boot-Module list */
multiboot_u32 mods_count; multiboot_uint32_t mods_count;
multiboot_u32 mods_addr; multiboot_uint32_t mods_addr;
union { union {
multiboot_aout_symbol_table_t aout_sym; multiboot_aout_symbol_table_t aout_sym;
@ -165,105 +165,104 @@ struct multiboot_info {
} u; } u;
/* Memory Mapping buffer */ /* Memory Mapping buffer */
multiboot_u32 mmap_length; multiboot_uint32_t mmap_length;
multiboot_u32 mmap_addr; multiboot_uint32_t mmap_addr;
/* Drive Info buffer */ /* Drive Info buffer */
multiboot_u32 drives_length; multiboot_uint32_t drives_length;
multiboot_u32 drives_addr; multiboot_uint32_t drives_addr;
/* ROM configuration table */ /* ROM configuration table */
multiboot_u32 config_table; multiboot_uint32_t config_table;
/* Boot Loader Name */ /* Boot Loader Name */
multiboot_u32 boot_loader_name; multiboot_uint32_t boot_loader_name;
/* APM table */ /* APM table */
multiboot_u32 apm_table; multiboot_uint32_t apm_table;
/* Video */ /* Video */
multiboot_u32 vbe_control_info; multiboot_uint32_t vbe_control_info;
multiboot_u32 vbe_mode_info; multiboot_uint32_t vbe_mode_info;
multiboot_u16 vbe_mode; multiboot_uint16_t vbe_mode;
multiboot_u16 vbe_interface_seg; multiboot_uint16_t vbe_interface_seg;
multiboot_u16 vbe_interface_off; multiboot_uint16_t vbe_interface_off;
multiboot_u16 vbe_interface_len; multiboot_uint16_t vbe_interface_len;
multiboot_u64 framebuffer_addr; multiboot_uint64_t framebuffer_addr;
multiboot_u32 framebuffer_pitch; multiboot_uint32_t framebuffer_pitch;
multiboot_u32 framebuffer_width; multiboot_uint32_t framebuffer_width;
multiboot_u32 framebuffer_height; multiboot_uint32_t framebuffer_height;
multiboot_u8 framebuffer_bpp; multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_u8 framebuffer_type; multiboot_uint8_t framebuffer_type;
union { union {
struct { struct {
multiboot_u32 framebuffer_palette_addr; multiboot_uint32_t framebuffer_palette_addr;
multiboot_u16 framebuffer_palette_num_colors; multiboot_uint16_t framebuffer_palette_num_colors;
}; };
struct { struct {
multiboot_u8 framebuffer_red_field_position; multiboot_uint8_t framebuffer_red_field_position;
multiboot_u8 framebuffer_red_mask_size; multiboot_uint8_t framebuffer_red_mask_size;
multiboot_u8 framebuffer_green_field_position; multiboot_uint8_t framebuffer_green_field_position;
multiboot_u8 framebuffer_green_mask_size; multiboot_uint8_t framebuffer_green_mask_size;
multiboot_u8 framebuffer_blue_field_position; multiboot_uint8_t framebuffer_blue_field_position;
multiboot_u8 framebuffer_blue_mask_size; multiboot_uint8_t framebuffer_blue_mask_size;
}; };
}; };
}; };
typedef struct multiboot_info multiboot_info_t; typedef struct multiboot_info multiboot_info_t;
struct multiboot_color { struct multiboot_color {
multiboot_u8 red; multiboot_uint8_t red;
multiboot_u8 green; multiboot_uint8_t green;
multiboot_u8 blue; multiboot_uint8_t blue;
}; };
struct multiboot_mmap_entry { struct multiboot_mmap_entry {
multiboot_u32 size; multiboot_uint32_t size;
multiboot_u64 addr; multiboot_uint64_t addr;
multiboot_u64 len; multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5 #define MULTIBOOT_MEMORY_BADRAM 5
multiboot_u32 type; multiboot_uint32_t type;
} __attribute__((packed)); } __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t; typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list { struct multiboot_mod_list {
/* the memory used goes from bytes mod_start to mod_end-1 inclusive /* the memory used goes from bytes mod_start to mod_end-1 inclusive
*/ */
multiboot_u32 mod_start; multiboot_uint32_t mod_start;
multiboot_u32 mod_end; multiboot_uint32_t mod_end;
/* Module command line */ /* Module command line */
multiboot_u32 cmdline; multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */ /* padding to take it to 16 bytes (must be zero) */
multiboot_u32 pad; multiboot_uint32_t pad;
}; };
typedef struct multiboot_mod_list multiboot_module_t; typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */ /* APM BIOS info. */
struct multiboot_apm_info { struct multiboot_apm_info {
multiboot_u16 version; multiboot_uint16_t version;
multiboot_u16 cseg; multiboot_uint16_t cseg;
multiboot_u32 offset; multiboot_uint32_t offset;
multiboot_u16 cseg_16; multiboot_uint16_t cseg_16;
multiboot_u16 dseg; multiboot_uint16_t dseg;
multiboot_u16 flags; multiboot_uint16_t flags;
multiboot_u16 cseg_len; multiboot_uint16_t cseg_len;
multiboot_u16 cseg_16_len; multiboot_uint16_t cseg_16_len;
multiboot_u16 dseg_len; multiboot_uint16_t dseg_len;
}; };
#endif /* ! ASM_FILE */ #endif /* ! ASM_FILE */
#include "types.h"
#include <stdint.h> #include <stdint.h>
void init_multiboot(multiboot_info_t *mbd, u32 magic); void init_multiboot(multiboot_info_t *mbd, uint32_t magic);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define SECOND_REGISTER 0x00 #define SECOND_REGISTER 0x00
@ -18,14 +17,14 @@
enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 }; enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 };
struct rtc_date { struct rtc_date {
u8 second; uint8_t second;
u8 minute; uint8_t minute;
u8 hour; uint8_t hour;
u8 index_of_the_day; uint8_t index_of_the_day;
u8 day; uint8_t day;
u8 month; uint8_t month;
u32 year; uint32_t year;
}; };
struct rtc_date get_date(void); struct rtc_date get_date(void);

View File

@ -1,9 +1,12 @@
#pragma once #pragma once
#define SIG_DFL -1 #include <stdbool.h>
#define SIG_IGN 0 #include <stdint.h>
enum { #define SIG_DFL 0
#define SIG_IGN -1
typedef enum {
SIGABRT, // Abort signal from abort(3) SIGABRT, // Abort signal from abort(3)
SIGALRM, // Timer signal from alarm(2) SIGALRM, // Timer signal from alarm(2)
SIGBUS, // Bus error (bad memory access) SIGBUS, // Bus error (bad memory access)
@ -44,11 +47,16 @@ enum {
SIGXFSZ, // File size limit exceeded (4.2BSD); see setrlimit(2) SIGXFSZ, // File size limit exceeded (4.2BSD); see setrlimit(2)
SIGWINCH, // Window resize signal (4.3BSD, Sun) SIGWINCH, // Window resize signal (4.3BSD, Sun)
SIG_INT, // Interrupt from keyboard SIG_INT, // Interrupt from keyboard
}; LAST
} SIGNAL_CODE;
typedef void (*sighandler_t)(int); typedef void (*signal_handler_t)(int);
struct signal { void signal(SIGNAL_CODE sig_num, void *handler);
int signum; void kill(int pid, SIGNAL_CODE sig_num);
sighandler_t handler; void exec_signal_pending(void);
struct signal_data {
void *handlers[LAST];
uint32_t pending;
}; };

View File

@ -2,7 +2,7 @@
#include "list.h" #include "list.h"
#include "memory.h" #include "memory.h"
#include "types.h" #include "signal.h"
#include <stdint.h> #include <stdint.h>
@ -14,30 +14,31 @@ enum owner { OWNER_KERNEL, OWNER_USER };
#define STACK_SIZE PAGE_SIZE * 4 #define STACK_SIZE PAGE_SIZE * 4
struct task { struct task {
u8 *esp; uint8_t *esp;
u8 *esp0; uint8_t *esp0;
u32 *cr3; // physical uint32_t *cr3; // physical
u32 *heap; // virtual uint32_t *heap; // virtual
u32 *eip; uint32_t *eip;
u16 pid; uint16_t pid;
u8 status; uint8_t status;
u8 uid; uint8_t uid;
struct task *daddy; struct task *daddy;
struct task *child; struct task *child;
struct list **signals; struct signal_data signals;
struct task *next; struct task *next;
struct task *prev; struct task *prev;
}; };
void scheduler(void); void scheduler(void);
void switch_to_task(struct task *next_task); void switch_to_task(struct task *next_task);
struct task *create_task(u8 uid); struct task *create_task(uint8_t uid);
i8 create_kernel_task(void); int8_t create_kernel_task(void);
void remove_task(struct task *task); void remove_task(struct task *task);
struct task *copy_task(const struct task *task); struct task *copy_task(const struct task *task);
void kfork(struct task *daddy); void kfork(struct task *daddy);
void zombify_task(struct task *task);
// utils // utils
void exec_fn(void (*fn)(void)); void exec_fn(void (*fn)(void));
u16 fork(void); uint16_t fork(void);
u16 wait(void); uint16_t wait(void);

View File

@ -3,7 +3,7 @@
#include "font.h" #include "font.h"
#include "icon.h" #include "icon.h"
#include "keyboard.h" #include "keyboard.h"
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -19,10 +19,10 @@
struct screen { struct screen {
size_t row; size_t row;
size_t column; size_t column;
u32 fg_color; uint32_t fg_color;
u32 bg_color; uint32_t bg_color;
u8 buffer[VGA_WIDTH * VGA_HEIGHT]; uint8_t buffer[VGA_WIDTH * VGA_HEIGHT];
u32 default_color; uint32_t default_color;
struct icon *background; struct icon *background;
struct font *font; struct font *font;
char line[256]; char line[256];
@ -50,8 +50,8 @@ typedef enum {
enum cursor_direction { LEFT, RIGHT, UP, DOWN }; enum cursor_direction { LEFT, RIGHT, UP, DOWN };
void terminal_initialize(void); void terminal_initialize(void);
void terminal_set_bg_color(u32 color); void terminal_set_bg_color(uint32_t color);
void terminal_set_fg_color(u32 color); void terminal_set_fg_color(uint32_t color);
int terminal_putchar(char c); int terminal_putchar(char c);
int terminal_write(const char *data, size_t size); int terminal_write(const char *data, size_t size);
int terminal_writestring(const char *data); int terminal_writestring(const char *data);
@ -63,9 +63,9 @@ struct key_event terminal_getkey(void);
void update_cursor(void); void update_cursor(void);
void move_cursor(int direction); void move_cursor(int direction);
void set_color_level(int level); void set_color_level(int level);
void terminal_set_default_fg_color(u32 fg_color); void terminal_set_default_fg_color(uint32_t fg_color);
void terminal_set_default_bg_color(u32 fg_color); void terminal_set_default_bg_color(uint32_t fg_color);
void terminal_change_default_fg_color(u32 color); void terminal_change_default_fg_color(uint32_t color);
u32 terminal_get_default_color(void); uint32_t terminal_get_default_color(void);
u8 terminal_get_char(int column, int row); uint8_t terminal_get_char(int column, int row);
void terminal_remove_last_char(void); void terminal_remove_last_char(void);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
void sleep(u64 delay); void sleep(uint64_t delay);

View File

@ -1,61 +1,60 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
// _h fields are for the offset // _h fields are for the offset
struct tss { struct tss {
u16 link; uint16_t link;
u16 link_h; uint16_t link_h;
u32 esp0; uint32_t esp0;
u16 ss0; uint16_t ss0;
u16 ss0_h; uint16_t ss0_h;
u32 esp1; uint32_t esp1;
u16 ss1; uint16_t ss1;
u16 ss1_h; uint16_t ss1_h;
u32 esp2; uint32_t esp2;
u16 ss2; uint16_t ss2;
u16 ss2_h; uint16_t ss2_h;
u32 cr3; uint32_t cr3;
u32 eip; uint32_t eip;
u32 eflags; uint32_t eflags;
u32 eax; uint32_t eax;
u32 ecx; uint32_t ecx;
u32 edx; uint32_t edx;
u32 ebx; uint32_t ebx;
u32 esp; uint32_t esp;
u32 ebp; uint32_t ebp;
u32 esi; uint32_t esi;
u32 edi; uint32_t edi;
u16 es; uint16_t es;
u16 es_h; uint16_t es_h;
u16 cs; uint16_t cs;
u16 cs_h; uint16_t cs_h;
u16 ss; uint16_t ss;
u16 ss_h; uint16_t ss_h;
u16 ds; uint16_t ds;
u16 ds_h; uint16_t ds_h;
u16 fs; uint16_t fs;
u16 fs_h; uint16_t fs_h;
u16 gs; uint16_t gs;
u16 gs_h; uint16_t gs_h;
u16 ldt; uint16_t ldt;
u16 ldt_h; uint16_t ldt_h;
u16 trap; uint16_t trap;
u16 iomap; uint16_t iomap;
}; };

View File

@ -1,18 +1,18 @@
#pragma once #pragma once
#include "icon.h" #include "icon.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct vbe_interface { struct vbe_interface {
u32 *buff; uint32_t *buff;
u16 height; uint16_t height;
u16 width; uint16_t width;
u32 pitch; uint32_t pitch;
u8 bpp; uint8_t bpp;
}; };
extern struct vbe_interface display; extern struct vbe_interface display;
void draw_icon(u32 pos_x, u32 pos_y, struct icon *img); void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img);
void put_pixel(u32 color, u32 x, u32 y); void put_pixel(uint32_t color, uint32_t x, uint32_t y);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
char *strchr(const char *str, int c); char *strchr(const char *str, int c);

View File

@ -1,29 +1,28 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
static inline void outb(u16 port, u8 val) static inline void outb(uint16_t port, uint8_t val)
{ {
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory"); __asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
} }
static inline u8 inb(u16 port) static inline uint8_t inb(uint16_t port)
{ {
u8 ret; uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory"); __asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret; return ret;
} }
static inline void outw(u16 port, u16 val) static inline void outw(uint16_t port, uint16_t val)
{ {
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory"); __asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
} }
static inline u16 inw(u16 port) static inline uint16_t inw(uint16_t port)
{ {
u8 ret; uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory"); __asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret; return ret;
} }

View File

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
// Unsigned int
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
// Int
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef int8_t i8;

View File

@ -1,11 +1,11 @@
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
void *memcpy(void *dest, const void *src, size_t n) void *memcpy(void *dest, const void *src, size_t n)
{ {
u8 *c1 = (u8 *)dest; uint8_t *c1 = (uint8_t *)dest;
const u8 *c2 = (const u8 *)src; const uint8_t *c2 = (const uint8_t *)src;
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
c1[i] = c2[i]; c1[i] = c2[i];

View File

@ -1,10 +1,10 @@
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
void *memset(void *str, int c, size_t n) void *memset(void *str, int c, size_t n)
{ {
u8 *c1 = (u8 *)str; uint8_t *c1 = (uint8_t *)str;
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
c1[i] = c; c1[i] = c;

9
libbozo/src/types.sh Executable file
View File

@ -0,0 +1,9 @@
# !/bin/bash
sed -i 's/u8/uint8_t/g' **/*.c
sed -i 's/i8/int8_t/g' **/*.c
sed -i 's/u16/uint16_t/g' **/*.c
sed -i 's/i16/int16_t/g' **/*.c
sed -i 's/u32/uint32_t/g' **/*.c
sed -i 's/i32/int32_t/g' **/*.c
sed -i 's/u64/uint64_t/g' **/*.c
sed -i 's/i64/int64_t/g' **/*.c

View File

@ -13,8 +13,8 @@
#define PIT_COUNT (65535 / 2) #define PIT_COUNT (65535 / 2)
#define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT)) #define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
static u32 sleep_counter; static uint32_t sleep_counter;
static u32 scheduler_counter; static uint32_t scheduler_counter;
static void clock_handler(struct registers *regs); static void clock_handler(struct registers *regs);
@ -38,13 +38,13 @@ void clock_init(struct registers *regs)
static void clock_handler(struct registers *regs) static void clock_handler(struct registers *regs)
{ {
(void)regs; (void)regs;
if (scheduler_counter % 100 == 0) if (scheduler_counter % 10 == 0)
scheduler(); scheduler();
scheduler_counter++; scheduler_counter++;
sleep_counter--; sleep_counter--;
} }
void sleep(u64 delay) void sleep(uint64_t delay)
{ {
sleep_counter = delay / DELAY; sleep_counter = delay / DELAY;
while (sleep_counter) while (sleep_counter)

View File

@ -3,17 +3,17 @@
struct vbe_interface display; struct vbe_interface display;
void put_pixel(u32 color, u32 x, u32 y) void put_pixel(uint32_t color, uint32_t x, uint32_t y)
{ {
// divide by 4 because display.buff is in 32bit instead of 8bit // divide by 4 because display.buff is in 32bit instead of 8bit
const u32 coords = x + y * display.pitch / 4; const uint32_t coords = x + y * display.pitch / 4;
display.buff[coords] = color; display.buff[coords] = color;
} }
void draw_icon(u32 pos_x, u32 pos_y, struct icon *img) void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img)
{ {
for (u32 y = 0; y < img->height; y++) { for (uint32_t y = 0; y < img->height; y++) {
for (u32 x = 0; x < img->width; x++) { for (uint32_t x = 0; x < img->width; x++) {
put_pixel(img->pixels[y * img->width + x], pos_x + x, put_pixel(img->pixels[y * img->width + x], pos_x + x,
pos_y + y); pos_y + y);
} }

View File

@ -3,14 +3,14 @@
#include "gdt.h" #include "gdt.h"
#include "kprintf.h" #include "kprintf.h"
extern void set_gdt(u32 gdt_ptr); extern void set_gdt(uint32_t gdt_ptr);
struct tss TSS; struct tss TSS;
u8 gdt_entries[GDT_SIZE * 8]; uint8_t gdt_entries[GDT_SIZE * 8];
struct gdt_descriptor gdtr; struct gdt_descriptor gdtr;
static void set_gdt_entry_value(u8 *target, u32 base, u32 limit, static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
u8 access, u8 granularity) uint8_t access, uint8_t granularity)
{ {
if (limit > 0xFFFFF) { if (limit > 0xFFFFF) {
kprintf(KERN_ERR kprintf(KERN_ERR
@ -38,7 +38,7 @@ static void set_gdt_entry_value(u8 *target, u32 base, u32 limit,
void init_gdt(void) void init_gdt(void)
{ {
gdtr.size = 8 * GDT_SIZE - 1; gdtr.size = 8 * GDT_SIZE - 1;
gdtr.base = (u32)&gdt_entries[0]; gdtr.base = (uint32_t)&gdt_entries[0];
set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment
@ -92,8 +92,8 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack
// TSS // TSS
set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (u32)&TSS, set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (uint32_t)&TSS,
sizeof(struct tss) - 1, 0x89, 0); sizeof(struct tss) - 1, 0x89, 0);
set_gdt(((u32)&gdtr)); set_gdt(((uint32_t)&gdtr));
} }

View File

@ -1,6 +1,7 @@
#include "interrupts.h" #include "interrupts.h"
#include "kpanic.h" #include "kpanic.h"
#include "kprintf.h" #include "kprintf.h"
#include "power.h"
#include "utils.h" #include "utils.h"
#include <stddef.h> #include <stddef.h>
@ -33,8 +34,10 @@ static isr_t interrupt_handlers[16];
void isr_handler(struct registers *regs) void isr_handler(struct registers *regs)
{ {
u8 i = 0; uint8_t i = 0;
while (i < ARRAY_SIZE(faults)) { while (i < ARRAY_SIZE(faults)) {
if (i == 6)
reboot();
if (i == regs->int_no) if (i == regs->int_no)
kpanic("interrupt: %s\n", faults[i]); kpanic("interrupt: %s\n", faults[i]);
i++; i++;

View File

@ -21,27 +21,27 @@ static struct idt_descriptor idtr;
void load_idt(struct idt_descriptor *idtr); void load_idt(struct idt_descriptor *idtr);
void idt_set_descriptor(u8 index, void *isr, u8 flags) void idt_set_descriptor(uint8_t index, void *isr, uint8_t flags)
{ {
struct idt_entry *descriptor = &idt_entries[index]; struct idt_entry *descriptor = &idt_entries[index];
descriptor->isr_low = (u32)isr & 0xFFFF; descriptor->isr_low = (uint32_t)isr & 0xFFFF;
descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE; descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE;
descriptor->attributes = flags; descriptor->attributes = flags;
descriptor->isr_high = (u32)isr >> 16; descriptor->isr_high = (uint32_t)isr >> 16;
descriptor->reserved = 0; descriptor->reserved = 0;
} }
void init_idt(void) void init_idt(void)
{ {
idtr.offset = (uintptr_t)&idt_entries[0]; idtr.offset = (uintptr_t)&idt_entries[0];
idtr.size = (u16)sizeof(struct idt_entry) * IDT_SIZE - 1; idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
u8 i; uint8_t i;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
idt_set_descriptor(i, isr_stub_table[i], 0x8E); idt_set_descriptor(i, isr_stub_table[i], 0x8E);
pic_remap(0x20, 0x28); pic_remap(0x20, 0x28);
for (u8 j = 0; j < 16; j++) for (uint8_t j = 0; j < 16; j++)
idt_set_descriptor(i + j, irq_stub_table[j], 0x8E); idt_set_descriptor(i + j, irq_stub_table[j], 0x8E);
load_idt(&idtr); load_idt(&idtr);
__asm__ volatile("sti"); __asm__ volatile("sti");

View File

@ -1,9 +1,9 @@
#include "types.h"
#include <cpuid.h> #include <cpuid.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
const u32 CPUID_FLAG_MSR = 1 << 5; const uint32_t CPUID_FLAG_MSR = 1 << 5;
bool cpu_has_msr() bool cpu_has_msr()
{ {
@ -12,12 +12,12 @@ bool cpu_has_msr()
return edx & CPUID_FLAG_MSR; return edx & CPUID_FLAG_MSR;
} }
void cpu_get_msr(u32 msr, u32 *lo, u32 *hi) void cpu_get_msr(uint32_t msr, uint32_t *lo, uint32_t *hi)
{ {
asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr)); asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
} }
void cpu_set_msr(u32 msr, u32 lo, u32 hi) void cpu_set_msr(uint32_t msr, uint32_t lo, uint32_t hi)
{ {
asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr)); asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
} }

View File

@ -24,7 +24,7 @@
void pic_remap(int offset_master, int offset_slave) void pic_remap(int offset_master, int offset_slave)
{ {
u8 a1, a2; uint8_t a1, a2;
a1 = inb(PIC1_DATA); // save masks a1 = inb(PIC1_DATA); // save masks
a2 = inb(PIC2_DATA); a2 = inb(PIC2_DATA);
@ -56,7 +56,7 @@ void pic_remap(int offset_master, int offset_slave)
outb(PIC2_DATA, a2); outb(PIC2_DATA, a2);
} }
void pic_send_eoi(u8 irq) void pic_send_eoi(uint8_t irq)
{ {
if (irq >= 8) if (irq >= 8)
outb(PIC2_COMMAND, PIC_EOI); outb(PIC2_COMMAND, PIC_EOI);

View File

@ -1,10 +0,0 @@
#include "signal.h"
#include <stddef.h>
void (*signal(int sig, void (*func)(int)))(int)
{
// TODO after multi tasking and processes
(void)sig;
(void)func;
return NULL;
}

View File

@ -30,45 +30,23 @@
#error "This tutorial needs to be compiled with a ix86-elf compiler" #error "This tutorial needs to be compiled with a ix86-elf compiler"
#endif #endif
static void uwu(void) static void bozo(int int_code)
{ {
kprintf("uwu\n"); kprintf("apagnan code\n");
} }
static void owo(void) void kernel_main(multiboot_info_t *mbd, uint32_t magic)
{
while (true)
kprintf("owoooooooooooooooooooooooooooooooooooo\n");
}
static void awa(void)
{
u32 pid = fork();
PRINT_INT(pid);
if (pid < 0)
kprintf("camille il a une grosse bite (18cm)\n");
kprintf("awaille\n");
if (pid)
wait();
}
void kernel_main(multiboot_info_t *mbd, u32 magic)
{ {
terminal_initialize(); terminal_initialize();
init_gdt(); init_gdt();
init_idt(); init_idt();
init_memory(mbd, magic); init_memory(mbd, magic);
load_drivers(); load_drivers();
/* kprintf(KERN_ALERT */
/* "I see no way to confuse an array of 256 seg:off pairs with a
* " */
/* "complex 8*unknown quantity -byte descriptor table. -- Troy "
*/
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
create_kernel_task(); create_kernel_task();
exec_fn(awa); kill(0, 4);
/* exec_fn(owo); */ for (size_t i = 0; i < 10000; i++)
/* exec_fn(owo); */ free_pages(alloc_pages(1, NULL), 1);
/* exec_fn(owo); */ signal(4, bozo);
kill(0, 4);
shell_init(); shell_init();
} }

View File

@ -4,9 +4,12 @@
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
#include "power.h" #include "power.h"
#include "string.h"
#include "terminal.h" #include "terminal.h"
extern u32 page_table1[1024]; extern uint32_t page_table1[1024];
extern const char *faults[];
void clear_registers(void);
__attribute__((noreturn)) void kpanic(const char *format, ...) __attribute__((noreturn)) void kpanic(const char *format, ...)
{ {
@ -14,20 +17,20 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
/* terminal_set_bg_color(VGA_COLOR_BLUE); */ /* terminal_set_bg_color(VGA_COLOR_BLUE); */
/* terminal_clear(); */ /* terminal_clear(); */
kprintf("kpanic: ");
va_start(va, format); va_start(va, format);
kvprintf(format, &va); kvprintf(format, &va);
va_end(va); va_end(va);
u32 faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address)); uint32_t faulting_address;
kprintf("fault at address: %p\n", faulting_address); // __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
// kprintf("fault at address: %p\n", faulting_address);
/* for (int i = 16; i < 32; i++) */ /* for (int i = 16; i < 32; i++) */
/* kprintf("%p\n", page_table1[i]); */ /* kprintf("%p\n", page_table1[i]); */
/* show_valloc_mem(); */ // show_valloc_mem();
/* kprintf("\n\n"); */ /* kprintf("\n\n"); */
/* print_stack(); */ /* print_stack(); */
/* kprintf("\n\n"); */ /* kprintf("\n\n"); */
/* kprintf("PRESS SPACE TO REBOOT"); */ /* kprintf("PRESS SPACE TO REBOOT"); */
while (terminal_getkey().scan_code != KEY_SPACE) __asm__ __volatile__("jmp panic");
;
reboot();
} }

View File

@ -5,7 +5,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h> #include <stdint.h>
int print_int_base(i64 number, const char *prefix, const char *base); int print_int_base(int64_t number, const char *prefix, const char *base);
static int get_level(const char *str) static int get_level(const char *str)
{ {
@ -20,19 +20,19 @@ static int print_flag(char flag, va_list *ap)
case '%': case '%':
return terminal_putchar('%'); return terminal_putchar('%');
case 'i': case 'i':
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
case 'd': case 'd':
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
case 'c': case 'c':
return terminal_putchar(va_arg(*ap, int)); return terminal_putchar(va_arg(*ap, int));
case 's': case 's':
return terminal_writestring(va_arg(*ap, char *)); return terminal_writestring(va_arg(*ap, char *));
case 'p': case 'p':
return print_int_base(va_arg(*ap, u32), "0x", BASE_HEXA); return print_int_base(va_arg(*ap, uint32_t), "0x", BASE_HEXA);
case 'x': case 'x':
return print_int_base(va_arg(*ap, i32), "0x", BASE_HEXA); return print_int_base(va_arg(*ap, int32_t), "0x", BASE_HEXA);
case 'u': case 'u':
return print_int_base(va_arg(*ap, u32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, uint32_t), NULL, BASE_DECA);
} }
return 0; return 0;
} }

View File

@ -3,11 +3,11 @@
#include "string.h" #include "string.h"
#include "terminal.h" #include "terminal.h"
int print_int_base(i64 number, const char *prefix, const char *base) int print_int_base(int64_t number, const char *prefix, const char *base)
{ {
const int base_size = strlen(base); const int base_size = strlen(base);
u64 div = 1; uint64_t div = 1;
u32 tmp; uint32_t tmp;
int rv = 0; int rv = 0;
if (prefix) if (prefix)

View File

@ -34,7 +34,7 @@ int free_frame(void *frame_ptr)
frame_ptr >= it->addr + it->total_frames * PAGE_SIZE)) frame_ptr >= it->addr + it->total_frames * PAGE_SIZE))
it = it->next; it = it->next;
u32 index = ((frame_ptr - it->addr) / PAGE_SIZE); uint32_t index = ((frame_ptr - it->addr) / PAGE_SIZE);
SET_FRAME(it->frame_table, index, 0); SET_FRAME(it->frame_table, index, 0);
if (it->first_free_frame > index) if (it->first_free_frame > index)
it->first_free_frame = index; it->first_free_frame = index;

View File

@ -4,12 +4,19 @@
#include <stdint.h> #include <stdint.h>
u32 *page_directory = &boot_page_directory; uint32_t *kernel_pd = &boot_page_directory;
u32 page_table_default[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t *current_pd;
u32 frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
u32 mem_size; uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t mem_size;
struct frame_zone *head; struct frame_zone *head;
void switch_pd(uint32_t *pd, uint32_t *cr3)
{
current_pd = pd;
asm volatile("mov %0, %%cr3" ::"r"(cr3));
}
static void lst_add_back(struct frame_zone **root, struct frame_zone *element) static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
{ {
if (!*root) { if (!*root) {
@ -24,16 +31,16 @@ static void lst_add_back(struct frame_zone **root, struct frame_zone *element)
static void add_frame_node(multiboot_memory_map_t *mmmt) static void add_frame_node(multiboot_memory_map_t *mmmt)
{ {
static u32 index; static uint32_t index;
/** /**
* # = kernel code * # = kernel code
* - = blank * - = blank
*/ */
u64 start_addr = mmmt->addr; uint64_t start_addr = mmmt->addr;
u64 end_addr = mmmt->addr + mmmt->len; uint64_t end_addr = mmmt->addr + mmmt->len;
u64 len = mmmt->len; uint64_t len = mmmt->len;
/** Kernel code cover all the block /** Kernel code cover all the block
* this situation: * this situation:
@ -61,22 +68,21 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
end_addr = ROUND_CEIL(start_addr + len, PAGE_SIZE); end_addr = ROUND_CEIL(start_addr + len, PAGE_SIZE);
init_page_table(frame_zones_page_table, 0); init_page_table(frame_zones_page_table, 0);
page_directory[1022] = kernel_pd[1022] = ((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
((u32)frame_zones_page_table - HEAP_END) | 0x03;
frame_zones_page_table[index] = frame_zones_page_table[index] =
((u32)start_addr & PAGE_MASK) | INIT_FLAGS; ((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS;
struct frame_zone *current = struct frame_zone *current =
(struct frame_zone *)GET_PAGE_ADDR(1022, index++); (struct frame_zone *)GET_PAGE_ADDR(1022, index++);
current->frame_table = (u8 *)current + sizeof(struct frame_zone); current->frame_table = (uint8_t *)current + sizeof(struct frame_zone);
/** 8 is cause we are using u8 /** 8 is cause we are using uint8_t
nb_frame = size / (PAGE_SIZE + 1 / 8) nb_frame = size / (PAGE_SIZE + 1 / 8)
cause we are using non decimal number cause we are using non decimal number
nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1)) nb_frame = ((size * 8) / (PAGE_SIZE * 8 + 1))
*/ */
const u32 nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1)); const uint32_t nb_frame = ((len * 8) / (PAGE_SIZE * 8 + 1));
current->first_free_frame = 0; current->first_free_frame = 0;
current->next = NULL; current->next = NULL;
current->remaining_frames = nb_frame; current->remaining_frames = nb_frame;
@ -85,10 +91,10 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
memset(current->frame_table, 0, memset(current->frame_table, 0,
nb_frame * sizeof(*current->frame_table)); nb_frame * sizeof(*current->frame_table));
u32 i = 1; uint32_t i = 1;
for (; i < CEIL(nb_frame, PAGE_SIZE); i++) for (; i < CEIL(nb_frame, PAGE_SIZE); i++)
frame_zones_page_table[index + i] = frame_zones_page_table[index + i] =
((u32)(start_addr + i * PAGE_SIZE) & PAGE_MASK) | ((uint32_t)(start_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS; INIT_FLAGS;
current->addr = (void *)start_addr + i * PAGE_SIZE; current->addr = (void *)start_addr + i * PAGE_SIZE;
index += i - 1; index += i - 1;
@ -97,7 +103,7 @@ static void add_frame_node(multiboot_memory_map_t *mmmt)
static void init_frame_zones(void) static void init_frame_zones(void)
{ {
for (u32 i = 0; i < mmap_length; i++) { for (uint32_t i = 0; i < mmap_length; i++) {
multiboot_memory_map_t *mmmt = multiboot_memory_map_t *mmmt =
(multiboot_memory_map_t *)mmap_addr + i; (multiboot_memory_map_t *)mmap_addr + i;
if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE) if (mmmt->type == MULTIBOOT_MEMORY_AVAILABLE)
@ -105,12 +111,13 @@ static void init_frame_zones(void)
} }
} }
void init_memory(multiboot_info_t *mbd, u32 magic) void init_memory(multiboot_info_t *mbd, uint32_t magic)
{ {
for (u16 i = 0; i < 0x300; i++) for (uint16_t i = 0; i < 0x300; i++)
page_directory[i] = 0x02; kernel_pd[i] = 0x02;
init_page_table(page_table_default, 0); init_page_table(page_table_default, 0);
page_directory[0] = ((u32)page_table_default - HEAP_END) | 0x03; kernel_pd[0] = ((uint32_t)page_table_default - HEAP_END) | 0x03;
current_pd = kernel_pd;
init_multiboot(mbd, magic); init_multiboot(mbd, magic);
init_frame_zones(); init_frame_zones();
} }

View File

@ -6,20 +6,21 @@
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
#include "string.h" #include "string.h"
#include "task.h"
#include "utils.h" #include "utils.h"
static i16 find_next_block(size_t nb_pages, u16 *pd_index_ptr, static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
u32 **page_table_ptr) uint32_t **page_table_ptr)
{ {
for (*pd_index_ptr = 1; *pd_index_ptr < 768; (*pd_index_ptr)++) { for (*pd_index_ptr = 1; *pd_index_ptr < 768; (*pd_index_ptr)++) {
if (page_directory[(*pd_index_ptr)] == 0x02) { if (current_pd[(*pd_index_ptr)] == 0x02) {
if (add_page_table(*pd_index_ptr) < 0) if (add_page_table(*pd_index_ptr) < 0)
return -2; return -2;
} }
*page_table_ptr = *page_table_ptr =
(u32 *)GET_PAGE_ADDR(0, *pd_index_ptr + PT_START); (uint32_t *)GET_PAGE_ADDR(0, *pd_index_ptr + PT_START);
for (u16 i = 0; i + nb_pages - 1 < PT_SIZE; i++) { for (uint16_t i = 0; i + nb_pages - 1 < PT_SIZE; i++) {
u16 j; uint16_t j;
for (j = 0; (*page_table_ptr)[i + j] >> 12 == i + j && for (j = 0; (*page_table_ptr)[i + j] >> 12 == i + j &&
j < nb_pages; j < nb_pages;
j++) j++)
@ -32,26 +33,26 @@ static i16 find_next_block(size_t nb_pages, u16 *pd_index_ptr,
return -1; return -1;
} }
i8 add_single_page(void *frame) int8_t add_single_page(void *frame)
{ {
u16 pd_index; uint16_t pd_index;
u32 *page_table; uint32_t *page_table;
const i16 i = find_next_block(1, &pd_index, &page_table); const int16_t i = find_next_block(1, &pd_index, &page_table);
if (i < 0) { if (i < 0) {
kprintf(KERN_CRIT "impossible to add page to page directory\n"); kprintf(KERN_CRIT "impossible to add page to page directory\n");
return -1; return -1;
} }
page_table[i] = ((u32)frame & PAGE_MASK) | INIT_FLAGS; page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
return 0; return 0;
} }
void *alloc_pages(size_t size, void **phys_addr) void *alloc_pages(size_t size, void **phys_addr)
{ {
const u32 nb_pages = CEIL(size, PAGE_SIZE); const uint32_t nb_pages = CEIL(size, PAGE_SIZE);
u16 pd_index; uint16_t pd_index;
u32 *page_table; uint32_t *page_table;
const i16 index = find_next_block(nb_pages, &pd_index, &page_table); const int16_t index = find_next_block(nb_pages, &pd_index, &page_table);
if (index < 0) { if (index < 0) {
kprintf(KERN_CRIT "%d: Not enough pages (max: %d)\n", index, kprintf(KERN_CRIT "%d: Not enough pages (max: %d)\n", index,
@ -67,7 +68,7 @@ void *alloc_pages(size_t size, void **phys_addr)
} }
if (phys_addr) if (phys_addr)
*phys_addr = frame; *phys_addr = frame;
page_table[i] = ((u32)frame & PAGE_MASK) | INIT_FLAGS; page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
} }
memset((void *)GET_PAGE_ADDR(pd_index, index), 0, nb_pages * PAGE_SIZE); memset((void *)GET_PAGE_ADDR(pd_index, index), 0, nb_pages * PAGE_SIZE);
return (void *)GET_PAGE_ADDR(pd_index, index); return (void *)GET_PAGE_ADDR(pd_index, index);
@ -75,13 +76,13 @@ void *alloc_pages(size_t size, void **phys_addr)
int free_pages(void *page_ptr, size_t size) int free_pages(void *page_ptr, size_t size)
{ {
const u32 page_addr = (u32)page_ptr; const uint32_t page_addr = (uint32_t)page_ptr;
const u32 nb_pages = CEIL(size, PAGE_SIZE); const uint32_t nb_pages = CEIL(size, PAGE_SIZE);
const u32 page_index = page_addr / PAGE_SIZE; const uint32_t page_index = page_addr / PAGE_SIZE;
const u32 pd_index = page_index / PD_SIZE; const uint32_t pd_index = page_index / PD_SIZE;
const u32 pt_index = page_index % PD_SIZE; const uint32_t pt_index = page_index % PD_SIZE;
if ((u32)pd_index > 0x300) { if ((uint32_t)pd_index > 0x300) {
kprintf(KERN_WARNING "Address out of range\n"); kprintf(KERN_WARNING "Address out of range\n");
return -1; return -1;
} else if (page_addr % PAGE_SIZE) { } else if (page_addr % PAGE_SIZE) {
@ -91,9 +92,9 @@ int free_pages(void *page_ptr, size_t size)
kprintf(KERN_WARNING "Invalid number of frames\n"); kprintf(KERN_WARNING "Invalid number of frames\n");
return -1; return -1;
} }
u32 *page_table = uint32_t *page_table =
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index); (uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
for (u16 i = pt_index; i < pt_index + nb_pages; i++) { for (uint16_t i = pt_index; i < pt_index + nb_pages; i++) {
if (page_table[i] >> 12 == i) { if (page_table[i] >> 12 == i) {
kprintf(KERN_WARNING "Page already free\n"); kprintf(KERN_WARNING "Page already free\n");
return -2; return -2;

View File

@ -1,22 +1,22 @@
#include "debug.h" #include "debug.h"
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
void init_page_table(u32 page_table[1024], u16 start) void init_page_table(uint32_t page_table[1024], uint16_t start)
{ {
for (u16 i = start; i < 1024; i++) for (uint16_t i = start; i < 1024; i++)
page_table[i] = (i << 12) | 0x03; page_table[i] = (i << 12) | 0x03;
} }
i16 add_page_table(u16 pd_index) int16_t add_page_table(uint16_t pd_index)
{ {
void *frame = alloc_frame(); void *frame = alloc_frame();
if (!frame) if (!frame)
return -1; return -1;
page_table_default[PT_START + pd_index] = page_table_default[PT_START + pd_index] =
((u32)frame & PAGE_MASK) | 0x03; ((uint32_t)frame & PAGE_MASK) | 0x03;
u32 *page_table = uint32_t *page_table =
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index); (uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
init_page_table(page_table, 0); init_page_table(page_table, 0);
page_directory[pd_index] = ((u32)frame & PAGE_MASK) | 0x03; kernel_pd[pd_index] = ((uint32_t)frame & PAGE_MASK) | 0x03;
return 0; return 0;
} }

View File

@ -0,0 +1,70 @@
#include "alloc.h"
#include "debug.h"
#include "kpanic.h"
#include "kprintf.h"
#include "memory.h"
#include "task.h"
Zone *kzones[3];
static void add_zone(Zone *zone, block_type_t type)
{
// We put the zone at the beginning of the list
if (kzones[type]) {
assert(kzones[type] != zone);
zone->next = kzones[type];
kzones[type]->prev = zone;
}
kzones[type] = zone;
}
static void new_block(Zone *zone, uint32_t zone_size)
{
Block *new_block = (Block *)align_mem((uint32_t)zone + sizeof(Zone));
// Metadata
new_block->in_use = false;
new_block->size = zone_size - sizeof(Zone) - sizeof(Block);
new_block->sub_size = new_block->size;
new_block->ptr = (Block *)((uint32_t)new_block + sizeof(Block));
new_block->zone = zone;
// Init future linked lists
new_block->prev = NULL;
new_block->prev_free = NULL;
new_block->prev_used = NULL;
new_block->next = NULL;
new_block->next_free = NULL;
new_block->next_used = NULL;
if (zone->free) {
zone->free->prev = new_block;
zone->free->prev_free = new_block;
new_block->next = zone->free;
new_block->next_free = zone->free;
}
zone->free = new_block;
assert(zone->free == new_block);
}
int new_kzone(block_type_t type, uint32_t size)
{
// assert(current_task->pid);
void *heap = alloc_frame();
if (heap == NULL) {
kprintf(KERN_ERR "error: alloc_frame failed\n");
return (-1);
}
Zone *zone = (Zone *)heap;
zone->type = type;
zone->size = size;
zone->used = NULL;
zone->next = NULL;
zone->prev = NULL;
new_block(zone, size);
add_zone(heap, type);
return (0);
}

52
src/memory/phys/info.c Normal file
View File

@ -0,0 +1,52 @@
#include "alloc.h"
#include "kprintf.h"
#include <stdint.h>
// FULL_INFO is to display (or not) both used and unused blocks
#define FULL_INFO 1
void show_kalloc_mem(void)
{
char *const zones_name[3] = {"TINY", "SMALL", "LARGE"};
uint32_t total_size = 0;
for (block_type_t type = 0; type < 3; ++type) {
int count = 0;
for (Zone *zone_it = kzones[type]; zone_it != NULL;
zone_it = zone_it->next) {
if (zone_it->used)
kprintf("---------- IN_USE %s [n°%d - %p] "
"----------\n",
zones_name[type], count, zone_it);
for (Block *block_it = zone_it->used; block_it != NULL;
block_it = block_it->next_used) {
/* i++; */
/* if (i < 10) */
kprintf("%p - %p : %u bytes\n", block_it->ptr,
(uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block),
block_it->sub_size);
total_size += block_it->sub_size;
}
if (zone_it->used)
kprintf("\n");
count++;
#if FULL_INFO
if (zone_it->free)
kprintf("---------- AVAILABLE %s [n°%d - %p] "
"----------\n",
zones_name[type], count, zone_it);
for (Block *block_it = zone_it->free; block_it != NULL;
block_it = block_it->next_free) {
kprintf("%p - %p : %u bytes\n", block_it->ptr,
(uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block),
block_it->sub_size);
}
if (zone_it->free)
kprintf("\n");
#endif
}
}
kprintf("Total: %u\n", total_size);
}

116
src/memory/phys/kfree.c Normal file
View File

@ -0,0 +1,116 @@
#include "alloc.h"
#include "kprintf.h"
#include "memory.h"
#include <stdint.h>
static void remove_used(Block *to_free)
{
Block *left = to_free->prev_used;
Block *right = to_free->next_used;
to_free->next_used = NULL;
to_free->prev_used = NULL;
if (!left && !right) {
to_free->zone->used = NULL;
return;
}
if (!left)
to_free->zone->used = right;
else
left->next_used = right;
if (right)
right->prev_used = left;
}
/*
* If all the blocks of the zone have been kfreed,
* we can unmap the zone and delete it from the list of zones
*/
static int unmap_zone(Zone *zone)
{
int err = 0;
block_type_t type = zone->type;
Zone *left = zone->prev;
Zone *right = zone->next;
zone->prev = NULL;
zone->next = NULL;
if (!left && !right) {
kzones[type] = NULL;
goto unmap;
}
if (!left)
kzones[type] = right;
else
left->next = right;
if (right)
right->prev = left;
unmap:
err = free_pages((void *)zone, zone->size);
if (err)
kprintf(KERN_ERR "error: munmap failed\n");
return (err);
}
/*
* If the newly kfreed block is next to another previously
* kfreed block, merge both of these and update the size
*/
static Block *merge_blocks(Block *left, Block *right)
{
if (right->next)
right->next->prev = left;
if (right->next_free) {
right->next_free->prev_free = left;
left->next_free = right->next_free;
}
left->next = right->next;
left->size += right->size + sizeof(Block);
return (left);
}
// Simply add the new block to the list of available blocks
static int add_available(Block *available, Block *merged)
{
Zone *zone = available->zone;
if (merged != zone->free && available != zone->free)
available->next_free = zone->free;
if (zone->free)
zone->free->prev_free = available;
zone->free = available;
if (zone->type == LARGE)
return (unmap_zone(zone));
return (0);
}
/*
* ptr: pointer to kfree, if the pointer is invalid the kfree()
* function will have an undefined behavior (most likely segfault)
*
* First, we remove the block from the list of in_use blocks
* Then, we check if the block needs to be merged with another
* neighboring block, if so we replace the previous block by the
* newly merged block
* Finally, we add the block to the list of available blocks
*/
void kfree(void *ptr)
{
if (ptr == NULL)
return;
Block *to_free = (Block *)((uint32_t)ptr - sizeof(Block));
Block *to_merge = NULL;
to_free->in_use = false;
remove_used(to_free);
if (to_free->prev && !to_free->prev->in_use) {
to_merge = to_free;
to_free = merge_blocks(to_free->prev, to_free);
}
if (to_free->next && !to_free->next->in_use) {
to_merge = to_free->next;
to_free = merge_blocks(to_free, to_free->next);
}
int err = add_available(to_free, to_merge);
if (err)
kprintf(KERN_ERR "kfree: fatal error\n");
}

162
src/memory/phys/kmalloc.c Normal file
View File

@ -0,0 +1,162 @@
#include "alloc.h"
#include "debug.h"
#include "kprintf.h"
#include "terminal.h"
#include <stdint.h>
/*
* Find first available (not in_use) block
* in a zone matching the size we need
*/
static Block *find_block(Zone *head, uint32_t size)
{
for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) {
for (Block *block_it = zone_it->free; block_it != NULL;
block_it = block_it->next_free) {
assert(block_it);
assert(!block_it->in_use);
if (size <= block_it->size) {
assert(block_it->zone == zone_it);
return (block_it);
}
}
}
return (NULL);
}
// PARTIALLY DEPRECATED
/*
* This will split the newly allocated block to use
* the remaining bytes for a new block
* This is our linked list of blocks
* ... -> [5] -> [6] -> ...
* After the allocation, this will become
* ... -> [5] -> [new] -> [6] -> ...
*
* For an example of [5].size = 32 and requiring a kmalloc of 10
* Let's say the metadata takes a size of 2:
* ... -> [metadata][data][remaining size] -> [6]
* ^ ^ ^
* 2 10 20
*
* So now our block [new] will become:
* [5] -> [metadata][available data] -> [6]
* ^ ^
* 2 18
* We can see that it now has its own metadata and available
* data and it points towards [6]
*/
static void frag_block(Zone *zone, Block *old_block, uint32_t size)
{
Block *new_block = (Block *)align_mem((uint32_t)old_block + size);
assert(new_block <
(Block *)((uint32_t)zone + get_zone_size(zone->type)));
if (old_block->size - align_mem(size) < sizeof(Block)) {
zone->free = NULL;
goto last_block;
}
// Newly created block metadata
new_block->size = old_block->size - align_mem(size);
new_block->sub_size = new_block->size;
new_block->in_use = false;
new_block->ptr = (void *)((uint32_t)new_block + sizeof(Block));
new_block->zone = zone;
new_block->prev = old_block;
new_block->next = old_block->next;
old_block->next = new_block;
new_block->prev_used = NULL;
new_block->next_used = NULL;
new_block->prev_free = old_block->prev_free;
new_block->next_free = NULL;
if (new_block != old_block->next_free)
new_block->next_free = old_block->next_free;
if (zone->free == old_block)
zone->free = new_block;
last_block:
old_block->next_free = NULL;
old_block->prev_free = NULL;
// Newly in_use block metadata
old_block->in_use = true;
old_block->size = size - sizeof(Block);
old_block->sub_size = old_block->size;
if (zone->used == NULL) {
zone->used = old_block;
return;
}
old_block->prev_used = NULL;
old_block->next_used = zone->used;
zone->used->prev_used = old_block;
zone->used = old_block;
}
// Set the block to used and unset free
static void save_block(Zone *head, Block *block, Zone *zone)
{
zone->free = NULL;
block->in_use = true;
if (head->used) {
head->used->prev_used = block;
head->used->prev = block;
block->next = head->used;
block->next_used = head->used;
}
head->used = block;
}
/*
* size: size needed by the user to get allocated
*
* First, we init the allocator if it's the first time
* Then we search if there is an available block in all
* the zones currently mapped
* If no block has been found (NULL), we create 1 new zone of
* the corresponding type
* We then search again for an available block (should not be NULL)
* Finally, if type == LARGE, we just have to change the block to used
* else, we frag the block to use just what's needed
*
* ptr: returns the aligned pointer of the block (after the metadata)
*/
void *kmalloc(uint32_t size)
{
void *ptr = NULL;
if (size == 0) {
kprintf(KERN_WARNING "kmalloc: can't kmalloc(0)\n");
return NULL;
}
// Find the zone we need to search
block_type_t type = get_type(size);
Zone *head = kzones[type];
// Find an available block in a zone of type "type"
Block *available = find_block(head, size);
if (available == NULL) {
uint32_t full_size;
if (type == LARGE)
full_size = size + sizeof(Block) + sizeof(Zone);
else
full_size = get_zone_size(type);
if (new_kzone(type, full_size) == -1)
return NULL;
head = kzones[type];
available = find_block(head, size);
}
assert(available != NULL);
if (type == LARGE)
save_block(head, available, available->zone);
else
frag_block(available->zone, available, size + sizeof(Block));
ptr = available->ptr;
return ptr;
}

View File

@ -0,0 +1,37 @@
#include "alloc.h"
#include "string.h"
#include <stdint.h>
// Prototype for kfree and kmalloc
void kfree(void *ptr);
void *kmalloc(uint32_t size);
/*
* ptr: block to resize (undefined behavior if invalid)
* size: size needed by the user to get kreallocated
*
* If we have a size <= to the previous size, we don't have
* to do anything, we just change sub_size for info purposes
* and return the same pointer
* Else, we allocate a new block and copy the content of
* the previous block in the new one and kfree the old block
*
* ptr: returns the aligned pointer of the kreallocated block
*/
void *krealloc(void *ptr, uint32_t size)
{
void *new_ptr = NULL;
if (ptr == NULL)
return NULL;
Block *block = (Block *)((uint32_t)ptr - sizeof(Block));
if (block->size >= size) {
block->sub_size = size;
return (ptr);
}
new_ptr = kmalloc(size);
if (new_ptr == NULL)
return NULL;
memmove(new_ptr, ptr, block->size);
kfree(ptr);
return (new_ptr);
}

9
src/memory/phys/ksize.c Normal file
View File

@ -0,0 +1,9 @@
#include "alloc.h"
#include <stdint.h>
uint32_t ksize(void *ptr)
{
Block *meta_data = (Block *)((uint32_t)ptr - sizeof(Block));
return meta_data->sub_size;
}

View File

@ -3,29 +3,30 @@
#include "kpanic.h" #include "kpanic.h"
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
#include "task.h"
Zone *zones[3]; Zone *vzones[3];
static void add_zone(Zone *zone, block_type_t type) static void add_zone(Zone *zone, block_type_t type)
{ {
// We put the zone at the beginning of the list // We put the zone at the beginning of the list
if (zones[type]) { if (vzones[type]) {
assert(zones[type] != zone); assert(vzones[type] != zone);
zone->next = zones[type]; zone->next = vzones[type];
zones[type]->prev = zone; vzones[type]->prev = zone;
} }
zones[type] = zone; vzones[type] = zone;
} }
static void new_block(Zone *zone, u32 zone_size) static void new_block(Zone *zone, uint32_t zone_size)
{ {
Block *new_block = (Block *)align_mem((u32)zone + sizeof(Zone)); Block *new_block = (Block *)align_mem((uint32_t)zone + sizeof(Zone));
// Metadata // Metadata
new_block->in_use = false; new_block->in_use = false;
new_block->size = zone_size - sizeof(Zone) - sizeof(Block); new_block->size = zone_size - sizeof(Zone) - sizeof(Block);
new_block->sub_size = new_block->size; new_block->sub_size = new_block->size;
new_block->ptr = (Block *)((u32)new_block + sizeof(Block)); new_block->ptr = (Block *)((uint32_t)new_block + sizeof(Block));
new_block->zone = zone; new_block->zone = zone;
// Init future linked lists // Init future linked lists
@ -46,8 +47,9 @@ static void new_block(Zone *zone, u32 zone_size)
assert(zone->free == new_block); assert(zone->free == new_block);
} }
int new_vzone(block_type_t type, u32 size) int new_vzone(block_type_t type, uint32_t size)
{ {
// assert(current_task->pid);
void *heap = alloc_pages(size, NULL); void *heap = alloc_pages(size, NULL);
if (heap == NULL) { if (heap == NULL) {
kprintf(KERN_ERR "error: alloc_pages failed\n"); kprintf(KERN_ERR "error: alloc_pages failed\n");

View File

@ -8,11 +8,11 @@
void show_valloc_mem(void) void show_valloc_mem(void)
{ {
char *const zones_name[3] = {"TINY", "SMALL", "LARGE"}; char *const zones_name[3] = {"TINY", "SMALL", "LARGE"};
u32 total_size = 0; uint32_t total_size = 0;
for (block_type_t type = 0; type < 3; ++type) { for (block_type_t type = 0; type < 3; ++type) {
int count = 0; int count = 0;
for (Zone *zone_it = zones[type]; zone_it != NULL; for (Zone *zone_it = vzones[type]; zone_it != NULL;
zone_it = zone_it->next) { zone_it = zone_it->next) {
if (zone_it->used) if (zone_it->used)
kprintf("---------- IN_USE %s [n°%d - %p] " kprintf("---------- IN_USE %s [n°%d - %p] "
@ -23,7 +23,7 @@ void show_valloc_mem(void)
/* i++; */ /* i++; */
/* if (i < 10) */ /* if (i < 10) */
kprintf("%p - %p : %u bytes\n", block_it->ptr, kprintf("%p - %p : %u bytes\n", block_it->ptr,
(u32)block_it->ptr + (uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block), block_it->sub_size + sizeof(Block),
block_it->sub_size); block_it->sub_size);
total_size += block_it->sub_size; total_size += block_it->sub_size;
@ -39,7 +39,7 @@ void show_valloc_mem(void)
for (Block *block_it = zone_it->free; block_it != NULL; for (Block *block_it = zone_it->free; block_it != NULL;
block_it = block_it->next_free) { block_it = block_it->next_free) {
kprintf("%p - %p : %u bytes\n", block_it->ptr, kprintf("%p - %p : %u bytes\n", block_it->ptr,
(u32)block_it->ptr + (uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block), block_it->sub_size + sizeof(Block),
block_it->sub_size); block_it->sub_size);
} }

View File

@ -37,11 +37,11 @@ static int unmap_zone(Zone *zone)
zone->next = NULL; zone->next = NULL;
if (!left && !right) { if (!left && !right) {
zones[type] = NULL; vzones[type] = NULL;
goto unmap; goto unmap;
} }
if (!left) if (!left)
zones[type] = right; vzones[type] = right;
else else
left->next = right; left->next = right;
if (right) if (right)
@ -98,7 +98,7 @@ void vfree(void *ptr)
{ {
if (ptr == NULL) if (ptr == NULL)
return; return;
Block *to_free = (Block *)((u32)ptr - sizeof(Block)); Block *to_free = (Block *)((uint32_t)ptr - sizeof(Block));
Block *to_merge = NULL; Block *to_merge = NULL;
to_free->in_use = false; to_free->in_use = false;
remove_used(to_free); remove_used(to_free);

View File

@ -8,7 +8,7 @@
* Find first available (not in_use) block * Find first available (not in_use) block
* in a zone matching the size we need * in a zone matching the size we need
*/ */
static Block *find_block(Zone *head, u32 size) static Block *find_block(Zone *head, uint32_t size)
{ {
for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) { for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) {
for (Block *block_it = zone_it->free; block_it != NULL; for (Block *block_it = zone_it->free; block_it != NULL;
@ -46,17 +46,22 @@ static Block *find_block(Zone *head, u32 size)
* We can see that it now has its own metadata and available * We can see that it now has its own metadata and available
* data and it points towards [6] * data and it points towards [6]
*/ */
static void frag_block(Zone *zone, Block *old_block, u32 size) static void frag_block(Zone *zone, Block *old_block, uint32_t size)
{ {
Block *new_block = (Block *)align_mem((u32)old_block + size); Block *new_block = (Block *)align_mem((uint32_t)old_block + size);
assert(new_block < assert(new_block <
(Block *)((u32)zone + get_zone_size(zone->type))); (Block *)((uint32_t)zone + get_zone_size(zone->type)));
if (old_block->size - align_mem(size) < sizeof(Block)) {
zone->free = NULL;
goto last_block;
}
// Newly created block metadata // Newly created block metadata
new_block->size = old_block->size - align_mem(size); new_block->size = old_block->size - align_mem(size);
new_block->sub_size = new_block->size; new_block->sub_size = new_block->size;
new_block->in_use = false; new_block->in_use = false;
new_block->ptr = (void *)((u32)new_block + sizeof(Block)); new_block->ptr = (void *)((uint32_t)new_block + sizeof(Block));
new_block->zone = zone; new_block->zone = zone;
new_block->prev = old_block; new_block->prev = old_block;
@ -74,6 +79,7 @@ static void frag_block(Zone *zone, Block *old_block, u32 size)
if (zone->free == old_block) if (zone->free == old_block)
zone->free = new_block; zone->free = new_block;
last_block:
old_block->next_free = NULL; old_block->next_free = NULL;
old_block->prev_free = NULL; old_block->prev_free = NULL;
@ -120,7 +126,7 @@ static void save_block(Zone *head, Block *block, Zone *zone)
* *
* ptr: returns the aligned pointer of the block (after the metadata) * ptr: returns the aligned pointer of the block (after the metadata)
*/ */
void *vmalloc(u32 size) void *vmalloc(uint32_t size)
{ {
void *ptr = NULL; void *ptr = NULL;
@ -131,19 +137,19 @@ void *vmalloc(u32 size)
// Find the zone we need to search // Find the zone we need to search
block_type_t type = get_type(size); block_type_t type = get_type(size);
Zone *head = zones[type]; Zone *head = vzones[type];
// Find an available block in a zone of type "type" // Find an available block in a zone of type "type"
Block *available = find_block(head, size); Block *available = find_block(head, size);
if (available == NULL) { if (available == NULL) {
u32 full_size; uint32_t full_size;
if (type == LARGE) if (type == LARGE)
full_size = size + sizeof(Block) + sizeof(Zone); full_size = size + sizeof(Block) + sizeof(Zone);
else else
full_size = get_zone_size(type); full_size = get_zone_size(type);
if (new_vzone(type, full_size) == -1) if (new_vzone(type, full_size) == -1)
return NULL; return NULL;
head = zones[type]; head = vzones[type];
available = find_block(head, size); available = find_block(head, size);
} }
assert(available != NULL); assert(available != NULL);

View File

@ -4,7 +4,7 @@
// Prototype for kfree and vmalloc // Prototype for kfree and vmalloc
void kfree(void *ptr); void kfree(void *ptr);
void *vmalloc(u32 size); void *vmalloc(uint32_t size);
/* /*
* ptr: block to resize (undefined behavior if invalid) * ptr: block to resize (undefined behavior if invalid)
@ -18,12 +18,12 @@ void *vmalloc(u32 size);
* *
* ptr: returns the aligned pointer of the vreallocated block * ptr: returns the aligned pointer of the vreallocated block
*/ */
void *vrealloc(void *ptr, u32 size) void *vrealloc(void *ptr, uint32_t size)
{ {
void *new_ptr = NULL; void *new_ptr = NULL;
if (ptr == NULL) if (ptr == NULL)
return NULL; return NULL;
Block *block = (Block *)((u32)ptr - sizeof(Block)); Block *block = (Block *)((uint32_t)ptr - sizeof(Block));
if (block->size >= size) { if (block->size >= size) {
block->sub_size = size; block->sub_size = size;
return (ptr); return (ptr);

View File

@ -1,9 +1,9 @@
#include "alloc.h" #include "alloc.h"
#include <stdint.h> #include <stdint.h>
u32 vsize(void *ptr) uint32_t vsize(void *ptr)
{ {
Block *meta_data = (Block *)((u32)ptr - sizeof(Block)); Block *meta_data = (Block *)((uint32_t)ptr - sizeof(Block));
return meta_data->sub_size; return meta_data->sub_size;
} }

View File

@ -9,21 +9,21 @@
#include "utils.h" #include "utils.h"
#include "vbe.h" #include "vbe.h"
u32 multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
u32 vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
multiboot_memory_map_t *mmap_addr; multiboot_memory_map_t *mmap_addr;
multiboot_u32 mmap_length; multiboot_uint32_t mmap_length;
static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index) static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
{ {
// Index mbd->mmap_addr pointers // Index mbd->mmap_addr pointers
u32 i = 0; uint32_t i = 0;
for (; i < mbd_virt->mmap_length; i++) for (; i < mbd_virt->mmap_length; i++)
multiboot_page_table[i + *pt_index] = multiboot_page_table[i + *pt_index] =
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) | ((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS; INIT_FLAGS;
mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) + mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) +
(u32)mbd_virt->mmap_addr % (uint32_t)mbd_virt->mmap_addr %
PAGE_SIZE); PAGE_SIZE);
mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t); mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t);
*pt_index += i; *pt_index += i;
@ -31,15 +31,15 @@ static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
static void init_vbe(multiboot_info_t *mbd_virt) static void init_vbe(multiboot_info_t *mbd_virt)
{ {
const u32 framebuffer_size = const uint32_t framebuffer_size =
mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch; mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch;
for (u32 i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) { for (uint32_t i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) {
vbe_page_table[i % 1024] = vbe_page_table[i % 1024] =
((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) | ((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS; INIT_FLAGS;
} }
page_directory[800] = ((u32)vbe_page_table - HEAP_END) | 0x03; kernel_pd[800] = ((uint32_t)vbe_page_table - HEAP_END) | 0x03;
display.buff = (u32 *)GET_PAGE_ADDR(800, 0) + display.buff = (uint32_t *)GET_PAGE_ADDR(800, 0) +
(mbd_virt->framebuffer_addr % PAGE_SIZE); (mbd_virt->framebuffer_addr % PAGE_SIZE);
display.height = mbd_virt->framebuffer_height; display.height = mbd_virt->framebuffer_height;
display.width = mbd_virt->framebuffer_width; display.width = mbd_virt->framebuffer_width;
@ -47,24 +47,23 @@ static void init_vbe(multiboot_info_t *mbd_virt)
display.bpp = mbd_virt->framebuffer_bpp; display.bpp = mbd_virt->framebuffer_bpp;
} }
void init_multiboot(multiboot_info_t *mbd, u32 magic) void init_multiboot(multiboot_info_t *mbd, uint32_t magic)
{ {
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
kpanic("invalid magic number! (git good skill issue)"); kpanic("invalid magic number! (git good skill issue)");
init_page_table(multiboot_page_table, 0); init_page_table(multiboot_page_table, 0);
page_directory[1023] = kernel_pd[1023] = ((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
((u32)multiboot_page_table - HEAP_END) | 0x03;
size_t pt_index = CEIL( size_t pt_index = CEIL(
(u32)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE); (uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
// Index multiboot_info_t struct // Index multiboot_info_t struct
for (u32 i = 0; i < pt_index; i++) for (uint32_t i = 0; i < pt_index; i++)
multiboot_page_table[i] = multiboot_page_table[i] =
(((u32)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS; (((uint32_t)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS;
multiboot_info_t *mbd_virt = multiboot_info_t *mbd_virt =
(multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) + (multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) +
(u32)mbd % PAGE_SIZE); (uint32_t)mbd % PAGE_SIZE);
init_mmap(mbd_virt, &pt_index); init_mmap(mbd_virt, &pt_index);
init_vbe(mbd_virt); init_vbe(mbd_virt);
} }

View File

@ -1,9 +1,8 @@
#include "interrupts.h" #include "interrupts.h"
#include "kprintf.h" #include "kprintf.h"
#include "task.h" #include "task.h"
#include "types.h"
u16 fork(void) uint16_t fork(void)
{ {
current_task->status = FORKED; current_task->status = FORKED;
scheduler(); scheduler();

View File

@ -12,12 +12,14 @@ struct task *current_task;
void scheduler(void) void scheduler(void)
{ {
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED // ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
void (*func[])(struct task *) = {remove_task, NULL, NULL, NULL, void (*func[])(struct task *) = {
NULL, remove_task, kfork}; zombify_task, NULL, NULL, NULL, NULL, remove_task, kfork,
};
if (!current_task) // || current_task->next == current_task) if (!current_task) // || current_task->next == current_task)
return; return;
cli(); cli();
switch_pd(kernel_pd, (uint32_t *)((uint32_t)kernel_pd - HEAP_END));
struct task *it = current_task->next; struct task *it = current_task->next;
while (it && it->status != RUN) { while (it && it->status != RUN) {
if (it != current_task && func[it->status]) { if (it != current_task && func[it->status]) {
@ -28,5 +30,6 @@ void scheduler(void)
it = it->next; it = it->next;
} }
switch_to_task(it); switch_to_task(it);
exec_signal_pending();
toris(); toris();
} }

View File

@ -23,6 +23,11 @@ switch_to_task:
mov esp, [eax+0] // get esp mov esp, [eax+0] // get esp
mov ecx, [eax+12] // get task's pd
mov [current_pd], ecx
mov ecx, [eax+8]
mov cr3, ecx
pop esi pop esi
pop edi pop edi
pop ebp pop ebp

View File

@ -10,36 +10,52 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
u32 esp_backup; uint32_t esp_backup;
struct task *create_task(u8 uid) struct task *create_task(uint8_t uid)
{ {
static u32 pid = 1; static uint32_t pid = 1;
switch_pd(kernel_pd, (uint32_t *)((uint32_t)kernel_pd - HEAP_END));
struct task *new_task = vmalloc(sizeof(struct task)); struct task *new_task = vmalloc(sizeof(struct task));
if (!new_task) if (!new_task) {
switch_pd(current_task->heap, current_task->cr3);
return NULL; return NULL;
}
switch_pd(current_task->heap, current_task->cr3);
new_task->status = RUN;
new_task->uid = uid;
new_task->esp = new_task->esp0 + STACK_SIZE;
new_task->pid = pid++;
// Allocate new pd
new_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
if (!new_task->heap) {
vfree(new_task);
return NULL;
}
new_task->heap[768] = ((uint32_t)boot_page_table1 - HEAP_END) | 0x03;
memcpy(new_task->heap, current_task->heap, 4096);
switch_pd(new_task->heap, new_task->cr3);
// Allocate new stack on the newly allocated pd
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
switch_pd(current_task->heap, current_task->cr3);
if (!new_task->esp0) {
vfree(new_task);
free_pages(new_task->heap, 4096);
return NULL;
}
new_task->next = current_task->next; new_task->next = current_task->next;
new_task->prev = current_task; new_task->prev = current_task;
current_task->next = new_task; current_task->next = new_task;
new_task->status = RUN;
new_task->uid = uid; new_task->signals.pending = SIG_IGN;
new_task->esp0 = alloc_pages(STACK_SIZE, NULL);
if (!new_task->esp0) {
vfree(new_task);
return NULL;
}
new_task->esp = new_task->esp0 + STACK_SIZE;
new_task->pid = pid++;
new_task->heap = alloc_pages(4096, (void **)&new_task->cr3);
if (!new_task->heap) {
free_pages(new_task->esp0, STACK_SIZE);
vfree(new_task);
return NULL;
}
return new_task; return new_task;
} }
i8 create_kernel_task(void) int8_t create_kernel_task(void)
{ {
struct task *new_task = vmalloc(sizeof(struct task)); struct task *new_task = vmalloc(sizeof(struct task));
if (!new_task) if (!new_task)
@ -47,10 +63,11 @@ i8 create_kernel_task(void)
new_task->status = RUN; new_task->status = RUN;
new_task->uid = 0; new_task->uid = 0;
new_task->pid = 0; new_task->pid = 0;
new_task->heap = page_directory; new_task->heap = kernel_pd;
new_task->cr3 = page_directory - KERNEL_START; new_task->cr3 = (uint32_t *)((uint32_t)kernel_pd - HEAP_END);
new_task->prev = new_task; new_task->prev = new_task;
new_task->next = new_task; new_task->next = new_task;
new_task->signals.pending = SIG_IGN;
current_task = new_task; current_task = new_task;
return 0; return 0;
} }
@ -60,26 +77,37 @@ void exec_fn(void (*fn)(void))
struct task *new_task = create_task(OWNER_KERNEL); struct task *new_task = create_task(OWNER_KERNEL);
if (!new_task) if (!new_task)
kpanic("failed to create new task"); kpanic("failed to create new task");
new_task->eip = (u32 *)fn; new_task->eip = (uint32_t *)fn;
}
void zombify_task(struct task *task)
{
cli(); // Technically useless
free_pages(task->heap, 4096);
free_pages(task->esp0, STACK_SIZE);
task->esp0 = NULL;
task->heap = NULL;
toris();
} }
void remove_task(struct task *task) void remove_task(struct task *task)
{ {
cli();
struct task *left = task->prev; struct task *left = task->prev;
struct task *right = task->next; struct task *right = task->next;
if (task->child)
if (task->child) {
remove_task(task->child); remove_task(task->child);
task->child = NULL;
}
if (task->heap) if (task->heap)
free_pages(task->heap, 4096); free_pages(task->heap, 4096);
if (task->esp0) if (task->esp0)
free_pages(task->esp0, STACK_SIZE); free_pages(task->esp0, STACK_SIZE);
task->heap = NULL;
task->esp0 = NULL;
if (task->status != ZOMBIE) {
left->next = right; left->next = right;
right->prev = left; right->prev = left;
vfree(task); vfree(task);
} toris();
} }
struct task *copy_task(const struct task *task) struct task *copy_task(const struct task *task)
@ -104,5 +132,5 @@ void exit_task(void)
current_task->status = STOPPED; current_task->status = STOPPED;
} }
toris(); toris();
asm volatile("jmp scheduler"); scheduler();
} }

View File

@ -1,7 +1,7 @@
#include "interrupts.h" #include "interrupts.h"
#include "task.h" #include "task.h"
u16 wait(void) uint16_t wait(void)
{ {
if (current_task->child == NULL) if (current_task->child == NULL)
return -1; return -1;
@ -10,7 +10,7 @@ u16 wait(void)
current_task->child->status = STOPPED; current_task->child->status = STOPPED;
else else
current_task->status = WAIT; current_task->status = WAIT;
u16 child_pid = current_task->child->pid; uint16_t child_pid = current_task->child->pid;
toris(); toris();
scheduler(); scheduler();
return child_pid; return child_pid;

19
src/panic.s Normal file
View File

@ -0,0 +1,19 @@
.intel_syntax noprefix
.section .text
.global panic
panic:
xor eax, eax
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esp, esp
xor ebp, ebp
xor esi, esi
xor edi, edi
cli
loop:
hlt
jmp loop

View File

@ -17,7 +17,7 @@
void reboot(void) void reboot(void)
{ {
u8 tmp; uint8_t tmp;
__asm__ volatile("cli"); /* disable all interrupts */ __asm__ volatile("cli"); /* disable all interrupts */
do { do {

View File

@ -4,7 +4,7 @@
#include "kprintf.h" #include "kprintf.h"
static u16 raw_read_register(u16 cmos_register) static uint16_t raw_read_register(uint16_t cmos_register)
{ {
// selecting the register // selecting the register
outb(CMOS_ADDRESS, cmos_register); outb(CMOS_ADDRESS, cmos_register);
@ -12,19 +12,19 @@ static u16 raw_read_register(u16 cmos_register)
return inb(CMOS_DATA); return inb(CMOS_DATA);
} }
static u8 update_is_in_progress(void) static uint8_t update_is_in_progress(void)
{ {
return raw_read_register(REGISTER_A) & 0x80; return raw_read_register(REGISTER_A) & 0x80;
} }
static u16 read_register(u16 cmos_register) static uint16_t read_register(uint16_t cmos_register)
{ {
while (update_is_in_progress()) while (update_is_in_progress())
kprintf("%d\n", update_is_in_progress()); kprintf("%d\n", update_is_in_progress());
return raw_read_register(cmos_register); return raw_read_register(cmos_register);
} }
u8 bcd_mode_to_bin(u8 value) uint8_t bcd_mode_to_bin(uint8_t value)
{ {
return (value & 0x0F) + ((value / 16) * 10); return (value & 0x0F) + ((value / 16) * 10);
} }
@ -32,7 +32,7 @@ u8 bcd_mode_to_bin(u8 value)
struct rtc_date get_date(void) struct rtc_date get_date(void)
{ {
struct rtc_date rv = {}; struct rtc_date rv = {};
u8 century; uint8_t century;
rv.second = read_register(SECOND_REGISTER); rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER); rv.minute = read_register(MINUTE_REGISTER);

View File

@ -6,7 +6,7 @@
void color_cmd(char *arg) void color_cmd(char *arg)
{ {
u8 tmp_color; uint8_t tmp_color;
static const char *colors[] = { static const char *colors[] = {
"BLACK", "BLUE", "GREEN", "CYAN", "BLACK", "BLUE", "GREEN", "CYAN",
"RED", "MAGENTA", "BROWN", "LIGHT_GREY", "RED", "MAGENTA", "BROWN", "LIGHT_GREY",

View File

@ -0,0 +1,19 @@
#include "keyboard.h"
#include "kprintf.h"
#include "string.h"
extern char const **keymap;
void layout_cmd(char *arg)
{
if (!strcmp(arg, "us") || !strcmp(arg, "qwerty")) {
kprintf("Successfully changed layout to us/qwerty\n");
keymap = qwerty_keymap;
} else if (!strcmp(arg, "fr") || !strcmp(arg, "azerty")) {
kprintf("Successfully changed layout to fr/azerty\n");
keymap = azerty_keymap;
} else {
kprintf(
"Invalid argument: please type us|qwerty or fr|azerty\n");
}
}

View File

@ -30,6 +30,7 @@ const struct shell_command cmds[] = {
{"date", "Display the current time and date", date_cmd}, {"date", "Display the current time and date", date_cmd},
{"merdella", "Surprise", merdella_cmd}, {"merdella", "Surprise", merdella_cmd},
{"color", "Change the screen color", color_cmd}, {"color", "Change the screen color", color_cmd},
{"layout", "Change the current layout (us or fr)", layout_cmd},
}; };
#define NB_CMDS ARRAY_SIZE(cmds) #define NB_CMDS ARRAY_SIZE(cmds)

49
src/signal/signal.c Normal file
View File

@ -0,0 +1,49 @@
#include "signal.h"
#include "kprintf.h"
#include "task.h"
#include <stdint.h>
void signal(SIGNAL_CODE sig_num, void *handler)
{
current_task->signals.handlers[sig_num] = handler;
}
void kill(int pid, SIGNAL_CODE sig_num)
{
struct task *task = current_task;
while (task->pid != pid)
task = task->next;
task->signals.pending = sig_num;
}
static void display_signal(SIGNAL_CODE sig_num)
{
kprintf("signal: %d\n", sig_num);
}
static void exec_signal(SIGNAL_CODE sig_num)
{
void *handler = current_task->signals.handlers[sig_num];
if (handler == SIG_IGN)
return;
if (handler == SIG_DFL) {
display_signal(sig_num);
return;
}
signal_handler_t func = handler;
func(sig_num);
}
void exec_signal_pending(void)
{
uint32_t signal_code = current_task->signals.pending;
if (signal_code != SIG_IGN) {
exec_signal(signal_code);
current_task->signals.pending = SIG_IGN;
}
}

View File

@ -8,5 +8,5 @@ uintptr_t __stack_chk_guard = STACK_CHK_GUARD;
__attribute__((noreturn)) void __stack_chk_fail(void) __attribute__((noreturn)) void __stack_chk_fail(void)
{ {
kpanic("Stack smashing detected"); kpanic("Stack smashing detected\n");
} }

View File

@ -4,11 +4,13 @@
#include "sys/io.h" #include "sys/io.h"
#include "terminal.h" #include "terminal.h"
char const **keymap = qwerty_keymap;
struct key_event terminal_getkey(void) struct key_event terminal_getkey(void)
{ {
static bool caps_mode = false; static bool caps_mode = false;
struct key_event ev = {0}; struct key_event ev = {0};
u8 scan_code; uint8_t scan_code;
scan_code = inb(KEYBOARD_PORT); scan_code = inb(KEYBOARD_PORT);
if (scan_code == 0x3A || scan_code == 0x58) { if (scan_code == 0x3A || scan_code == 0x58) {

View File

@ -2,7 +2,7 @@
#include "debug.h" #include "debug.h"
#include "font.h" #include "font.h"
#include "fonts/consolas_regular_13.h" #include "fonts/consolas_regular_13.h"
/* #include "icons/image.h" */ // #include "icons/image.h"
#include "kprintf.h" #include "kprintf.h"
#include "shell.h" #include "shell.h"
#include "string.h" #include "string.h"
@ -28,7 +28,7 @@ void terminal_initialize(void)
screens[i].column = 0; screens[i].column = 0;
screens[i].default_color = 0xffffff; screens[i].default_color = 0xffffff;
screens[i].fg_color = screens[i].default_color; screens[i].fg_color = screens[i].default_color;
/* screens[i].background = &image_icon; */ // screens[i].background = &image_icon;
screens[i].font = consolas_regular_13_font; screens[i].font = consolas_regular_13_font;
memset(screens[i].line, 0, sizeof(screen->line)); memset(screens[i].line, 0, sizeof(screen->line));
} }
@ -42,23 +42,22 @@ void terminal_remove_last_char(void)
screen->column = VGA_WIDTH - 1; screen->column = VGA_WIDTH - 1;
screen->row--; screen->row--;
} }
u32 pos_x = (screen->column) * FONT_WIDTH; uint32_t pos_x = (screen->column) * FONT_WIDTH;
u32 pos_y = screen->row * FONT_HEIGHT; uint32_t pos_y = screen->row * FONT_HEIGHT;
struct font node = get_font_node( struct font node = get_font_node(
screen->buffer[screen->row * VGA_WIDTH + screen->column]); screen->buffer[screen->row * VGA_WIDTH + screen->column]);
screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0'; screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0';
for (u32 y = 0; y < node.height; y++) { for (uint32_t y = 0; y < node.height; y++) {
for (u32 x = 0; x < node.width; x++) { for (uint32_t x = 0; x < node.width; x++) {
// Current bg is taking too much memory // Current bg is taking too much memory
// so we do a black bg for now // so we do a black bg for now
/* struct icon *bg = screen->background; */ // struct icon *bg = screen->background;
/* u32 pixel = 0; */ // uint32_t pixel = 0;
/* if (bg->width > pos_x + x && bg->height > pos_y + y) // if (bg->width > pos_x + x && bg->height > pos_y + y)
*/ // pixel = bg->pixels[(pos_y + y) * bg->width +
/* pixel = bg->pixels[(pos_y + y) * bg->width + */ // (pos_x + x)];
/* (pos_x + x)]; */ put_pixel(0, pos_x + x, pos_y + y + node.yoffset);
put_pixel(0, pos_x + x, pos_y + y);
} }
} }
} }
@ -74,38 +73,38 @@ void terminal_set_screen(int pos)
/* kprintf(PROMPT); */ /* kprintf(PROMPT); */
} }
void terminal_set_bg_color(u32 bg_color) void terminal_set_bg_color(uint32_t bg_color)
{ {
screen->bg_color = bg_color; screen->bg_color = bg_color;
} }
void terminal_set_fg_color(u32 fg_color) void terminal_set_fg_color(uint32_t fg_color)
{ {
screen->fg_color = screen->fg_color; screen->fg_color = screen->fg_color;
} }
void terminal_set_color(u32 fg_color, u32 bg_color) void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
{ {
screen->fg_color = fg_color; screen->fg_color = fg_color;
screen->bg_color = bg_color; screen->bg_color = bg_color;
} }
void terminal_set_default_fg_color(u32 fg_color) void terminal_set_default_fg_color(uint32_t fg_color)
{ {
screen->default_color = fg_color; screen->default_color = fg_color;
} }
u32 terminal_get_default_color(void) uint32_t terminal_get_default_color(void)
{ {
return screen->default_color; return screen->default_color;
} }
u8 terminal_get_char(int x, int y) uint8_t terminal_get_char(int x, int y)
{ {
return screen->buffer[y * VGA_WIDTH + x]; return screen->buffer[y * VGA_WIDTH + x];
} }
void terminal_putentryat(struct font node, u32 fg_color, u32 bg_color, void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
size_t x, size_t y) size_t x, size_t y)
{ {
char *glyph = node.bitmap; char *glyph = node.bitmap;
@ -128,8 +127,8 @@ static void terminal_scroll(void)
screen->row--; screen->row--;
memset(display.buff, 0, display.height * display.pitch); memset(display.buff, 0, display.height * display.pitch);
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) { for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
const u32 x = (i % VGA_WIDTH) * FONT_WIDTH; const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
const u32 y = (i / VGA_WIDTH) * FONT_HEIGHT; const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
screen->buffer[i] = screen->buffer[i + VGA_WIDTH]; screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
terminal_putentryat(get_font_node(screen->buffer[i]), terminal_putentryat(get_font_node(screen->buffer[i]),
screen->fg_color, screen->bg_color, x, y); screen->fg_color, screen->bg_color, x, y);
@ -143,7 +142,7 @@ static void terminal_new_line(void)
terminal_scroll(); terminal_scroll();
} }
void terminal_change_default_color(u32 color) void terminal_change_default_color(uint32_t color)
{ {
// TODO // TODO
/* terminal_set_color(color); */ /* terminal_set_color(color); */
@ -151,7 +150,7 @@ void terminal_change_default_color(u32 color)
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */ /* for (size_t x = 0; x < VGA_WIDTH; x++) { */
/* const size_t index = y * VGA_WIDTH + x; /* const size_t index = y * VGA_WIDTH + x;
*/ */
/* u8 entry_color = /* uint8_t entry_color =
* get_entry_color(TERM_BUF[index]); * get_entry_color(TERM_BUF[index]);
*/ */
/* TERM_BUF[index] = vga_entry( */ /* TERM_BUF[index] = vga_entry( */
@ -170,7 +169,7 @@ void terminal_change_default_color(u32 color)
/* screen->color = color; */ /* screen->color = color; */
} }
void terminal_change_default_fg_color(u32 fg_color) void terminal_change_default_fg_color(uint32_t fg_color)
{ {
terminal_set_fg_color(fg_color); terminal_set_fg_color(fg_color);
/* terminal_change_default_color(screen->fg_color); */ /* terminal_change_default_color(screen->fg_color); */
@ -228,7 +227,7 @@ int terminal_writestring(const char *data)
void update_cursor(void) void update_cursor(void)
{ {
/* u16 pos = screen->row * VGA_WIDTH + /* uint16_t pos = screen->row * VGA_WIDTH +
* screen->column; */ * screen->column; */
/* outb(0x3D4, 0x0F); */ /* outb(0x3D4, 0x0F); */