TCC-anothertry begins

This commit is contained in:
Jarkko Toivanen 2023-09-19 19:51:51 +03:00
parent 946c9e468d
commit 12e7efb8b5
Signed by: jt
GPG key ID: 9151B109B73ECAD5
6 changed files with 87 additions and 84 deletions

View file

@ -1,23 +1,21 @@
all: build/kernel-i386.elf all: build/kernel-i386.elf
clean: clean:
-@rm build/*.o build/*.elf 2> /dev/null || true -@rm build/* 2> /dev/null || true
build/start32.o: build/ src/start32.asm build/kernel-i386.elf: src/*
nasm -felf32 src/start32.asm -o build/start32.o tcc -m32 -nostdlib -Wl,-Ttext,0x100000 -o build/kernel-i386.elf src/start32.s src/*.c
build/kernel-i386.elf: build/start32.o
tcc -m32 -nostdlib -Wl,-Ttext,0x100000 -o build/kernel-i386.elf src/*.c build/start32.o
image: build/kernel-i386.elf mount image: build/kernel-i386.elf mount
cp build/kernel-i386.elf mnt/ cp build/kernel-i386.elf mnt/roska/start32.elf
sync sync
qemu-multiboot: build/kernel-i386.elf qemu-multiboot: build/kernel-i386.elf
qemu-system-i386 -kernel build/kernel-i386.elf -serial stdio qemu-system-i386 -kernel build/kernel-i386.elf -serial stdio
qemu-image: image qemu-image: image
qemu-system-i386 koalemos.img -serial stdio qemu-system-i386 roska.img -serial stdio
mount: koalemos.img mnt/ mount: roska.img mnt/
@if ! mountpoint -q "mnt/"; then \ @if ! mountpoint -q "mnt/"; then \
sudo mount -o loop,offset=1048576,umask=177,dmask=022,uid=$(shell id -u),gid=$(shell id -g) koalemos.img mnt/; \ sudo mount -o loop,offset=1048576,umask=177,dmask=022,uid=$(shell id -u),gid=$(shell id -g) roska.img mnt/; \
fi; fi;
umount: umount:
@sudo umount mnt @sudo umount mnt

View file

@ -1,9 +1,10 @@
# KoalemOS # rOSka
Multiboot compatible stupid useless OS-like project. Multiboot compatible stupid useless OS-like project.
## Compatibility ## Compatibility
32bit x86 legacy BIOS system - x86 system with MultiBoot compatible bootloader.
- Linear framebuffer graphics
## Building ## Building
NASM and TinyCCompiler are used. TinyCCompiler is used, even for assembly lol.
TCC might need manual compilation for 32bit crosscompilation TCC might need manual compilation for 32bit crosscompilation
on 64bit systems. on 64bit systems.
Just download the source and `make cross` or something. Just download the source and `make cross` or something.

View file

@ -1,3 +1,4 @@
#include "multiboot.h" #include "multiboot.h"
#include "framebuffer.h" #include "framebuffer.h"
#include "serial.h" #include "serial.h"
@ -19,7 +20,7 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
outb(0x3D5, 0x20); outb(0x3D5, 0x20);
int serial_initialized = serial_init(); int serial_initialized = serial_init();
serial_write_string("\n=== KoalemOS ===\n"); serial_write_string("\n=== rOSka ===\n");
// Check multiboot header // Check multiboot header
if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) { if (mbootmagick != MULTIBOOT_BOOTLOADER_MAGIC) {
@ -73,11 +74,11 @@ void kmain (unsigned int mbootmagick, multiboot_info_t* mbootinfo) {
for(;;) { for(;;) {
for(y=0; y < mbootinfo->framebuffer_height; y++) { for(y=0; y < mbootinfo->framebuffer_height; y++) {
for(x=0; x < mbootinfo->framebuffer_width; x++) { for(x=0; x < mbootinfo->framebuffer_width; x++) {
putpixel(x, y, c, c, c, 0xff); putpixel(x, y, 0, c, c, 0xff);
} }
} }
c+=4; c+=4;
} }
serial_write_string("\nExecution finished, halting..."); serial_write_string("\nExecution finished, halting...\n");
} }

View file

@ -20,30 +20,31 @@ int serial_init() {
outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(PORT + 4, 0x1E); // Set in loopback mode, test the serial chip 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 outb(PORT + 0, 0xAE); // Test serial chip (send byte 0xAE and check if serial
// returns same byte) // returns same byte)
// Check if serial is faulty (i.e: not same byte as sent) // Check if serial is faulty (i.e: not same byte as sent)
if (inb(PORT + 0) != 0xAE) { if (inb(PORT + 0) != 0xAE) {
return 1; return 1;
}
// If serial is not faulty set it in normal operation mode
// (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
outb(PORT + 4, 0x0F);
return 0;
}
static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; }
static void serial_write_char(char chr) {
while (serial_is_transmit_empty() == 0);
outb(PORT, chr);
} }
void serial_write_string(const char* text) { // If serial is not faulty set it in normal operation mode
int i = 0; // (not-loopback with IRQs enabled and OUT#1 and OUT#2 bits enabled)
while(text[i]) { outb(PORT + 4, 0x0F);
serial_write_char(text[i]); return 0;
i++; }
}
static int serial_is_transmit_empty() { return inb(PORT + 5) & 0x20; }
static void serial_write_char(char chr) {
while (serial_is_transmit_empty() == 0);
outb(PORT, chr);
}
void serial_write_string(const char* text) {
int i = 0;
while(text[i]) {
serial_write_char(text[i]);
i++;
} }
}

View file

@ -1,47 +0,0 @@
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_PAGE_ALIGN equ 1 << 0
MULTIBOOT_MEMORY_INFO equ 1 << 1
MULTIBOOT_VIDEO_REQUEST equ 0 << 2
MULTIBOOT_AOUT_KLUDGE equ 0 << 16
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_VIDEO_REQUEST
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO | MULTIBOOT_VIDEO_REQUEST | MULTIBOOT_AOUT_KLUDGE
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
section .multiboot
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_CHECKSUM
dd 0 ; header address
dd 0 ; load address
dd 0 ; load end address
dd 0 ; bss end address
dd 0 ; entry address
dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!)
dd 1024 ; video width
dd 768 ; video height
dd 32 ; video depth
section .bss
align 16
stack_bottom:
resb 16384
stack_top:
section .text
global _start
extern kmain
_start:
; Setup stack
mov esp, stack_top
; Call the main kernel function.
push ebx
push eax
call kmain
.hang:
cli
hlt
jmp .hang

49
src/start32.s Normal file
View file

@ -0,0 +1,49 @@
.set MULTIBOOT_PAGE_ALIGN, 1 << 0
.set MULTIBOOT_MEMORY_INFO, 1 << 1
.set MULTIBOOT_VIDEO_REQUEST, 1 << 2
.set MULTIBOOT_AOUT_KLUDGE, 0 << 16
.set MULTIBOOT_HEADER_MAGIC, 0x1BADB002
.set MULTIBOOT_HEADER_FLAGS, \
MULTIBOOT_PAGE_ALIGN |\
MULTIBOOT_MEMORY_INFO |\
MULTIBOOT_VIDEO_REQUEST |\
MULTIBOOT_AOUT_KLUDGE
.set MULTIBOOT_CHECKSUM, -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
#.section ".multiboottbabeee"
.align 4
.long MULTIBOOT_HEADER_MAGIC
.long MULTIBOOT_HEADER_FLAGS
.long MULTIBOOT_CHECKSUM
.long 0 # header address
.long 0 # load address
.long 0 # load end address
.long 0 # bss end address
.long 0 # entry address
.long 0 # video mode_type (0:fb, 1:txt) (set flags[2]!)
.long 1024 # video width
.long 768 # video height
.long 32 # video depth
.bss
.align 16
stack_bottom:
.skip 16384 # 16k
stack_top:
.text
.global _start
_start:
# Setup stack
mov $stack_top, %esp
# Call the main kernel function.
push %ebx
push %eax
call kmain
cli
1: hlt
jmp 1b
#include "lol.s"