Add ftpget

This commit is contained in:
2025-10-03 23:48:11 +02:00
parent d1bea93d07
commit 775295804e
5 changed files with 94 additions and 2 deletions

View File

@@ -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 .

View File

@@ -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

33
src/ftpget.c Normal file
View File

@@ -0,0 +1,33 @@
#include <stdint.h>
#include <unistd.h>
#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;
}
}

7
src/polos.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
#define kLpt1 0x10
#define kUntilIdle 1
#define kOnce 0
int runcomms(char until_idle);

View File

@@ -1,6 +1,8 @@
#include <stdint.h>
#include <stdlib.h>
#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;
}