diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 1f2a82b..f0af9ac 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -19,7 +19,6 @@ } Provider; extern void loadElf(void *fileData, char *serviceName); -extern void run(Service *service, void *address); extern void resume(Syscall *syscall); extern void *runEnd; diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 1f2a82b..f0af9ac 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -19,7 +19,6 @@ } Provider; extern void loadElf(void *fileData, char *serviceName); -extern void run(Service *service, void *address); extern void resume(Syscall *syscall); extern void *runEnd; diff --git a/src/kernel/main.c b/src/kernel/main.c index 76909ef..b51bd98 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -28,9 +28,8 @@ runLoader->service = loader; memset(runLoader->esp, 0, 0x1000); runLoader->esp += 0xFFC; - *(void **)runLoader->esp = runEnd; + *(void **)runLoader->esp = &runEnd; sharePage(&loader->pagingInfo, runLoader->esp, runLoader->esp); - listAdd(&callsToProcess, runLoader); } diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 1f2a82b..f0af9ac 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -19,7 +19,6 @@ } Provider; extern void loadElf(void *fileData, char *serviceName); -extern void run(Service *service, void *address); extern void resume(Syscall *syscall); extern void *runEnd; diff --git a/src/kernel/main.c b/src/kernel/main.c index 76909ef..b51bd98 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -28,9 +28,8 @@ runLoader->service = loader; memset(runLoader->esp, 0, 0x1000); runLoader->esp += 0xFFC; - *(void **)runLoader->esp = runEnd; + *(void **)runLoader->esp = &runEnd; sharePage(&loader->pagingInfo, runLoader->esp, runLoader->esp); - listAdd(&callsToProcess, runLoader); } diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index 8e3ede8..e6f9ac4 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -13,18 +13,13 @@ extern void *functionsStart; extern void(runFunction)(); + Service *currentService; - ListElement *services, *callsToProcess; - -void run(Service *service, void *main) { - serviceCR3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); - mainFunction = main; - currentService = service; - runFunction(); -} +Syscall *currentSyscall; void resume(Syscall *syscall) { + currentSyscall = syscall; mainFunction = syscall->address; serviceESP = syscall->esp; currentService = syscall->service; diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 1f2a82b..f0af9ac 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -19,7 +19,6 @@ } Provider; extern void loadElf(void *fileData, char *serviceName); -extern void run(Service *service, void *address); extern void resume(Syscall *syscall); extern void *runEnd; diff --git a/src/kernel/main.c b/src/kernel/main.c index 76909ef..b51bd98 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -28,9 +28,8 @@ runLoader->service = loader; memset(runLoader->esp, 0, 0x1000); runLoader->esp += 0xFFC; - *(void **)runLoader->esp = runEnd; + *(void **)runLoader->esp = &runEnd; sharePage(&loader->pagingInfo, runLoader->esp, runLoader->esp); - listAdd(&callsToProcess, runLoader); } diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index 8e3ede8..e6f9ac4 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -13,18 +13,13 @@ extern void *functionsStart; extern void(runFunction)(); + Service *currentService; - ListElement *services, *callsToProcess; - -void run(Service *service, void *main) { - serviceCR3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); - mainFunction = main; - currentService = service; - runFunction(); -} +Syscall *currentSyscall; void resume(Syscall *syscall) { + currentSyscall = syscall; mainFunction = syscall->address; serviceESP = syscall->esp; currentService = syscall->service; diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index db68c2d..c3ff4e3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -7,6 +7,8 @@ extern void *runEndSyscall; extern ListElement *callsToProcess; +extern void(syscallStub)(); +extern Syscall *currentSyscall; void wrmsr(uint32_t msr, uint32_t low, uint32_t high) { asm("wrmsr" ::"a"(low), "d"(high), "c"(msr)); @@ -19,6 +21,9 @@ void handleSyscall(void *cr3, Syscall *callData) { if (!callData) { + if (currentSyscall->respondingTo) { + listAdd(&callsToProcess, currentSyscall->respondingTo); + } asm("jmp runEndSyscall"); } void *dataPhysical = @@ -30,8 +35,6 @@ asm("jmp runEndSyscall"); } -extern void(syscallStub)(); - void *syscallStubPtr = syscallStub; void *syscallStubPointer = &syscallStubPtr; @@ -42,43 +45,79 @@ return; } -void handleInstallSyscall(Syscall *call) { +void handleInstallSyscall(RegisterServiceProviderSyscall *call) { Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, registerCall->name)); + char *providerName = kernelMapPhysical( + getPhysicalAddress(service->pagingInfo.pageDirectory, call->name)); provider->name = providerName; - provider->address = registerCall->handler; + provider->address = call->handler; provider->service = call->service; listAdd(&service->providers, provider); call->resume = true; listAdd(&callsToProcess, call); } -void handleRequestSyscall(Syscall *call) { - RequestSyscall *request = (void *)call; +void handleRequestSyscall(RequestSyscall *call) { + call->resume = true; Service *service = call->service; char *serviceName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, request->serviceName)); + service->pagingInfo.pageDirectory, call->serviceName)); Service *providerService = findService(serviceName); char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, request->providerName)); + service->pagingInfo.pageDirectory, call->providerName)); Provider *callProvider = findProvider(providerService, providerName); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->address = callProvider->address; runCall->esp = malloc(0x1000); - runCall->respondingTo = call; + runCall->respondingTo = (void *)call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); runCall->esp += 0xFFC; - *(void **)runCall->esp = runEnd; + *(void **)runCall->esp = &runEnd; listAdd(&callsToProcess, runCall); } -void (*syscallHandlers[])(Syscall *) = {0, handleInstallSyscall, - handleRequestSyscall}; +void handleIOInSyscall(IOPortInSyscall *call) { + switch (call->size) { + case 1: + asm("in %%dx, %%al" : "=a"(call->result) : "d"(call->port)); + break; + case 2: + asm("in %%dx, %%ax" : "=a"(call->result) : "d"(call->port)); + break; + case 4: + asm("in %%dx, %%eax" : "=a"(call->result) : "d"(call->port)); + break; + } + call->resume = true; + listAdd(&callsToProcess, call); +} + +void handleIOOutSyscall(IOPortOutSyscall *call) { + switch (call->size) { + case 1: + asm("out %0, %1" : : "a"((uint8_t)call->value), "Nd"(call->port)); + break; + case 2: + asm("out %0, %1" : : "a"((uint16_t)call->value), "Nd"(call->port)); + break; + case 4: + asm("out %0, %1" : : "a"((uint32_t)call->value), "Nd"(call->port)); + break; + } + call->resume = true; + listAdd(&callsToProcess, call); +} + +void (*syscallHandlers[])(Syscall *) = { + 0, + (void *)handleInstallSyscall, + (void *)handleRequestSyscall, + (void *)handleIOInSyscall, + (void *)handleIOOutSyscall, +}; diff --git a/Makefile b/Makefile index b4d10a9..35e0643 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar @echo "creating the iso image" - dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\ + @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) &&\ sudo losetup $$loop0 $(IMAGE_FILE) &&\ diff --git a/src/include/syscalls.h b/src/include/syscalls.h index a3c11ad..cc19d50 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -8,6 +8,8 @@ SYS_RUN, SYS_REGISTER_FUNCTION, SYS_REQUEST, + SYS_IO_IN, + SYS_IO_OUT, } SyscallIds; typedef struct Syscall { @@ -33,4 +35,20 @@ void *data; } RequestSyscall; +typedef struct { + Syscall; + uint16_t port; + uint8_t size; +} IOPortSyscall; + +typedef struct { + IOPortSyscall; + uint32_t result; +} IOPortInSyscall; + +typedef struct { + IOPortSyscall; + uint32_t value; +} IOPortOutSyscall; + #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index 1f2a82b..f0af9ac 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -19,7 +19,6 @@ } Provider; extern void loadElf(void *fileData, char *serviceName); -extern void run(Service *service, void *address); extern void resume(Syscall *syscall); extern void *runEnd; diff --git a/src/kernel/main.c b/src/kernel/main.c index 76909ef..b51bd98 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -28,9 +28,8 @@ runLoader->service = loader; memset(runLoader->esp, 0, 0x1000); runLoader->esp += 0xFFC; - *(void **)runLoader->esp = runEnd; + *(void **)runLoader->esp = &runEnd; sharePage(&loader->pagingInfo, runLoader->esp, runLoader->esp); - listAdd(&callsToProcess, runLoader); } diff --git a/src/kernel/service/services.c b/src/kernel/service/services.c index 8e3ede8..e6f9ac4 100644 --- a/src/kernel/service/services.c +++ b/src/kernel/service/services.c @@ -13,18 +13,13 @@ extern void *functionsStart; extern void(runFunction)(); + Service *currentService; - ListElement *services, *callsToProcess; - -void run(Service *service, void *main) { - serviceCR3 = getPhysicalAddressKernel(service->pagingInfo.pageDirectory); - mainFunction = main; - currentService = service; - runFunction(); -} +Syscall *currentSyscall; void resume(Syscall *syscall) { + currentSyscall = syscall; mainFunction = syscall->address; serviceESP = syscall->esp; currentService = syscall->service; diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index db68c2d..c3ff4e3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -7,6 +7,8 @@ extern void *runEndSyscall; extern ListElement *callsToProcess; +extern void(syscallStub)(); +extern Syscall *currentSyscall; void wrmsr(uint32_t msr, uint32_t low, uint32_t high) { asm("wrmsr" ::"a"(low), "d"(high), "c"(msr)); @@ -19,6 +21,9 @@ void handleSyscall(void *cr3, Syscall *callData) { if (!callData) { + if (currentSyscall->respondingTo) { + listAdd(&callsToProcess, currentSyscall->respondingTo); + } asm("jmp runEndSyscall"); } void *dataPhysical = @@ -30,8 +35,6 @@ asm("jmp runEndSyscall"); } -extern void(syscallStub)(); - void *syscallStubPtr = syscallStub; void *syscallStubPointer = &syscallStubPtr; @@ -42,43 +45,79 @@ return; } -void handleInstallSyscall(Syscall *call) { +void handleInstallSyscall(RegisterServiceProviderSyscall *call) { Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; Service *service = call->service; - char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, registerCall->name)); + char *providerName = kernelMapPhysical( + getPhysicalAddress(service->pagingInfo.pageDirectory, call->name)); provider->name = providerName; - provider->address = registerCall->handler; + provider->address = call->handler; provider->service = call->service; listAdd(&service->providers, provider); call->resume = true; listAdd(&callsToProcess, call); } -void handleRequestSyscall(Syscall *call) { - RequestSyscall *request = (void *)call; +void handleRequestSyscall(RequestSyscall *call) { + call->resume = true; Service *service = call->service; char *serviceName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, request->serviceName)); + service->pagingInfo.pageDirectory, call->serviceName)); Service *providerService = findService(serviceName); char *providerName = kernelMapPhysical(getPhysicalAddress( - service->pagingInfo.pageDirectory, request->providerName)); + service->pagingInfo.pageDirectory, call->providerName)); Provider *callProvider = findProvider(providerService, providerName); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->address = callProvider->address; runCall->esp = malloc(0x1000); - runCall->respondingTo = call; + runCall->respondingTo = (void *)call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); runCall->esp += 0xFFC; - *(void **)runCall->esp = runEnd; + *(void **)runCall->esp = &runEnd; listAdd(&callsToProcess, runCall); } -void (*syscallHandlers[])(Syscall *) = {0, handleInstallSyscall, - handleRequestSyscall}; +void handleIOInSyscall(IOPortInSyscall *call) { + switch (call->size) { + case 1: + asm("in %%dx, %%al" : "=a"(call->result) : "d"(call->port)); + break; + case 2: + asm("in %%dx, %%ax" : "=a"(call->result) : "d"(call->port)); + break; + case 4: + asm("in %%dx, %%eax" : "=a"(call->result) : "d"(call->port)); + break; + } + call->resume = true; + listAdd(&callsToProcess, call); +} + +void handleIOOutSyscall(IOPortOutSyscall *call) { + switch (call->size) { + case 1: + asm("out %0, %1" : : "a"((uint8_t)call->value), "Nd"(call->port)); + break; + case 2: + asm("out %0, %1" : : "a"((uint16_t)call->value), "Nd"(call->port)); + break; + case 4: + asm("out %0, %1" : : "a"((uint32_t)call->value), "Nd"(call->port)); + break; + } + call->resume = true; + listAdd(&callsToProcess, call); +} + +void (*syscallHandlers[])(Syscall *) = { + 0, + (void *)handleInstallSyscall, + (void *)handleRequestSyscall, + (void *)handleIOInSyscall, + (void *)handleIOOutSyscall, +}; diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 620bb05..d55cf86 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -1,40 +1,6 @@ #include #include -uint8_t inb(uint16_t port) { - uint8_t result; - __asm__("in %%dx, %%al" : "=a"(result) : "d"(port)); - return result; -} - -void outb(uint16_t port, uint8_t val) { - asm volatile("outb %0, %1" : : "a"(val), "Nd"(port)); -} - -void writeParallel(unsigned char pData) { - unsigned char lControl; - - while (!(inb(0x379) & 0x80)) { - } - outb(0x378, pData); - - lControl = inb(0x37A); - outb(0x37A, lControl | 1); - outb(0x37A, lControl); - while (!(inb(0x379) & 0x80)) { - } -} - -void testProvider(void *requestData) { - // writeParallel('t'); - // writeParallel('e'); - // writeParallel('s'); - // writeParallel('t'); - asm("mov %%eax, %0" ::"r"(0xB105F00D)); - while (1) - ; -} - void syscall(void *callData) { Syscall *call = callData; asm("mov %%ebp, %%eax" : "=a"(call->esp)); @@ -45,6 +11,47 @@ return; } +uint32_t ioIn(uint16_t port, uint8_t size) { + IOPortInSyscall call = { + .function = SYS_IO_IN, + .port = port, + .size = size, + }; + syscall(&call); + return call.result; +} + +void ioOut(uint16_t port, uint32_t value, uint8_t size) { + IOPortOutSyscall call = { + .function = SYS_IO_OUT, + .port = port, + .value = value, + .size = size, + }; + syscall(&call); +} + +void writeParallel(uint8_t data) { + uint8_t control; + + while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { + } + ioOut(0x378, data, sizeof(uint8_t)); + + control = ioIn(0x37A, sizeof(uint8_t)); + ioOut(0x37A, control | 1, sizeof(uint8_t)); + ioOut(0x37A, control, sizeof(uint8_t)); + while (!(ioIn(0x379, sizeof(uint8_t)) & 0x80)) { + } +} + +void testProvider(void *requestData) { + writeParallel('t'); + writeParallel('e'); + writeParallel('s'); + writeParallel('t'); +} + void makeRequest(char *moduleName, char *functionName) { RequestSyscall call = { .function = SYS_REQUEST,