Compare commits

...

65 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
7b7cc86999 wip: multitasking: add status forked 2025-02-03 13:11:38 +01:00
18486a6705 fix: infinite loop when scheduler call before create_kernel_task 2025-01-30 14:04:15 +01:00
c9a92819b4 fix: fork return pid instead uid 2025-01-30 10:47:36 +01:00
f75e121251 fix: fork: call scheduler before fork 2025-01-30 10:47:15 +01:00
9c89433db5 fix: task: use 8bit represent ptr instead of 32 to fix stack ptr 2025-01-29 13:30:42 +01:00
69686a2c91 fix: fork: set child espat the right postion 2025-01-29 12:41:57 +01:00
1ca8c68cf5 wip: fork and wait are almost working (missing child's stack) 2025-01-28 15:44:09 +01:00
e60969b37a fix: multitasking: switch to task 2025-01-28 15:10:13 +01:00
dbdf851dd2 feature: fork added and exit_task is almost working 2025-01-28 13:38:39 +01:00
d7626df19c core: change types from uint32_t to u32 (e.g) 2025-01-27 11:26:15 +01:00
95fec015f2 fix: simple multitasking work !!!!
add a stack at every task, and execute task while multitasking switching
2025-01-24 12:33:29 +01:00
dc84d5856b fix: switch to task: dereference variable rightly 2025-01-23 15:53:42 +01:00
19eea56a7e fix: switch to task: dereference variable rightly 2025-01-23 15:25:49 +01:00
8c63eac00e fix: no switch to task when only one task 2025-01-23 14:48:53 +01:00
d4db6acf61 fix: infinite loop when only one task 2025-01-23 14:27:28 +01:00
540226fb0f Merge branch 'main' of git.chauvet.pro:starnakin/42_KFS 2025-01-23 14:13:04 +01:00
2d6b24842e fix: a bunch of stuff related to multitasking 2025-01-23 14:12:38 +01:00
494a0f425c add: bzero 2025-01-22 14:44:50 +01:00
2ba4037af2 core: add debug flags to use gdb 2025-01-22 14:41:41 +01:00
7ba3eead14 core: change main debug func 2025-01-22 14:06:44 +01:00
35b73e8004 clean: remove useless code 2025-01-22 14:06:44 +01:00
4ec1a4962d fix: (maybe): remove gdt address 2025-01-22 14:06:44 +01:00
24c7ea8b19 clean: remove useless code 2025-01-22 14:06:44 +01:00
d2f7a3ce26 repo: add .txt (for logs) in .gitignore 2025-01-22 14:04:20 +01:00
57ce3c792d wip: multitasking: change eip but not working 2025-01-21 10:41:27 +01:00
d889a251ef add: kernel task 2025-01-20 15:11:22 +01:00
b3be29246e wip: eip saved after the interrupt 2025-01-20 14:36:43 +01:00
2fe4ac5ad5 Merge branch 'main' of git.chauvet.pro:starnakin/42_KFS 2025-01-17 12:56:30 +01:00
fa3ef311ad wip: scheduler needs to change eip or smth in order to call the fn 2025-01-17 12:56:05 +01:00
02c3d72a4b core: add set variable in static 2025-01-16 13:43:14 +01:00
b9691b1948 wip: TSS added to the gdt and start to implement scheduler 2025-01-13 15:46:09 +01:00
916e8b6f19 add: sleep 2025-01-08 16:38:02 +01:00
bab3069152 feature: line spacing + characters are aligned 2024-12-19 19:04:43 +01:00
61debdcb85 fix: autocomplete working again (ratio starnakin) and clean some stuff 2024-12-19 11:03:09 +01:00
4028372475 add: Makefile create iso without compression 2024-12-19 02:18:47 +01:00
6bdba0cb4f clean: simplify code && maybe fix 2024-12-19 00:22:02 +01:00
4a99b82e15 add: backspace work with vbe 2024-12-18 23:56:17 +01:00
77928aca4b feature: black screen with scrolling is better, it also uses the full screen length 2024-12-18 14:13:45 +01:00
dda9c8a1ef feature: terminal scroll works again (with a bg image, without the bg image it's a wip) 2024-12-17 15:33:21 +01:00
3b0b090430 core: add fonts 2024-12-17 14:12:42 +01:00
917ccf0465 wip: good text support (scrolling not quite working rn) 2024-12-12 23:14:20 +01:00
2edc92bbcc Merge branch 'main' of git.chauvet.pro:starnakin/42_KFS 2024-12-11 21:20:34 +01:00
5383c4eced wip: putchar and stuff 2024-12-11 21:19:40 +01:00
903b303322 fix: tools: font_converter import stddef.h 2024-12-11 21:05:26 +01:00
db596a9212 fix: putchat: use right index 2024-12-11 21:03:29 +01:00
99e2d7053b fix: tootls: font_converter: remove extra bracket 2024-12-11 20:55:41 +01:00
71 changed files with 62695 additions and 1165 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ obj
.* .*
compile_commands.json compile_commands.json
tags tags
base_fonts
*.log

View File

@ -1,9 +1,9 @@
NAME := bozOS NAME := bozOS
AS := i386-elf-as AS := i386-elf-as
ASFLAGS := ASFLAGS := -g
CC := i386-elf-gcc CC := i386-elf-gcc
CFLAGS := -std=gnu99 -ffreestanding -Wall -Wextra -iquotelibbozo/headers -iquoteheaders -MMD -fno-omit-frame-pointer -fstack-protector-all -g CFLAGS := -std=gnu99 -ffreestanding -Wall -Wextra -iquotelibbozo/headers -iquoteheaders -MMD -fno-omit-frame-pointer -fstack-protector-all -g3
LD := $(CC) LD := $(CC)
LDFLAGS := -T boot/linker.ld -ffreestanding -nostdlib LDFLAGS := -T boot/linker.ld -ffreestanding -nostdlib
LIBS := -L libbozo/build/ -lbozo -lgcc LIBS := -L libbozo/build/ -lbozo -lgcc
@ -40,11 +40,21 @@ iso: $(NAME)
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
fast-iso: $(NAME)
mkdir -p isodir/boot/grub
cp build/$(NAME).bin isodir/boot/$(NAME).bin
cp config/grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o build/$(NAME).iso --themes= isodir
rm -rf isodir
run-iso: iso run-iso: iso
qemu-system-i386 -cdrom build/$(NAME).iso -vga std qemu-system-i386 -cdrom build/$(NAME).iso -vga std
debug: iso fast-run-iso: fast-iso
qemu-system-i386 -s -S build/$(NAME).iso -vga std qemu-system-i386 -cdrom build/$(NAME).iso -vga std
debug: fast-iso
qemu-system-i386 -s -S -cdrom build/$(NAME).iso -vga std -D qemu.log -d in_asm,int -M smm=off
clean: clean:
make -C libbozo clean make -C libbozo clean
@ -59,5 +69,5 @@ re:
$(MAKE) fclean $(MAKE) fclean
$(MAKE) all $(MAKE) all
.PHONY: all clean fclean re run iso run-iso .PHONY: all clean fclean re run iso run-iso fast-iso fast-run-iso
-include $(DEP) -include $(DEP)

View File

@ -1,9 +1,6 @@
#pragma once #pragma once
// boolean types
#include <stdbool.h> #include <stdbool.h>
// size_t, already in libft.h but for readability
#include <stddef.h> #include <stddef.h>
// Remove this and replace it with <assert.h> header // Remove this and replace it with <assert.h> header
@ -64,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);
@ -74,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

@ -6,7 +6,8 @@ void date_cmd(char *arg);
void poweroff_cmd(char *arg); void poweroff_cmd(char *arg);
void stack_cmd(char *arg); void stack_cmd(char *arg);
void help_cmd(char *arg); void help_cmd(char *arg);
void reboot_cmd(char* arg); 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,6 +2,7 @@
#include "kpanic.h" #include "kpanic.h"
#include "kprintf.h" #include "kprintf.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)

View File

@ -6,4 +6,4 @@
void load_drivers(void); void load_drivers(void);
void keyboard_handler(struct registers *regs); void keyboard_handler(struct registers *regs);
void clock_handler(struct registers *regs); void clock_init(struct registers *regs);

View File

@ -5,5 +5,6 @@
struct font { struct font {
uint32_t height; uint32_t height;
uint32_t width; uint32_t width;
uint32_t yoffset;
char *bitmap; char *bitmap;
}; };

View File

@ -0,0 +1,878 @@
#pragma once
#include <stddef.h>
#include "font.h"
struct font consolas_regular_13_font[] = {
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
{
.width = 1,
.height = 1,
.yoffset = 12,
.bitmap = " ",
},
{
.width = 3,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ## ## ## ## ## ## #########",
},
{
.width = 6,
.height = 5,
.yoffset = 0,
.bitmap = "##############################",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
" ## ## ## ## ## ## #################### ## ## ## "
"## #################### ## ## ## ## ## ## ",
},
{
.width = 8,
.height = 15,
.yoffset = 0,
.bitmap =
" ### ## ##### ###### ## ## ## ## ##### ###### "
" ##### ### ## ### ######### ###### ## ## ",
},
{
.width = 11,
.height = 13,
.yoffset = 0,
.bitmap = " ### ## ##### ### ## ## ## ## ## ## ######## ### "
"## ## ###### ####### ## ## ## ### ## "
"## ## ##### ## ### ",
},
{
.width = 11,
.height = 13,
.yoffset = 0,
.bitmap = " #### ###### ## ## ## ## ###### "
"#### #### ## ###### ## ## ##### ## #### ## "
"#### ######## #### ### ",
},
{
.width = 3,
.height = 5,
.yoffset = 0,
.bitmap = "###############",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## "
" ## ## ### # ",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = " # ### ## ## ## ## ## ## ## ## ## ## "
" ## ## ### # ",
},
{
.width = 8,
.height = 8,
.yoffset = 0,
.bitmap =
" ## # ## # ######## ###### ###### ######## # ## # ## ",
},
{
.width = 8,
.height = 8,
.yoffset = 4,
.bitmap =
" ## ## ## ################ ## ## ## ",
},
{
.width = 5,
.height = 6,
.yoffset = 10,
.bitmap = " ### #### ### ####### ### ",
},
{
.width = 6,
.height = 2,
.yoffset = 7,
.bitmap = "############",
},
{
.width = 4,
.height = 3,
.yoffset = 10,
.bitmap = " ## ########",
},
{
.width = 9,
.height = 15,
.yoffset = 0,
.bitmap = " ## ## ### ## ### ## "
"### ## ## ### ## ### ## "
"### ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## ## ## ##### ###### ########## "
"###### ##### ## ## ## ###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " ## #### ##### ## ## ## ## ## "
"## ## ## ################",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### # ## ## ## ### ## "
"### ### ### ################",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## ##### ##### ## "
" ## ######## ##### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
" ### ### #### ##### ## ## ### ## ### "
"## ## ## #################### ## ## ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "###### ###### ## ## ##### ###### ## ## "
" ## ######### ##### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ##### ## ## ###### ####### ## #### "
" #### ##### ### ###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ### ## ### ## ### "
"## ### ### ### ### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ######### #### ##### ### ###### ###### ### "
" ##### #### ######### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ### ##### #### #### ## ####### "
"###### ## ## ##### #### ",
},
{
.width = 3,
.height = 9,
.yoffset = 4,
.bitmap = "######### #########",
},
{
.width = 5,
.height = 12,
.yoffset = 4,
.bitmap =
" ### ### ### ### #### ### ####### ### ",
},
{
.width = 7,
.height = 10,
.yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### "
"### # ",
},
{
.width = 8,
.height = 5,
.yoffset = 6,
.bitmap = "################ ################",
},
{
.width = 7,
.height = 10,
.yoffset = 3,
.bitmap = " # ### ### #### #### #### #### ### ### "
" # ",
},
{
.width = 6,
.height = 13,
.yoffset = 0,
.bitmap = "### ##### ### ## ## ##### #### ## ## ## "
" ### ### ### ",
},
{
.width = 10,
.height = 16,
.yoffset = 0,
.bitmap =
" #### ####### ## ## ## ## ## ##################### "
"######## ######## ######## ############## ## ###### ## "
"## ## ####### ##### ",
},
{
.width = 12,
.height = 12,
.yoffset = 1,
.bitmap = " ### #### #### ###### ## ## "
" ## ## ### ### ######## ######## ### ### "
" ## ## ### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "###### ########## #### #### ########## ####### ## "
" #### #### ######### ###### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## ### ## ## ## ## "
" ## ## # ####### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## #### #### #### #### "
" #### ##### ## ####### ##### ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ################ ## "
" ## ##############",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ################ ## "
" ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## #### ## ## ###### ###### "
" #### ## ## ## ####### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "## #### #### #### #### #################### "
" #### #### #### #### ##",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ## ## ## "
"## ## ## ################",
},
{
.width = 6,
.height = 12,
.yoffset = 1,
.bitmap = "############ ## ## ## ## ## ## ### "
"####### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
"## ### ## ### ## ### ## ### ##### #### #### "
" ##### ## ### ## ### ## ### ## ### ",
},
{
.width = 7,
.height = 12,
.yoffset = 1,
.bitmap = "## ## ## ## ## ## ## ## ## "
" ## ##############",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap = "### ####### ######## ######## "
"############################## ###### ## ###### ###### "
" ###### ###### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "### ##### ###### ###### ###### #### ## #### ## #### "
"###### ###### ###### ##### ###",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
" #### ######## ## ## ### #### #### #### "
" #### #### ### ## ## ######## #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "###### ####### ## ##### #### #### ########## "
"###### ## ## ## ## ",
},
{
.width = 9,
.height = 15,
.yoffset = 1,
.bitmap = " #### ####### ## ## ## #### #### #### "
" #### #### ## ## ## ####### ##### ## # "
" ##### ### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "##### ####### ## ## ## ## ## ## ###### ##### ## "
"### ## ### ## ### ## ##### ###",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = " #### ###### ## # ## ### ##### ##### "
" ### #### ######### ##### ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ## ## ## ## "
"## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "## #### #### #### #### #### #### #### "
" #### #### ### ###### #### ",
},
{
.width = 12,
.height = 12,
.yoffset = 1,
.bitmap = "### ### ### ## ### ### ## ## ### ### "
" ### ### ## ## ###### ###### #### "
" #### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
" ## # ## ## ## ## ## ## ## ## ## ## ## ## "
"######## ######## ######## ######## ### ### ### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
"### ### ## ## ### ### ###### #### #### "
"#### #### ###### ### ### ### ### ### ###",
},
{
.width = 10,
.height = 12,
.yoffset = 1,
.bitmap =
"## ##### ### ## ## ## ## ###### #### "
"#### ## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 1,
.bitmap = "################ ## ### ## ### ### "
"### ### ## ################",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = "############ ## ## ## ## ## ## ## ## ## "
"## ## ##########",
},
{
.width = 9,
.height = 15,
.yoffset = 0,
.bitmap = "## ### ## ### ## ### ## "
" ## ### ## ### ## ### "
" ## ## ",
},
{
.width = 5,
.height = 16,
.yoffset = 0,
.bitmap = "########## ## ## ## ## ## ## ## ## ## "
"## ## ############",
},
{
.width = 10,
.height = 6,
.yoffset = 1,
.bitmap =
" ## #### ###### ## ## ## ## ### ###",
},
{
.width = 10,
.height = 2,
.yoffset = 14,
.bitmap = "####################",
},
{
.width = 7,
.height = 5,
.yoffset = 0,
.bitmap = " ### ### ## ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
" #### ###### # ## ############## #### ########## ######",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ###### ####### ### #### "
" #### #### #### ########## ##### ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
" #### ######### ### ## ## ### # ###### #### ",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = " ## ## ## ## ###### ########## #### "
" #### #### #### ### ####### ### ##",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = " #### ###### ### #################### ### "
"####### ######",
},
{
.width = 9,
.height = 13,
.yoffset = 0,
.bitmap =
" #### ##### ## ## ## ####### ####### "
"## ## ## ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = " ################ ## ## ## ####### ###### ## "
"####### ########## ########## ##### ",
},
{
.width = 7,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ###### ########## #### #### "
" #### #### #### #### ##",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = " ### ### ### ##### ##### ## "
"## ## ## ## ################",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = " ### ### ### ############## ## ## "
" ## ## ## ## ### ######## #### ",
},
{
.width = 9,
.height = 13,
.yoffset = 0,
.bitmap = "## ## ## ## ## ### ## ### ##### "
" #### #### ##### ## ### ## ### ## ### ",
},
{
.width = 8,
.height = 13,
.yoffset = 0,
.bitmap = "##### ##### ## ## ## ## ## "
"## ## ## ## ################",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = "#### ## ################## ## #### ## #### ## #### ## #### "
"## #### ## ##",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
"###### ########## #### #### #### #### #### #### ##",
},
{
.width = 8,
.height = 9,
.yoffset = 4,
.bitmap = " #### ###### ### ##### #### #### ##### ### "
"###### #### ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = "###### ####### ### #### #### #### #### "
"########## ###### ## ## ## ",
},
{
.width = 8,
.height = 12,
.yoffset = 4,
.bitmap = " ###### ########## #### #### #### #### ### "
"####### ###### ## ## ##",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
"###### ########## #### #### ## ## ## ## ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
" ##### ###### ## #### ##### #### ############### ",
},
{
.width = 9,
.height = 12,
.yoffset = 1,
.bitmap = " # ## ## ################## ## ## "
" ## ## ## ###### #####",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
"## #### #### #### #### #### #### ########## ######",
},
{
.width = 10,
.height = 9,
.yoffset = 4,
.bitmap = "### ### ## ## ### ### ## ## ## ## ###### "
" #### #### ## ",
},
{
.width = 10,
.height = 9,
.yoffset = 4,
.bitmap = "### ### ## ## ## ## ## ## ## ## ######## ######## "
" ######## ### #### ### ### ",
},
{
.width = 11,
.height = 9,
.yoffset = 4,
.bitmap = " ### ### ### ### ### ### ##### #### "
"#### ###### ###### ### ### ",
},
{
.width = 10,
.height = 12,
.yoffset = 4,
.bitmap =
"### ### ### ## ### ### ## ## ###### ##### "
"#### ### ## ### ##### #### ",
},
{
.width = 7,
.height = 9,
.yoffset = 4,
.bitmap =
"############## ## ## ### ## ### ##############",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = " ### #### ## ## ## ## ## ### "
"#### ## ## ## ## ## ##### ####",
},
{
.width = 2,
.height = 18,
.yoffset = -2,
.bitmap = "####################################",
},
{
.width = 7,
.height = 16,
.yoffset = 0,
.bitmap = "### #### ## ## ## ## ## ### "
"#### ## ## ## ## ## ##### #### ",
},
{
.width = 9,
.height = 4,
.yoffset = 6,
.bitmap = " ### ######## #### ######## #### ",
},
{
.width = 0,
.height = 0,
.yoffset = 0,
.bitmap = NULL,
},
};

View File

@ -0,0 +1,770 @@
#pragma once
#include <stddef.h>
#include "font.h"
struct font eating_pasta_regular_13_font[] = {
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 1,
.height = 1,
.bitmap = " ",
},
{
.width = 4,
.height = 13,
.bitmap = "####### ### ### ### ### ### ### ### ### ### ### ",
},
{
.width = 6,
.height = 5,
.bitmap = " ## ##### ##### ## ## ## # ",
},
{
.width = 13,
.height = 12,
.bitmap = " ### ### #### #### #### #### "
"############ ############ #### #### ############ "
"############ ### ### ### ### #### #### ",
},
{
.width = 9,
.height = 15,
.bitmap = " # #### ###### ####### #### #### #### "
" ####### ###### # ### # ### ######## ####### "
"####### # ",
},
{
.width = 16,
.height = 13,
.bitmap = " #### ### ##### #### ### ## ### ### ## #### "
" ##### ### ### #### #### ### ###### "
"### ## ## #### ## ## ### ## ### #### ##### "
" #### #### ## ",
},
{
.width = 11,
.height = 13,
.bitmap = " #### ###### ### ## ### ### ###### "
"##### ### #### ### ######## ######## ### #### "
"######### ##### ### ### ",
},
{
.width = 3,
.height = 5,
.bitmap = " ######## ## # ",
},
{
.width = 5,
.height = 15,
.bitmap = " # ### #### ### #### ### ### ### ### ### ### ### "
"#### #### ### ",
},
{
.width = 6,
.height = 16,
.bitmap = " ## #### ### #### ### ### #### #### #### "
"#### ### ### #### #### ### ",
},
{
.width = 7,
.height = 6,
.bitmap = " # # # # ##### ##### ##### # ",
},
{
.width = 8,
.height = 9,
.bitmap = " ### ### ### ######################## ### "
"### ## ",
},
{
.width = 4,
.height = 5,
.bitmap = " ## ### ### ### ## ",
},
{
.width = 8,
.height = 3,
.bitmap = "########################",
},
{
.width = 4,
.height = 4,
.bitmap = " ## ####### ###",
},
{
.width = 7,
.height = 14,
.bitmap = " ### ### ### ### ### ### ### ### "
"#### ### ### #### ### ### ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### ###### ######## ### ### ### ### ## ### ## "
"## ### ## ### ### ### ### ######## ####### ##### ",
},
{
.width = 6,
.height = 13,
.bitmap = " ### #### ################# ### ### ### ### "
"### ### ### ###",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ###### ######## ### #### ### #### "
"### #### #### #### ####### ##################",
},
{
.width = 10,
.height = 13,
.bitmap = " #### ####### ######## # ### ## #### "
" #### # ### ### ## ### ######## ######## "
" ##### ",
},
{
.width = 10,
.height = 13,
.bitmap =
" #### ##### ##### ###### ### ### ####### ### "
"#### ############################# # #### #### #### ",
},
{
.width = 8,
.height = 14,
.bitmap = " ##### ####### ####### ### ### ###### ####### "
"######## #### #### ########### ####### ##### ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ### #### ###### ######## ### "
"####### ### ### ### ### ### ######## ###### ## ",
},
{
.width = 7,
.height = 13,
.bitmap = "############## ###### ### #### ### ### #### "
"### ### ### #### #### ",
},
{
.width = 10,
.height = 13,
.bitmap = " ##### ####### ######## ### ### ### ## ####### "
" ###### ######## ### ## ### #### ######## ######## "
" ###### ",
},
{
.width = 9,
.height = 13,
.bitmap =
" #### ####### ######## ## ###### ###### ### ######## "
"######## ###### ### #### #### ## ",
},
{
.width = 5,
.height = 10,
.bitmap = " ### #### #### ### ## ### #### ### ",
},
{
.width = 5,
.height = 12,
.bitmap =
" # ### #### ### ## ## ### ### ## ",
},
{
.width = 7,
.height = 9,
.bitmap =
" # ### #### ##### ### ###### ##### ### ",
},
{
.width = 7,
.height = 7,
.bitmap = " #### ###### ###### ###### ###### ######",
},
{
.width = 7,
.height = 9,
.bitmap =
" # ### #### ##### ### ###### ##### ### # ",
},
{
.width = 8,
.height = 13,
.bitmap = " #### ###### ###### ### ###### ## ### ##### "
"#### ### ### ### ### ",
},
{
.width = 14,
.height = 14,
.bitmap = " ###### ######## ########## #### ### "
"### ######### ######### ### ## ### # #### ## ### ##### "
"############ ### ### ### #### ######### "
"######## ####### ",
},
{
.width = 11,
.height = 12,
.bitmap = " ##### ##### ###### ## ### ### ### "
"### ### ### ## ######### ######### ### ### ### "
"####### ####",
},
{
.width = 9,
.height = 12,
.bitmap = "####### ######## ### ####### ############ ####### "
"######## ### ### ### #################### ###### ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### ###### #### ### ### ### ### #### #### "
" #### ### ## ### ### ######## ###### #### ",
},
{
.width = 9,
.height = 12,
.bitmap = "##### ####### ####### ### #### ## ### ### ## ### "
"###### ####### #### ####### ###### #### ",
},
{
.width = 9,
.height = 13,
.bitmap =
"######## ######## ######## ### ### #### ####### "
"###### ### ### ######## ######## ######## ",
},
{
.width = 8,
.height = 12,
.bitmap = "########################### ### ####### ####### "
"####### ### ### ### ### ",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ###### ######## ### ### ### #### #### "
" #### #### ### #### ### ## ######## ###### #### ",
},
{
.width = 10,
.height = 13,
.bitmap = "### ###### ###### ###### ###### "
"##################################### ####### ####### "
"####### ####### ####",
},
{
.width = 3,
.height = 12,
.bitmap = "####################################",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ### ### ### ### ### "
"###### ###### ######## ### ######## ####### #### ",
},
{
.width = 10,
.height = 13,
.bitmap = "### ### ### ### ### ### ### ### #### ####### "
"###### ###### ####### ### #### ### #### ### ### "
"### # ",
},
{
.width = 8,
.height = 13,
.bitmap = " ### ### ### ### ### ### ### "
"### ### ### ####### ####### #######",
},
{
.width = 12,
.height = 13,
.bitmap = " ## ## #### #### ##### #### ##### ##### ##### "
"##### ########### ########### ### ### ### ### ### ### ### "
"# ### ### ### ### ### ### ###",
},
{
.width = 10,
.height = 13,
.bitmap = "#### ####### ######## ######## ######## ######### "
"###### ## ###### ######### ######### ######## ######## "
"####### ####",
},
{
.width = 10,
.height = 13,
.bitmap =
" ##### ####### ######### ### #### ### ###### ###### "
" ###### ### ### ### ### #### ######## ####### ##### ",
},
{
.width = 8,
.height = 13,
.bitmap = "### ###### ####### ### ###### ###### ###### "
"########### ###### #### ### ### ### ",
},
{
.width = 10,
.height = 15,
.bitmap = " ##### ####### ######### ### #### ### ###### "
"###### ###### ####### ##### ### ##### ######## "
"####### ####### ## # ",
},
{
.width = 9,
.height = 13,
.bitmap = "### ###### ####### ### ### ### ### ### ### ### "
"#### ####### ###### ###### ### ### ### ####### # ",
},
{
.width = 9,
.height = 13,
.bitmap =
" ##### ###### ####### #### #### #### ####### "
" ##### #### ### ######## ####### ###### ",
},
{
.width = 8,
.height = 12,
.bitmap = "################ ### ### ### ### ### "
"### ### ### ### ### ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ### ### ### ### ### ### ## ### ## ### ## ### ### "
" ### ### ### ### ### ### ### ######## ###### #### ",
},
{
.width = 10,
.height = 13,
.bitmap =
"### ###### ### ### #### ### ### ### ### ### ### ### "
"### ###### ###### ###### ###### ##### #### ",
},
{
.width = 14,
.height = 13,
.bitmap =
"### #### ###### #### ####### #### ### ### #### ### ### "
"##### ### ############ ############ ###### ##### ##### ##### "
"##### ##### #### #### #### #### #### ### ",
},
{
.width = 10,
.height = 13,
.bitmap = " ### ## #### #### ######## ###### ###### #### "
" #### ##### ###### ####### ### #### #### ### "
"### ####",
},
{
.width = 11,
.height = 13,
.bitmap = "#### ####### ### #### #### #### ### ####### "
"##### #### ### ### ### ### "
" ### ### ",
},
{
.width = 8,
.height = 13,
.bitmap = " ####### ####### ## #### ### ### ### ### "
"### ### ### ###### ################",
},
{
.width = 7,
.height = 16,
.bitmap = " ####################### ### ### ### ### ### "
" ### ### ### #### ############## ######",
},
{
.width = 7,
.height = 14,
.bitmap = "### ### #### ### ### #### ### ### "
"#### ### ### ### #### ###",
},
{
.width = 7,
.height = 16,
.bitmap = "###### ############## #### ### ### ### ### "
"### ### ### ### ################# ###### ",
},
{
.width = 8,
.height = 7,
.bitmap = " ### #### #### ##### ###### ## ### ### ###",
},
{
.width = 9,
.height = 3,
.bitmap = "###########################",
},
{
.width = 4,
.height = 3,
.bitmap = " ## ### # ",
},
{
.width = 11,
.height = 12,
.bitmap = " #### ##### ###### ## ### ### ### "
"### ### ### ### ######### ######### ### ### #### "
"####### ###",
},
{
.width = 9,
.height = 12,
.bitmap = "###### ######## ### ####### ############ ####### "
"######## ### ### ### #################### ###### ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### ###### #### ### ### ### ### #### #### "
" #### #### ## ### ### ######## ###### #### ",
},
{
.width = 10,
.height = 12,
.bitmap =
" ##### ###### ####### ## #### ## ### ## ## ## "
" ### ### ### ### #### ####### ###### #### ",
},
{
.width = 9,
.height = 13,
.bitmap =
" ######## ######## ######## ### ### #### ###### "
"###### ### ### ######## ######## ########",
},
{
.width = 8,
.height = 12,
.bitmap = "####################### ### ### ####### ####### "
"####### ### ### ### ### ",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ###### ######## ### ### ### #### #### "
" #### ######## #### ### ### ######## ###### #### ",
},
{
.width = 10,
.height = 13,
.bitmap = "### ###### ###### ####### ####### "
"##################################### ####### ####### "
"####### ####### ####",
},
{
.width = 3,
.height = 12,
.bitmap = "####################################",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ### ### ### ### ### "
"###### ###### ######## ############ ####### #### ",
},
{
.width = 11,
.height = 13,
.bitmap = " ### ### ### ### ### ### ### ### #### "
"####### ###### ###### ####### ### #### ### "
"#### ### #### ### # ",
},
{
.width = 8,
.height = 13,
.bitmap = " ### ### ### ### ### ### ### "
"### ### ### ####### ####### ###### ",
},
{
.width = 12,
.height = 13,
.bitmap = " ## ## #### #### ##### #### ##### ##### ##### "
"##### ########### ########### ### ### ### ### ### ### ### "
"# ### ### ### ### ### ### ###",
},
{
.width = 10,
.height = 13,
.bitmap = "#### ####### ####### ######## ######## ######### "
"###### ## ## ### ##### ### ##### ### #### ### #### ### "
"### ### ### ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ##### ####### ######### ### #### ### ###### ###### "
" ###### ####### ### ### #### ######## ####### ##### ",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ###### ####### ### ### ### ### ### ### ### "
"#### ####### ###### #### ### ### ### ",
},
{
.width = 10,
.height = 15,
.bitmap = " ##### ####### ######### ### #### ### ###### "
"###### ###### ####### ##### ### ##### ######## "
"####### ####### ### # ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ### ###### ####### ### ### ### ### ### ### ### "
"#### ####### ###### ###### ### ### ### #### ### # ",
},
{
.width = 9,
.height = 13,
.bitmap =
" ##### ###### ####### #### #### #### ####### "
" ##### #### ### ######## ####### ###### ",
},
{
.width = 8,
.height = 12,
.bitmap = "################ ### ### ### ### ### "
"### ### ### ### ### ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ### ### ### ### ## ###### ###### ###### ### ## "
" ### ### ### ### ### ### ### ######## ###### #### ",
},
{
.width = 10,
.height = 13,
.bitmap =
"### ####### ### ### #### ### ### ### ### ### ### ### "
"### ###### ###### ###### ###### ##### #### ",
},
{
.width = 14,
.height = 13,
.bitmap =
"### #### ###### #### ###### #### ### ### #### ### ### "
"######### ############ ############ ##### ##### ##### ##### "
"##### ##### #### #### #### #### #### ### ",
},
{
.width = 10,
.height = 13,
.bitmap = " ### ## #### #### ######## ###### ###### #### "
" #### ##### ###### ####### ### #### #### ### "
"### ####",
},
{
.width = 11,
.height = 13,
.bitmap = "#### ####### ### #### #### ### ### ####### "
"##### ##### ### ### ### ### "
" ### ### ",
},
{
.width = 8,
.height = 13,
.bitmap = " ####### ####### ## #### ### ### ### ### "
"### ### ### ###### ################",
},
{
.width = 6,
.height = 17,
.bitmap = " # ### #### #### ### ### ### ### #### ### "
" #### #### #### #### #### #### # ",
},
{
.width = 4,
.height = 17,
.bitmap = " ###########################################################"
"########",
},
{
.width = 6,
.height = 17,
.bitmap = " ## ### ##### #### ### ### ### #### ### "
"#### ### ### ### #### ##### ### ## ",
},
{
.width = 10,
.height = 5,
.bitmap = " ## #### # ########## ######### #### ",
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,765 @@
#pragma once
#include <stddef.h>
#include "font.h"
struct font minecraft_medium_13_font[] = {
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
{
.width = 1,
.height = 1,
.bitmap = " ",
},
{
.width = 2,
.height = 13,
.bitmap = "#################### ####",
},
{
.width = 9,
.height = 7,
.bitmap =
" ## ### ## ### ## ### ## ############## ## ## ## ",
},
{
.width = 11,
.height = 13,
.bitmap = " ## ### ## ### ## ### "
"################################# ## ### ## ### "
"###################### ## ### ## ### ## ### ",
},
{
.width = 9,
.height = 15,
.bitmap = " ## ## ####### ################## ## "
" ## ## ## ## ################## "
" ## ## ",
},
{
.width = 13,
.height = 13,
.bitmap = " ## # # # # # # # # # ## # # "
"## # # ## ## ## # ## # # # "
" # # # # # # # # # # ## ",
},
{
.width = 11,
.height = 13,
.bitmap = " ## ## ## ### ## ### ######### "
"#### ### #### ##### ### ## ### ## ### ## "
"### #### ### #### ###",
},
{
.width = 2,
.height = 5,
.bitmap = "##########",
},
{
.width = 6,
.height = 13,
.bitmap = " #### ###### ## ## ## ## ## ## ## "
"## #### ####",
},
{
.width = 6,
.height = 13,
.bitmap = "#### #### ## ## ## ## ## ## ## "
"## ###### #### ",
},
{
.width = 6,
.height = 7,
.bitmap = "## #### ## #### #### ######## #### ##",
},
{
.width = 9,
.height = 9,
.bitmap = " ## ## ## ## ################## ## "
" ## ## ",
},
{
.width = 2,
.height = 4,
.bitmap = "#### ## ",
},
{
.width = 5,
.height = 2,
.bitmap = "##########",
},
{
.width = 2,
.height = 2,
.bitmap = "####",
},
{
.width = 9,
.height = 13,
.bitmap = " ## ## # # # # # "
" # # # # # # ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ## ##### ###### ###### ###### ## "
"##### ## ###### ###### ##### ### #### #### ",
},
{
.width = 6,
.height = 13,
.bitmap = " ## ## #### #### #### ## ## ## ## ## "
" ## ############",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ## ##### ##### ##### ## "
"## ## ## ## ## ##################",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ## ##### ##### ### ### "
"## ## ##### ##### ### #### #### ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ### ### ##### ##### ####### ## ### ## "
"### ## ### ## ### #################### ### ### ",
},
{
.width = 11,
.height = 13,
.bitmap = "######### ######### ## ## ## ## "
" ## ####### ####### # #### "
"### ######## ######## ",
},
{
.width = 10,
.height = 13,
.bitmap =
" ##### ##### ## ## #### ## ## "
" ####### ####### ## ##### ### ##### ##### ",
},
{
.width = 9,
.height = 13,
.bitmap = "#################### ##### ##### ##### ## "
"## ## ## ## ## ## ## ",
},
{
.width = 9,
.height = 13,
.bitmap =
" #### #### ## ##### ##### ##### ### #### "
"#### ## ##### ##### ### #### #### ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ## ##### ##### ##### ##### "
"### ####### ####### ### ### #### #### ",
},
{
.width = 2,
.height = 10,
.bitmap = "###### ####",
},
{
.width = 2,
.height = 12,
.bitmap = "###### #### ## ",
},
{
.width = 6,
.height = 9,
.bitmap = " ## ## #### ## ## ## ## ## ##",
},
{
.width = 9,
.height = 7,
.bitmap =
"########################### ##################",
},
{
.width = 6,
.height = 9,
.bitmap = "## ## #### ## ## ## ## ## ## ",
},
{
.width = 9,
.height = 13,
.bitmap = " #### #### ## ##### ##### ### ### "
"## ## ## ## ## ## ",
},
{
.width = 15,
.height = 16,
.bitmap =
" ########### ############# ## #### #### "
"###### #### ###### #### ###### #### ## ## #### ## "
"## #### ## ## #### ## ## #### ############# ######### "
"## ## ############# ########### ",
},
{
.width = 10,
.height = 13,
.bitmap = " ##### ##### ## ##### "
"################################### ##### ##### "
"##### ##### ##### ###",
},
{
.width = 11,
.height = 13,
.bitmap = "######### ######### ## ##### ##### ##### "
" ############ ######### ## ##### ##### "
"############ ######### ",
},
{
.width = 12,
.height = 13,
.bitmap = " ######### ######### ## #### #### "
"#### ## ## ## ## "
"#### ## ######### ######### ",
},
{
.width = 11,
.height = 13,
.bitmap = "######### ######### ## ##### ##### ##### "
" ##### ##### ##### ##### ##### "
"############ ######### ",
},
{
.width = 11,
.height = 13,
.bitmap = "######################## ## ##### "
"##### ##### ## ## ## ## "
" ######################",
},
{
.width = 10,
.height = 13,
.bitmap = "###################### ## ###### ###### "
"###### ## ## ## ## ## "
"## ",
},
{
.width = 12,
.height = 13,
.bitmap = " ########## ############ ## ## "
"####### ####### ####### #### #### "
" #### ## ######## ######## ",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ##### ##### ##### ##### "
" ########################### ##### ##### "
"##### ##### ###",
},
{
.width = 4,
.height = 13,
.bitmap = "######## ## ## ## ## ## ## ## ## ## ########",
},
{
.width = 7,
.height = 13,
.bitmap = " ## ## ## ## ## ## ## ## "
" #### #### ## ### ### ",
},
{
.width = 10,
.height = 13,
.bitmap =
"## ## ##### ##### ## ## ## ## ## ##### "
" ##### ## ## ## ## ## ##### ##### ###",
},
{
.width = 10,
.height = 13,
.bitmap =
"## ## ## ## ## ## ## "
" ## ## ## ## ####################",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ####### ######### ################## "
"## ##### ## ##### ##### ##### ##### "
"##### ##### ###",
},
{
.width = 11,
.height = 13,
.bitmap = "## ####### ####### ##### ## ##### ## ##### "
"## ##### ####### ####### ##### ##### "
"##### ##### ###",
},
{
.width = 13,
.height = 13,
.bitmap = " ######### ######### ## #### #### "
" #### #### #### #### #### "
" #### ## ######### ######### ",
},
{
.width = 11,
.height = 13,
.bitmap = "######### ######### ## ##### "
"####################### ######### ## ## "
"## ## ## ## ",
},
{
.width = 13,
.height = 13,
.bitmap = " ######### ######### ## #### #### "
" #### #### #### #### #### "
" #### ### ## ######### ###########",
},
{
.width = 13,
.height = 13,
.bitmap = "########## ########## ## ## ## ## "
"############ ########## ########## ## ### ## "
"### ## ### ## ### ## #### ##",
},
{
.width = 10,
.height = 13,
.bitmap = " ######## ########## ## ####### ##### "
" ##### ### ### ### ########## "
"####### ",
},
{
.width = 11,
.height = 13,
.bitmap = "###################### ## ## ## "
"## ## ## ## ## ## "
" ## ## ",
},
{
.width = 10,
.height = 13,
.bitmap =
"## ##### ##### ##### ##### ##### ##### "
" ##### ##### ##### ##### ### ###### ###### ",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ##### ##### ##### ##### "
" ### ## ### ## ### ## ### ## ## "
" ## ## ",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ##### ##### ##### ##### "
" ##### ##### ## ##### ## ####### ######### "
"####### ##### ###",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ### ## ### ## ### ####### "
"## ## ## ### ## ### ## ##### "
"##### ##### ###",
},
{
.width = 11,
.height = 13,
.bitmap = "## ##### ### ## ### ## ### ####### "
"## ## ## ## ## ## "
" ## ## ",
},
{
.width = 11,
.height = 13,
.bitmap = "###################### ### ### ##### "
" ### ### ## ## ## ## "
" ######################",
},
{
.width = 4,
.height = 16,
.bitmap =
"########## ## ## ## ## ## ## ## ## ## ## ## ########",
},
{
.width = 9,
.height = 13,
.bitmap = "# # # # # # # "
" # # # # # ##",
},
{
.width = 4,
.height = 16,
.bitmap =
"######## ## ## ## ## ## ## ## ## ## ## ## ##########",
},
{
.width = 9,
.height = 7,
.bitmap =
" ## ## ## ## ## ## ### ##### ### ##",
},
{
.width = 10,
.height = 1,
.bitmap = "##########",
},
{
.width = 3,
.height = 3,
.bitmap = "# # #",
},
{
.width = 10,
.height = 10,
.bitmap = "####### ####### ####### ### ######## "
"########## ##### ### ######## ########",
},
{
.width = 11,
.height = 13,
.bitmap = "## ## ## ## ## ##### ## "
"##### ## ##### #### ####### ##### ##### "
"############ ######### ",
},
{
.width = 10,
.height = 10,
.bitmap = " ##### ##### ##### ## ##### ##### "
"## ##### ### ##### ##### ",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ### ### ####### ####### ######### "
"##### ##### ##### ##### #####################",
},
{
.width = 9,
.height = 10,
.bitmap = " ####### ####### ######### ################## ## "
" ## ### ####### #######",
},
{
.width = 9,
.height = 13,
.bitmap = " ##### ##### ## ########################### ## "
" ## ## ## ## ## ## ",
},
{
.width = 9,
.height = 14,
.bitmap =
" ####### ####### ######### ##### ### ####### ####### "
" ### ### ##### ##### ### #### #### ",
},
{
.width = 9,
.height = 13,
.bitmap = "## ## ## ## ## ## ## ## ## "
"## #### ####### ##### ##### ##### ##### ###",
},
{
.width = 2,
.height = 13,
.bitmap = "#### ####################",
},
{
.width = 7,
.height = 13,
.bitmap = " ## ## ## ## ## ## ## "
" #### #### ## ### ### ",
},
{
.width = 9,
.height = 13,
.bitmap = "## ## ## ##### ##### ####### ## ## "
"## #### #### ## ## ## ## ## ##### ###",
},
{
.width = 2,
.height = 13,
.bitmap = "##########################",
},
{
.width = 15,
.height = 10,
.bitmap = "###### ##### ###### ##### ###### ##### ## ### "
"#### ### #### ### #### ### #### ### "
"#### ### #### ### ##",
},
{
.width = 10,
.height = 10,
.bitmap = "####### ####### ####### ## ##### ##### "
"##### ##### ##### ##### ###",
},
{
.width = 9,
.height = 10,
.bitmap = " #### #### #### ## ##### ##### ##### "
"##### ### #### #### ",
},
{
.width = 10,
.height = 13,
.bitmap =
"## ### ## ### ## ### #### ####### ##### ##### "
" ########## ####### ## ## ## ## ",
},
{
.width = 9,
.height = 13,
.bitmap = " ### ### ####### ######### ###### ##### ##### "
"##### ### ####### ####### ### ### ###",
},
{
.width = 7,
.height = 10,
.bitmap = "## ### ################# ### ## ## ## ## "
" ## ",
},
{
.width = 7,
.height = 11,
.bitmap = " ##### ############## ## ### ### ## "
" ####### ##### ",
},
{
.width = 5,
.height = 12,
.bitmap =
" ## ## #### #### #### ## ## ## ## ## ## ##",
},
{
.width = 9,
.height = 10,
.bitmap = "## ##### ##### ##### ##### ##### ##### "
"##### ### ####### #######",
},
{
.width = 11,
.height = 7,
.bitmap = "## ##### ##### ### ## ### ## ### "
"## ## ",
},
{
.width = 12,
.height = 9,
.bitmap = "## #### #### #### #### ## "
"#### ## #### ## ## ########## ##########",
},
{
.width = 11,
.height = 11,
.bitmap =
"## ##### ####### ##### ## ### ## ### ## "
" ## ## ### ## ### ## ##### ###",
},
{
.width = 9,
.height = 12,
.bitmap = "## ##### ##### ##### ##### ##### ### "
"####### ####### ### ######### ###### ",
},
{
.width = 9,
.height = 11,
.bitmap = "########################### ## ## ## ## "
" ## ## ##################",
},
{
.width = 5,
.height = 17,
.bitmap = " ## ## ## ## ## ## ## ## ## ## ## ## "
" ## ## ## ## ##",
},
{
.width = 2,
.height = 17,
.bitmap = "##################################",
},
{
.width = 5,
.height = 17,
.bitmap = "## ## ## ## ## ## ## ## ## ## ## ## "
" ## ## ## ## ## ",
},
{
.width = 11,
.height = 2,
.bitmap = " ### ##### #### ",
},
{
.width = 0,
.height = 0,
.bitmap = NULL,
},
};

View File

@ -1,9 +1,10 @@
#pragma once #pragma once
#include "tss.h"
#include <stdint.h> #include <stdint.h>
#define GDT_ADDRESS 0xC0105040 #define GDT_SIZE 8
#define GDT_SIZE 7
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR // https://wiki.osdev.org/Global_Descriptor_Table#GDTR
struct gdt_descriptor { struct gdt_descriptor {
@ -11,6 +12,8 @@ struct gdt_descriptor {
uint32_t base; uint32_t base;
} __attribute__((packed)); } __attribute__((packed));
extern struct tss TSS;
void init_gdt(); void init_gdt();
#define GDT_FLAG_64BIT_MODE 0b0010 #define GDT_FLAG_64BIT_MODE 0b0010
@ -39,3 +42,4 @@ extern uint8_t gdt_entries[GDT_SIZE * 8];
#define GDT_OFFSET_USER_CODE 0x20 #define GDT_OFFSET_USER_CODE 0x20
#define GDT_OFFSET_USER_DATA 0x28 #define GDT_OFFSET_USER_DATA 0x28
#define GDT_OFFSET_USER_STACK 0x30 #define GDT_OFFSET_USER_STACK 0x30
#define GDT_OFFSET_TSS 0x38

File diff suppressed because one or more lines are too long

View File

@ -18,3 +18,14 @@ typedef void (*isr_t)(struct registers *);
void isr_handler(struct registers *regs); void isr_handler(struct registers *regs);
void pic_send_eoi(uint8_t 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)
{
__asm__ volatile("cli");
}
// aka sti
static inline void toris(void)
{
__asm__ volatile("sti");
}

View File

@ -3,7 +3,35 @@
#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",

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "multiboot.h" #include "multiboot.h"
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -15,9 +16,9 @@
#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 ((uint32_t) & _kernel_end - HEAP_END) #define HEAP_START ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_START ((uint32_t) & _kernel_start) #define KERNEL_START ((uint32_t)&_kernel_start)
#define KERNEL_END ((uint32_t) & _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) \
@ -44,7 +45,9 @@ struct frame_zone {
extern uint32_t _kernel_end; extern uint32_t _kernel_end;
extern uint32_t _kernel_start; extern uint32_t _kernel_start;
extern uint32_t boot_page_directory; extern uint32_t boot_page_directory;
extern uint32_t *page_directory; extern uint32_t boot_page_table1;
extern uint32_t *kernel_pd;
extern uint32_t *current_pd;
extern uint32_t page_table_default[1024]; extern uint32_t page_table_default[1024];
extern uint32_t mem_size; extern uint32_t mem_size;
extern multiboot_memory_map_t *mmap_addr; extern multiboot_memory_map_t *mmap_addr;
@ -55,7 +58,9 @@ uint32_t *virt_to_phys(uint32_t *virt_addr);
void init_memory(multiboot_info_t *mbd, uint32_t 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);
void *alloc_pages(size_t size); int8_t add_single_page(void *frame);
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(uint32_t page_table[1024], uint16_t start); void init_page_table(uint32_t page_table[1024], uint16_t start);
int16_t add_page_table(uint16_t pd_index); int16_t add_page_table(uint16_t pd_index);
void switch_pd(uint32_t *pd, uint32_t *cr3);

View File

@ -3,4 +3,3 @@
#define PROMPT "> " #define PROMPT "> "
void shell_init(void); void shell_init(void);
void auto_complete(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;
}; };

44
headers/task.h Normal file
View File

@ -0,0 +1,44 @@
#pragma once
#include "list.h"
#include "memory.h"
#include "signal.h"
#include <stdint.h>
extern struct task *current_task;
enum status { ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED };
enum owner { OWNER_KERNEL, OWNER_USER };
#define STACK_SIZE PAGE_SIZE * 4
struct task {
uint8_t *esp;
uint8_t *esp0;
uint32_t *cr3; // physical
uint32_t *heap; // virtual
uint32_t *eip;
uint16_t pid;
uint8_t status;
uint8_t uid;
struct task *daddy;
struct task *child;
struct signal_data signals;
struct task *next;
struct task *prev;
};
void scheduler(void);
void switch_to_task(struct task *next_task);
struct task *create_task(uint8_t uid);
int8_t create_kernel_task(void);
void remove_task(struct task *task);
struct task *copy_task(const struct task *task);
void kfork(struct task *daddy);
void zombify_task(struct task *task);
// utils
void exec_fn(void (*fn)(void));
uint16_t fork(void);
uint16_t wait(void);

View File

@ -1,21 +1,30 @@
#pragma once #pragma once
#include "font.h"
#include "icon.h"
#include "keyboard.h" #include "keyboard.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#define VGA_WIDTH 80 #define SCREEN_WIDTH 1024
#define VGA_HEIGHT 25 #define SCREEN_HEIGHT 768
#define TERM_BUF ((uint16_t *)0xC03FF000) #define FONT_WIDTH 13
#define FONT_HEIGHT 17
#define VGA_WIDTH (SCREEN_WIDTH / FONT_WIDTH)
#define VGA_HEIGHT (SCREEN_HEIGHT / FONT_HEIGHT)
#define TERM_COUNT 10 #define TERM_COUNT 10
struct screen { struct screen {
size_t row; size_t row;
size_t column; size_t column;
uint8_t color; uint32_t fg_color;
uint16_t buffer[VGA_WIDTH * VGA_HEIGHT]; uint32_t bg_color;
uint8_t default_color; uint8_t buffer[VGA_WIDTH * VGA_HEIGHT];
uint32_t default_color;
struct icon *background;
struct font *font;
char line[256]; char line[256];
}; };
@ -41,20 +50,22 @@ 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(uint8_t color); void terminal_set_bg_color(uint32_t color);
void terminal_set_fg_color(uint8_t 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);
int terminal_writelong(long number); int terminal_writelong(long number);
void terminal_set_screen(int pos); void terminal_set_screen(int pos);
void terminal_clear(void); void terminal_clear(void);
void terminal_refresh(void);
struct key_event terminal_getkey(void); 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(uint8_t fg_color); void terminal_set_default_fg_color(uint32_t fg_color);
void terminal_set_default_bg_color(uint8_t fg_color); void terminal_set_default_bg_color(uint32_t fg_color);
void terminal_change_default_fg_color(uint8_t color); void terminal_change_default_fg_color(uint32_t color);
uint8_t terminal_get_default_color(void); uint32_t terminal_get_default_color(void);
uint8_t terminal_get_char(int column, int row); uint8_t terminal_get_char(int column, int row);
void terminal_remove_last_char(void);

5
headers/time.h Normal file
View File

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

60
headers/tss.h Normal file
View File

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

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "icon.h" #include "icon.h"
#include <stdint.h> #include <stdint.h>
struct vbe_interface { struct vbe_interface {

6
libbozo/headers/list.h Normal file
View File

@ -0,0 +1,6 @@
#pragma once
struct list {
void *content;
struct list *next;
};

View File

@ -12,3 +12,4 @@ void *memcpy(void *dest, const void *src, size_t n);
int memcmp(const void *s1, const void *s2, size_t n); int memcmp(const void *s1, const void *s2, size_t n);
void *memset(void *str, int c, size_t n); void *memset(void *str, int c, size_t n);
void *memmove(void *dest, const void *src, size_t n); void *memmove(void *dest, const void *src, size_t n);
void bzero(void *s, size_t n);

View File

@ -1,4 +1,4 @@
int isprint(int c) int isprint(int c)
{ {
return (32 <= c && c < 127); return (c >= 32 && c < 127);
} }

View File

@ -0,0 +1,6 @@
#include "string.h"
void bzero(void *s, size_t n)
{
memset(s, 0, n);
}

View File

@ -1,3 +1,4 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>

View File

@ -1,3 +1,4 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>

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

@ -1,6 +1,52 @@
#include "interrupts.h" #include <stdint.h>
void clock_handler(struct registers *regs) #include "debug.h"
#include "drivers.h"
#include "interrupts.h"
#include "kprintf.h"
#include "memory.h"
#include "sys/io.h"
#include "task.h"
#define PIT_CHANNEL0 0x40
#define PIT_FREQUENCY 1193182
#define PIT_COUNT (65535 / 2)
#define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
static uint32_t sleep_counter;
static uint32_t scheduler_counter;
static void clock_handler(struct registers *regs);
static void set_pit_count(unsigned count)
{
cli();
outb(0x40, count & 0xFF); // Low byte
outb(0x40, (count & 0xFF00) >> 8); // High byte
toris();
}
void clock_init(struct registers *regs)
{ {
(void)regs; (void)regs;
set_pit_count(PIT_COUNT);
register_interrupt_handler(0, clock_handler);
}
static void clock_handler(struct registers *regs)
{
(void)regs;
if (scheduler_counter % 10 == 0)
scheduler();
scheduler_counter++;
sleep_counter--;
}
void sleep(uint64_t delay)
{
sleep_counter = delay / DELAY;
while (sleep_counter)
;
} }

View File

@ -3,6 +3,6 @@
void load_drivers(void) void load_drivers(void)
{ {
register_interrupt_handler(0, clock_handler); register_interrupt_handler(0, clock_init);
register_interrupt_handler(1, keyboard_handler); register_interrupt_handler(1, keyboard_handler);
} }

View File

@ -5,8 +5,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
extern struct screen *screen;
static bool new_input_indicator = false; static bool new_input_indicator = false;
static struct key_event new_input = {}; static struct key_event new_input = {};

View File

@ -1,5 +1,4 @@
#include "vbe.h" #include "vbe.h"
#include "drivers.h"
#include "icon.h" #include "icon.h"
struct vbe_interface display; struct vbe_interface display;

View File

@ -5,8 +5,9 @@
extern void set_gdt(uint32_t gdt_ptr); extern void set_gdt(uint32_t gdt_ptr);
struct tss TSS;
uint8_t gdt_entries[GDT_SIZE * 8]; uint8_t gdt_entries[GDT_SIZE * 8];
struct gdt_descriptor *gdtr = (struct gdt_descriptor *)GDT_ADDRESS; struct gdt_descriptor gdtr;
static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit, static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
uint8_t access, uint8_t granularity) uint8_t access, uint8_t granularity)
@ -36,8 +37,8 @@ static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
void init_gdt(void) void init_gdt(void)
{ {
gdtr->size = 8 * GDT_SIZE - 1; gdtr.size = 8 * GDT_SIZE - 1;
gdtr->base = (uint32_t)&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
@ -90,6 +91,9 @@ void init_gdt(void)
GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA | GDT_ACCESS_RW_READABLE_FOR_CODE_WRITABLE_FOR_DATA |
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
set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (uint32_t)&TSS,
sizeof(struct tss) - 1, 0x89, 0);
set_gdt(((uint32_t)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>
@ -35,6 +36,8 @@ void isr_handler(struct registers *regs)
{ {
uint8_t 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

@ -38,6 +38,7 @@ irq_common_stub:
iret iret
irq0: irq0:
mov [esp_backup], esp
push 0 push 0
push 32 push 32
jmp irq_common_stub jmp irq_common_stub

View File

@ -1,3 +1,4 @@
#include <cpuid.h> #include <cpuid.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>

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

@ -3,7 +3,6 @@
#include "drivers.h" #include "drivers.h"
#include "gdt.h" #include "gdt.h"
#include "icon.h" #include "icon.h"
#include "icons/image.h"
#include "idt.h" #include "idt.h"
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
@ -11,7 +10,9 @@
#include "power.h" #include "power.h"
#include "shell.h" #include "shell.h"
#include "string.h" #include "string.h"
#include "task.h"
#include "terminal.h" #include "terminal.h"
#include "time.h"
#include "vbe.h" #include "vbe.h"
#include <stdbool.h> #include <stdbool.h>
@ -29,20 +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 bozo(int int_code)
{
kprintf("apagnan code\n");
}
void kernel_main(multiboot_info_t *mbd, uint32_t magic) void kernel_main(multiboot_info_t *mbd, uint32_t 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 */ create_kernel_task();
/* "I see no way to confuse an array of 256 seg:off pairs with a kill(0, 4);
* " */ for (size_t i = 0; i < 10000; i++)
/* "complex 8*unknown quantity -byte descriptor table. -- Troy " free_pages(alloc_pages(1, NULL), 1);
*/ signal(4, bozo);
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */ kill(0, 4);
terminal_putchar('A'); shell_init();
/* memset(display.buff, 255, 1024 * 1024); */
/* 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 uint32_t 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);
uint32_t faulting_address; uint32_t faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address)); // __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("fault at address: %p\n", 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

@ -4,12 +4,19 @@
#include <stdint.h> #include <stdint.h>
uint32_t *page_directory = &boot_page_directory; uint32_t *kernel_pd = &boot_page_directory;
uint32_t *current_pd;
uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t page_table_default[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t frame_zones_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
uint32_t mem_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) {
@ -61,8 +68,7 @@ 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;
((uint32_t)frame_zones_page_table - HEAP_END) | 0x03;
frame_zones_page_table[index] = frame_zones_page_table[index] =
((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS; ((uint32_t)start_addr & PAGE_MASK) | INIT_FLAGS;
@ -108,9 +114,10 @@ static void init_frame_zones(void)
void init_memory(multiboot_info_t *mbd, uint32_t magic) void init_memory(multiboot_info_t *mbd, uint32_t magic)
{ {
for (uint16_t 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] = ((uint32_t)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,13 +6,14 @@
#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 int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr, static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
uint32_t **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;
} }
@ -32,7 +33,21 @@ static int16_t find_next_block(size_t nb_pages, uint16_t *pd_index_ptr,
return -1; return -1;
} }
void *alloc_pages(size_t size) int8_t add_single_page(void *frame)
{
uint16_t pd_index;
uint32_t *page_table;
const int16_t i = find_next_block(1, &pd_index, &page_table);
if (i < 0) {
kprintf(KERN_CRIT "impossible to add page to page directory\n");
return -1;
}
page_table[i] = ((uint32_t)frame & PAGE_MASK) | INIT_FLAGS;
return 0;
}
void *alloc_pages(size_t size, void **phys_addr)
{ {
const uint32_t nb_pages = CEIL(size, PAGE_SIZE); const uint32_t nb_pages = CEIL(size, PAGE_SIZE);
uint16_t pd_index; uint16_t pd_index;
@ -51,6 +66,8 @@ void *alloc_pages(size_t size)
free_frame((void *)(page_table[j] & PAGE_MASK)); free_frame((void *)(page_table[j] & PAGE_MASK));
return NULL; return NULL;
} }
if (phys_addr)
*phys_addr = frame;
page_table[i] = ((uint32_t)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);

View File

@ -17,6 +17,6 @@ int16_t add_page_table(uint16_t pd_index)
uint32_t *page_table = uint32_t *page_table =
(uint32_t *)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] = ((uint32_t)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,18 +3,19 @@
#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, uint32_t zone_size) static void new_block(Zone *zone, uint32_t zone_size)
@ -48,7 +49,8 @@ static void new_block(Zone *zone, uint32_t zone_size)
int new_vzone(block_type_t type, uint32_t size) int new_vzone(block_type_t type, uint32_t size)
{ {
void *heap = alloc_pages(size); // assert(current_task->pid);
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");
return (-1); return (-1);

View File

@ -12,7 +12,7 @@ void show_valloc_mem(void)
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] "

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)

View File

@ -52,6 +52,11 @@ static void frag_block(Zone *zone, Block *old_block, uint32_t size)
assert(new_block < assert(new_block <
(Block *)((uint32_t)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;
@ -74,6 +79,7 @@ static void frag_block(Zone *zone, Block *old_block, uint32_t 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;
@ -131,7 +137,7 @@ void *vmalloc(uint32_t 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);
@ -143,7 +149,7 @@ void *vmalloc(uint32_t size)
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

@ -33,13 +33,12 @@ static void init_vbe(multiboot_info_t *mbd_virt)
{ {
const uint32_t framebuffer_size = const uint32_t framebuffer_size =
mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch; mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch;
uint32_t i = 0; for (uint32_t i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) {
for (; 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] = ((uint32_t)vbe_page_table - HEAP_END) | 0x03; kernel_pd[800] = ((uint32_t)vbe_page_table - HEAP_END) | 0x03;
display.buff = (uint32_t *)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;
@ -54,8 +53,7 @@ void init_multiboot(multiboot_info_t *mbd, uint32_t 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;
((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
size_t pt_index = CEIL( size_t pt_index = CEIL(
(uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE); (uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);

26
src/multitasking/fork.c Normal file
View File

@ -0,0 +1,26 @@
#include "interrupts.h"
#include "kprintf.h"
#include "task.h"
uint16_t fork(void)
{
current_task->status = FORKED;
scheduler();
return current_task->child ? current_task->child->pid : 0;
}
void kfork(struct task *daddy)
{
cli();
struct task *child = copy_task(daddy);
if (!child) {
kprintf(KERN_ALERT "Fork failed ! retry at the next loop");
toris();
return;
}
child->daddy = daddy;
daddy->child = child;
daddy->status = RUN;
child->status = RUN;
toris();
}

View File

@ -0,0 +1,35 @@
#include "alloc.h"
#include "debug.h"
#include "interrupts.h"
#include "kprintf.h"
#include "task.h"
#include "time.h"
#include <stddef.h>
struct task *current_task;
void scheduler(void)
{
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
void (*func[])(struct task *) = {
zombify_task, NULL, NULL, NULL, NULL, remove_task, kfork,
};
if (!current_task) // || current_task->next == current_task)
return;
cli();
switch_pd(kernel_pd, (uint32_t *)((uint32_t)kernel_pd - HEAP_END));
struct task *it = current_task->next;
while (it && it->status != RUN) {
if (it != current_task && func[it->status]) {
struct task *new_it = it->prev;
func[it->status](it);
it = new_it;
}
it = it->next;
}
switch_to_task(it);
exec_signal_pending();
toris();
}

View File

@ -0,0 +1,58 @@
.intel_syntax noprefix
.section .text
.global switch_to_task
switch_to_task:
push ebx
push ebp
push edi
push esi
mov eax, [current_task]
// save the current stack pointer to the old stack
mov [eax+0], esp
// stack pointer + the 4 regs pushed
// and + 1 to get the argument (next task)
mov esi, [esp+(4+1)*4]
mov [current_task], esi
mov eax, [current_task]
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 edi
pop ebp
pop ebx
mov ecx, 0
cmp [eax+16], ecx
je .END
sti
push [eax+16] // store func_ptr
mov [eax+16], ecx // clear eip in current_task
push 0
call pic_send_eoi
pop edx // remove pic_send_eoi argument
pop edx // get func_ptr
call edx
call exit_task
.END:
ret

136
src/multitasking/task.c Normal file
View File

@ -0,0 +1,136 @@
#include "task.h"
#include "alloc.h"
#include "debug.h"
#include "interrupts.h"
#include "kpanic.h"
#include "kprintf.h"
#include "memory.h"
#include "string.h"
#include <stdbool.h>
#include <stdint.h>
uint32_t esp_backup;
struct task *create_task(uint8_t uid)
{
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));
if (!new_task) {
switch_pd(current_task->heap, current_task->cr3);
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->prev = current_task;
current_task->next = new_task;
new_task->signals.pending = SIG_IGN;
return new_task;
}
int8_t create_kernel_task(void)
{
struct task *new_task = vmalloc(sizeof(struct task));
if (!new_task)
return -1;
new_task->status = RUN;
new_task->uid = 0;
new_task->pid = 0;
new_task->heap = kernel_pd;
new_task->cr3 = (uint32_t *)((uint32_t)kernel_pd - HEAP_END);
new_task->prev = new_task;
new_task->next = new_task;
new_task->signals.pending = SIG_IGN;
current_task = new_task;
return 0;
}
void exec_fn(void (*fn)(void))
{
struct task *new_task = create_task(OWNER_KERNEL);
if (!new_task)
kpanic("failed to create new task");
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)
{
cli();
struct task *left = task->prev;
struct task *right = task->next;
if (task->child) {
remove_task(task->child);
task->child = NULL;
}
if (task->heap)
free_pages(task->heap, 4096);
if (task->esp0)
free_pages(task->esp0, STACK_SIZE);
left->next = right;
right->prev = left;
vfree(task);
toris();
}
struct task *copy_task(const struct task *task)
{
struct task *new_task = create_task(task->uid);
if (!new_task)
return NULL;
memcpy(new_task->esp0, task->esp0, STACK_SIZE);
new_task->esp = new_task->esp0 + (task->esp - task->esp0);
new_task->status = task->status;
return new_task;
}
void exit_task(void)
{
cli();
if (current_task->daddy && current_task->daddy->status != WAIT)
current_task->status = ZOMBIE;
else {
if (current_task->daddy->status == WAIT)
current_task->daddy->status = RUN;
current_task->status = STOPPED;
}
toris();
scheduler();
}

17
src/multitasking/wait.c Normal file
View File

@ -0,0 +1,17 @@
#include "interrupts.h"
#include "task.h"
uint16_t wait(void)
{
if (current_task->child == NULL)
return -1;
cli();
if (current_task->child->status == ZOMBIE)
current_task->child->status = STOPPED;
else
current_task->status = WAIT;
uint16_t child_pid = current_task->child->pid;
toris();
scheduler();
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

@ -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

@ -2,12 +2,13 @@
#include "alloc.h" #include "alloc.h"
#include "commands.h" #include "commands.h"
#include "ctype.h" #include "font.h"
#include "kprintf.h" #include "kprintf.h"
#include "shell.h" #include "shell.h"
#include "string.h" #include "string.h"
#include "terminal.h" #include "terminal.h"
#include "utils.h" #include "utils.h"
#include "vbe.h"
#define BORDER "===========================================================" #define BORDER "==========================================================="
#define HEADER "Welcome to bozOShell - Available Commands" #define HEADER "Welcome to bozOShell - Available Commands"
@ -29,11 +30,13 @@ 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)
extern struct screen *screen; extern struct screen *screen;
extern struct icon *terminal_bg;
extern int line_status; extern int line_status;
void help_cmd(char *arg) void help_cmd(char *arg)
@ -55,7 +58,7 @@ void help_cmd(char *arg)
kprintf("%s\n", BORDER); kprintf("%s\n", BORDER);
} }
void auto_complete(void) static void auto_complete(void)
{ {
const size_t len = strlen(screen->line); const size_t len = strlen(screen->line);
int nb_matches = 0; int nb_matches = 0;
@ -92,9 +95,7 @@ static char *get_line(void)
if (!i) if (!i)
continue; continue;
buf[--i] = '\0'; buf[--i] = '\0';
move_cursor(LEFT); terminal_remove_last_char();
terminal_putchar(' ');
move_cursor(LEFT);
} else if (ev.scan_code == KEY_TAB && i) { } else if (ev.scan_code == KEY_TAB && i) {
auto_complete(); auto_complete();
} else if (ev.c && i < size - 1) { } else if (ev.c && i < size - 1) {
@ -110,7 +111,7 @@ static char *get_line(void)
return screen->line; return screen->line;
} }
void shell_init() void shell_init(void)
{ {
while (1) { while (1) {
kprintf(PROMPT); kprintf(PROMPT);

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,6 +4,8 @@
#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;

View File

@ -1,6 +1,8 @@
#include "ctype.h" #include "ctype.h"
#include "debug.h"
#include "font.h" #include "font.h"
#include "fonts/eating_pasta_regular_32.h" #include "fonts/consolas_regular_13.h"
// #include "icons/image.h"
#include "kprintf.h" #include "kprintf.h"
#include "shell.h" #include "shell.h"
#include "string.h" #include "string.h"
@ -15,163 +17,197 @@
static struct screen screens[TERM_COUNT]; static struct screen screens[TERM_COUNT];
struct screen *screen = &screens[0]; struct screen *screen = &screens[0];
static inline uint8_t vga_entry_color(vga_color fg, vga_color bg) static struct font get_font_node(int c);
{ static void terminal_scroll(void);
return fg | bg << 4; static void terminal_new_line(void);
}
static inline uint16_t vga_entry(unsigned char uc, uint8_t color)
{
return (uint16_t)uc | (uint16_t)color << 8;
}
void terminal_initialize(void) void terminal_initialize(void)
{ {
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
TERM_BUF[index] = vga_entry(' ', VGA_COLOR_WHITE);
}
}
for (int i = 0; i < TERM_COUNT; i++) { for (int i = 0; i < TERM_COUNT; i++) {
screens[i].row = 0; screens[i].row = 0;
screens[i].column = 0; screens[i].column = 0;
screens[i].default_color = screens[i].default_color = 0xffffff;
vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK); screens[i].fg_color = screens[i].default_color;
screens[i].color = screens[i].default_color; // screens[i].background = &image_icon;
memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer)); screens[i].font = consolas_regular_13_font;
memset(screens[i].line, 0, sizeof(screen->line));
}
}
void terminal_remove_last_char(void)
{
if (screen->column)
screen->column--;
else if (screen->row) {
screen->column = VGA_WIDTH - 1;
screen->row--;
}
uint32_t pos_x = (screen->column) * FONT_WIDTH;
uint32_t pos_y = screen->row * FONT_HEIGHT;
struct font node = get_font_node(
screen->buffer[screen->row * VGA_WIDTH + screen->column]);
screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0';
for (uint32_t y = 0; y < node.height; y++) {
for (uint32_t x = 0; x < node.width; x++) {
// Current bg is taking too much memory
// so we do a black bg for now
// struct icon *bg = screen->background;
// uint32_t pixel = 0;
// if (bg->width > pos_x + x && bg->height > pos_y + y)
// pixel = bg->pixels[(pos_y + y) * bg->width +
// (pos_x + x)];
put_pixel(0, pos_x + x, pos_y + y + node.yoffset);
}
} }
} }
void terminal_set_screen(int pos) void terminal_set_screen(int pos)
{ {
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); // TODO
screen = &screens[pos]; /* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer)); /* screen = &screens[pos]; */
update_cursor(); /* memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer)); */
if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE)) /* update_cursor(); */
kprintf(PROMPT); /* if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE)) */
/* kprintf(PROMPT); */
} }
void terminal_set_bg_color(uint8_t bg_color) void terminal_set_bg_color(uint32_t bg_color)
{ {
screen->color = bg_color << 4 | (screen->color & 0x0F); screen->bg_color = bg_color;
} }
void terminal_set_fg_color(uint8_t fg_color) void terminal_set_fg_color(uint32_t fg_color)
{ {
screen->color = (screen->color & 0xF0) | fg_color; screen->fg_color = screen->fg_color;
} }
void terminal_set_color(uint8_t color) void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
{ {
screen->color = color; screen->fg_color = fg_color;
screen->bg_color = bg_color;
} }
void terminal_set_default_fg_color(uint8_t fg_color) void terminal_set_default_fg_color(uint32_t fg_color)
{ {
screen->default_color = (screen->default_color & 0xF0) | fg_color; screen->default_color = fg_color;
} }
void terminal_set_default_bg_color(uint8_t bg_color) uint32_t terminal_get_default_color(void)
{
screen->default_color = bg_color << 4 | (screen->default_color & 0x0F);
}
uint8_t terminal_get_default_color(void)
{ {
return screen->default_color; return screen->default_color;
} }
uint8_t terminal_get_char(int column, int row) uint8_t terminal_get_char(int x, int y)
{ {
return screen->buffer[row * VGA_WIDTH + column]; return screen->buffer[y * VGA_WIDTH + x];
} }
void terminal_putentryat(char c, uint32_t color, size_t x, size_t y) void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
size_t x, size_t y)
{ {
struct font node = eating_pasta_regular_32_font[(int)c];
char *glyph = node.bitmap; char *glyph = node.bitmap;
for (size_t cy = 0; cy < node.height; cy++) for (size_t cy = 0; cy < node.height; cy++) {
for (size_t cx = 0; cx < node.width; cx++) for (size_t cx = 0; cx < node.width; cx++) {
if (glyph[cy + node.width + cx] == '#') if (glyph[cy * node.width + cx] == '#')
put_pixel(color, x + cx, y + cy); put_pixel(fg_color, x + cx,
/* const size_t index = y * VGA_WIDTH + x; */ y + cy + node.yoffset);
/* TERM_BUF[index] = vga_entry(c, color); */ }
}
}
static struct font get_font_node(int c)
{
return screen->font[c];
} }
static void terminal_scroll(void) static void terminal_scroll(void)
{ {
screen->row--; screen->row--;
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) memset(display.buff, 0, display.height * display.pitch);
TERM_BUF[i] = TERM_BUF[i + VGA_WIDTH]; for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
for (size_t i = 0; i < VGA_WIDTH; i++) const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
terminal_putentryat(' ', VGA_COLOR_WHITE, i, VGA_HEIGHT - 1); const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
terminal_putentryat(get_font_node(screen->buffer[i]),
screen->fg_color, screen->bg_color, x, y);
}
} }
static void terminal_new_line(void) static void terminal_new_line(void)
{ {
screen->column = 0; screen->column = 0;
if (++screen->row == VGA_HEIGHT) if (++screen->row >= VGA_HEIGHT - 1)
terminal_scroll(); terminal_scroll();
} }
static uint8_t get_entry_color(uint16_t vga_entry) void terminal_change_default_color(uint32_t color)
{ {
return vga_entry >> 8; // TODO
/* terminal_set_color(color); */
/* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
/* const size_t index = y * VGA_WIDTH + x;
*/
/* uint8_t entry_color =
* get_entry_color(TERM_BUF[index]);
*/
/* TERM_BUF[index] = vga_entry( */
/* TERM_BUF[index], */
/* entry_color == screen->default_color
* ? color
*/
/* :
* entry_color);
*/
/* } */
/* } */
/* memcpy(screen->buffer, TERM_BUF,
* sizeof(screen->buffer)); */
/* screen->default_color = color; */
/* screen->color = color; */
} }
void terminal_change_default_color(uint8_t color) void terminal_change_default_fg_color(uint32_t fg_color)
{
terminal_set_color(color);
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
uint8_t entry_color = get_entry_color(TERM_BUF[index]);
TERM_BUF[index] = vga_entry(
TERM_BUF[index],
entry_color == screen->default_color ? color
: entry_color);
}
}
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer));
screen->default_color = color;
screen->color = color;
}
void terminal_change_default_fg_color(uint8_t fg_color)
{ {
terminal_set_fg_color(fg_color); terminal_set_fg_color(fg_color);
terminal_change_default_color(screen->color); /* terminal_change_default_color(screen->fg_color); */
} }
void terminal_clear(void) void terminal_clear(void)
{ {
for (size_t y = 0; y < VGA_HEIGHT; y++) { // TODO
for (size_t x = 0; x < VGA_WIDTH; x++) { /* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
const size_t index = y * VGA_WIDTH + x; /* for (size_t x = 0; x < VGA_WIDTH; x++) { */
TERM_BUF[index] = vga_entry(' ', screen->color); /* const size_t index = y * VGA_WIDTH + x;
} */
} /* TERM_BUF[index] = vga_entry(' ',
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); * screen->color);
screen->column = 0; */
screen->row = 0; /* } */
/* } */
/* memcpy(screen->buffer, TERM_BUF,
* sizeof(screen->buffer)); */
/* screen->column = 0; */
/* screen->row = 0; */
} }
int terminal_putchar(char c) int terminal_putchar(char c)
{ {
terminal_putentryat(c, 0xCCFFE5, 10, 10); if (c == '\r')
/* if (c == '\r') */ screen->column = 0;
/* screen->column = 0; */ else if (c == '\n')
/* else if (c == '\n') */ terminal_new_line();
/* terminal_new_line(); */ if (!isprint(c))
/* if (!isprint(c)) */ return 1;
/* return 1; */ screen->buffer[screen->column + screen->row * VGA_WIDTH] = c;
/* terminal_putentryat(c, screen->color, screen->column, screen->row); terminal_putentryat(get_font_node(c), screen->fg_color,
*/ screen->bg_color, screen->column * FONT_WIDTH,
/* if (++screen->column == VGA_WIDTH) */ screen->row * FONT_HEIGHT);
/* terminal_new_line(); */ if (++screen->column >= VGA_WIDTH)
/* return 1; */ terminal_new_line();
return 1;
} }
int terminal_write(const char *data, size_t size) int terminal_write(const char *data, size_t size)
@ -191,12 +227,13 @@ int terminal_writestring(const char *data)
void update_cursor(void) void update_cursor(void)
{ {
uint16_t pos = screen->row * VGA_WIDTH + screen->column; /* uint16_t pos = screen->row * VGA_WIDTH +
* screen->column; */
outb(0x3D4, 0x0F); /* outb(0x3D4, 0x0F); */
outb(0x3D5, pos & 0xFF); /* outb(0x3D5, pos & 0xFF); */
outb(0x3D4, 0x0E); /* outb(0x3D4, 0x0E); */
outb(0x3D5, (pos >> 8) & 0xFF); /* outb(0x3D5, (pos >> 8) & 0xFF); */
} }
void move_cursor(int direction) void move_cursor(int direction)
@ -237,10 +274,11 @@ void set_color_level(int level)
VGA_COLOR_RED, VGA_COLOR_MAGENTA, VGA_COLOR_RED, VGA_COLOR_MAGENTA,
VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW, VGA_COLOR_LIGHT_YELLOW,
VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN, VGA_COLOR_LIGHT_BLUE, VGA_COLOR_GREEN,
VGA_COLOR_LIGHT_GREY}; VGA_COLOR_LIGHT_GREY,
};
if (level == 0) { if (level == 0) {
terminal_set_color(screen->default_color); terminal_set_color(screen->default_color, 0);
return; return;
} }
terminal_set_fg_color(color_translation[level]); terminal_set_fg_color(color_translation[level]);

View File

@ -13,7 +13,8 @@ with open(sys.argv[1]) as f:
font_name: str = os.path.basename(sys.argv[1]).split(".")[0] font_name: str = os.path.basename(sys.argv[1]).split(".")[0]
img_file_relative_path: str = re.findall(r"file=\"(\w+[^\"]+)\"", fnt_data)[0] img_file_relative_path: str = re.findall(r"file=\"(\w+[^\"]+)\"", fnt_data)[0]
img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") + 1] + img_file_relative_path img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") +
1] + img_file_relative_path
image = Image.open(img_file_absolute_path) image = Image.open(img_file_absolute_path)
@ -23,19 +24,24 @@ pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
characteres: list[list[int]] = [None for i in range(128)] characteres: list[list[int]] = [None for i in range(128)]
for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)", fnt_data): for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance) r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)",
fnt_data):
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(
y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance)
bitmap: list[str] = [] bitmap: list[str] = []
for line in pixels[y:y + height]: for line in pixels[y:y + height]:
tmp: str = "" tmp: str = ""
for r,g,b,a in line[x:x + width]: for r, g, b, a in line[x:x + width]:
tmp += "#" if a else " " tmp += "#" if a else " "
bitmap.append(tmp) bitmap.append(tmp)
characteres[id] = [height, width, bitmap] characteres[id] = [height, width, yoffset, bitmap]
string: str = f"""\ string: str = f"""\
#pragma once #pragma once
#include <stddef.h>
#include "font.h" #include "font.h"
struct font {font_name}_font[] = {{\\\ struct font {font_name}_font[] = {{\\\
@ -43,11 +49,12 @@ struct font {font_name}_font[] = {{\\\
for charactere in characteres: for charactere in characteres:
if (charactere is not None): if (charactere is not None):
height, width, bitmap = charactere height, width, yoffset, bitmap = charactere
string += f""" string += f"""
{{ {{
.width = {width}, .width = {width},
.height = {height}, .height = {height},
.yoffset = {yoffset},
.bitmap = "{"".join(bitmap)}", .bitmap = "{"".join(bitmap)}",
}},\ }},\
""" """
@ -56,10 +63,11 @@ for charactere in characteres:
{{ {{
.width = 0, .width = 0,
.height = 0, .height = 0,
.yoffset = 0,
.bitmap = NULL, .bitmap = NULL,
}},\ }},\
""" """
string += "\n}};" string += "\n};"
if not os.path.exists("./headers/fonts"): if not os.path.exists("./headers/fonts"):
os.makedirs("./headers/fonts") os.makedirs("./headers/fonts")

37
tools/icon_maker.py Normal file
View File

@ -0,0 +1,37 @@
from PIL import Image
import sys
import os
if (len(sys.argv) < 2):
print("Error: usage python icon_maker.py {img}")
image = Image.open(sys.argv[1])
width, height = image.size
pixels = list(image.getdata())
pixels = [r << 16 | g << 8 | b for r, g, b in pixels]
string = str(pixels).replace("(", "{").replace(")", "}").replace("[", "{").replace("]", "}")
filename: str = os.path.basename(sys.argv[1]).split(".")[0]
string = f"""\
#pragma once
#include <stdint.h>
#include "icon.h"
uint32_t {filename}_color_map[{width} * {height}] = {string};
struct icon {filename}_icon = {{
.height = {height},
.width = {width},
.pixels = {filename}_color_map
}};
"""
with open(f"./headers/icons/{filename}.h", "w") as f:
f.write(string)