diff --git a/Makefile b/Makefile index 146b4b0..7cd866f 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,6 @@ binaries: ## Build all small binaries docker build --build-arg TARGET=readfloppy.bin -o . --target=export . docker build --build-arg TARGET=writefloppy.bin -o . --target=export . docker build --build-arg TARGET=crc16.bin -o . --target=export . - docker build --build-arg TARGET=wozmon.bin -o . --target=export . docker build --build-arg TARGET=hello.bin -o . --target=export . docker build --build-arg TARGET=copy.bin -o . --target=export . docker build --build-arg TARGET=call.bin -o . --target=export . @@ -22,6 +21,15 @@ binaries: ## Build all small binaries docker build --build-arg TARGET=readio.bin -o . --target=export . docker build --build-arg TARGET=writeio.bin -o . --target=export . +.PHONY: polos +polos: ## Build polOS components + docker build --build-arg TARGET=fat12boot.bin -o . --target=export . + docker build --build-arg TARGET=polio.com -o . --target=export . + docker build --build-arg TARGET=polmon.com -o . --target=export . + docker build --build-arg TARGET=mushroom.com -o . --target=export . + docker build --build-arg TARGET=hello.com -o . --target=export . + docker build --build-arg TARGET=ftpget.com -o . --target=export . + .PHONY: floppy floppy: ## Make a bootable floppy image docker build --build-arg TARGET=polos.img -o . --target=export . diff --git a/src/Makefile b/src/Makefile index 7a43b09..761a44c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -39,11 +39,12 @@ polio.elf: polio-main.o polio.s fat12.o paracomm.o stdlib.o paracli.elf: LDFLAGS += -T doscom.ld paracli.elf: paracli.s paracomm.o -dos-programs = mushroom.elf hello.elf +dos-programs = mushroom.elf hello.elf ftpget.elf $(dos-programs): LDFLAGS += -T doscom.ld mushroom.elf: mushroom.s hello.elf: hello.o stdlib.o crt0.s +ftpget.elf: ftpget.o stdlib.o crt0.s polos.img: fat12boot.bin polmon.com polio.com mushroom.com hello.com dd if=/dev/zero of=$@ bs=512 count=720 diff --git a/src/ftpget.c b/src/ftpget.c new file mode 100644 index 0000000..0c70ca9 --- /dev/null +++ b/src/ftpget.c @@ -0,0 +1,33 @@ +#include +#include + +#include "polos.h" + +#define kDefaultChunkSize 0x20 + +int main(int argc, uint16_t argv[]) { + if (argc < 2) { + return -1; + } + + uint8_t* dest = (uint8_t*)argv[0]; + uint16_t size = argv[1]; + uint8_t chunksize = kDefaultChunkSize; + if (argc > 2) { + chunksize = argv[2]; + } + + uint8_t ok = 0x42; + + for (int i = 0; i < size; i += chunksize) { + runcomms(kUntilIdle); + // delay? + + uint8_t len = read(kLpt1, dest, chunksize); + if (len == 0) { + break; + } + write(kLpt1, &ok, 1); + dest += len; + } +} diff --git a/src/polos.h b/src/polos.h new file mode 100644 index 0000000..24aabe8 --- /dev/null +++ b/src/polos.h @@ -0,0 +1,7 @@ +#pragma once + +#define kLpt1 0x10 +#define kUntilIdle 1 +#define kOnce 0 + +int runcomms(char until_idle); diff --git a/src/stdlib.c b/src/stdlib.c index 2f2949a..bb319d3 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -1,6 +1,8 @@ #include #include +#include "polos.h" + int getchar() { register char c asm("al"); asm volatile("movb $0x00, %%ah\n\t" @@ -43,3 +45,44 @@ void* memset(void* ptr, int val, size_t len) { } return ptr; } + +int runcomms(char until_idle) { + register int ret asm("ax"); + register char ui asm("al") = until_idle; + asm volatile("mov $0x07, %%ah \n\t" + "int $0x80 \n\t" + : "=r"(ret) + : "r"(until_idle)); + + return ret; +} + +int read(int fd, void* buf, size_t size) { + if (fd != kLpt1) { + return -1; + } + register int ret asm("ax"); + asm volatile("push %2 \n\t" + "push %1 \n\t" + "mov $0x05, %%ah \n\t" + "int $0x80 \n\t" + : "=r"(ret) + : "r"(buf), "r"(size)); + + return ret; +} + +int write(int fd, void* buf, size_t size) { + if (fd != kLpt1) { + return -1; + } + register int ret asm("ax"); + asm volatile("push %2 \n\t" + "push %1 \n\t" + "mov $0x06, %%ah \n\t" + "int $0x80 \n\t" + : "=r"(ret) + : "r"(buf), "r"(size)); + + return ret; +}