build system refresh

This commit is contained in:
2026-07-16 16:09:12 -05:00
parent b588634253
commit 3246dbbd19
49 changed files with 185 additions and 203 deletions

6
.gitignore vendored
View File

@@ -10,7 +10,5 @@
.idea .idea
.vscode .vscode
build sysroot
isodir isodir
compiler*/

View File

@@ -1,11 +1,16 @@
#!/bin/bash #!/bin/bash
./build_libc.sh ./build_sysroot.sh
./build_libs.sh
./build_programs.sh ./build_programs.sh
make clean make clean
bear -- make bear -- make
./copy_resources.sh
./make_img.sh ./make_img.sh
make -B make -B

View File

@@ -1,6 +0,0 @@
#!/bin/bash
cd rocklibc
make clean
bear -- make
cd ..

17
build_libs.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
cp -r kernel/sys/*.h rlibc/include/sys
cd rlibc
make clean
bear -- make
cp rlibc.a ../sysroot/usr/lib
cp -r include/. ../sysroot/usr/include
cd ..
cd rlibgui
make clean
bear -- make
cp rlibgui.a ../sysroot/usr/lib
cp -r include/. ../sysroot/usr/include
cd ..

View File

@@ -1,17 +1,16 @@
#!/bin/bash #!/bin/bash
TARGET_DIR="programs" cd programs
ln -s ../sysroot sysroot 2>/dev/null
if [ ! -d "$TARGET_DIR" ]; then find "." -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do
exit 1
fi
find "$TARGET_DIR" -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do
dir_path=$(dirname "$makefile_path") dir_path=$(dirname "$makefile_path")
( (
cd "$dir_path" || exit cd "$dir_path" || exit
make clean make clean
make bear -- make
) )
done done
cd..

12
build_sysroot.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
mkdir -p sysroot
mkdir -p sysroot/usr
mkdir -p sysroot/dev
mkdir -p sysroot/kernel
mkdir -p sysroot/usr/include
mkdir -p sysroot/usr/lib
mkdir -p sysroot/usr/bin
mkdir -p sysroot/usr/fonts

View File

@@ -1,9 +1,16 @@
#!/bin/bash #!/bin/bash
cd rocklibc # libc
cd rlibc
make clean make clean
cd .. cd ..
# libgui
cd rlibgui
make clean
cd ..
# programs
cd programs cd programs
find . -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do find . -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefile_path; do
dir_path=$(dirname "$makefile_path") dir_path=$(dirname "$makefile_path")
@@ -13,10 +20,10 @@ find . -type f \( -name "Makefile" -o -name "makefile" \) | while read -r makefi
make clean make clean
) )
done done
rm sysroot
cd .. cd ..
# kernel
make clean make clean
cd initrd rm -rf sysroot
rm -f bin/*.elf
cd ..

5
copy_resources.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
cp -r resources/fonts/. sysroot/usr/fonts
cp -r kernel/. sysroot/kernel

View File

@@ -2,6 +2,8 @@
#include <drivers/ps2/ps2.h> #include <drivers/ps2/ps2.h>
#include <vfs.h>
static const char scancode_to_ascii[] = { static const char scancode_to_ascii[] = {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b',
'\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n',
@@ -73,7 +75,11 @@ int init_ps2() {
write_ccb(ccb); write_ccb(ccb);
return 0; return 0;
} }
void ps2_init_kbd(vfs_node_t* dev) {
}
char ps2_get_ascii(uint8_t scancode) { char ps2_get_ascii(uint8_t scancode) {
if (scancode & 0x80) { if (scancode & 0x80) {
@@ -88,4 +94,5 @@ char ps2_get_ascii(uint8_t scancode) {
} }
return 0; return 0;
} }

View File

@@ -18,8 +18,10 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
#include <stdint.h> #include <stdint.h>
#include <vfs.h>
int init_ps2(); int init_ps2();
void ps2_init_kbd(vfs_node_t* dev);
uint8_t ps2_read_data(); uint8_t ps2_read_data();
char ps2_get_ascii(uint8_t scancode); char ps2_get_ascii(uint8_t scancode);

View File

@@ -2,7 +2,7 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <lib/stream.h> #include <lib/print.h>
#include <drivers/vga/vga.h> #include <drivers/vga/vga.h>
#include <drivers/serial/serial.h> #include <drivers/serial/serial.h>
@@ -10,7 +10,7 @@
#include <common.h> #include <common.h>
#include <memory/mm.h> #include <memory/mm.h>
#include <user/video.h> #include <sys/video.h>
static uint32_t framebuffer_address; static uint32_t framebuffer_address;
static uint32_t framebuffer_width; static uint32_t framebuffer_width;
@@ -19,25 +19,11 @@ static uint32_t framebuffer_total_pixels;
static uint32_t framebuffer_pitch; static uint32_t framebuffer_pitch;
static uint32_t framebuffer_bpp; static uint32_t framebuffer_bpp;
static uint8_t red_mask_sz;
static uint8_t red_field_pos;
static uint8_t green_mask_sz;
static uint8_t green_field_pos;
static uint8_t blue_mask_sz;
static uint8_t blue_field_pos;
static uint32_t create_pixel(uint8_t r, uint8_t g, uint8_t b) {
return (r >> (8 - red_mask_sz)) << red_field_pos
| (g >> (8 - green_mask_sz)) << green_field_pos
| (b >> (8 - blue_mask_sz)) << blue_field_pos;
}
vga_color_t VGA_COLOR_BLACK = {0, 0, 0, 255}; vga_color_t VGA_COLOR_BLACK = {0, 0, 0, 255};
vga_color_t VGA_COLOR_RED = {0, 0, 255, 255}; vga_color_t VGA_COLOR_RED = {0, 0, 255, 255};
vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255}; vga_color_t VGA_COLOR_GREEN = {0, 255, 0, 255};
vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255}; vga_color_t VGA_COLOR_BLUE = {255, 0, 0, 255};
uint32_t vga_mmap(vfs_node_t* node, uint32_t address) { uint32_t vga_mmap(vfs_node_t* node, uint32_t address) {
uint32_t fb_size_bytes = framebuffer_height * framebuffer_pitch; uint32_t fb_size_bytes = framebuffer_height * framebuffer_pitch;
uint32_t num_pages = (fb_size_bytes + 4095) / 4096; uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
@@ -77,6 +63,8 @@ void vga_init(
framebuffer_pitch = fb_pitch; framebuffer_pitch = fb_pitch;
framebuffer_bpp = fb_bpp; framebuffer_bpp = fb_bpp;
kprintf("mapping vga pages\n");
uint32_t fb_size_bytes = fb_height * fb_pitch; uint32_t fb_size_bytes = fb_height * fb_pitch;
uint32_t num_pages = (fb_size_bytes + 4095) / 4096; uint32_t num_pages = (fb_size_bytes + 4095) / 4096;
for (uint32_t i = 0; i < num_pages; i++) { for (uint32_t i = 0; i < num_pages; i++) {
@@ -113,9 +101,7 @@ uint8_t vga_get_bpp() {
} }
void vga_clear_scrn(uint32_t color) { void vga_clear_scrn(uint32_t color) {
if (framebuffer_address == 0) return; uint8_t* fb_bytes = (uint8_t*)VGA_FRAMEBUFFER;
uint8_t* fb_bytes = (uint8_t*)framebuffer_address;
uint8_t bytes_per_pixel = framebuffer_bpp / 8; uint8_t bytes_per_pixel = framebuffer_bpp / 8;
for (uint32_t y = 0; y < framebuffer_height; y++) { for (uint32_t y = 0; y < framebuffer_height; y++) {

View File

@@ -1,4 +1,3 @@
#include "lib/font.h"
#include "multiboot.h" #include "multiboot.h"
#include "interrupts.h" #include "interrupts.h"
#include "gdt.h" #include "gdt.h"
@@ -166,20 +165,16 @@ void kmain(multiboot_info* mbi) {
dev->mnt = devfs; dev->mnt = devfs;
kprintf("mounted devfs\n"); kprintf("mounted devfs\n");
console_init(); int font_loaded = set_console_font("/usr/fonts/kernel_font.psf");
kprintf("kernel console initialized\n");
int font_loaded = set_console_font("/fonts/kernel_font.psf");
if (!font_loaded) { if (!font_loaded) {
kprintf("failed to load console font\n"); kprintf("failed to load console font\n");
} }
console_init();
kprintf("console font set\n"); kprintf("kernel console initialized\n");
kprintf("basic initializations complete. check serial for details\n"); kprintf("basic initializations complete. check serial for details\n");
kprintf("starting rockos\n"); kprintf("starting rockos\n");
load_root_program("/bin/vga_text_term.elf");
kprintf("kernel going to sleep...\n"); load_root_program("/usr/bin/rockterm");
} }

View File

@@ -16,7 +16,6 @@ static uint32_t console_text_color;
static uint32_t console_backgrnd_color; static uint32_t console_backgrnd_color;
static void write_vga_char(char c) { static void write_vga_char(char c) {
print_serial("write_vga_char invoked\r\n");
uint32_t vga_pitch = vga_get_pitch(); uint32_t vga_pitch = vga_get_pitch();
uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz); uint8_t* glyph = (uint8_t*)font->glyphs + (c * font->hdr->charsz);
@@ -71,7 +70,6 @@ void console_putchar(char c) {
if (!font) return; if (!font) return;
if (c == '\n') { if (c == '\n') {
print_serial("\r\n");
console_col = 0; console_col = 0;
console_row++; console_row++;
if (console_row >= console_height) { if (console_row >= console_height) {
@@ -80,7 +78,6 @@ void console_putchar(char c) {
return; return;
} }
write_serial(c);
write_vga_char(c); write_vga_char(c);
console_col++; console_col++;

View File

@@ -1,12 +1,5 @@
#!/bin/bash #!/bin/bash
mkdir -p initrd cd sysroot
rm -f initrd/bin/*.elf
mkdir -p initrd/dev
mkdir -p initrd/bin
cp programs/bin/* initrd/bin
cd initrd
find . -depth -print | cpio -o -H newc > ../isodir/boot/initrd.img find . -depth -print | cpio -o -H newc > ../isodir/boot/initrd.img
cd .. cd ..

Binary file not shown.

1
programs/rocksh/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
rocksh

View File

@@ -1,10 +1,14 @@
CC = i686-elf-gcc CC = i686-elf-gcc
LD = i686-elf-ld LD = i686-elf-ld
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include SYSROOT = ../sysroot
USR_INCLUDE = $(SYSROOT)/usr/include
USR_LIB = $(SYSROOT)/usr/lib
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I$(USR_INCLUDE)
LDFLAGS = -m elf_i386 -nostdlib LDFLAGS = -m elf_i386 -nostdlib
TARGET = rocksh.elf TARGET = rocksh
all: $(TARGET) all: $(TARGET)
@@ -14,11 +18,12 @@ crt0.o: crt0.S
main.o: main.c main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o $(CC) $(CFLAGS) -c main.c -o main.o
$(TARGET): crt0.o main.o ../lib/rlibc.a $(TARGET): crt0.o main.o $(USR_LIB)/*
$(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET) $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o $(USR_LIB)/* -o $(TARGET)
cp $(TARGET) $(SYSROOT)/usr/bin
clean: clean:
rm -f *.o $(TARGET) compile_commands.json rm -f *.o $(TARGET) compile_commands.json
rm -rf .cache rm -rf .cache
.PHONY: all clean test .PHONY: all clean test

1
programs/rockterm/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
rockterm

View File

@@ -1,46 +1,31 @@
#include "syscall.h"
#include <unistd.h> #include <unistd.h>
#include <sys/video.h> #include <sys/video.h>
#define VGA_TEXT_W 80 typedef struct {
#define VGA_TEXT_H 25
void term(); } font_t;
void term_write_char(char c);
void render_char_at(char c, int x, int y);
int spawn_shell();
int ptys; int ptys;
int ptym; int ptym;
void* fb;
fb_info_t fb_info; fb_info_t fb_info;
void* framebuffer_address;
int terminal_col = 0; int terminal_col = 0;
int terminal_row = 0; int terminal_row = 0;
void term_write_char(char c) { font_t* terminal_font = NULL;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
(void)argc; (void)argc;
(void)argv; (void)argv;
ptym = pty(&ptys);
if (fork() == 0) {
close(ptym);
dup2(ptys, 0);
dup2(0, 1);
dup2(0, 2);
exec("/bin/rocksh.elf");
}
close(ptys);
dup2(ptym, 0);
dup2(0, 1);
dup2(0, 2);
int vga_fd = open("/dev/vga"); int vga_fd = open("/dev/vga");
if (vga_fd == -1) return 1; if (vga_fd == -1) return 1;
@@ -52,9 +37,38 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
framebuffer_address = mmap(vga_fd); mmap(vga_fd);
// if (!spawn_shell()) {
// return 1;
// }
return 0; return 0;
}
void render_char_at(char c, int x, int y) {
if (!terminal_font) return;
}
void term_write_char(char c) {
}
int spawn_shell() {
ptym = pty(&ptys);
if (fork() == 0) {
close(ptym);
dup2(ptys, 0);
dup2(0, 1);
dup2(0, 2);
if (!exec("/usr/bin/rocksh")) return 0;
}
close(ptys);
dup2(ptym, 0);
dup2(0, 1);
dup2(0, 2);
return 1;
} }

View File

@@ -0,0 +1,29 @@
CC = i686-elf-gcc
LD = i686-elf-ld
SYSROOT = ../sysroot
USR_INCLUDE = $(SYSROOT)/usr/include
USR_LIB = $(SYSROOT)/usr/lib
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I$(USR_INCLUDE)
LDFLAGS = -m elf_i386 -nostdlib
TARGET = rockterm
all: $(TARGET)
crt0.o: crt0.S
$(CC) $(CFLAGS) -c crt0.S -o crt0.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
$(TARGET): crt0.o main.o $(USR_LIB)/*
$(LD) $(LDFLAGS) -T linker.ld crt0.o main.o $(USR_LIB)/* -o $(TARGET)
cp $(TARGET) $(SYSROOT)/usr/bin
clean:
rm -f *.o $(TARGET) compile_commands.json
rm -rf .cache
.PHONY: all clean test

View File

@@ -1,6 +0,0 @@
#include <stdio.h>
int main(int argc, char** argv) {
printf("hello, world!\n");
return 0;
}

View File

@@ -1,24 +0,0 @@
CC = i686-elf-gcc
LD = i686-elf-ld
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include
LDFLAGS = -m elf_i386 -nostdlib
TARGET = test.elf
all: $(TARGET)
crt0.o: crt0.S
$(CC) $(CFLAGS) -c crt0.S -o crt0.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
$(TARGET): crt0.o main.o ../lib/rlibc.a
$(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET)
clean:
rm -f *.o $(TARGET) compile_commands.json
rm -rf .cache
.PHONY: all clean test

View File

@@ -1,21 +0,0 @@
.global _start
.extern exit
.section .text
_start:
xor %ebp, %ebp
mov (%esp), %eax
lea 4(%esp), %ebx
lea 8(%esp,%eax,4), %ecx
and $-16, %esp
push %ecx
push %ebx
push %eax
call main
push %eax
call exit

View File

@@ -1,31 +0,0 @@
ENTRY(_start)
SECTIONS
{
. = 0x40000000;
.text ALIGN(4K) :
{
/* Force the crt0.o entry code to be placed FIRST in memory */
KEEP(*crt0.o(.text))
*(.text .text.*)
}
.rodata ALIGN(4K) :
{
*(.rodata .rodata.*)
}
.data ALIGN(4K) :
{
*(.data .data.*)
}
.bss ALIGN(4K) :
{
_bss_start = .;
*(.bss .bss.*)
*(COMMON)
_bss_end = .;
}
}

View File

@@ -1,24 +0,0 @@
CC = i686-elf-gcc
LD = i686-elf-ld
CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include
LDFLAGS = -m elf_i386 -nostdlib
TARGET = vga_text_term.elf
all: $(TARGET)
crt0.o: crt0.S
$(CC) $(CFLAGS) -c crt0.S -o crt0.o
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
$(TARGET): crt0.o main.o ../lib/rlibc.a
$(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET)
clean:
rm -f *.o $(TARGET) compile_commands.json
rm -rf .cache
.PHONY: all clean test

View File

@@ -13,4 +13,5 @@ typedef struct {
uint32_t fb_size; uint32_t fb_size;
} fb_info_t; } fb_info_t;
#endif #endif

View File

@@ -80,5 +80,5 @@ void* mmap(int fd) {
} }
int ioctl(int fd, uint32_t request, void* arg) { int ioctl(int fd, uint32_t request, void* arg) {
return syscall3(SYS_IOCTL, fd, request, arg); return syscall3(SYS_IOCTL, fd, request, (uint32_t)arg);
} }

0
rlibgui/include/psf.h Normal file
View File

20
rlibgui/makefile Normal file
View File

@@ -0,0 +1,20 @@
CC = i686-elf-gcc
AR = i686-elf-ar
CFLAGS = -ffreestanding -O2 -Wall -Wextra -Iinclude
TARGET = rlibgui.a
SRCS = $(shell find src -name "*.c")
OBJS = $(SRCS:.c=.o)
all: $(TARGET)
$(TARGET): $(OBJS)
$(AR) rcs $@ $(OBJS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f $(OBJS) $(TARGET) compile_commands.json
.PHONY: all clean

BIN
rlibgui/rlibgui.a Normal file

Binary file not shown.

0
rlibgui/src/psf.c Normal file
View File

Binary file not shown.