Got .bin file execution working (badly). Will need to do something with syscalls probably

This commit is contained in:
2024-04-21 18:09:55 +02:00
parent 6e44e5d729
commit 26cefb5916
5 changed files with 94 additions and 46 deletions
+10 -1
View File
@@ -7,12 +7,13 @@ CFLAGS = -ffreestanding -m32 -Iinclude -Wall -Wextra
SRC = ./src SRC = ./src
BUILD = ./build BUILD = ./build
C_FILES = calc
# C_FILES = $(shell find $(SRC) -name "*.c" -exec basename -s ".c" {} \;) # C_FILES = $(shell find $(SRC) -name "*.c" -exec basename -s ".c" {} \;)
.PHONY: os clean run .PHONY: os clean run
# Main compilation target # Main compilation target
os: $(BUILD) bootloader kernel os: $(BUILD) bootloader kernel $(C_FILES)
@echo "Assembling $(SRC)/testfont.asm..." @echo "Assembling $(SRC)/testfont.asm..."
@$(AS) -fbin -o $(BUILD)/testfont.bin $(SRC)/testfont.asm @$(AS) -fbin -o $(BUILD)/testfont.bin $(SRC)/testfont.asm
@echo "Building filesystem..." @echo "Building filesystem..."
@@ -23,6 +24,7 @@ os: $(BUILD) bootloader kernel
@dd if=$(BUILD)/os.bin of=kern.iso conv=notrunc status=none @dd if=$(BUILD)/os.bin of=kern.iso conv=notrunc status=none
@dd if=$(BUILD)/testfont.bin of=kern.iso bs=512 seek=35 conv=notrunc status=none @dd if=$(BUILD)/testfont.bin of=kern.iso bs=512 seek=35 conv=notrunc status=none
@dd if=$(SRC)/fs/test.txt of=kern.iso bs=512 seek=39 conv=notrunc status=none @dd if=$(SRC)/fs/test.txt of=kern.iso bs=512 seek=39 conv=notrunc status=none
@dd if=$(BUILD)/calc.bin of=kern.iso bs=512 seek=40 conv=notrunc status=none
@echo "\nDone!\n" @echo "\nDone!\n"
$(BUILD): $(BUILD):
@@ -44,6 +46,13 @@ kernel: $(SRC)/kernel.c $(SRC)/entry.asm
@echo "Compiling $(SRC)/kernel.c..." @echo "Compiling $(SRC)/kernel.c..."
@$(CC) $(CFLAGS) -o $(BUILD)/kernel.o -c $(SRC)/kernel.c @$(CC) $(CFLAGS) -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
@$(LD) -T $(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o @$(LD) -T $(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/*.o
@rm $(BUILD)/*.o
$(C_FILES):
@echo "Compiling $(SRC)/$@.c..."
@$(CC) $(CFLAGS) -o $(BUILD)/$@.o -c $(SRC)/$@.c
@$(LD) -T $(SRC)/$@.ld --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o
@rm $(BUILD)/$@.o
# Run QEMU # Run QEMU
run: run:
+11
View File
@@ -0,0 +1,11 @@
void main() {
int wait = 0xfffffff;
unsigned int *vidmem = *(unsigned int**)(0x5000 + 40);
vidmem[8000] = 0x00ffffff;
while (wait != 0) wait--;
return;
}
+14
View File
@@ -0,0 +1,14 @@
SECTIONS {
.text 0x10000 : {
*(.text*);
}
.data : {
*(.data*);
}
.rodata : {
*(.rodata*);
}
.bss : {
*(.bss*);
}
}
+1
View File
@@ -15,6 +15,7 @@ filetable:
db "kernel",0,0,0,0, "bin",0,5,30 db "kernel",0,0,0,0, "bin",0,5,30
db "testfont",0,0, "fnt",0,35,4 db "testfont",0,0, "fnt",0,35,4
db "test",0,0,0,0,0,0, "txt",0,39,1 db "test",0,0,0,0,0,0, "txt",0,39,1
db "calc",0,0,0,0,0,0, "bin",0,40,2
times 512-($-$$) db 0 times 512-($-$$) db 0
+58 -45
View File
@@ -14,6 +14,9 @@
// TODO: Put this at a set address // TODO: Put this at a set address
char filetable[512]; char filetable[512];
// Function declarations
void printFiletable(char* ft);
void main() { void main() {
// Interrupts // Interrupts
setupIdt(); setupIdt();
@@ -159,44 +162,7 @@ void main() {
print(" reboot | Reboots the system\n"); print(" reboot | Reboots the system\n");
print(" test | Performs tests\n"); print(" test | Performs tests\n");
} else if (strcmp(input, "ls") == 0) { } else if (strcmp(input, "ls") == 0) {
char* ft = filetable; printFiletable(filetable);
while (*ft != '\0') {
char filename[15] = { 0 };
uint8_t offset = 0;
for (uint8_t i = 0; i < 14; i++) {
if (i == 9) {
filename[offset++] = '.';
continue;
}
if (*ft != '\0') { filename[offset++] = *ft; }
ft++;
}
ft++; // RESERVED
uint8_t sector = *ft++;
uint8_t size = *ft++;
if (sector < 10) putc('0');
if (sector == 0) putc('0');
else print(itoa(sector, 10));
print(": ");
print(filename);
for (uint8_t i = 14 - strlen(filename); i > 0; i--) {
putc(' ');
}
print(" | ");
if (size >> 1) {
print(itoa(size >> 1, 10));
if (size & 0x01) { print(".5"); }
print("kB\n");
} else {
print(itoa(size*512, 10));
print("B\n");
}
}
} else if (strcmp(input, "reboot") == 0) { } else if (strcmp(input, "reboot") == 0) {
outb(0x64, 0xFE); outb(0x64, 0xFE);
} else if (strcmp(input, "test") == 0) { } else if (strcmp(input, "test") == 0) {
@@ -240,21 +206,29 @@ void main() {
ft++; // RESERVED ft++; // RESERVED
uint8_t sector = *ft++; uint8_t sector = *ft++;
uint8_t size = *ft++; uint8_t size = *ft++;
found++; // Set found to 1
char buf[size * 512]; char buf[size * 512];
diskRead(sector, size, buf); diskRead(sector, size, buf);
// TODO: Print .txt files, launch .bin files char* fileType = strchr(filename, '.') + 1;
// For calling .bin files, use '((void (*)(void))buf)()' to jump to it
for (size_t i = 0; i < size * 512; i++) { if (strcmp(fileType, "bin") == 0) {
if (buf[i] != '\0') { memcopy(buf, (char*)0x10000, size * 512);
putc(buf[i]); clear();
((void(*)(void))0x10000)(); // Call program
clear();
} else if (strcmp(fileType, "tab") == 0) {
printFiletable(buf);
} else {
for (size_t i = 0; i < size * 512; i++) {
if (buf[i] != '\0') {
putc(buf[i]);
}
} }
putc('\n');
} }
putc('\n');
found++; // Set found to 1
break; break;
} }
@@ -270,3 +244,42 @@ void main() {
} }
} }
void printFiletable(char* ft) {
while (*ft != '\0') {
char filename[15] = { 0 };
uint8_t offset = 0;
for (uint8_t i = 0; i < 14; i++) {
if (i == 9) {
filename[offset++] = '.';
continue;
}
if (*ft != '\0') { filename[offset++] = *ft; }
ft++;
}
ft++; // RESERVED
uint8_t sector = *ft++;
uint8_t size = *ft++;
if (sector < 10) putc('0');
if (sector == 0) putc('0');
else print(itoa(sector, 10));
print(": ");
print(filename);
for (uint8_t i = 14 - strlen(filename); i > 0; i--) {
putc(' ');
}
print(" | ");
if (size >> 1) {
print(itoa(size >> 1, 10));
if (size & 0x01) { print(".5"); }
print("kB\n");
} else {
print(itoa(size*512, 10));
print("B\n");
}
}
}