mirror of
https://github.com/tailix/kernel.git
synced 2024-11-20 11:16:10 -05:00
Rename project to "Tailix kernel"
This commit is contained in:
parent
0087ae334b
commit
3d58d4d37e
38 changed files with 111 additions and 111 deletions
10
Makefile
10
Makefile
|
@ -3,20 +3,20 @@ KERNEL = rootfs/boot/tailix.multiboot2
|
|||
|
||||
IMAGE = image.iso
|
||||
|
||||
.PHONY: kernelmq/tailix.multiboot2
|
||||
.PHONY: kernel/tailix.multiboot2
|
||||
|
||||
run: $(IMAGE)
|
||||
qemu-system-i386 -cdrom $< -display none -serial stdio
|
||||
|
||||
clean:
|
||||
rm -f $(KERNEL)
|
||||
make -C kernelmq clean
|
||||
make -C kernel clean
|
||||
|
||||
$(IMAGE): $(GRUBCFG) $(KERNEL)
|
||||
grub-mkrescue rootfs -o $@
|
||||
|
||||
$(KERNEL): kernelmq/tailix.multiboot2
|
||||
$(KERNEL): kernel/tailix.multiboot2
|
||||
cp $< $@
|
||||
|
||||
kernelmq/tailix.multiboot2:
|
||||
make -C kernelmq tailix.multiboot2
|
||||
kernel/tailix.multiboot2:
|
||||
make -C kernel tailix.multiboot2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
KernelMQ
|
||||
========
|
||||
Tailix kernel
|
||||
=============
|
||||
|
||||
Message queue with additional IPC capabilities implemented as microkernel.
|
||||
|
||||
|
|
0
kernelmq/.gitignore → kernel/.gitignore
vendored
0
kernelmq/.gitignore → kernel/.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_CONFIG
|
||||
#define KERNELMQ_INCLUDED_CONFIG 1
|
||||
#ifndef KERNEL_INCLUDED_CONFIG
|
||||
#define KERNEL_INCLUDED_CONFIG 1
|
||||
|
||||
#define MEM_UPPER_BASE ((unsigned long)(1 * 1024 * 1024)) // 1 MB
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef KERNELMQ_INCLUDED_ELF
|
||||
#define KERNELMQ_INCLUDED_ELF 1
|
||||
#ifndef KERNEL_INCLUDED_ELF
|
||||
#define KERNEL_INCLUDED_ELF 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct KernelMQ_ELF_Header {
|
||||
struct Kernel_ELF_Header {
|
||||
unsigned char magic_0x7F : 8; // Must be 0x7F.
|
||||
unsigned char magic_E : 8; // Must be 'E'.
|
||||
unsigned char magic_L : 8; // Must be 'L'.
|
||||
|
@ -32,7 +32,7 @@ struct KernelMQ_ELF_Header {
|
|||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct KernelMQ_ELF_ProgramEntry {
|
||||
struct Kernel_ELF_ProgramEntry {
|
||||
unsigned long type : 32;
|
||||
unsigned long offset : 32;
|
||||
unsigned long virt_addr : 32;
|
||||
|
@ -44,7 +44,7 @@ struct KernelMQ_ELF_ProgramEntry {
|
|||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct KernelMQ_ELF_SectionEntry {
|
||||
struct Kernel_ELF_SectionEntry {
|
||||
unsigned long name : 32;
|
||||
unsigned long type : 32;
|
||||
unsigned long flags : 32;
|
||||
|
@ -58,24 +58,24 @@ struct KernelMQ_ELF_SectionEntry {
|
|||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct KernelMQ_ELF_RelocationEntry {
|
||||
struct Kernel_ELF_RelocationEntry {
|
||||
unsigned long virt_addr : 32;
|
||||
unsigned long info : 32;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
typedef struct KernelMQ_ELF_ProgramEntry KernelMQ_ELF_ProgramTable[];
|
||||
typedef struct Kernel_ELF_ProgramEntry Kernel_ELF_ProgramTable[];
|
||||
|
||||
typedef struct KernelMQ_ELF_SectionEntry KernelMQ_ELF_SectionTable[];
|
||||
typedef struct Kernel_ELF_SectionEntry Kernel_ELF_SectionTable[];
|
||||
|
||||
typedef struct KernelMQ_ELF_RelocationEntry KernelMQ_ELF_RelocationTable[];
|
||||
typedef struct Kernel_ELF_RelocationEntry Kernel_ELF_RelocationTable[];
|
||||
|
||||
inline static unsigned char KernelMQ_ELF_Header_is_valid(
|
||||
const struct KernelMQ_ELF_Header *header
|
||||
inline static unsigned char Kernel_ELF_Header_is_valid(
|
||||
const struct Kernel_ELF_Header *header
|
||||
);
|
||||
|
||||
unsigned char KernelMQ_ELF_Header_is_valid(
|
||||
const struct KernelMQ_ELF_Header *const header
|
||||
unsigned char Kernel_ELF_Header_is_valid(
|
||||
const struct Kernel_ELF_Header *const header
|
||||
) {
|
||||
return (
|
||||
header->magic_0x7F == 0x7F &&
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_HWINT
|
||||
#define KERNELMQ_INCLUDED_HWINT 1
|
||||
#ifndef KERNEL_INCLUDED_HWINT
|
||||
#define KERNEL_INCLUDED_HWINT 1
|
||||
|
||||
typedef void(*hwint_handler_t)();
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
static unsigned char cmdline_terminated(const char *s);
|
||||
|
||||
unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
||||
unsigned char kernel_info_validate(const struct Kernel_Info *const kinfo)
|
||||
{
|
||||
if (!kinfo) {
|
||||
return 0;
|
||||
|
@ -12,11 +12,11 @@ unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (kinfo->modules_count > KERNELMQ_INFO_MODULES_MAX) {
|
||||
if (kinfo->modules_count > KERNEL_INFO_MODULES_MAX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (kinfo->areas_count > KERNELMQ_INFO_AREAS_MAX) {
|
||||
if (kinfo->areas_count > KERNEL_INFO_AREAS_MAX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
|||
unsigned long modules_total_size = 0;
|
||||
|
||||
for (unsigned int i = 0; i < kinfo->modules_count; ++i) {
|
||||
const struct KernelMQ_Info_Module *const module = &kinfo->modules[i];
|
||||
const struct Kernel_Info_Module *const module = &kinfo->modules[i];
|
||||
|
||||
modules_total_size += module->size;
|
||||
|
||||
|
@ -71,7 +71,7 @@ unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
|||
unsigned long long last = 0;
|
||||
|
||||
for (unsigned int i = 0; i < kinfo->areas_count; ++i) {
|
||||
const struct KernelMQ_Info_Area *const area = &kinfo->areas[i];
|
||||
const struct Kernel_Info_Area *const area = &kinfo->areas[i];
|
||||
if (last > area->base) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
|||
}
|
||||
|
||||
for (unsigned int j = 0; j < kinfo->modules_count; ++j) {
|
||||
const struct KernelMQ_Info_Module *const module = &kinfo->modules[j];
|
||||
const struct Kernel_Info_Module *const module = &kinfo->modules[j];
|
||||
|
||||
if (module->base >= area->base &&
|
||||
module->base <= area->limit) {
|
||||
|
@ -118,7 +118,7 @@ unsigned char kernelmq_info_validate(const struct KernelMQ_Info *const kinfo)
|
|||
|
||||
unsigned char cmdline_terminated(const char *const s)
|
||||
{
|
||||
for (unsigned int i = 0; i < KERNELMQ_INFO_CMDLINE_SIZE_MAX; ++i) {
|
||||
for (unsigned int i = 0; i < KERNEL_INFO_CMDLINE_SIZE_MAX; ++i) {
|
||||
if (s[i] == 0) {
|
||||
return 1;
|
||||
}
|
|
@ -1,25 +1,25 @@
|
|||
#ifndef KERNELMQ_INCLUDED_INFO
|
||||
#define KERNELMQ_INCLUDED_INFO 1
|
||||
#ifndef KERNEL_INCLUDED_INFO
|
||||
#define KERNEL_INCLUDED_INFO 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define KERNELMQ_INFO_CMDLINE_SIZE_MAX 256
|
||||
#define KERNELMQ_INFO_CMDLINE_SLEN_MAX (KERNELMQ_INFO_CMDLINE_SIZE_MAX - 1)
|
||||
#define KERNEL_INFO_CMDLINE_SIZE_MAX 256
|
||||
#define KERNEL_INFO_CMDLINE_SLEN_MAX (KERNEL_INFO_CMDLINE_SIZE_MAX - 1)
|
||||
|
||||
#define KERNELMQ_INFO_MODULES_MAX 20
|
||||
#define KERNELMQ_INFO_AREAS_MAX 20
|
||||
#define KERNEL_INFO_MODULES_MAX 20
|
||||
#define KERNEL_INFO_AREAS_MAX 20
|
||||
|
||||
struct KernelMQ_Info_Module {
|
||||
struct Kernel_Info_Module {
|
||||
unsigned long base;
|
||||
unsigned long size;
|
||||
unsigned long limit;
|
||||
|
||||
char cmdline[KERNELMQ_INFO_CMDLINE_SIZE_MAX];
|
||||
char cmdline[KERNEL_INFO_CMDLINE_SIZE_MAX];
|
||||
};
|
||||
|
||||
struct KernelMQ_Info_Area {
|
||||
struct Kernel_Info_Area {
|
||||
unsigned long long base;
|
||||
unsigned long long size;
|
||||
unsigned long long limit;
|
||||
|
@ -27,13 +27,13 @@ struct KernelMQ_Info_Area {
|
|||
unsigned char is_available;
|
||||
};
|
||||
|
||||
struct KernelMQ_Info {
|
||||
char cmdline[KERNELMQ_INFO_CMDLINE_SIZE_MAX];
|
||||
struct Kernel_Info {
|
||||
char cmdline[KERNEL_INFO_CMDLINE_SIZE_MAX];
|
||||
|
||||
struct KernelMQ_Info_Module modules[KERNELMQ_INFO_MODULES_MAX];
|
||||
struct Kernel_Info_Module modules[KERNEL_INFO_MODULES_MAX];
|
||||
unsigned int modules_count;
|
||||
|
||||
struct KernelMQ_Info_Area areas[KERNELMQ_INFO_AREAS_MAX];
|
||||
struct Kernel_Info_Area areas[KERNEL_INFO_AREAS_MAX];
|
||||
unsigned int areas_count;
|
||||
|
||||
unsigned long kernel_offset;
|
||||
|
@ -52,7 +52,7 @@ struct KernelMQ_Info {
|
|||
unsigned long kernel_stack_top;
|
||||
};
|
||||
|
||||
unsigned char kernelmq_info_validate(const struct KernelMQ_Info *kinfo);
|
||||
unsigned char kernel_info_validate(const struct Kernel_Info *kinfo);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_INTERRUPT
|
||||
#define KERNELMQ_INCLUDED_INTERRUPT 1
|
||||
#ifndef KERNEL_INCLUDED_INTERRUPT
|
||||
#define KERNEL_INCLUDED_INTERRUPT 1
|
||||
|
||||
struct IsrRegisters {
|
||||
unsigned int ds; // Data segment selector
|
|
@ -20,7 +20,7 @@ extern char _kernel_phys_base;
|
|||
extern char _kernel_virt_base;
|
||||
extern char _kernel_stack_top;
|
||||
|
||||
static struct KernelMQ_Info kinfo;
|
||||
static struct Kernel_Info kinfo;
|
||||
|
||||
static struct KernAux_PFA pfa;
|
||||
|
||||
|
@ -38,7 +38,7 @@ void main(
|
|||
panic("Multiboot 2 info is invalid.");
|
||||
}
|
||||
|
||||
kernaux_memset(&kinfo, 0, sizeof(struct KernelMQ_Info));
|
||||
kernaux_memset(&kinfo, 0, sizeof(struct Kernel_Info));
|
||||
|
||||
KernAux_PFA_initialize(&pfa);
|
||||
|
||||
|
@ -49,7 +49,7 @@ void main(
|
|||
if (cmdline) {
|
||||
unsigned int slen = kernaux_strlen(cmdline);
|
||||
|
||||
if (slen > KERNELMQ_INFO_CMDLINE_SLEN_MAX) {
|
||||
if (slen > KERNEL_INFO_CMDLINE_SLEN_MAX) {
|
||||
panic("Multiboot 2 boot cmd line is too long.");
|
||||
}
|
||||
|
||||
|
@ -85,11 +85,11 @@ void main(
|
|||
);
|
||||
}
|
||||
|
||||
if (kinfo.areas_count >= KERNELMQ_INFO_AREAS_MAX) {
|
||||
if (kinfo.areas_count >= KERNEL_INFO_AREAS_MAX) {
|
||||
panic("Too many memory map entries in Multiboot 2 info.");
|
||||
}
|
||||
|
||||
struct KernelMQ_Info_Area *const area =
|
||||
struct Kernel_Info_Area *const area =
|
||||
&kinfo.areas[kinfo.areas_count];
|
||||
|
||||
area->base = entry->base_addr;
|
||||
|
@ -117,17 +117,17 @@ void main(
|
|||
(struct KernAux_Multiboot2_TagBase*)tag
|
||||
)
|
||||
) {
|
||||
if (kinfo.modules_count >= KERNELMQ_INFO_MODULES_MAX) {
|
||||
if (kinfo.modules_count >= KERNEL_INFO_MODULES_MAX) {
|
||||
panic("Too many modules in Multiboot 2 info.");
|
||||
}
|
||||
|
||||
unsigned int slen = kernaux_strlen(tag->cmdline);
|
||||
|
||||
if (slen > KERNELMQ_INFO_CMDLINE_SLEN_MAX) {
|
||||
if (slen > KERNEL_INFO_CMDLINE_SLEN_MAX) {
|
||||
panic("Multiboot 2 module cmd line is too long.");
|
||||
}
|
||||
|
||||
struct KernelMQ_Info_Module *const module =
|
||||
struct Kernel_Info_Module *const module =
|
||||
&kinfo.modules[kinfo.modules_count];
|
||||
|
||||
kernaux_strncpy(module->cmdline, tag->cmdline, slen);
|
||||
|
@ -161,15 +161,15 @@ void main(
|
|||
|
||||
paging_enable();
|
||||
|
||||
assert(kernelmq_info_validate(&kinfo), "Invalid kernel information.");
|
||||
assert(kernel_info_validate(&kinfo), "Invalid kernel information.");
|
||||
|
||||
protected_initialize(&kinfo);
|
||||
|
||||
if (kinfo.modules_count > 0) {
|
||||
const struct KernelMQ_ELF_Header *const elf_header =
|
||||
const struct Kernel_ELF_Header *const elf_header =
|
||||
(void*)kinfo.modules[0].base;
|
||||
|
||||
if (KernelMQ_ELF_Header_is_valid(elf_header)) {
|
||||
if (Kernel_ELF_Header_is_valid(elf_header)) {
|
||||
const unsigned long real_entrypoint =
|
||||
kinfo.modules[0].base + elf_header->entrypoint;
|
||||
|
|
@ -79,7 +79,7 @@ void paging_identity()
|
|||
}
|
||||
}
|
||||
|
||||
int paging_mapkernel(const struct KernelMQ_Info *const kinfo)
|
||||
int paging_mapkernel(const struct Kernel_Info *const kinfo)
|
||||
{
|
||||
assert(!(kinfo->kernel_phys_base % PAGE_BIG_SIZE), "Kernel physical address is not aligned.");
|
||||
assert(!(kinfo->kernel_virt_base % PAGE_BIG_SIZE), "Kernel virtual address is not aligned.");
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_PAGING
|
||||
#define KERNELMQ_INCLUDED_PAGING 1
|
||||
#ifndef KERNEL_INCLUDED_PAGING
|
||||
#define KERNEL_INCLUDED_PAGING 1
|
||||
|
||||
#include "config.h"
|
||||
#include "info.h"
|
||||
|
@ -29,7 +29,7 @@ void paging_enable();
|
|||
|
||||
void paging_clear();
|
||||
void paging_identity();
|
||||
int paging_mapkernel(const struct KernelMQ_Info *kinfo);
|
||||
int paging_mapkernel(const struct Kernel_Info *kinfo);
|
||||
unsigned long paging_load();
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_PANIC
|
||||
#define KERNELMQ_INCLUDED_PANIC 1
|
||||
#ifndef KERNEL_INCLUDED_PANIC
|
||||
#define KERNEL_INCLUDED_PANIC 1
|
||||
|
||||
void panic(const char *s);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_PIC
|
||||
#define KERNELMQ_INCLUDED_PIC 1
|
||||
#ifndef KERNEL_INCLUDED_PIC
|
||||
#define KERNEL_INCLUDED_PIC 1
|
||||
|
||||
void pic_remap(unsigned char master_irq_start, unsigned char slave_irq_start);
|
||||
|
|
@ -51,7 +51,7 @@ static void idt_set_gate(unsigned char num, unsigned int base, unsigned short se
|
|||
void gdt_flush(const struct GdtPointer *pointer);
|
||||
void idt_flush(const struct IdtPointer *pointer);
|
||||
|
||||
void protected_initialize(const struct KernelMQ_Info *const kinfo)
|
||||
void protected_initialize(const struct Kernel_Info *const kinfo)
|
||||
{
|
||||
pic_remap(32, 40);
|
||||
pic_disable_all();
|
8
kernel/protected.h
Normal file
8
kernel/protected.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef KERNEL_INCLUDED_PROTECTED
|
||||
#define KERNEL_INCLUDED_PROTECTED 1
|
||||
|
||||
#include "info.h"
|
||||
|
||||
void protected_initialize(const struct Kernel_Info *kinfo);
|
||||
|
||||
#endif
|
|
@ -13,7 +13,7 @@ void syscall_handler(const struct IsrRegisters regs)
|
|||
kernaux_console_printf("[INFO] syscall: number %u\n", id);
|
||||
|
||||
switch (id) {
|
||||
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
|
||||
case KERNEL_SYSCALL_EXIT: return syscall_do_exit(regs);
|
||||
}
|
||||
}
|
||||
|
16
kernel/syscall.h
Normal file
16
kernel/syscall.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef KERNEL_INCLUDED_SYSCALL
|
||||
#define KERNEL_INCLUDED_SYSCALL 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum Kernel_Syscall_Number {
|
||||
KERNEL_SYSCALL_EXIT = 0,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
6
kernel/tasks.h
Normal file
6
kernel/tasks.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef KERNEL_INCLUDED_TASKS
|
||||
#define KERNEL_INCLUDED_TASKS 1
|
||||
|
||||
void tasks_switch_to_user(unsigned long base);
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef KERNELMQ_INCLUDED_TIMER
|
||||
#define KERNELMQ_INCLUDED_TIMER 1
|
||||
#ifndef KERNEL_INCLUDED_TIMER
|
||||
#define KERNEL_INCLUDED_TIMER 1
|
||||
|
||||
#include "hwint.h"
|
||||
|
|
@ -55,7 +55,7 @@ struct tss_entry {
|
|||
|
||||
static struct tss_entry tss;
|
||||
|
||||
void tss_write_to_gdt(const struct KernelMQ_Info *const kinfo, void *gdt_entry_ptr)
|
||||
void tss_write_to_gdt(const struct Kernel_Info *const kinfo, void *gdt_entry_ptr)
|
||||
{
|
||||
struct gdt_entry_bits *const g = gdt_entry_ptr;
|
||||
|
10
kernel/tss.h
Normal file
10
kernel/tss.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef KERNEL_INCLUDED_TSS
|
||||
#define KERNEL_INCLUDED_TSS 1
|
||||
|
||||
#include "info.h"
|
||||
|
||||
void tss_write_to_gdt(const struct Kernel_Info *kinfo, void *gdt_entry);
|
||||
|
||||
void tss_flush();
|
||||
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef KERNELMQ_INCLUDED_PROTECTED
|
||||
#define KERNELMQ_INCLUDED_PROTECTED 1
|
||||
|
||||
#include "info.h"
|
||||
|
||||
void protected_initialize(const struct KernelMQ_Info *kinfo);
|
||||
|
||||
#endif
|
|
@ -1,16 +0,0 @@
|
|||
#ifndef KERNELMQ_INCLUDED_SYSCALL
|
||||
#define KERNELMQ_INCLUDED_SYSCALL 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum KernelMQ_Syscall_Number {
|
||||
KERNELMQ_SYSCALL_EXIT = 0,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef KERNELMQ_INCLUDED_TASKS
|
||||
#define KERNELMQ_INCLUDED_TASKS 1
|
||||
|
||||
void tasks_switch_to_user(unsigned long base);
|
||||
|
||||
#endif
|
|
@ -1,10 +0,0 @@
|
|||
#ifndef KERNELMQ_INCLUDED_TSS
|
||||
#define KERNELMQ_INCLUDED_TSS 1
|
||||
|
||||
#include "info.h"
|
||||
|
||||
void tss_write_to_gdt(const struct KernelMQ_Info *kinfo, void *gdt_entry);
|
||||
|
||||
void tss_flush();
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue