diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/src/kernel/main.c b/src/kernel/main.c index 9b91775..f5879d0 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -10,7 +10,7 @@ void *initrd = findInitrd(address, &tarSize); void *loaderProgram = findTarFile(initrd, tarSize, "initrd/loader"); loadElf(loaderProgram); - asm("mov %%eax, %0" ::"r"(loaderProgram)); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); while (1) ; } diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/src/kernel/main.c b/src/kernel/main.c index 9b91775..f5879d0 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -10,7 +10,7 @@ void *initrd = findInitrd(address, &tarSize); void *loaderProgram = findTarFile(initrd, tarSize, "initrd/loader"); loadElf(loaderProgram); - asm("mov %%eax, %0" ::"r"(loaderProgram)); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); while (1) ; } diff --git a/src/kernel/service/service.h b/src/kernel/service/service.h index e69de29..e1955f4 100644 --- a/src/kernel/service/service.h +++ b/src/kernel/service/service.h @@ -0,0 +1,23 @@ +#ifndef SERVICE_H +#define SERVICE_H + +#include + +typedef struct { + uint32_t registers[20]; +} Context; + +typedef struct { + PagingInfo pagingInfo; + uint32_t operationCount; + void **operationLocations; + char **operationNames; + // AllocationBlock allocationBlocks[12]; +} Service; + +typedef struct { + uint32_t operation; + void *parameters; +} Request; + +#endif diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/src/kernel/main.c b/src/kernel/main.c index 9b91775..f5879d0 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -10,7 +10,7 @@ void *initrd = findInitrd(address, &tarSize); void *loaderProgram = findTarFile(initrd, tarSize, "initrd/loader"); loadElf(loaderProgram); - asm("mov %%eax, %0" ::"r"(loaderProgram)); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); while (1) ; } diff --git a/src/kernel/service/service.h b/src/kernel/service/service.h index e69de29..e1955f4 100644 --- a/src/kernel/service/service.h +++ b/src/kernel/service/service.h @@ -0,0 +1,23 @@ +#ifndef SERVICE_H +#define SERVICE_H + +#include + +typedef struct { + uint32_t registers[20]; +} Context; + +typedef struct { + PagingInfo pagingInfo; + uint32_t operationCount; + void **operationLocations; + char **operationNames; + // AllocationBlock allocationBlocks[12]; +} Service; + +typedef struct { + uint32_t operation; + void *parameters; +} Request; + +#endif diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index f0c69e3..189b8b8 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -4,15 +4,59 @@ #include #include -PagingInfo testInfo; +Service loaderService; +Service kernelService; +Context kernelContext; + +extern void *kernelCodePageTable; + +// these are temporary variables but I need the pointers in the asm parts +void *currentCr3 = 0; +void *currentEsp = 0; +void *mainFunction = NULL; +void *returnStack = 0; + +void run(Service *service, void *main) { + currentEsp = malloc(0x1000); + memset(currentEsp, 0, 0x1000); + ((void **)currentEsp)[0x3FF] = &&runEnd; + sharePage(&service->pagingInfo, currentEsp, currentEsp); + currentCr3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); + mainFunction = main; + asm(".intel_syntax noprefix\n" + "mov eax, [currentCr3]\n" + "mov cr3, eax\n" + "mov eax, esp\n" + "mov [returnStack], eax\n" + "mov eax, [currentEsp]\n" + "add eax, 0xFFC\n" + "mov esp, eax\n" + "push [mainFunction]\n" + "ret\n" + ".att_syntax"); +runEnd: + currentCr3 = PTR(0x500000); + asm(".intel_syntax noprefix\n" + "mov eax, [returnStack]\n" + "mov esp, eax\n" + "mov eax, 0x500000\n" + "mov cr3, eax\n" + ".att_syntax"); +} void loadElf(void *elfStart) { - // use this function ONLY to load the initrd/loader program! + // use this function ONLY to load the initrd/loader program(maybe also the + // ELF loader service)! ElfHeader *header = elfStart; ProgramHeader *programHeader = elfStart + header->programHeaderTablePosition; - PagingInfo *paging = &testInfo; + PagingInfo *paging = &loaderService.pagingInfo; memset(paging, 0, sizeof(PagingInfo)); + paging->pageDirectory = malloc(0x1000); + paging->pageDirectory[0x3FF].pageTableID = + U32(getPhysicalAddressKernel(kernelCodePageTable)) >> 12; + paging->pageDirectory[0x3FF].present = 1; + paging->pageDirectory[0x3FF].writable = 1; void *data; for (uint32_t i = 0; i < header->programHeaderEntryCount; i++) { for (uint32_t page = 0; page < programHeader->segmentMemorySize; @@ -21,12 +65,9 @@ memset(data, 0, 0x1000); memcpy(elfStart + programHeader->dataOffset, data, MIN(0x1000, programHeader->segmentFileSize - page)); - // sharePage(paging, data, - // elfStart + programHeader->dataOffset + page); + sharePage(paging, data, PTR(programHeader->virtualAddress + page)); } programHeader = (void *)programHeader + header->programHeaderEntrySize; } - asm("mov %%eax, %0" ::"r"(U32(data))); - while (1) - ; + run(&loaderService, PTR(header->entryPosition)); } diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/src/kernel/main.c b/src/kernel/main.c index 9b91775..f5879d0 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -10,7 +10,7 @@ void *initrd = findInitrd(address, &tarSize); void *loaderProgram = findTarFile(initrd, tarSize, "initrd/loader"); loadElf(loaderProgram); - asm("mov %%eax, %0" ::"r"(loaderProgram)); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); while (1) ; } diff --git a/src/kernel/service/service.h b/src/kernel/service/service.h index e69de29..e1955f4 100644 --- a/src/kernel/service/service.h +++ b/src/kernel/service/service.h @@ -0,0 +1,23 @@ +#ifndef SERVICE_H +#define SERVICE_H + +#include + +typedef struct { + uint32_t registers[20]; +} Context; + +typedef struct { + PagingInfo pagingInfo; + uint32_t operationCount; + void **operationLocations; + char **operationNames; + // AllocationBlock allocationBlocks[12]; +} Service; + +typedef struct { + uint32_t operation; + void *parameters; +} Request; + +#endif diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index f0c69e3..189b8b8 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -4,15 +4,59 @@ #include #include -PagingInfo testInfo; +Service loaderService; +Service kernelService; +Context kernelContext; + +extern void *kernelCodePageTable; + +// these are temporary variables but I need the pointers in the asm parts +void *currentCr3 = 0; +void *currentEsp = 0; +void *mainFunction = NULL; +void *returnStack = 0; + +void run(Service *service, void *main) { + currentEsp = malloc(0x1000); + memset(currentEsp, 0, 0x1000); + ((void **)currentEsp)[0x3FF] = &&runEnd; + sharePage(&service->pagingInfo, currentEsp, currentEsp); + currentCr3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); + mainFunction = main; + asm(".intel_syntax noprefix\n" + "mov eax, [currentCr3]\n" + "mov cr3, eax\n" + "mov eax, esp\n" + "mov [returnStack], eax\n" + "mov eax, [currentEsp]\n" + "add eax, 0xFFC\n" + "mov esp, eax\n" + "push [mainFunction]\n" + "ret\n" + ".att_syntax"); +runEnd: + currentCr3 = PTR(0x500000); + asm(".intel_syntax noprefix\n" + "mov eax, [returnStack]\n" + "mov esp, eax\n" + "mov eax, 0x500000\n" + "mov cr3, eax\n" + ".att_syntax"); +} void loadElf(void *elfStart) { - // use this function ONLY to load the initrd/loader program! + // use this function ONLY to load the initrd/loader program(maybe also the + // ELF loader service)! ElfHeader *header = elfStart; ProgramHeader *programHeader = elfStart + header->programHeaderTablePosition; - PagingInfo *paging = &testInfo; + PagingInfo *paging = &loaderService.pagingInfo; memset(paging, 0, sizeof(PagingInfo)); + paging->pageDirectory = malloc(0x1000); + paging->pageDirectory[0x3FF].pageTableID = + U32(getPhysicalAddressKernel(kernelCodePageTable)) >> 12; + paging->pageDirectory[0x3FF].present = 1; + paging->pageDirectory[0x3FF].writable = 1; void *data; for (uint32_t i = 0; i < header->programHeaderEntryCount; i++) { for (uint32_t page = 0; page < programHeader->segmentMemorySize; @@ -21,12 +65,9 @@ memset(data, 0, 0x1000); memcpy(elfStart + programHeader->dataOffset, data, MIN(0x1000, programHeader->segmentFileSize - page)); - // sharePage(paging, data, - // elfStart + programHeader->dataOffset + page); + sharePage(paging, data, PTR(programHeader->virtualAddress + page)); } programHeader = (void *)programHeader + header->programHeaderEntrySize; } - asm("mov %%eax, %0" ::"r"(U32(data))); - while (1) - ; + run(&loaderService, PTR(header->entryPosition)); } diff --git a/src/userland/loader/Makefile b/src/userland/loader/Makefile index d6c7c6c..c0d9686 100644 --- a/src/userland/loader/Makefile +++ b/src/userland/loader/Makefile @@ -1,7 +1,7 @@ CC = i686-elf-gcc CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 LD = i686-elf-ld -LD_FLAGS = -z max-page-size=0x1000 +LD_FLAGS = -z max-page-size=0x1000 -e main AS = nasm ASFlAGS = -felf32 diff --git a/Makefile b/Makefile index 801e89e..b4d10a9 100644 --- a/Makefile +++ b/Makefile @@ -7,21 +7,22 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s BUILD_FOLDER = build SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s) OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) USER_PROGRAMS := $(shell ls src/userland) -USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=initrd/%) +USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%) +USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%) -run: $(IMAGE_FILE) +run: $(USER_PROGRAM_NAMES) $(IMAGE_FILE) @echo "starting qemu" @$(EMU) $(EMUFLAGS) $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar - echo "creating the iso image" + @echo "creating the iso image" dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\ loop0=$$(sudo losetup -f) &&\ @@ -37,7 +38,7 @@ sudo losetup -d $$loop0 &&\ sudo losetup -d $$loop1 -rootfs/initrd.tar: $(USER_PROGRAM_NAMES) +rootfs/initrd.tar: $(USER_PROGRAM_FILES) tar cvf rootfs/initrd.tar initrd/ rootfs/boot/kernel: $(OBJS) link.ld @@ -59,7 +60,7 @@ @mkdir -p $(dir $@) @$(CC) $(CCFLAGS) -r $< -o $@ -initrd/%: src/userland/% +user/%: src/userland/% @echo "compiling userspace program $<" @make -C $< diff --git a/src/kernel/main.c b/src/kernel/main.c index 9b91775..f5879d0 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -10,7 +10,7 @@ void *initrd = findInitrd(address, &tarSize); void *loaderProgram = findTarFile(initrd, tarSize, "initrd/loader"); loadElf(loaderProgram); - asm("mov %%eax, %0" ::"r"(loaderProgram)); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); while (1) ; } diff --git a/src/kernel/service/service.h b/src/kernel/service/service.h index e69de29..e1955f4 100644 --- a/src/kernel/service/service.h +++ b/src/kernel/service/service.h @@ -0,0 +1,23 @@ +#ifndef SERVICE_H +#define SERVICE_H + +#include + +typedef struct { + uint32_t registers[20]; +} Context; + +typedef struct { + PagingInfo pagingInfo; + uint32_t operationCount; + void **operationLocations; + char **operationNames; + // AllocationBlock allocationBlocks[12]; +} Service; + +typedef struct { + uint32_t operation; + void *parameters; +} Request; + +#endif diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index f0c69e3..189b8b8 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -4,15 +4,59 @@ #include #include -PagingInfo testInfo; +Service loaderService; +Service kernelService; +Context kernelContext; + +extern void *kernelCodePageTable; + +// these are temporary variables but I need the pointers in the asm parts +void *currentCr3 = 0; +void *currentEsp = 0; +void *mainFunction = NULL; +void *returnStack = 0; + +void run(Service *service, void *main) { + currentEsp = malloc(0x1000); + memset(currentEsp, 0, 0x1000); + ((void **)currentEsp)[0x3FF] = &&runEnd; + sharePage(&service->pagingInfo, currentEsp, currentEsp); + currentCr3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); + mainFunction = main; + asm(".intel_syntax noprefix\n" + "mov eax, [currentCr3]\n" + "mov cr3, eax\n" + "mov eax, esp\n" + "mov [returnStack], eax\n" + "mov eax, [currentEsp]\n" + "add eax, 0xFFC\n" + "mov esp, eax\n" + "push [mainFunction]\n" + "ret\n" + ".att_syntax"); +runEnd: + currentCr3 = PTR(0x500000); + asm(".intel_syntax noprefix\n" + "mov eax, [returnStack]\n" + "mov esp, eax\n" + "mov eax, 0x500000\n" + "mov cr3, eax\n" + ".att_syntax"); +} void loadElf(void *elfStart) { - // use this function ONLY to load the initrd/loader program! + // use this function ONLY to load the initrd/loader program(maybe also the + // ELF loader service)! ElfHeader *header = elfStart; ProgramHeader *programHeader = elfStart + header->programHeaderTablePosition; - PagingInfo *paging = &testInfo; + PagingInfo *paging = &loaderService.pagingInfo; memset(paging, 0, sizeof(PagingInfo)); + paging->pageDirectory = malloc(0x1000); + paging->pageDirectory[0x3FF].pageTableID = + U32(getPhysicalAddressKernel(kernelCodePageTable)) >> 12; + paging->pageDirectory[0x3FF].present = 1; + paging->pageDirectory[0x3FF].writable = 1; void *data; for (uint32_t i = 0; i < header->programHeaderEntryCount; i++) { for (uint32_t page = 0; page < programHeader->segmentMemorySize; @@ -21,12 +65,9 @@ memset(data, 0, 0x1000); memcpy(elfStart + programHeader->dataOffset, data, MIN(0x1000, programHeader->segmentFileSize - page)); - // sharePage(paging, data, - // elfStart + programHeader->dataOffset + page); + sharePage(paging, data, PTR(programHeader->virtualAddress + page)); } programHeader = (void *)programHeader + header->programHeaderEntrySize; } - asm("mov %%eax, %0" ::"r"(U32(data))); - while (1) - ; + run(&loaderService, PTR(header->entryPosition)); } diff --git a/src/userland/loader/Makefile b/src/userland/loader/Makefile index d6c7c6c..c0d9686 100644 --- a/src/userland/loader/Makefile +++ b/src/userland/loader/Makefile @@ -1,7 +1,7 @@ CC = i686-elf-gcc CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 LD = i686-elf-ld -LD_FLAGS = -z max-page-size=0x1000 +LD_FLAGS = -z max-page-size=0x1000 -e main AS = nasm ASFlAGS = -felf32 diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index bee09ed..0e9e383 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -26,6 +26,8 @@ int32_t main() { // send a x to the parralel port to test stuff out - Parallel_SendByte('x'); + Parallel_SendByte('h'); + Parallel_SendByte('i'); + Parallel_SendByte('!'); return 0; }