Ok, last changes tonight for real
This commit is contained in:
9
Makefile
9
Makefile
@@ -21,15 +21,6 @@ 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 .
|
||||
|
20
src/Makefile
20
src/Makefile
@@ -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
|
||||
CXX = ia16-elf-gcc
|
||||
LD = ia16-elf-gcc
|
||||
OBJCOPY = ia16-elf-objcopy
|
||||
CXXFLAGS = -mregparmcall -ffunction-sections -Os -flto
|
||||
CFLAGS = -mregparmcall -ffunction-sections -Os -flto
|
||||
LDFLAGS = -mregparmcall -Wl,--gc-sections -Os -nostdlib -flto
|
||||
|
||||
%.bin: %.asm
|
||||
nasm $< -o $@
|
||||
|
||||
%.elf:
|
||||
$(LD) $(LDFLAGS) $(CPPFLAGS) -o $@ $^
|
||||
|
||||
%.com: %.elf
|
||||
ia16-elf-objcopy -O binary $< $@
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
fat12boot.bin:
|
||||
ia16-elf-objcopy -O binary $< $@
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
fat12boot.elf: fat12boot.o fat12.o bootsect.S
|
||||
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: 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
|
||||
|
||||
mushroom.elf: mushroom.s
|
||||
hello.elf: hello.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)
|
||||
dd if=/dev/zero of=$@ bs=512 count=720
|
||||
|
30
src/crc16.c
30
src/crc16.c
@@ -1,13 +1,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define kDataAddr ((uint8_t*)0x0000)
|
||||
#include "polos.h"
|
||||
|
||||
uint16_t crc16(int data_len) {
|
||||
const uint8_t* data = kDataAddr;
|
||||
#define kDefaultSegment 0
|
||||
|
||||
uint16_t crc16(uint16_t data, const uint16_t seg, int data_len) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
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;
|
||||
for (unsigned char j = 0; j < 8; ++j) {
|
||||
uint16_t mix = crc & 0x8000;
|
||||
@@ -19,15 +19,13 @@ uint16_t crc16(int data_len) {
|
||||
return crc;
|
||||
}
|
||||
|
||||
asm(".global main \n"
|
||||
"main: \n"
|
||||
" push %bp \n"
|
||||
" mov %sp, %bp \n"
|
||||
" mov 8(%bp), %si \n"
|
||||
" push (%si) \n"
|
||||
" call crc16 \n"
|
||||
" add $0x2, %sp \n"
|
||||
" mov 6(%bp), %di \n"
|
||||
" mov %ax, (%di) \n"
|
||||
" pop %bp \n"
|
||||
" lret $4 \n");
|
||||
int main(int argc, int argv[]) {
|
||||
if (argc < 2) {
|
||||
return -1;
|
||||
}
|
||||
uint16_t seg = kDefaultSegment;
|
||||
if (argc > 2) {
|
||||
seg = argv[2];
|
||||
}
|
||||
return crc16(argv[0], seg, argv[1]);
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ int main(int argc, uint16_t argv[]) {
|
||||
|
||||
uint8_t ok = 0x42;
|
||||
|
||||
for (int i = 0; i < size; ) {
|
||||
for (int i = 0; i < size;) {
|
||||
runcomms(kUntilIdle);
|
||||
// delay?
|
||||
|
||||
|
@@ -164,15 +164,17 @@ char toupper(char 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++) {
|
||||
if (*name == 0 || *name == '.') {
|
||||
if (j == len || name[j] == '.') {
|
||||
fatname[i] = ' ';
|
||||
} else {
|
||||
fatname[i] = toupper(*name++);
|
||||
fatname[i] = toupper(name[j]);
|
||||
j++;
|
||||
}
|
||||
if (i == 7 && *name == '.') {
|
||||
name++;
|
||||
if (i == 7 && name[j] == '.') {
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +194,8 @@ uint16_t __readfile__(const char* name, uint16_t addr) {
|
||||
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 kAddress = 0x100;
|
||||
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};
|
||||
|
||||
char fatname[11];
|
||||
tofatname(name, fatname);
|
||||
tofatname(name, len, fatname);
|
||||
|
||||
uint16_t r = __readfile__(fatname, kFlatAddress);
|
||||
if (r) {
|
||||
memcpy(fatname + 8, "COM", 3);
|
||||
r = __readfile__(fatname, kFlatAddress);
|
||||
}
|
||||
if (r) {
|
||||
return r;
|
||||
}
|
||||
@@ -312,7 +319,8 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
|
||||
ptr++;
|
||||
}
|
||||
const char* fname = ptr;
|
||||
for (; *ptr && *ptr != ' '; ptr++) {
|
||||
int l;
|
||||
for (l = 0; *ptr && *ptr != ' '; l++, ptr++) {
|
||||
}
|
||||
for (; *ptr && nargs < 8;) {
|
||||
if (*ptr == ' ') {
|
||||
@@ -321,7 +329,7 @@ bool ParseCommand(const char* buf, uint16_t& cur_addr, uint16_t& cur_seg) {
|
||||
}
|
||||
args[nargs++] = ReadUint16(ptr);
|
||||
}
|
||||
uint16_t ret = LaunchFile(fname, nargs, args);
|
||||
uint16_t ret = LaunchFile(fname, l, nargs, args);
|
||||
WriteUint16ln(ret);
|
||||
} else if (*ptr == 'w') {
|
||||
dump = false;
|
||||
|
13
src/polos.h
13
src/polos.h
@@ -1,7 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define kLpt1 0x10
|
||||
#define kUntilIdle 1
|
||||
#define kOnce 0
|
||||
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user