Skip to content

Commit

Permalink
- commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsoftware1 committed Jan 16, 2025
1 parent 7a00b62 commit 9247306
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 28 deletions.
32 changes: 5 additions & 27 deletions build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,15 @@ include rules.ninja
build help: HELP
build clean: CLEAN

#libc
build ./build/libc/string.o: gcc ./src/arch/i386/kernel/include/libc/string.c
build ./libs/libc.a: ar ./build/libc/string.o

#i386
build ./build/i386/boot.o: nasm ./src/arch/i386/boot.asm
build ./build/i386/gdt.asm.o: nasm ./src/arch/i386/kernel/gdt.asm
build ./build/i386/idt.asm.o: nasm ./src/arch/i386/kernel/idt.asm
build ./build/i386/irq.o: nasm ./src/arch/i386/kernel/irq.asm
build ./build/i386/exceptions.o: nasm ./src/arch/i386/kernel/exceptions.asm
build ./build/i386/gdt.c.o: gcc ./src/arch/i386/kernel/gdt.c
build ./build/i386/idt.c.o: gcc ./src/arch/i386/kernel/idt.c
build ./build/i386/isr.o: gcc ./src/arch/i386/kernel/isr.c
build ./build/i386/io.o: gcc ./src/arch/i386/kernel/io.c
build ./build/i386/vga.o: gcc ./src/arch/i386/kernel/drivers/vga.c
build ./build/i386/pic.o: gcc ./src/arch/i386/kernel/drivers/pic.c
build ./build/i386/cmos.o: gcc ./src/arch/i386/kernel/drivers/cmos.c
build ./build/i386/keyboard.o: gcc ./src/arch/i386/kernel/drivers/keyboard.c
build ./build/i386/fpu.o: gcc ./src/arch/i386/kernel/drivers/fpu.c
build ./build/i386/pit.o: gcc ./src/arch/i386/kernel/drivers/pit.c
build ./build/i386/ata.o: gcc ./src/arch/i386/kernel/drivers/ata.c
build ./build/i386/console.o: gcc ./src/arch/i386/kernel/console.c
build ./build/i386/acpi.o: gcc ./src/arch/i386/kernel/acpi.c
build ./build/i386/madt.o: gcc ./src/arch/i386/kernel/madt.c
build ./build/i386/kernel.o: gcc ./src/arch/i386/kernel/kernel.c
build ./build/i386/boot.o: gcc ./src/arch/i386/boot.c
build ./build/i386/vga.o: gcc ./src/arch/i386/drivers/vga.c
build ./build/i386/kernel.o: gcc ./src/arch/i386/kernel.c

build ./isodir/boot/piriquitOS-i386.bin: ld ./build/i386/ata.o ./build/i386/acpi.o ./build/i386/madt.o ./build/libc/string.o ./build/i386/boot.o ./build/i386/gdt.asm.o ./build/i386/gdt.c.o ./build/i386/idt.c.o ./build/i386/idt.asm.o ./build/i386/irq.o ./build/i386/exceptions.o ./build/i386/isr.o ./build/i386/io.o ./build/i386/vga.o ./build/i386/pic.o ./build/i386/cmos.o ./build/i386/keyboard.o ./build/i386/pit.o ./build/i386/console.o ./build/i386/fpu.o ./build/i386/kernel.o
build ./isodir/boot/piriquitOS-i386.bin: ld ./build/i386/boot.o ./build/i386/vga.o ./build/i386/kernel.o
build ./build/piriquitOS-i386.iso: iso ./isodir

#phony
build libc: phony ./build/libc/string.o ./libs/libc.a
build i386: phony ./libs/libc.a ./build/i386/ata.o ./build/i386/acpi.o ./build/i386/madt.o ./build/i386/boot.o ./build/i386/gdt.asm.o ./build/i386/idt.asm.o ./build/i386/irq.o ./build/i386/exceptions.o ./build/i386/isr.o ./build/i386/io.o ./build/i386/vga.o ./build/i386/pic.o ./build/i386/cmos.o ./build/i386/keyboard.o ./build/i386/console.o ./build/i386/fpu.o ./build/i386/pit.o ./build/i386/kernel.o ./isodir/boot/piriquitOS-i386.bin ./build/piriquitOS-i386.iso
build i386: phony ./isodir/boot/piriquitOS-i386.bin ./build/piriquitOS-i386.iso

default help
File renamed without changes.
2 changes: 1 addition & 1 deletion rules.ninja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
NASMARGS = -f elf32
LDARGS = -m elf_i386 -T ./src/arch/i386/linker.ld -nostdlib -z noexecstack
CCARGS = -m32 -std=gnu99 -ffreestanding -fcompare-debug -Wall -Wextra -Wno-implicit-function-declaration -fno-diagnostics-show-caret -c
CCINCLUDES = -L./libs -lc -I ./src/arch/i386/kernel/include
CCINCLUDES = -L./libs -lc
ARARGS = -rcs

rule HELP
Expand Down
73 changes: 73 additions & 0 deletions src/arch/i386/drivers/vga.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "vga.h"

#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define VGA_MEMORY ((u16 *)0xB8000)

static size_t terminal_row;
static size_t terminal_column;
static u8 terminal_color;
static u16* terminal_buffer;

static u8 vga_entry_color(enum vga_color fg, enum vga_color bg) {
return fg | bg << 4;
}

static u16 vga_entry(unsigned char uc, u8 color) {
return (u16)uc | (u16)color << 8;
}

void vga_init(void) {
terminal_row = 0;
terminal_column = 0;
terminal_color = vga_entry_color(VGA_LIGHT_GREY, VGA_BLACK);
terminal_buffer = VGA_MEMORY;

vga_clear();
}

void vga_clear(void) {
for (size_t y = 0; y < VGA_HEIGHT; y++) {
for (size_t x = 0; x < VGA_WIDTH; x++) {
const size_t index = y * VGA_WIDTH + x;
terminal_buffer[index] = vga_entry(' ', terminal_color);
}
}
}

void vga_setcolor(u8 color) {
terminal_color = color;
}

void vga_putchar(char c) {
if (c == '\n') {
terminal_column = 0;
terminal_row++;
if (terminal_row == VGA_HEIGHT) {
terminal_row = 0;
}
return;
}

unsigned char uc = c;
terminal_buffer[terminal_row * VGA_WIDTH + terminal_column] = vga_entry(uc, terminal_color);

if (++terminal_column == VGA_WIDTH) {
terminal_column = 0;
if (++terminal_row == VGA_HEIGHT) {
terminal_row = 0;
}
}
}

void vga_write(const char *data, size_t size) {
for (size_t i = 0; i < size; i++) {
vga_putchar(data[i]);
}
}

void vga_writestring(const char *data) {
for (size_t i = 0; data[i] != '\0'; i++) {
vga_putchar(data[i]);
}
}
33 changes: 33 additions & 0 deletions src/arch/i386/drivers/vga.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef VGA_H
#define VGA_H

#include "../types.h"

enum vga_color
{
VGA_BLACK = 0,
VGA_BLUE = 1,
VGA_GREEN = 2,
VGA_CYAN = 3,
VGA_RED = 4,
VGA_MAGENTA = 5,
VGA_BROWN = 6,
VGA_LIGHT_GREY = 7,
VGA_DARK_GREY = 8,
VGA_LIGHT_BLUE = 9,
VGA_LIGHT_GREEN = 10,
VGA_LIGHT_CYAN = 11,
VGA_LIGHT_RED = 12,
VGA_LIGHT_MAGENTA = 13,
VGA_LIGHT_BROWN = 14,
VGA_WHITE = 15
};

void vga_init(void);
void vga_putchar(char c);
void vga_write(const char *data, size_t size);
void vga_writestring(const char *data);
void vga_setcolor(u8 color);
void vga_clear(void);

#endif
13 changes: 13 additions & 0 deletions src/arch/i386/kernel.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#include "drivers/vga.h"

void kmain(void)
{
vga_init();
vga_setcolor(VGA_LIGHT_GREY);
vga_putchar('H');
vga_setcolor(VGA_LIGHT_BLUE);
vga_putchar('e');
vga_setcolor(VGA_LIGHT_GREEN);
vga_putchar('l');
vga_setcolor(VGA_LIGHT_RED);
vga_putchar('l');
vga_setcolor(VGA_LIGHT_MAGENTA);
vga_putchar('o');

while (0)
{
__asm__ volatile ("hlt");
Expand Down
2 changes: 2 additions & 0 deletions src/arch/i386/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;

typedef unsigned int size_t;

#endif

0 comments on commit 9247306

Please sign in to comment.