makefile: introduce a format command to run clang-format all over the kernel source.

This commit is contained in:
RaphProductions 2025-05-11 11:45:04 +02:00
parent c4e98f5ef2
commit a379d66784
47 changed files with 5092 additions and 4603 deletions

View file

@ -266,3 +266,8 @@ clean:
distclean: distclean:
$(MAKE) -C kernel distclean $(MAKE) -C kernel distclean
rm -rf iso_root *.iso *.hdd kernel-deps limine ovmf rm -rf iso_root *.iso *.hdd kernel-deps limine ovmf
# Make some function to run clang-format all over the kernel
.PHONY: format
format:
clang-format -i -style=file $(shell find kernel/src -name '*.c' -or -name '*.h')

44
compile_commands.json Executable file → Normal file
View file

@ -33,8 +33,46 @@
"obj-x86_64/main.c.o", "obj-x86_64/main.c.o",
"src/main.c" "src/main.c"
], ],
"directory": "/home/raphm/Projets/sild/kernel", "directory": "/home/raphm/Projets/sild/soaplin/kernel",
"file": "/home/raphm/Projets/sild/kernel/src/main.c", "file": "/home/raphm/Projets/sild/soaplin/kernel/src/main.c",
"output": "/home/raphm/Projets/sild/kernel/obj-x86_64/main.c.o" "output": "/home/raphm/Projets/sild/soaplin/kernel/obj-x86_64/main.c.o"
},
{
"arguments": [
"/usr/bin/cc",
"-g",
"-O2",
"-pipe",
"-Wall",
"-Wextra",
"-std=gnu11",
"-nostdinc",
"-ffreestanding",
"-fno-stack-protector",
"-fno-stack-check",
"-fno-PIC",
"-ffunction-sections",
"-fdata-sections",
"-m64",
"-march=x86-64",
"-mno-80387",
"-mno-mmx",
"-mno-sse",
"-mno-sse2",
"-mno-red-zone",
"-mcmodel=kernel",
"-I",
"src",
"-isystem",
"freestnd-c-hdrs",
"-DLIMINE_API_REVISION=3",
"-c",
"-o",
"obj-x86_64/mm/vmm.c.o",
"src/mm/vmm.c"
],
"directory": "/home/raphm/Projets/sild/soaplin/kernel",
"file": "/home/raphm/Projets/sild/soaplin/kernel/src/mm/vmm.c",
"output": "/home/raphm/Projets/sild/soaplin/kernel/obj-x86_64/mm/vmm.c.o"
} }
] ]

View file

@ -2,18 +2,15 @@
#include "mm/memop.h" #include "mm/memop.h"
#include "mm/pmm.h" #include "mm/pmm.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include <mm/liballoc/liballoc.h>
#include <exec/elf.h> #include <exec/elf.h>
#include <mm/liballoc/liballoc.h>
#include <stdint.h> #include <stdint.h>
#include <sys/log.h> #include <sys/log.h>
program_t *elf_load(char *data) { program_t *elf_load(char *data, int user) {
Elf64_Ehdr *ehdr = (Elf64_Ehdr *)data; Elf64_Ehdr *ehdr = (Elf64_Ehdr *)data;
if ( ehdr->e_ident[EI_MAG0] != ELFMAG0 if (ehdr->e_ident[EI_MAG0] != ELFMAG0 || ehdr->e_ident[EI_MAG1] != ELFMAG1 ||
|| ehdr->e_ident[EI_MAG1] != ELFMAG1 ehdr->e_ident[EI_MAG2] != ELFMAG2 || ehdr->e_ident[EI_MAG3] != ELFMAG3) {
|| ehdr->e_ident[EI_MAG2] != ELFMAG2
|| ehdr->e_ident[EI_MAG3] != ELFMAG3)
{
log("elf - loading failed: magic is incorrect\n"); log("elf - loading failed: magic is incorrect\n");
return NULL; return NULL;
} }
@ -26,96 +23,100 @@ program_t *elf_load(char *data) {
log("elf - e_type: %p\n", ehdr->e_type); log("elf - e_type: %p\n", ehdr->e_type);
log("elf - e_phnum: %p\n", ehdr->e_phnum); log("elf - e_phnum: %p\n", ehdr->e_phnum);
if ( ehdr->e_ident[EI_CLASS] != ELFCLASS64 if (ehdr->e_ident[EI_CLASS] != ELFCLASS64 || ehdr->e_machine != EM_X86_64) {
|| ehdr->e_machine != EM_X86_64)
{
log("elf - loading failed: is the file built for amd64?\n"); log("elf - loading failed: is the file built for amd64?\n");
return NULL; return NULL;
} }
if (ehdr->e_type != ET_EXEC) if (ehdr->e_type != ET_EXEC) {
{
log("elf - loading failed: ELF type isn't ET_EXEC\n"); log("elf - loading failed: ELF type isn't ET_EXEC\n");
return NULL; return NULL;
} }
// There's the interesing part // There's the interesing part
elf_program_t *ret = malloc(sizeof(elf_program_t)); // Allocate memory for the program. elf_program_t *ret =
malloc(sizeof(elf_program_t)); // Allocate memory for the program.
pagemap_t *pm = vmm_alloc_pm(); // Allocate a pagemap, so that we can map the program inside. pagemap_t *pm = vmm_alloc_pm(); // Allocate a pagemap, so that we can map the
// program inside.
ret->program.pm = pm; ret->program.pm = pm;
ret->program.entry = ehdr->e_entry; ret->program.entry = ehdr->e_entry;
ret->ehdr = ehdr; ret->ehdr = ehdr;
Elf64_Phdr *phdr = (Elf64_Phdr *)((uint8_t *)data + ehdr->e_phoff); Elf64_Phdr *phdr = (Elf64_Phdr *)((uint8_t *)data + ehdr->e_phoff);
for (uint16_t i = 0; i <= ehdr->e_phnum; i++) for (uint16_t i = 0; i < ehdr->e_phnum; i++) {
{
log("elf - ELF segment type: %d\n", phdr[i].p_type); log("elf - ELF segment type: %d\n", phdr[i].p_type);
if (phdr[i].p_type != PT_LOAD) if (phdr[i].p_type != PT_LOAD)
continue; continue;
uint64_t vaddr_start = ALIGN_DOWN(phdr[i].p_vaddr, PMM_PAGE_SIZE); uint64_t vaddr_start = ALIGN_DOWN(phdr[i].p_vaddr, PMM_PAGE_SIZE);
uint64_t vaddr_end = ALIGN_UP(phdr[i].p_vaddr + phdr[i].p_memsz, PMM_PAGE_SIZE); uint64_t vaddr_end =
ALIGN_UP(phdr[i].p_vaddr + phdr[i].p_memsz, PMM_PAGE_SIZE);
uint64_t offset = phdr[i].p_offset; uint64_t offset = phdr[i].p_offset;
uint64_t flags = VMM_PRESENT; uint64_t flags = VMM_PRESENT;
//if (phdr[i].p_flags & PF_W) if (phdr[i].p_flags & PF_W)
flags |= VMM_WRITABLE; flags |= VMM_WRITABLE;
//if (!(phdr[i].p_flags & PF_X)) if (!(phdr[i].p_flags & PF_X))
// flags |= VMM_NX; flags |= VMM_NX;
if (user)
flags |= VMM_USER; flags |= VMM_USER;
log("elf - loading ELF program header %u: vaddr 0x%llx - 0x%llx, offset 0x%llx, filesz 0x%llx, size 0x%llx, flags 0x%llx\n", log("elf - loading ELF program header %u: vaddr 0x%llx - 0x%llx, offset "
i, vaddr_start, vaddr_end, offset, phdr[i].p_filesz, phdr[i].p_memsz, flags); "0x%llx, filesz 0x%llx, size 0x%llx, flags 0x%llx\n",
i, vaddr_start, vaddr_end, offset, phdr[i].p_filesz, phdr[i].p_memsz,
flags);
uint64_t page_offset = phdr[i].p_vaddr & (PMM_PAGE_SIZE - 1); uint64_t page_offset = phdr[i].p_vaddr & (PMM_PAGE_SIZE - 1);
for (uint64_t vaddr = vaddr_start; vaddr < vaddr_end; vaddr += PMM_PAGE_SIZE) for (uint64_t vaddr = vaddr_start; vaddr < vaddr_end;
{ vaddr += PMM_PAGE_SIZE) {
uint64_t phys = (uint64_t)pmm_request_page(); uint64_t phys = (uint64_t)pmm_request_page();
if (!phys) if (!phys) {
{
log("elf - pmm page alloc failed. out of memory?\n"); log("elf - pmm page alloc failed. out of memory?\n");
return 0; return 0;
} }
if (user) {
log("elf - vmm_map_user(%p, %p, %p, %d)\n", pm, vaddr, phys, flags);
vmm_map_user(pm, vaddr, phys, flags);
} else {
log("elf - vmm_map(%p, %p, %p, %d)\n", pm, vaddr, phys, flags); log("elf - vmm_map(%p, %p, %p, %d)\n", pm, vaddr, phys, flags);
vmm_map(pm, vaddr, phys, flags); vmm_map(pm, vaddr, phys, flags);
}
log("elf - memset(%p, 0, 0x1000)\n", HIGHER_HALF(phys)); log("elf - memset(%p, 0, 0x1000)\n", HIGHER_HALF(phys));
memset((void *)HIGHER_HALF(phys), 0, PMM_PAGE_SIZE); memset((void *)HIGHER_HALF(phys), 0, PMM_PAGE_SIZE);
uint64_t file_page_offset = offset + (vaddr - vaddr_start); uint64_t file_page_offset = offset + (vaddr - vaddr_start);
uint64_t file_data_end = offset + phdr[i].p_filesz; uint64_t file_data_end = offset + phdr[i].p_filesz;
if (file_page_offset < file_data_end) if (file_page_offset < file_data_end) {
{
uint64_t bytes_from_start = vaddr - vaddr_start; uint64_t bytes_from_start = vaddr - vaddr_start;
uint64_t page_data_offset = 0; uint64_t page_data_offset = 0;
if (bytes_from_start == 0 && page_offset > 0) if (bytes_from_start == 0 && page_offset > 0) {
{
page_data_offset = page_offset; page_data_offset = page_offset;
} }
uint64_t copy_offset = file_page_offset; uint64_t copy_offset = file_page_offset;
uint64_t copy_size = PMM_PAGE_SIZE - page_data_offset; uint64_t copy_size = PMM_PAGE_SIZE - page_data_offset;
if (copy_offset + copy_size > file_data_end) if (copy_offset + copy_size > file_data_end) {
{
copy_size = file_data_end - copy_offset; copy_size = file_data_end - copy_offset;
} }
if (copy_size > 0) if (copy_size > 0) {
{
void *dest = (void *)(HIGHER_HALF(phys) + page_data_offset); void *dest = (void *)(HIGHER_HALF(phys) + page_data_offset);
void *src = (uint8_t *)data + copy_offset; void *src = (uint8_t *)data + copy_offset;
log("elf - memcpy(%p, %p, %d)\n", dest, src, copy_size); log("elf - memcpy(%p, %p, %d)\n", dest, src, copy_size);
memcpy(dest, src, copy_size); memcpy(dest, src, copy_size);
//log("elf - copied 0x%llx bytes from ELF file offset 0x%llx to vaddr 0x%llx (phys 0x%llx)\n", // log("elf - copied 0x%llx bytes from ELF file offset 0x%llx to vaddr
// copy_size, copy_offset, vaddr + page_data_offset, phys + page_data_offset); // 0x%llx (phys 0x%llx)\n",
// copy_size, copy_offset, vaddr + page_data_offset, phys +
// page_data_offset);
} }
} }
} }

View file

@ -122,4 +122,4 @@ typedef struct {
Elf64_Ehdr *ehdr; Elf64_Ehdr *ehdr;
} elf_program_t; } elf_program_t;
program_t *elf_load(char *data); program_t *elf_load(char *data, int user);

View file

@ -14,12 +14,15 @@ typedef struct {
// The pagemap where the program's code is loaded. // The pagemap where the program's code is loaded.
pagemap_t *pm; pagemap_t *pm;
// The path to the first instruction. This will be passed to the new process's rip register. // The path to the first instruction. This will be passed to the new process's
// rip register.
uint64_t entry; uint64_t entry;
// The program type. Used to get additional, unneeded information out of a program // The program type. Used to get additional, unneeded information out of a
// program
int type; int type;
// That is what Soaplin needs to know. Executable file loaders are encouraged to extend this structure // That is what Soaplin needs to know. Executable file loaders are encouraged
// to include info such as the EHDR for the ELF loader... // to extend this structure to include info such as the EHDR for the ELF
// loader...
} program_t; } program_t;

View file

@ -1,258 +1,343 @@
unsigned char VGA8[] = { unsigned char VGA8[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x81, 0xa5, 0x81, 0x81, 0xbd,
0x00, 0x00, 0x7e, 0xff, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x99, 0x81, 0x81, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xff,
0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0xdb, 0xff, 0xff, 0xc3, 0xe7, 0xff, 0xff, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38, 0x10,
0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x7c, 0xfe,
0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x3c, 0xe7, 0xe7, 0xe7, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0xff, 0xff, 0x7e, 0x18, 0x18, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c,
0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x1e, 0x0e, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xe7, 0xc3, 0xc3, 0xe7, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x42, 0x42, 0x66, 0x3c, 0x00,
0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc3, 0x99, 0xbd,
0x00, 0x00, 0x7f, 0x63, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00, 0x00, 0xbd, 0x99, 0xc3, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x1e, 0x0e,
0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x1a, 0x32, 0x78, 0xcc, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x18,
0x00, 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x33, 0x3f, 0x30, 0x30, 0x30,
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x70, 0xf0, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x63, 0x63, 0x63, 0x63, 0x67, 0xe7, 0xe6, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7f, 0xdb, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0xdb, 0x3c, 0xe7, 0x3c, 0xdb, 0x18, 0x18,
0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfe, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0e,
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x3e, 0xfe, 0x3e, 0x1e, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00,
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xdb,
0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdb, 0xdb, 0x7b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x6c, 0xc6, 0xc6, 0x6c, 0x38, 0x0c, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c,
0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x7e, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x7e, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x0c, 0xfe, 0x0c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xfe, 0x60, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0,
0x00, 0x00, 0x38, 0x6c, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x6c, 0xfe, 0x6c, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0x00,
0x00, 0x00, 0x30, 0x18, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe, 0x7c, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x24, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c,
0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xfe, 0x6c, 0x6c, 0x6c, 0xfe, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xd6, 0xd6, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7c, 0xc6, 0xc2, 0xc0, 0x7c, 0x06, 0x06, 0x86, 0xc6, 0x7c,
0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xc6, 0x0c, 0x18,
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0xc6, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c,
0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x38, 0x76, 0xdc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30,
0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x18, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18,
0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x3c, 0xff, 0x3c, 0x66, 0x00, 0x00,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xde, 0xde, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xd6, 0xd6, 0xc6, 0xc6, 0x6c, 0x38,
0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x38, 0x78, 0x18, 0x18, 0x18,
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf8, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x06, 0x06, 0x3c, 0x06, 0x06, 0x06, 0xc6, 0x7c,
0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x1c, 0x3c, 0x6c, 0xcc, 0xfe,
0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0,
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xfc, 0x06, 0x06, 0x06, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x60, 0xc0, 0xc0, 0xfc, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c,
0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x06, 0x06, 0x0c, 0x18,
0x00, 0x00, 0x1e, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x06, 0x06, 0x0c, 0x78,
0x00, 0x00, 0xc6, 0xee, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x30, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x06,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c, 0x0c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60,
0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x7e, 0x7e, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0x0c, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18,
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xde, 0xde,
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00, 0xde, 0xdc, 0xc0, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38,
0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0xee, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x7c, 0x38, 0x38, 0x7c, 0x6c, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x66, 0x66, 0x66, 0x66, 0xfc,
0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0,
0x00, 0x00, 0xfe, 0xc6, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc2, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc2, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x6c,
0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x6c, 0xf8, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68, 0x60, 0x62, 0x66, 0xfe,
0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x66, 0x62, 0x68, 0x78, 0x68,
0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xc2, 0xc0, 0xc0, 0xde, 0xc6, 0xc6, 0x66, 0x3a, 0x00, 0x00, 0x00, 0x00,
0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0xe0, 0x60, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x0c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0c, 0x0c, 0x0c, 0xcc, 0xcc, 0xcc, 0x78, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe6, 0x66, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0x66, 0xe6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x60, 0x60, 0x60, 0x60, 0x60,
0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x60, 0x62, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xee,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78, 0x00, 0xfe, 0xfe, 0xd6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xe0, 0x60, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0xc6,
0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66,
0x00, 0x00, 0xe0, 0x60, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x7c, 0x60, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xde, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6, 0xd6, 0xd6, 0xd6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x66, 0x66, 0x66, 0x7c, 0x6c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x60, 0x38, 0x0c, 0x06, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x7e, 0x7e, 0x5a, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x6c, 0x38, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x30, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0xee, 0x6c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0x6c, 0x7c, 0x38, 0x38,
0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x7c, 0x6c, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0x86, 0x0c, 0x18, 0x30, 0x60, 0xc2, 0xc6, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x30, 0x30, 0x30, 0x30, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xe0, 0x70, 0x38, 0x1c, 0x0e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x3c,
0x00, 0x00, 0x70, 0x18, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x3c, 0x66, 0xc2, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x0c, 0x06, 0x7c, 0x00, 0x00, 0x30, 0x30, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c,
0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x60,
0x00, 0x10, 0x38, 0x6c, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x60, 0x78, 0x6c, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xcc, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc0, 0xc0, 0xc0, 0xc6, 0x7c,
0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x0c, 0x0c, 0x3c, 0x6c, 0xcc,
0x00, 0x38, 0x6c, 0x38, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x60, 0x60, 0x66, 0x3c, 0x0c, 0x06, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xf0,
0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc,
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0xcc, 0x78, 0x00, 0x00, 0x00, 0xe0, 0x60,
0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x60, 0x6c, 0x76, 0x66, 0x66, 0x66, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x3c, 0x66, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c,
0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x00, 0x0e, 0x06, 0x06,
0x00, 0xc6, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0xe0, 0x60,
0x38, 0x6c, 0x38, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x60, 0x66, 0x6c, 0x78, 0x78, 0x6c, 0x66, 0xe6, 0x00, 0x00, 0x00, 0x00,
0x18, 0x30, 0x60, 0x00, 0xfe, 0x66, 0x60, 0x7c, 0x60, 0x60, 0x66, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x76, 0x36, 0x7e, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xec, 0xfe, 0xd6,
0x00, 0x00, 0x3e, 0x6c, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00, 0x00, 0xd6, 0xd6, 0xd6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c,
0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x66, 0x66,
0x00, 0x30, 0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x60, 0x30, 0x18, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x7c, 0x0c, 0x0c, 0x1e, 0x00,
0x00, 0x00, 0xc6, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x76, 0x66, 0x60, 0x60, 0x60, 0xf0,
0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c, 0xc6, 0x60,
0x00, 0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x38, 0x0c, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x30,
0x00, 0x18, 0x18, 0x3c, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x30, 0xfc, 0x30, 0x30, 0x30, 0x30, 0x36, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xe6, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76,
0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66,
0x00, 0xf8, 0xcc, 0xcc, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0x70, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xd6, 0xd6, 0xd6, 0xfe, 0x6c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x6c, 0x38, 0x38, 0x38, 0x6c, 0xc6,
0x00, 0x0c, 0x18, 0x30, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6,
0x00, 0x18, 0x30, 0x60, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x18, 0x30, 0x60, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xcc, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x76, 0xdc, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x18, 0x18, 0x18, 0x70, 0x18, 0x18, 0x18, 0x18, 0x0e,
0x76, 0xdc, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18,
0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x18,
0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x0e, 0x18, 0x18, 0x18, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xc0, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0xc6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66,
0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x60, 0xdc, 0x86, 0x0c, 0x18, 0x3e, 0x00, 0x00, 0xc2, 0xc0, 0xc0, 0xc0, 0xc2, 0x66, 0x3c, 0x0c, 0x06, 0x7c, 0x00, 0x00,
0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76,
0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x00, 0x7c, 0xc6, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36, 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00,
0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76,
0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x78, 0x0c, 0x7c,
0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x78, 0x0c, 0x7c, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x66, 0x60, 0x60, 0x66, 0x3c, 0x0c, 0x06,
0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xfe,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x60, 0x30, 0x18, 0x00, 0x7c, 0xc6, 0xfe, 0xc0, 0xc0, 0xc6, 0x7c,
0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x38, 0x18, 0x18,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3c, 0x66,
0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x10, 0x38, 0x6c, 0xc6, 0xc6,
0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x38, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0xfe, 0x66, 0x60, 0x7c, 0x60, 0x60, 0x66, 0xfe,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0x76, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e, 0xd8, 0xd8, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x6c,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xcc, 0xcc, 0xfe, 0xcc, 0xcc, 0xcc, 0xcc, 0xce, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x38, 0x6c, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x7c, 0xc6, 0xc6,
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0xcc, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x76,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x30, 0x18, 0x00, 0xcc, 0xcc, 0xcc,
0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7e, 0x06, 0x0c, 0x78, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0xc6, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x00, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6,
0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xc6, 0xc6, 0xc6, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x3c,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x60, 0x60, 0x60, 0x66, 0x3c, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x64, 0x60, 0xf0, 0x60, 0x60, 0x60, 0x60, 0xe6, 0xfc,
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xcc, 0xcc,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xc4, 0xcc, 0xde, 0xcc, 0xcc, 0xcc, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x18, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0x78, 0x0c, 0x7c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x18, 0x30,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x00, 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x00, 0x00, 0x00, 0x00,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x18, 0x30, 0x60, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x7c,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x30, 0x60, 0x00, 0xcc, 0xcc, 0xcc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xcc, 0xcc, 0xcc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xdc, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x76, 0xdc, 0x00, 0xc6, 0xe6, 0xf6, 0xfe, 0xde, 0xce, 0xc6, 0xc6, 0xc6,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x6c, 0x6c, 0x3e, 0x00, 0x7e, 0x00,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0xd8, 0xd8, 0xd8, 0xdc, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x30, 0x30, 0x60, 0xc0, 0xc6, 0xc6, 0x7c,
0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc0,
0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfe, 0xc6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc6, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30, 0x60, 0xdc, 0x86, 0x0c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x18, 0x3e, 0x00, 0x00, 0x00, 0xc0, 0xc0, 0xc2, 0xc6, 0xcc, 0x18, 0x30,
0x00, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x66, 0xce, 0x9e, 0x3e, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x3c, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66, 0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x6c, 0xd8, 0x6c, 0x36, 0x00, 0x00,
0x00, 0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x6c, 0x36,
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0xee, 0x00, 0x00, 0x00, 0x00, 0x6c, 0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x44, 0x11, 0x44,
0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66, 0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44,
0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa,
0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x55, 0xaa, 0x55, 0xaa, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77,
0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7c, 0x60, 0x60, 0x60, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0xdd, 0x77, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x7c, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18, 0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8,
0x00, 0x00, 0x00, 0x30, 0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x18, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00, 0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0xf6, 0x06, 0xf6, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x38, 0x6c, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x06, 0xf6,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x00, 0x0f, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x6c, 0x3c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x36, 0xf6, 0x06, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xd8, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xfe, 0x00, 0x00, 0x00, 0x00,
0x00, 0x70, 0xd8, 0x30, 0x60, 0xc8, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8, 0x18, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0xf8, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
}; 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x37,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x37, 0x30, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xf7, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x37, 0x30, 0x37, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36,
0x36, 0xf7, 0x00, 0xf7, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0xff,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xff, 0x00, 0xff, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x3f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x18, 0x18,
0x18, 0x1f, 0x18, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x18, 0x1f, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x36, 0x36, 0x36, 0xff, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36, 0x36,
0x18, 0x18, 0x18, 0x18, 0x18, 0xff, 0x18, 0xff, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0,
0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0,
0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
0x0f, 0x0f, 0x0f, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x76, 0xdc, 0xd8, 0xd8, 0xd8, 0xdc, 0x76, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x78, 0xcc, 0xcc, 0xcc, 0xd8, 0xcc, 0xc6, 0xc6, 0xc6, 0xcc,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xc6, 0xc6, 0xc0, 0xc0, 0xc0,
0xc0, 0xc0, 0xc0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xfe, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfe, 0xc6, 0x60, 0x30, 0x18, 0x30, 0x60, 0xc6, 0xfe,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0xd8, 0xd8,
0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x66, 0x66, 0x66, 0x66, 0x66, 0x7c, 0x60, 0x60, 0xc0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x18, 0x3c, 0x66, 0x66,
0x66, 0x3c, 0x18, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38,
0x6c, 0xc6, 0xc6, 0xfe, 0xc6, 0xc6, 0x6c, 0x38, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x38, 0x6c, 0xc6, 0xc6, 0xc6, 0x6c, 0x6c, 0x6c, 0x6c, 0xee,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x30, 0x18, 0x0c, 0x3e, 0x66,
0x66, 0x66, 0x66, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7e, 0xdb, 0xdb, 0xdb, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x06, 0x7e, 0xdb, 0xdb, 0xf3, 0x7e, 0x60, 0xc0,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x30, 0x60, 0x60, 0x7c, 0x60,
0x60, 0x60, 0x30, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c,
0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0xc6, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x7e, 0x18,
0x18, 0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
0x18, 0x0c, 0x06, 0x0c, 0x18, 0x30, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0c, 0x00, 0x7e,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x1b, 0x1b, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0xd8, 0xd8, 0xd8, 0x70, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x7e, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0xdc, 0x00,
0x76, 0xdc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x6c, 0x6c,
0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x0c, 0x0c,
0x0c, 0x0c, 0x0c, 0xec, 0x6c, 0x6c, 0x3c, 0x1c, 0x00, 0x00, 0x00, 0x00,
0x00, 0xd8, 0x6c, 0x6c, 0x6c, 0x6c, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0xd8, 0x30, 0x60, 0xc8, 0xf8, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};

View file

@ -21,8 +21,8 @@ typedef struct __vnode {
} vnode; } vnode;
typedef struct __vfs_mount { typedef struct __vfs_mount {
struct vfs_node *mount_point; // The directory in the main VFS where this is mounted struct vfs_node
*mount_point; // The directory in the main VFS where this is mounted
struct vfs_node *mounted_root; // The root node of the mounted filesystem struct vfs_node *mounted_root; // The root node of the mounted filesystem
struct vfs_mount *next; // Pointer to next mount point struct vfs_mount *next; // Pointer to next mount point
} vfs_mount; } vfs_mount;

View file

@ -2,8 +2,7 @@
#include <stdint.h> #include <stdint.h>
typedef struct spinlock typedef struct spinlock {
{
volatile int locked; volatile int locked;
} spinlock_t; } spinlock_t;

83
kernel/src/main.c Executable file → Normal file
View file

@ -1,49 +1,49 @@
#include "exec/elf.h" #include "exec/elf.h"
#include "exec/exec.h" #include "exec/exec.h"
#include "mm/liballoc/liballoc.h"
#include "mm/pmm.h" #include "mm/pmm.h"
#include "mm/vma.h" #include "mm/vma.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include "mm/liballoc/liballoc.h"
#include "sched/sched.h" #include "sched/sched.h"
#include "sys/acpi.h"
#include "sys/arch/x86_64/pit.h" #include "sys/arch/x86_64/pit.h"
#include "sys/arch/x86_64/sse.h" #include "sys/arch/x86_64/sse.h"
#include "sys/syscall.h" #include "sys/syscall.h"
#include <sys/log.h> #include <font.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <limine.h> #include <limine.h>
#include <sys/printf.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/arch/x86_64/fpu.h>
#include <sys/arch/x86_64/gdt.h> #include <sys/arch/x86_64/gdt.h>
#include <sys/arch/x86_64/idt.h> #include <sys/arch/x86_64/idt.h>
#include <sys/arch/x86_64/fpu.h>
#include <sys/gfx/flanterm/flanterm.h>
#include <sys/gfx/flanterm/backends/fb.h> #include <sys/gfx/flanterm/backends/fb.h>
#include <font.h> #include <sys/gfx/flanterm/flanterm.h>
#include <sys/log.h>
#include <sys/printf.h>
// Set the base revision to 3, this is recommended as this is the latest // Set the base revision to 3, this is recommended as this is the latest
// base revision described by the Limine boot protocol specification. // base revision described by the Limine boot protocol specification.
// See specification for further info. // See specification for further info.
__attribute__((used, section(".limine_requests"))) __attribute__((
static volatile LIMINE_BASE_REVISION(3); used, section(".limine_requests"))) static volatile LIMINE_BASE_REVISION(3);
// The Limine requests can be placed anywhere, but it is important that // The Limine requests can be placed anywhere, but it is important that
// the compiler does not optimise them away, so, usually, they should // the compiler does not optimise them away, so, usually, they should
// be made volatile or equivalent, _and_ they should be accessed at least // be made volatile or equivalent, _and_ they should be accessed at least
// once or marked as used with the "used" attribute as done here. // once or marked as used with the "used" attribute as done here.
__attribute__((used, section(".limine_requests"))) __attribute__((
static volatile struct limine_framebuffer_request framebuffer_request = { used,
.id = LIMINE_FRAMEBUFFER_REQUEST, section(
.revision = 0 ".limine_requests"))) static volatile struct limine_framebuffer_request
}; framebuffer_request = {.id = LIMINE_FRAMEBUFFER_REQUEST, .revision = 0};
__attribute__((used, section(".limine_requests"))) __attribute__((
static volatile struct limine_module_request module_request = { used,
.id = LIMINE_MODULE_REQUEST, section(".limine_requests"))) static volatile struct limine_module_request
.revision = 0 module_request = {.id = LIMINE_MODULE_REQUEST, .revision = 0};
};
/*__attribute__((used, section(".limine_requests"))) /*__attribute__((used, section(".limine_requests")))
static volatile struct limine_entry_point_request entrypoint_request = { static volatile struct limine_entry_point_request entrypoint_request = {
@ -53,12 +53,14 @@ static volatile struct limine_entry_point_request entrypoint_request = {
// Finally, define the start and end markers for the Limine requests. // Finally, define the start and end markers for the Limine requests.
// These can also be moved anywhere, to any .c file, as seen fit. // These can also be moved anywhere, to any .c file, as seen fit.
__attribute__((used, section(".limine_requests_start"))) __attribute__((used,
static volatile LIMINE_REQUESTS_START_MARKER; section(".limine_requests_"
"start"))) static volatile LIMINE_REQUESTS_START_MARKER;
__attribute__((used, section(".limine_requests_end")))
static volatile LIMINE_REQUESTS_END_MARKER;
__attribute__((
used,
section(
".limine_requests_end"))) static volatile LIMINE_REQUESTS_END_MARKER;
// Halt and catch fire function. // Halt and catch fire function.
static void hcf(void) { static void hcf(void) {
@ -92,24 +94,17 @@ void kmain(void) {
if (framebuffer_request.response != NULL) { if (framebuffer_request.response != NULL) {
// Fetch the first framebuffer. // Fetch the first framebuffer.
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0]; struct limine_framebuffer *framebuffer =
framebuffer_request.response->framebuffers[0];
fb = framebuffer; fb = framebuffer;
ft_ctx = flanterm_fb_init( ft_ctx = flanterm_fb_init(
NULL, NULL, NULL, framebuffer->address, framebuffer->width,
NULL, framebuffer->height, framebuffer->pitch, framebuffer->red_mask_size,
framebuffer->address, framebuffer->width, framebuffer->height, framebuffer->pitch, framebuffer->red_mask_shift, framebuffer->green_mask_size,
framebuffer->red_mask_size, framebuffer->red_mask_shift, framebuffer->green_mask_shift, framebuffer->blue_mask_size,
framebuffer->green_mask_size, framebuffer->green_mask_shift, framebuffer->blue_mask_shift, NULL, NULL, NULL, NULL, &fg, NULL, NULL,
framebuffer->blue_mask_size, framebuffer->blue_mask_shift, VGA8, 8, 16, 0, 0, 0, 0);
NULL,
NULL, NULL,
NULL, &fg,
NULL, NULL,
VGA8, 8, 16, 0,
0, 0,
0
);
} }
printf("\n Soaplin 1.0-sild is booting up your computer...\n\n"); printf("\n Soaplin 1.0-sild is booting up your computer...\n\n");
@ -130,6 +125,7 @@ void kmain(void) {
asm("hlt"); asm("hlt");
} }
// acpi_init();
syscall_init(); syscall_init();
pit_init(1000); pit_init(1000);
sched_init(); sched_init();
@ -138,11 +134,12 @@ void kmain(void) {
struct limine_file *f = module_request.response->modules[0]; struct limine_file *f = module_request.response->modules[0];
log("kmain - %s\n", f->path); log("kmain - %s\n", f->path);
program_t *prog = elf_load((char*)f->address); program_t *prog = elf_load((char *)f->address, 1);
sched_create("Init", prog->entry, prog->pm, SCHED_USER_PROCESS); sched_create("Init", prog->entry, prog->pm, SCHED_USER_PROCESS);
log("kernel - Soaplin initialized sucessfully.\n"); log("kernel - Soaplin initialized sucessfully.\n");
while (1) while (1)
;;//__asm__ volatile ("hlt"); ;
; //__asm__ volatile ("hlt");
} }

View file

@ -17,26 +17,21 @@
#define USE_CASE5 #define USE_CASE5
#define ALIGN(ptr) \ #define ALIGN(ptr) \
if (ALIGNMENT > 1) \ if (ALIGNMENT > 1) { \
{ \
uintptr_t diff; \ uintptr_t diff; \
ptr = (void *)((uintptr_t)ptr + ALIGN_INFO); \ ptr = (void *)((uintptr_t)ptr + ALIGN_INFO); \
diff = (uintptr_t)ptr & (ALIGNMENT - 1); \ diff = (uintptr_t)ptr & (ALIGNMENT - 1); \
if (diff != 0) \ if (diff != 0) { \
{ \
diff = ALIGNMENT - diff; \ diff = ALIGNMENT - diff; \
ptr = (void *)((uintptr_t)ptr + diff); \ ptr = (void *)((uintptr_t)ptr + diff); \
} \ } \
*((ALIGN_TYPE *)((uintptr_t)ptr - ALIGN_INFO)) = \ *((ALIGN_TYPE *)((uintptr_t)ptr - ALIGN_INFO)) = diff + ALIGN_INFO; \
diff + ALIGN_INFO; \
} }
#define UNALIGN(ptr) \ #define UNALIGN(ptr) \
if (ALIGNMENT > 1) \ if (ALIGNMENT > 1) { \
{ \
uintptr_t diff = *((ALIGN_TYPE *)((uintptr_t)ptr - ALIGN_INFO)); \ uintptr_t diff = *((ALIGN_TYPE *)((uintptr_t)ptr - ALIGN_INFO)); \
if (diff < (ALIGNMENT + ALIGN_INFO)) \ if (diff < (ALIGNMENT + ALIGN_INFO)) { \
{ \
ptr = (void *)((uintptr_t)ptr - diff); \ ptr = (void *)((uintptr_t)ptr - diff); \
} \ } \
} }
@ -44,8 +39,7 @@
#define LIBALLOC_MAGIC 0xc001c0de #define LIBALLOC_MAGIC 0xc001c0de
#define LIBALLOC_DEAD 0xdeaddead #define LIBALLOC_DEAD 0xdeaddead
struct liballoc_major struct liballoc_major {
{
struct liballoc_major *prev; struct liballoc_major *prev;
struct liballoc_major *next; struct liballoc_major *next;
unsigned int pages; unsigned int pages;
@ -54,8 +48,7 @@ struct liballoc_major
struct liballoc_minor *first; struct liballoc_minor *first;
}; };
struct liballoc_minor struct liballoc_minor {
{
struct liballoc_minor *prev; struct liballoc_minor *prev;
struct liballoc_minor *next; struct liballoc_minor *next;
struct liballoc_major *block; struct liballoc_major *block;
@ -76,23 +69,20 @@ static long long l_warningCount = 0;
static long long l_errorCount = 0; static long long l_errorCount = 0;
static long long l_possibleOverruns = 0; static long long l_possibleOverruns = 0;
static void *liballoc_memset(void *s, int c, size_t n) static void *liballoc_memset(void *s, int c, size_t n) {
{
unsigned int i; unsigned int i;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
((char *)s)[i] = c; ((char *)s)[i] = c;
return s; return s;
} }
static void *liballoc_memcpy(void *s1, const void *s2, size_t n) static void *liballoc_memcpy(void *s1, const void *s2, size_t n) {
{
char *cdest; char *cdest;
char *csrc; char *csrc;
unsigned int *ldest = (unsigned int *)s1; unsigned int *ldest = (unsigned int *)s1;
unsigned int *lsrc = (unsigned int *)s2; unsigned int *lsrc = (unsigned int *)s2;
while (n >= sizeof(unsigned int)) while (n >= sizeof(unsigned int)) {
{
*ldest++ = *lsrc++; *ldest++ = *lsrc++;
n -= sizeof(unsigned int); n -= sizeof(unsigned int);
} }
@ -100,8 +90,7 @@ static void *liballoc_memcpy(void *s1, const void *s2, size_t n)
cdest = (char *)ldest; cdest = (char *)ldest;
csrc = (char *)lsrc; csrc = (char *)lsrc;
while (n > 0) while (n > 0) {
{
*cdest++ = *csrc++; *cdest++ = *csrc++;
n -= 1; n -= 1;
} }
@ -110,8 +99,7 @@ static void *liballoc_memcpy(void *s1, const void *s2, size_t n)
} }
#if _DEBUG #if _DEBUG
void liballoc_dump() void liballoc_dump() {
{
#ifdef _DEBUG #ifdef _DEBUG
struct liballoc_major *maj = l_memRoot; struct liballoc_major *maj = l_memRoot;
struct liballoc_minor *min = NULL; struct liballoc_minor *min = NULL;
@ -125,19 +113,12 @@ void liballoc_dump()
info("Possible overruns: %i", l_possibleOverruns); info("Possible overruns: %i", l_possibleOverruns);
#ifdef _DEBUG #ifdef _DEBUG
while (maj != NULL) while (maj != NULL) {
{ info("%x: total = %i, used = %i", maj, maj->size, maj->usage);
info("%x: total = %i, used = %i",
maj,
maj->size,
maj->usage);
min = maj->first; min = maj->first;
while (min != NULL) while (min != NULL) {
{ info(" %x: %i bytes", min, min->size);
info(" %x: %i bytes",
min,
min->size);
min = min->next; min = min->next;
} }
@ -146,14 +127,10 @@ void liballoc_dump()
#endif #endif
} }
#else #else
void liballoc_dump() void liballoc_dump() { return; }
{
return;
}
#endif #endif
static struct liballoc_major *allocate_new_page(unsigned int size) static struct liballoc_major *allocate_new_page(unsigned int size) {
{
unsigned int st; unsigned int st;
struct liballoc_major *maj; struct liballoc_major *maj;
@ -170,8 +147,7 @@ static struct liballoc_major *allocate_new_page(unsigned int size)
maj = (struct liballoc_major *)liballoc_alloc(st); maj = (struct liballoc_major *)liballoc_alloc(st);
if (maj == NULL) if (maj == NULL) {
{
l_warningCount += 1; l_warningCount += 1;
log("liballoc - (warning) liballoc_alloc( %i ) return NULL", st); log("liballoc - (warning) liballoc_alloc( %i ) return NULL", st);
return NULL; return NULL;
@ -186,14 +162,14 @@ static struct liballoc_major *allocate_new_page(unsigned int size)
l_allocated += maj->size; l_allocated += maj->size;
log("liballoc - Resource allocated %x of %i pages (%i bytes) for %i size.", maj, st, maj->size, size); log("liballoc - Resource allocated %x of %i pages (%i bytes) for %i size.",
maj, st, maj->size, size);
log("liballoc - Total memory usage = %i KB", (int)((l_allocated / (1024)))); log("liballoc - Total memory usage = %i KB", (int)((l_allocated / (1024))));
return maj; return maj;
} }
void *PREFIX(malloc)(size_t req_size) void *PREFIX(malloc)(size_t req_size) {
{
int startedBet = 0; int startedBet = 0;
unsigned long long bestSize = 0; unsigned long long bestSize = 0;
void *p = NULL; void *p = NULL;
@ -203,15 +179,13 @@ void *PREFIX(malloc)(size_t req_size)
struct liballoc_minor *new_min; struct liballoc_minor *new_min;
unsigned long size = req_size; unsigned long size = req_size;
if (ALIGNMENT > 1) if (ALIGNMENT > 1) {
{
size += ALIGNMENT + ALIGN_INFO; size += ALIGNMENT + ALIGN_INFO;
} }
liballoc_lock(); liballoc_lock();
if (size == 0) if (size == 0) {
{
l_warningCount += 1; l_warningCount += 1;
log("liballoc - (warning) alloc( 0 ) called from %x", log("liballoc - (warning) alloc( 0 ) called from %x",
__builtin_return_address(0)); __builtin_return_address(0));
@ -220,12 +194,10 @@ void *PREFIX(malloc)(size_t req_size)
return PREFIX(malloc)(1); return PREFIX(malloc)(1);
} }
if (l_memRoot == NULL) if (l_memRoot == NULL) {
{
log("liballoc - initialization of liballoc " VERSION ""); log("liballoc - initialization of liballoc " VERSION "");
l_memRoot = allocate_new_page(size); l_memRoot = allocate_new_page(size);
if (l_memRoot == NULL) if (l_memRoot == NULL) {
{
liballoc_unlock(); liballoc_unlock();
log("liballoc - initial l_memRoot initialization failed", p); log("liballoc - initial l_memRoot initialization failed", p);
return NULL; return NULL;
@ -234,30 +206,25 @@ void *PREFIX(malloc)(size_t req_size)
log("liballoc - set up first memory major %x", l_memRoot); log("liballoc - set up first memory major %x", l_memRoot);
} }
log("liballoc - %x PREFIX(malloc)( %i ): ", log("liballoc - %x PREFIX(malloc)( %i ): ", __builtin_return_address(0),
__builtin_return_address(0),
size); size);
maj = l_memRoot; maj = l_memRoot;
startedBet = 0; startedBet = 0;
if (l_bestBet != NULL) if (l_bestBet != NULL) {
{
bestSize = l_bestBet->size - l_bestBet->usage; bestSize = l_bestBet->size - l_bestBet->usage;
if (bestSize > (size + sizeof(struct liballoc_minor))) if (bestSize > (size + sizeof(struct liballoc_minor))) {
{
maj = l_bestBet; maj = l_bestBet;
startedBet = 1; startedBet = 1;
} }
} }
while (maj != NULL) while (maj != NULL) {
{
diff = maj->size - maj->usage; diff = maj->size - maj->usage;
if (bestSize < diff) if (bestSize < diff) {
{
l_bestBet = maj; l_bestBet = maj;
bestSize = diff; bestSize = diff;
@ -265,18 +232,15 @@ void *PREFIX(malloc)(size_t req_size)
#ifdef USE_CASE1 #ifdef USE_CASE1
if (diff < (size + sizeof(struct liballoc_minor))) if (diff < (size + sizeof(struct liballoc_minor))) {
{
log("liballoc - (warning) CASE 1: Insufficient space in block %x", maj); log("liballoc - (warning) CASE 1: Insufficient space in block %x", maj);
if (maj->next != NULL) if (maj->next != NULL) {
{
maj = maj->next; maj = maj->next;
continue; continue;
} }
if (startedBet == 1) if (startedBet == 1) {
{
maj = l_memRoot; maj = l_memRoot;
startedBet = 0; startedBet = 0;
continue; continue;
@ -293,9 +257,9 @@ void *PREFIX(malloc)(size_t req_size)
#ifdef USE_CASE2 #ifdef USE_CASE2
if (maj->first == NULL) if (maj->first == NULL) {
{ maj->first = (struct liballoc_minor *)((uintptr_t)maj +
maj->first = (struct liballoc_minor *)((uintptr_t)maj + sizeof(struct liballoc_major)); sizeof(struct liballoc_major));
maj->first->magic = LIBALLOC_MAGIC; maj->first->magic = LIBALLOC_MAGIC;
maj->first->prev = NULL; maj->first->prev = NULL;
@ -324,10 +288,11 @@ void *PREFIX(malloc)(size_t req_size)
diff -= (uintptr_t)maj; diff -= (uintptr_t)maj;
diff -= sizeof(struct liballoc_major); diff -= sizeof(struct liballoc_major);
if (diff >= (size + sizeof(struct liballoc_minor))) if (diff >= (size + sizeof(struct liballoc_minor))) {
{
maj->first->prev = (struct liballoc_minor *)((uintptr_t)maj + sizeof(struct liballoc_major)); maj->first->prev =
(struct liballoc_minor *)((uintptr_t)maj +
sizeof(struct liballoc_major));
maj->first->prev->next = maj->first; maj->first->prev->next = maj->first;
maj->first = maj->first->prev; maj->first = maj->first->prev;
@ -354,21 +319,20 @@ void *PREFIX(malloc)(size_t req_size)
min = maj->first; min = maj->first;
while (min != NULL) while (min != NULL) {
{
if (min->next == NULL) if (min->next == NULL) {
{
diff = (uintptr_t)(maj) + maj->size; diff = (uintptr_t)(maj) + maj->size;
diff -= (uintptr_t)min; diff -= (uintptr_t)min;
diff -= sizeof(struct liballoc_minor); diff -= sizeof(struct liballoc_minor);
diff -= min->size; diff -= min->size;
if (diff >= (size + sizeof(struct liballoc_minor))) if (diff >= (size + sizeof(struct liballoc_minor))) {
{
min->next = (struct liballoc_minor *)((uintptr_t)min + sizeof(struct liballoc_minor) + min->size); min->next = (struct liballoc_minor *)((uintptr_t)min +
sizeof(struct liballoc_minor) +
min->size);
min->next->prev = min; min->next->prev = min;
min = min->next; min = min->next;
min->next = NULL; min->next = NULL;
@ -389,18 +353,18 @@ void *PREFIX(malloc)(size_t req_size)
} }
} }
if (min->next != NULL) if (min->next != NULL) {
{
diff = (uintptr_t)(min->next); diff = (uintptr_t)(min->next);
diff -= (uintptr_t)min; diff -= (uintptr_t)min;
diff -= sizeof(struct liballoc_minor); diff -= sizeof(struct liballoc_minor);
diff -= min->size; diff -= min->size;
if (diff >= (size + sizeof(struct liballoc_minor))) if (diff >= (size + sizeof(struct liballoc_minor))) {
{
new_min = (struct liballoc_minor *)((uintptr_t)min + sizeof(struct liballoc_minor) + min->size); new_min = (struct liballoc_minor *)((uintptr_t)min +
sizeof(struct liballoc_minor) +
min->size);
new_min->magic = LIBALLOC_MAGIC; new_min->magic = LIBALLOC_MAGIC;
new_min->next = min->next; new_min->next = min->next;
@ -430,12 +394,10 @@ void *PREFIX(malloc)(size_t req_size)
#ifdef USE_CASE5 #ifdef USE_CASE5
if (maj->next == NULL) if (maj->next == NULL) {
{
log("liballoc - (warning) CASE 5: block full"); log("liballoc - (warning) CASE 5: block full");
if (startedBet == 1) if (startedBet == 1) {
{
maj = l_memRoot; maj = l_memRoot;
startedBet = 0; startedBet = 0;
continue; continue;
@ -461,13 +423,11 @@ void *PREFIX(malloc)(size_t req_size)
return NULL; return NULL;
} }
void PREFIX(free)(void *ptr) void PREFIX(free)(void *ptr) {
{
struct liballoc_minor *min; struct liballoc_minor *min;
struct liballoc_major *maj; struct liballoc_major *maj;
if (ptr == NULL) if (ptr == NULL) {
{
l_warningCount += 1; l_warningCount += 1;
log("liballoc - (warning) PREFIX(free)( NULL ) called from %x", log("liballoc - (warning) PREFIX(free)( NULL ) called from %x",
__builtin_return_address(0)); __builtin_return_address(0));
@ -479,33 +439,25 @@ void PREFIX(free)(void *ptr)
liballoc_lock(); liballoc_lock();
min = (struct liballoc_minor *)((uintptr_t)ptr - sizeof(struct liballoc_minor)); min =
(struct liballoc_minor *)((uintptr_t)ptr - sizeof(struct liballoc_minor));
if (min->magic != LIBALLOC_MAGIC) if (min->magic != LIBALLOC_MAGIC) {
{
l_errorCount += 1; l_errorCount += 1;
if ( if (((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) || ((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) ||
((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))) ((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))) {
{
l_possibleOverruns += 1; l_possibleOverruns += 1;
log("liballoc - (warning) Possible 1-3 byte overrun for magic %x != %x", log("liballoc - (warning) Possible 1-3 byte overrun for magic %x != %x",
min->magic, min->magic, LIBALLOC_MAGIC);
LIBALLOC_MAGIC);
} }
if (min->magic == LIBALLOC_DEAD) if (min->magic == LIBALLOC_DEAD) {
{ log("liballoc - multiple PREFIX(free)() attempt on %x from %x.", ptr,
log("liballoc - multiple PREFIX(free)() attempt on %x from %x.",
ptr,
__builtin_return_address(0)); __builtin_return_address(0));
} } else {
else log("liballoc - Bad PREFIX(free)( %x ) called from %x", ptr,
{
log("liballoc - Bad PREFIX(free)( %x ) called from %x",
ptr,
__builtin_return_address(0)); __builtin_return_address(0));
} }
@ -513,9 +465,7 @@ void PREFIX(free)(void *ptr)
return; return;
} }
log("liballoc - %x PREFIX(free)( %x ): ", log("liballoc - %x PREFIX(free)( %x ): ", __builtin_return_address(0), ptr);
__builtin_return_address(0),
ptr);
maj = min->block; maj = min->block;
@ -532,8 +482,7 @@ void PREFIX(free)(void *ptr)
if (min->prev == NULL) if (min->prev == NULL)
maj->first = min->next; maj->first = min->next;
if (maj->first == NULL) if (maj->first == NULL) {
{
if (l_memRoot == maj) if (l_memRoot == maj)
l_memRoot = maj->next; l_memRoot = maj->next;
if (l_bestBet == maj) if (l_bestBet == maj)
@ -545,11 +494,8 @@ void PREFIX(free)(void *ptr)
l_allocated -= maj->size; l_allocated -= maj->size;
liballoc_free(maj, maj->pages); liballoc_free(maj, maj->pages);
} } else {
else if (l_bestBet != NULL) {
{
if (l_bestBet != NULL)
{
int bestSize = l_bestBet->size - l_bestBet->usage; int bestSize = l_bestBet->size - l_bestBet->usage;
int majSize = maj->size - maj->usage; int majSize = maj->size - maj->usage;
@ -563,8 +509,7 @@ void PREFIX(free)(void *ptr)
liballoc_unlock(); liballoc_unlock();
} }
void *PREFIX(calloc)(size_t nobj, size_t size) void *PREFIX(calloc)(size_t nobj, size_t size) {
{
int real_size; int real_size;
void *p; void *p;
@ -577,14 +522,12 @@ void *PREFIX(calloc)(size_t nobj, size_t size)
return p; return p;
} }
void *PREFIX(realloc)(void *p, size_t size) void *PREFIX(realloc)(void *p, size_t size) {
{
void *ptr; void *ptr;
struct liballoc_minor *min; struct liballoc_minor *min;
unsigned int real_size; unsigned int real_size;
if (size == 0) if (size == 0) {
{
PREFIX(free) PREFIX(free)
(p); (p);
return NULL; return NULL;
@ -598,33 +541,25 @@ void *PREFIX(realloc)(void *p, size_t size)
liballoc_lock(); liballoc_lock();
min = (struct liballoc_minor *)((uintptr_t)ptr - sizeof(struct liballoc_minor)); min =
(struct liballoc_minor *)((uintptr_t)ptr - sizeof(struct liballoc_minor));
if (min->magic != LIBALLOC_MAGIC) if (min->magic != LIBALLOC_MAGIC) {
{
l_errorCount += 1; l_errorCount += 1;
if ( if (((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
((min->magic & 0xFFFFFF) == (LIBALLOC_MAGIC & 0xFFFFFF)) ||
((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) || ((min->magic & 0xFFFF) == (LIBALLOC_MAGIC & 0xFFFF)) ||
((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))) ((min->magic & 0xFF) == (LIBALLOC_MAGIC & 0xFF))) {
{
l_possibleOverruns += 1; l_possibleOverruns += 1;
log("liballoc - Possible 1-3 byte overrun for magic %x != %x", log("liballoc - Possible 1-3 byte overrun for magic %x != %x", min->magic,
min->magic,
LIBALLOC_MAGIC); LIBALLOC_MAGIC);
} }
if (min->magic == LIBALLOC_DEAD) if (min->magic == LIBALLOC_DEAD) {
{
log("liballoc - liballoc: multiple PREFIX(free)() attempt on %x from %x.", log("liballoc - liballoc: multiple PREFIX(free)() attempt on %x from %x.",
ptr, ptr, __builtin_return_address(0));
__builtin_return_address(0)); } else {
} log("liballoc - liballoc: Bad PREFIX(free)( %x ) called from %x", ptr,
else
{
log("liballoc - liballoc: Bad PREFIX(free)( %x ) called from %x",
ptr,
__builtin_return_address(0)); __builtin_return_address(0));
} }
@ -634,8 +569,7 @@ void *PREFIX(realloc)(void *p, size_t size)
real_size = min->req_size; real_size = min->req_size;
if (real_size >= size) if (real_size >= size) {
{
min->req_size = size; min->req_size = size;
liballoc_unlock(); liballoc_unlock();
return p; return p;

View file

@ -1,39 +1,33 @@
#include "mm/liballoc/liballoc.h" #include "mm/liballoc/liballoc.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include <mm/vma.h>
#include <lib/spinlock.h> #include <lib/spinlock.h>
#include <mm/vma.h>
#include <stddef.h> #include <stddef.h>
extern vma_context_t *kernel_vma_context; extern vma_context_t *kernel_vma_context;
static spinlock_t liballoc_lock_var = {0}; static spinlock_t liballoc_lock_var = {0};
int liballoc_lock() int liballoc_lock() {
{
spinlock_acquire(&liballoc_lock_var); spinlock_acquire(&liballoc_lock_var);
return 0; return 0;
} }
int liballoc_unlock() int liballoc_unlock() {
{
spinlock_release(&liballoc_lock_var); spinlock_release(&liballoc_lock_var);
return 0; return 0;
} }
void *liballoc_alloc(size_t pages) void *liballoc_alloc(size_t pages) {
{
return vma_alloc(kernel_vma_context, pages, VMM_PRESENT | VMM_WRITABLE); return vma_alloc(kernel_vma_context, pages, VMM_PRESENT | VMM_WRITABLE);
} }
int liballoc_free(void *ptr, size_t pages) int liballoc_free(void *ptr, size_t pages) {
{
(void)pages; (void)pages;
vma_free(kernel_vma_context, ptr); vma_free(kernel_vma_context, ptr);
return 0; return 0;
} }
// void *malloc(size_t s) { return PREFIX(malloc)(s); } // void *malloc(size_t s) { return PREFIX(malloc)(s); }
// void *realloc(void *v, size_t s) { return PREFIX(realloc)(v, s); } // void *realloc(void *v, size_t s) { return PREFIX(realloc)(v, s); }
// void *calloc(size_t s1, size_t s) { return PREFIX(calloc)(s1, s); } // void *calloc(size_t s1, size_t s) { return PREFIX(calloc)(s1, s); }

1
kernel/src/mm/memop.c Executable file → Normal file
View file

@ -10,7 +10,6 @@ void *memcpy(void *dest, const void *src, size_t n) {
uint8_t *pdest = (uint8_t *)dest; uint8_t *pdest = (uint8_t *)dest;
const uint8_t *psrc = (const uint8_t *)src; const uint8_t *psrc = (const uint8_t *)src;
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
pdest[i] = psrc[i]; pdest[i] = psrc[i];
} }

59
kernel/src/mm/pmm.c Executable file → Normal file
View file

@ -1,7 +1,7 @@
#include "limine.h" #include "limine.h"
#include <stddef.h>
#include <mm/memop.h> #include <mm/memop.h>
#include <mm/pmm.h> #include <mm/pmm.h>
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <sys/log.h> #include <sys/log.h>
@ -10,21 +10,15 @@ struct limine_memmap_response *_memmap;
uint64_t hhdm_offset = 0x0; uint64_t hhdm_offset = 0x0;
__attribute__((used, section(".limine_requests"))) __attribute__((
struct limine_memmap_request mm_req = { used, section(".limine_requests"))) struct limine_memmap_request mm_req = {
.id = LIMINE_MEMMAP_REQUEST, .id = LIMINE_MEMMAP_REQUEST, .revision = 3};
.revision = 3
};
__attribute__((
used, section(".limine_requests"))) struct limine_hhdm_request hhdm_req = {
.id = LIMINE_HHDM_REQUEST, .revision = 3};
__attribute__((used, section(".limine_requests"))) int pmm_init() {
struct limine_hhdm_request hhdm_req = {
.id = LIMINE_HHDM_REQUEST,
.revision = 3
};
int pmm_init()
{
uint64_t free_pages = 0; uint64_t free_pages = 0;
hhdm_offset = hhdm_req.response->offset; hhdm_offset = hhdm_req.response->offset;
@ -33,11 +27,10 @@ int pmm_init()
// DEBUG("mm", "----- PMM //INFO -----"); // DEBUG("mm", "----- PMM //INFO -----");
int freemem = 0; int freemem = 0;
for (uint64_t i = 0; i < memmap->entry_count; i++) for (uint64_t i = 0; i < memmap->entry_count; i++) {
{ if (memmap->entries[i]->type == LIMINE_MEMMAP_USABLE) {
if (memmap->entries[i]->type == LIMINE_MEMMAP_USABLE) // DEBUG("mm", " - USABLE ENTRY\t\t@ 0x%.16llx, size: 0x%.16llx",
{ // memmap->entries[i]->base, memmap->entries[i]->length);
//DEBUG("mm", " - USABLE ENTRY\t\t@ 0x%.16llx, size: 0x%.16llx", memmap->entries[i]->base, memmap->entries[i]->length);
free_pages += DIV_ROUND_UP(memmap->entries[i]->length, PMM_PAGE_SIZE); free_pages += DIV_ROUND_UP(memmap->entries[i]->length, PMM_PAGE_SIZE);
freemem += memmap->entries[i]->length; freemem += memmap->entries[i]->length;
} }
@ -45,11 +38,9 @@ int pmm_init()
uint64_t array_size = ALIGN_UP(free_pages * 8, PMM_PAGE_SIZE); uint64_t array_size = ALIGN_UP(free_pages * 8, PMM_PAGE_SIZE);
for (uint64_t i = 0; i < memmap->entry_count; i++) for (uint64_t i = 0; i < memmap->entry_count; i++) {
{
struct limine_memmap_entry *entry = memmap->entries[i]; struct limine_memmap_entry *entry = memmap->entries[i];
if (entry->length >= array_size && entry->type == LIMINE_MEMMAP_USABLE) if (entry->length >= array_size && entry->type == LIMINE_MEMMAP_USABLE) {
{
stack.pages = (uintptr_t *)HIGHER_HALF(entry->base); stack.pages = (uintptr_t *)HIGHER_HALF(entry->base);
entry->length -= array_size; entry->length -= array_size;
entry->base += array_size; entry->base += array_size;
@ -58,13 +49,10 @@ int pmm_init()
} }
} }
for (uint64_t i = 0; i < memmap->entry_count; i++) for (uint64_t i = 0; i < memmap->entry_count; i++) {
{
struct limine_memmap_entry *entry = memmap->entries[i]; struct limine_memmap_entry *entry = memmap->entries[i];
if (entry->type == LIMINE_MEMMAP_USABLE) if (entry->type == LIMINE_MEMMAP_USABLE) {
{ for (uint64_t j = 0; j < entry->length; j += PMM_PAGE_SIZE) {
for (uint64_t j = 0; j < entry->length; j += PMM_PAGE_SIZE)
{
stack.pages[stack.idx++] = entry->base + j; stack.pages[stack.idx++] = entry->base + j;
} }
} }
@ -75,15 +63,12 @@ int pmm_init()
// DEBUG("mm", " - CURRENT INDEX:\t%d", stack.idx); // DEBUG("mm", " - CURRENT INDEX:\t%d", stack.idx);
// DEBUG("mm", "--------------------"); // DEBUG("mm", "--------------------");
log("pmm - %dmb is available to us.\n", freemem / (1024 * 1024)); log("pmm - %dmb is available to us.\n", freemem / (1024 * 1024));
return 0; return 0;
} }
void *pmm_request_page() void *pmm_request_page() {
{ if (stack.idx == 0) {
if (stack.idx == 0)
{
// ERROR("mm", "No more pages available."); // ERROR("mm", "No more pages available.");
log("pmm - out of memory.\n"); log("pmm - out of memory.\n");
asm("cli"); asm("cli");
@ -98,13 +83,11 @@ void *pmm_request_page()
return (void *)page_addr; return (void *)page_addr;
} }
void pmm_free_page(void *ptr) void pmm_free_page(void *ptr) {
{
if (ptr == NULL) if (ptr == NULL)
return; return;
if (stack.idx >= stack.max) if (stack.idx >= stack.max) {
{
// ERROR("mm", "Stack overflow attempt while freeing a page."); // ERROR("mm", "Stack overflow attempt while freeing a page.");
log("pmm - could not free the page: stack overflow.\n"); log("pmm - could not free the page: stack overflow.\n");
return; return;

6
kernel/src/mm/pmm.h Executable file → Normal file
View file

@ -4,8 +4,7 @@
#include <stdint.h> #include <stdint.h>
#define PMM_PAGE_SIZE 4096 #define PMM_PAGE_SIZE 4096
typedef struct pmm_stack typedef struct pmm_stack {
{
uintptr_t *pages; uintptr_t *pages;
uint64_t idx; uint64_t idx;
uint64_t max; uint64_t max;
@ -13,7 +12,8 @@ typedef struct pmm_stack
extern uint64_t hhdm_offset; extern uint64_t hhdm_offset;
#define DIV_ROUND_UP(x, y) (((uint64_t)(x) + ((uint64_t)(y) - 1)) / (uint64_t)(y)) #define DIV_ROUND_UP(x, y) \
(((uint64_t)(x) + ((uint64_t)(y) - 1)) / (uint64_t)(y))
#define ALIGN_UP(x, y) (DIV_ROUND_UP(x, y) * (uint64_t)(y)) #define ALIGN_UP(x, y) (DIV_ROUND_UP(x, y) * (uint64_t)(y))
#define ALIGN_DOWN(x, y) (((uint64_t)(x) / (uint64_t)(y)) * (uint64_t)(y)) #define ALIGN_DOWN(x, y) (((uint64_t)(x) / (uint64_t)(y)) * (uint64_t)(y))

View file

@ -3,19 +3,18 @@
#include "mm/pmm.h" #include "mm/pmm.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include <mm/vma.h>
#include <mm/memop.h> #include <mm/memop.h>
#include <mm/vma.h>
#include <sys/log.h> #include <sys/log.h>
vma_context_t *kernel_vma_context; vma_context_t *kernel_vma_context;
vma_context_t *vma_create_context(pagemap_t *pagemap) vma_context_t *vma_create_context(pagemap_t *pagemap) {
{ log("vma - creating VMA context with pagemap: 0x%.16llx\n",
log("vma - creating VMA context with pagemap: 0x%.16llx\n", (uint64_t)pagemap); (uint64_t)pagemap);
vma_context_t *ctx = (vma_context_t *)HIGHER_HALF(pmm_request_page()); vma_context_t *ctx = (vma_context_t *)HIGHER_HALF(pmm_request_page());
if (ctx == NULL) if (ctx == NULL) {
{
log("vma - failed to allocate VMA context\n"); log("vma - failed to allocate VMA context\n");
return NULL; return NULL;
} }
@ -24,8 +23,7 @@ vma_context_t *vma_create_context(pagemap_t *pagemap)
log("vma - zeroed out VMA context at 0x%.16llx\n", (uint64_t)ctx); log("vma - zeroed out VMA context at 0x%.16llx\n", (uint64_t)ctx);
ctx->root = (vma_region_t *)HIGHER_HALF(pmm_request_page()); ctx->root = (vma_region_t *)HIGHER_HALF(pmm_request_page());
if (ctx->root == NULL) if (ctx->root == NULL) {
{
log("vma - failed to allocate root region\n"); log("vma - failed to allocate root region\n");
pmm_free_page((void *)PHYSICAL(ctx)); pmm_free_page((void *)PHYSICAL(ctx));
return NULL; return NULL;
@ -36,23 +34,21 @@ vma_context_t *vma_create_context(pagemap_t *pagemap)
ctx->root->start = PMM_PAGE_SIZE; ctx->root->start = PMM_PAGE_SIZE;
ctx->root->size = 0; ctx->root->size = 0;
log("vma - VMA context created at 0x%.16llx with root region at 0x%.16llx\n", (uint64_t)ctx, (uint64_t)ctx->root); log("vma - VMA context created at 0x%.16llx with root region at 0x%.16llx\n",
(uint64_t)ctx, (uint64_t)ctx->root);
return ctx; return ctx;
} }
void vma_destroy_context(vma_context_t *ctx) void vma_destroy_context(vma_context_t *ctx) {
{
log("vma - destroying VMA context at 0x%.16llx\n", (uint64_t)ctx); log("vma - destroying VMA context at 0x%.16llx\n", (uint64_t)ctx);
if (ctx->root == NULL || ctx->pagemap == NULL) if (ctx->root == NULL || ctx->pagemap == NULL) {
{
log("vma - invalid context or root passed to vma_destroy_context\n"); log("vma - invalid context or root passed to vma_destroy_context\n");
return; return;
} }
vma_region_t *region = ctx->root; vma_region_t *region = ctx->root;
while (region != NULL) while (region != NULL) {
{
log("vma - freeing region at 0x%.16llx\n", (uint64_t)region); log("vma - freeing region at 0x%.16llx\n", (uint64_t)region);
vma_region_t *next = region->next; vma_region_t *next = region->next;
pmm_free_page((void *)PHYSICAL(region)); pmm_free_page((void *)PHYSICAL(region));
@ -63,10 +59,8 @@ void vma_destroy_context(vma_context_t *ctx)
log("vma - destroyed VMA context at 0x%.16llx\n", (uint64_t)ctx); log("vma - destroyed VMA context at 0x%.16llx\n", (uint64_t)ctx);
} }
void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags) void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags) {
{ if (ctx == NULL || ctx->root == NULL || ctx->pagemap == NULL) {
if (ctx == NULL || ctx->root == NULL || ctx->pagemap == NULL)
{
log("vma - invalid context or root passed to vma_alloc\n"); log("vma - invalid context or root passed to vma_alloc\n");
return NULL; return NULL;
} }
@ -75,13 +69,11 @@ void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags)
vma_region_t *new_region; vma_region_t *new_region;
vma_region_t *last_region = ctx->root; vma_region_t *last_region = ctx->root;
while (region != NULL) while (region != NULL) {
{ if (region->next == NULL ||
if (region->next == NULL || region->start + region->size < region->next->start) region->start + region->size < region->next->start) {
{
new_region = (vma_region_t *)HIGHER_HALF(pmm_request_page()); new_region = (vma_region_t *)HIGHER_HALF(pmm_request_page());
if (new_region == NULL) if (new_region == NULL) {
{
log("vma - failed to allocate new VMA region\n"); log("vma - failed to allocate new VMA region\n");
return NULL; return NULL;
} }
@ -94,16 +86,15 @@ void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags)
new_region->prev = region; new_region->prev = region;
region->next = new_region; region->next = new_region;
for (uint64_t i = 0; i < size; i++) for (uint64_t i = 0; i < size; i++) {
{
uint64_t page = (uint64_t)pmm_request_page(); uint64_t page = (uint64_t)pmm_request_page();
if (page == 0) if (page == 0) {
{
log("vma - failed to allocate physical memory for VMA region\n"); log("vma - failed to allocate physical memory for VMA region\n");
return NULL; return NULL;
} }
vmm_map(ctx->pagemap, new_region->start + i * PMM_PAGE_SIZE, page, new_region->flags); vmm_map(ctx->pagemap, new_region->start + i * PMM_PAGE_SIZE, page,
new_region->flags);
} }
return (void *)new_region->start; return (void *)new_region->start;
@ -112,8 +103,7 @@ void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags)
} }
new_region = (vma_region_t *)HIGHER_HALF(pmm_request_page()); new_region = (vma_region_t *)HIGHER_HALF(pmm_request_page());
if (new_region == NULL) if (new_region == NULL) {
{
log("vma - failed to allocate new VMA region\n"); log("vma - failed to allocate new VMA region\n");
return NULL; return NULL;
} }
@ -127,73 +117,63 @@ void *vma_alloc(vma_context_t *ctx, uint64_t size, uint64_t flags)
new_region->flags = flags; new_region->flags = flags;
new_region->next = NULL; new_region->next = NULL;
for (uint64_t i = 0; i < size; i++) for (uint64_t i = 0; i < size; i++) {
{
uint64_t page = (uint64_t)pmm_request_page(); uint64_t page = (uint64_t)pmm_request_page();
if (page == 0) if (page == 0) {
{
log("vma - failed to allocate physical memory for VMA region\n"); log("vma - failed to allocate physical memory for VMA region\n");
return NULL; return NULL;
} }
vmm_map(ctx->pagemap, new_region->start + i * PMM_PAGE_SIZE, page, new_region->flags); vmm_map(ctx->pagemap, new_region->start + i * PMM_PAGE_SIZE, page,
new_region->flags);
} }
return (void *)new_region->start; return (void *)new_region->start;
} }
void vma_free(vma_context_t *ctx, void *ptr) void vma_free(vma_context_t *ctx, void *ptr) {
{ if (ctx == NULL) {
if (ctx == NULL)
{
log("vma - invalid context passed to vma_free\n"); log("vma - invalid context passed to vma_free\n");
return; return;
} }
vma_region_t *region = ctx->root; vma_region_t *region = ctx->root;
while (region != NULL) while (region != NULL) {
{ if (region->start == (uint64_t)ptr) {
if (region->start == (uint64_t)ptr)
{
log("vma - found region to free at 0x%.16llx\n", (uint64_t)region); log("vma - found region to free at 0x%.16llx\n", (uint64_t)region);
break; break;
} }
region = region->next; region = region->next;
} }
if (region == NULL) if (region == NULL) {
{ log("vma - unable to find region to free at address 0x%.16llx\n",
log("vma - unable to find region to free at address 0x%.16llx\n", (uint64_t)ptr); (uint64_t)ptr);
return; return;
} }
vma_region_t *prev = region->prev; vma_region_t *prev = region->prev;
vma_region_t *next = region->next; vma_region_t *next = region->next;
for (uint64_t i = 0; i < region->size; i++) for (uint64_t i = 0; i < region->size; i++) {
{
uint64_t virt = region->start + i * PMM_PAGE_SIZE; uint64_t virt = region->start + i * PMM_PAGE_SIZE;
uint64_t phys = virt_to_phys(vmm_kernel_pm, virt); uint64_t phys = virt_to_phys(vmm_kernel_pm, virt);
if (phys != 0) if (phys != 0) {
{
pmm_free_page((void *)phys); pmm_free_page((void *)phys);
vmm_unmap(ctx->pagemap, virt); vmm_unmap(ctx->pagemap, virt);
} }
} }
if (prev != NULL) if (prev != NULL) {
{
prev->next = next; prev->next = next;
} }
if (next != NULL) if (next != NULL) {
{
next->prev = prev; next->prev = prev;
} }
if (region == ctx->root) if (region == ctx->root) {
{
ctx->root = next; ctx->root = next;
} }

View file

@ -3,12 +3,11 @@
#pragma once #pragma once
#include <mm/vmm.h>
#include <mm/pmm.h> #include <mm/pmm.h>
#include <mm/vmm.h>
#include <stdint.h> #include <stdint.h>
typedef struct vma_region typedef struct vma_region {
{
uint64_t start; uint64_t start;
uint64_t size; uint64_t size;
uint64_t flags; uint64_t flags;
@ -16,8 +15,7 @@ typedef struct vma_region
struct vma_region *prev; struct vma_region *prev;
} vma_region_t; } vma_region_t;
typedef struct vma_context typedef struct vma_context {
{
pagemap_t *pagemap; pagemap_t *pagemap;
vma_region_t *root; vma_region_t *root;
} vma_context_t; } vma_context_t;

80
kernel/src/mm/vmm.c Executable file → Normal file
View file

@ -4,6 +4,7 @@
#include "mm/pmm.h" #include "mm/pmm.h"
#include "sys/log.h" #include "sys/log.h"
#include "vmm.h" #include "vmm.h"
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
__attribute__(( __attribute__((
@ -150,15 +151,16 @@ void vmm_load_pagemap(pagemap_t *pm) {
} }
static uint64_t *__vmm_get_next_lvl(uint64_t *level, uint64_t entry, static uint64_t *__vmm_get_next_lvl(uint64_t *level, uint64_t entry,
uint64_t flags) { uint64_t flags, bool alloc) {
if (!(level[entry] & 1)) { if (level[entry] & VMM_PRESENT)
uint64_t *pml = HIGHER_HALF(pmm_request_page());
memset(pml, 0, PMM_PAGE_SIZE);
level[entry] = (uint64_t)PHYSICAL(pml);
}
level[entry] |= (flags & 0xFFF);
return HIGHER_HALF(PTE_GET_ADDR(level[entry])); return HIGHER_HALF(PTE_GET_ADDR(level[entry]));
if (alloc) {
uint64_t *pml = (uint64_t *)HIGHER_HALF(pmm_request_page());
memset(pml, 0, PMM_PAGE_SIZE);
level[entry] = (uint64_t)PHYSICAL(pml) | flags;
return pml;
}
return NULL;
} }
uint64_t vmm_get_flags(pagemap_t *pm, uint64_t vaddr) { uint64_t vmm_get_flags(pagemap_t *pm, uint64_t vaddr) {
@ -167,9 +169,15 @@ uint64_t vmm_get_flags(pagemap_t *pm, uint64_t vaddr) {
uint64_t pml2_entry = (vaddr >> 21) & 0x1ff; uint64_t pml2_entry = (vaddr >> 21) & 0x1ff;
uint64_t pml1_entry = (vaddr >> 12) & 0x1ff; uint64_t pml1_entry = (vaddr >> 12) & 0x1ff;
uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry, 0); uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry, 0, false);
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, 0); if (!pml3)
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, 0); return 0;
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, 0, false);
if (!pml2)
return 0;
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, 0, false);
if (!pml1)
return 0;
return pml1[pml1_entry] & 0x7000000000000FFF; return pml1[pml1_entry] & 0x7000000000000FFF;
} }
@ -180,14 +188,17 @@ uint64_t virt_to_phys(pagemap_t *pagemap, uint64_t virt) {
uint64_t pml2_idx = (virt >> 21) & 0x1FF; uint64_t pml2_idx = (virt >> 21) & 0x1FF;
uint64_t pml1_idx = (virt >> 12) & 0x1FF; uint64_t pml1_idx = (virt >> 12) & 0x1FF;
uint64_t *pml3 = __vmm_get_next_lvl(pagemap->toplevel, pml4_idx, 0); uint64_t *pml3 = __vmm_get_next_lvl(pagemap->toplevel, pml4_idx, 0, false);
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_idx, 0); if (!pml3)
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_idx, 0); return 0;
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_idx, 0, false);
if (!pml2)
return 0;
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_idx, 0, false);
if (!pml1)
return 0;
uint64_t phys_addr = uint64_t phys_addr = pml1[pml1_idx] & 0x000FFFFFFFFFF000;
pml1[pml1_idx] &
0x000FFFFFFFFFF000; // Masque pour obtenir l'adresse physique (en retirant
// les bits de flags)
return phys_addr; return phys_addr;
} }
@ -198,9 +209,30 @@ void vmm_map(pagemap_t *pm, uint64_t vaddr, uint64_t paddr, uint64_t flags) {
uint64_t pml2_entry = (vaddr >> 21) & 0x1ff; uint64_t pml2_entry = (vaddr >> 21) & 0x1ff;
uint64_t pml1_entry = (vaddr >> 12) & 0x1ff; uint64_t pml1_entry = (vaddr >> 12) & 0x1ff;
uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry, flags); uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry,
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, flags); VMM_PRESENT | VMM_WRITABLE, true);
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, flags); uint64_t *pml2 =
__vmm_get_next_lvl(pml3, pml3_entry, VMM_PRESENT | VMM_WRITABLE, true);
uint64_t *pml1 =
__vmm_get_next_lvl(pml2, pml2_entry, VMM_PRESENT | VMM_WRITABLE, true);
pml1[pml1_entry] = paddr | flags;
}
void vmm_map_user(pagemap_t *pm, uint64_t vaddr, uint64_t paddr,
uint64_t flags) {
uint64_t pml4_entry = (vaddr >> 39) & 0x1ff;
uint64_t pml3_entry = (vaddr >> 30) & 0x1ff;
uint64_t pml2_entry = (vaddr >> 21) & 0x1ff;
uint64_t pml1_entry = (vaddr >> 12) & 0x1ff;
uint64_t *pml3 =
__vmm_get_next_lvl(pm->toplevel, pml4_entry, flags,
true); // PML3 / Page Directory Pointer Entry
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, flags,
true); // PML2 / Page Directory Entry
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, flags,
true); // PML1 / Page Table Entry
pml1[pml1_entry] = paddr | flags; pml1[pml1_entry] = paddr | flags;
} }
@ -211,13 +243,13 @@ void vmm_unmap(pagemap_t *pm, uint64_t vaddr) {
uint64_t pml3_entry = (vaddr >> 30) & 0x1ff; uint64_t pml3_entry = (vaddr >> 30) & 0x1ff;
uint64_t pml4_entry = (vaddr >> 39) & 0x1ff; uint64_t pml4_entry = (vaddr >> 39) & 0x1ff;
uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry, 0); uint64_t *pml3 = __vmm_get_next_lvl(pm->toplevel, pml4_entry, 0, false);
if (pml3 == NULL) if (pml3 == NULL)
return; return;
uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, 0); uint64_t *pml2 = __vmm_get_next_lvl(pml3, pml3_entry, 0, false);
if (pml2 == NULL) if (pml2 == NULL)
return; return;
uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, 0); uint64_t *pml1 = __vmm_get_next_lvl(pml2, pml2_entry, 0, false);
if (pml1 == NULL) if (pml1 == NULL)
return; return;

5
kernel/src/mm/vmm.h Executable file → Normal file
View file

@ -25,7 +25,6 @@ extern sym rodata_end_ld;
extern sym data_start_ld; extern sym data_start_ld;
extern sym data_end_ld; extern sym data_end_ld;
typedef struct pagemap { typedef struct pagemap {
uint64_t *toplevel; uint64_t *toplevel;
} pagemap_t; } pagemap_t;
@ -39,5 +38,9 @@ void vmm_release_pm(pagemap_t *pm);
void vmm_load_pagemap(pagemap_t *pm); void vmm_load_pagemap(pagemap_t *pm);
uint64_t vmm_get_flags(pagemap_t *pm, uint64_t vaddr); uint64_t vmm_get_flags(pagemap_t *pm, uint64_t vaddr);
uint64_t virt_to_phys(pagemap_t *pagemap, uint64_t virt); uint64_t virt_to_phys(pagemap_t *pagemap, uint64_t virt);
// NOTE: for user mode, please use vmm_map_user instead.
void vmm_map(pagemap_t *pm, uint64_t vaddr, uint64_t paddr, uint64_t flags); void vmm_map(pagemap_t *pm, uint64_t vaddr, uint64_t paddr, uint64_t flags);
void vmm_map_user(pagemap_t *pm, uint64_t vaddr, uint64_t paddr,
uint64_t flags);
void vmm_unmap(pagemap_t *pm, uint64_t vaddr); void vmm_unmap(pagemap_t *pm, uint64_t vaddr);

39
kernel/src/sched/sched.c Executable file → Normal file
View file

@ -1,6 +1,6 @@
#include "sched/sched.h" #include "sched/sched.h"
#include "mm/pmm.h"
#include "mm/memop.h" #include "mm/memop.h"
#include "mm/pmm.h"
#include "mm/vmm.h" #include "mm/vmm.h"
#include "sys/arch/x86_64/idt.h" #include "sys/arch/x86_64/idt.h"
#include "sys/log.h" #include "sys/log.h"
@ -11,13 +11,15 @@ sched_process *curr_proc;
int current_pid = 0; int current_pid = 0;
int standby = 0; int standby = 0;
void map_range_to_pagemap(pagemap_t *dest_pagemap, pagemap_t *src_pagemap, uint64_t start, uint64_t size, uint64_t flags) void map_range_to_pagemap(pagemap_t *dest_pagemap, pagemap_t *src_pagemap,
{ uint64_t start, uint64_t size, int user,
for (uint64_t offset = 0; offset < size; offset += PMM_PAGE_SIZE) uint64_t flags) {
{ for (uint64_t offset = 0; offset < size; offset += PMM_PAGE_SIZE) {
uint64_t phys = virt_to_phys(src_pagemap, start + offset); uint64_t phys = virt_to_phys(src_pagemap, start + offset);
if (phys) if (phys) {
{ if (user)
vmm_map_user(dest_pagemap, start + offset, phys, flags);
else
vmm_map(dest_pagemap, start + offset, phys, flags); vmm_map(dest_pagemap, start + offset, phys, flags);
} }
} }
@ -41,8 +43,8 @@ void sched_init() {
"mode.\n"); "mode.\n");
} }
sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uint32_t flags) sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm,
{ uint32_t flags) {
// TODO: implement a separate strlen function // TODO: implement a separate strlen function
// as there's like 4 strlen impls in the kernel. // as there's like 4 strlen impls in the kernel.
int i = 0; int i = 0;
@ -71,7 +73,8 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
proc->stack_base_physical = stack_phys; proc->stack_base_physical = stack_phys;
proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE; proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE;
} else if (flags == SCHED_USER_PROCESS) { } else if (flags == SCHED_USER_PROCESS) {
vmm_map(proc->pm, (uint64_t)stack_virt, (uint64_t)stack_phys, VMM_PRESENT | VMM_WRITABLE | VMM_USER); vmm_map_user(proc->pm, (uint64_t)stack_virt, (uint64_t)stack_phys,
VMM_PRESENT | VMM_WRITABLE | VMM_USER);
proc->stack_base = stack_virt; proc->stack_base = stack_virt;
proc->stack_base_physical = stack_phys; proc->stack_base_physical = stack_phys;
proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE; proc->stack_end = proc_list->stack_base + PMM_PAGE_SIZE;
@ -81,8 +84,7 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
if (flags == SCHED_KERNEL_PROCESS) { if (flags == SCHED_KERNEL_PROCESS) {
proc->regs.cs = 0x28; // Run in kernel mode proc->regs.cs = 0x28; // Run in kernel mode
proc->regs.ss = 0x30; proc->regs.ss = 0x30;
} } else if (flags == SCHED_USER_PROCESS) {
else if (flags == SCHED_USER_PROCESS) {
proc->regs.cs = 0x43; // Run in user mode proc->regs.cs = 0x43; // Run in user mode
proc->regs.ss = 0x3B; proc->regs.ss = 0x3B;
} }
@ -95,7 +97,12 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
current_pid++; current_pid++;
map_range_to_pagemap(pm, vmm_kernel_pm, 0x1000, 0x10000, VMM_PRESENT | VMM_WRITABLE | VMM_USER); if (flags == SCHED_USER_PROCESS)
map_range_to_pagemap(pm, vmm_kernel_pm, 0x1000, 0x10000, 1,
VMM_PRESENT | VMM_WRITABLE | VMM_USER);
else
map_range_to_pagemap(pm, vmm_kernel_pm, 0x1000, 0x10000, 0,
VMM_PRESENT | VMM_WRITABLE);
if (standby) { if (standby) {
// Disable standby mode as there's actually something to // Disable standby mode as there's actually something to
@ -105,7 +112,8 @@ sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t* pm, uin
"disabled.\n"); "disabled.\n");
} }
log("sched - created process '%s' (pid: %d, rip: %p)\n", proc->name, proc->pid, proc->regs.rip); log("sched - created process '%s' (pid: %d, rip: %p)\n", proc->name,
proc->pid, proc->regs.rip);
return proc; return proc;
} }
@ -115,8 +123,7 @@ void sched_exit(int exit_code) {
schedule(&curr_proc->regs); schedule(&curr_proc->regs);
} }
void schedule(registers_t *regs) void schedule(registers_t *regs) {
{
if (standby) { if (standby) {
// log("sched - Sched is in standby.\n"); // log("sched - Sched is in standby.\n");
return; return;

13
kernel/src/sched/sched.h Executable file → Normal file
View file

@ -4,13 +4,11 @@
#include "sys/arch/x86_64/idt.h" #include "sys/arch/x86_64/idt.h"
#define SCHED_KERNEL_PROCESS 0 // A process that runs in kernel mode. #define SCHED_KERNEL_PROCESS 0 // A process that runs in kernel mode.
#define SCHED_USER_PROCESS 1 // A process that runs in userspace. The code MUST be mapped directly after creating the process. #define SCHED_USER_PROCESS \
1 // A process that runs in userspace. The code MUST be mapped directly after
// creating the process.
typedef enum { typedef enum { SCHED_RUNNING, SCHED_DIED, SCHED_EMPTY } sched_proc_type;
SCHED_RUNNING,
SCHED_DIED,
SCHED_EMPTY
} sched_proc_type;
typedef struct _sched_process { typedef struct _sched_process {
char name[128]; char name[128];
@ -36,6 +34,7 @@ extern sched_process *proc_list;
// extern sched_process *idle_process; // extern sched_process *idle_process;
void sched_init(); void sched_init();
sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm, uint32_t flags); sched_process *sched_create(char *name, uint64_t entry_point, pagemap_t *pm,
uint32_t flags);
void sched_exit(int exit_code); void sched_exit(int exit_code);
void schedule(registers_t *regs); void schedule(registers_t *regs);

95
kernel/src/sys/acpi.c Normal file
View file

@ -0,0 +1,95 @@
#include "limine.h"
#include "mm/pmm.h"
#include "sys/log.h"
#include <mm/memop.h>
#include <stddef.h>
#include <sys/acpi.h>
__attribute__((
used,
section(".limine_requests"))) static volatile struct limine_rsdp_request
rsdp_req = {.revision = 0, .id = LIMINE_RSDP_REQUEST};
rsdp_t *rsdp;
int acpi_available = 0;
int is_xsdt = 0;
xsdt_t *xsdt;
rsdt_t *rsdt;
int item_count = 0;
static int acpi_validate_rsdp(char *byte_array, size_t size) {
uint32_t sum = 0;
for (int i = 0; i < size; i++) {
sum += byte_array[i];
}
return (sum & 0xFF) == 0;
}
void *acpi_find_table(char *sign, int sign_size) {
if (!acpi_available)
return NULL;
if (is_xsdt) {
for (int i = 0; i < item_count; i++) {
uint64_t *lst =
(uint64_t *)HIGHER_HALF((uint64_t)xsdt->PointerToOtherSDT);
acpi_table_header_t *ptr = (acpi_table_header_t *)HIGHER_HALF(lst[i]);
if (!memcmp(ptr->Signature, sign, sign_size))
return (void *)ptr;
}
} else {
for (int i = 0; i < item_count; i++) {
acpi_table_header_t *ptr = (acpi_table_header_t *)HIGHER_HALF(
(uint64_t)rsdt->PointerToOtherSDT[i]);
if (!memcmp(ptr->Signature, sign, sign_size))
return (void *)ptr;
}
}
return NULL;
}
void acpi_init() {
rsdp_t *rsdp = (rsdp_t *)HIGHER_HALF(rsdp_req.response->address);
if (!rsdp) {
log("acpi - not available: RSDP is NULL!\n");
return;
}
if (rsdp->rev < 2) {
if (!acpi_validate_rsdp((char *)rsdp, sizeof(rsdp_t))) {
log("acpi - not available: Was the RSDP hijacked?\n");
return;
}
rsdt = (rsdt_t *)HIGHER_HALF((uint64_t)rsdp->rsdt_addr);
log("acpi - RSDT found at %p\n", rsdt);
item_count = (rsdt->h.Length - sizeof(acpi_table_header_t)) / 4;
log("acpi - RSDT contains %d entries\n", item_count);
} else {
is_xsdt = 1;
if (!acpi_validate_rsdp((char *)rsdp, sizeof(xsdp_t))) {
log("acpi - not available: Was the XSDP hijacked?\n");
return;
}
xsdt = (xsdt_t *)HIGHER_HALF((uint64_t)((xsdp_t *)rsdp)->xsdt_addr);
log("acpi - XSDT found at %p\n", xsdt);
item_count = (xsdt->h.Length - sizeof(acpi_table_header_t)) / 8;
log("acpi - XSDT contains %d entries\n", item_count);
}
acpi_available = 1;
void *fadt = acpi_find_table("FACP", 4);
if (!fadt) {
log("acpi - FADT not found\n");
acpi_available = 0;
return;
} else {
log("acpi - FADT found at %p\n", fadt);
log("acpi - ACPI initialized successfully\n");
}
}

51
kernel/src/sys/acpi.h Normal file
View file

@ -0,0 +1,51 @@
#pragma once
#include <stdint.h>
#define ACPI_RSDP_SIGNATURE "RSD PTR "
#define ACPI_RSDP_SIGNATURE_LEN 7
typedef struct __acpi_table_header {
char Signature[4];
uint32_t Length;
uint8_t Revision;
uint8_t Checksum;
char OEMID[6];
char OEMTableID[8];
uint32_t OEMRevision;
uint32_t CreatorID;
uint32_t CreatorRevision;
} acpi_table_header_t;
typedef struct __rsdp {
char signature[8];
uint8_t chksum;
char oemid[6];
uint8_t rev;
uint32_t rsdt_addr;
} __attribute__((packed)) rsdp_t;
typedef struct __xsdp {
char signature[8];
uint8_t chksum;
char oemid[6];
uint8_t rev;
uint32_t rsdt_addr; // deprecated since version 2.0
uint32_t len;
uint64_t xsdt_addr;
uint8_t chksum_ex;
uint8_t reserved[3];
} __attribute__((packed)) xsdp_t;
typedef struct __rsdt {
acpi_table_header_t h;
uint32_t *PointerToOtherSDT;
} rsdt_t;
typedef struct __xsdt {
acpi_table_header_t h;
uint64_t *PointerToOtherSDT;
} xsdt_t;
void acpi_init();

46
kernel/src/sys/arch/x86_64/cpuid.h Executable file → Normal file
View file

@ -345,7 +345,8 @@
#define CPUID_EXTENDED_FEATURES_EDX_FAST_REP_MOV 1 << 4 #define CPUID_EXTENDED_FEATURES_EDX_FAST_REP_MOV 1 << 4
#define CPUID_EXTENDED_FEATURES_EDX_UINTR 1 << 5 #define CPUID_EXTENDED_FEATURES_EDX_UINTR 1 << 5
// bits 6 and 7 are reserved // bits 6 and 7 are reserved
#define CPUID_EXTENDED_FEATURES_EDX_AVX512_VPINTERSECT 1 << 8 // intel you son of a bitch #define CPUID_EXTENDED_FEATURES_EDX_AVX512_VPINTERSECT \
1 << 8 // intel you son of a bitch
#define CPUID_EXTENDED_FEATURES_EDX_SRBDS_CTRL 1 << 9 #define CPUID_EXTENDED_FEATURES_EDX_SRBDS_CTRL 1 << 9
#define CPUID_EXTENDED_FEATURES_EDX_MD_CLEAR 1 << 10 #define CPUID_EXTENDED_FEATURES_EDX_MD_CLEAR 1 << 10
#define CPUID_EXTENDED_FEATURES_EDX_RTM_ALWAYS_ABORT 1 << 11 #define CPUID_EXTENDED_FEATURES_EDX_RTM_ALWAYS_ABORT 1 << 11
@ -396,7 +397,6 @@
#define CPUID_EXTENDED_FEATURES_SL2_EDX_BHI_CTRL 1 << 4 #define CPUID_EXTENDED_FEATURES_SL2_EDX_BHI_CTRL 1 << 4
// The rest of the bits are reserved // The rest of the bits are reserved
enum leaves { enum leaves {
/* @ Basic CPU info /* @ Basic CPU info
* @ Returned EAX: Highest basic CPUID leaf present * @ Returned EAX: Highest basic CPUID leaf present
@ -407,7 +407,8 @@ enum leaves {
CPUID_VENDOR = 0x00000000, CPUID_VENDOR = 0x00000000,
/* @ CPU Version information /* @ CPU Version information
* @ Returned EAX: Family,Model,Stepping * @ Returned EAX: Family,Model,Stepping
* @ Returned EBX: Brand Index,CLFLUSH line size, Max number of logical processors * @ Returned EBX: Brand Index,CLFLUSH line size, Max number of logical
* processors
* @ Returned ECX: Featrue information * @ Returned ECX: Featrue information
* @ Retruned EDX: More feature information * @ Retruned EDX: More feature information
*/ */
@ -427,7 +428,8 @@ enum leaves {
*/ */
CPUID_SERIAL_NUMBER = 0x00000003, CPUID_SERIAL_NUMBER = 0x00000003,
/* @ CPU Deterministic cache parameters !!! Initial ECX = Cache level !!! /* @ CPU Deterministic cache parameters !!! Initial ECX = Cache level !!!
* @ Returned EAX: Cache level,Is self init,Is fully associative,Maximum number of addressable IDs for logical processors sharing this cache * @ Returned EAX: Cache level,Is self init,Is fully associative,Maximum
* number of addressable IDs for logical processors sharing this cache
* @ Returned EBX: L, P and W * @ Returned EBX: L, P and W
* @ Returned ECX: S * @ Returned ECX: S
* @ Retruned EDX: Cache inclusiveness and Complex Cache indexing * @ Retruned EDX: Cache inclusiveness and Complex Cache indexing
@ -436,8 +438,10 @@ enum leaves {
/* @ MONITOR/MWAIT params /* @ MONITOR/MWAIT params
* @ Returned EAX: Smallest monitor-line size * @ Returned EAX: Smallest monitor-line size
* @ Returned EBX: Largest monitor-line size * @ Returned EBX: Largest monitor-line size
* @ Returned ECX: Enumeration of Monitor-Mwait extensions,Supports treating interrupts as break-event for MWAIT * @ Returned ECX: Enumeration of Monitor-Mwait extensions,Supports treating
* @ Retruned EDX: Number of sub C-states supported using MWAIT for each C number thingy IDK * interrupts as break-event for MWAIT
* @ Retruned EDX: Number of sub C-states supported using MWAIT for each C
* number thingy IDK
*/ */
CPUID_MONITOR_MWAIT = 0x00000005, CPUID_MONITOR_MWAIT = 0x00000005,
/* @ Thermal and power managment /* @ Thermal and power managment
@ -484,8 +488,10 @@ enum leaves {
/* @ Hypervisor CPUID Leaf Range /* @ Hypervisor CPUID Leaf Range
* @ Returned EAX: Highest hypervisor CPUID leaf present * @ Returned EAX: Highest hypervisor CPUID leaf present
* @ Returned EBX: Largest monitor-line size * @ Returned EBX: Largest monitor-line size
* @ Returned ECX: Enumeration of Monitor-Mwait extensions,Supports treating interrupts as break-event for MWAIT * @ Returned ECX: Enumeration of Monitor-Mwait extensions,Supports treating
* @ Retruned EDX: Number of sub C-states supported using MWAIT for each C number thingy IDK * interrupts as break-event for MWAIT
* @ Retruned EDX: Number of sub C-states supported using MWAIT for each C
* number thingy IDK
*/ */
CPUID_HYPERV_IDENT = 0x40000000, CPUID_HYPERV_IDENT = 0x40000000,
/* @ Hypervisor Vendor-Neutral Interface Identification /* @ Hypervisor Vendor-Neutral Interface Identification
@ -519,7 +525,8 @@ enum leaves {
/* @ Hypervisor Implementation Limits /* @ Hypervisor Implementation Limits
* @ Returned EAX: The maximum number of virtual processors supported * @ Returned EAX: The maximum number of virtual processors supported
* @ Returned EBX: The maximum number of logical processors supported * @ Returned EBX: The maximum number of logical processors supported
* @ Returned ECX: The maximum number of physical interrupt vectors available for interrupt remapping. * @ Returned ECX: The maximum number of physical interrupt vectors available
* for interrupt remapping.
* @ Retruned EDX: Reserved * @ Retruned EDX: Reserved
*/ */
CPUID_MS_HYPERV_IMPL_LIMITS = 0x40000005, CPUID_MS_HYPERV_IMPL_LIMITS = 0x40000005,
@ -575,7 +582,8 @@ enum leaves {
/* @ Cache line size and associativity /* @ Cache line size and associativity
* @ Returned EAX: Reserved * @ Returned EAX: Reserved
* @ Returned EBX: Reserved * @ Returned EBX: Reserved
* @ Returned ECX: Bits 0-7 = Cache line size in bytes, Bits 12-15 = L2 Associativity, Bits 16-31 = Cache size in 1K blocks * @ Returned ECX: Bits 0-7 = Cache line size in bytes, Bits 12-15 = L2
* Associativity, Bits 16-31 = Cache size in 1K blocks
* @ Retruned EDX: Reserved * @ Retruned EDX: Reserved
*/ */
CPUID_MORE_CACHE = 0x800000006, CPUID_MORE_CACHE = 0x800000006,
@ -587,7 +595,8 @@ enum leaves {
*/ */
CPUID_INVARIANT_TSC_AVAILABLE = 0x800000007, CPUID_INVARIANT_TSC_AVAILABLE = 0x800000007,
/* @ Physical adress size /* @ Physical adress size
* @ Returned EAX: Bits 0-7 = Physical Adress bits, Bits 8-15 = Linear Address bits * @ Returned EAX: Bits 0-7 = Physical Adress bits, Bits 8-15 = Linear
* Address bits
* @ Returned EBX: Bit 9 = WBNOINVD available * @ Returned EBX: Bit 9 = WBNOINVD available
* @ Returned ECX: Reserved * @ Returned ECX: Reserved
* @ Retruned EDX: Reserved * @ Retruned EDX: Reserved
@ -596,14 +605,16 @@ enum leaves {
}; };
enum sub_leaves { enum sub_leaves {
/* @ Extended features available subleaf 1 !!! All fields return 0 is info not available !!! /* @ Extended features available subleaf 1 !!! All fields return 0 is info not
* available !!!
* @ Returned EAX: Features * @ Returned EAX: Features
* @ Returned EBX: PPIN * @ Returned EBX: PPIN
* @ Returned ECX: Reserved * @ Returned ECX: Reserved
* @ Retruned EDX: CET_SSS * @ Retruned EDX: CET_SSS
*/ */
CPUID_EXTENDED_FEATURES_SL1 = 0x00000001, CPUID_EXTENDED_FEATURES_SL1 = 0x00000001,
/* @ Extended features available subleaf 2 !!! All fields return 0 is info not available !!! /* @ Extended features available subleaf 2 !!! All fields return 0 is info not
* available !!!
* @ Returned EAX: Reserved * @ Returned EAX: Reserved
* @ Returned EBX: Reserved * @ Returned EBX: Reserved
* @ Returned ECX: Reserved * @ Returned ECX: Reserved
@ -626,12 +637,11 @@ enum sub_leaves{
CPUID_TILE_INFO_PALETTE1 = 0x000000001, CPUID_TILE_INFO_PALETTE1 = 0x000000001,
}; };
static inline void cpuid(int leaf, int subleaf, int* a, int* b, int* c, int* d) { static inline void cpuid(int leaf, int subleaf, int *a, int *b, int *c,
__asm__ __volatile__ ( int *d) {
"cpuid" __asm__ __volatile__("cpuid"
: "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d) : "=a"(*a), "=b"(*b), "=c"(*c), "=d"(*d)
: "a" (leaf), "c" (subleaf) : "a"(leaf), "c"(subleaf));
);
} }
#endif // __CPUID_H__ #endif // __CPUID_H__

View file

@ -1,9 +1,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
void fpu_set_cw(const uint16_t cw) { void fpu_set_cw(const uint16_t cw) { asm volatile("fldcw %0" ::"m"(cw)); }
asm volatile("fldcw %0" :: "m"(cw));
}
void fpu_activate() { void fpu_activate() {
size_t cr4; size_t cr4;

15
kernel/src/sys/arch/x86_64/gdt.c Executable file → Normal file
View file

@ -1,11 +1,10 @@
// #include "sys/log.h" // #include "sys/log.h"
#include <mm/memop.h>
#include <stdint.h> #include <stdint.h>
#include <sys/arch/x86_64/gdt.h> #include <sys/arch/x86_64/gdt.h>
#include <sys/log.h> #include <sys/log.h>
#include <mm/memop.h>
gdt_table def_table = { gdt_table def_table = {{
{
0x0000000000000000, // 0x00 0x0000000000000000, // 0x00
0x00009a000000ffff, // 0x08 16 bit code 0x00009a000000ffff, // 0x08 16 bit code
@ -20,9 +19,7 @@ gdt_table def_table = {
0x00aff3000000ffff, // 0x38 data ss 0x00aff3000000ffff, // 0x38 data ss
0x00affb000000ffff, // 0x40 user mode code cs 0x00affb000000ffff, // 0x40 user mode code cs
}, },
{ {}};
}
};
tssr tss_list[256]; // One tssr per CPU tssr tss_list[256]; // One tssr per CPU
@ -41,10 +38,8 @@ void gdt_init( char* kstack ) {
def_table.tss_entry.base3 = (uint32_t)(tss >> 32); def_table.tss_entry.base3 = (uint32_t)(tss >> 32);
def_table.tss_entry.resv = 0; def_table.tss_entry.resv = 0;
gdtr gdt = (gdtr){ gdtr gdt =
.size = (sizeof(gdt_table)) - 1, (gdtr){.size = (sizeof(gdt_table)) - 1, .address = (uint64_t)&def_table};
.address = (uint64_t)&def_table
};
__asm__ volatile("lgdt %0\n\t" : : "m"(gdt) : "memory"); __asm__ volatile("lgdt %0\n\t" : : "m"(gdt) : "memory");
__asm__ volatile("ltr %0\n\t" : : "r"((uint16_t)0x48)); __asm__ volatile("ltr %0\n\t" : : "r"((uint16_t)0x48));

1
kernel/src/sys/arch/x86_64/gdt.h Executable file → Normal file
View file

@ -23,7 +23,6 @@ typedef struct {
uint64_t address; uint64_t address;
} __attribute__((packed)) gdtr; } __attribute__((packed)) gdtr;
typedef struct { typedef struct {
uint32_t resv; uint32_t resv;
uint64_t rsp[4]; uint64_t rsp[4];

9
kernel/src/sys/arch/x86_64/idt.c Executable file → Normal file
View file

@ -3,8 +3,7 @@
#include <sys/arch/x86_64/idt.h> #include <sys/arch/x86_64/idt.h>
#include <sys/log.h> #include <sys/log.h>
__attribute__((aligned(0x10))) __attribute__((aligned(0x10))) static idt_entry_t idt[256];
static idt_entry_t idt[256];
static idtr_t idtr; static idtr_t idtr;
@ -30,7 +29,8 @@ void idt_init() {
for (uint16_t vector = 0; vector <= 256; vector++) { for (uint16_t vector = 0; vector <= 256; vector++) {
if (vector == 0x80) if (vector == 0x80)
continue; // We skip the syscall handler, since it should be called from user space. continue; // We skip the syscall handler, since it should be called from
// user space.
idt_set_descriptor(vector, isr_stub_table[vector], 0x8E); idt_set_descriptor(vector, isr_stub_table[vector], 0x8E);
vectors[vector] = 1; vectors[vector] = 1;
} }
@ -45,6 +45,7 @@ void idt_init() {
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT __asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
__asm__ volatile("sti"); // set the interrupt flag __asm__ volatile("sti"); // set the interrupt flag
//logln(progress, "kinit stage 1", "IDT initialized! Time to receive interrupts!\n"); // logln(progress, "kinit stage 1", "IDT initialized! Time to receive
// interrupts!\n");
log("idt - initialized\n"); log("idt - initialized\n");
} }

9
kernel/src/sys/arch/x86_64/idt.h Executable file → Normal file
View file

@ -34,10 +34,13 @@ typedef struct stackframe {
typedef struct { typedef struct {
uint16_t isr_low; // The lower 16 bits of the ISR's address uint16_t isr_low; // The lower 16 bits of the ISR's address
uint16_t kernel_cs; // The GDT segment selector that the CPU will load into CS before calling the ISR uint16_t kernel_cs; // The GDT segment selector that the CPU will load into CS
uint8_t ist; // The IST in the TSS that the CPU will load into RSP; set to zero for now // before calling the ISR
uint8_t ist; // The IST in the TSS that the CPU will load into RSP; set to
// zero for now
uint8_t attributes; // Type and attributes; see the IDT page uint8_t attributes; // Type and attributes; see the IDT page
uint16_t isr_mid; // The higher 16 bits of the lower 32 bits of the ISR's address uint16_t
isr_mid; // The higher 16 bits of the lower 32 bits of the ISR's address
uint32_t isr_high; // The higher 32 bits of the ISR's address uint32_t isr_high; // The higher 32 bits of the ISR's address
uint32_t reserved; // Set to zero uint32_t reserved; // Set to zero
} __attribute__((packed)) idt_entry_t; } __attribute__((packed)) idt_entry_t;

31
kernel/src/sys/arch/x86_64/interrupts.c Executable file → Normal file
View file

@ -15,14 +15,14 @@
int pit_millis = 0; int pit_millis = 0;
int pit_secs = 0; int pit_secs = 0;
extern int vmm_kernel_pm_exists;
struct Idt_StackFrame { struct Idt_StackFrame {
struct Idt_StackFrame *rbp; struct Idt_StackFrame *rbp;
uint64_t rip; uint64_t rip;
} __attribute__((packed)); } __attribute__((packed));
void dump_backtrace(registers_t *r) void dump_backtrace(registers_t *r) {
{
log("ints - backtrace : \n"); log("ints - backtrace : \n");
struct Idt_StackFrame *frame = (struct Idt_StackFrame *)r->rbp; struct Idt_StackFrame *frame = (struct Idt_StackFrame *)r->rbp;
@ -40,13 +40,16 @@ void exception_handler(registers_t *regs) {
if (regs->int_no < 32) { if (regs->int_no < 32) {
// panic(kmode_cpu_exception, regs); // panic(kmode_cpu_exception, regs);
log("ints - %d (RIP: %p, ERR: %d)\n", regs->int_no, regs->rip, regs->err_code); log("ints - %d (RIP: %p, ERR: %d)\n", regs->int_no, regs->rip,
regs->err_code);
if(regs->int_no == 0xe) { if (regs->int_no == 0xe && vmm_kernel_pm_exists) {
uint64_t cr2; uint64_t cr2;
asm("mov %%cr2, %0" : "=r"(cr2)); asm("mov %%cr2, %0" : "=r"(cr2));
log("ints - PF: Faulting location: %p (%p)\n", cr2, virt_to_phys(vmm_current_pm, cr2)); log("ints - PF: Faulting location: %p (%p)\n", cr2,
log("ints - PF: Faulting page flags: %p\n", vmm_get_flags(vmm_current_pm, cr2)); virt_to_phys(vmm_current_pm, cr2));
log("ints - PF: Faulting page flags: %p\n",
vmm_get_flags(vmm_current_pm, cr2));
log("ints - PF: Faulting page map: %p\n", PHYSICAL(vmm_current_pm)); log("ints - PF: Faulting page map: %p\n", PHYSICAL(vmm_current_pm));
} }
@ -56,24 +59,18 @@ void exception_handler(registers_t *regs) {
asm("hlt"); asm("hlt");
} }
if (regs->int_no == 1 + 32) if (regs->int_no == 1 + 32) {
{ if (inb(0x60) & 0x80) {
if (inb(0x60) & 0x80)
{
pic_ack(regs->int_no - 32); pic_ack(regs->int_no - 32);
return; return;
} }
log("ints - keyboard\n"); log("ints - keyboard\n");
} } else if (regs->int_no == 32 + 8) {
else if (regs->int_no == 32 + 8) {
rtc_handle_interrupt(regs); rtc_handle_interrupt(regs);
} } else if (regs->int_no == 0x80 - 32 || regs->int_no == 32) {
else if (regs->int_no == 0x80 - 32 || regs->int_no == 32) {
pit_handler(regs); pit_handler(regs);
} } else if (regs->int_no == 0x80) {
else if (regs->int_no == 0x80)
{
syscall_handle(regs); syscall_handle(regs);
} }
// logln(info, "arch/ints", "Received interrupt %d\n", regs->int_no); // logln(info, "arch/ints", "Received interrupt %d\n", regs->int_no);

0
kernel/src/sys/arch/x86_64/pic.c Executable file → Normal file
View file

28
kernel/src/sys/arch/x86_64/pit.c Executable file → Normal file
View file

@ -1,26 +1,24 @@
#include "sched/sched.h" #include "sched/sched.h"
#include "sys/arch/x86_64/idt.h" #include "sys/arch/x86_64/idt.h"
#include "sys/arch/x86_64/pic.h" #include "sys/arch/x86_64/pic.h"
#include <sys/log.h>
#include <stdint.h> #include <stdint.h>
#include <sys/log.h>
#ifdef __x86_64__ #ifdef __x86_64__
#include <sys/arch/x86_64/pit.h>
#include <sys/arch/x86_64/idt.h> #include <sys/arch/x86_64/idt.h>
#include <sys/arch/x86_64/pit.h>
// #include <sipaa/sched.h> // #include <sipaa/sched.h>
uint32_t tick = 0; uint32_t tick = 0;
void pit_handler(registers_t *regs) void pit_handler(registers_t *regs) {
{
tick++; tick++;
schedule(regs); schedule(regs);
// Scheduler_Schedule(regs); // Scheduler_Schedule(regs);
} }
void pit_init(uint32_t frequency) void pit_init(uint32_t frequency) {
{
uint32_t divisor = PIT_FREQUENCY / frequency; uint32_t divisor = PIT_FREQUENCY / frequency;
outb(0x43, 0x34); outb(0x43, 0x34);
outb(0x40, (uint8_t)(divisor & 0xFF)); outb(0x40, (uint8_t)(divisor & 0xFF));
@ -29,30 +27,24 @@ void pit_init(uint32_t frequency)
pic_unmask_irq(0); pic_unmask_irq(0);
} }
void sleep(uint32_t seconds) void sleep(uint32_t seconds) {
{
uint32_t eticks = tick + seconds * HZ; uint32_t eticks = tick + seconds * HZ;
while (tick < eticks) while (tick < eticks) {
{
__asm__ __volatile__("hlt"); __asm__ __volatile__("hlt");
} }
} }
void sleep_ms(uint32_t milliseconds) void sleep_ms(uint32_t milliseconds) {
{
uint32_t eticks = tick + (milliseconds * HZ) / 1000; uint32_t eticks = tick + (milliseconds * HZ) / 1000;
while (tick < eticks) while (tick < eticks) {
{
__asm__ __volatile__("hlt"); __asm__ __volatile__("hlt");
} }
} }
// todo: unistd: add usleep function // todo: unistd: add usleep function
void usleep(uint32_t usecs) void usleep(uint32_t usecs) {
{
uint32_t eticks = tick + (usecs * HZ); uint32_t eticks = tick + (usecs * HZ);
while (tick < eticks) while (tick < eticks) {
{
__asm__ __volatile__("hlt"); __asm__ __volatile__("hlt");
} }
} }

8
kernel/src/sys/arch/x86_64/rtc.c Executable file → Normal file
View file

@ -1,7 +1,7 @@
#include "sys/arch/x86_64/idt.h" #include "sys/arch/x86_64/idt.h"
#include "sys/arch/x86_64/io.h" #include "sys/arch/x86_64/io.h"
#include <sys/arch/x86_64/rtc.h>
#include <sys/arch/x86_64/pic.h> #include <sys/arch/x86_64/pic.h>
#include <sys/arch/x86_64/rtc.h>
#include <sys/printf.h> #include <sys/printf.h>
void rtc_init() { void rtc_init() {
@ -13,8 +13,10 @@ void rtc_init() {
asm("cli"); // disable interrupts asm("cli"); // disable interrupts
outb(0x70, 0x8B); // select register B, and disable NMI outb(0x70, 0x8B); // select register B, and disable NMI
char prev = inb(0x71); // read the current value of register B char prev = inb(0x71); // read the current value of register B
outb(0x70, 0x8B); // set the index again (a read will reset the index to register D) outb(0x70,
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This turns on bit 6 of register B 0x8B); // set the index again (a read will reset the index to register D)
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This
// turns on bit 6 of register B
asm("sti"); asm("sti");
// pic_unmask_irq(8); // pic_unmask_irq(8);

View file

@ -1,6 +1,4 @@
#include "sys/arch/x86_64/smp.h" #include "sys/arch/x86_64/smp.h"
#include "limine.h" #include "limine.h"
void smp_init() { void smp_init() {}
}

8
kernel/src/sys/arch/x86_64/sse.c Executable file → Normal file
View file

@ -1,14 +1,14 @@
#include <sys/arch/x86_64/sse.h> #include <sys/arch/x86_64/sse.h>
#include <sys/printf.h>
#include <sys/log.h> #include <sys/log.h>
#include <sys/printf.h>
int cpuid_check_bit(int reg, int bit) { int cpuid_check_bit(int reg, int bit) {
int eax, ebx, ecx, edx; int eax, ebx, ecx, edx;
// Minimal inline assembly to execute CPUID // Minimal inline assembly to execute CPUID
__asm__ volatile ( __asm__ volatile("cpuid" // Execute CPUID instruction
"cpuid" // Execute CPUID instruction : "=a"(eax), "=b"(ebx), "=c"(ecx),
: "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) // Output registers "=d"(edx) // Output registers
: "a"(0x1) // Input: EAX = 0x1 (query feature flags) : "a"(0x1) // Input: EAX = 0x1 (query feature flags)
: // No clobbered registers : // No clobbered registers
); );

View file

@ -1,3 +1 @@
void panic_ctx() { void panic_ctx() {}
}

View file

@ -24,7 +24,8 @@
*/ */
#ifdef __cplusplus #ifdef __cplusplus
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer." #error \
"Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
#endif #endif
#ifndef __STDC_VERSION__ #ifndef __STDC_VERSION__
@ -39,9 +40,9 @@
#define ALWAYS_INLINE inline #define ALWAYS_INLINE inline
#endif #endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define FLANTERM_IN_FLANTERM #define FLANTERM_IN_FLANTERM
@ -434,15 +435,16 @@ static const uint8_t builtin_font[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00};
};
static ALWAYS_INLINE uint32_t convert_colour(struct flanterm_context *_ctx, uint32_t colour) { static ALWAYS_INLINE uint32_t convert_colour(struct flanterm_context *_ctx,
uint32_t colour) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
uint32_t r = (colour >> 16) & 0xff; uint32_t r = (colour >> 16) & 0xff;
uint32_t g = (colour >> 8) & 0xff; uint32_t g = (colour >> 8) & 0xff;
uint32_t b = colour & 0xff; uint32_t b = colour & 0xff;
return (r << ctx->red_mask_shift) | (g << ctx->green_mask_shift) | (b << ctx->blue_mask_shift); return (r << ctx->red_mask_shift) | (g << ctx->green_mask_shift) |
(b << ctx->blue_mask_shift);
} }
static void flanterm_fb_save_state(struct flanterm_context *_ctx) { static void flanterm_fb_save_state(struct flanterm_context *_ctx) {
@ -468,7 +470,9 @@ static void flanterm_fb_swap_palette(struct flanterm_context *_ctx) {
ctx->text_fg = tmp; ctx->text_fg = tmp;
} }
static void plot_char_scaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) { static void plot_char_scaled_canvas(struct flanterm_context *_ctx,
struct flanterm_fb_char *c, size_t x,
size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) { if (x >= _ctx->cols || y >= _ctx->rows) {
@ -482,7 +486,8 @@ static void plot_char_scaled_canvas(struct flanterm_context *_ctx, struct flante
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates // naming: fx,fy for font coordinates, gx,gy for glyph coordinates
for (size_t gy = 0; gy < ctx->glyph_height; gy++) { for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
uint8_t fy = gy / ctx->font_scale_y; uint8_t fy = gy / ctx->font_scale_y;
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4); volatile uint32_t *fb_line =
ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width; uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
bool *glyph_pointer = glyph + (fy * ctx->font_width); bool *glyph_pointer = glyph + (fy * ctx->font_width);
for (size_t fx = 0; fx < ctx->font_width; fx++) { for (size_t fx = 0; fx < ctx->font_width; fx++) {
@ -497,7 +502,9 @@ static void plot_char_scaled_canvas(struct flanterm_context *_ctx, struct flante
} }
} }
static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) { static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx,
struct flanterm_fb_char *c, size_t x,
size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) { if (x >= _ctx->cols || y >= _ctx->rows) {
@ -516,7 +523,8 @@ static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx, struct flan
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates // naming: fx,fy for font coordinates, gx,gy for glyph coordinates
for (size_t gy = 0; gy < ctx->glyph_height; gy++) { for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
uint8_t fy = gy / ctx->font_scale_y; uint8_t fy = gy / ctx->font_scale_y;
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4); volatile uint32_t *fb_line =
ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
bool *glyph_pointer = glyph + (fy * ctx->font_width); bool *glyph_pointer = glyph + (fy * ctx->font_width);
for (size_t fx = 0; fx < ctx->font_width; fx++) { for (size_t fx = 0; fx < ctx->font_width; fx++) {
for (size_t i = 0; i < ctx->font_scale_x; i++) { for (size_t i = 0; i < ctx->font_scale_x; i++) {
@ -528,7 +536,9 @@ static void plot_char_scaled_uncanvas(struct flanterm_context *_ctx, struct flan
} }
} }
static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) { static void plot_char_unscaled_canvas(struct flanterm_context *_ctx,
struct flanterm_fb_char *c, size_t x,
size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) { if (x >= _ctx->cols || y >= _ctx->rows) {
@ -541,7 +551,8 @@ static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flan
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width]; bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates // naming: fx,fy for font coordinates, gx,gy for glyph coordinates
for (size_t gy = 0; gy < ctx->glyph_height; gy++) { for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4); volatile uint32_t *fb_line =
ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width; uint32_t *canvas_line = ctx->canvas + x + (y + gy) * ctx->width;
bool *glyph_pointer = glyph + (gy * ctx->font_width); bool *glyph_pointer = glyph + (gy * ctx->font_width);
for (size_t fx = 0; fx < ctx->font_width; fx++) { for (size_t fx = 0; fx < ctx->font_width; fx++) {
@ -552,7 +563,9 @@ static void plot_char_unscaled_canvas(struct flanterm_context *_ctx, struct flan
} }
} }
static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) { static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx,
struct flanterm_fb_char *c, size_t x,
size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) { if (x >= _ctx->cols || y >= _ctx->rows) {
@ -570,7 +583,8 @@ static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct fl
bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width]; bool *glyph = &ctx->font_bool[c->c * ctx->font_height * ctx->font_width];
// naming: fx,fy for font coordinates, gx,gy for glyph coordinates // naming: fx,fy for font coordinates, gx,gy for glyph coordinates
for (size_t gy = 0; gy < ctx->glyph_height; gy++) { for (size_t gy = 0; gy < ctx->glyph_height; gy++) {
volatile uint32_t *fb_line = ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4); volatile uint32_t *fb_line =
ctx->framebuffer + x + (y + gy) * (ctx->pitch / 4);
bool *glyph_pointer = glyph + (gy * ctx->font_width); bool *glyph_pointer = glyph + (gy * ctx->font_width);
for (size_t fx = 0; fx < ctx->font_width; fx++) { for (size_t fx = 0; fx < ctx->font_width; fx++) {
fb_line[fx] = *(glyph_pointer++) ? fg : bg; fb_line[fx] = *(glyph_pointer++) ? fg : bg;
@ -578,11 +592,13 @@ static void plot_char_unscaled_uncanvas(struct flanterm_context *_ctx, struct fl
} }
} }
static inline bool compare_char(struct flanterm_fb_char *a, struct flanterm_fb_char *b) { static inline bool compare_char(struct flanterm_fb_char *a,
struct flanterm_fb_char *b) {
return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg); return !(a->c != b->c || a->bg != b->bg || a->fg != b->fg);
} }
static void push_to_queue(struct flanterm_context *_ctx, struct flanterm_fb_char *c, size_t x, size_t y) { static void push_to_queue(struct flanterm_context *_ctx,
struct flanterm_fb_char *c, size_t x, size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols || y >= _ctx->rows) { if (x >= _ctx->cols || y >= _ctx->rows) {
@ -621,7 +637,8 @@ static void flanterm_fb_revscroll(struct flanterm_context *_ctx) {
} else { } else {
c = &ctx->grid[i]; c = &ctx->grid[i];
} }
push_to_queue(_ctx, c, (i + _ctx->cols) % _ctx->cols, (i + _ctx->cols) / _ctx->cols); push_to_queue(_ctx, c, (i + _ctx->cols) % _ctx->cols,
(i + _ctx->cols) / _ctx->cols);
} }
// Clear the first line of the screen. // Clear the first line of the screen.
@ -646,7 +663,8 @@ static void flanterm_fb_scroll(struct flanterm_context *_ctx) {
} else { } else {
c = &ctx->grid[i]; c = &ctx->grid[i];
} }
push_to_queue(_ctx, c, (i - _ctx->cols) % _ctx->cols, (i - _ctx->cols) / _ctx->cols); push_to_queue(_ctx, c, (i - _ctx->cols) % _ctx->cols,
(i - _ctx->cols) / _ctx->cols);
} }
// Clear the last line of the screen. // Clear the last line of the screen.
@ -676,7 +694,8 @@ static void flanterm_fb_clear(struct flanterm_context *_ctx, bool move) {
} }
} }
static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x, size_t y) { static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x,
size_t y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (x >= _ctx->cols) { if (x >= _ctx->cols) {
@ -697,18 +716,21 @@ static void flanterm_fb_set_cursor_pos(struct flanterm_context *_ctx, size_t x,
ctx->cursor_y = y; ctx->cursor_y = y;
} }
static void flanterm_fb_get_cursor_pos(struct flanterm_context *_ctx, size_t *x, size_t *y) { static void flanterm_fb_get_cursor_pos(struct flanterm_context *_ctx, size_t *x,
size_t *y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
*x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x; *x = ctx->cursor_x >= _ctx->cols ? _ctx->cols - 1 : ctx->cursor_x;
*y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y; *y = ctx->cursor_y >= _ctx->rows ? _ctx->rows - 1 : ctx->cursor_y;
} }
static void flanterm_fb_move_character(struct flanterm_context *_ctx, size_t new_x, size_t new_y, size_t old_x, size_t old_y) { static void flanterm_fb_move_character(struct flanterm_context *_ctx,
size_t new_x, size_t new_y, size_t old_x,
size_t old_y) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (old_x >= _ctx->cols || old_y >= _ctx->rows if (old_x >= _ctx->cols || old_y >= _ctx->rows || new_x >= _ctx->cols ||
|| new_x >= _ctx->cols || new_y >= _ctx->rows) { new_y >= _ctx->rows) {
return; return;
} }
@ -737,25 +759,29 @@ static void flanterm_fb_set_text_bg(struct flanterm_context *_ctx, size_t bg) {
ctx->text_bg = ctx->ansi_colours[bg]; ctx->text_bg = ctx->ansi_colours[bg];
} }
static void flanterm_fb_set_text_fg_bright(struct flanterm_context *_ctx, size_t fg) { static void flanterm_fb_set_text_fg_bright(struct flanterm_context *_ctx,
size_t fg) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->ansi_bright_colours[fg]; ctx->text_fg = ctx->ansi_bright_colours[fg];
} }
static void flanterm_fb_set_text_bg_bright(struct flanterm_context *_ctx, size_t bg) { static void flanterm_fb_set_text_bg_bright(struct flanterm_context *_ctx,
size_t bg) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = ctx->ansi_bright_colours[bg]; ctx->text_bg = ctx->ansi_bright_colours[bg];
} }
static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx, uint32_t fg) { static void flanterm_fb_set_text_fg_rgb(struct flanterm_context *_ctx,
uint32_t fg) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = convert_colour(_ctx, fg); ctx->text_fg = convert_colour(_ctx, fg);
} }
static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx, uint32_t bg) { static void flanterm_fb_set_text_bg_rgb(struct flanterm_context *_ctx,
uint32_t bg) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = convert_colour(_ctx, bg); ctx->text_bg = convert_colour(_ctx, bg);
@ -773,13 +799,15 @@ static void flanterm_fb_set_text_bg_default(struct flanterm_context *_ctx) {
ctx->text_bg = 0xffffffff; ctx->text_bg = 0xffffffff;
} }
static void flanterm_fb_set_text_fg_default_bright(struct flanterm_context *_ctx) { static void
flanterm_fb_set_text_fg_default_bright(struct flanterm_context *_ctx) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_fg = ctx->default_fg_bright; ctx->text_fg = ctx->default_fg_bright;
} }
static void flanterm_fb_set_text_bg_default_bright(struct flanterm_context *_ctx) { static void
flanterm_fb_set_text_bg_default_bright(struct flanterm_context *_ctx) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
ctx->text_bg = ctx->default_bg_bright; ctx->text_bg = ctx->default_bg_bright;
@ -829,9 +857,13 @@ static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
ctx->map[offset] = NULL; ctx->map[offset] = NULL;
} }
if ((ctx->old_cursor_x != ctx->cursor_x || ctx->old_cursor_y != ctx->cursor_y) || _ctx->cursor_enabled == false) { if ((ctx->old_cursor_x != ctx->cursor_x ||
ctx->old_cursor_y != ctx->cursor_y) ||
_ctx->cursor_enabled == false) {
if (ctx->old_cursor_x < _ctx->cols && ctx->old_cursor_y < _ctx->rows) { if (ctx->old_cursor_x < _ctx->cols && ctx->old_cursor_y < _ctx->rows) {
ctx->plot_char(_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols], ctx->old_cursor_x, ctx->old_cursor_y); ctx->plot_char(
_ctx, &ctx->grid[ctx->old_cursor_x + ctx->old_cursor_y * _ctx->cols],
ctx->old_cursor_x, ctx->old_cursor_y);
} }
} }
@ -844,7 +876,9 @@ static void flanterm_fb_double_buffer_flush(struct flanterm_context *_ctx) {
static void flanterm_fb_raw_putchar(struct flanterm_context *_ctx, uint8_t c) { static void flanterm_fb_raw_putchar(struct flanterm_context *_ctx, uint8_t c) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (ctx->cursor_x >= _ctx->cols && (ctx->cursor_y < _ctx->scroll_bottom_margin - 1 || _ctx->scroll_enabled)) { if (ctx->cursor_x >= _ctx->cols &&
(ctx->cursor_y < _ctx->scroll_bottom_margin - 1 ||
_ctx->scroll_enabled)) {
ctx->cursor_x = 0; ctx->cursor_x = 0;
ctx->cursor_y++; ctx->cursor_y++;
if (ctx->cursor_y == _ctx->scroll_bottom_margin) { if (ctx->cursor_y == _ctx->scroll_bottom_margin) {
@ -871,7 +905,8 @@ static void flanterm_fb_full_refresh(struct flanterm_context *_ctx) {
for (size_t y = 0; y < ctx->height; y++) { for (size_t y = 0; y < ctx->height; y++) {
for (size_t x = 0; x < ctx->width; x++) { for (size_t x = 0; x < ctx->width; x++) {
if (ctx->canvas != NULL) { if (ctx->canvas != NULL) {
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = ctx->canvas[y * ctx->width + x]; ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] =
ctx->canvas[y * ctx->width + x];
} else { } else {
ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = default_bg; ctx->framebuffer[y * (ctx->pitch / sizeof(uint32_t)) + x] = default_bg;
} }
@ -890,7 +925,8 @@ static void flanterm_fb_full_refresh(struct flanterm_context *_ctx) {
} }
} }
static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void *, size_t)) { static void flanterm_fb_deinit(struct flanterm_context *_ctx,
void (*_free)(void *, size_t)) {
struct flanterm_fb_context *ctx = (void *)_ctx; struct flanterm_fb_context *ctx = (void *)_ctx;
if (_free == NULL) { if (_free == NULL) {
@ -917,20 +953,15 @@ static void flanterm_fb_deinit(struct flanterm_context *_ctx, void (*_free)(void
} }
struct flanterm_context *flanterm_fb_init( struct flanterm_context *flanterm_fb_init(
void *(*_malloc)(size_t), void *(*_malloc)(size_t), void (*_free)(void *, size_t),
void (*_free)(void *, size_t),
uint32_t *framebuffer, size_t width, size_t height, size_t pitch, uint32_t *framebuffer, size_t width, size_t height, size_t pitch,
uint8_t red_mask_size, uint8_t red_mask_shift, uint8_t red_mask_size, uint8_t red_mask_shift, uint8_t green_mask_size,
uint8_t green_mask_size, uint8_t green_mask_shift, uint8_t green_mask_shift, uint8_t blue_mask_size, uint8_t blue_mask_shift,
uint8_t blue_mask_size, uint8_t blue_mask_shift, uint32_t *canvas, uint32_t *ansi_colours, uint32_t *ansi_bright_colours,
uint32_t *canvas, uint32_t *default_bg, uint32_t *default_fg, uint32_t *default_bg_bright,
uint32_t *ansi_colours, uint32_t *ansi_bright_colours, uint32_t *default_fg_bright, void *font, size_t font_width,
uint32_t *default_bg, uint32_t *default_fg, size_t font_height, size_t font_spacing, size_t font_scale_x,
uint32_t *default_bg_bright, uint32_t *default_fg_bright, size_t font_scale_y, size_t margin) {
void *font, size_t font_width, size_t font_height, size_t font_spacing,
size_t font_scale_x, size_t font_scale_y,
size_t margin
) {
if (font_scale_x == 0 || font_scale_y == 0) { if (font_scale_x == 0 || font_scale_y == 0) {
font_scale_x = 1; font_scale_x = 1;
font_scale_y = 1; font_scale_y = 1;
@ -944,8 +975,8 @@ struct flanterm_context *flanterm_fb_init(
} }
} }
/*if (red_mask_size < 8 || red_mask_size != green_mask_size || red_mask_size != blue_mask_size) { /*if (red_mask_size < 8 || red_mask_size != green_mask_size || red_mask_size
return NULL; != blue_mask_size) { return NULL;
}*/ }*/
if (_malloc == NULL) { if (_malloc == NULL) {
@ -956,10 +987,15 @@ struct flanterm_context *flanterm_fb_init(
_malloc = bump_alloc; _malloc = bump_alloc;
// Limit terminal size if needed // Limit terminal size if needed
if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) { if (width > FLANTERM_FB_WIDTH_LIMIT || height > FLANTERM_FB_HEIGHT_LIMIT) {
size_t width_limit = width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width; size_t width_limit =
size_t height_limit = height > FLANTERM_FB_HEIGHT_LIMIT ? FLANTERM_FB_HEIGHT_LIMIT : height; width > FLANTERM_FB_WIDTH_LIMIT ? FLANTERM_FB_WIDTH_LIMIT : width;
size_t height_limit =
height > FLANTERM_FB_HEIGHT_LIMIT ? FLANTERM_FB_HEIGHT_LIMIT : height;
framebuffer = (uint32_t *)((uintptr_t)framebuffer + ((((height / 2) - (height_limit / 2)) * pitch) + (((width / 2) - (width_limit / 2)) * 4))); framebuffer =
(uint32_t *)((uintptr_t)framebuffer +
((((height / 2) - (height_limit / 2)) * pitch) +
(((width / 2) - (width_limit / 2)) * 4)));
width = width_limit; width = width_limit;
height = height_limit; height = height_limit;
@ -1005,7 +1041,8 @@ struct flanterm_context *flanterm_fb_init(
if (ansi_bright_colours != NULL) { if (ansi_bright_colours != NULL) {
for (size_t i = 0; i < 8; i++) { for (size_t i = 0; i < 8; i++) {
ctx->ansi_bright_colours[i] = convert_colour(_ctx, ansi_bright_colours[i]); ctx->ansi_bright_colours[i] =
convert_colour(_ctx, ansi_bright_colours[i]);
} }
} else { } else {
ctx->ansi_bright_colours[0] = convert_colour(_ctx, 0x00555555); // black ctx->ansi_bright_colours[0] = convert_colour(_ctx, 0x00555555); // black
@ -1033,13 +1070,15 @@ struct flanterm_context *flanterm_fb_init(
if (default_bg_bright != NULL) { if (default_bg_bright != NULL) {
ctx->default_bg_bright = convert_colour(_ctx, *default_bg_bright); ctx->default_bg_bright = convert_colour(_ctx, *default_bg_bright);
} else { } else {
ctx->default_bg_bright = convert_colour(_ctx, 0x00555555); // background (black) ctx->default_bg_bright =
convert_colour(_ctx, 0x00555555); // background (black)
} }
if (default_fg_bright != NULL) { if (default_fg_bright != NULL) {
ctx->default_fg_bright = convert_colour(_ctx, *default_fg_bright); ctx->default_fg_bright = convert_colour(_ctx, *default_fg_bright);
} else { } else {
ctx->default_fg_bright = convert_colour(_ctx, 0x00ffffff); // foreground (grey) ctx->default_fg_bright =
convert_colour(_ctx, 0x00ffffff); // foreground (grey)
} }
ctx->text_fg = ctx->default_fg; ctx->text_fg = ctx->default_fg;
@ -1077,7 +1116,8 @@ struct flanterm_context *flanterm_fb_init(
ctx->font_width += font_spacing; ctx->font_width += font_spacing;
ctx->font_bool_size = FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool); ctx->font_bool_size =
FLANTERM_FB_FONT_GLYPHS * font_height * ctx->font_width * sizeof(bool);
ctx->font_bool = _malloc(ctx->font_bool_size); ctx->font_bool = _malloc(ctx->font_bool_size);
if (ctx->font_bool == NULL) { if (ctx->font_bool == NULL) {
goto fail; goto fail;
@ -1091,7 +1131,8 @@ struct flanterm_context *flanterm_fb_init(
// 9 dot wide fonts have 8 dots and one empty column, except // 9 dot wide fonts have 8 dots and one empty column, except
// characters 0xC0-0xDF replicate column 9. // characters 0xC0-0xDF replicate column 9.
for (size_t x = 0; x < 8; x++) { for (size_t x = 0; x < 8; x++) {
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x; size_t offset =
i * font_height * ctx->font_width + y * ctx->font_width + x;
if ((glyph[y] & (0x80 >> x))) { if ((glyph[y] & (0x80 >> x))) {
ctx->font_bool[offset] = true; ctx->font_bool[offset] = true;
@ -1101,7 +1142,8 @@ struct flanterm_context *flanterm_fb_init(
} }
// fill columns above 8 like VGA Line Graphics Mode does // fill columns above 8 like VGA Line Graphics Mode does
for (size_t x = 8; x < ctx->font_width; x++) { for (size_t x = 8; x < ctx->font_width; x++) {
size_t offset = i * font_height * ctx->font_width + y * ctx->font_width + x; size_t offset =
i * font_height * ctx->font_width + y * ctx->font_width + x;
if (i >= 0xc0 && i <= 0xdf) { if (i >= 0xc0 && i <= 0xdf) {
ctx->font_bool[offset] = (glyph[y] & 1); ctx->font_bool[offset] = (glyph[y] & 1);
@ -1135,7 +1177,8 @@ struct flanterm_context *flanterm_fb_init(
ctx->grid[i].bg = ctx->text_bg; ctx->grid[i].bg = ctx->text_bg;
} }
ctx->queue_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item); ctx->queue_size =
_ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item);
ctx->queue = _malloc(ctx->queue_size); ctx->queue = _malloc(ctx->queue_size);
if (ctx->queue == NULL) { if (ctx->queue == NULL) {
goto fail; goto fail;
@ -1143,7 +1186,8 @@ struct flanterm_context *flanterm_fb_init(
ctx->queue_i = 0; ctx->queue_i = 0;
memset(ctx->queue, 0, ctx->queue_size); memset(ctx->queue, 0, ctx->queue_size);
ctx->map_size = _ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *); ctx->map_size =
_ctx->rows * _ctx->cols * sizeof(struct flanterm_fb_queue_item *);
ctx->map = _malloc(ctx->map_size); ctx->map = _malloc(ctx->map_size);
if (ctx->map == NULL) { if (ctx->map == NULL) {
goto fail; goto fail;

View file

@ -26,9 +26,9 @@
#ifndef FLANTERM_FB_H #ifndef FLANTERM_FB_H
#define FLANTERM_FB_H 1 #define FLANTERM_FB_H 1
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -43,23 +43,24 @@ extern "C" {
#endif #endif
struct flanterm_context *flanterm_fb_init( struct flanterm_context *flanterm_fb_init(
/* If _malloc and _free are nulled, use the bump allocated instance (1 use only). */ /* If _malloc and _free are nulled, use the bump allocated instance (1 use
only). */
void *(*_malloc)(size_t size), void *(*_malloc)(size_t size),
void (*_free)(void *ptr, size_t size), void (*_free)(void *ptr, size_t size), uint32_t *framebuffer, size_t width,
uint32_t *framebuffer, size_t width, size_t height, size_t pitch, size_t height, size_t pitch, uint8_t red_mask_size, uint8_t red_mask_shift,
uint8_t red_mask_size, uint8_t red_mask_shift, uint8_t green_mask_size, uint8_t green_mask_shift, uint8_t blue_mask_size,
uint8_t green_mask_size, uint8_t green_mask_shift, uint8_t blue_mask_shift, uint32_t *canvas, /* If nulled, no canvas. */
uint8_t blue_mask_size, uint8_t blue_mask_shift, uint32_t *ansi_colours,
uint32_t *canvas, /* If nulled, no canvas. */ uint32_t *ansi_bright_colours, /* If nulled, default. */
uint32_t *ansi_colours, uint32_t *ansi_bright_colours, /* If nulled, default. */
uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */ uint32_t *default_bg, uint32_t *default_fg, /* If nulled, default. */
uint32_t *default_bg_bright, uint32_t *default_fg_bright, /* If nulled, default. */ uint32_t *default_bg_bright,
/* If font is null, use default font and font_width and font_height ignored. */ uint32_t *default_fg_bright, /* If nulled, default. */
/* If font is null, use default font and font_width and font_height ignored.
*/
void *font, size_t font_width, size_t font_height, size_t font_spacing, void *font, size_t font_width, size_t font_height, size_t font_spacing,
/* If scale_x and scale_y are 0, automatically scale font based on resolution. */ /* If scale_x and scale_y are 0, automatically scale font based on
size_t font_scale_x, size_t font_scale_y, resolution. */
size_t margin size_t font_scale_x, size_t font_scale_y, size_t margin);
);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -30,9 +30,9 @@
#error "Do not use fb_private.h. Use interfaces defined in fb.h only." #error "Do not use fb_private.h. Use interfaces defined in fb.h only."
#endif #endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -54,7 +54,8 @@ struct flanterm_fb_queue_item {
struct flanterm_fb_context { struct flanterm_fb_context {
struct flanterm_context term; struct flanterm_context term;
void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c, size_t x, size_t y); void (*plot_char)(struct flanterm_context *ctx, struct flanterm_fb_char *c,
size_t x, size_t y);
size_t font_width; size_t font_width;
size_t font_height; size_t font_height;

View file

@ -24,16 +24,17 @@
*/ */
#ifdef __cplusplus #ifdef __cplusplus
#error "Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer." #error \
"Please do not compile Flanterm as C++ code! Flanterm should be compiled as C99 or newer."
#endif #endif
#ifndef __STDC_VERSION__ #ifndef __STDC_VERSION__
#error "Flanterm must be compiled as C99 or newer." #error "Flanterm must be compiled as C99 or newer."
#endif #endif
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#define FLANTERM_IN_FLANTERM #define FLANTERM_IN_FLANTERM
@ -43,37 +44,41 @@
// https://man7.org/linux/man-pages/man4/console_codes.4.html // https://man7.org/linux/man-pages/man4/console_codes.4.html
static const uint32_t col256[] = { static const uint32_t col256[] = {
0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00, 0x005f5f, 0x000000, 0x00005f, 0x000087, 0x0000af, 0x0000d7, 0x0000ff, 0x005f00,
0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f, 0x008787, 0x0087af, 0x005f5f, 0x005f87, 0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f,
0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff, 0x008787, 0x0087af, 0x0087d7, 0x0087ff, 0x00af00, 0x00af5f, 0x00af87,
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f, 0x00afaf, 0x00afd7, 0x00afff, 0x00d700, 0x00d75f, 0x00d787, 0x00d7af,
0x00ff87, 0x00ffaf, 0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af, 0x00d7d7, 0x00d7ff, 0x00ff00, 0x00ff5f, 0x00ff87, 0x00ffaf, 0x00ffd7,
0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f, 0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087, 0x5f00af, 0x5f00d7, 0x5f00ff,
0x5f8700, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff, 0x5faf00, 0x5faf5f, 0x5f5f00, 0x5f5f5f, 0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff, 0x5f8700,
0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af, 0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff, 0x5faf00, 0x5faf5f,
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf, 0x5fffd7, 0x5fffff, 0x5faf87, 0x5fafaf, 0x5fafd7, 0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787,
0x870000, 0x87005f, 0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00, 0x875f5f, 0x5fd7af, 0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87, 0x5fffaf,
0x875f87, 0x875faf, 0x875fd7, 0x875fff, 0x878700, 0x87875f, 0x878787, 0x8787af, 0x5fffd7, 0x5fffff, 0x870000, 0x87005f, 0x870087, 0x8700af, 0x8700d7,
0x8787d7, 0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf, 0x87afd7, 0x87afff, 0x8700ff, 0x875f00, 0x875f5f, 0x875f87, 0x875faf, 0x875fd7, 0x875fff,
0x87d700, 0x87d75f, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f, 0x878700, 0x87875f, 0x878787, 0x8787af, 0x8787d7, 0x8787ff, 0x87af00,
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af, 0x87af5f, 0x87af87, 0x87afaf, 0x87afd7, 0x87afff, 0x87d700, 0x87d75f,
0xaf00d7, 0xaf00ff, 0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7, 0xaf5fff, 0x87d787, 0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f, 0x87ff87,
0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af, 0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000, 0xaf005f, 0xaf0087, 0xaf00af,
0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f, 0xafd787, 0xafd7af, 0xaf00d7, 0xaf00ff, 0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7,
0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff, 0xaf5fff, 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af, 0xaf87d7, 0xaf87ff,
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f, 0xafaf00, 0xafaf5f, 0xafaf87, 0xafafaf, 0xafafd7, 0xafafff, 0xafd700,
0xd75f87, 0xd75faf, 0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af, 0xafd75f, 0xafd787, 0xafd7af, 0xafd7d7, 0xafd7ff, 0xafff00, 0xafff5f,
0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f, 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff, 0xd70000, 0xd7005f, 0xd70087,
0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, 0xd7ff00, 0xd7ff5f, 0xd700af, 0xd700d7, 0xd700ff, 0xd75f00, 0xd75f5f, 0xd75f87, 0xd75faf,
0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af, 0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787, 0xd787af, 0xd787d7,
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87, 0xff5faf, 0xff5fd7, 0xff5fff, 0xd787ff, 0xd7af00, 0xd7af5f, 0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff,
0xff8700, 0xff875f, 0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f, 0xd7d700, 0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff, 0xd7ff00,
0xffaf87, 0xffafaf, 0xffafd7, 0xffafff, 0xffd700, 0xffd75f, 0xffd787, 0xffd7af, 0xd7ff5f, 0xd7ff87, 0xd7ffaf, 0xd7ffd7, 0xd7ffff, 0xff0000, 0xff005f,
0xffd7d7, 0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff, 0xff0087, 0xff00af, 0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87,
0x080808, 0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e, 0xff5faf, 0xff5fd7, 0xff5fff, 0xff8700, 0xff875f, 0xff8787, 0xff87af,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494, 0x9e9e9e, 0xff87d7, 0xff87ff, 0xffaf00, 0xffaf5f, 0xffaf87, 0xffafaf, 0xffafd7,
0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4, 0xeeeeee 0xffafff, 0xffd700, 0xffd75f, 0xffd787, 0xffd7af, 0xffd7d7, 0xffd7ff,
}; 0xffff00, 0xffff5f, 0xffff87, 0xffffaf, 0xffffd7, 0xffffff, 0x080808,
0x121212, 0x1c1c1c, 0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080, 0x8a8a8a, 0x949494,
0x9e9e9e, 0xa8a8a8, 0xb2b2b2, 0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada,
0xe4e4e4, 0xeeeeee};
#define CHARSET_DEFAULT 0 #define CHARSET_DEFAULT 0
#define CHARSET_DEC_SPECIAL 1 #define CHARSET_DEC_SPECIAL 1
@ -112,7 +117,8 @@ void flanterm_context_reinit(struct flanterm_context *ctx) {
static void flanterm_putchar(struct flanterm_context *ctx, uint8_t c); static void flanterm_putchar(struct flanterm_context *ctx, uint8_t c);
void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count) { void flanterm_write(struct flanterm_context *ctx, const char *buf,
size_t count) {
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
flanterm_putchar(ctx, buf[i]); flanterm_putchar(ctx, buf[i]);
} }
@ -227,8 +233,8 @@ def:
} }
set_fg: set_fg:
if ((ctx->bold && !ctx->reverse_video) if ((ctx->bold && !ctx->reverse_video) ||
|| (ctx->bg_bold && ctx->reverse_video)) { (ctx->bg_bold && ctx->reverse_video)) {
ctx->set_text_fg_bright(ctx, ctx->esc_values[i] - offset); ctx->set_text_fg_bright(ctx, ctx->esc_values[i] - offset);
} else { } else {
ctx->set_text_fg(ctx, ctx->esc_values[i] - offset); ctx->set_text_fg(ctx, ctx->esc_values[i] - offset);
@ -245,8 +251,8 @@ set_fg:
} }
set_bg: set_bg:
if ((ctx->bold && ctx->reverse_video) if ((ctx->bold && ctx->reverse_video) ||
|| (ctx->bg_bold && !ctx->reverse_video)) { (ctx->bg_bold && !ctx->reverse_video)) {
ctx->set_text_bg_bright(ctx, ctx->esc_values[i] - offset); ctx->set_text_bg_bright(ctx, ctx->esc_values[i] - offset);
} else { } else {
ctx->set_text_bg(ctx, ctx->esc_values[i] - offset); ctx->set_text_bg(ctx, ctx->esc_values[i] - offset);
@ -375,7 +381,8 @@ set_bg_bright:
if (col < 8) { if (col < 8) {
(fg ? ctx->set_text_fg : ctx->set_text_bg)(ctx, col); (fg ? ctx->set_text_fg : ctx->set_text_bg)(ctx, col);
} else if (col < 16) { } else if (col < 16) {
(fg ? ctx->set_text_fg_bright : ctx->set_text_bg_bright)(ctx, col - 8); (fg ? ctx->set_text_fg_bright : ctx->set_text_bg_bright)(ctx,
col - 8);
} else if (col < 256) { } else if (col < 256) {
uint32_t rgb_value = col256[col - 16]; uint32_t rgb_value = col256[col - 16];
(fg ? ctx->set_text_fg_rgb : ctx->set_text_bg_rgb)(ctx, rgb_value); (fg ? ctx->set_text_fg_rgb : ctx->set_text_bg_rgb)(ctx, rgb_value);
@ -383,7 +390,8 @@ set_bg_bright:
break; break;
} }
default: continue; default:
continue;
} }
} }
} }
@ -402,9 +410,11 @@ static void dec_private_parse(struct flanterm_context *ctx, uint8_t c) {
switch (c) { switch (c) {
case 'h': case 'h':
set = true; break; set = true;
break;
case 'l': case 'l':
set = false; break; set = false;
break;
default: default:
return; return;
} }
@ -421,7 +431,8 @@ static void dec_private_parse(struct flanterm_context *ctx, uint8_t c) {
} }
if (ctx->callback != NULL) { if (ctx->callback != NULL) {
ctx->callback(ctx, FLANTERM_CB_DEC, ctx->esc_values_i, (uintptr_t)ctx->esc_values, c); ctx->callback(ctx, FLANTERM_CB_DEC, ctx->esc_values_i,
(uintptr_t)ctx->esc_values, c);
} }
} }
@ -431,7 +442,8 @@ static void linux_private_parse(struct flanterm_context *ctx) {
} }
if (ctx->callback != NULL) { if (ctx->callback != NULL) {
ctx->callback(ctx, FLANTERM_CB_LINUX, ctx->esc_values_i, (uintptr_t)ctx->esc_values, 0); ctx->callback(ctx, FLANTERM_CB_LINUX, ctx->esc_values_i,
(uintptr_t)ctx->esc_values, 0);
} }
} }
@ -444,20 +456,24 @@ static void mode_toggle(struct flanterm_context *ctx, uint8_t c) {
switch (c) { switch (c) {
case 'h': case 'h':
set = true; break; set = true;
break;
case 'l': case 'l':
set = false; break; set = false;
break;
default: default:
return; return;
} }
switch (ctx->esc_values[0]) { switch (ctx->esc_values[0]) {
case 4: case 4:
ctx->insert_mode = set; return; ctx->insert_mode = set;
return;
} }
if (ctx->callback != NULL) { if (ctx->callback != NULL) {
ctx->callback(ctx, FLANTERM_CB_MODE, ctx->esc_values_i, (uintptr_t)ctx->esc_values, c); ctx->callback(ctx, FLANTERM_CB_MODE, ctx->esc_values_i,
(uintptr_t)ctx->esc_values, c);
} }
} }
@ -521,10 +537,14 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
size_t esc_default; size_t esc_default;
switch (c) { switch (c) {
case 'J': case 'K': case 'q': case 'J':
esc_default = 0; break; case 'K':
case 'q':
esc_default = 0;
break;
default: default:
esc_default = 1; break; esc_default = 1;
break;
} }
for (size_t i = ctx->esc_values_i; i < FLANTERM_MAX_ESC_VALUES; i++) { for (size_t i = ctx->esc_values_i; i < FLANTERM_MAX_ESC_VALUES; i++) {
@ -551,8 +571,10 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
size_t orig_y = y; size_t orig_y = y;
size_t dest_y = y - ctx->esc_values[0]; size_t dest_y = y - ctx->esc_values[0];
bool will_be_in_scroll_region = false; bool will_be_in_scroll_region = false;
if ((ctx->scroll_top_margin >= dest_y && ctx->scroll_top_margin <= orig_y) if ((ctx->scroll_top_margin >= dest_y &&
|| (ctx->scroll_bottom_margin >= dest_y && ctx->scroll_bottom_margin <= orig_y)) { ctx->scroll_top_margin <= orig_y) ||
(ctx->scroll_bottom_margin >= dest_y &&
ctx->scroll_bottom_margin <= orig_y)) {
will_be_in_scroll_region = true; will_be_in_scroll_region = true;
} }
if (will_be_in_scroll_region && dest_y < ctx->scroll_top_margin) { if (will_be_in_scroll_region && dest_y < ctx->scroll_top_margin) {
@ -571,8 +593,10 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
size_t orig_y = y; size_t orig_y = y;
size_t dest_y = y + ctx->esc_values[0]; size_t dest_y = y + ctx->esc_values[0];
bool will_be_in_scroll_region = false; bool will_be_in_scroll_region = false;
if ((ctx->scroll_top_margin >= orig_y && ctx->scroll_top_margin <= dest_y) if ((ctx->scroll_top_margin >= orig_y &&
|| (ctx->scroll_bottom_margin >= orig_y && ctx->scroll_bottom_margin <= dest_y)) { ctx->scroll_top_margin <= dest_y) ||
(ctx->scroll_bottom_margin >= orig_y &&
ctx->scroll_bottom_margin <= dest_y)) {
will_be_in_scroll_region = true; will_be_in_scroll_region = true;
} }
if (will_be_in_scroll_region && dest_y >= ctx->scroll_bottom_margin) { if (will_be_in_scroll_region && dest_y >= ctx->scroll_bottom_margin) {
@ -625,7 +649,8 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
ctx->set_cursor_pos(ctx, ctx->esc_values[1], ctx->esc_values[0]); ctx->set_cursor_pos(ctx, ctx->esc_values[1], ctx->esc_values[0]);
break; break;
case 'M': { case 'M': {
size_t count = ctx->esc_values[0] > ctx->rows ? ctx->rows : ctx->esc_values[0]; size_t count =
ctx->esc_values[0] > ctx->rows ? ctx->rows : ctx->esc_values[0];
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
ctx->scroll(ctx); ctx->scroll(ctx);
} }
@ -634,7 +659,8 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
case 'L': { case 'L': {
size_t old_scroll_top_margin = ctx->scroll_top_margin; size_t old_scroll_top_margin = ctx->scroll_top_margin;
ctx->scroll_top_margin = y; ctx->scroll_top_margin = y;
size_t count = ctx->esc_values[0] > ctx->rows ? ctx->rows : ctx->esc_values[0]; size_t count =
ctx->esc_values[0] > ctx->rows ? ctx->rows : ctx->esc_values[0];
for (size_t i = 0; i < count; i++) { for (size_t i = 0; i < count; i++) {
ctx->revscroll(ctx); ctx->revscroll(ctx);
} }
@ -712,7 +738,8 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
ctx->set_cursor_pos(ctx, ctx->cols - ctx->esc_values[0], y); ctx->set_cursor_pos(ctx, ctx->cols - ctx->esc_values[0], y);
// FALLTHRU // FALLTHRU
case 'X': { case 'X': {
size_t count = ctx->esc_values[0] > ctx->cols ? ctx->cols : ctx->esc_values[0]; size_t count =
ctx->esc_values[0] > ctx->cols ? ctx->cols : ctx->esc_values[0];
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
ctx->raw_putchar(ctx, ' '); ctx->raw_putchar(ctx, ' ');
ctx->set_cursor_pos(ctx, x, y); ctx->set_cursor_pos(ctx, x, y);
@ -765,9 +792,9 @@ static void control_sequence_parse(struct flanterm_context *ctx, uint8_t c) {
if (ctx->esc_values_i > 1) { if (ctx->esc_values_i > 1) {
ctx->scroll_bottom_margin = ctx->esc_values[1]; ctx->scroll_bottom_margin = ctx->esc_values[1];
} }
if (ctx->scroll_top_margin >= ctx->rows if (ctx->scroll_top_margin >= ctx->rows ||
|| ctx->scroll_bottom_margin > ctx->rows ctx->scroll_bottom_margin > ctx->rows ||
|| ctx->scroll_top_margin >= (ctx->scroll_bottom_margin - 1)) { ctx->scroll_top_margin >= (ctx->scroll_bottom_margin - 1)) {
ctx->scroll_top_margin = 0; ctx->scroll_top_margin = 0;
ctx->scroll_bottom_margin = ctx->rows; ctx->scroll_bottom_margin = ctx->rows;
} }
@ -889,36 +916,66 @@ static void escape_parse(struct flanterm_context *ctx, uint8_t c) {
} }
static bool dec_special_print(struct flanterm_context *ctx, uint8_t c) { static bool dec_special_print(struct flanterm_context *ctx, uint8_t c) {
#define FLANTERM_DEC_SPCL_PRN(C) ctx->raw_putchar(ctx, (C)); return true; #define FLANTERM_DEC_SPCL_PRN(C) \
ctx->raw_putchar(ctx, (C)); \
return true;
switch (c) { switch (c) {
case '`': FLANTERM_DEC_SPCL_PRN(0x04) case '`':
case '0': FLANTERM_DEC_SPCL_PRN(0xdb) FLANTERM_DEC_SPCL_PRN(0x04)
case '-': FLANTERM_DEC_SPCL_PRN(0x18) case '0':
case ',': FLANTERM_DEC_SPCL_PRN(0x1b) FLANTERM_DEC_SPCL_PRN(0xdb)
case '.': FLANTERM_DEC_SPCL_PRN(0x19) case '-':
case 'a': FLANTERM_DEC_SPCL_PRN(0xb1) FLANTERM_DEC_SPCL_PRN(0x18)
case 'f': FLANTERM_DEC_SPCL_PRN(0xf8) case ',':
case 'g': FLANTERM_DEC_SPCL_PRN(0xf1) FLANTERM_DEC_SPCL_PRN(0x1b)
case 'h': FLANTERM_DEC_SPCL_PRN(0xb0) case '.':
case 'j': FLANTERM_DEC_SPCL_PRN(0xd9) FLANTERM_DEC_SPCL_PRN(0x19)
case 'k': FLANTERM_DEC_SPCL_PRN(0xbf) case 'a':
case 'l': FLANTERM_DEC_SPCL_PRN(0xda) FLANTERM_DEC_SPCL_PRN(0xb1)
case 'm': FLANTERM_DEC_SPCL_PRN(0xc0) case 'f':
case 'n': FLANTERM_DEC_SPCL_PRN(0xc5) FLANTERM_DEC_SPCL_PRN(0xf8)
case 'q': FLANTERM_DEC_SPCL_PRN(0xc4) case 'g':
case 's': FLANTERM_DEC_SPCL_PRN(0x5f) FLANTERM_DEC_SPCL_PRN(0xf1)
case 't': FLANTERM_DEC_SPCL_PRN(0xc3) case 'h':
case 'u': FLANTERM_DEC_SPCL_PRN(0xb4) FLANTERM_DEC_SPCL_PRN(0xb0)
case 'v': FLANTERM_DEC_SPCL_PRN(0xc1) case 'j':
case 'w': FLANTERM_DEC_SPCL_PRN(0xc2) FLANTERM_DEC_SPCL_PRN(0xd9)
case 'x': FLANTERM_DEC_SPCL_PRN(0xb3) case 'k':
case 'y': FLANTERM_DEC_SPCL_PRN(0xf3) FLANTERM_DEC_SPCL_PRN(0xbf)
case 'z': FLANTERM_DEC_SPCL_PRN(0xf2) case 'l':
case '~': FLANTERM_DEC_SPCL_PRN(0xfa) FLANTERM_DEC_SPCL_PRN(0xda)
case '_': FLANTERM_DEC_SPCL_PRN(0xff) case 'm':
case '+': FLANTERM_DEC_SPCL_PRN(0x1a) FLANTERM_DEC_SPCL_PRN(0xc0)
case '{': FLANTERM_DEC_SPCL_PRN(0xe3) case 'n':
case '}': FLANTERM_DEC_SPCL_PRN(0x9c) FLANTERM_DEC_SPCL_PRN(0xc5)
case 'q':
FLANTERM_DEC_SPCL_PRN(0xc4)
case 's':
FLANTERM_DEC_SPCL_PRN(0x5f)
case 't':
FLANTERM_DEC_SPCL_PRN(0xc3)
case 'u':
FLANTERM_DEC_SPCL_PRN(0xb4)
case 'v':
FLANTERM_DEC_SPCL_PRN(0xc1)
case 'w':
FLANTERM_DEC_SPCL_PRN(0xc2)
case 'x':
FLANTERM_DEC_SPCL_PRN(0xb3)
case 'y':
FLANTERM_DEC_SPCL_PRN(0xf3)
case 'z':
FLANTERM_DEC_SPCL_PRN(0xf2)
case '~':
FLANTERM_DEC_SPCL_PRN(0xfa)
case '_':
FLANTERM_DEC_SPCL_PRN(0xff)
case '+':
FLANTERM_DEC_SPCL_PRN(0x1a)
case '{':
FLANTERM_DEC_SPCL_PRN(0xe3)
case '}':
FLANTERM_DEC_SPCL_PRN(0x9c)
} }
#undef FLANTERM_DEC_SPCL_PRN #undef FLANTERM_DEC_SPCL_PRN
@ -1004,8 +1061,7 @@ int mk_wcwidth(uint32_t ucs) {
{0x10A38, 0x10A3A}, {0x10A3F, 0x10A3F}, {0x1D167, 0x1D169}, {0x10A38, 0x10A3A}, {0x10A3F, 0x10A3F}, {0x1D167, 0x1D169},
{0x1D173, 0x1D182}, {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD}, {0x1D173, 0x1D182}, {0x1D185, 0x1D18B}, {0x1D1AA, 0x1D1AD},
{0x1D242, 0x1D244}, {0xE0001, 0xE0001}, {0xE0020, 0xE007F}, {0x1D242, 0x1D244}, {0xE0001, 0xE0001}, {0xE0020, 0xE007F},
{ 0xE0100, 0xE01EF } {0xE0100, 0xE01EF}};
};
/* test for 8-bit control characters */ /* test for 8-bit control characters */
if (ucs == 0) if (ucs == 0)
@ -1014,8 +1070,7 @@ int mk_wcwidth(uint32_t ucs) {
return 1; return 1;
/* binary search in table of non-spacing characters */ /* binary search in table of non-spacing characters */
if (bisearch(ucs, combining, if (bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1))
sizeof(combining) / sizeof(struct interval) - 1))
return 0; return 0;
/* if we arrive here, ucs is not a combining or C0/C1 control character */ /* if we arrive here, ucs is not a combining or C0/C1 control character */
@ -1024,10 +1079,10 @@ int mk_wcwidth(uint32_t ucs) {
(ucs >= 0x1100 && (ucs >= 0x1100 &&
(ucs <= 0x115f || /* Hangul Jamo init. consonants */ (ucs <= 0x115f || /* Hangul Jamo init. consonants */
ucs == 0x2329 || ucs == 0x232a || ucs == 0x2329 || ucs == 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf && (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || /* CJK ... Yi */
ucs != 0x303f) || /* CJK ... Yi */
(ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
(ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ (ucs >= 0xf900 &&
ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
(ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
(ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
@ -1040,166 +1095,325 @@ int mk_wcwidth(uint32_t ucs) {
static int unicode_to_cp437(uint64_t code_point) { static int unicode_to_cp437(uint64_t code_point) {
switch (code_point) { switch (code_point) {
case 0x263a: return 1; case 0x263a:
case 0x263b: return 2; return 1;
case 0x2665: return 3; case 0x263b:
case 0x2666: return 4; return 2;
case 0x2663: return 5; case 0x2665:
case 0x2660: return 6; return 3;
case 0x2022: return 7; case 0x2666:
case 0x25d8: return 8; return 4;
case 0x25cb: return 9; case 0x2663:
case 0x25d9: return 10; return 5;
case 0x2642: return 11; case 0x2660:
case 0x2640: return 12; return 6;
case 0x266a: return 13; case 0x2022:
case 0x266b: return 14; return 7;
case 0x263c: return 15; case 0x25d8:
case 0x25ba: return 16; return 8;
case 0x25c4: return 17; case 0x25cb:
case 0x2195: return 18; return 9;
case 0x203c: return 19; case 0x25d9:
case 0x00b6: return 20; return 10;
case 0x00a7: return 21; case 0x2642:
case 0x25ac: return 22; return 11;
case 0x21a8: return 23; case 0x2640:
case 0x2191: return 24; return 12;
case 0x2193: return 25; case 0x266a:
case 0x2192: return 26; return 13;
case 0x2190: return 27; case 0x266b:
case 0x221f: return 28; return 14;
case 0x2194: return 29; case 0x263c:
case 0x25b2: return 30; return 15;
case 0x25bc: return 31; case 0x25ba:
return 16;
case 0x25c4:
return 17;
case 0x2195:
return 18;
case 0x203c:
return 19;
case 0x00b6:
return 20;
case 0x00a7:
return 21;
case 0x25ac:
return 22;
case 0x21a8:
return 23;
case 0x2191:
return 24;
case 0x2193:
return 25;
case 0x2192:
return 26;
case 0x2190:
return 27;
case 0x221f:
return 28;
case 0x2194:
return 29;
case 0x25b2:
return 30;
case 0x25bc:
return 31;
case 0x2302: return 127; case 0x2302:
case 0x00c7: return 128; return 127;
case 0x00fc: return 129; case 0x00c7:
case 0x00e9: return 130; return 128;
case 0x00e2: return 131; case 0x00fc:
case 0x00e4: return 132; return 129;
case 0x00e0: return 133; case 0x00e9:
case 0x00e5: return 134; return 130;
case 0x00e7: return 135; case 0x00e2:
case 0x00ea: return 136; return 131;
case 0x00eb: return 137; case 0x00e4:
case 0x00e8: return 138; return 132;
case 0x00ef: return 139; case 0x00e0:
case 0x00ee: return 140; return 133;
case 0x00ec: return 141; case 0x00e5:
case 0x00c4: return 142; return 134;
case 0x00c5: return 143; case 0x00e7:
case 0x00c9: return 144; return 135;
case 0x00e6: return 145; case 0x00ea:
case 0x00c6: return 146; return 136;
case 0x00f4: return 147; case 0x00eb:
case 0x00f6: return 148; return 137;
case 0x00f2: return 149; case 0x00e8:
case 0x00fb: return 150; return 138;
case 0x00f9: return 151; case 0x00ef:
case 0x00ff: return 152; return 139;
case 0x00d6: return 153; case 0x00ee:
case 0x00dc: return 154; return 140;
case 0x00a2: return 155; case 0x00ec:
case 0x00a3: return 156; return 141;
case 0x00a5: return 157; case 0x00c4:
case 0x20a7: return 158; return 142;
case 0x0192: return 159; case 0x00c5:
case 0x00e1: return 160; return 143;
case 0x00ed: return 161; case 0x00c9:
case 0x00f3: return 162; return 144;
case 0x00fa: return 163; case 0x00e6:
case 0x00f1: return 164; return 145;
case 0x00d1: return 165; case 0x00c6:
case 0x00aa: return 166; return 146;
case 0x00ba: return 167; case 0x00f4:
case 0x00bf: return 168; return 147;
case 0x2310: return 169; case 0x00f6:
case 0x00ac: return 170; return 148;
case 0x00bd: return 171; case 0x00f2:
case 0x00bc: return 172; return 149;
case 0x00a1: return 173; case 0x00fb:
case 0x00ab: return 174; return 150;
case 0x00bb: return 175; case 0x00f9:
case 0x2591: return 176; return 151;
case 0x2592: return 177; case 0x00ff:
case 0x2593: return 178; return 152;
case 0x2502: return 179; case 0x00d6:
case 0x2524: return 180; return 153;
case 0x2561: return 181; case 0x00dc:
case 0x2562: return 182; return 154;
case 0x2556: return 183; case 0x00a2:
case 0x2555: return 184; return 155;
case 0x2563: return 185; case 0x00a3:
case 0x2551: return 186; return 156;
case 0x2557: return 187; case 0x00a5:
case 0x255d: return 188; return 157;
case 0x255c: return 189; case 0x20a7:
case 0x255b: return 190; return 158;
case 0x2510: return 191; case 0x0192:
case 0x2514: return 192; return 159;
case 0x2534: return 193; case 0x00e1:
case 0x252c: return 194; return 160;
case 0x251c: return 195; case 0x00ed:
case 0x2500: return 196; return 161;
case 0x253c: return 197; case 0x00f3:
case 0x255e: return 198; return 162;
case 0x255f: return 199; case 0x00fa:
case 0x255a: return 200; return 163;
case 0x2554: return 201; case 0x00f1:
case 0x2569: return 202; return 164;
case 0x2566: return 203; case 0x00d1:
case 0x2560: return 204; return 165;
case 0x2550: return 205; case 0x00aa:
case 0x256c: return 206; return 166;
case 0x2567: return 207; case 0x00ba:
case 0x2568: return 208; return 167;
case 0x2564: return 209; case 0x00bf:
case 0x2565: return 210; return 168;
case 0x2559: return 211; case 0x2310:
case 0x2558: return 212; return 169;
case 0x2552: return 213; case 0x00ac:
case 0x2553: return 214; return 170;
case 0x256b: return 215; case 0x00bd:
case 0x256a: return 216; return 171;
case 0x2518: return 217; case 0x00bc:
case 0x250c: return 218; return 172;
case 0x2588: return 219; case 0x00a1:
case 0x2584: return 220; return 173;
case 0x258c: return 221; case 0x00ab:
case 0x2590: return 222; return 174;
case 0x2580: return 223; case 0x00bb:
case 0x03b1: return 224; return 175;
case 0x00df: return 225; case 0x2591:
case 0x0393: return 226; return 176;
case 0x03c0: return 227; case 0x2592:
case 0x03a3: return 228; return 177;
case 0x03c3: return 229; case 0x2593:
case 0x00b5: return 230; return 178;
case 0x03c4: return 231; case 0x2502:
case 0x03a6: return 232; return 179;
case 0x0398: return 233; case 0x2524:
case 0x03a9: return 234; return 180;
case 0x03b4: return 235; case 0x2561:
case 0x221e: return 236; return 181;
case 0x03c6: return 237; case 0x2562:
case 0x03b5: return 238; return 182;
case 0x2229: return 239; case 0x2556:
case 0x2261: return 240; return 183;
case 0x00b1: return 241; case 0x2555:
case 0x2265: return 242; return 184;
case 0x2264: return 243; case 0x2563:
case 0x2320: return 244; return 185;
case 0x2321: return 245; case 0x2551:
case 0x00f7: return 246; return 186;
case 0x2248: return 247; case 0x2557:
case 0x00b0: return 248; return 187;
case 0x2219: return 249; case 0x255d:
case 0x00b7: return 250; return 188;
case 0x221a: return 251; case 0x255c:
case 0x207f: return 252; return 189;
case 0x00b2: return 253; case 0x255b:
case 0x25a0: return 254; return 190;
case 0x2510:
return 191;
case 0x2514:
return 192;
case 0x2534:
return 193;
case 0x252c:
return 194;
case 0x251c:
return 195;
case 0x2500:
return 196;
case 0x253c:
return 197;
case 0x255e:
return 198;
case 0x255f:
return 199;
case 0x255a:
return 200;
case 0x2554:
return 201;
case 0x2569:
return 202;
case 0x2566:
return 203;
case 0x2560:
return 204;
case 0x2550:
return 205;
case 0x256c:
return 206;
case 0x2567:
return 207;
case 0x2568:
return 208;
case 0x2564:
return 209;
case 0x2565:
return 210;
case 0x2559:
return 211;
case 0x2558:
return 212;
case 0x2552:
return 213;
case 0x2553:
return 214;
case 0x256b:
return 215;
case 0x256a:
return 216;
case 0x2518:
return 217;
case 0x250c:
return 218;
case 0x2588:
return 219;
case 0x2584:
return 220;
case 0x258c:
return 221;
case 0x2590:
return 222;
case 0x2580:
return 223;
case 0x03b1:
return 224;
case 0x00df:
return 225;
case 0x0393:
return 226;
case 0x03c0:
return 227;
case 0x03a3:
return 228;
case 0x03c3:
return 229;
case 0x00b5:
return 230;
case 0x03c4:
return 231;
case 0x03a6:
return 232;
case 0x0398:
return 233;
case 0x03a9:
return 234;
case 0x03b4:
return 235;
case 0x221e:
return 236;
case 0x03c6:
return 237;
case 0x03b5:
return 238;
case 0x2229:
return 239;
case 0x2261:
return 240;
case 0x00b1:
return 241;
case 0x2265:
return 242;
case 0x2264:
return 243;
case 0x2320:
return 244;
case 0x2321:
return 245;
case 0x00f7:
return 246;
case 0x2248:
return 247;
case 0x00b0:
return 248;
case 0x2219:
return 249;
case 0x00b7:
return 250;
case 0x221a:
return 251;
case 0x207f:
return 252;
case 0x00b2:
return 253;
case 0x25a0:
return 254;
} }
return -1; return -1;
@ -1269,9 +1483,11 @@ unicode_error:
ctx->g_select--; ctx->g_select--;
switch (c) { switch (c) {
case 'B': case 'B':
ctx->charsets[ctx->g_select] = CHARSET_DEFAULT; break; ctx->charsets[ctx->g_select] = CHARSET_DEFAULT;
break;
case '0': case '0':
ctx->charsets[ctx->g_select] = CHARSET_DEC_SPECIAL; break; ctx->charsets[ctx->g_select] = CHARSET_DEC_SPECIAL;
break;
} }
ctx->g_select = 0; ctx->g_select = 0;
return; return;
@ -1300,9 +1516,11 @@ unicode_error:
case '\n': case '\n':
if (y == ctx->scroll_bottom_margin - 1) { if (y == ctx->scroll_bottom_margin - 1) {
ctx->scroll(ctx); ctx->scroll(ctx);
ctx->set_cursor_pos(ctx, (ctx->oob_output & FLANTERM_OOB_OUTPUT_ONLCR) ? 0 : x, y); ctx->set_cursor_pos(
ctx, (ctx->oob_output & FLANTERM_OOB_OUTPUT_ONLCR) ? 0 : x, y);
} else { } else {
ctx->set_cursor_pos(ctx, (ctx->oob_output & FLANTERM_OOB_OUTPUT_ONLCR) ? 0 : x, y + 1); ctx->set_cursor_pos(
ctx, (ctx->oob_output & FLANTERM_OOB_OUTPUT_ONLCR) ? 0 : x, y + 1);
} }
return; return;
case '\b': case '\b':
@ -1362,11 +1580,13 @@ void flanterm_full_refresh(struct flanterm_context *ctx) {
ctx->full_refresh(ctx); ctx->full_refresh(ctx);
} }
void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *, size_t)) { void flanterm_deinit(struct flanterm_context *ctx,
void (*_free)(void *, size_t)) {
ctx->deinit(ctx, _free); ctx->deinit(ctx, _free);
} }
void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows) { void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols,
size_t *rows) {
*cols = ctx->cols; *cols = ctx->cols;
*rows = ctx->rows; *rows = ctx->rows;
} }
@ -1375,7 +1595,9 @@ void flanterm_set_autoflush(struct flanterm_context *ctx, bool state) {
ctx->autoflush = state; ctx->autoflush = state;
} }
void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t)) { void flanterm_set_callback(struct flanterm_context *ctx,
void (*callback)(struct flanterm_context *, uint64_t,
uint64_t, uint64_t, uint64_t)) {
ctx->callback = callback; ctx->callback = callback;
} }
@ -1383,6 +1605,7 @@ uint64_t flanterm_get_oob_output(struct flanterm_context *ctx) {
return ctx->oob_output; return ctx->oob_output;
} }
void flanterm_set_oob_output(struct flanterm_context *ctx, uint64_t oob_output) { void flanterm_set_oob_output(struct flanterm_context *ctx,
uint64_t oob_output) {
ctx->oob_output = oob_output; ctx->oob_output = oob_output;
} }

View file

@ -26,9 +26,9 @@
#ifndef FLANTERM_H #ifndef FLANTERM_H
#define FLANTERM_H 1 #define FLANTERM_H 1
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -62,14 +62,19 @@ struct flanterm_context;
#endif #endif
void flanterm_write(struct flanterm_context *ctx, const char *buf, size_t count); void flanterm_write(struct flanterm_context *ctx, const char *buf,
size_t count);
void flanterm_flush(struct flanterm_context *ctx); void flanterm_flush(struct flanterm_context *ctx);
void flanterm_full_refresh(struct flanterm_context *ctx); void flanterm_full_refresh(struct flanterm_context *ctx);
void flanterm_deinit(struct flanterm_context *ctx, void (*_free)(void *ptr, size_t size)); void flanterm_deinit(struct flanterm_context *ctx,
void (*_free)(void *ptr, size_t size));
void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols, size_t *rows); void flanterm_get_dimensions(struct flanterm_context *ctx, size_t *cols,
size_t *rows);
void flanterm_set_autoflush(struct flanterm_context *ctx, bool state); void flanterm_set_autoflush(struct flanterm_context *ctx, bool state);
void flanterm_set_callback(struct flanterm_context *ctx, void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t)); void flanterm_set_callback(struct flanterm_context *ctx,
void (*callback)(struct flanterm_context *, uint64_t,
uint64_t, uint64_t, uint64_t));
uint64_t flanterm_get_oob_output(struct flanterm_context *ctx); uint64_t flanterm_get_oob_output(struct flanterm_context *ctx);
void flanterm_set_oob_output(struct flanterm_context *ctx, uint64_t oob_output); void flanterm_set_oob_output(struct flanterm_context *ctx, uint64_t oob_output);

View file

@ -27,12 +27,13 @@
#define FLANTERM_PRIVATE_H 1 #define FLANTERM_PRIVATE_H 1
#ifndef FLANTERM_IN_FLANTERM #ifndef FLANTERM_IN_FLANTERM
#error "Do not use flanterm_private.h. Use interfaces defined in flanterm.h only." #error \
"Do not use flanterm_private.h. Use interfaces defined in flanterm.h only."
#endif #endif
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -98,7 +99,8 @@ struct flanterm_context {
void (*set_text_bg_default)(struct flanterm_context *); void (*set_text_bg_default)(struct flanterm_context *);
void (*set_text_fg_default_bright)(struct flanterm_context *); void (*set_text_fg_default_bright)(struct flanterm_context *);
void (*set_text_bg_default_bright)(struct flanterm_context *); void (*set_text_bg_default_bright)(struct flanterm_context *);
void (*move_character)(struct flanterm_context *, size_t new_x, size_t new_y, size_t old_x, size_t old_y); void (*move_character)(struct flanterm_context *, size_t new_x, size_t new_y,
size_t old_x, size_t old_y);
void (*scroll)(struct flanterm_context *); void (*scroll)(struct flanterm_context *);
void (*revscroll)(struct flanterm_context *); void (*revscroll)(struct flanterm_context *);
void (*swap_palette)(struct flanterm_context *); void (*swap_palette)(struct flanterm_context *);
@ -110,7 +112,8 @@ struct flanterm_context {
/* to be set by client */ /* to be set by client */
void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t, uint64_t); void (*callback)(struct flanterm_context *, uint64_t, uint64_t, uint64_t,
uint64_t);
}; };
void flanterm_context_reinit(struct flanterm_context *ctx); void flanterm_context_reinit(struct flanterm_context *ctx);

15
kernel/src/sys/log.c Executable file → Normal file
View file

@ -1,8 +1,8 @@
#include "sys/arch/x86_64/io.h" #include "sys/arch/x86_64/io.h"
#include "sys/gfx/flanterm/flanterm.h" #include "sys/gfx/flanterm/flanterm.h"
#include <lib/spinlock.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/printf.h> #include <sys/printf.h>
#include <lib/spinlock.h>
extern struct flanterm_context *ft_ctx; extern struct flanterm_context *ft_ctx;
@ -11,9 +11,13 @@ static spinlock_t log_lock = {0};
void log(char *format, ...) { void log(char *format, ...) {
// spinlock_acquire(&log_lock); // spinlock_acquire(&log_lock);
// TODO: replace this call with a call to printf() when the RTC is implemented. // TODO: replace this call with a call to printf() when the RTC is
// implemented.
char *date = "1970-01-01 00:00:00 | "; char *date = "1970-01-01 00:00:00 | ";
int i2 = 0; for (i2; date[i2] != 0; i2++);; int i2 = 0;
for (i2; date[i2] != 0; i2++)
;
;
if (ft_ctx) if (ft_ctx)
flanterm_write(ft_ctx, date, i2); flanterm_write(ft_ctx, date, i2);
@ -23,7 +27,10 @@ void log(char *format, ...) {
npf_vsnprintf(buf, 2048, format, l); npf_vsnprintf(buf, 2048, format, l);
va_end(l); va_end(l);
int i = 0; for (i; buf[i] != 0; i++);; int i = 0;
for (i; buf[i] != 0; i++)
;
;
if (ft_ctx) if (ft_ctx)
flanterm_write(ft_ctx, buf, i); flanterm_write(ft_ctx, buf, i);

5
kernel/src/sys/printf.c Executable file → Normal file
View file

@ -25,7 +25,10 @@ void printf(char *format, ...) {
va_end(lst); va_end(lst);
// rt_print(buf); // rt_print(buf);
int i = 0; for (i; buf[i] != 0; i++);; int i = 0;
for (i; buf[i] != 0; i++)
;
;
if (ft_ctx) if (ft_ctx)
flanterm_write(ft_ctx, buf, i); flanterm_write(ft_ctx, buf, i);

View file

@ -1,6 +1,6 @@
#include "sched/sched.h" #include "sched/sched.h"
#include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <sys/log.h> #include <sys/log.h>
#include <sys/syscall.h> #include <sys/syscall.h>
@ -13,7 +13,8 @@ static uint64_t __syscall_undefined() { return 0; }
void syscall_handle(registers_t *regs) { void syscall_handle(registers_t *regs) {
if (regs->rax > 1024) { if (regs->rax > 1024) {
log("syscall - syscall_handle was called with rax better than what Soaplin supports (1024). did you forget to set rax?\n"); log("syscall - syscall_handle was called with rax better than what Soaplin "
"supports (1024). did you forget to set rax?\n");
return; return;
} }
@ -23,18 +24,21 @@ void syscall_handle(registers_t *regs) {
} }
if (syscall_table[regs->rax] == (syscall)__syscall_undefined) { if (syscall_table[regs->rax] == (syscall)__syscall_undefined) {
log("syscall - syscall_handle was called with an undefined system call. (%d)\n", regs->rax); log("syscall - syscall_handle was called with an undefined system call. "
"(%d)\n",
regs->rax);
return; return;
} }
regs->rax = syscall_table[regs->rax](regs->rdi, regs->rsi, regs->rdx, regs->rcx, regs->r8, regs->r9); regs->rax = syscall_table[regs->rax](regs->rdi, regs->rsi, regs->rdx,
regs->rcx, regs->r8, regs->r9);
return; return;
} }
void syscall_register(int id, syscall handler) { void syscall_register(int id, syscall handler) {
if (syscall_table[id] != (syscall)__syscall_undefined) if (syscall_table[id] != (syscall)__syscall_undefined) {
{ log("syscall - warning: syscall_register has been called to try replacing "
log("syscall - warning: syscall_register has been called to try replacing an existing syscall.\n"); "an existing syscall.\n");
return; return;
} }

View file

@ -4,8 +4,10 @@
#include <stdint.h> #include <stdint.h>
/// A function that defines a system call. /// A function that defines a system call.
/// NOTE: Arguments are defined as uint64_t, but you can simply put your own type, and then cast your function to syscall. /// NOTE: Arguments are defined as uint64_t, but you can simply put your own
typedef uint64_t(*syscall)(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx, uint64_t r8, uint64_t r9); /// type, and then cast your function to syscall.
typedef uint64_t (*syscall)(uint64_t rdi, uint64_t rsi, uint64_t rdx,
uint64_t rcx, uint64_t r8, uint64_t r9);
/// Registers a system call. /// Registers a system call.
/// NOTE: an existing system call cannot be replaced by another. /// NOTE: an existing system call cannot be replaced by another.