forked from xamidev/pepperOS
remove old term support + PSFv1 font
This commit is contained in:
3
Makefile
3
Makefile
@@ -1,11 +1,10 @@
|
|||||||
SOURCES = src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c
|
SOURCES = src/debug/misc.c src/io/term/flanterm_backends/fb.c src/io/term/flanterm.c src/debug/panic.c src/debug/stacktrace.c src/boot/boot.c src/sched/scheduler.c src/sched/process.c src/mem/heap/kheap.c src/mem/paging/vmm.c src/mem/paging/paging.c src/mem/paging/pmm.c src/string/string.c src/io/kbd/ps2.c src/io/serial/serial.c src/io/term/printf.c src/io/term/term.c src/idt/idt.c src/mem/gdt/gdt.c src/mem/misc/utils.c src/time/timer.c src/kmain.c
|
||||||
|
|
||||||
PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable
|
PROBLEMATIC_FLAGS=-Wno-unused-parameter -Wno-unused-variable
|
||||||
|
|
||||||
build:
|
build:
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(PROBLEMATIC_FLAGS) -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel
|
x86_64-elf-gcc -g -c -Isrc $(SOURCES) $(PROBLEMATIC_FLAGS) -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-omit-frame-pointer -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel
|
||||||
objcopy -O elf64-x86-64 -B i386 -I binary zap-light16.psf zap-light16.o
|
|
||||||
nasm -f elf64 src/idt/idt.S -o idt_stub.o
|
nasm -f elf64 src/idt/idt.S -o idt_stub.o
|
||||||
x86_64-elf-ld -o pepperk -T linker.ld *.o
|
x86_64-elf-ld -o pepperk -T linker.ld *.o
|
||||||
nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
|
nm -n pepperk | awk '$$2 ~ /[TtDdBbRr]/ {print $$1, $$3}' > symbols.map
|
||||||
|
|||||||
61
src/debug/misc.c
Normal file
61
src/debug/misc.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include <kernel.h>
|
||||||
|
#include "limine.h"
|
||||||
|
#include "string/string.h"
|
||||||
|
|
||||||
|
extern struct boot_context boot_ctx;
|
||||||
|
|
||||||
|
// Display the memmap so we see how the memory is laid out at handoff
|
||||||
|
void memmap_display(struct limine_memmap_response* response)
|
||||||
|
{
|
||||||
|
DEBUG("Got memory map from Limine: revision %u, %u entries", response->revision, response->entry_count);
|
||||||
|
|
||||||
|
for (size_t i=0; i<response->entry_count; i++)
|
||||||
|
{
|
||||||
|
struct limine_memmap_entry* entry = response->entries[i];
|
||||||
|
char type[32] = {0};
|
||||||
|
switch(entry->type)
|
||||||
|
{
|
||||||
|
case LIMINE_MEMMAP_USABLE:
|
||||||
|
strcpy(type, "USABLE");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_RESERVED:
|
||||||
|
strcpy(type, "RESERVED");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_ACPI_RECLAIMABLE:
|
||||||
|
strcpy(type, "ACPI_RECLAIMABLE");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_ACPI_NVS:
|
||||||
|
strcpy(type, "ACPI_NVS");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_BAD_MEMORY:
|
||||||
|
strcpy(type, "BAD_MEMORY");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE:
|
||||||
|
strcpy(type, "BOOTLOADER_RECLAIMABLE");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_KERNEL_AND_MODULES:
|
||||||
|
strcpy(type, "KERNEL_AND_MODULES");
|
||||||
|
break;
|
||||||
|
case LIMINE_MEMMAP_FRAMEBUFFER:
|
||||||
|
strcpy(type, "FRAMEBUFFER");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
strcpy(type, "UNKNOWN");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
DEBUG("entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display the HHDM
|
||||||
|
void hhdm_display(struct limine_hhdm_response* hhdm)
|
||||||
|
{
|
||||||
|
DEBUG("Got HHDM revision=%u offset=0x%p", hhdm->revision, hhdm->offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void boot_mem_display()
|
||||||
|
{
|
||||||
|
memmap_display(boot_ctx.mmap);
|
||||||
|
hhdm_display(boot_ctx.hhdm);
|
||||||
|
DEBUG("kernel: phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base);
|
||||||
|
}
|
||||||
23
src/entry.S
23
src/entry.S
@@ -1,23 +0,0 @@
|
|||||||
bits 64
|
|
||||||
global _start
|
|
||||||
|
|
||||||
extern kmain
|
|
||||||
extern kernel_stack
|
|
||||||
|
|
||||||
KERNEL_STACK_SIZE equ 65536
|
|
||||||
|
|
||||||
section .text
|
|
||||||
|
|
||||||
_start:
|
|
||||||
cli
|
|
||||||
|
|
||||||
; load kernel stack
|
|
||||||
lea rsp, [kernel_stack+KERNEL_STACK_SIZE]
|
|
||||||
|
|
||||||
; rbp=0 so last frame in stack trace
|
|
||||||
xor rbp, rbp
|
|
||||||
|
|
||||||
; 16 byte align
|
|
||||||
and rsp, -16
|
|
||||||
|
|
||||||
call kmain
|
|
||||||
@@ -11,104 +11,14 @@ because this shitty implementation will be replaced one day by Flanterm
|
|||||||
(once memory management is okay: paging & kernel malloc)
|
(once memory management is okay: paging & kernel malloc)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <limine.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include "term.h"
|
#include "term.h"
|
||||||
#include "mem/misc/utils.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "flanterm.h"
|
#include "flanterm.h"
|
||||||
|
|
||||||
extern struct boot_context boot_ctx;
|
|
||||||
|
|
||||||
// Importing the PSF object file
|
|
||||||
extern unsigned char _binary_zap_light16_psf_start[];
|
|
||||||
extern unsigned char _binary_zap_light16_psf_end[];
|
|
||||||
|
|
||||||
PSF1_Header* font = (PSF1_Header*)_binary_zap_light16_psf_start;
|
|
||||||
uint8_t* glyphs = _binary_zap_light16_psf_start + sizeof(PSF1_Header);
|
|
||||||
|
|
||||||
#define FONT_WIDTH 8
|
|
||||||
#define FONT_HEIGHT font->characterSize
|
|
||||||
|
|
||||||
extern struct flanterm_context* ft_ctx;
|
extern struct flanterm_context* ft_ctx;
|
||||||
|
|
||||||
// Character cursor
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
size_t x;
|
|
||||||
size_t y;
|
|
||||||
} Cursor;
|
|
||||||
|
|
||||||
static Cursor cursor = {0, 0};
|
|
||||||
|
|
||||||
static uint8_t* fb;
|
|
||||||
static struct limine_framebuffer* framebuffer;
|
|
||||||
|
|
||||||
uint8_t lines_length[TERM_HISTORY_MAX_LINES];
|
|
||||||
|
|
||||||
static inline size_t term_max_cols(void)
|
|
||||||
{
|
|
||||||
return framebuffer->width / FONT_WIDTH;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline size_t term_max_lines(void)
|
|
||||||
{
|
|
||||||
return framebuffer->height / FONT_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
int term_init()
|
|
||||||
{
|
|
||||||
// Get framebuffer address from Limine struct
|
|
||||||
|
|
||||||
if (!boot_ctx.fb)
|
|
||||||
{
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
framebuffer = boot_ctx.fb;
|
|
||||||
fb = (uint8_t*)framebuffer->address;
|
|
||||||
|
|
||||||
memset(lines_length, 0, sizeof(lines_length));
|
|
||||||
|
|
||||||
DEBUG("terminal initialized, fb=0x%p (width=%u height=%u pitch=%u bpp=%u)", fb, framebuffer->width, framebuffer->height, framebuffer->pitch, framebuffer->bpp);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// These are marked "static" because we don't wanna expose them all around
|
|
||||||
// AKA they should just be seen here (kind of like private functions in cpp)
|
|
||||||
static inline void putpixel(size_t x, size_t y, uint32_t color)
|
|
||||||
{
|
|
||||||
// Guard so we don't write past fb boundaries
|
|
||||||
if (x >= framebuffer->width || y >= framebuffer->height) return;
|
|
||||||
// Depth isn't part of limine_framebuffer attributes so it will be 4
|
|
||||||
size_t pos = x*4 + y*framebuffer->pitch;
|
|
||||||
fb[pos] = color & 255; // blue channel
|
|
||||||
fb[pos+1] = (color >> 8) & 255; // green
|
|
||||||
fb[pos+2] = (color >> 16) & 255; // blue
|
|
||||||
}
|
|
||||||
|
|
||||||
void term_scroll()
|
|
||||||
{
|
|
||||||
// Erase first text line
|
|
||||||
memset(fb, 255, FONT_HEIGHT*framebuffer->pitch);
|
|
||||||
|
|
||||||
// Move whole framebuffer up by one text line
|
|
||||||
memmove(fb, fb+(FONT_HEIGHT*framebuffer->pitch), (framebuffer->height-FONT_HEIGHT)*framebuffer->pitch);
|
|
||||||
|
|
||||||
// Clear last text line
|
|
||||||
size_t clear_start = (framebuffer->height - FONT_HEIGHT) * framebuffer->pitch;
|
|
||||||
memset(fb + clear_start, 255, FONT_HEIGHT * framebuffer->pitch);
|
|
||||||
|
|
||||||
// Shift line lengths by 1 (for backspace handling)
|
|
||||||
size_t max_lines = term_max_lines();
|
|
||||||
for (size_t i = 1; i < max_lines; i++)
|
|
||||||
{
|
|
||||||
lines_length[i - 1] = lines_length[i];
|
|
||||||
}
|
|
||||||
lines_length[max_lines - 1] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Overhead that could be avoided, right? (for printf)
|
// Overhead that could be avoided, right? (for printf)
|
||||||
void _putchar(char character)
|
void _putchar(char character)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,26 +7,7 @@
|
|||||||
#ifndef TERM_H
|
#ifndef TERM_H
|
||||||
#define TERM_H
|
#define TERM_H
|
||||||
|
|
||||||
int term_init();
|
|
||||||
void kputs(const char* str);
|
void kputs(const char* str);
|
||||||
void _putchar(char character);
|
void _putchar(char character);
|
||||||
|
|
||||||
enum TermColors
|
|
||||||
{
|
|
||||||
BLACK = 0x000000,
|
|
||||||
WHITE = 0xffffff
|
|
||||||
};
|
|
||||||
|
|
||||||
#define PSF1_FONT_MAGIC 0x0436
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint16_t magic;
|
|
||||||
uint8_t fontMode;
|
|
||||||
uint8_t characterSize; // height
|
|
||||||
} PSF1_Header;
|
|
||||||
|
|
||||||
// debug
|
|
||||||
void term_scroll();
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ void idle();
|
|||||||
|
|
||||||
void debug_stack_trace(unsigned int max_frames);
|
void debug_stack_trace(unsigned int max_frames);
|
||||||
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset);
|
const char* debug_find_symbol(uintptr_t rip, uintptr_t* offset);
|
||||||
|
void boot_mem_display();
|
||||||
|
|
||||||
#define assert(check) do { if(!(check)) hcf(); } while(0)
|
#define assert(check) do { if(!(check)) hcf(); } while(0)
|
||||||
|
|
||||||
|
|||||||
@@ -70,13 +70,6 @@ void flanterm_free_wrapper(void* ptr, size_t size)
|
|||||||
kfree(ptr);
|
kfree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void boot_mem_display()
|
|
||||||
{
|
|
||||||
memmap_display(boot_ctx.mmap);
|
|
||||||
hhdm_display(boot_ctx.hhdm);
|
|
||||||
DEBUG("kernel: phys_base=0x%p virt_base=0x%p", boot_ctx.kaddr->physical_base, boot_ctx.kaddr->virtual_base);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern uintptr_t kheap_start;
|
extern uintptr_t kheap_start;
|
||||||
|
|
||||||
// This is our entry point
|
// This is our entry point
|
||||||
@@ -139,6 +132,6 @@ void kmain()
|
|||||||
|
|
||||||
keyboard_init(FR);
|
keyboard_init(FR);
|
||||||
|
|
||||||
printf(PEPPEROS_SPLASH);
|
kputs(PEPPEROS_SPLASH);
|
||||||
idle();
|
idle();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,52 +77,3 @@ int memcmp(const void* s1, const void* s2, size_t n)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the memmap so we see how the memory is laid out at handoff
|
|
||||||
void memmap_display(struct limine_memmap_response* response)
|
|
||||||
{
|
|
||||||
DEBUG("Got memory map from Limine: revision %u, %u entries", response->revision, response->entry_count);
|
|
||||||
|
|
||||||
for (size_t i=0; i<response->entry_count; i++)
|
|
||||||
{
|
|
||||||
struct limine_memmap_entry* entry = response->entries[i];
|
|
||||||
char type[32] = {0};
|
|
||||||
switch(entry->type)
|
|
||||||
{
|
|
||||||
case LIMINE_MEMMAP_USABLE:
|
|
||||||
strcpy(type, "USABLE");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_RESERVED:
|
|
||||||
strcpy(type, "RESERVED");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_ACPI_RECLAIMABLE:
|
|
||||||
strcpy(type, "ACPI_RECLAIMABLE");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_ACPI_NVS:
|
|
||||||
strcpy(type, "ACPI_NVS");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_BAD_MEMORY:
|
|
||||||
strcpy(type, "BAD_MEMORY");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_BOOTLOADER_RECLAIMABLE:
|
|
||||||
strcpy(type, "BOOTLOADER_RECLAIMABLE");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_KERNEL_AND_MODULES:
|
|
||||||
strcpy(type, "KERNEL_AND_MODULES");
|
|
||||||
break;
|
|
||||||
case LIMINE_MEMMAP_FRAMEBUFFER:
|
|
||||||
strcpy(type, "FRAMEBUFFER");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
strcpy(type, "UNKNOWN");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DEBUG("entry %02u: [0x%016x | %016u bytes] - %s", i, entry->base, entry->length, type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display the HHDM
|
|
||||||
void hhdm_display(struct limine_hhdm_response* hhdm)
|
|
||||||
{
|
|
||||||
DEBUG("Got HHDM revision=%u offset=0x%p", hhdm->revision, hhdm->offset);
|
|
||||||
}
|
|
||||||
BIN
zap-light16.psf
BIN
zap-light16.psf
Binary file not shown.
Reference in New Issue
Block a user