1
0
Fork 0
mirror of https://github.com/tailix/kernel.git synced 2025-02-17 15:45:37 -05:00

Add process

This commit is contained in:
Alex Kotov 2020-11-25 13:14:21 +05:00
parent 75e7eeff8a
commit 015aa6a25b
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 50 additions and 10 deletions

3
.gitignore vendored
View file

@ -1,9 +1,10 @@
*.o
*.a
*.multiboot2
*.bin
*.iso
/config.mk
/rootfs/boot/kernelmq.multiboot2
/rootfs/boot/syscallproc
/vendor/*
!/vendor/.keep

View file

@ -4,7 +4,9 @@ AR = $(CCPREFIX)ar
AS = $(CCPREFIX)as
CC = $(CCPREFIX)gcc
KERNEL = rootfs/boot/kernelmq.multiboot2
GRUBCFG = rootfs/boot/grub/grub.cfg
KERNEL = rootfs/boot/kernelmq.multiboot2
SYSCALLPROC = rootfs/boot/syscallproc
CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra
@ -53,20 +55,22 @@ OBJS := $(addprefix src/, $(OBJS))
run: $(IMAGE)
qemu-system-i386 -cdrom $< -display none -serial stdio
all: $(KERNEL)
clean:
rm -f $(OBJS)
rm -f $(IMAGE)
rm -f $(KERNEL)
rm -f $(SYSCALLPROC)
$(IMAGE): $(KERNEL)
$(IMAGE): $(GRUBCFG) $(KERNEL) $(SYSCALLPROC)
grub-mkrescue rootfs -o $@
$(KERNEL): $(OBJS)
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
grub-file --is-x86-multiboot2 $@
$(SYSCALLPROC): syscallproc.asm
nasm -f bin syscallproc.asm -o $@
%.c.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)

View file

@ -1,5 +1,6 @@
set timeout=0
menuentry "KernelMQ" {
multiboot2 /boot/kernelmq.multiboot2 hello kernel
multiboot2 /boot/kernelmq.multiboot2
module2 /boot/syscallproc
}

View file

@ -26,4 +26,8 @@ void init(const struct KernelMQ_Info *const kinfo_ptr)
paging_identity(); // Still need 1:1 for lapic and video mem and such.
paging_mapkernel(&kinfo);
paging_load();
if (kinfo.modules_count > 0) {
tasks_switch_to_user(kinfo.modules[0].base);
}
}

View file

@ -7,16 +7,18 @@ static void syscall_do_exit(struct IsrRegisters regs);
void syscall_handler(const struct IsrRegisters regs)
{
const unsigned int id = regs.eax;
const unsigned int id = regs.eax << 16 >> 16;
logger_info_from("syscall", "number %u", id);
switch (id) {
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
}
logger_info_from("syscall", "number %u", id);
}
void syscall_do_exit(const struct IsrRegisters regs)
{
logger_warn_from("syscall", "process try to exit with error code %u, haha", regs.ebx);
const unsigned int exit_code = regs.ebx << 16 >> 16;
logger_warn_from("syscall", "process try to exit with error code %u, haha", exit_code);
}

28
syscallproc.asm Normal file
View file

@ -0,0 +1,28 @@
main:
xor eax, eax
xor ebx, ebx
int 0x80
xor eax, eax
mov ebx, 1
int 0x80
mov eax, 1
xor ebx, ebx
int 0x80
mov eax, 2
xor ebx, ebx
int 0x80
mov eax, 256
xor ebx, ebx
int 0x80
mov eax, 257
xor ebx, ebx
int 0x80
mov eax, 258
xor ebx, ebx
int 0x80