mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Commited some old changes, idk what they were
This commit is contained in:
+14
-2
@@ -1,3 +1,15 @@
|
|||||||
build
|
.DS_Store
|
||||||
kern.iso
|
|
||||||
|
# Binaries
|
||||||
|
bin/
|
||||||
|
*.bin
|
||||||
makedisk
|
makedisk
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
*.elf
|
||||||
|
|
||||||
|
# Vim swap files
|
||||||
|
*.swp
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# Variables
|
# Variables
|
||||||
CC = i386-elf-gcc
|
CC = i686-elf-gcc
|
||||||
LD = i386-elf-ld
|
LD = i686-elf-ld
|
||||||
AS = nasm
|
AS = nasm
|
||||||
|
|
||||||
CFLAGS = -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
CFLAGS = -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
||||||
@@ -8,51 +8,51 @@ CFLAGS = -std=c17 -ffreestanding -fno-builtin -fno-stack-protector -fno-pie \
|
|||||||
LDFLAGS = -z notext -melf_i386
|
LDFLAGS = -z notext -melf_i386
|
||||||
|
|
||||||
SRC = ./src
|
SRC = ./src
|
||||||
BUILD = ./build
|
BIN = ./bin
|
||||||
C_FILES = calc editor
|
C_FILES = calc editor
|
||||||
FONTS = testfont term16n
|
FONTS = testfont term16n
|
||||||
|
|
||||||
.PHONY: os clean run
|
.PHONY: os clean run
|
||||||
|
|
||||||
# Main compilation target
|
# Main compilation target
|
||||||
os: $(BUILD) bootloader kernel $(C_FILES) $(FONTS)
|
os: $(BIN) bootloader kernel $(C_FILES) $(FONTS)
|
||||||
@cc ./makedisk.c -o ./makedisk
|
@cc ./makedisk.c -o ./makedisk
|
||||||
@./makedisk # TODO: List of files
|
@./makedisk # TODO: List of files
|
||||||
@echo "\nDone!\n"
|
@echo "\nDone!\n"
|
||||||
|
|
||||||
$(BUILD):
|
$(BIN):
|
||||||
@[ -d $(BUILD) ] || mkdir $(BUILD)
|
@[ -d $(BIN) ] || mkdir $(BIN)
|
||||||
@rm -rf $(BUILD)/*
|
@rm -rf $(BIN)/*
|
||||||
|
|
||||||
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
# Bootloader: This target is responsible for creating stage?.bin (1,2,3)
|
||||||
bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
bootloader: $(SRC)/stage1.asm $(SRC)/stage2.asm
|
||||||
@echo "Assembling $(SRC)/stage1.asm..."
|
@echo "Assembling $(SRC)/stage1.asm..."
|
||||||
@$(AS) -fbin -o $(BUILD)/stage1.bin $(SRC)/stage1.asm
|
@$(AS) -fbin -o $(BIN)/stage1.bin $(SRC)/stage1.asm
|
||||||
@echo "Assembling $(SRC)/stage2.asm..."
|
@echo "Assembling $(SRC)/stage2.asm..."
|
||||||
@$(AS) -fbin -o $(BUILD)/stage2.bin $(SRC)/stage2.asm
|
@$(AS) -fbin -o $(BIN)/stage2.bin $(SRC)/stage2.asm
|
||||||
@echo "Compiling $(SRC)/stage3.c..."
|
@echo "Compiling $(SRC)/stage3.c..."
|
||||||
@$(CC) $(CFLAGS) -Iinclude -o $(BUILD)/stage3.o -c $(SRC)/stage3.c
|
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/stage3.o -c $(SRC)/stage3.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BUILD)/stage3.bin $(BUILD)/stage3.o
|
@$(LD) $(LDFLAGS) -T$(SRC)/stage3.ld --oformat binary -o $(BIN)/stage3.bin $(BIN)/stage3.o
|
||||||
@rm $(BUILD)/stage3.o
|
@rm $(BIN)/stage3.o
|
||||||
|
|
||||||
# Kernel: This target is responsible for creating kernel.bin
|
# Kernel: This target is responsible for creating kernel.bin
|
||||||
kernel: $(SRC)/kernel.c
|
kernel: $(SRC)/kernel.c
|
||||||
@echo "Compiling $(SRC)/kernel.c..."
|
@echo "Compiling $(SRC)/kernel.c..."
|
||||||
@$(CC) $(CFLAGS) -Iinclude -o $(BUILD)/kernel.o -c $(SRC)/kernel.c
|
@$(CC) $(CFLAGS) -Iinclude -o $(BIN)/kernel.o -c $(SRC)/kernel.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BUILD)/kernel.bin $(BUILD)/kernel.o
|
@$(LD) $(LDFLAGS) -T$(SRC)/kernel.ld --oformat binary -o $(BIN)/kernel.bin $(BIN)/kernel.o
|
||||||
@rm $(BUILD)/kernel.o
|
@rm $(BIN)/kernel.o
|
||||||
|
|
||||||
# This target compiles *.c (except kernel.c)
|
# This target compiles *.c (except kernel.c)
|
||||||
$(C_FILES):
|
$(C_FILES):
|
||||||
@echo "Compiling $(SRC)/$@.c..."
|
@echo "Compiling $(SRC)/$@.c..."
|
||||||
@$(CC) $(CFLAGS) -o $(BUILD)/$@.o -c $(SRC)/$@.c
|
@$(CC) $(CFLAGS) -o $(BIN)/$@.o -c $(SRC)/$@.c
|
||||||
@$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BUILD)/$@.bin $(BUILD)/$@.o
|
@$(LD) $(LDFLAGS) -T$(SRC)/$@.ld --oformat binary -o $(BIN)/$@.bin $(BIN)/$@.o
|
||||||
@rm $(BUILD)/$@.o
|
@rm $(BIN)/$@.o
|
||||||
|
|
||||||
# This target builds all fonts inside src/fonts
|
# This target builds all fonts inside src/fonts
|
||||||
$(FONTS):
|
$(FONTS):
|
||||||
@echo "Assembling $(SRC)/fonts/$@.asm..."
|
@echo "Assembling $(SRC)/fonts/$@.asm..."
|
||||||
@$(AS) -fbin -o $(BUILD)/$@.fnt $(SRC)/fonts/$@.asm
|
@$(AS) -fbin -o $(BIN)/$@.fnt $(SRC)/fonts/$@.asm
|
||||||
|
|
||||||
# Run QEMU
|
# Run QEMU
|
||||||
run:
|
run:
|
||||||
@@ -64,7 +64,7 @@ run:
|
|||||||
|
|
||||||
# Clean all build files
|
# Clean all build files
|
||||||
clean:
|
clean:
|
||||||
@rm -rf $(BUILD)
|
@rm -rf $(BIN)
|
||||||
@rm -f kern.iso
|
@rm -f kern.iso
|
||||||
@rm makedisk
|
@rm makedisk
|
||||||
|
|
||||||
|
|||||||
+11
-18
@@ -4,23 +4,16 @@ Syscall handlers are prefixed by 'sys_'
|
|||||||
Syscalls can be called using interrupt 0x80
|
Syscalls can be called using interrupt 0x80
|
||||||
The EAX register should countain a syscall number on calling and it will contain a return value (if applicable) after calling
|
The EAX register should countain a syscall number on calling and it will contain a return value (if applicable) after calling
|
||||||
|
|
||||||
Here's a list of syscalls: (and their numbers)
|
--- Syscall Table ---
|
||||||
|
|
||||||
Syscall(0) : Sleep()
|
| NR | SYSC NAME | RETURN (EAX) | ARG0 (EBX) | ARG1 (ECX) | ARG2 (EDX) |
|
||||||
Args: EBX - Number of miliseconds to sleep for
|
| 00 | reserved | - | - | - | - |
|
||||||
|
| 01 | sleep | - | uint ms | - | - |
|
||||||
Syscall(1) : Write()
|
| 02 | read | int count | int fd | char* buf | uint count |
|
||||||
Args: EBX - File descriptor
|
| 03 | write | int count | int fd | char* buf | uint count |
|
||||||
ECX - Buffer to write
|
| 04 | open | int fd | char* path | int oflag | - |
|
||||||
EDX - Length
|
| 05 | close | int status | int fd | - | - |
|
||||||
Returns: Status
|
| 06 | malloc | void* buf | int count | - | - |
|
||||||
|
| 07 | free | - | void* buf | - | - |
|
||||||
Syscall(2) : Read() #TBD
|
| 08 | seek | #TBD | | | |
|
||||||
|
|
||||||
Syscall(3) : Malloc()
|
|
||||||
Args: EBX - Amount of bytes to malloc
|
|
||||||
Returns: Address of allocated memory
|
|
||||||
|
|
||||||
Syscall(4) : Free()
|
|
||||||
Args: EBX - Pointer to free
|
|
||||||
|
|
||||||
|
|||||||
+31
-13
@@ -1,23 +1,41 @@
|
|||||||
#ifndef SYSCALLNUMS_H
|
#ifndef SYSCALLNUMS_H
|
||||||
#define SYSCALLNUMS_H
|
#define SYSCALLNUMS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#define MAX_SYSCALLS 9
|
||||||
|
|
||||||
#define MAX_SYSCALLS 5
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
SYS_SLEEP,
|
|
||||||
SYS_WRITE,
|
|
||||||
SYS_GETS,
|
|
||||||
SYS_MALLOC,
|
|
||||||
SYS_FREE,
|
|
||||||
} SYSCALL_NUMBERS;
|
|
||||||
|
|
||||||
// TODO: Add malloc() and free() syscall wrappers??
|
// TODO: Add malloc() and free() syscall wrappers??
|
||||||
int32_t write(int32_t fd, const void* buf, uint32_t len) {
|
|
||||||
int32_t result = -1;
|
typedef enum {
|
||||||
|
SYS_RESERVED,
|
||||||
|
SYS_SLEEP,
|
||||||
|
SYS_GETS,
|
||||||
|
SYS_WRITE,
|
||||||
|
SYS_OPEN,
|
||||||
|
SYS_CLOSE,
|
||||||
|
SYS_MALLOC,
|
||||||
|
SYS_FREE,
|
||||||
|
SYS_SEEK,
|
||||||
|
} SYSCALL_NUMBERS;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
O_CREAT = 0x1, // Create if does not exist
|
||||||
|
O_RDONLY = 0x2, // Read only
|
||||||
|
O_WRONLY = 0x4, // Write only
|
||||||
|
O_RDWR = 0x8, // Read and write
|
||||||
|
O_APPEND = 0x10, // Always writes at the end (appends)
|
||||||
|
O_TRUNC = 0x20, // Truncate file size and position to 0 on Open
|
||||||
|
} OFLAGS;
|
||||||
|
|
||||||
|
int write(int fd, const void* buf, unsigned int len) {
|
||||||
|
int result = -1;
|
||||||
__asm__ volatile ("int $0x80" : "=a"(result) : "a"(SYS_WRITE), "b"(fd), "c"(buf), "d"(len));
|
__asm__ volatile ("int $0x80" : "=a"(result) : "a"(SYS_WRITE), "b"(fd), "c"(buf), "d"(len));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int open(const char* path, int oflag) {
|
||||||
|
int result = -1;
|
||||||
|
__asm__ volatile ("int $0x80" : "=a"(result) : "a"(SYS_OPEN), "b"(path), "c"(oflag));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
#ifndef FILESYS_H
|
|
||||||
#define FILESYS_H
|
|
||||||
|
|
||||||
#include <disk/disk.h>
|
|
||||||
#include <memory/addresses.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
char filename[10];
|
|
||||||
char filetype[3];
|
|
||||||
uint8_t reserved;
|
|
||||||
uint8_t startAddress;
|
|
||||||
uint8_t length;
|
|
||||||
} __attribute__ ((packed)) fileEntry_t;
|
|
||||||
|
|
||||||
char* filetable = (char*)FILETABLE_LOC; // Pretty sure we don't have to care about the bootloader at 0x7c00
|
|
||||||
|
|
||||||
fileEntry_t* findFile(const char* filename) {
|
|
||||||
if (strlen(filename) > 14) { return NULL; } // Filename too long
|
|
||||||
static char filenameBuf[16];
|
|
||||||
strcpy(filenameBuf, filename);
|
|
||||||
|
|
||||||
char* filetype = strchr(filenameBuf, '.');
|
|
||||||
*filetype++ = '\0'; // Split filename and filetype by a NULL
|
|
||||||
|
|
||||||
char* ft = filetable;
|
|
||||||
while (*ft != '\0') {
|
|
||||||
if (strcmp(filenameBuf, ft) != 0) { // Filename doesn't match
|
|
||||||
ft += 16; // Goto next entry
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ft += 10; // Goto filetype
|
|
||||||
|
|
||||||
if (strcmp(filetype, ft) != 0) {
|
|
||||||
ft += 6; // Goto next entry
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ft -= 10; // Go back to start of entry
|
|
||||||
|
|
||||||
return (fileEntry_t*)ft;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL; // No such file
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateFiletable() {
|
|
||||||
// TODO: Update the filetable by writing data from memory to disk!
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t readFile(char* filename, void* buffer) { // Hopefully the buffer is large enought :/
|
|
||||||
fileEntry_t* file = findFile(filename);
|
|
||||||
if (file == NULL) { return 1; } // File doesn't exist!
|
|
||||||
|
|
||||||
diskRead(file->startAddress, file->length, buffer);
|
|
||||||
return 0; // Success
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t writeFile(char* filename, void* buffer) { // TODO: Add length so we don't write too much/too little
|
|
||||||
fileEntry_t* file = findFile(filetable);
|
|
||||||
if (file == NULL) { // File exists -> override
|
|
||||||
// File doesn't exist -> create new file
|
|
||||||
file = (fileEntry_t*)filetable;
|
|
||||||
while (*(char*)file != '\0') { file++; } // Find end of the filetable
|
|
||||||
|
|
||||||
*strchr(filename, '.') = '\0';
|
|
||||||
|
|
||||||
char* filetype = filename + strlen(filename); // + 1?
|
|
||||||
fileEntry_t* previous = file - 1;
|
|
||||||
|
|
||||||
strcpy(file->filename, filename);
|
|
||||||
strcpy(file->filetype, filetype);
|
|
||||||
file->startAddress = previous->startAddress + previous->length;
|
|
||||||
file->length = 1; // TODO: Add lenght! Currently will just assume 1 sector :/
|
|
||||||
}
|
|
||||||
|
|
||||||
diskWrite(file->startAddress, file->length, buffer); // Write the file
|
|
||||||
return 0; // Success
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+6
-7
@@ -27,11 +27,11 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t inodeCount;
|
uint32_t inodeCount;
|
||||||
|
|
||||||
uint16_t firstInodeBitmapBlock;
|
uint16_t firstINodeBitmapBlock;
|
||||||
uint16_t firstDataBitmapBlock;
|
uint16_t firstDataBitmapBlock;
|
||||||
uint16_t inodeBitmapBlockCount;
|
uint16_t inodeBitmapBlockCount;
|
||||||
uint16_t dataBitmapBlockCount;
|
uint16_t dataBitmapBlockCount;
|
||||||
uint32_t firstInodeBlock;
|
uint32_t firstINodeBlock;
|
||||||
uint32_t firstDataBlock;
|
uint32_t firstDataBlock;
|
||||||
uint16_t inodeBlockCount;
|
uint16_t inodeBlockCount;
|
||||||
uint16_t dataBlockCount;
|
uint16_t dataBlockCount;
|
||||||
@@ -40,14 +40,14 @@ typedef struct {
|
|||||||
uint16_t blockSize; // in bytes
|
uint16_t blockSize; // in bytes
|
||||||
uint8_t inodeSize; // in bytes
|
uint8_t inodeSize; // in bytes
|
||||||
|
|
||||||
uint32_t rootInodePtr;
|
uint32_t rootINodePtr;
|
||||||
uint8_t inodesPerBlock;
|
uint8_t inodesPerBlock;
|
||||||
uint8_t directExtentsPerInode;
|
uint8_t directExtentsPerINode;
|
||||||
uint16_t extentsPerIndirectBlock;
|
uint16_t extentsPerIndirectBlock;
|
||||||
uint32_t firstFreeInodeBit;
|
uint32_t firstFreeINodeBit;
|
||||||
uint32_t firstFreeDataBit;
|
uint32_t firstFreeDataBit;
|
||||||
uint16_t deviceNumber;
|
uint16_t deviceNumber;
|
||||||
uint8_t firstUnreservedInode;
|
uint8_t firstUnreservedINode;
|
||||||
|
|
||||||
uint8_t reserved[14];
|
uint8_t reserved[14];
|
||||||
} __attribute__ ((packed)) superBlock_t;
|
} __attribute__ ((packed)) superBlock_t;
|
||||||
@@ -87,5 +87,4 @@ uint32_t bytesToSectors(uint32_t bytes) {
|
|||||||
if (bytes <= FS_SECTOR_SIZE) return 1;
|
if (bytes <= FS_SECTOR_SIZE) return 1;
|
||||||
return (bytes / FS_SECTOR_SIZE) + ((bytes % FS_SECTOR_SIZE) > 0 ? 1 : 0);
|
return (bytes / FS_SECTOR_SIZE) + ((bytes % FS_SECTOR_SIZE) > 0 ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#ifndef IMPL_H
|
||||||
|
#define IMPL_H
|
||||||
|
|
||||||
|
#include <disk/disk.h>
|
||||||
|
#include <fs/fs.h>
|
||||||
|
#include <memory/addresses.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
char* currentDir;
|
||||||
|
inode_t currentDirINode;
|
||||||
|
|
||||||
|
char tempSector[FS_SECTOR_SIZE];
|
||||||
|
char tempBlock[FS_BLOCK_SIZE];
|
||||||
|
|
||||||
|
inode_t rootINode;
|
||||||
|
|
||||||
|
inode_t* getINode(char* path) {
|
||||||
|
dirEntry_t* dirEntry = (dirEntry_t*)SCRATCH_BLOCK_LOC;
|
||||||
|
while (dirEntry->name[0] != '\0') {
|
||||||
|
if (strcmp(dirEntry->name, path) == 0) break;
|
||||||
|
dirEntry++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dirEntry->name[0] == '\0') return NULL;
|
||||||
|
|
||||||
|
inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC;
|
||||||
|
while (inode->id != dirEntry->id) {
|
||||||
|
inode++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return inode;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t loadFile(inode_t* inode, void* dest) {
|
||||||
|
uint32_t totalBlocks = bytesToBlocks(inode->sizeBytes);
|
||||||
|
uint32_t addressOffset = 0;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 4 && totalBlocks > 0; i++) {
|
||||||
|
diskRead(inode->extent[i].firstBlock * 8, inode->extent[i].length * 8, dest + addressOffset);
|
||||||
|
addressOffset += inode->extent[i].length * FS_BLOCK_SIZE;
|
||||||
|
totalBlocks -= inode->extent[i].length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (totalBlocks > 0) {
|
||||||
|
// TODO: Indirect extents
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,8 +9,12 @@
|
|||||||
#include <memory/addresses.h>
|
#include <memory/addresses.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <fs/fs.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO WARNING - Update MAX_SYSCALLS in the handler TODO
|
||||||
|
*/
|
||||||
|
|
||||||
// Syscall(0) - Sleep()
|
|
||||||
// Args: ebx - number of miliseconds
|
// Args: ebx - number of miliseconds
|
||||||
void sys_sleep() {
|
void sys_sleep() {
|
||||||
__asm__ volatile ("movl %%ebx, %0" : "=r"(*sleepTimerTicks));
|
__asm__ volatile ("movl %%ebx, %0" : "=r"(*sleepTimerTicks));
|
||||||
@@ -20,7 +24,6 @@ void sys_sleep() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Syscall(1) - Write()
|
|
||||||
// Args: ebx - int fd
|
// Args: ebx - int fd
|
||||||
// ecx - void* buf
|
// ecx - void* buf
|
||||||
// edx - uint32_t len
|
// edx - uint32_t len
|
||||||
@@ -48,7 +51,6 @@ void sys_gets() {
|
|||||||
read(s);
|
read(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Syscall(3) - Malloc()
|
|
||||||
// Args: ebx - amount of bytes to malloc
|
// Args: ebx - amount of bytes to malloc
|
||||||
// Returns: eax - Pointer to allocated memory
|
// Returns: eax - Pointer to allocated memory
|
||||||
void sys_malloc() {
|
void sys_malloc() {
|
||||||
@@ -67,7 +69,6 @@ void sys_malloc() {
|
|||||||
__asm__ volatile ("movl %0, %%eax" : : "r"(ptr));
|
__asm__ volatile ("movl %0, %%eax" : : "r"(ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Syscall(4) - Free()
|
|
||||||
// Args: ebx - allocated pointer
|
// Args: ebx - allocated pointer
|
||||||
void sys_free() {
|
void sys_free() {
|
||||||
void* ptr = NULL;
|
void* ptr = NULL;
|
||||||
@@ -75,6 +76,29 @@ void sys_free() {
|
|||||||
mallocFree(ptr);
|
mallocFree(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Args: ebx - path, ecx - oflag
|
||||||
|
void sys_open() {
|
||||||
|
int32_t fd = -1;
|
||||||
|
char* path = NULL;
|
||||||
|
uint32_t oflag = 0;
|
||||||
|
|
||||||
|
// From kernel.c
|
||||||
|
//extern openFileTable_t* openFileTable;
|
||||||
|
//extern inode_t* openINodeTable;
|
||||||
|
//extern uint32_t maxOpenFiles;
|
||||||
|
//extern uint32_t openFileCount;
|
||||||
|
//extern uint32_t maxOpenInodes;
|
||||||
|
//extern uint32_t openInodeCount;
|
||||||
|
|
||||||
|
__asm__ volatile ("nop" : "=b"(path), "=c"(oflag));
|
||||||
|
|
||||||
|
__asm__ volatile ("movl %0, %%eax" : : "a"(fd));
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_close() {}
|
||||||
|
|
||||||
|
void sys_seek() {}
|
||||||
|
|
||||||
// System call table
|
// System call table
|
||||||
void (*syscalls[MAX_SYSCALLS])(void) = {
|
void (*syscalls[MAX_SYSCALLS])(void) = {
|
||||||
[SYS_SLEEP] = sys_sleep,
|
[SYS_SLEEP] = sys_sleep,
|
||||||
@@ -82,6 +106,9 @@ void (*syscalls[MAX_SYSCALLS])(void) = {
|
|||||||
[SYS_GETS] = sys_gets,
|
[SYS_GETS] = sys_gets,
|
||||||
[SYS_MALLOC] = sys_malloc,
|
[SYS_MALLOC] = sys_malloc,
|
||||||
[SYS_FREE] = sys_free,
|
[SYS_FREE] = sys_free,
|
||||||
|
[SYS_OPEN] = sys_open,
|
||||||
|
[SYS_CLOSE] = sys_close,
|
||||||
|
[SYS_SEEK] = sys_seek,
|
||||||
};
|
};
|
||||||
|
|
||||||
// int 0x80 - Syscall interrupt, handled by this function
|
// int 0x80 - Syscall interrupt, handled by this function
|
||||||
@@ -92,7 +119,7 @@ void syscallHandler(intFrame_t* iframe) {
|
|||||||
// We should also push these regs: ax, gs, fs, es, ds, bp, di, si, dx, cx, bx
|
// We should also push these regs: ax, gs, fs, es, ds, bp, di, si, dx, cx, bx
|
||||||
__asm__ volatile (
|
__asm__ volatile (
|
||||||
".intel_syntax noprefix\n" // We use intel syntax
|
".intel_syntax noprefix\n" // We use intel syntax
|
||||||
".equ MAX_SYSCALLS, 5\n" // Define MAX_SYSCALLS again TODO: I don't want to have to do this
|
".equ MAX_SYSCALLS, 9\n" // Define MAX_SYSCALLS again TODO: I don't want to have to do this
|
||||||
|
|
||||||
// Check if syscall exists
|
// Check if syscall exists
|
||||||
"cmp eax, MAX_SYSCALLS - 1\n"
|
"cmp eax, MAX_SYSCALLS - 1\n"
|
||||||
|
|||||||
@@ -4,19 +4,9 @@
|
|||||||
#include <terminal/terminal.h>
|
#include <terminal/terminal.h>
|
||||||
#include <memory/addresses.h>
|
#include <memory/addresses.h>
|
||||||
#include <screen/gfxmode.h>
|
#include <screen/gfxmode.h>
|
||||||
#include <disk/filesys.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
// TODO: Make this check if it's a valid font
|
|
||||||
// TODO: Make it take a fileEntry_t?
|
|
||||||
uint8_t loadFont(char* filename) {
|
|
||||||
if (readFile(filename, (void*)FONT_LOC) != 0) { return 1; } // File not found
|
|
||||||
if (*(uint8_t*)FONT_WIDTH == 0 || *(uint8_t*)FONT_HEIGHT == 0) { return 1; } // Not a font
|
|
||||||
|
|
||||||
return 0; // Success
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Reimplement larger text
|
// TODO: Reimplement larger text
|
||||||
void drawChar(char c, uint32_t x, uint32_t y, uint32_t fgColor, uint32_t bgColor) {
|
void drawChar(char c, uint32_t x, uint32_t y, uint32_t fgColor, uint32_t bgColor) {
|
||||||
// Font info
|
// Font info
|
||||||
|
|||||||
+17
-16
@@ -8,6 +8,7 @@
|
|||||||
#include "include/fs/fs.h"
|
#include "include/fs/fs.h"
|
||||||
|
|
||||||
#define IMAGE_NAME "kern.iso"
|
#define IMAGE_NAME "kern.iso"
|
||||||
|
#define BIN_DIR "./bin/"
|
||||||
#define DISK_SIZE (2880 * 512) // 1.44MB
|
#define DISK_SIZE (2880 * 512) // 1.44MB
|
||||||
|
|
||||||
uint8_t nullBlock[FS_BLOCK_SIZE] = { 0 };
|
uint8_t nullBlock[FS_BLOCK_SIZE] = { 0 };
|
||||||
@@ -19,15 +20,15 @@ typedef struct {
|
|||||||
} fileInfo_t;
|
} fileInfo_t;
|
||||||
|
|
||||||
fileInfo_t files[] = { // TODO: Not have to list all of the files, loop through a directory or smth
|
fileInfo_t files[] = { // TODO: Not have to list all of the files, loop through a directory or smth
|
||||||
{ "./build/stage1.bin" },
|
{ BIN_DIR"stage1.bin" },
|
||||||
{ "./build/stage2.bin" },
|
{ BIN_DIR"stage2.bin" },
|
||||||
{ "./build/stage3.bin" },
|
{ BIN_DIR"stage3.bin" },
|
||||||
{ "./build/kernel.bin" },
|
{ BIN_DIR"kernel.bin" },
|
||||||
{ "./build/term16n.fnt" },
|
{ BIN_DIR"term16n.fnt" },
|
||||||
{ "./build/testfont.fnt" },
|
{ BIN_DIR"testfont.fnt" },
|
||||||
{ "./src/fs/test.txt" },
|
{ "./src/fs/test.txt" },
|
||||||
{ "./build/calc.bin" },
|
{ BIN_DIR"calc.bin" },
|
||||||
{ "./build/editor.bin" },
|
{ BIN_DIR"editor.bin" },
|
||||||
};
|
};
|
||||||
|
|
||||||
superBlock_t superblock = { 0 };
|
superBlock_t superblock = { 0 };
|
||||||
@@ -117,29 +118,29 @@ void writeBootblock() {
|
|||||||
|
|
||||||
void writeSuperblock() {
|
void writeSuperblock() {
|
||||||
superblock.inodeCount = fileCount; // 2 reserved INodes (0 - Invalid, 1 - Root)
|
superblock.inodeCount = fileCount; // 2 reserved INodes (0 - Invalid, 1 - Root)
|
||||||
superblock.firstInodeBitmapBlock = 2; // Block 0 - Boot, Block 1 - Superblock
|
superblock.firstINodeBitmapBlock = 2; // Block 0 - Boot, Block 1 - Superblock
|
||||||
superblock.inodeBitmapBlockCount = superblock.inodeCount / (FS_BLOCK_SIZE * 8) + ((superblock.inodeCount % (FS_BLOCK_SIZE * 8) > 0) ? 1 : 0);
|
superblock.inodeBitmapBlockCount = superblock.inodeCount / (FS_BLOCK_SIZE * 8) + ((superblock.inodeCount % (FS_BLOCK_SIZE * 8) > 0) ? 1 : 0);
|
||||||
superblock.firstDataBitmapBlock = superblock.firstInodeBitmapBlock + superblock.inodeBitmapBlockCount;
|
superblock.firstDataBitmapBlock = superblock.firstINodeBitmapBlock + superblock.inodeBitmapBlockCount;
|
||||||
superblock.inodeBlockCount = bytesToBlocks(superblock.inodeCount * sizeof(inode_t));
|
superblock.inodeBlockCount = bytesToBlocks(superblock.inodeCount * sizeof(inode_t));
|
||||||
|
|
||||||
dataBlocks = bytesToBlocks(diskSize);
|
dataBlocks = bytesToBlocks(diskSize);
|
||||||
dataBitCount = (dataBlocks - superblock.firstDataBitmapBlock - superblock.inodeBlockCount);
|
dataBitCount = (dataBlocks - superblock.firstDataBitmapBlock - superblock.inodeBlockCount);
|
||||||
|
|
||||||
superblock.dataBitmapBlockCount = dataBitCount / (FS_BLOCK_SIZE * 8) + ((dataBitCount % (FS_BLOCK_SIZE * 8) > 0) ? 1 : 0);
|
superblock.dataBitmapBlockCount = dataBitCount / (FS_BLOCK_SIZE * 8) + ((dataBitCount % (FS_BLOCK_SIZE * 8) > 0) ? 1 : 0);
|
||||||
superblock.firstInodeBlock = superblock.firstDataBitmapBlock + superblock.dataBitmapBlockCount;
|
superblock.firstINodeBlock = superblock.firstDataBitmapBlock + superblock.dataBitmapBlockCount;
|
||||||
superblock.firstDataBlock = superblock.firstInodeBlock + superblock.inodeBlockCount;
|
superblock.firstDataBlock = superblock.firstINodeBlock + superblock.inodeBlockCount;
|
||||||
superblock.dataBlockCount = (fileBlocks - 2) + 1; // 1 Block for root dir (-1 for boot block)
|
superblock.dataBlockCount = (fileBlocks - 2) + 1; // 1 Block for root dir (-1 for boot block)
|
||||||
superblock.maxFileSize = 0xffffffff;
|
superblock.maxFileSize = 0xffffffff;
|
||||||
superblock.blockSize = FS_BLOCK_SIZE;
|
superblock.blockSize = FS_BLOCK_SIZE;
|
||||||
superblock.inodeSize = sizeof(inode_t);
|
superblock.inodeSize = sizeof(inode_t);
|
||||||
superblock.rootInodePtr = 0; // Gets setup at runtime
|
superblock.rootINodePtr = 0; // Gets setup at runtime
|
||||||
superblock.inodesPerBlock = FS_BLOCK_SIZE / sizeof(inode_t);
|
superblock.inodesPerBlock = FS_BLOCK_SIZE / sizeof(inode_t);
|
||||||
superblock.directExtentsPerInode = 4;
|
superblock.directExtentsPerINode = 4;
|
||||||
superblock.extentsPerIndirectBlock = FS_BLOCK_SIZE / sizeof(extent_t);
|
superblock.extentsPerIndirectBlock = FS_BLOCK_SIZE / sizeof(extent_t);
|
||||||
superblock.firstFreeInodeBit = superblock.inodeCount;
|
superblock.firstFreeINodeBit = superblock.inodeCount;
|
||||||
superblock.firstFreeDataBit = (fileBlocks - 2) + 1; // +1 for root dir
|
superblock.firstFreeDataBit = (fileBlocks - 2) + 1; // +1 for root dir
|
||||||
superblock.deviceNumber = 0x01;
|
superblock.deviceNumber = 0x01;
|
||||||
superblock.firstUnreservedInode = 3; // 0 - Invalid; 1 - Root dir; 2 - Bootloader INode
|
superblock.firstUnreservedINode = 3; // 0 - Invalid; 1 - Root dir; 2 - Bootloader INode
|
||||||
|
|
||||||
assert(fwrite(&superblock, sizeof(superBlock_t), 1, imagePtr) == 1);
|
assert(fwrite(&superblock, sizeof(superBlock_t), 1, imagePtr) == 1);
|
||||||
assert(fwrite(nullBlock, paddingBytes(sizeof(superBlock_t), FS_BLOCK_SIZE), 1, imagePtr) == 1); // Padding
|
assert(fwrite(nullBlock, paddingBytes(sizeof(superBlock_t), FS_BLOCK_SIZE), 1, imagePtr) == 1); // Padding
|
||||||
|
|||||||
+39
-8
@@ -10,8 +10,8 @@
|
|||||||
#include <memory/virtual.h>
|
#include <memory/virtual.h>
|
||||||
#include <memory/addresses.h>
|
#include <memory/addresses.h>
|
||||||
#include <memory/malloc.h>
|
#include <memory/malloc.h>
|
||||||
#include <disk/filesys.h>
|
#include <fs/fs.h>
|
||||||
#include <disk/disk.h>
|
#include <fs/impl.h>
|
||||||
#include <screen/text.h>
|
#include <screen/text.h>
|
||||||
#include <screen/graphics.h>
|
#include <screen/graphics.h>
|
||||||
#include <sound/pcspk.h>
|
#include <sound/pcspk.h>
|
||||||
@@ -23,14 +23,22 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <color.h>
|
#include <color.h>
|
||||||
#include <fs/fs.h>
|
|
||||||
|
|
||||||
#define PROMPT "/ #> "
|
#define PROMPT "#>"
|
||||||
|
|
||||||
|
//openFileTable_t* openFileTable;
|
||||||
|
inode_t* openINodeTable;
|
||||||
|
uint32_t maxOpenFiles = 256;
|
||||||
|
uint32_t openFileCount = 3; // First 3 reserved for stdin, stdout, stderr
|
||||||
|
uint32_t maxOpenINodes = 256;
|
||||||
|
uint32_t openINodeCount = 0;
|
||||||
|
|
||||||
// Function declarations
|
// Function declarations
|
||||||
void listFiles();
|
void listFiles();
|
||||||
void printRegs();
|
void printRegs();
|
||||||
void printPhysicalMemmap();
|
void printPhysicalMemmap();
|
||||||
|
void initOpenFileTable();
|
||||||
|
void initOpenINodeTable();
|
||||||
|
|
||||||
__attribute__ ((section("entry")))
|
__attribute__ ((section("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
@@ -73,6 +81,18 @@ void main() {
|
|||||||
mallocPhysicalAddr = kernelMallocPhysicalAddr;
|
mallocPhysicalAddr = kernelMallocPhysicalAddr;
|
||||||
mallocPages = kernelMallocPages;
|
mallocPages = kernelMallocPages;
|
||||||
|
|
||||||
|
// Setup filesystem
|
||||||
|
currentDir = malloc(1024);
|
||||||
|
strcpy(currentDir, "/"); // Start at root
|
||||||
|
|
||||||
|
|
||||||
|
// Setup kernel open file table and open inode table
|
||||||
|
initOpenFileTable();
|
||||||
|
initOpenINodeTable();
|
||||||
|
currentDir = malloc(1024);
|
||||||
|
strcpy(currentDir, "/");
|
||||||
|
|
||||||
|
// Terminal setup
|
||||||
terminal->fg = FG_COLOR;
|
terminal->fg = FG_COLOR;
|
||||||
terminal->bg = BG_COLOR;
|
terminal->bg = BG_COLOR;
|
||||||
clear();
|
clear();
|
||||||
@@ -81,7 +101,7 @@ void main() {
|
|||||||
// Run Interactive Shell Program
|
// Run Interactive Shell Program
|
||||||
// TODO: Make it in another file
|
// TODO: Make it in another file
|
||||||
while (1) {
|
while (1) {
|
||||||
printf(PROMPT);
|
printf("%s %s ", currentDir, PROMPT);
|
||||||
char input[256];
|
char input[256];
|
||||||
char* inputPtr = input;
|
char* inputPtr = input;
|
||||||
|
|
||||||
@@ -223,12 +243,13 @@ void main() {
|
|||||||
} else if (strcmp(argv[0], "test") == 0) {
|
} else if (strcmp(argv[0], "test") == 0) {
|
||||||
printf("\x1b[1MError: 'test' is not available.\x1b[8M\n");
|
printf("\x1b[1MError: 'test' is not available.\x1b[8M\n");
|
||||||
} else { // TODO: Use new filesystem!
|
} else { // TODO: Use new filesystem!
|
||||||
|
/*
|
||||||
fileEntry_t* file = findFile(argv[0]);
|
fileEntry_t* file = findFile(argv[0]);
|
||||||
|
|
||||||
if (file == NULL) {
|
if (file == NULL) {*/
|
||||||
printf("Command not found: %s\n", argv[0]);
|
printf("Command not found: %s\n", argv[0]);
|
||||||
continue;
|
continue;
|
||||||
}
|
/*}
|
||||||
|
|
||||||
uint32_t neededPages = (file->length * 512) / PAGE_SIZE;
|
uint32_t neededPages = (file->length * 512) / PAGE_SIZE;
|
||||||
if ((file->length * 512) % PAGE_SIZE > 0) { neededPages++; }
|
if ((file->length * 512) % PAGE_SIZE > 0) { neededPages++; }
|
||||||
@@ -291,7 +312,7 @@ void main() {
|
|||||||
unmapPage((void*)virtualAddr);
|
unmapPage((void*)virtualAddr);
|
||||||
flushTlbEntry(virtualAddr); // Invalidate unused page
|
flushTlbEntry(virtualAddr); // Invalidate unused page
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,3 +396,13 @@ void printPhysicalMemmap() {
|
|||||||
printf("Free blocks: %d\n\n", maxBlocks - usedBlocks);
|
printf("Free blocks: %d\n\n", maxBlocks - usedBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initOpenFileTable() {
|
||||||
|
//openFileTable = malloc(sizeof(openFileTable_t) * maxOpenFiles);
|
||||||
|
//*openFileTable = (openFileTable_t) { 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
void initOpenINodeTable() {
|
||||||
|
openINodeTable = malloc(sizeof(inode_t) * maxOpenINodes);
|
||||||
|
*openINodeTable = (inode_t) { 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -369,9 +369,9 @@ DATA_SEG equ GDT.dataDescriptor - GDT.start
|
|||||||
|
|
||||||
;; VBE Stuff
|
;; VBE Stuff
|
||||||
;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !!
|
;; !! IF YOU WANT TO SELECT ANY VALUE IN THE SETUP, SET THESE TO ZERO !!
|
||||||
width: dw 0
|
width: dw 1920
|
||||||
height: dw 0
|
height: dw 1080
|
||||||
bpp: db 0
|
bpp: db 32
|
||||||
|
|
||||||
offset: dw 0
|
offset: dw 0
|
||||||
_segment: dw 0 ; segment is a keyword
|
_segment: dw 0 ; segment is a keyword
|
||||||
|
|||||||
+11
-38
@@ -2,12 +2,9 @@
|
|||||||
#include <memory/virtual.h>
|
#include <memory/virtual.h>
|
||||||
#include <memory/addresses.h>
|
#include <memory/addresses.h>
|
||||||
#include <disk/disk.h>
|
#include <disk/disk.h>
|
||||||
//#include <disk/filesys.h>
|
#include <fs/impl.h>
|
||||||
#include <screen/gfxmode.h>
|
|
||||||
|
|
||||||
#include <fs/fs.h>
|
#include <fs/fs.h>
|
||||||
|
#include <screen/gfxmode.h>
|
||||||
uint8_t loadFile(char* filename, void* dest);
|
|
||||||
|
|
||||||
__attribute__ ((section("entry")))
|
__attribute__ ((section("entry")))
|
||||||
void main() {
|
void main() {
|
||||||
@@ -31,11 +28,17 @@ void main() {
|
|||||||
|
|
||||||
// Load root dir, find kernel INode and parse it
|
// Load root dir, find kernel INode and parse it
|
||||||
superBlock_t* superblock = (superBlock_t*)SUPERBLOCK_LOC;
|
superBlock_t* superblock = (superBlock_t*)SUPERBLOCK_LOC;
|
||||||
superblock->rootInodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t);
|
superblock->rootINodePtr = BOOT_FIRST_INODE_LOC + sizeof(inode_t);
|
||||||
diskRead(superblock->firstDataBlock * 8, 8, (void*)SCRATCH_BLOCK_LOC);
|
diskRead(superblock->firstDataBlock * 8, 8, (void*)SCRATCH_BLOCK_LOC);
|
||||||
|
|
||||||
if (loadFile("kernel.bin", (void*)KERNEL_LOC) != 0) __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
|
inode_t* inode;
|
||||||
if (loadFile("term16n.fnt", (void*)FONT_LOC) != 0) __asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
|
if ((inode = getINode("kernel.bin")) == NULL) {
|
||||||
|
__asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
|
||||||
|
} else { loadFile(inode, (void*)KERNEL_LOC); }
|
||||||
|
|
||||||
|
if ((inode = getINode("term16n.fnt")) == NULL) {
|
||||||
|
__asm__ volatile ("cli; hlt" : : "a"(0xDeadBeef));
|
||||||
|
} else { loadFile(inode, (void*)FONT_LOC); }
|
||||||
|
|
||||||
// Virtual memory manager setup
|
// Virtual memory manager setup
|
||||||
if (setupVirtualMemoryManager() != 0) {
|
if (setupVirtualMemoryManager() != 0) {
|
||||||
@@ -66,33 +69,3 @@ void main() {
|
|||||||
((void(*)(void))0xC0000000)();
|
((void(*)(void))0xC0000000)();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t loadFile(char* filename, void* dest) {
|
|
||||||
dirEntry_t* dirEntry = (dirEntry_t*)SCRATCH_BLOCK_LOC;
|
|
||||||
while (dirEntry->name[0] != '\0') {
|
|
||||||
if (strcmp(dirEntry->name, filename) == 0) break;
|
|
||||||
dirEntry++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dirEntry->name[0] == '\0') return 1;
|
|
||||||
|
|
||||||
inode_t* inode = (inode_t*)BOOT_FIRST_INODE_LOC;
|
|
||||||
while (inode->id != dirEntry->id) {
|
|
||||||
inode++;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t totalBlocks = bytesToBlocks(inode->sizeBytes);
|
|
||||||
uint32_t addressOffset = 0;
|
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 4 && totalBlocks > 0; i++) {
|
|
||||||
diskRead(inode->extent[i].firstBlock * 8, inode->extent[i].length * 8, dest + addressOffset);
|
|
||||||
addressOffset += inode->extent[i].length * FS_BLOCK_SIZE;
|
|
||||||
totalBlocks -= inode->extent[i].length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalBlocks > 0) {
|
|
||||||
// TODO: Indirect extents
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user