diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index d9e370993..fb77f4b6a 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -54,6 +54,17 @@ typedef struct } DPB; +typedef struct +{ + uint8_t xlt[2]; /* address of translation vector */ + uint8_t scratch[6]; /* BDOS scratchpad */ + uint8_t dirbuf[2]; /* address of directory scratchpad */ + uint8_t dpb[2]; /* address of DPB */ + uint8_t csv[2]; /* address of disk change scratchpad */ + uint8_t alv[2]; /* address of allocation bitmap */ +} +DPH; + /* Access an unaligned field (see above). */ #define U16(ptr) (*(uint16_t*)(ptr)) @@ -129,8 +140,22 @@ extern void cpm_printstring0(const char* s); #define cpm_get_user() cpm_get_set_user(0xff) #define cpm_set_user(u) cpm_get_set_user(u) -extern uint8_t bios_conin(void); -extern uint8_t bios_const(void); -extern void bios_conout(uint8_t c); +extern void cpm_bios_boot(void); +extern void cpm_bios_wboot(void); +extern uint8_t cpm_bios_const(void); +extern uint8_t cpm_bios_conin(void); +extern void cpm_bios_conout(uint8_t c); +extern void cpm_bios_list(uint8_t c); +extern void cpm_bios_punch(uint8_t c); +extern uint8_t cpm_bios_reader(void); +extern void cpm_bios_home(void); +extern DPH* cpm_bios_seldsk(uint8_t disk); +extern void cpm_bios_settrk(uint16_t track); +extern void cpm_bios_setsec(uint16_t sector); +extern void cpm_bios_setdma(void* dma); +extern uint8_t cpm_bios_read(void); +extern uint8_t cpm_bios_write(void); +extern uint8_t cpm_bios_listst(void); +extern uint16_t cpm_bios_sectran(uint8_t* table, uint16_t sector); #endif diff --git a/plat/cpm/libsys/_bios.s b/plat/cpm/libsys/_bios.s new file mode 100644 index 000000000..29b9f5629 --- /dev/null +++ b/plat/cpm/libsys/_bios.s @@ -0,0 +1,22 @@ +# +#include "asm.h" + +! Calls a BIOS routine which returns its value in A. +! a = BIOS offset + +.define call_bios_a +call_bios_a: + pop h ! pop return address + pop d ! pop parameter (possibly junk) + push d + push h + push b ! save FP as we'll corrupt it + + mov b, d ! put parameter in BC + mov c, e + call call_bios_raw + + pop b + mov e, a ! put result in DE + mvi d, 0 + ret diff --git a/plat/cpm/libsys/_bios_raw.s b/plat/cpm/libsys/_bios_raw.s new file mode 100644 index 000000000..a8cf11246 --- /dev/null +++ b/plat/cpm/libsys/_bios_raw.s @@ -0,0 +1,14 @@ +# +#include "asm.h" + +! Low level BIOS call routine. The entrypoint offset from WBOOT is in A. +! HL is corrupted on entry. +.define call_bios_raw +call_bios_raw: + lhld 1 ! get BIOS entrypoint + 3 + add l ! add on offset (the -3 is supplied by the caller) + mov l, a + jnc .1 + inr h +.1: + pchl ! call the routine diff --git a/plat/cpm/libsys/bios_conin.s b/plat/cpm/libsys/bios_conin.s deleted file mode 100644 index 98ba4d67c..000000000 --- a/plat/cpm/libsys/bios_conin.s +++ /dev/null @@ -1,15 +0,0 @@ -# -#include "asm.h" - -.define _bios_conin -_bios_conin: - lhld 1 - lxi d, 6 - dad d - push b - call .pchl - pop b - mov e, a - mvi d, 0 - ret - diff --git a/plat/cpm/libsys/bios_conout.s b/plat/cpm/libsys/bios_conout.s deleted file mode 100644 index 6562d3aa6..000000000 --- a/plat/cpm/libsys/bios_conout.s +++ /dev/null @@ -1,21 +0,0 @@ -# -#include "asm.h" - -.define _bios_conout -_bios_conout: - pop h ! pop return address - pop d ! pop parameter into DE - push d - push h - - push b - mov c, e - - lhld 1 - lxi d, 9 - dad d - call .pchl - - pop b - ret - diff --git a/plat/cpm/libsys/bios_const.s b/plat/cpm/libsys/bios_const.s deleted file mode 100644 index c8036be33..000000000 --- a/plat/cpm/libsys/bios_const.s +++ /dev/null @@ -1,16 +0,0 @@ -# -#include "asm.h" - -.define _bios_const -_bios_const: - lhld 1 - lxi d, 3 - dad d - push b - call .pchl - pop b - mov e, a - mvi d, 0 - ret - - diff --git a/plat/cpm/libsys/bios_sectran.s b/plat/cpm/libsys/bios_sectran.s new file mode 100644 index 000000000..75e09cdde --- /dev/null +++ b/plat/cpm/libsys/bios_sectran.s @@ -0,0 +1,31 @@ +# +#include "asm.h" + +! Calls the BIOS SECTRAN routine, which returns its result in HL. + +.define _cpm_bios_sectran +_cpm_bios_sectran: + pop d ! pop return address + pop h ! pop translation table + shld trans_table + pop h ! pop sector number + shld sec_num + push h + push h + push d + push b ! save FP as we'll corrupt it + +trans_table = . + 1 + lxi d, 0 +sec_num = . + 1 + lxi b, 0 + + lda 0x30-3 ! BIOS offset from WBOOT to SECTRAN + call call_bios_raw + + pop b + xchg ! DE = HL + ret + + + diff --git a/plat/cpm/libsys/bios_seldsk.s b/plat/cpm/libsys/bios_seldsk.s new file mode 100644 index 000000000..03ced056f --- /dev/null +++ b/plat/cpm/libsys/bios_seldsk.s @@ -0,0 +1,22 @@ +# +#include "asm.h" + +! Calls the BIOS SELDSK routine, which returns its result in HL. + +.define _cpm_bios_seldsk +_cpm_bios_seldsk: + pop h ! pop return address + pop d ! pop parameter + push d + push h + push b ! save FP as we'll corrupt it + + mov b, d ! put parameter in BC + mov c, e + + mvi a, 0x1b-3 ! offset from WBOOT to SELDSK + call call_bios_raw + + pop b + xchg ! DE = HL + ret diff --git a/plat/cpm/libsys/build.lua b/plat/cpm/libsys/build.lua index 070290326..b7b0c6d8c 100644 --- a/plat/cpm/libsys/build.lua +++ b/plat/cpm/libsys/build.lua @@ -45,6 +45,24 @@ local bdos_calls = { [40] = "cpm_write_random_filled", } +local bios_calls = { + [ 6] = "cpm_bios_const", + [ 9] = "cpm_bios_conin", + [12] = "cpm_bios_conout", + [15] = "cpm_bios_list", + [18] = "cpm_bios_punch", + [21] = "cpm_bios_reader", + [24] = "cpm_bios_home", + -- Special: [27] = "cpm_bios_seldsk", + [30] = "cpm_bios_settrk", + [33] = "cpm_bios_setsec", + [36] = "cpm_bios_setdma", + [39] = "cpm_bios_read", + [42] = "cpm_bios_write", + [45] = "cpm_bios_listst", + -- Special: [48] = "cpm_bios_sectran", +} + local trap_calls = { "EARRAY", "EBADGTO", @@ -83,6 +101,16 @@ for n, name in pairs(bdos_calls) do } } end +for n, name in pairs(bios_calls) do + generated[#generated+1] = normalrule { + name = name, + ins = { "./make_bios_call.sh" }, + outleaves = { name..".s" }, + commands = { + "%{ins[1]} "..n.." "..name.." > %{outs}" + } + } +end for _, name in pairs(trap_calls) do generated[#generated+1] = normalrule { name = name, diff --git a/plat/cpm/libsys/make_bios_call.sh b/plat/cpm/libsys/make_bios_call.sh new file mode 100755 index 000000000..78f8473f8 --- /dev/null +++ b/plat/cpm/libsys/make_bios_call.sh @@ -0,0 +1,10 @@ +#!/bin/sh +cat <