3 Commits

Author SHA1 Message Date
62302e03d5 Add: init serial + getting text out of it 2025-12-21 20:33:48 +01:00
e6f4200ae9 rename stuff + add GDB debug rule 2025-12-21 15:59:14 +01:00
c8df8934b5 Merge pull request #1 from xamidev/hello-world
Hello world
2025-12-21 15:41:10 +01:00
9 changed files with 95 additions and 10 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
limine limine
kernel kernel
pepperk
iso_root iso_root
*.o *.o
*.iso *.iso

View File

@@ -1,8 +1,8 @@
build: build:
rm -f *.o rm -f *.o
x86_64-elf-gcc -c -I src src/io/term.c src/io/printf.c src/kmain.c -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -fno-stack-check -fno-PIC -ffunction-sections -fdata-sections -mcmodel=kernel x86_64-elf-gcc -g -c -I src src/io/serial.c src/io/term.c src/io/printf.c src/kmain.c -Wall -Wextra -std=gnu99 -nostdlib -ffreestanding -fno-stack-protector -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 objcopy -O elf64-x86-64 -B i386 -I binary zap-light16.psf zap-light16.o
x86_64-elf-ld -o kernel -T linker.ld *.o x86_64-elf-ld -o pepperk -T linker.ld *.o
limine/limine: limine/limine:
rm -rf limine rm -rf limine
@@ -12,7 +12,7 @@ limine/limine:
build-iso: limine/limine build build-iso: limine/limine build
rm -rf iso_root rm -rf iso_root
mkdir -p iso_root/boot mkdir -p iso_root/boot
cp -v kernel iso_root/boot cp -v pepperk iso_root/boot
mkdir -p iso_root/boot/limine mkdir -p iso_root/boot/limine
cp -v limine.conf iso_root/boot/limine cp -v limine.conf iso_root/boot/limine
mkdir -p iso_root/EFI/BOOT mkdir -p iso_root/EFI/BOOT
@@ -23,11 +23,15 @@ build-iso: limine/limine build
-no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \ -no-emul-boot -boot-load-size 4 -boot-info-table -hfsplus \
-apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \ -apm-block-size 2048 --efi-boot boot/limine/limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \ -efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o kernel.iso iso_root -o pepper.iso
./limine/limine bios-install kernel.iso ./limine/limine bios-install pepper.iso
debug:
qemu-system-x86_64 -drive file=pepper.iso -s -S &
gdb pepperk --command=debug.gdb
run: build-iso run: build-iso
qemu-system-x86_64 -cdrom kernel.iso qemu-system-x86_64 -cdrom pepper.iso -serial stdio
clean: clean:
rm -rf *.o kernel iso_root kernel.iso limine rm -rf *.o pepperk iso_root pepper.iso limine

View File

@@ -13,4 +13,8 @@ PepperOS wouldn't be possible without the following freely-licensed software:
- the [Limine](https://codeberg.org/Limine/Limine) portable bootloader - the [Limine](https://codeberg.org/Limine/Limine) portable bootloader
- Marco Paland's freestanding [printf implementation](https://github.com/mpaland) - Marco Paland's freestanding [printf implementation](https://github.com/mpaland)
- the [ZAP](https://www.zap.org.au/projects/console-fonts-zap/) PSF console fonts - the [ZAP](https://www.zap.org.au/projects/console-fonts-zap/) PSF console fonts
...and without these amazing resources:
- the [OSDev](https://osdev.org) wiki & forums

1
debug.gdb Normal file
View File

@@ -0,0 +1 @@
target remote localhost:1234

View File

@@ -3,4 +3,4 @@ timeout: 3
/PepperOS /PepperOS
protocol: limine protocol: limine
path: boot():/boot/kernel path: boot():/boot/pepperk

59
src/io/serial.c Normal file
View File

@@ -0,0 +1,59 @@
#include "../kernel.h"
void outb(int port, unsigned char data)
{
__asm__ __volatile__("outb %%al, %%dx" :: "a" (data),"d" (port));
}
unsigned char inb(int port)
{
unsigned char data = 0;
__asm__ __volatile__("inb %%dx, %%al" : "=a" (data) : "d" (port));
return data;
}
// COM1
#define PORT 0x3F8
int serial_init()
{
outb(PORT + 1, 0x00); // Disable all interrupts
outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
outb(PORT + 1, 0x00); // (hi byte)
outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit
outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial returns same byte)
if (inb(PORT) != 0xAE)
{
return -EIO;
}
// Set normal operation mode
outb(PORT + 4, 0x0F);
return 0;
}
static int is_transmit_empty()
{
return inb(PORT + 5) & 0x20;
}
void write_serial(char c)
{
while (!is_transmit_empty()); // wait for free spot
outb(PORT, c);
}
void serial_kputs(const char* str)
{
unsigned int i=0;
while (str[i])
{
write_serial(str[i]);
i++;
}
}

10
src/io/serial.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef SERIAL_H
#define SERIAL_H
void outb(int port, unsigned char data);
unsigned char inb(int port);
int serial_init();
void serial_kputs(const char* str);
#endif

View File

@@ -3,7 +3,8 @@
enum ErrorCodes enum ErrorCodes
{ {
ENOMEM ENOMEM,
EIO
}; };
#endif #endif

View File

@@ -3,6 +3,7 @@
#include <limine.h> #include <limine.h>
#include "io/term.h" #include "io/term.h"
#include "io/printf.h" #include "io/printf.h"
#include "io/serial.h"
// Limine version used // Limine version used
__attribute__((used, section(".limine_requests"))) __attribute__((used, section(".limine_requests")))
@@ -111,6 +112,10 @@ void kmain()
if (term_init()) hcf(); if (term_init()) hcf();
if (serial_init()) kputs("kernel: serial: error: Cannot init serial communication!");
serial_kputs("\n\nkernel: serial: Hello, world from serial!");
// Draw something // Draw something
printf("%s, %s!", "Hello", "world"); printf("%s, %s!", "Hello", "world");