feat: implemented errno, strtol. Started ustar. Reformatted headers and

code. Added some self-tests. Started prepwork for vfs.
This commit is contained in:
2021-03-14 21:14:22 +01:00
parent 586b8191b4
commit 77c8dca72a
39 changed files with 504 additions and 60 deletions

View File

@@ -68,6 +68,6 @@ struct elf32_symtab_entry {
uint8_t st_info;
uint8_t st_other;
uint16_t st_shndx;
};
} packed;
#endif //NEW_KERNEL_ELF_H

View File

@@ -5,4 +5,41 @@
#ifndef NEW_KERNEL_ERRNO_H
#define NEW_KERNEL_ERRNO_H
extern int errno;
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
#define ESRCH 3 /* No such process */
#define EINTR 4 /* Interrupted system call */
#define EIO 5 /* I/O error */
#define ENXIO 6 /* No such device or address */
#define E2BIG 7 /* Argument list too long */
#define ENOEXEC 8 /* Exec format error */
#define EBADF 9 /* Bad file number */
#define ECHILD 10 /* No child processes */
#define EAGAIN 11 /* Try again */
#define ENOMEM 12 /* Out of memory */
#define EACCES 13 /* Permission denied */
#define EFAULT 14 /* Bad address */
#define ENOTBLK 15 /* Block device required */
#define EBUSY 16 /* Device or resource busy */
#define EEXIST 17 /* File exists */
#define EXDEV 18 /* Cross-device link */
#define ENODEV 19 /* No such device */
#define ENOTDIR 20 /* Not a directory */
#define EISDIR 21 /* Is a directory */
#define EINVAL 22 /* Invalid argument */
#define ENFILE 23 /* File table overflow */
#define EMFILE 24 /* Too many open files */
#define ENOTTY 25 /* Not a typewriter */
#define ETXTBSY 26 /* Text file busy */
#define EFBIG 27 /* File too large */
#define ENOSPC 28 /* No space left on device */
#define ESPIPE 29 /* Illegal seek */
#define EROFS 30 /* Read-only file system */
#define EMLINK 31 /* Too many links */
#define EPIPE 32 /* Broken pipe */
#define EDOM 33 /* Math argument out of domain of func */
#define ERANGE 34 /* Math result not representable */
#endif //NEW_KERNEL_ERRNO_H

View File

@@ -9,6 +9,6 @@
void store_bootloader_info(multiboot_info_t *multiboot_info);
void main_loop(void* data);
void main_loop(void *data);
#endif //NEW_KERNEL_COMMAND_H

View File

@@ -4,6 +4,7 @@
#ifndef NEW_KERNEL_CPU_H
#define NEW_KERNEL_CPU_H
#include <sys/types.h>
typedef struct {

View File

@@ -36,7 +36,7 @@ typedef struct {
bool xsave: 1;
bool osxsave: 1;
bool avx: 1;
} cpu_features_ecx ;
} cpu_features_ecx;
typedef struct {
bool fpu: 1;
@@ -72,7 +72,7 @@ typedef struct {
bool ia64: 1;
bool pbe: 1;
} cpu_features_edx ;
} cpu_features_edx;
enum cpu_features {
CPUID_FEAT_ECX_SSE3 = 1 << 0,

View File

@@ -5,6 +5,7 @@
#ifndef MY_KERNEL_IDT_H
#define MY_KERNEL_IDT_H
#include <myke/attributes.h>
#define KERNEL_CS 0x08

View File

@@ -126,7 +126,7 @@ extern void isr128();
#define IRQ14 46
#define IRQ15 47
typedef void (*isr_t)(isr_registers_t*);
typedef void (*isr_t)(isr_registers_t *);
void register_interrupt_handler(uint8_t n, isr_t handler);

View File

@@ -4,6 +4,7 @@
#ifndef NEW_KERNEL_SYSCALL_HANDLER_H
#define NEW_KERNEL_SYSCALL_HANDLER_H
#include <myke/cpu/cpu.h>
void syscall_handle(isr_registers_t *registers);

View File

@@ -8,9 +8,17 @@
#include <stdbool.h>
#ifdef DEBUG_INIT
#include <multiboot.h>
void debug_store_info(struct multiboot_info *info);
#endif
#ifdef ENABLE_SELF_TEST
void self_test();
#endif
void debug_backtrace(bool do_sync);

View File

@@ -4,6 +4,7 @@
#ifndef NEW_KERNEL_DRIVER_H
#define NEW_KERNEL_DRIVER_H
#include <myke/attributes.h>
#include <myke/preprocessor_format_zero.h>
@@ -12,8 +13,8 @@
#endif
#define DRIVER_CAT(a, b) DRIVER_DUMMY() a ## _ ## b
#define DRIVER_DUMMY()
#define SECT_NAME_(a,b) "." #a "." #b
#define SECT_NAME(a,b) SECT_NAME_(a, b)
#define SECT_NAME_(a, b) "." #a "." #b
#define SECT_NAME(a, b) SECT_NAME_(a, b)
#define GENERIC_DRIVER(drivername, order) \
static struct drivername DRIVER_CAT(drivername, counter) \

View File

@@ -5,6 +5,7 @@
#ifndef NEW_KERNEL_BLOCKDEV_H
#define NEW_KERNEL_BLOCKDEV_H
#include <stdbool.h>
#include <sys/types.h>
#include <myke/driver.h>
@@ -24,18 +25,19 @@
#define BLOCK_DEV_REGISTER_FULL 1
typedef struct block_device block_device;
typedef struct block_device block_device_t;
typedef uint8_t (*block_device_driver_check_device)(const block_device *device, uint8_t *first_sector);
typedef uint8_t (*block_device_driver_check_device)(const block_device_t *device, uint8_t *first_sector);
typedef uint8_t (*block_device_driver_free)(const block_device *device);
typedef uint8_t (*block_device_driver_free)(const block_device_t *device);
typedef uint8_t (*block_device_access)(const block_device *device, uint8_t direction, uint32_t lba, uint8_t sectors, void *target);
typedef uint8_t (*block_device_access)(const block_device_t *device, uint8_t direction, uint32_t lba, uint8_t sectors,
void *target);
struct block_dev_driver {
char name[16];
struct {
uint8_t root_only: 1;
uint8_t partitioning: 1;
} flags;
block_device_driver_check_device check_device;
block_device_driver_free free_device;
@@ -43,7 +45,7 @@ struct block_dev_driver {
#define BLOCK_DEV_DRIVER(order) GENERIC_DRIVER(block_dev_driver, order)
typedef struct block_device {
struct block_device {
struct {
uint8_t present: 1;
uint8_t scanned: 1;
@@ -58,14 +60,16 @@ typedef struct block_device {
struct block_dev_driver *driver;
void *device_info; // pointer to driver defined structure
// todo device info
} block_device;
};
uint8_t block_dev_register(block_device *device);
uint8_t block_dev_register(block_device_t *device);
void block_dev_free(block_device *device);
void block_dev_free(block_device_t *device);
void block_dev_start_task();
void block_dev_print_info();
bool block_dev_mount(char *identifier, char *driver);
#endif //NEW_KERNEL_BLOCKDEV_H

View File

@@ -15,7 +15,7 @@ void kprint_register(kprint_handler);
void kprint(const char *msg);
void kprint_sync(const char* msg);
void kprint_sync(const char *msg);
void kprint_init();

View File

@@ -4,11 +4,12 @@
#ifndef NEW_KERNEL_LIBK_H
#define NEW_KERNEL_LIBK_H
#include <myke/attributes.h>
#include <stdbool.h>
extern void* _kernel_start;
extern void* _kernel_end;
extern void *_kernel_start;
extern void *_kernel_end;
#define kernel_start ((uint32_t)(&_kernel_start))
#define kernel_end ((uint32_t)(&_kernel_end))

View File

@@ -4,6 +4,7 @@
#ifndef NEW_KERNEL_SYSCALL_H
#define NEW_KERNEL_SYSCALL_H
#include <sys/types.h>
#include <myke/attributes.h>

View File

@@ -16,7 +16,9 @@ void *calloc(size_t, size_t);
void free(void *);
#ifndef INCLUDE_STDLIB
void print_malloc_info();
#endif
#endif //NEW_KERNEL_MALLOC_H

View File

@@ -4,13 +4,16 @@
#ifndef NEW_KERNEL_PMM_H
#define NEW_KERNEL_PMM_H
#include <sys/types.h>
// 4k blocks
#define PAGE_SIZE 4096
void pmm_init(void* start_addr, size_t size);
void pmm_init(void *start_addr, size_t size);
void *pmm_get_pages(uint32_t num_pages);
void pmm_free_pages(void* page, uint32_t num_pages);
void pmm_free_pages(void *page, uint32_t num_pages);
#endif //NEW_KERNEL_PMM_H

View File

@@ -4,6 +4,7 @@
#ifndef NEW_KERNEL_POWER_H
#define NEW_KERNEL_POWER_H
#include <myke/attributes.h>
void noreturn power_shutdown();

View File

@@ -33,4 +33,6 @@ long long llabs(long long val);
void qsort(void *base, size_t num, size_t size, int (*compar)(const void *, const void *));
long strtol(const char *nptr, char **endptr, int base);
#endif //NEW_KERNEL_STDLIB_H

View File

@@ -11,7 +11,7 @@ int memcpy(void *dst, const void *src, size_t amount);
int memset(void *dst, int data, size_t amount);
int strcpy(char *dst, char *src);
int strcpy(char *dst, const char *src);
size_t strlen(const char *str);

View File

@@ -5,7 +5,7 @@
#ifndef NEW_KERNEL_PARAM_H
#define NEW_KERNEL_PARAM_H
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a, b) (((a)<(b))?(a):(b))
#define MAX(a, b) (((a)>(b))?(a):(b))
#endif //NEW_KERNEL_PARAM_H

View File

@@ -4,11 +4,14 @@
#ifndef NEW_KERNEL_UNISTD_H
#define NEW_KERNEL_UNISTD_H
#include <sys/types.h>
int execv(const char*, char* const[]);
int execve(const char*, char* const[], char* const[]);
int execvp(const char*, char* const[]);
int execv(const char *, char *const[]);
int execve(const char *, char *const[], char *const[]);
int execvp(const char *, char *const[]);
pid_t fork(void);