From fbd4fa608904047221d60bc431bb295a3b601e1d Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat, 24 Aug 2024 17:17:53 +0200 Subject: [PATCH] Clean: harmonizing & header-commenting code --- src/drivers/ata.c | 27 ++++++--------------------- src/drivers/ata.h | 26 ++++++++++++++++++++++++++ src/drivers/framebuffer.c | 17 +++++++---------- src/drivers/framebuffer.h | 12 +++++++++++- src/drivers/kb.c | 13 ++++++------- src/drivers/kb.h | 12 ++++++++++++ src/drivers/serial.c | 6 +++++- src/drivers/serial.h | 10 ++++++++-- src/drivers/timer.c | 5 +++++ src/kernel/gdt.c | 21 +++++---------------- src/kernel/gdt.h | 22 +++++++++++++++++++++- src/kernel/idt.c | 20 +++++--------------- src/kernel/idt.h | 21 ++++++++++++++++++++- src/kernel/io.h | 9 +++++++-- src/kernel/io.s | 19 ++++++++++++------- src/kernel/irq.c | 5 +++++ src/kernel/isr.c | 7 +++++-- src/kernel/kheap.c | 6 +++++- src/kernel/kheap.h | 5 +++++ src/kernel/loader.s | 25 ++++++++++++++----------- src/kernel/paging.c | 9 +++++---- src/kernel/paging.h | 11 ++++++++++- src/kernel/shell.c | 9 ++++++--- src/kernel/sysinfo.c | 5 +++++ src/kernel/sysinfo.h | 5 +++++ src/kernel/system.c | 5 +++++ src/kernel/system.h | 5 +++++ src/libc/crypto.c | 5 +++++ src/libc/crypto.h | 5 +++++ src/libc/ctype.c | 5 ++++- src/libc/ctype.h | 5 +++++ src/libc/stdio.c | 8 +++++--- src/libc/stdio.h | 28 +++++++++++++++++----------- src/libc/string.c | 5 +++++ src/libc/string.h | 9 +++++++-- src/programs/bf.c | 4 ++++ src/programs/ciphers.c | 10 +++++++--- src/programs/ciphers.h | 5 +++++ src/programs/conway.c | 5 +++++ src/programs/conway.h | 5 +++++ src/programs/math.c | 5 ++++- src/programs/misc.c | 7 +++++-- src/programs/primes.c | 5 +++++ src/programs/programs.h | 6 ++++++ src/programs/sysinfo.c | 4 ++++ src/programs/words.c | 6 +++++- 46 files changed, 339 insertions(+), 130 deletions(-) diff --git a/src/drivers/ata.c b/src/drivers/ata.c index 8df5997..e67df19 100644 --- a/src/drivers/ata.c +++ b/src/drivers/ata.c @@ -1,27 +1,12 @@ +// ATA PIO driver implementation +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include #include "../kernel/io.h" #include "../libc/stdio.h" - -#define ATA_PRIMARY_IO 0x1F0 -#define ATA_PRIMARY_CTRL 0x3F6 -#define ATA_CMD_READ_PIO 0x20 -#define ATA_CMD_WRITE_PIO 0x30 -#define ATA_IDENTIFY 0xEC - -#define ATA_REG_DATA 0x00 -#define ATA_REG_ERROR 0x01 -#define ATA_REG_SECCOUNT0 0x02 -#define ATA_REG_LBA0 0x03 -#define ATA_REG_LBA1 0x04 -#define ATA_REG_LBA2 0x05 -#define ATA_REG_HDDEVSEL 0x06 -#define ATA_REG_COMMAND 0x07 -#define ATA_REG_STATUS 0x07 - -#define ATA_SR_BSY 0x80 -#define ATA_SR_DRDY 0x40 -#define ATA_SR_DRQ 0x08 -#define ATA_SR_ERR 0x01 +#include "ata.h" static inline uint16_t inw(uint16_t port) { uint16_t result; diff --git a/src/drivers/ata.h b/src/drivers/ata.h index 08c1f7d..f585c5f 100644 --- a/src/drivers/ata.h +++ b/src/drivers/ata.h @@ -1,8 +1,34 @@ +// ATA PIO driver implementation header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef ATA_H #define ATA_H #include +#define ATA_PRIMARY_IO 0x1F0 +#define ATA_PRIMARY_CTRL 0x3F6 +#define ATA_CMD_READ_PIO 0x20 +#define ATA_CMD_WRITE_PIO 0x30 +#define ATA_IDENTIFY 0xEC + +#define ATA_REG_DATA 0x00 +#define ATA_REG_ERROR 0x01 +#define ATA_REG_SECCOUNT0 0x02 +#define ATA_REG_LBA0 0x03 +#define ATA_REG_LBA1 0x04 +#define ATA_REG_LBA2 0x05 +#define ATA_REG_HDDEVSEL 0x06 +#define ATA_REG_COMMAND 0x07 +#define ATA_REG_STATUS 0x07 + +#define ATA_SR_BSY 0x80 +#define ATA_SR_DRDY 0x40 +#define ATA_SR_DRQ 0x08 +#define ATA_SR_ERR 0x01 + void ata_read_sector(uint32_t lba, uint8_t* buffer); void test_read_sector(); diff --git a/src/drivers/framebuffer.c b/src/drivers/framebuffer.c index bc684f7..b1dd622 100644 --- a/src/drivers/framebuffer.c +++ b/src/drivers/framebuffer.c @@ -1,11 +1,16 @@ +// Framebuffer driver +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include #include "framebuffer.h" #include "serial.h" #include "../kernel/system.h" -//extern uint32_t *g_framebuffer; +extern char* framebuffer; -void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) // framebuffer pointer, x, y, color +void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) { if (bpp == 32) { uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8)); @@ -13,14 +18,6 @@ void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) // } } -extern char* framebuffer; -extern int scanline; -extern char _binary_include_fonts_UniCyr_8x16_psf_start; -uint16_t* unicode; - -#define PIXEL uint32_t - -// Character, cursor X, cursor Y, foreground, background void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg) { PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start; diff --git a/src/drivers/framebuffer.h b/src/drivers/framebuffer.h index 7ec9029..06e14bd 100644 --- a/src/drivers/framebuffer.h +++ b/src/drivers/framebuffer.h @@ -1,8 +1,19 @@ +// Framebuffer driver header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef FRAMEBUFFER_H #define FRAMEBUFFER_H #include +extern int scanline; +extern char _binary_include_fonts_UniCyr_8x16_psf_start; +uint16_t* unicode; + +#define PIXEL uint32_t + #define PSF1_FONT_MAGIC 0x0436 typedef struct { @@ -24,7 +35,6 @@ typedef struct { uint32_t width; /* width in pixels */ } PSF_font; -//extern const unsigned char font[512][64]; void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color); void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg); void scroll(); diff --git a/src/drivers/kb.c b/src/drivers/kb.c index d5c7986..52bdc4f 100644 --- a/src/drivers/kb.c +++ b/src/drivers/kb.c @@ -1,13 +1,12 @@ +// Keyboard driver +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../kernel/io.h" #include "../libc/stdio.h" #include "../kernel/system.h" - -#define KEYBOARD_BUFFER_SIZE 256 - -#define LEFT_SHIFT_PRESSED 0x2A -#define RIGHT_SHIFT_PRESSED 0x36 -#define LEFT_SHIFT_RELEASED 0xAA -#define RIGHT_SHIFT_RELEASED 0xB6 +#include "kb.h" unsigned char kbdus[128] = { diff --git a/src/drivers/kb.h b/src/drivers/kb.h index f50cab5..9a4574b 100644 --- a/src/drivers/kb.h +++ b/src/drivers/kb.h @@ -1,6 +1,18 @@ +// Keyboard driver header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef KB_H #define KB_H +#define KEYBOARD_BUFFER_SIZE 256 + +#define LEFT_SHIFT_PRESSED 0x2A +#define RIGHT_SHIFT_PRESSED 0x36 +#define LEFT_SHIFT_RELEASED 0xAA +#define RIGHT_SHIFT_RELEASED 0xB6 + char keyboard_getchar(); #endif diff --git a/src/drivers/serial.c b/src/drivers/serial.c index 7b08c3f..90d7c39 100644 --- a/src/drivers/serial.c +++ b/src/drivers/serial.c @@ -1,3 +1,8 @@ +// Serial I/O driver +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../kernel/io.h" #include "serial.h" #include "../libc/stdio.h" @@ -279,4 +284,3 @@ void serial_printf(int errlevel, const char* fmt, ...) } serial_puts("\n"); } - diff --git a/src/drivers/serial.h b/src/drivers/serial.h index 52cc4b4..b69740f 100644 --- a/src/drivers/serial.h +++ b/src/drivers/serial.h @@ -1,5 +1,10 @@ -#ifndef INCLUDE_SERIAL_H -#define INCLUDE_SERIAL_H +// Serial I/O driver header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + +#ifndef SERIAL_H +#define SERIAL_H #define PORT 0x3f8 //COM1 @@ -9,4 +14,5 @@ void write_serial(const char a); void serial_puts(const char* str); void log(const char* str, const int errlevel); void serial_printf(int errlevel, const char* fmt, ...); + #endif diff --git a/src/drivers/timer.c b/src/drivers/timer.c index acccb19..40b479b 100644 --- a/src/drivers/timer.c +++ b/src/drivers/timer.c @@ -1,3 +1,8 @@ +// Programmable Interval Timer channel 0 driver +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../kernel/system.h" #include "../libc/stdio.h" diff --git a/src/kernel/gdt.c b/src/kernel/gdt.c index 4ba0952..fc465c2 100644 --- a/src/kernel/gdt.c +++ b/src/kernel/gdt.c @@ -1,22 +1,11 @@ +// Global descriptor table setup +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "gdt.h" #include "../libc/stdio.h" -struct gdt_entry -{ - unsigned short limit_low; - unsigned short base_low; - unsigned char base_middle; - unsigned char access; - unsigned char granularity; - unsigned char base_high; -} __attribute__((packed)); - -struct gdt_ptr -{ - unsigned short limit; - unsigned int base; -} __attribute__((packed)); - struct gdt_entry gdt[3]; struct gdt_ptr gp; diff --git a/src/kernel/gdt.h b/src/kernel/gdt.h index 2607869..950fecc 100644 --- a/src/kernel/gdt.h +++ b/src/kernel/gdt.h @@ -1,8 +1,28 @@ +// Global descriptor table setup header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef GDT_H #define GDT_H -void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran); +struct gdt_entry +{ + unsigned short limit_low; + unsigned short base_low; + unsigned char base_middle; + unsigned char access; + unsigned char granularity; + unsigned char base_high; +} __attribute__((packed)); +struct gdt_ptr +{ + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +void gdt_set_gate(int num, unsigned long base, unsigned long limit, unsigned char access, unsigned char gran); void gdt_install(); #endif diff --git a/src/kernel/idt.c b/src/kernel/idt.c index f892f03..d981ca3 100644 --- a/src/kernel/idt.c +++ b/src/kernel/idt.c @@ -1,22 +1,12 @@ +// Interrupt descriptor table setup +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "idt.h" #include "system.h" #include "../libc/stdio.h" -struct idt_entry -{ - unsigned short base_lo; - unsigned short sel; - unsigned char always0; - unsigned char flags; - unsigned short base_hi; -} __attribute__((packed)); - -struct idt_ptr -{ - unsigned short limit; - unsigned int base; -} __attribute__((packed)); - struct idt_entry idt[256]; struct idt_ptr idtp; diff --git a/src/kernel/idt.h b/src/kernel/idt.h index 2d28f8f..5a55306 100644 --- a/src/kernel/idt.h +++ b/src/kernel/idt.h @@ -1,8 +1,27 @@ +// Interrupt descriptor table setup header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef IDT_H #define IDT_H -void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags); +struct idt_entry +{ + unsigned short base_lo; + unsigned short sel; + unsigned char always0; + unsigned char flags; + unsigned short base_hi; +} __attribute__((packed)); +struct idt_ptr +{ + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags); void idt_install(); #endif diff --git a/src/kernel/io.h b/src/kernel/io.h index 4a5553f..6c3ec01 100644 --- a/src/kernel/io.h +++ b/src/kernel/io.h @@ -1,5 +1,10 @@ -#ifndef INCLUDE_IO_H -#define INCLUDE_IO_H +// Raw CPU port I/O kernel module header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + +#ifndef IO_H +#define IO_H #include diff --git a/src/kernel/io.s b/src/kernel/io.s index b677e49..88cb997 100644 --- a/src/kernel/io.s +++ b/src/kernel/io.s @@ -1,17 +1,22 @@ +; Raw CPU port I/O kernel module +; Author: xamidev +; Licensed under the Unlicense. See the repo below. +; https//github.com/xamidev/blankos + global outb outb: - mov al, [esp + 8] - mov dx, [esp + 4] - out dx, al - ret + mov al, [esp + 8] + mov dx, [esp + 4] + out dx, al + ret global inb inb: - mov dx, [esp + 4] - in al, dx - ret + mov dx, [esp + 4] + in al, dx + ret global x86_div64_32 diff --git a/src/kernel/irq.c b/src/kernel/irq.c index 89b9adc..87c0098 100644 --- a/src/kernel/irq.c +++ b/src/kernel/irq.c @@ -1,3 +1,8 @@ +// Interrupt Requests setup +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "system.h" #include "io.h" #include "idt.h" diff --git a/src/kernel/isr.c b/src/kernel/isr.c index fa17ce9..d4934fd 100644 --- a/src/kernel/isr.c +++ b/src/kernel/isr.c @@ -1,3 +1,8 @@ +// Interrupt service routines setup +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "system.h" #include "../libc/stdio.h" #include "idt.h" @@ -37,7 +42,6 @@ extern void isr31(); void isr_install() { - idt_set_gate(0, (unsigned)isr0, 0x08, 0x8E); idt_set_gate(1, (unsigned)isr1, 0x08, 0x8E); idt_set_gate(2, (unsigned)isr2, 0x08, 0x8E); @@ -116,4 +120,3 @@ void fault_handler(struct regs *r) for (;;); } } - diff --git a/src/kernel/kheap.c b/src/kernel/kheap.c index 3076a97..a0711b4 100644 --- a/src/kernel/kheap.c +++ b/src/kernel/kheap.c @@ -1,5 +1,9 @@ -#include "kheap.h" +// Kernel heap management +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos +#include "kheap.h" #include extern uint32_t end; diff --git a/src/kernel/kheap.h b/src/kernel/kheap.h index 0e0e130..c24180b 100644 --- a/src/kernel/kheap.h +++ b/src/kernel/kheap.h @@ -1,3 +1,8 @@ +// Kernel heap management header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef KHEAP_H #define KHEAP_H diff --git a/src/kernel/loader.s b/src/kernel/loader.s index 36410ac..fd38650 100644 --- a/src/kernel/loader.s +++ b/src/kernel/loader.s @@ -1,3 +1,8 @@ +; Kernel loader assembly stub and multiboot2 header +; Author: xamidev +; Licensed under the Unlicense. See the repo below. +; https//github.com/xamidev/blankos + global loader section .multiboot_header @@ -6,9 +11,9 @@ align 8 ; ASM macros -MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic -FLAGS equ 0x0 ; 32-bit protected mode for i386 -HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28 +MAGIC_NUMBER equ 0xe85250d6 ; multiboot2 magic +FLAGS equ 0x0 ; 32-bit protected mode for i386 +HEADER_LEN equ 44 ; Tags=2+2+4+4+4+4+2+2+4=28 CHECKSUM equ -(MAGIC_NUMBER + FLAGS + HEADER_LEN) ; Multiboot 2 header, according to specification (16bytes) @@ -43,14 +48,12 @@ KERNEL_STACK_SIZE equ 4096 extern kmain loader: - cli - ; mov eax, 0xCAFEBABE - ; push dword 42 - push ebx - call kmain + cli + push ebx + call kmain .loop: - jmp .loop + jmp .loop global gdt_flush extern gp @@ -206,5 +209,5 @@ irq_common_stub: section .bss align 4 kernel_stack: - resb KERNEL_STACK_SIZE - mov esp, kernel_stack + KERNEL_STACK_SIZE + resb KERNEL_STACK_SIZE + mov esp, kernel_stack + KERNEL_STACK_SIZE diff --git a/src/kernel/paging.c b/src/kernel/paging.c index c4fad18..87125ee 100644 --- a/src/kernel/paging.c +++ b/src/kernel/paging.c @@ -1,18 +1,19 @@ +// Paging kernel module +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include #include "paging.h" #include "../libc/stdio.h" #include "system.h" #include "kheap.h" - uint32_t *frames; uint32_t nframes; extern uint32_t placement_address; -#define INDEX_FROM_BIT(a) (a/(8*4)) -#define OFFSET_FROM_BIT(a) (a%(8*4)) - static void set_frame(uint32_t frame_addr) { uint32_t frame = frame_addr/0x1000; diff --git a/src/kernel/paging.h b/src/kernel/paging.h index 2b6474d..9e96899 100644 --- a/src/kernel/paging.h +++ b/src/kernel/paging.h @@ -1,12 +1,21 @@ +// Paging kernel module header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef PAGING_H #define PAGING_H #include "system.h" #include + +#define INDEX_FROM_BIT(a) (a/(8*4)) +#define OFFSET_FROM_BIT(a) (a%(8*4)) + typedef struct { uint32_t present : 1; - uint32_t rw : 1; + uint32_t rw : 1; uint32_t user : 1; uint32_t accessed : 1; uint32_t dirty : 1; diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 46f6fc4..0739af1 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -1,3 +1,8 @@ +// Basic shell and commands kernel module +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "system.h" #include "../libc/stdio.h" #include "../libc/string.h" @@ -6,8 +11,7 @@ #define BUFFER_SIZE 256 #define MAX_COMMANDS 16 -#define MAX_ARGS 64 - +#define MAX_ARGS 64 char* ascii_title = "\n" @@ -17,7 +21,6 @@ char* ascii_title = "----------------------------------------------\n" "\n"; - typedef void (*command_func_t)(int argc, char *argv[]); typedef struct diff --git a/src/kernel/sysinfo.c b/src/kernel/sysinfo.c index b5b7bbe..39839ae 100644 --- a/src/kernel/sysinfo.c +++ b/src/kernel/sysinfo.c @@ -1,3 +1,8 @@ +// System information kernel module +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../libc/stdio.h" #include "../libc/string.h" diff --git a/src/kernel/sysinfo.h b/src/kernel/sysinfo.h index 66188ca..a6e3a93 100644 --- a/src/kernel/sysinfo.h +++ b/src/kernel/sysinfo.h @@ -1,3 +1,8 @@ +// System information kernel module header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef SYSINFO_H #define SYSINFO_H diff --git a/src/kernel/system.c b/src/kernel/system.c index 0b02871..3f39277 100644 --- a/src/kernel/system.c +++ b/src/kernel/system.c @@ -1,3 +1,8 @@ +// System utilities and routines kernel module +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "system.h" #include diff --git a/src/kernel/system.h b/src/kernel/system.h index b9b650c..e0123d3 100644 --- a/src/kernel/system.h +++ b/src/kernel/system.h @@ -1,3 +1,8 @@ +// System utilities and routines kernel module header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef SYSTEM_H #define SYSTEM_H diff --git a/src/libc/crypto.c b/src/libc/crypto.c index c0ba0b3..d666214 100644 --- a/src/libc/crypto.c +++ b/src/libc/crypto.c @@ -1,3 +1,8 @@ +// Cryptography routines for blankos/libc +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "crypto.h" #include diff --git a/src/libc/crypto.h b/src/libc/crypto.h index c5aafbd..fdaced1 100644 --- a/src/libc/crypto.h +++ b/src/libc/crypto.h @@ -1,3 +1,8 @@ +// Cryptography routines for blankos/libc header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef CRYPTO_H #define CRYPTO_H diff --git a/src/libc/ctype.c b/src/libc/ctype.c index 862028a..0a89be6 100644 --- a/src/libc/ctype.c +++ b/src/libc/ctype.c @@ -1,3 +1,7 @@ +// Ctype implementation for blankos/libc +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include #include @@ -7,7 +11,6 @@ bool isdigit(char c) return c >= '0' && c <= '9'; } - bool isspace(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\v' || c == '\f' || c == '\r'; diff --git a/src/libc/ctype.h b/src/libc/ctype.h index a93d394..5c29a4e 100644 --- a/src/libc/ctype.h +++ b/src/libc/ctype.h @@ -1,3 +1,8 @@ +// Ctype implementation for blankos/libc header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef CTYPE_H #define CTYPE_H diff --git a/src/libc/stdio.c b/src/libc/stdio.c index 7c06d03..0b6aef2 100644 --- a/src/libc/stdio.c +++ b/src/libc/stdio.c @@ -1,3 +1,8 @@ +// Standard input/output implementation for blankos/libc +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../kernel/io.h" #include "stdio.h" #include "string.h" @@ -10,9 +15,6 @@ extern uint32_t* framebuffer; extern uint32_t VGA_WIDTH; extern uint32_t VGA_HEIGHT; unsigned int VGA_X = 0, VGA_Y = 0; - -#define CURSOR_WIDTH 8 -#define CURSOR_HEIGHT 16 extern int scanline; void draw_cursor(uint32_t color) diff --git a/src/libc/stdio.h b/src/libc/stdio.h index a4490f0..3ffacaa 100644 --- a/src/libc/stdio.h +++ b/src/libc/stdio.h @@ -1,17 +1,24 @@ -#ifndef INCLUDE_STDIO_H -#define INCLUDE_STDIO_H +// Standard input/output implementation for blankos/libc header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + +#ifndef STDIO_H +#define STDIO_H #include #include -#define FB_GREEN 2 -#define FB_DARK_GREY 8 +#define FB_GREEN 2 +#define FB_DARK_GREY 8 #define FB_CMD_PORT 0x3D4 #define FB_DATA_PORT 0x3D5 #define FB_HIGH_BYTE_CMD 14 #define FB_LOW_BYTE_CMD 15 +#define CURSOR_WIDTH 8 +#define CURSOR_HEIGHT 16 void draw_cursor(uint32_t color); void erase_cursor(); @@ -27,24 +34,23 @@ unsigned int getcolor(int x, int y); void putc(char c); void colorputc(char c, uint32_t fg, uint32_t bg); -#define PRINTF_STATE_START 0 +#define PRINTF_STATE_START 0 #define PRINTF_STATE_LENGTH 1 -#define PRINTF_STATE_SHORT 2 -#define PRINTF_STATE_LONG 3 -#define PRINTF_STATE_SPEC 4 -#define PRINTF_STATE_WIDTH 5 +#define PRINTF_STATE_SHORT 2 +#define PRINTF_STATE_LONG 3 +#define PRINTF_STATE_SPEC 4 +#define PRINTF_STATE_WIDTH 5 #define PRINTF_LENGTH_START 0 #define PRINTF_LENGTH_SHORT_SHORT 1 #define PRINTF_LENGTH_SHORT 2 -#define PRINTF_LENGTH_LONG 3 +#define PRINTF_LENGTH_LONG 3 #define PRINTF_LENGTH_LONG_LONG 4 void printf(const char* fmt, ...); int* printf_number(int* argp, int length, bool sign, int radix, int width, char pad_char); int getch(); void get_input(char *buffer, int size); - void dtostrf(double val, char *buffer, int precision); enum Colors diff --git a/src/libc/string.c b/src/libc/string.c index 6f5bd54..e013313 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -1,3 +1,8 @@ +// String operations implementation for blankos/libc +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include #include "../kernel/system.h" diff --git a/src/libc/string.h b/src/libc/string.h index 384507e..2b04950 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -1,5 +1,10 @@ -#ifndef INCLUDE_STRING_H -#define INCLUDE_STRING_H +// String operations implementation for blankos/libc header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + +#ifndef STRING_H +#define STRING_H int strlen(const char* str); int strcmp(const char* str1, const char* str2); diff --git a/src/programs/bf.c b/src/programs/bf.c index 33bcb03..ee0bc90 100644 --- a/src/programs/bf.c +++ b/src/programs/bf.c @@ -1,3 +1,7 @@ +// Simple brainfuck interpreter program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include "../kernel/system.h" #include "../libc/stdio.h" diff --git a/src/programs/ciphers.c b/src/programs/ciphers.c index a4eeb14..3a86da3 100644 --- a/src/programs/ciphers.c +++ b/src/programs/ciphers.c @@ -1,5 +1,12 @@ +// Cipher programs +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "../libc/stdio.h" #include "ciphers.h" +#include "../libc/string.h" +#include void rot13(char* input, char* output) { @@ -32,9 +39,6 @@ void program_rot13() printf("\n%s\n", output); } -#include "../libc/string.h" -#include - const char* morse_alphabet[] = { ".-", // A "-...", // B diff --git a/src/programs/ciphers.h b/src/programs/ciphers.h index 7a015a3..83f43a5 100644 --- a/src/programs/ciphers.h +++ b/src/programs/ciphers.h @@ -1,3 +1,8 @@ +// Cipher programs header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef CIPHERS_H #define CIPHERS_H diff --git a/src/programs/conway.c b/src/programs/conway.c index a1e63a2..df9a867 100644 --- a/src/programs/conway.c +++ b/src/programs/conway.c @@ -1,3 +1,8 @@ +// Conway's Game of Life program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #include "conway.h" #include "../libc/stdio.h" #include "../kernel/system.h" diff --git a/src/programs/conway.h b/src/programs/conway.h index 77d3db2..7fe7794 100644 --- a/src/programs/conway.h +++ b/src/programs/conway.h @@ -1,3 +1,8 @@ +// Conway's Game of Life program header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef CONWAY_H #define CONWAY_H diff --git a/src/programs/math.c b/src/programs/math.c index e91362c..a502916 100644 --- a/src/programs/math.c +++ b/src/programs/math.c @@ -1,4 +1,7 @@ -// Math expression lexer and parser +// Basic math expression lexer and parser program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include #include "../kernel/system.h" diff --git a/src/programs/misc.c b/src/programs/misc.c index 32b24c1..7c37e1b 100644 --- a/src/programs/misc.c +++ b/src/programs/misc.c @@ -1,4 +1,7 @@ // Miscellaneous small programs +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include "../libc/stdio.h" #include "../kernel/system.h" @@ -30,7 +33,7 @@ void program_rainbow() void program_clear() { - for (int i=0; i #include "../libc/stdio.h" #include "../kernel/system.h" diff --git a/src/programs/programs.h b/src/programs/programs.h index f3895e9..16e9b91 100644 --- a/src/programs/programs.h +++ b/src/programs/programs.h @@ -1,3 +1,8 @@ +// Global program entry points header +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos + #ifndef PROGRAMS_H #define PROGRAMS_H @@ -22,4 +27,5 @@ void program_uptime(); void program_panic(); void program_help(); void program_echo(); + #endif diff --git a/src/programs/sysinfo.c b/src/programs/sysinfo.c index 778b67f..2e7f7c8 100644 --- a/src/programs/sysinfo.c +++ b/src/programs/sysinfo.c @@ -1,3 +1,7 @@ +// System information program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include "../kernel/sysinfo.h" #include "../libc/stdio.h" diff --git a/src/programs/words.c b/src/programs/words.c index 129f1e6..03beaf5 100644 --- a/src/programs/words.c +++ b/src/programs/words.c @@ -1,3 +1,7 @@ +// Pseudo-random word generation program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https//github.com/xamidev/blankos #include "../libc/stdio.h" #include "../libc/crypto.h" @@ -37,7 +41,7 @@ char* words[] = int words_size = sizeof(words)/sizeof(words[0]); -// Generates 5 random words +// Generates random words void program_words() { for (int i=0; i<10; i++)