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

@@ -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

@@ -1,73 +0,0 @@
//
// Created by rick on 07-03-21.
//
#ifndef NEW_KERNEL_ELF_H
#define NEW_KERNEL_ELF_H
#include <sys/types.h>
#include <myke/attributes.h>
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
#define SHF_WRITE 0x1
#define SHF_ALLOC 0x2
#define SHF_EXECINSTR 0x4
#define SHF_MASKPROC 0xf0000000
#define ELF32_ST_BIND(i) ((i)>>4)
#define ELF32_ST_TYPE(i) ((i)&0xf)
#define ELF32_ST_INFO(b, t) (((b)<<4)+((t)&0xf))
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_LOPROC 13
#define STB_HIPROC 15
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_LOPROC 13
#define STT_HIPROC 15
struct elf32_section_header {
uint32_t sh_name;
uint32_t sh_type;
uint32_t sh_flags;
uint32_t sh_addr;
uint32_t sh_offset;
uint32_t sh_size;
uint32_t sh_link;
uint32_t sh_info;
uint32_t sh_addr_align;
uint32_t sh_ent_size;
} packed;
struct elf32_symtab_entry {
uint32_t st_name;
uint32_t st_value;
uint32_t st_size;
uint8_t st_info;
uint8_t st_other;
uint16_t st_shndx;
};
#endif //NEW_KERNEL_ELF_H

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();