From 9ce983480064ed6e57fa681ffc9dcb60459b1c93 Mon Sep 17 00:00:00 2001 From: Daniel Thornburgh Date: Mon, 10 Oct 2022 11:35:57 -0700 Subject: [PATCH] Revert "SDK port for CP/M-65 (#80)" (#82) This reverts commit c158ca9949c549551a441a2767bd8e4720d9b55d. --- mos-platform/CMakeLists.txt | 1 - mos-platform/common/c/ctype.c | 19 -- mos-platform/common/include/ctype.h | 5 +- mos-platform/cpm65/CMakeLists.txt | 37 ---- mos-platform/cpm65/bios.S | 13 -- mos-platform/cpm65/clang.cfg | 4 - mos-platform/cpm65/comhdr.S | 4 - mos-platform/cpm65/cpm-wrappers.c | 112 ----------- mos-platform/cpm65/cpm.S | 106 ----------- mos-platform/cpm65/cpm.h | 179 ----------------- mos-platform/cpm65/link.ld | 70 ------- mos-platform/cpm65/pblock.S | 12 -- mos-platform/cpm65/putchar.c | 9 - mos-platform/cpm65/registers.S | 29 --- mos-platform/cpm65/stack.S | 7 - utils/CMakeLists.txt | 1 - utils/elftocpm65/CMakeLists.txt | 3 - utils/elftocpm65/elftocpm65.cc | 286 ---------------------------- 18 files changed, 1 insertion(+), 896 deletions(-) delete mode 100644 mos-platform/cpm65/CMakeLists.txt delete mode 100644 mos-platform/cpm65/bios.S delete mode 100644 mos-platform/cpm65/clang.cfg delete mode 100644 mos-platform/cpm65/comhdr.S delete mode 100644 mos-platform/cpm65/cpm-wrappers.c delete mode 100644 mos-platform/cpm65/cpm.S delete mode 100644 mos-platform/cpm65/cpm.h delete mode 100644 mos-platform/cpm65/link.ld delete mode 100644 mos-platform/cpm65/pblock.S delete mode 100644 mos-platform/cpm65/putchar.c delete mode 100644 mos-platform/cpm65/registers.S delete mode 100644 mos-platform/cpm65/stack.S delete mode 100644 utils/elftocpm65/CMakeLists.txt delete mode 100644 utils/elftocpm65/elftocpm65.cc diff --git a/mos-platform/CMakeLists.txt b/mos-platform/CMakeLists.txt index 84827d8a7..4f610f207 100644 --- a/mos-platform/CMakeLists.txt +++ b/mos-platform/CMakeLists.txt @@ -48,7 +48,6 @@ add_subdirectory(common) add_subdirectory(atari8) add_subdirectory(commodore) add_subdirectory(c64) -add_subdirectory(cpm65) add_subdirectory(cx16) add_subdirectory(mega65) add_subdirectory(sim) diff --git a/mos-platform/common/c/ctype.c b/mos-platform/common/c/ctype.c index 73db6e80f..6479b7c4f 100644 --- a/mos-platform/common/c/ctype.c +++ b/mos-platform/common/c/ctype.c @@ -4,22 +4,3 @@ int isprint(int c) { char ch = (char)c; return ch >= 0x1f && ch < 0x7f /*DEL*/; } - -int isdigit(int c) { - char ch = (char)c; - return ch >= '0' && ch <= '9'; -} - -int isalpha(int c) { - char ch = (char)c; - return ((ch >= 'A') && (ch <= 'Z')) - || ((ch >= 'a') && (ch <= 'z')); -} - -int toupper(int c) { - char ch = (char)c; - if ((ch >= 'a') && (ch <= 'z')) - ch &= ~0x20; - return ch; -} - diff --git a/mos-platform/common/include/ctype.h b/mos-platform/common/include/ctype.h index 863d647c4..b3cf26add 100644 --- a/mos-platform/common/include/ctype.h +++ b/mos-platform/common/include/ctype.h @@ -5,10 +5,7 @@ extern "C" { #endif -extern int isprint(int c); -extern int isdigit(int c); -extern int isalpha(int c); -extern int toupper(int c); +int isprint(int c); #ifdef __cplusplus } diff --git a/mos-platform/cpm65/CMakeLists.txt b/mos-platform/cpm65/CMakeLists.txt deleted file mode 100644 index 879123d74..000000000 --- a/mos-platform/cpm65/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -platform(cpm65 HOSTED PARENT common) - -if(NOT CMAKE_CROSSCOMPILING) - return() -endif() - -install(FILES - cpm.h -TYPE INCLUDE) -install(FILES link.ld TYPE LIB) - -add_platform_library(cpm65-crt0) -merge_libraries(cpm65-crt0 - common-init-stack - common-copy-zp-data - common-zero-bss -) - -add_platform_library(cpm65-c - cpm.S - cpm-wrappers.c - bios.S - comhdr.S - pblock.S - putchar.c - stack.S - registers.S -) -merge_libraries(cpm65-c - common-c -) - -# abort is preemptively included if LTO is used, which pulls in _exit support -# unneccessarily. It can also be called in an interrupt. -set_property(SOURCE abort.c PROPERTY COMPILE_OPTIONS -fno-lto -fno-static-stack) -target_include_directories(cpm65-c PUBLIC .) - diff --git a/mos-platform/cpm65/bios.S b/mos-platform/cpm65/bios.S deleted file mode 100644 index 4cf8ab4e0..000000000 --- a/mos-platform/cpm65/bios.S +++ /dev/null @@ -1,13 +0,0 @@ -.section .init.20, "Rax", @progbits -__do_setup_bios: - ldy #38 - jsr BDOS - sta BIOS+1 - stx BIOS+2 - -.text - -.global BIOS -BIOS: - jmp 0 ; patched by startup code - diff --git a/mos-platform/cpm65/clang.cfg b/mos-platform/cpm65/clang.cfg deleted file mode 100644 index 03d183775..000000000 --- a/mos-platform/cpm65/clang.cfg +++ /dev/null @@ -1,4 +0,0 @@ --D__CPM65__ --Wl,-emit-relocs --fpost-link-tool=elftocpm65 - diff --git a/mos-platform/cpm65/comhdr.S b/mos-platform/cpm65/comhdr.S deleted file mode 100644 index 46d575052..000000000 --- a/mos-platform/cpm65/comhdr.S +++ /dev/null @@ -1,4 +0,0 @@ -.section .comhdr, "aw", @progbits -_comhdr: - .short _pblock /* address of pblock / relocation data */ - diff --git a/mos-platform/cpm65/cpm-wrappers.c b/mos-platform/cpm65/cpm-wrappers.c deleted file mode 100644 index b8c6e785b..000000000 --- a/mos-platform/cpm65/cpm-wrappers.c +++ /dev/null @@ -1,112 +0,0 @@ -#include "cpm.h" - -void cpm_printstring(const char* s) /* $-terminated */ -{ - cpm_printstring_i((uint16_t)s); -} - -uint8_t cpm_open_file(FCB* fcb) -{ - return cpm_open_file_i((uint16_t)fcb); -} - -uint8_t cpm_close_file(FCB* fcb) -{ - return cpm_close_file_i((uint16_t)fcb); -} - -uint8_t cpm_findfirst(FCB* fcb) -{ - return cpm_findfirst_i((uint16_t)fcb); -} - -uint8_t cpm_findnext(FCB* fcb) -{ - return cpm_findnext_i((uint16_t)fcb); -} - -uint8_t cpm_delete_file(FCB* fcb) -{ - return cpm_delete_file_i((uint16_t)fcb); -} - -uint8_t cpm_read_sequential(FCB* fcb) -{ - return cpm_read_sequential_i((uint16_t)fcb); -} - -uint8_t cpm_write_sequential(FCB* fcb) -{ - return cpm_write_sequential_i((uint16_t)fcb); -} - -uint8_t cpm_make_file(FCB* fcb) -{ - return cpm_make_file_i((uint16_t)fcb); -} - -uint8_t cpm_rename_file(RCB* rcb) -{ - return cpm_rename_file_i((uint16_t)rcb); -} - -void cpm_set_dma(void* ptr) -{ - cpm_set_dma_i((uint16_t)ptr); -} - -uint8_t* cpm_get_allocation_vector(void) -{ - return (uint8_t*)cpm_get_allocation_vector_i(); -} - -uint8_t cpm_set_file_attributes(FCB* fcb) -{ - return cpm_set_file_attributes_i((uint16_t)fcb); -} - -DPB* cpm_get_dpb(void) -{ - return (DPB*)cpm_get_dpb_i(); -} - -uint8_t cpm_read_random(FCB* fcb) -{ - return cpm_read_random_i((uint16_t)fcb); -} - -uint8_t cpm_write_random(FCB* fcb) -{ - return cpm_write_random_i((uint16_t)fcb); -} - -void cpm_seek_to_end(FCB* fcb) -{ - return cpm_seek_to_end_i((uint16_t)fcb); -} - -void cpm_seek_to_seq_pos(FCB* fcb) -{ - return cpm_seek_to_seq_pos_i((uint16_t)fcb); -} - -uint8_t cpm_write_random_filled(FCB* fcb) -{ - return cpm_write_random_filled_i((uint16_t)fcb); -} - -DPH* cpm_bios_seldsk(uint8_t drive) -{ - return (DPH*) cpm_bios_seldsk_i(drive); -} - -void cpm_bios_setdma(void* dma) -{ - cpm_bios_setdma_i((uint16_t) dma); -} - -void cpm_bios_setsec(uint32_t* sector) -{ - cpm_bios_setsec_i((uint16_t) sector); -} - diff --git a/mos-platform/cpm65/cpm.S b/mos-platform/cpm65/cpm.S deleted file mode 100644 index b2dd6bb47..000000000 --- a/mos-platform/cpm65/cpm.S +++ /dev/null @@ -1,106 +0,0 @@ -.macro cpmentry sym:req, num:req, exiter - .section .text.\sym, "ax", @progbits - .global \sym -\sym: - ldy #\num - .ifb \exiter - jmp BDOS - .else - jsr BDOS - jmp \exiter - .endif -.endm - -.macro biosentry sym:req, num:req, exiter - .section .text.\sym, "ax", @progbits - .global \sym -\sym: - ldy #\num - .ifb \exiter - jmp BIOS - .else - jsr BDOS - jmp \exiter - .endif -.endm - -cpmentry cpm_warmboot, 0 -cpmentry cpm_conin, 1 -cpmentry cpm_conout, 2 -cpmentry cpm_auxin, 3 -cpmentry cpm_auxout, 4 -cpmentry cpm_lstout, 5 -cpmentry cpm_conio, 6 -cpmentry cpm_get_iobyte, 7 -cpmentry cpm_set_iobyte, 8 -cpmentry cpm_printstring_i, 9 -cpmentry cpm_readline, 10, __cpmexiter_errno -cpmentry cpm_const, 11 -cpmentry cpm_get_version, 12 -cpmentry cpm_reset_disk_system, 13 -cpmentry cpm_select_drive, 14 -cpmentry cpm_open_file_i, 15, __cpmexiter_errno -cpmentry cpm_close_file_i, 16, __cpmexiter_errno -cpmentry cpm_findfirst_i, 17, __cpmexiter_aorerrno -cpmentry cpm_findnext_i, 18, __cpmexiter_aorerrno -cpmentry cpm_delete_file_i, 19, __cpmexiter_errno -cpmentry cpm_read_sequential_i, 20, __cpmexiter_errno -cpmentry cpm_write_sequential_i, 21, __cpmexiter_errno -cpmentry cpm_make_file_i, 22, __cpmexiter_errno -cpmentry cpm_rename_file_i, 23, __cpmexiter_errno -cpmentry cpm_get_login_vector, 24 -cpmentry cpm_get_current_drive, 25 -cpmentry cpm_set_dma_i, 26 -cpmentry cpm_get_allocation_vector_i, 27 -cpmentry cpm_write_protect_drive, 28 -cpmentry cpm_get_readonly_vector, 29 -cpmentry cpm_set_file_attributes_i, 30, __cpmexiter_errno -cpmentry cpm_get_dpb_i, 31 -cpmentry cpm_get_set_user, 32 -cpmentry cpm_read_random_i, 33, __cpmexiter_errno -cpmentry cpm_write_random_i, 34, __cpmexiter_errno -cpmentry cpm_seek_to_end_i, 35 -cpmentry cpm_seek_to_seq_pos_i, 36 -cpmentry cpm_reset_drives, 37, __cpmexiter_errno -cpmentry cpm_write_random_filled_i, 40, __cpmexiter_errno - -biosentry cpm_bios_const, 0 -biosentry cpm_bios_conin, 1 -biosentry cpm_bios_conout, 2 -biosentry cpm_bios_seldsk_i, 3 -biosentry cpm_bios_setsec_i, 4 -biosentry cpm_bios_setdma_i, 5 -biosentry cpm_bios_read, 6, __cpmexiter_errno -biosentry cpm_bios_write, 7, __cpmexiter_errno -biosentry cpm_bios_relocate, 8 -biosentry cpm_bios_gettpa, 9 -biosentry cpm_bios_settpa, 10 -biosentry cpm_bios_getzp, 11 -biosentry cpm_bios_setzp, 12 - -; On exit from the BDOS (or BIOS), the return value is in A -; and carry is set on error. - -.section .text.cpmexiter_errno, "ax", @progbits -__cpmexiter_errno: - sta cpm_errno - lda #0 - bcc 1f - lda #$ff -1: - rts - -.section .text.cpmexiter_aorerrno, "ax", @progbits -__cpmexiter_aorerrno: - sta cpm_errno - bcc 1f - lda #$ff -1: - rts - -.section .bss.cpm_errno -.global cpm_errno -cpm_errno: .fill 1 - -; vim: ts=4 sw=4 et ft=asm - diff --git a/mos-platform/cpm65/cpm.h b/mos-platform/cpm65/cpm.h deleted file mode 100644 index f1bc16830..000000000 --- a/mos-platform/cpm65/cpm.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef CPM_H -#define CPM_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct __attribute__((packed)) -{ - uint8_t dr; - uint8_t f[11]; - uint8_t ex; - uint8_t s1; - uint8_t s2; - uint8_t rc; - uint8_t al[16]; - uint8_t cr; - uint16_t r; - uint8_t r2; -} -FCB; - -typedef struct __attribute__((packed)) -{ - uint8_t dr; - uint8_t src[11]; - uint8_t _padding[5]; - uint8_t dest[11]; -} -RCB; - -typedef struct __attribute__((packed)) -{ - uint8_t us; - uint8_t f[11]; - uint8_t ex; - uint8_t s1; - uint8_t s2; - uint8_t rc; - uint8_t al[16]; -} -DIRE; - -typedef struct __attribute__((packed)) -{ - uint16_t spt; /* number of 128-byte sectors per track (unused on CP/M-65) */ - uint8_t bsh; /* block shift; 3=1kB, 4=2kB, 5=4kB etc */ - uint8_t blm; /* block mask; 0x07=1kB, 0x0f=2kB, 0x1f=4k etc */ - uint8_t exm; /* extent mask */ - uint16_t dsm; /* maximum block number */ - uint16_t drm; /* maximum directory entry number */ - uint8_t al[2]; /* directory allocation bitmap */ - uint16_t cks; /* checksum vector size */ - uint16_t off; /* number of reserved tracks */ -} -DPB; - -typedef struct __attribute__((packed)) -{ - uint8_t* xlt; /* address of translation vector */ - uint8_t scratch[6]; /* BDOS scratchpad */ - uint8_t* dirbuf; /* address of directory scratchpad */ - DPB* dpb; /* address of DPB */ - uint8_t* csv; /* address of disk change scratchpad */ - uint8_t* alv; /* address of allocation bitmap */ -} -DPH; - -enum -{ - CPME_OK = 0x00, /* success (usually) */ - CPME_NOBLOCK = 0x01, /* or EOF */ - CPME_DISKFULL = 0x02, /* no free blocks on disk */ - CPME_CANTCLOSE = 0x03, /* can't write extent back to disk */ - CPME_NOEXTENT = 0x04, /* only on random access reads */ - CPME_DIRFULL = 0x05, /* no free dirents on disk */ - CPME_BADFCB = 0x09, /* FCB couldn't be parsed */ - CPME_FAILED = 0xff, /* general purpose failure code */ -}; - -extern FCB cpm_fcb; /* primary FCB */ -extern FCB cpm_fcb2; /* secondary FCB (special purpose, overlaps cpm_fcb) */ - -extern uint8_t cpm_default_dma[128]; /* also contains the parsed command line */ -extern uint8_t cpm_ram[]; -extern uint8_t* cpm_ramtop; -extern uint8_t cpm_cmdlinelen; -extern char cpm_cmdline[0x7f]; -extern uint8_t cpm_errno; - -/* 0 */ extern __attribute__((leaf)) void _Noreturn cpm_warmboot(void); -/* 1 */ extern __attribute__((leaf)) uint8_t cpm_conin(void); -/* 2 */ extern __attribute__((leaf)) void cpm_conout(uint8_t b); -/* 3 */ extern __attribute__((leaf)) uint8_t cpm_auxin(void); -/* 4 */ extern __attribute__((leaf)) void cpm_auxout(uint8_t b); -/* 5 */ extern __attribute__((leaf)) void cpm_lstout(uint8_t b); -/* 6 */ extern __attribute__((leaf)) uint8_t cpm_conio(uint8_t b); -/* 7 */ extern __attribute__((leaf)) uint8_t cpm_get_iobyte(void); -/* 8 */ extern __attribute__((leaf)) void cpm_set_iobyte(uint8_t iob); -/* 9 */ extern __attribute__((leaf)) void cpm_printstring_i(uint16_t s); - extern void cpm_printstring(const char* s); /* $-terminated */ -/* 10 */ extern __attribute__((leaf)) uint8_t cpm_readline(uint8_t* buffer); -/* 11 */ extern __attribute__((leaf)) uint8_t cpm_const(void); -/* 12 */ extern __attribute__((leaf)) uint16_t cpm_get_version(void); -/* 13 */ extern __attribute__((leaf)) void cpm_reset_disk_system(void); -/* 14 */ extern __attribute__((leaf)) void cpm_select_drive(uint8_t disk); -/* 15 */ extern __attribute__((leaf)) uint8_t cpm_open_file_i(uint16_t fcb); - extern uint8_t cpm_open_file(FCB* fcb); -/* 16 */ extern __attribute__((leaf)) uint8_t cpm_close_file_i(uint16_t fcb); - extern uint8_t cpm_close_file(FCB* fcb); -/* 17 */ extern __attribute__((leaf)) uint8_t cpm_findfirst_i(uint16_t fcb); - extern uint8_t cpm_findfirst(FCB* fcb); -/* 18 */ extern __attribute__((leaf)) uint8_t cpm_findnext_i(uint16_t fcb); - extern uint8_t cpm_findnext(FCB* fcb); -/* 19 */ extern __attribute__((leaf)) uint8_t cpm_delete_file_i(uint16_t fcb); - extern uint8_t cpm_delete_file(FCB* fcb); -/* 20 */ extern __attribute__((leaf)) uint8_t cpm_read_sequential_i(uint16_t fcb); - extern uint8_t cpm_read_sequential(FCB* fcb); -/* 21 */ extern __attribute__((leaf)) uint8_t cpm_write_sequential_i(uint16_t fcb); - extern uint8_t cpm_write_sequential(FCB* fcb); -/* 22 */ extern __attribute__((leaf)) uint8_t cpm_make_file_i(uint16_t fcb); - extern uint8_t cpm_make_file(FCB* fcb); -/* 23 */ extern __attribute__((leaf)) uint8_t cpm_rename_file_i(uint16_t rcb); - extern uint8_t cpm_rename_file(RCB* rcb); -/* 24 */ extern __attribute__((leaf)) uint16_t cpm_get_login_vector(void); -/* 25 */ extern __attribute__((leaf)) uint8_t cpm_get_current_drive(void); -/* 26 */ extern __attribute__((leaf)) void cpm_set_dma_i(uint16_t ptr); - extern void cpm_set_dma(void* ptr); -/* 27 */ extern __attribute__((leaf)) uint16_t cpm_get_allocation_vector_i(void); - extern uint8_t* cpm_get_allocation_vector(void); -/* 28 */ extern __attribute__((leaf)) void cpm_write_protect_drive(void); -/* 29 */ extern __attribute__((leaf)) uint16_t cpm_get_readonly_vector(void); -/* 30 */ extern __attribute__((leaf)) uint8_t cpm_set_file_attributes_i(uint16_t fcb); - extern uint8_t cpm_set_file_attributes(FCB* fcb); -/* 31 */ extern __attribute__((leaf)) uint16_t cpm_get_dpb_i(void); - extern DPB* cpm_get_dpb(void); -/* 32 */ extern __attribute__((leaf)) uint8_t cpm_get_set_user(uint8_t user); -/* 33 */ extern __attribute__((leaf)) uint8_t cpm_read_random_i(uint16_t fcb); - extern uint8_t cpm_read_random(FCB* fcb); -/* 34 */ extern __attribute__((leaf)) uint8_t cpm_write_random_i(uint16_t fcb); - extern uint8_t cpm_write_random(FCB* fcb); -/* 35 */ extern __attribute__((leaf)) void cpm_seek_to_end_i(uint16_t fcb); - extern void cpm_seek_to_end(FCB* fcb); -/* 36 */ extern __attribute__((leaf)) void cpm_seek_to_seq_pos_i(uint16_t fcb); - extern void cpm_seek_to_seq_pos(FCB* fcb); -/* 37 */ extern __attribute__((leaf)) uint8_t cpm_reset_drives(uint16_t drive_bitmap); -/* 40 */ extern __attribute__((leaf)) uint8_t cpm_write_random_filled_i(uint16_t fcb); - extern uint8_t cpm_write_random_filled(FCB* fcb); - -#define cpm_get_user() cpm_get_set_user(0xff) -#define cpm_set_user(u) cpm_get_set_user(u) - -extern __attribute__((leaf)) uint8_t cpm_bios_const(void); -extern __attribute__((leaf)) uint8_t cpm_bios_conin(void); -extern __attribute__((leaf)) void cpm_bios_conout(uint8_t c); -extern uint16_t cpm_bios_seldsk_i(uint8_t disk); -extern DPH* cpm_bios_seldsk(uint8_t disk); -extern __attribute__((leaf)) void cpm_bios_setsec_i(uint16_t sector); /* actually only 24 bits */ -extern void cpm_bios_setsec(uint32_t* sector); /* actually only 24 bits */ -extern __attribute__((leaf)) void cpm_bios_setdma_i(uint16_t dma); -extern void cpm_bios_setdma(void* dma); -extern __attribute__((leaf)) uint8_t cpm_bios_read(void); -extern __attribute__((leaf)) uint8_t cpm_bios_write(uint8_t deblock); -extern __attribute__((leaf)) void cpm_bios_relocate(uint8_t zp, uint8_t mem); -extern __attribute__((leaf)) uint16_t cpm_bios_gettpa(void); -extern __attribute__((leaf)) void cpm_bios_settpa(uint8_t start, uint8_t end); -extern __attribute__((leaf)) uint16_t cpm_bios_getzp(void); -extern __attribute__((leaf)) void cpm_bios_setzp(uint8_t start, uint8_t end); - -#ifdef __cplusplus -} -#endif - -#endif - -// vim: ts=4 sw=4 et - diff --git a/mos-platform/cpm65/link.ld b/mos-platform/cpm65/link.ld deleted file mode 100644 index f3312eee9..000000000 --- a/mos-platform/cpm65/link.ld +++ /dev/null @@ -1,70 +0,0 @@ -MEMORY { - zp : ORIGIN = 0, LENGTH = 0x70 - ram (rw) : ORIGIN = 0x200, LENGTH = 0xfe00 -} - -PHDRS { - load PT_LOAD; - init PT_LOAD; - relo PT_NOTE; - symtab PT_NOTE; -} - -SECTIONS { - .zp.bss (NOLOAD) : { INCLUDE zp-bss-sections.ld } >zp :NONE - INCLUDE zp-bss-symbols.ld - - .zp (NOLOAD) : { INCLUDE zp-noinit-sections.ld } >zp - - .text : { - BYTE (SIZEOF(.zp)) /* ZP size */ - BYTE ((__heap_start + 255) / 256) /* total memory size (pages) */ - SHORT (_pblock) /* address of pblock / relocation data */ - - KEEP _pblock; - - BDOS = .; - BYTE (0x4c) /* jump instruction for BDOS calls */ - SHORT (0) /* patched by loader */ - } >ram :load - - INCLUDE text.ld - INCLUDE rodata.ld - INCLUDE data.ld - - .zp.data : { - INCLUDE zp-data-sections.ld - BYTE(0) - } >zp AT>ram :init - INCLUDE zp-data-symbols.ld - - .pblock (NOLOAD) : { - _pblock = .; - *(.pblock) - } >ram :NONE - - INCLUDE bss.ld - INCLUDE noinit.ld - - .rela.text : { - } :relo - - .rela.rodata : { - } :relo - - .symtab : { - } :symtab - - PROVIDE (cpm_ram = __heap_start); - -} - -/* The result of this is actually irrelevant --- the elftocpm65 tool will - * rewrite the output file and add relocation information. The only reason this - * is here is to trick the linker into emitting the $FILENAME.elf file which - * elftocpm65 reads. */ - -OUTPUT_FORMAT { - TRIM(ram) -} - diff --git a/mos-platform/cpm65/pblock.S b/mos-platform/cpm65/pblock.S deleted file mode 100644 index 544ab0982..000000000 --- a/mos-platform/cpm65/pblock.S +++ /dev/null @@ -1,12 +0,0 @@ -.global cpm_fcb -.global cpm_fcb2 -.global cpm_default_dma -.global cpm_cmdlinelen -.global cpm_cmdline - -.section .pblock, "wa", @nobits -cpm_fcb: .fill 37 -cpm_fcb2 = cpm_fcb + 16 -cpm_default_dma: -cpm_cmdlinelen: .fill 1 -cpm_cmdline: .fill 127 diff --git a/mos-platform/cpm65/putchar.c b/mos-platform/cpm65/putchar.c deleted file mode 100644 index 111ce9c4d..000000000 --- a/mos-platform/cpm65/putchar.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -void __putchar(char c) { - if (__builtin_expect(c == '\n', 0)) - cpm_conout('\r'); - cpm_conout(c); -} - diff --git a/mos-platform/cpm65/registers.S b/mos-platform/cpm65/registers.S deleted file mode 100644 index 3f72b5c97..000000000 --- a/mos-platform/cpm65/registers.S +++ /dev/null @@ -1,29 +0,0 @@ -/* We define registers as variables each in their own section, rather than - * statically in the linker script, to allow the linker to discard them if - * they're not in use. The compiler doesn't always use them all and - * hand-written machine code only rarely uses any. */ - -.macro register n, m - .section .zp.reg_\n\()_\m, "za", @nobits - .global __rc\n, __rc\m - __rc\n: .fill 1 - __rc\m: .fill 1 -.endm - -register 0, 1 -register 2, 3 -register 4, 5 -register 6, 7 -register 8, 9 -register 10, 11 -register 12, 13 -register 14, 15 -register 16, 17 -register 18, 19 -register 20, 21 -register 22, 23 -register 24, 25 -register 26, 27 -register 28, 29 -register 30, 31 - diff --git a/mos-platform/cpm65/stack.S b/mos-platform/cpm65/stack.S deleted file mode 100644 index db42c3c98..000000000 --- a/mos-platform/cpm65/stack.S +++ /dev/null @@ -1,7 +0,0 @@ -.global __stack - -.section .noinit, "wa", @nobits -stack_start: - .fill 2*1024 -__stack: - diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 916027dc8..5f5b7e94e 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,4 +1,3 @@ -add_subdirectory(elftocpm65) add_subdirectory(ft2-nsf2data) add_subdirectory(ft2-text2data) add_subdirectory(sim) diff --git a/utils/elftocpm65/CMakeLists.txt b/utils/elftocpm65/CMakeLists.txt deleted file mode 100644 index 8a232666d..000000000 --- a/utils/elftocpm65/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -add_executable(elftocpm65 elftocpm65.cc) -install(TARGETS elftocpm65) - diff --git a/utils/elftocpm65/elftocpm65.cc b/utils/elftocpm65/elftocpm65.cc deleted file mode 100644 index 834543422..000000000 --- a/utils/elftocpm65/elftocpm65.cc +++ /dev/null @@ -1,286 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -/* MOS relocations (at least, the ones we care about). */ - -#define R_MOS_ADDR8 2 -#define R_MOS_ADDR16 3 -#define R_MOS_ADDR16_LO 4 -#define R_MOS_ADDR16_HI 5 - -/* ELF structure definitions. */ - -#define ELF32_PHDR_OFFSET offsetof(Elf32_Phdr, p_offset) -#define ELF32_PHDR_FILESZ offsetof(Elf32_Phdr, p_filesz) -#define ELF32_PHDR_VADDR offsetof(Elf32_Phdr, p_vaddr) -#define ELF32_PHDR_PADDR offsetof(Elf32_Phdr, p_paddr) -#define ELF32_PHDR__SIZE sizeof(Elf32_Phdr) - -#define ELF32_SYM_VALUE offsetof(Elf32_Sym, st_value) -#define ELF32_SYM__SIZE sizeof(Elf32_Sym) - -#define ELF32_RELA_OFFSET offsetof(Elf32_Rela, r_offset) -#define ELF32_RELA_INFO offsetof(Elf32_Rela, r_info) -#define ELF32_RELA__SIZE sizeof(Elf32_Rela) - -static std::string outputFilename; -static std::string inputFilename; -static std::fstream outputFile; - -static void error(const char* msg, ...) -{ - va_list ap; - va_start(ap, msg); - fprintf(stderr, "error: "); - vfprintf(stderr, msg, ap); - fputc('\n', stderr); - exit(1); -} - -static void syntaxError() -{ - error("syntax: elftocpm65 []"); -} - -static void parseArguments(int argc, char* const* argv) -{ - if (argc == 2) - { - inputFilename = argv[1]; - outputFilename = - std::regex_replace(inputFilename, std::regex("\\.elf$"), ""); - } - else - { - inputFilename = argv[1]; - outputFilename = argv[2]; - } -} - -class Elf -{ -public: - Elf(const std::string& filename) - { - std::ifstream is( - filename.c_str(), std::fstream::out | std::fstream::binary); - - if (!is) - error("cannot open input file: %s", strerror(errno)); - - _bytes = std::vector((std::istreambuf_iterator(is)), - std::istreambuf_iterator()); - - auto ident = arrayAt(0, 16); - if ((ident[EI_MAG0] != ELFMAG0) || (ident[EI_MAG1] != ELFMAG1) || - (ident[EI_MAG2] != ELFMAG2) || (ident[EI_MAG3] != ELFMAG3) || - (ident[EI_CLASS] != ELFCLASS32) || (ident[EI_DATA] != ELFDATA2LSB)) - error("not a little-endian ELF32 file"); - - if (wordAt(0x2c) != 4) - error("file must have exactly four PHDRs"); - if (wordAt(0x2a) != 32) - error("unsupported PHDR size"); - _phoff = longAt(0x1c); - } - - uint8_t byteAt(uint32_t offset) - { - return _bytes.at(offset); - } - - uint16_t wordAt(uint32_t offset) - { - return byteAt(offset) | (byteAt(offset + 1) << 8); - } - - uint32_t longAt(uint32_t offset) - { - return wordAt(offset) | (wordAt(offset + 2) << 16); - } - - std::vector arrayAt(uint32_t offset, uint32_t length) - { - std::vector result(length); - for (unsigned i = 0; i < length; i++) - result[i] = byteAt(offset + i); - return result; - } - - uint32_t findPhdr(int index) - { - return _phoff + index * 32; - } - -private: - std::vector _bytes; - uint32_t _phoff; -}; - -std::vector toBytestream(const std::set& differences) -{ - std::vector bytes; - uint16_t pos = 0; - - for (uint16_t diff : differences) - { - uint16_t delta = diff - pos; - while (delta >= 0xe) - { - bytes.push_back(0xe); - delta -= 0xe; - } - bytes.push_back(delta); - - pos = diff; - } - bytes.push_back(0xf); - - std::vector results; - for (int i = 0; i < bytes.size(); i += 2) - { - uint8_t left = bytes[i]; - uint8_t right = ((i + 1) < bytes.size()) ? bytes[i + 1] : 0x00; - results.push_back((left << 4) | right); - } - return results; -} - -int main(int argc, char* const* argv) -{ - parseArguments(argc, argv); - if (inputFilename.empty() || outputFilename.empty()) - syntaxError(); - - /* Open the input ELF file. */ - - Elf elf(inputFilename); - - /* Open the output file. */ - - outputFile.open(outputFilename, - std::fstream::in | std::fstream::out | std::fstream::trunc | - std::fstream::binary); - if (!outputFile) - error("cannot open output file: %s", strerror(errno)); - - /* Fetch the actual bytes. */ - - std::vector bytes; - { - auto append_phdr = [&](int index) - { - uint32_t textPhdr = elf.findPhdr(index); - uint32_t codeOffset = elf.longAt(textPhdr + ELF32_PHDR_OFFSET); - uint32_t targetAddress = elf.longAt(textPhdr + ELF32_PHDR_PADDR); - uint32_t codeLen = elf.longAt(textPhdr + ELF32_PHDR_FILESZ); - uint32_t currentLen = bytes.size(); - - bytes.resize(std::max( - bytes.size(), targetAddress + codeLen - 0x200)); - for (int i = 0; i < codeLen; i++) - bytes[targetAddress - 0x200 + i] = elf.byteAt(codeOffset + i); - }; - - append_phdr(0); - append_phdr(1); - } - - /* Accumulate relocations. */ - - std::set zpRelocations; - std::set memRelocations; - memRelocations.insert(3); /* work around linker weirdness */ - uint32_t relaPhdr = elf.findPhdr(2); - uint32_t relaCount = - elf.longAt(relaPhdr + ELF32_PHDR_FILESZ) / ELF32_RELA__SIZE; - uint32_t relaOffset = elf.longAt(relaPhdr + ELF32_PHDR_OFFSET); - uint32_t symbolPhdr = elf.findPhdr(3); - uint32_t symbolCount = - elf.longAt(symbolPhdr + ELF32_PHDR_FILESZ) / ELF32_SYM__SIZE; - uint32_t symbolOffset = elf.longAt(symbolPhdr + ELF32_PHDR_OFFSET); - for (unsigned i = 0; i < relaCount; i++) - { - uint32_t rela = relaOffset + i * ELF32_RELA__SIZE; - uint32_t offset = elf.longAt(rela + ELF32_RELA_OFFSET) - 0x0200; - unsigned symbolIndex = ELF32_R_SYM(elf.longAt(rela + ELF32_RELA_INFO)); - uint32_t symbol = symbolOffset + symbolIndex * ELF32_SYM__SIZE; - uint32_t value = elf.longAt(symbol + ELF32_SYM_VALUE); - - if (value < 0x100) - { - /* Zero page address. */ - - switch (ELF32_R_TYPE(elf.longAt(rela + ELF32_RELA_INFO))) - { - case R_MOS_ADDR8: - case R_MOS_ADDR16: - case R_MOS_ADDR16_LO: - zpRelocations.insert(offset + 0); - break; - - case R_MOS_ADDR16_HI: - break; - } - } - else - { - /* Normal address. */ - - switch (ELF32_R_TYPE(elf.longAt(rela + ELF32_RELA_INFO))) - { - case R_MOS_ADDR8: - error( - "8-bit reference to 16-bit address 0x%x at relo %d, address " - "0x%x?", - value, - i, - offset); - break; - - case R_MOS_ADDR16: - memRelocations.insert(offset + 1); - break; - - case R_MOS_ADDR16_HI: - memRelocations.insert(offset + 0); - break; - - case R_MOS_ADDR16_LO: - break; - } - } - } - - /* Adjust memory relocations to remove the link offset. */ - - for (uint16_t offset : memRelocations) - bytes[offset] -= 2; - - /* Add the relocation tables. */ - - for (uint8_t b : toBytestream(zpRelocations)) - bytes.push_back(b); - for (uint8_t b : toBytestream(memRelocations)) - bytes.push_back(b); - - /* Adjust the memory requirements to ensure the relocations can be loaded. - */ - - bytes[1] = std::max(bytes[1], (bytes.size() + 255) / 256); - - /* Write the output file. */ - - outputFile.write((const char*)&bytes[0], bytes.size()); - outputFile.close(); - - return 0; -} - -// vim: ts=4 sw=4 et