mirror of
https://github.com/tailix/kernel.git
synced 2025-02-17 15:45:37 -05:00
Add process
This commit is contained in:
parent
75e7eeff8a
commit
015aa6a25b
6 changed files with 50 additions and 10 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,9 +1,10 @@
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.multiboot2
|
|
||||||
*.bin
|
*.bin
|
||||||
*.iso
|
*.iso
|
||||||
|
|
||||||
/config.mk
|
/config.mk
|
||||||
|
/rootfs/boot/kernelmq.multiboot2
|
||||||
|
/rootfs/boot/syscallproc
|
||||||
/vendor/*
|
/vendor/*
|
||||||
!/vendor/.keep
|
!/vendor/.keep
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -4,7 +4,9 @@ AR = $(CCPREFIX)ar
|
||||||
AS = $(CCPREFIX)as
|
AS = $(CCPREFIX)as
|
||||||
CC = $(CCPREFIX)gcc
|
CC = $(CCPREFIX)gcc
|
||||||
|
|
||||||
|
GRUBCFG = rootfs/boot/grub/grub.cfg
|
||||||
KERNEL = rootfs/boot/kernelmq.multiboot2
|
KERNEL = rootfs/boot/kernelmq.multiboot2
|
||||||
|
SYSCALLPROC = rootfs/boot/syscallproc
|
||||||
|
|
||||||
CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra
|
CFLAGS = -std=gnu99 -ffreestanding -nostdinc -fno-builtin -fno-stack-protector -Wall -Wextra
|
||||||
|
|
||||||
|
@ -53,20 +55,22 @@ OBJS := $(addprefix src/, $(OBJS))
|
||||||
run: $(IMAGE)
|
run: $(IMAGE)
|
||||||
qemu-system-i386 -cdrom $< -display none -serial stdio
|
qemu-system-i386 -cdrom $< -display none -serial stdio
|
||||||
|
|
||||||
all: $(KERNEL)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS)
|
rm -f $(OBJS)
|
||||||
rm -f $(IMAGE)
|
rm -f $(IMAGE)
|
||||||
rm -f $(KERNEL)
|
rm -f $(KERNEL)
|
||||||
|
rm -f $(SYSCALLPROC)
|
||||||
|
|
||||||
$(IMAGE): $(KERNEL)
|
$(IMAGE): $(GRUBCFG) $(KERNEL) $(SYSCALLPROC)
|
||||||
grub-mkrescue rootfs -o $@
|
grub-mkrescue rootfs -o $@
|
||||||
|
|
||||||
$(KERNEL): $(OBJS)
|
$(KERNEL): $(OBJS)
|
||||||
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
|
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -lgcc $^
|
||||||
grub-file --is-x86-multiboot2 $@
|
grub-file --is-x86-multiboot2 $@
|
||||||
|
|
||||||
|
$(SYSCALLPROC): syscallproc.asm
|
||||||
|
nasm -f bin syscallproc.asm -o $@
|
||||||
|
|
||||||
%.c.o: %.c
|
%.c.o: %.c
|
||||||
$(CC) -c $< -o $@ $(CFLAGS)
|
$(CC) -c $< -o $@ $(CFLAGS)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
set timeout=0
|
set timeout=0
|
||||||
|
|
||||||
menuentry "KernelMQ" {
|
menuentry "KernelMQ" {
|
||||||
multiboot2 /boot/kernelmq.multiboot2 hello kernel
|
multiboot2 /boot/kernelmq.multiboot2
|
||||||
|
module2 /boot/syscallproc
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_identity(); // Still need 1:1 for lapic and video mem and such.
|
||||||
paging_mapkernel(&kinfo);
|
paging_mapkernel(&kinfo);
|
||||||
paging_load();
|
paging_load();
|
||||||
|
|
||||||
|
if (kinfo.modules_count > 0) {
|
||||||
|
tasks_switch_to_user(kinfo.modules[0].base);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,16 +7,18 @@ static void syscall_do_exit(struct IsrRegisters regs);
|
||||||
|
|
||||||
void syscall_handler(const 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) {
|
switch (id) {
|
||||||
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
|
case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger_info_from("syscall", "number %u", id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syscall_do_exit(const struct IsrRegisters regs)
|
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
28
syscallproc.asm
Normal 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
|
Loading…
Add table
Reference in a new issue