Ok, last changes tonight for real

This commit is contained in:
2025-10-04 01:27:59 +02:00
parent d7df8501d6
commit 0917aa1280
6 changed files with 53 additions and 47 deletions

View File

@@ -21,15 +21,6 @@ binaries: ## Build all small binaries
docker build --build-arg TARGET=readio.bin -o . --target=export . docker build --build-arg TARGET=readio.bin -o . --target=export .
docker build --build-arg TARGET=writeio.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 .PHONY: floppy
floppy: ## Make a bootable floppy image floppy: ## Make a bootable floppy image
docker build --build-arg TARGET=polos.img -o . --target=export . docker build --build-arg TARGET=polos.img -o . --target=export .

View File

@@ -1,27 +1,22 @@
%.bin: %.asm
nasm $< -o $@
crc16.s: crc16.c
ia16-elf-gcc -S -Os -o crc16.s crc16.c
crc16.bin: crc16.s
ia16-elf-gcc -o crc16.bin -Os -nostdlib crc16.s
CC = ia16-elf-gcc CC = ia16-elf-gcc
CXX = ia16-elf-gcc CXX = ia16-elf-gcc
LD = ia16-elf-gcc LD = ia16-elf-gcc
OBJCOPY = ia16-elf-objcopy
CXXFLAGS = -mregparmcall -ffunction-sections -Os -flto CXXFLAGS = -mregparmcall -ffunction-sections -Os -flto
CFLAGS = -mregparmcall -ffunction-sections -Os -flto CFLAGS = -mregparmcall -ffunction-sections -Os -flto
LDFLAGS = -mregparmcall -Wl,--gc-sections -Os -nostdlib -flto LDFLAGS = -mregparmcall -Wl,--gc-sections -Os -nostdlib -flto
%.bin: %.asm
nasm $< -o $@
%.elf: %.elf:
$(LD) $(LDFLAGS) $(CPPFLAGS) -o $@ $^ $(LD) $(LDFLAGS) $(CPPFLAGS) -o $@ $^
%.com: %.elf %.com: %.elf
ia16-elf-objcopy -O binary $< $@ $(OBJCOPY) -O binary $< $@
fat12boot.bin: fat12boot.bin:
ia16-elf-objcopy -O binary $< $@ $(OBJCOPY) -O binary $< $@
fat12boot.elf: fat12boot.o fat12.o bootsect.S fat12boot.elf: fat12boot.o fat12.o bootsect.S
fat12boot.elf: LDFLAGS += -T bootsect.ld fat12boot.elf: LDFLAGS += -T bootsect.ld
@@ -39,12 +34,13 @@ polio.elf: polio-main.o polio.s fat12.o paracomm.o stdlib.o
paracli.elf: LDFLAGS += -T doscom.ld paracli.elf: LDFLAGS += -T doscom.ld
paracli.elf: paracli.s paracomm.o paracli.elf: paracli.s paracomm.o
dos-programs = mushroom.com hello.com ftpget.com dos-programs = mushroom.com hello.com ftpget.com crc16.com
$(dos-programs:.com=.elf): LDFLAGS += -T doscom.ld $(dos-programs:.com=.elf): LDFLAGS += -T doscom.ld
mushroom.elf: mushroom.s mushroom.elf: mushroom.s
hello.elf: hello.o stdlib.o crt0.s hello.elf: hello.o stdlib.o crt0.s
ftpget.elf: ftpget.o stdlib.o crt0.s ftpget.elf: ftpget.o stdlib.o crt0.s
crc16.elf: crc16.o stdlib.o crt0.s
polos.img: fat12boot.bin polmon.com polio.com $(dos-programs) polos.img: fat12boot.bin polmon.com polio.com $(dos-programs)
dd if=/dev/zero of=$@ bs=512 count=720 dd if=/dev/zero of=$@ bs=512 count=720

View File

@@ -1,13 +1,13 @@
#include <stdint.h> #include <stdint.h>
#define kDataAddr ((uint8_t*)0x0000) #include "polos.h"
uint16_t crc16(int data_len) { #define kDefaultSegment 0
const uint8_t* data = kDataAddr;
uint16_t crc16(uint16_t data, const uint16_t seg, int data_len) {
uint16_t crc = 0xFFFF; uint16_t crc = 0xFFFF;
for (unsigned int i = 0; i < data_len; ++i) { for (unsigned int i = 0; i < data_len; ++i) {
uint16_t dbyte = data[i]; uint16_t dbyte = __get_far_u8__(data + i, seg);
crc ^= dbyte << 8; crc ^= dbyte << 8;
for (unsigned char j = 0; j < 8; ++j) { for (unsigned char j = 0; j < 8; ++j) {
uint16_t mix = crc & 0x8000; uint16_t mix = crc & 0x8000;
@@ -19,15 +19,13 @@ uint16_t crc16(int data_len) {
return crc; return crc;
} }
asm(".global main \n" int main(int argc, int argv[]) {
"main: \n" if (argc < 2) {
" push %bp \n" return -1;
" mov %sp, %bp \n" }
" mov 8(%bp), %si \n" uint16_t seg = kDefaultSegment;
" push (%si) \n" if (argc > 2) {
" call crc16 \n" seg = argv[2];
" add $0x2, %sp \n" }
" mov 6(%bp), %di \n" return crc16(argv[0], seg, argv[1]);
" mov %ax, (%di) \n" }
" pop %bp \n"
" lret $4 \n");

View File

@@ -19,7 +19,7 @@ int main(int argc, uint16_t argv[]) {
uint8_t ok = 0x42; uint8_t ok = 0x42;
for (int i = 0; i < size; ) { for (int i = 0; i < size;) {
runcomms(kUntilIdle); runcomms(kUntilIdle);
// delay? // delay?

View File

@@ -164,15 +164,17 @@ char toupper(char c) {
return c; return c;
} }
void tofatname(const char* name, char* fatname) { void tofatname(const char* name, uint8_t len, char* fatname) {
int j = 0;
for (int i = 0; i < 11; i++) { for (int i = 0; i < 11; i++) {
if (*name == 0 || *name == '.') { if (j == len || name[j] == '.') {
fatname[i] = ' '; fatname[i] = ' ';
} else { } else {
fatname[i] = toupper(*name++); fatname[i] = toupper(name[j]);
j++;
} }
if (i == 7 && *name == '.') { if (i == 7 && name[j] == '.') {
name++; j++;
} }
} }
} }
@@ -192,7 +194,8 @@ uint16_t __readfile__(const char* name, uint16_t addr) {
return ret; return ret;
} }
uint16_t LaunchFile(const char* name, uint8_t argc, uint16_t* argv) { uint16_t LaunchFile(const char* name, uint8_t len, uint8_t argc,
uint16_t* argv) {
constexpr uint16_t kSegment = 0x200; constexpr uint16_t kSegment = 0x200;
constexpr uint16_t kAddress = 0x100; constexpr uint16_t kAddress = 0x100;
constexpr uint16_t kHeaderAddress = (kSegment << 4); constexpr uint16_t kHeaderAddress = (kSegment << 4);
@@ -205,9 +208,13 @@ uint16_t LaunchFile(const char* name, uint8_t argc, uint16_t* argv) {
constexpr uint8_t kTrampoline[] = {0xe8, 0xfd, 0x00, 0xcb}; constexpr uint8_t kTrampoline[] = {0xe8, 0xfd, 0x00, 0xcb};
char fatname[11]; char fatname[11];
tofatname(name, fatname); tofatname(name, len, fatname);
uint16_t r = __readfile__(fatname, kFlatAddress); uint16_t r = __readfile__(fatname, kFlatAddress);
if (r) {
memcpy(fatname + 8, "COM", 3);
r = __readfile__(fatname, kFlatAddress);
}
if (r) { if (r) {
return r; return r;
} }
@@ -312,7 +319,8 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
ptr++; ptr++;
} }
const char* fname = ptr; const char* fname = ptr;
for (; *ptr && *ptr != ' '; ptr++) { int l;
for (l = 0; *ptr && *ptr != ' '; l++, ptr++) {
} }
for (; *ptr && nargs < 8;) { for (; *ptr && nargs < 8;) {
if (*ptr == ' ') { if (*ptr == ' ') {
@@ -321,7 +329,7 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
} }
args[nargs++] = ReadUint16(ptr); args[nargs++] = ReadUint16(ptr);
} }
uint16_t ret = LaunchFile(fname, nargs, args); uint16_t ret = LaunchFile(fname, l, nargs, args);
WriteUint16ln(ret); WriteUint16ln(ret);
} else if (*ptr == 'w') { } else if (*ptr == 'w') {
dump = false; dump = false;

View File

@@ -1,7 +1,20 @@
#pragma once #pragma once
#include <stdint.h>
#define kLpt1 0x10 #define kLpt1 0x10
#define kUntilIdle 1 #define kUntilIdle 1
#define kOnce 0 #define kOnce 0
int runcomms(char until_idle); int runcomms(char until_idle);
inline static uint8_t __get_far_u8__(uint16_t addr, uint16_t seg) {
register uint16_t ad asm("di") = addr;
register uint8_t ret asm("al");
asm("mov %2, %%es \t\n"
"movb %%es:(%%di), %%al \t\n"
: "=r"(ret)
: "r"(ad), "r"(seg)
: "es");
return ret;
}