mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Got .bin file execution working (badly). Will need to do something with syscalls probably
This commit is contained in:
@@ -7,12 +7,13 @@ CFLAGS = -ffreestanding -m32 -Iinclude -Wall -Wextra
|
||||
|
||||
SRC = ./src
|
||||
BUILD = ./build
|
||||
C_FILES = calc
|
||||
# C_FILES = $(shell find $(SRC) -name "*.c" -exec basename -s ".c" {} \;)
|
||||
|
||||
.PHONY: os clean run
|
||||
|
||||
# Main compilation target
|
||||
os: $(BUILD) bootloader kernel
|
||||
os: $(BUILD) bootloader kernel $(C_FILES)
|
||||
@echo "Assembling $(SRC)/testfont.asm..."
|
||||
@$(AS) -fbin -o $(BUILD)/testfont.bin $(SRC)/testfont.asm
|
||||
@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)/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=$(BUILD)/calc.bin of=kern.iso bs=512 seek=40 conv=notrunc status=none
|
||||
@echo "\nDone!\n"
|
||||
|
||||
$(BUILD):
|
||||
@@ -44,6 +46,13 @@ kernel: $(SRC)/kernel.c $(SRC)/entry.asm
|
||||
@echo "Compiling $(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
|
||||
@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:
|
||||
|
||||
+11
@@ -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
@@ -0,0 +1,14 @@
|
||||
SECTIONS {
|
||||
.text 0x10000 : {
|
||||
*(.text*);
|
||||
}
|
||||
.data : {
|
||||
*(.data*);
|
||||
}
|
||||
.rodata : {
|
||||
*(.rodata*);
|
||||
}
|
||||
.bss : {
|
||||
*(.bss*);
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ filetable:
|
||||
db "kernel",0,0,0,0, "bin",0,5,30
|
||||
db "testfont",0,0, "fnt",0,35,4
|
||||
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
|
||||
|
||||
|
||||
+58
-45
@@ -14,6 +14,9 @@
|
||||
// TODO: Put this at a set address
|
||||
char filetable[512];
|
||||
|
||||
// Function declarations
|
||||
void printFiletable(char* ft);
|
||||
|
||||
void main() {
|
||||
// Interrupts
|
||||
setupIdt();
|
||||
@@ -159,44 +162,7 @@ void main() {
|
||||
print(" reboot | Reboots the system\n");
|
||||
print(" test | Performs tests\n");
|
||||
} else if (strcmp(input, "ls") == 0) {
|
||||
char* ft = 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");
|
||||
}
|
||||
}
|
||||
printFiletable(filetable);
|
||||
} else if (strcmp(input, "reboot") == 0) {
|
||||
outb(0x64, 0xFE);
|
||||
} else if (strcmp(input, "test") == 0) {
|
||||
@@ -240,21 +206,29 @@ void main() {
|
||||
ft++; // RESERVED
|
||||
uint8_t sector = *ft++;
|
||||
uint8_t size = *ft++;
|
||||
found++; // Set found to 1
|
||||
|
||||
char buf[size * 512];
|
||||
diskRead(sector, size, buf);
|
||||
|
||||
// TODO: Print .txt files, launch .bin files
|
||||
// For calling .bin files, use '((void (*)(void))buf)()' to jump to it
|
||||
char* fileType = strchr(filename, '.') + 1;
|
||||
|
||||
for (size_t i = 0; i < size * 512; i++) {
|
||||
if (buf[i] != '\0') {
|
||||
putc(buf[i]);
|
||||
if (strcmp(fileType, "bin") == 0) {
|
||||
memcopy(buf, (char*)0x10000, size * 512);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user