Consolidate formating

This commit is contained in:
Thomas Lovén 2022-01-17 00:38:43 +01:00
parent 121858ee31
commit f9b7390923
29 changed files with 139 additions and 354 deletions

View File

@ -11,7 +11,7 @@ CFLAGS := -Wall -Wextra -pedantic -ffreestanding -mcmodel=large -std=c2x
CFLAGS += -ggdb -O0 CFLAGS += -ggdb -O0
ASFLAGS += -ggdb ASFLAGS += -ggdb
CPPFLAGS += -nostdinc -I include -I /opt/sysroot/usr/include CPPFLAGS += -nostdinc -I include -I /opt/sysroot/usr/include
LDFLAGS := -n -T Link.ld LDFLAGS := -n -T Link.ld
LDLIBS := -nostdlib -lgcc -L/opt/sysroot/usr/lib -lc -lmittos LDLIBS := -nostdlib -lgcc -L/opt/sysroot/usr/lib -lc -lmittos
kernel: $(OBJ) kernel: $(OBJ)

View File

@ -8,8 +8,7 @@ extern gfx_context kernel_fb;
int *position = (void *)0x20000; int *position = (void *)0x20000;
void thread1() void thread1() {
{
int a = 1; int a = 1;
gfx_context *ctx = framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100); gfx_context *ctx = framebuffer_make_subcontext(&kernel_fb, 700, 300, 100, 100);
while(1) { while(1) {
@ -18,25 +17,21 @@ void thread1()
draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0)); draw_line(ctx, 0, 100, 50, ((a-1)%100), RGB(0,0,0));
draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0)); draw_line(ctx, 0, 100, 50, (a%100), RGB(255,0,0));
flip(ctx); flip(ctx);
sched_yield(); sched_yield();
} }
} }
void thread2() void thread2() {
{
int a = 0; int a = 0;
while(1) { while(1) {
putCharacter(term_fb, *position, *position, RGB(0,255,255), RGB(0,0,0), 'A'+(a++%10)); putCharacter(term_fb, *position, *position, RGB(0,255,255), RGB(0,0,0), 'A'+(a++%10));
flip(term_fb); flip(term_fb);
sched_yield(); sched_yield();
} }
} }
void TEMP_test_scheduler() void TEMP_test_scheduler() {
{
struct process *th1 = new_process(thread1); struct process *th1 = new_process(thread1);
scheduler_insert(th1); scheduler_insert(th1);

View File

@ -89,6 +89,6 @@ upper_memory:
.extern kmain //; boot/kmain.c .extern kmain //; boot/kmain.c
movabs rax, offset kmain movabs rax, offset kmain
call rax call rax
hlt hlt
jmp $ jmp $

View File

@ -11,8 +11,7 @@ void TEMP_test_scheduler();
struct kernel_boot_data_st kernel_boot_data; struct kernel_boot_data_st kernel_boot_data;
void kmain(uint64_t multiboot_magic, void *multiboot_data) void kmain(uint64_t multiboot_magic, void *multiboot_data) {
{
musl_init(); musl_init();
debug_info("Started kernel\n"); debug_info("Started kernel\n");
multiboot_init(multiboot_magic, P2V(multiboot_data)); multiboot_init(multiboot_magic, P2V(multiboot_data));

View File

@ -31,17 +31,14 @@ struct mmap {
struct mmap_entry entries[]; struct mmap_entry entries[];
}__attribute__((packed)); }__attribute__((packed));
static int parse_multiboot2(struct taglist *tags) static int parse_multiboot2(struct taglist *tags) {
{
struct mmap *mmap; struct mmap *mmap;
struct tag *tag = incptr(tags, sizeof(struct taglist)); struct tag *tag = incptr(tags, sizeof(struct taglist));
kernel_boot_data.mboot_tags = tag; kernel_boot_data.mboot_tags = tag;
kernel_boot_data.tags_length = tags->total_size; kernel_boot_data.tags_length = tags->total_size;
while(tag->type) while(tag->type) {
{ switch(tag->type) {
switch(tag->type)
{
case MBOOT2_TAG_BOOTLOADER: case MBOOT2_TAG_BOOTLOADER:
kernel_boot_data.bootloader = (char *)tag->data; kernel_boot_data.bootloader = (char *)tag->data;
break; break;
@ -61,7 +58,7 @@ static int parse_multiboot2(struct taglist *tags)
kernel_boot_data.rsdp = (void *)tag->data; kernel_boot_data.rsdp = (void *)tag->data;
break; break;
} }
// Tags are 8 byte alligned, so make sure we look for the next one in the right place // Tags are 8 byte alligned, so make sure we look for the next one in the right place
int padded_size = tag->size + ((tag->size % 8)?(8-(tag->size%8)):0); int padded_size = tag->size + ((tag->size % 8)?(8-(tag->size%8)):0);
tag = incptr(tag, padded_size); tag = incptr(tag, padded_size);
@ -69,21 +66,18 @@ static int parse_multiboot2(struct taglist *tags)
return 0; return 0;
} }
int multiboot_init(uint64_t magic, void *mboot_info) int multiboot_init(uint64_t magic, void *mboot_info) {
{ if(magic == MBOOT2_REPLY) {
if(magic == MBOOT2_REPLY)
{
kernel_boot_data.multiboot_version = 2; kernel_boot_data.multiboot_version = 2;
parse_multiboot2(mboot_info); parse_multiboot2(mboot_info);
} } else {
else
return 1; return 1;
}
return 0; return 0;
} }
int multiboot_get_memory_area(size_t index, uintptr_t *start, uintptr_t *end, uint32_t *type) int multiboot_get_memory_area(size_t index, uintptr_t *start, uintptr_t *end, uint32_t *type) {
{
if(index >= kernel_boot_data.mmap_len) return 1; if(index >= kernel_boot_data.mmap_len) return 1;
struct mmap *mmap = kernel_boot_data.mmap; struct mmap *mmap = kernel_boot_data.mmap;
@ -96,10 +90,9 @@ int multiboot_get_memory_area(size_t index, uintptr_t *start, uintptr_t *end, ui
return 0; return 0;
} }
int multiboot_page_used(uintptr_t page) int multiboot_page_used(uintptr_t page) {
{
#define within_page(st, l) (((uintptr_t)st + l) > page && (uintptr_t)st < (page + PAGE_SIZE)) #define within_page(st, l) (((uintptr_t)st + l) > page && (uintptr_t)st < (page + PAGE_SIZE))
size_t fb_size = 0; size_t fb_size = 0;
uintptr_t fb_start = 0; uintptr_t fb_start = 0;
if(kernel_boot_data.fbinfo) { if(kernel_boot_data.fbinfo) {
@ -112,7 +105,8 @@ int multiboot_page_used(uintptr_t page)
within_page(kernel_boot_data.commandline, strlen(kernel_boot_data.commandline)) || within_page(kernel_boot_data.commandline, strlen(kernel_boot_data.commandline)) ||
within_page(kernel_boot_data.mmap, kernel_boot_data.mmap_size) || within_page(kernel_boot_data.mmap, kernel_boot_data.mmap_size) ||
within_page(fb_start, fb_size) || within_page(fb_start, fb_size) ||
0) { 0
) {
return 1; return 1;
} }
return 0; return 0;

View File

@ -6,8 +6,7 @@
// ACPI Specification https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf // ACPI Specification https://uefi.org/sites/default/files/resources/ACPI_6_3_final_Jan30.pdf
struct rsdp // 5.2.5.3 struct rsdp { // 5.2.5.3
{
char signature[8]; char signature[8];
uint8_t checksum; uint8_t checksum;
char OEMID[6]; char OEMID[6];
@ -19,8 +18,7 @@ struct rsdp // 5.2.5.3
uint8_t reserved[3]; // only if revision >= 2 uint8_t reserved[3]; // only if revision >= 2
}__attribute__((packed)); }__attribute__((packed));
struct sdt_header // 5.2.6 struct sdt_header { // 5.2.6
{
char signature[4]; char signature[4];
uint32_t length; uint32_t length;
uint8_t revision; uint8_t revision;
@ -33,15 +31,13 @@ struct sdt_header // 5.2.6
uint8_t data[]; uint8_t data[];
}__attribute__((packed)); }__attribute__((packed));
struct madt_header // 5.2.12 struct madt_header { // 5.2.12
{
uint32_t controllerAddress; uint32_t controllerAddress;
uint32_t flags; uint32_t flags;
uint8_t fields[]; uint8_t fields[];
}__attribute__((packed)); }__attribute__((packed));
struct madt_field struct madt_field {
{
uint8_t type; uint8_t type;
uint8_t length; uint8_t length;
uint8_t data[]; uint8_t data[];
@ -49,8 +45,7 @@ struct madt_field
// MADT field type: 0 // MADT field type: 0
#define MADT_TYPE_LAPIC 0 #define MADT_TYPE_LAPIC 0
struct madt_data_lapic struct madt_data_lapic { // 5.2.12.2
{ // 5.2.12.2
uint8_t id; uint8_t id;
uint8_t apic; uint8_t apic;
uint32_t flags; uint32_t flags;
@ -58,8 +53,7 @@ struct madt_data_lapic
// MADT field type: 1 // MADT field type: 1
#define MADT_TYPE_IOAPIC 1 #define MADT_TYPE_IOAPIC 1
struct madt_data_ioapic struct madt_data_ioapic { // 5.2.12.3
{ // 5.2.12.3
uint8_t id; uint8_t id;
uint8_t reserved; uint8_t reserved;
uint32_t address; uint32_t address;
@ -68,8 +62,7 @@ struct madt_data_ioapic
// MADT field type: 2 // MADT field type: 2
#define MADT_TYPE_ISO 2 #define MADT_TYPE_ISO 2
struct madt_data_iso struct madt_data_iso { // 5.2.12.5
{ // 5.2.12.5
uint8_t bus; uint8_t bus;
uint8_t source; uint8_t source;
uint32_t interrupt; uint32_t interrupt;
@ -77,8 +70,7 @@ struct madt_data_iso
}__attribute__((packed)); }__attribute__((packed));
void acpi_parse() void acpi_parse() {
{
int cpu_i=0; int cpu_i=0;
struct rsdp *rsdp = kernel_boot_data.rsdp; struct rsdp *rsdp = kernel_boot_data.rsdp;
@ -86,23 +78,19 @@ void acpi_parse()
uint32_t *table = (void *)rsdt->data; uint32_t *table = (void *)rsdt->data;
int entries = (rsdt->length - sizeof(struct sdt_header))/sizeof(uint32_t); int entries = (rsdt->length - sizeof(struct sdt_header))/sizeof(uint32_t);
for(int i = 0; i < entries; i++) for(int i = 0; i < entries; i++) {
{
struct sdt_header *h = P2V(table[i]); struct sdt_header *h = P2V(table[i]);
if(h->length == 0) continue; if(h->length == 0) continue;
if(!strncmp(h->signature, "APIC", 4)) // 5.2.12 if(!strncmp(h->signature, "APIC", 4)) { // 5.2.12
{
struct madt_header *madt = P2V(h->data); struct madt_header *madt = P2V(h->data);
for( for(
struct madt_field *f = (void *)madt->fields; struct madt_field *f = (void *)madt->fields;
(size_t)f <= (size_t)h + h->length; (size_t)f <= (size_t)h + h->length;
f = incptr(f, f->length) f = incptr(f, f->length)
) ) {
{
switch(f->type) { switch(f->type) {
case MADT_TYPE_LAPIC: case MADT_TYPE_LAPIC: {
{
struct madt_data_lapic *lapic = (void *)f->data; struct madt_data_lapic *lapic = (void *)f->data;
struct cpu *cpu = P2V(pmm_alloc()); struct cpu *cpu = P2V(pmm_alloc());
cpus[cpu_i++] = cpu; cpus[cpu_i++] = cpu;
@ -111,16 +99,14 @@ void acpi_parse()
cpu->flags = lapic->flags; cpu->flags = lapic->flags;
break; break;
} }
case MADT_TYPE_IOAPIC: case MADT_TYPE_IOAPIC: {
{
struct madt_data_ioapic *_ioapic = (void *)f->data; struct madt_data_ioapic *_ioapic = (void *)f->data;
ioapic.id = _ioapic->id; ioapic.id = _ioapic->id;
ioapic.addr = _ioapic->address; ioapic.addr = _ioapic->address;
ioapic.base = _ioapic->base; ioapic.base = _ioapic->base;
break; break;
} }
case MADT_TYPE_ISO: case MADT_TYPE_ISO: {
{
struct madt_data_iso *iso = (void *)f->data; struct madt_data_iso *iso = (void *)f->data;
irq_redirects[iso->source] = iso->interrupt; irq_redirects[iso->source] = iso->interrupt;
break; break;

View File

@ -9,7 +9,7 @@
#define APIC_REG(r) (((uint32_t *)P2V(APIC_BASE + (r)))[0]) #define APIC_REG(r) (((uint32_t *)P2V(APIC_BASE + (r)))[0])
union ioapic_redirection{ union ioapic_redirection {
uint64_t val; uint64_t val;
struct { struct {
uint32_t l; uint32_t l;
@ -24,43 +24,37 @@ union ioapic_redirection{
}__attribute__((packed)); }__attribute__((packed));
}; };
static uint32_t ioapic_read(int reg) static uint32_t ioapic_read(int reg) {
{
uint32_t volatile *ioregsel = P2V(ioapic.addr); uint32_t volatile *ioregsel = P2V(ioapic.addr);
uint32_t volatile *iowin = P2V(ioapic.addr + 0x10); uint32_t volatile *iowin = P2V(ioapic.addr + 0x10);
*ioregsel = reg; *ioregsel = reg;
return *iowin; return *iowin;
} }
static void ioapic_write(int reg, uint32_t value) static void ioapic_write(int reg, uint32_t value) {
{
uint32_t volatile *ioregsel = P2V(ioapic.addr); uint32_t volatile *ioregsel = P2V(ioapic.addr);
uint32_t volatile *iowin = P2V(ioapic.addr + 0x10); uint32_t volatile *iowin = P2V(ioapic.addr + 0x10);
*ioregsel = reg; *ioregsel = reg;
*iowin = value; *iowin = value;
} }
static uint64_t ioapic_read_redirection(int irq) static uint64_t ioapic_read_redirection(int irq) {
{
union ioapic_redirection retval; union ioapic_redirection retval;
retval.l = ioapic_read(0x10 + 2*irq); retval.l = ioapic_read(0x10 + 2*irq);
retval.h = ioapic_read(0x11 + 2*irq); retval.h = ioapic_read(0x11 + 2*irq);
return retval.val; return retval.val;
} }
static void ioapic_write_redirection(int irq, uint64_t val) static void ioapic_write_redirection(int irq, uint64_t val) {
{
union ioapic_redirection value; union ioapic_redirection value;
value.val = val; value.val = val;
ioapic_write(0x10 + 2*irq, value.l); ioapic_write(0x10 + 2*irq, value.l);
ioapic_write(0x11 + 2*irq, value.h); ioapic_write(0x11 + 2*irq, value.h);
} }
void ioapic_init() void ioapic_init() {
{
vmm_set_page(kernel_P4, (uintptr_t)P2V(ioapic.addr), ioapic.addr, PAGE_PRESENT | PAGE_WRITE | PAGE_GLOBAL); vmm_set_page(kernel_P4, (uintptr_t)P2V(ioapic.addr), ioapic.addr, PAGE_PRESENT | PAGE_WRITE | PAGE_GLOBAL);
union ioapic_redirection red; union ioapic_redirection red;
for(int i = 0; i < 24; i++) for(int i = 0; i < 24; i++) {
{
red.val = ioapic_read_redirection(i); red.val = ioapic_read_redirection(i);
red.vector = IRQ_BASE+i; red.vector = IRQ_BASE+i;
red.flags = 0x0; red.flags = 0x0;
@ -73,8 +67,7 @@ void ioapic_init()
} }
} }
void apic_init() void apic_init() {
{
// Enable local APIC // Enable local APIC
write_msr(MSR_APIC_BASE, read_msr(MSR_APIC_BASE) | APIC_MSR_ENABLE); write_msr(MSR_APIC_BASE, read_msr(MSR_APIC_BASE) | APIC_MSR_ENABLE);

View File

@ -11,8 +11,7 @@ uint8_t irq_redirects[MAX_IRQS] = \
#define PIC2_ADDR 0xA0 #define PIC2_ADDR 0xA0
#define PIC_INITIALIZE 0x10 #define PIC_INITIALIZE 0x10
#define PIC_SINGLE 0x02 #define PIC_SINGLE 0x02
static void pic_disable() static void pic_disable() {
{
// Absolute minimum work to initialize and disable legacy PIC. // Absolute minimum work to initialize and disable legacy PIC.
// Both the primary and secondary PIC will think they are alone // Both the primary and secondary PIC will think they are alone
// in a MCS-80 arch computer but that doesn't matter since all // in a MCS-80 arch computer but that doesn't matter since all
@ -27,13 +26,11 @@ static void pic_disable()
outb(PIC2_ADDR | 1, 0xFF); outb(PIC2_ADDR | 1, 0xFF);
} }
void early_cpu_init() void early_cpu_init() {
{
interrupt_init(); interrupt_init();
} }
void cpu_init() void cpu_init() {
{
acpi_parse(); acpi_parse();
pic_disable(); pic_disable();
apic_init(); apic_init();

View File

@ -5,14 +5,12 @@
#define GDT_PRESENT (1<<15) #define GDT_PRESENT (1<<15)
#define GDT_LONG (1<<21) #define GDT_LONG (1<<21)
struct gdt struct gdt {
{
uint32_t _; uint32_t _;
uint32_t flags; uint32_t flags;
}__attribute__((packed)); }__attribute__((packed));
struct gdtp struct gdtp {
{
uint16_t len; uint16_t len;
struct gdt *gdt; struct gdt *gdt;
}__attribute__((packed)); }__attribute__((packed));

View File

@ -29,11 +29,9 @@ struct {
extern uintptr_t isr_table[]; extern uintptr_t isr_table[];
int_handler_t int_handlers[NUM_INTERRUPTS]; int_handler_t int_handlers[NUM_INTERRUPTS];
void interrupt_init() void interrupt_init() {
{
memset(idt, 0, sizeof(idt)); memset(idt, 0, sizeof(idt));
for(int i=0; i < NUM_INTERRUPTS; i++) for(int i=0; i < NUM_INTERRUPTS; i++) {
{
idt[i].base_l = isr_table[i] & 0xFFFF; idt[i].base_l = isr_table[i] & 0xFFFF;
idt[i].base_m = (isr_table[i] >> 16) & 0xFFFF; idt[i].base_m = (isr_table[i] >> 16) & 0xFFFF;
idt[i].base_h = (isr_table[i] >> 32) & 0xFFFFFFFF; idt[i].base_h = (isr_table[i] >> 32) & 0xFFFFFFFF;
@ -53,12 +51,10 @@ int_handler_t bind_interrupt(uint32_t num, int_handler_t fn) {
return old; return old;
} }
registers *int_handler(registers *r) registers *int_handler(registers *r) {
{
if(int_handlers[r->int_no]) if(int_handlers[r->int_no])
return int_handlers[r->int_no](r); return int_handlers[r->int_no](r);
if(r->int_no < IRQ_BASE) if(r->int_no < IRQ_BASE) {
{
debug_error("UNHANDLED EXCEPTION\n"); debug_error("UNHANDLED EXCEPTION\n");
switch(r->int_no) { switch(r->int_no) {
case 14: case 14:

View File

@ -7,27 +7,22 @@ gfx_context kernel_fb;
gfx_context *term_fb; gfx_context *term_fb;
static int setup = 0; static int setup = 0;
void fbterm_movecursor(unsigned int cursor) void fbterm_movecursor(unsigned int cursor) {
{
(void) cursor; (void) cursor;
} }
void fbterm_flush(struct vga_cell *buffer) void fbterm_flush(struct vga_cell *buffer) {
{
if(!setup) return; if(!setup) return;
int i = 0; int i = 0;
for(int row = 0; row < VGA_ROWS; row++) for(int row = 0; row < VGA_ROWS; row++) {
{ for(int col=0; col < VGA_COLS; col++) {
for(int col=0; col < VGA_COLS; col++)
{
putCharacter(term_fb, col*8, row*16, 0xebdbb2, 0x282828, (char)buffer[i++].c); putCharacter(term_fb, col*8, row*16, 0xebdbb2, 0x282828, (char)buffer[i++].c);
} }
} }
flip(term_fb); flip(term_fb);
} }
void fbterm_init(struct fbinfo *fbinfo) void fbterm_init(struct fbinfo *fbinfo) {
{
kernel_fb.width = fbinfo->framebuffer_width; kernel_fb.width = fbinfo->framebuffer_width;
kernel_fb.height = fbinfo->framebuffer_height; kernel_fb.height = fbinfo->framebuffer_height;
kernel_fb.bpp = fbinfo->framebuffer_bpp/8; kernel_fb.bpp = fbinfo->framebuffer_bpp/8;
@ -36,8 +31,11 @@ void fbterm_init(struct fbinfo *fbinfo)
kernel_fb.size = fbinfo->framebuffer_pitch * (kernel_fb.height); kernel_fb.size = fbinfo->framebuffer_pitch * (kernel_fb.height);
kernel_fb.buffer = calloc(1, kernel_fb.size); kernel_fb.buffer = calloc(1, kernel_fb.size);
for(uintptr_t p = (uintptr_t)kernel_fb.addr; p < ((uintptr_t)kernel_fb.addr + kernel_fb.size); p += PAGE_SIZE) for(
{ uintptr_t p = (uintptr_t)kernel_fb.addr;
p < ((uintptr_t)kernel_fb.addr + kernel_fb.size);
p += PAGE_SIZE
) {
vmm_set_page(kernel_P4, p, V2P(p), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT); vmm_set_page(kernel_P4, p, V2P(p), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT);
} }

View File

@ -19,21 +19,17 @@ uint8_t format = 0x7;
static int terminal_type; static int terminal_type;
static void scroll() static void scroll() {
{ while(cursor >= VGA_SIZE) {
while(cursor >= VGA_SIZE)
{
memmove(buffer, &buffer[VGA_POS(1,0)], VGA_COLS*(VGA_ROWS-1)*sizeof(struct vga_cell)); memmove(buffer, &buffer[VGA_POS(1,0)], VGA_COLS*(VGA_ROWS-1)*sizeof(struct vga_cell));
memset(&buffer[VGA_POS(VGA_ROWS-1, 0)], 0, VGA_COLS*sizeof(struct vga_cell)); memset(&buffer[VGA_POS(VGA_ROWS-1, 0)], 0, VGA_COLS*sizeof(struct vga_cell));
cursor -= VGA_COLS; cursor -= VGA_COLS;
} }
} }
static void terminal_write(char c) static void terminal_write(char c) {
{
int doflush = 0; int doflush = 0;
switch(c) switch(c) {
{
case '\n': case '\n':
cursor += VGA_COLS - VGA_COL(cursor); cursor += VGA_COLS - VGA_COL(cursor);
doflush = 1; doflush = 1;
@ -42,8 +38,7 @@ static void terminal_write(char c)
buffer[cursor++] = (struct vga_cell){.c = c, .f = format}; buffer[cursor++] = (struct vga_cell){.c = c, .f = format};
} }
scroll(); scroll();
switch(terminal_type) switch(terminal_type) {
{
case FRAMEBUFFER: case FRAMEBUFFER:
if(doflush) if(doflush)
fbterm_flush(buffer); fbterm_flush(buffer);
@ -57,14 +52,12 @@ static void terminal_write(char c)
} }
} }
static void terminal_putsn(char *s, size_t n) static void terminal_putsn(char *s, size_t n) {
{
while(n--) while(n--)
terminal_write(*s++); terminal_write(*s++);
} }
long k_ioctl(long fd, long cmd, long arg3, long, long, long) long k_ioctl(long fd, long cmd, long arg3, long, long, long) {
{
if(fd == 1 && cmd == 0x5413) { if(fd == 1 && cmd == 0x5413) {
struct { struct {
unsigned short ws_row; unsigned short ws_row;
@ -81,14 +74,12 @@ long k_ioctl(long fd, long cmd, long arg3, long, long, long)
return retval; return retval;
} }
long k_writev(long fd, long iov, long iovcnt, long, long, long) long k_writev(long fd, long iov, long iovcnt, long, long, long) {
{
if(fd == 1) if(fd == 1)
{ {
size_t len = 0; size_t len = 0;
struct iovec *v = (void *) iov; struct iovec *v = (void *) iov;
for(int i = 0; i < iovcnt; i++) for(int i = 0; i < iovcnt; i++) {
{
terminal_putsn(v[i].iov_base, v[i].iov_len); terminal_putsn(v[i].iov_base, v[i].iov_len);
len += v[i].iov_len; len += v[i].iov_len;
} }
@ -99,12 +90,11 @@ long k_writev(long fd, long iov, long iovcnt, long, long, long)
return retval; return retval;
} }
void terminal_init(){ void terminal_init() {
struct fbinfo *fbinfo = kernel_boot_data.fbinfo; struct fbinfo *fbinfo = kernel_boot_data.fbinfo;
terminal_type = fbinfo->framebuffer_type; terminal_type = fbinfo->framebuffer_type;
switch(terminal_type) switch(terminal_type) {
{
case FRAMEBUFFER: case FRAMEBUFFER:
fbterm_init(fbinfo); fbterm_init(fbinfo);
break; break;

View File

@ -15,16 +15,14 @@ static void *vidmem;
static int setup = 0; static int setup = 0;
void vga_init(struct fbinfo *fbinfo) void vga_init(struct fbinfo *fbinfo) {
{
(void) fbinfo; (void) fbinfo;
vidmem = VGA_MEMORY; vidmem = VGA_MEMORY;
memset(vidmem, 0, VGA_SIZE*sizeof(struct vga_cell)); memset(vidmem, 0, VGA_SIZE*sizeof(struct vga_cell));
setup = 1; setup = 1;
} }
void vga_movecursor(unsigned int cursor) void vga_movecursor(unsigned int cursor) {
{
if(!setup) return; if(!setup) return;
outb(VGA_ADDRESS_PORT, VGA_REGISTER_CURSOR_POS_LOW); outb(VGA_ADDRESS_PORT, VGA_REGISTER_CURSOR_POS_LOW);
outb(VGA_DATA_PORT, (uint8_t)(cursor & 0xFF)); outb(VGA_DATA_PORT, (uint8_t)(cursor & 0xFF));
@ -32,8 +30,7 @@ void vga_movecursor(unsigned int cursor)
outb(VGA_DATA_PORT, (uint8_t)((cursor >> 8) & 0xFF)); outb(VGA_DATA_PORT, (uint8_t)((cursor >> 8) & 0xFF));
} }
void vga_flush(struct vga_cell *buffer) void vga_flush(struct vga_cell *buffer) {
{
if(!setup) return; if(!setup) return;
memcpy(vidmem, buffer, VGA_SIZE*2); memcpy(vidmem, buffer, VGA_SIZE*2);
} }

View File

@ -28,7 +28,7 @@ struct fbinfo {
uint8_t color_info[]; uint8_t color_info[];
}__attribute__((packed)); }__attribute__((packed));
struct kernel_boot_data_st{ struct kernel_boot_data_st {
int multiboot_version; int multiboot_version;
void *mboot_tags; void *mboot_tags;
size_t tags_length; size_t tags_length;

View File

@ -1,13 +1,11 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
static __inline void _outb(uint16_t port, uint8_t value) static __inline void _outb(uint16_t port, uint8_t value) {
{
__asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value)); __asm__ volatile("outb %1, %0" : : "dN" (port), "a" (value));
} }
static __inline uint8_t _inb(uint16_t port) static __inline uint8_t _inb(uint16_t port) {
{
uint8_t ret; uint8_t ret;
__asm__ volatile("inb %1, %0" : "=a" (ret) : "dN" (port)); __asm__ volatile("inb %1, %0" : "=a" (ret) : "dN" (port));
return ret; return ret;

View File

@ -1,8 +1,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
struct process struct process {
{
uint64_t pid; uint64_t pid;
void *stack_ptr; void *stack_ptr;
uint64_t state; uint64_t state;

View File

@ -9,15 +9,13 @@ syscall_handler syscall_handlers[440] = {
[SYSCALL_MMAP] = k_mmap, [SYSCALL_MMAP] = k_mmap,
}; };
syscall_handler set_syscall_handler(long num, syscall_handler handler) syscall_handler set_syscall_handler(long num, syscall_handler handler) {
{
syscall_handler old = syscall_handlers[num]; syscall_handler old = syscall_handlers[num];
syscall_handlers[num] = handler; syscall_handlers[num] = handler;
return old; return old;
} }
long syscall0(long num) long syscall0(long num) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](0, 0, 0, 0, 0, 0); retval = syscall_handlers[num](0, 0, 0, 0, 0, 0);
@ -26,8 +24,7 @@ long syscall0(long num)
return retval; return retval;
} }
long syscall1(long num, long a1) long syscall1(long num, long a1) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, 0, 0, 0, 0, 0); retval = syscall_handlers[num](a1, 0, 0, 0, 0, 0);
@ -36,8 +33,7 @@ long syscall1(long num, long a1)
return retval; return retval;
} }
long syscall2(long num, long a1, long a2) long syscall2(long num, long a1, long a2) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, a2, 0, 0, 0, 0); retval = syscall_handlers[num](a1, a2, 0, 0, 0, 0);
@ -46,8 +42,7 @@ long syscall2(long num, long a1, long a2)
return retval; return retval;
} }
long syscall3(long num, long a1, long a2, long a3) long syscall3(long num, long a1, long a2, long a3) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, a2, a3, 0, 0, 0); retval = syscall_handlers[num](a1, a2, a3, 0, 0, 0);
@ -56,8 +51,7 @@ long syscall3(long num, long a1, long a2, long a3)
return retval; return retval;
} }
long syscall4(long num, long a1, long a2, long a3, long a4) long syscall4(long num, long a1, long a2, long a3, long a4) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, a2, a3, a4, 0, 0); retval = syscall_handlers[num](a1, a2, a3, a4, 0, 0);
@ -66,8 +60,7 @@ long syscall4(long num, long a1, long a2, long a3, long a4)
return retval; return retval;
} }
long syscall5(long num, long a1, long a2, long a3, long a4, long a5) long syscall5(long num, long a1, long a2, long a3, long a4, long a5) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, a2, a3, a4, a5, 0); retval = syscall_handlers[num](a1, a2, a3, a4, a5, 0);
@ -76,8 +69,7 @@ long syscall5(long num, long a1, long a2, long a3, long a4, long a5)
return retval; return retval;
} }
long syscall6(long num, long a1, long a2, long a3, long a4, long a5, long a6) long syscall6(long num, long a1, long a2, long a3, long a4, long a5, long a6) {
{
long retval = 0; long retval = 0;
if(syscall_handlers[num]) if(syscall_handlers[num])
retval = syscall_handlers[num](a1, a2, a3, a4, a5, a6); retval = syscall_handlers[num](a1, a2, a3, a4, a5, a6);
@ -89,7 +81,6 @@ long syscall6(long num, long a1, long a2, long a3, long a4, long a5, long a6)
size_t auxv[] = {0}; size_t auxv[] = {0};
void musl_init() void musl_init() {
{
__libc.auxv = auxv; __libc.auxv = auxv;
} }

View File

@ -4,10 +4,8 @@
static long _brk = KERNEL_BRK0; static long _brk = KERNEL_BRK0;
static long _mmap = KERNEL_MMAP; static long _mmap = KERNEL_MMAP;
long k_brk(long brk, long, long, long, long, long) long k_brk(long brk, long, long, long, long, long) {
{ if(brk) {
if(brk)
{
while(_brk < brk) { while(_brk < brk) {
vmm_set_page(kernel_P4, _brk, pmm_alloc(), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT); vmm_set_page(kernel_P4, _brk, pmm_alloc(), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT);
_brk += PAGE_SIZE; _brk += PAGE_SIZE;
@ -18,8 +16,7 @@ long k_brk(long brk, long, long, long, long, long)
} }
} }
long k_mmap(long addr, long length, long prot, long flags, long fd, long offset) long k_mmap(long addr, long length, long prot, long flags, long fd, long offset) {
{
(void)addr; (void)addr;
(void)prot; (void)prot;
(void)flags; (void)flags;
@ -27,8 +24,7 @@ long k_mmap(long addr, long length, long prot, long flags, long fd, long offset)
if(fd != -1) if(fd != -1)
PANIC("Unknown mmap request\n"); PANIC("Unknown mmap request\n");
long retval = _mmap; long retval = _mmap;
while(length > 0) while(length > 0) {
{
vmm_set_page(kernel_P4, _mmap, pmm_alloc(), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT); vmm_set_page(kernel_P4, _mmap, pmm_alloc(), PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT);
_mmap += PAGE_SIZE; _mmap += PAGE_SIZE;
length -= PAGE_SIZE; length -= PAGE_SIZE;

View File

@ -6,20 +6,16 @@
uint64_t kernel_P4; uint64_t kernel_P4;
void memory_init() void memory_init() {
{
kernel_P4 = (uint64_t)&BootP4; kernel_P4 = (uint64_t)&BootP4;
uint64_t start, end; uint64_t start, end;
uint32_t type, i = 0; uint32_t type, i = 0;
while(!multiboot_get_memory_area(i++, &start, &end, &type)) while(!multiboot_get_memory_area(i++, &start, &end, &type)) {
{ for(uint64_t p = start; p < end; p += PAGE_SIZE) {
for(uint64_t p = start; p < end; p += PAGE_SIZE)
{
uint64_t vaddr = (uint64_t)P2V(p); uint64_t vaddr = (uint64_t)P2V(p);
uint64_t page = vmm_get_page(kernel_P4, vaddr); uint64_t page = vmm_get_page(kernel_P4, vaddr);
if(page == (uint64_t)-1 || !(page & PAGE_PRESENT)) if(page == (uint64_t)-1 || !(page & PAGE_PRESENT)) {
{
uint16_t flags = PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT; uint16_t flags = PAGE_GLOBAL | PAGE_WRITE | PAGE_PRESENT;
vmm_set_page(kernel_P4, vaddr, p, flags); vmm_set_page(kernel_P4, vaddr, p, flags);
} }

View File

@ -5,22 +5,19 @@
// Physical address of next page // Physical address of next page
uint64_t next = 0; uint64_t next = 0;
void pmm_free(uint64_t page) void pmm_free(uint64_t page) {
{
*(uint64_t *)P2V(page) = next; *(uint64_t *)P2V(page) = next;
next = page; next = page;
} }
uint64_t pmm_alloc() uint64_t pmm_alloc() {
{
if(!next) return 0; if(!next) return 0;
uint64_t page = next; uint64_t page = next;
next = *(uint64_t *)P2V(page); next = *(uint64_t *)P2V(page);
return page; return page;
} }
uint64_t pmm_calloc() uint64_t pmm_calloc() {
{
uint64_t page = pmm_alloc(); uint64_t page = pmm_alloc();
memset(P2V(page), 0, PAGE_SIZE); memset(P2V(page), 0, PAGE_SIZE);
return page; return page;

View File

@ -16,16 +16,14 @@
#define P1E(P4, addr) (PT(P2E(P4, addr))[P1_OFFSET(addr)]) #define P1E(P4, addr) (PT(P2E(P4, addr))[P1_OFFSET(addr)])
static int P1_exists(uint64_t P4, uint64_t addr) static int P1_exists(uint64_t P4, uint64_t addr) {
{
if (P4 && PRESENT(P4E(P4, addr)) && PRESENT(P3E(P4, addr)) && PRESENT(P2E(P4, addr))) if (P4 && PRESENT(P4E(P4, addr)) && PRESENT(P3E(P4, addr)) && PRESENT(P2E(P4, addr)))
return 1; return 1;
return 0; return 0;
} }
static int touch_P1(uint64_t P4, uint64_t addr, uint16_t flags) static int touch_P1(uint64_t P4, uint64_t addr, uint16_t flags) {
{
if (!P4) return -1; if (!P4) return -1;
if(!PRESENT(P4E(P4, addr)) && (!(P4E(P4,addr) = pmm_calloc()))) if(!PRESENT(P4E(P4, addr)) && (!(P4E(P4,addr) = pmm_calloc())))
@ -43,22 +41,19 @@ static int touch_P1(uint64_t P4, uint64_t addr, uint16_t flags)
return 0; return 0;
} }
uint64_t new_P4() uint64_t new_P4() {
{
uint64_t p4 = pmm_alloc(); uint64_t p4 = pmm_alloc();
memcpy(P2V(p4), (void *)kernel_P4, PAGE_SIZE); memcpy(P2V(p4), (void *)kernel_P4, PAGE_SIZE);
return p4; return p4;
} }
uint64_t vmm_get_page(uint64_t P4, uint64_t addr) uint64_t vmm_get_page(uint64_t P4, uint64_t addr) {
{
if(P1_exists(P4, addr)) if(P1_exists(P4, addr))
return P1E(P4, addr); return P1E(P4, addr);
return -1; return -1;
} }
int vmm_set_page(uint64_t P4, uint64_t addr, uint64_t page, uint16_t flags) int vmm_set_page(uint64_t P4, uint64_t addr, uint64_t page, uint16_t flags) {
{
if(!P1_exists(P4, addr)) if(!P1_exists(P4, addr))
if(touch_P1(P4, addr, flags)) if(touch_P1(P4, addr, flags))
return -1; return -1;
@ -67,8 +62,7 @@ int vmm_set_page(uint64_t P4, uint64_t addr, uint64_t page, uint16_t flags)
return 0; return 0;
} }
void vmm_clear_page(uint64_t P4, uint64_t addr, int free) void vmm_clear_page(uint64_t P4, uint64_t addr, int free) {
{
if(!P1_exists(P4, addr)) if(!P1_exists(P4, addr))
return; return;

View File

@ -2,8 +2,7 @@
#include <proc.h> #include <proc.h>
#include <memory.h> #include <memory.h>
struct swtch_stack struct swtch_stack {
{
uint64_t RBP; uint64_t RBP;
uint64_t RBX; uint64_t RBX;
uint64_t R12; uint64_t R12;
@ -18,8 +17,7 @@ static uint64_t next_pid = 1;
struct process *current_proc; struct process *current_proc;
struct process *new_process(void (*function)(void)) struct process *new_process(void (*function)(void)) {
{
struct process *p = P2V(pmm_calloc()); struct process *p = P2V(pmm_calloc());
p->pid = next_pid++; p->pid = next_pid++;
p->stack_ptr = incptr(p, PAGE_SIZE - sizeof(struct swtch_stack)); p->stack_ptr = incptr(p, PAGE_SIZE - sizeof(struct swtch_stack));
@ -33,7 +31,6 @@ struct process *new_process(void (*function)(void))
return p; return p;
} }
struct process *proc() struct process *proc() {
{
return current_proc; return current_proc;
} }

View File

@ -8,16 +8,14 @@ static struct {
static struct process *scheduler_proc; static struct process *scheduler_proc;
static struct process *scheduler_next() static struct process *scheduler_next() {
{
struct process *ret = run_q.first; struct process *ret = run_q.first;
if(run_q.first && !(run_q.first = run_q.first->q_next)) if(run_q.first && !(run_q.first = run_q.first->q_next))
run_q.last = 0; run_q.last = 0;
return ret; return ret;
} }
void scheduler_insert(struct process *new) void scheduler_insert(struct process *new) {
{
if(run_q.last) { if(run_q.last) {
run_q.last->q_next = new; run_q.last->q_next = new;
run_q.last = new; run_q.last = new;
@ -27,10 +25,8 @@ void scheduler_insert(struct process *new)
new->q_next = 0; new->q_next = 0;
} }
void scheduler() void scheduler() {
{ while(1) {
while(1)
{
struct process *new = 0; struct process *new = 0;
while(!(new = scheduler_next())); while(!(new = scheduler_next()));
@ -43,14 +39,12 @@ void scheduler()
} }
} }
long k_sched_yield(long, long, long, long, long, long) long k_sched_yield(long, long, long, long, long, long) {
{
switch_stack(&current_proc->stack_ptr, &scheduler_proc->stack_ptr); switch_stack(&current_proc->stack_ptr, &scheduler_proc->stack_ptr);
return 0; return 0;
} }
void start_scheduler() void start_scheduler() {
{
scheduler_proc = new_process(scheduler); scheduler_proc = new_process(scheduler);
scheduler_proc->pid = (uint64_t)-1; scheduler_proc->pid = (uint64_t)-1;

View File

@ -11,7 +11,7 @@ switch_stack:
push r12 push r12
push rbx push rbx
push rbp push rbp
mov [rdi], rsp mov [rdi], rsp
mov rsp, [rsi] mov rsp, [rsi]

View File

@ -11,15 +11,13 @@
#define STEP_X(ctx) 1 #define STEP_X(ctx) 1
#define STEP_Y(ctx) (ctx)->pitch #define STEP_Y(ctx) (ctx)->pitch
void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) void putpixel(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr) {
{
if(x >= ctx->width || y >= ctx->height) return; if(x >= ctx->width || y >= ctx->height) return;
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
fb[PXL(ctx, x, y)] = clr; fb[PXL(ctx, x, y)] = clr;
} }
void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t y1, uint32_t clr) void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t y1, uint32_t clr) {
{
int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1; int64_t dx = x1 > x0 ? x1 - x0 : x0 - x1;
int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1; int64_t dy = y1 > y0 ? y1 - y0 : y0 - y1;
int sx = x1 > x0 ? 1 : -1; int sx = x1 > x0 ? 1 : -1;
@ -27,11 +25,10 @@ void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t
uint64_t x = x0, y = y0; uint64_t x = x0, y = y0;
int64_t diff = dx - dy; int64_t diff = dx - dy;
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
while(1) while(1) {
{
fb[PXL(ctx, x, y)] = clr; fb[PXL(ctx, x, y)] = clr;
if(x == x1 && y == y1) break; if(x == x1 && y == y1) break;
if((2*diff) > -dy) { if((2*diff) > -dy) {
diff -= dy; diff -= dy;
x += sx; x += sx;
@ -42,61 +39,50 @@ void draw_line(gfx_context *ctx, uint64_t x0, uint64_t x1, uint64_t y0, uint64_t
} }
} }
void draw_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr) void draw_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr) {
{
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
uint64_t l1 = PXL(ctx, x, y); uint64_t l1 = PXL(ctx, x, y);
uint64_t l2 = PXL(ctx, x, y + height); uint64_t l2 = PXL(ctx, x, y + height);
for(uint64_t _x = 0; _x <= width; _x++) for(uint64_t _x = 0; _x <= width; _x++) {
{
fb[l1] = fb[l2] = clr; fb[l1] = fb[l2] = clr;
l1 += STEP_X(ctx); l1 += STEP_X(ctx);
l2 += STEP_X(ctx); l2 += STEP_X(ctx);
} }
l1 = PXL(ctx, x, y); l1 = PXL(ctx, x, y);
l2 = PXL(ctx, x + width, y); l2 = PXL(ctx, x + width, y);
for(uint64_t _y = 0; _y <= height; _y++) for(uint64_t _y = 0; _y <= height; _y++) {
{
fb[l1] = fb[l2] = clr; fb[l1] = fb[l2] = clr;
l1 += STEP_Y(ctx); l1 += STEP_Y(ctx);
l2 += STEP_Y(ctx); l2 += STEP_Y(ctx);
} }
} }
void fill_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr) void fill_rect(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height, uint32_t clr) {
{
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
uint64_t loc = PXL(ctx, x, y); uint64_t loc = PXL(ctx, x, y);
for(uint64_t _y = 0; _y <= height; _y++) for(uint64_t _y = 0; _y <= height; _y++) {
{ for(uint64_t _x = 0; _x <= width; _x += STEP_X(ctx)) {
for(uint64_t _x = 0; _x <= width; _x += STEP_X(ctx))
{
fb[loc + _x] = clr; fb[loc + _x] = clr;
} }
loc += STEP_Y(ctx); loc += STEP_Y(ctx);
} }
} }
void putCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c) void putCharacter(gfx_context *ctx, uint64_t x, uint64_t y, uint32_t clr_fg, uint32_t clr_bg, char c) {
{
unsigned char *chr = c ? font[(int)c-0x20]: font[0]; unsigned char *chr = c ? font[(int)c-0x20]: font[0];
if(x >= ctx->width || y >= ctx->height) return; if(x >= ctx->width || y >= ctx->height) return;
uint32_t *fb = (uint32_t *)ctx->buffer; uint32_t *fb = (uint32_t *)ctx->buffer;
uint64_t loc = y * ctx->pitch + x; uint64_t loc = y * ctx->pitch + x;
for(int row = 0; row < 16; row++) for(int row = 0; row < 16; row++) {
{ for(int col = 0; col < 8; col++) {
for(int col = 0; col < 8; col++)
{
fb[loc+col] = ((chr[row]>>(7-col))&0x1) ? clr_fg : clr_bg; fb[loc+col] = ((chr[row]>>(7-col))&0x1) ? clr_fg : clr_bg;
} }
loc += ctx->pitch; loc += ctx->pitch;
} }
} }
void flip(gfx_context *ctx) void flip(gfx_context *ctx) {
{ for(uint64_t y = 0; y < ctx->height; y++) {
for(uint64_t y = 0; y < ctx->height; y++)
{
memcpy( memcpy(
incptr(ctx->addr, y*ctx->pitch*ctx->bpp), incptr(ctx->addr, y*ctx->pitch*ctx->bpp),
incptr(ctx->buffer, y*ctx->pitch*ctx->bpp), incptr(ctx->buffer, y*ctx->pitch*ctx->bpp),
@ -104,8 +90,7 @@ void flip(gfx_context *ctx)
} }
} }
gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height) gfx_context *framebuffer_make_subcontext(gfx_context *ctx, uint64_t x, uint64_t y, uint64_t width, uint64_t height) {
{
gfx_context *out = malloc(sizeof(gfx_context)); gfx_context *out = malloc(sizeof(gfx_context));
uint64_t loc = y * ctx->pitch + x; uint64_t loc = y * ctx->pitch + x;

View File

@ -1,98 +0,0 @@
// Font from https://github.com/atextor/unifont
char font[95][16] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x12, 0x7E, 0x24, 0x24, 0x7E, 0x48, 0x48, 0x48, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x08, 0x3E, 0x49, 0x48, 0x38, 0x0E, 0x09, 0x49, 0x3E, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x31, 0x4A, 0x4A, 0x34, 0x08, 0x08, 0x16, 0x29, 0x29, 0x46, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x22, 0x22, 0x1C, 0x39, 0x45, 0x42, 0x46, 0x39, 0x00, 0x00},
{0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x00},
{0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x49, 0x2A, 0x1C, 0x2A, 0x49, 0x08, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x7F, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 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, 0x02, 0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x0C, 0x10, 0x20, 0x40, 0x40, 0x7E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x1C, 0x02, 0x02, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x04, 0x0C, 0x14, 0x24, 0x44, 0x44, 0x7E, 0x04, 0x04, 0x04, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x02, 0x02, 0x02, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x20, 0x40, 0x40, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x02, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x3E, 0x02, 0x02, 0x02, 0x04, 0x38, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x1C, 0x22, 0x4A, 0x56, 0x52, 0x52, 0x52, 0x4E, 0x20, 0x1E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x42, 0x42, 0x42, 0x42, 0x7C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x78, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x40, 0x40, 0x40, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x40, 0x4E, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x7E, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x44, 0x48, 0x50, 0x60, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x66, 0x66, 0x5A, 0x5A, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x62, 0x62, 0x52, 0x52, 0x4A, 0x4A, 0x46, 0x46, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x66, 0x3C, 0x03, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7C, 0x42, 0x42, 0x42, 0x7C, 0x48, 0x44, 0x44, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x40, 0x30, 0x0C, 0x02, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7F, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x5A, 0x5A, 0x66, 0x66, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x7E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00},
{0x00, 0x00, 0x18, 0x24, 0x42, 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, 0x7F, 0x00},
{0x00, 0x20, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x02, 0x3E, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x3A, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x7E, 0x40, 0x40, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x0C, 0x10, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3A, 0x44, 0x44, 0x44, 0x38, 0x20, 0x3C, 0x42, 0x42, 0x3C},
{0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x0C, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x48, 0x30},
{0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5C, 0x40, 0x40},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x02, 0x02},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x40, 0x30, 0x0C, 0x02, 0x42, 0x3C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0C, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3A, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1A, 0x02, 0x02, 0x3C},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7E, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x0C, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x0C, 0x00},
{0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08},
{0x00, 0x00, 0x00, 0x30, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x30, 0x00},
{0x00, 0x00, 0x00, 0x31, 0x49, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
};

View File

@ -9,32 +9,25 @@ extern long syscall4(long, long, long, long, long);
extern long syscall5(long, long, long, long, long, long); extern long syscall5(long, long, long, long, long, long);
extern long syscall6(long, long, long, long, long, long, long); extern long syscall6(long, long, long, long, long, long, long);
static __inline long __syscall0(long n) static __inline long __syscall0(long n) {
{
return syscall0(n); return syscall0(n);
} }
static __inline long __syscall1(long n, long a1) static __inline long __syscall1(long n, long a1) {
{
return syscall1(n, a1); return syscall1(n, a1);
} }
static __inline long __syscall2(long n, long a1, long a2) static __inline long __syscall2(long n, long a1, long a2) {
{
return syscall2(n, a1, a2); return syscall2(n, a1, a2);
} }
static __inline long __syscall3(long n, long a1, long a2, long a3) static __inline long __syscall3(long n, long a1, long a2, long a3) {
{
return syscall3(n, a1, a2, a3); return syscall3(n, a1, a2, a3);
} }
static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) static __inline long __syscall4(long n, long a1, long a2, long a3, long a4) {
{
return syscall4(n, a1, a2, a3, a4); return syscall4(n, a1, a2, a3, a4);
} }
static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) static __inline long __syscall5(long n, long a1, long a2, long a3, long a4, long a5) {
{
return syscall5(n, a1, a2, a3, a4, a5); return syscall5(n, a1, a2, a3, a4, a5);
} }
static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) static __inline long __syscall6(long n, long a1, long a2, long a3, long a4, long a5, long a6) {
{
return syscall6(n, a1, a2, a3, a4, a5, a6); return syscall6(n, a1, a2, a3, a4, a5, a6);
} }

View File

@ -38,7 +38,7 @@ with open("u_vga16.termfont.inc", "w") as fp:
for codepoint in range(32, 127): # ONLY SAVE ASCII (for now) for codepoint in range(32, 127): # ONLY SAVE ASCII (for now)
fp.write("\t{" + ", ".join([f"0x{v:02X}" for v in chars.get(codepoint, [])]) + "},\n") fp.write("\t{" + ", ".join([f"0x{v:02X}" for v in chars.get(codepoint, [])]) + "},\n")
fp.write("};") fp.write("};")
EOF EOF

View File

@ -13,6 +13,6 @@ services:
image: thomasloven/mittos-run image: thomasloven/mittos-run
build: build:
context: . context: .
dockerfile: Dockerfile.run dockerfile: Dockerfile.run
volumes: volumes:
- ..:/opt - ..:/opt