/* Device parameters */
#define NUM_DEV_TTY 3
#define TTYDEV BOOT_TTY /* Device used by kernel for messages, panics */
-#define SWAPDEV (258) /* Device for swapping (2nd hd). */
+#define SWAPDEV (256) /* Device for swapping (1st hd). */
#define NBUFS 10 /* Number of block buffers */
#define NMOUNTS 4 /* Number of mounts at a time */
#define HDCMD_INIT 0x60 /* Ditto */
#define HDCMD_SEEK 0x70
+/* Used by the asm helpers */
+uint8_t hd_page;
+
/* Seek and restore low 4 bits are the step rate, read/write support
multi-sector mode but not all emulators do .. */
return st;
}
-
-
/* Wait for DRQ or an error */
static uint8_t hd_waitdrq(void)
{
/* FIXME: move this to asm in _COMMONMEM and support banks and swap */
static uint8_t hd_xfer(bool is_read, uint16_t addr)
{
- int ct = 256;
- uint8_t *ptr = (uint8_t *)addr;
-
/* Error ? */
if (hd_status & 0x01)
return hd_status;
- if (is_read) {
- /* Ought to check DRQ per byte ? */
- while (ct--) {
- *ptr++ = hd_data;
- }
- } else {
- while (ct--) {
- hd_data = *ptr++;
- }
- }
+ if (is_read)
+ hd_xfer_in(addr);
+ else
+ hd_xfer_out(addr);
/* Should be returning READY, and maybe SEEKDONE */
return hd_status;
}
{
blkno_t block;
uint16_t dptr;
- int ct = 0;
+ uint16_t ct = 0;
int tries;
uint8_t err = 0;
uint8_t cmd = HDCMD_READ;
uint8_t head;
uint8_t sector;
-
- if (rawflag)
+ uint16_t nblock;
+
+ if (rawflag == 0) {
+ dptr = (uint16_t)udata.u_buf->bf_data;
+ block = udata.u_buf->bf_blk;
+ nblock = 2;
+ hd_page = 0; /* Kernel */
+ } else if (rawflag == 2) {
+ nblock = swapcnt >> 8; /* in 256 byte chunks */
+ dptr = (uint16_t)swapbase;
+ hd_page = swapproc->p_page;
+ block = swapblk;
+ kprintf("Swapping for page %x %d blocks\n", hd_page, nblock);
+ } else
goto bad2;
if (!is_read)
cmd = HDCMD_WRITE;
- dptr = (uint16_t) udata.u_buf->bf_data;
- block = udata.u_buf->bf_blk;
/* We assume 32 sectors per track for now. From our 512 byte
PoV that's 16 */
hd_precomp = 0; /* FIXME */
hd_sdh = 0x80 | head | (minor << 3);
- while (ct < 2) {
+ while (ct < nblock) {
for (tries = 0; tries < 4; tries++) {
/* issue the command */
hd_cmd = cmd;
int hd_write(uint8_t minor, uint8_t rawflag, uint8_t flag);
int hd_open(uint8_t minor, uint16_t flag);
+/* helpers in common memory for the block transfers */
+int hd_xfer_in(uint16_t addr);
+int hd_xfer_out(uint16_t addr);
+
#endif /* __DEVHD_DOT_H__ */
.globl platform_interrupt_all
.globl _kernel_flag
+ ; hard disk helpers
+ .globl _hd_xfer_in
+ .globl _hd_xfer_out
+ ; and the page from the C code
+ .globl _hd_page
+
; exported debugging tools
.globl _trap_monitor
.globl outchar
.include "../kernel.def"
; -----------------------------------------------------------------------------
-; COMMON MEMORY BANK (0xEA00 upwards)
+; COMMON MEMORY BANK (0xE800 upwards)
; -----------------------------------------------------------------------------
.area _COMMONMEM
outchar:
; out (0x01), a
ret
+
+;
+; Swap helpers
+;
+_hd_xfer_in:
+ pop de
+ pop hl
+ push hl
+ push de
+ ld a, (_hd_page)
+ or a
+ call nz, map_process_a
+ ld bc, #0xC8 ; 256 bytes from 0xC8
+ inir
+ call map_kernel
+ ret
+
+_hd_xfer_out:
+ pop de
+ pop hl
+ push hl
+ push de
+ ld a, (_hd_page)
+ or a
+ call nz, map_process_a
+ ld bc, #0xC8 ; 256 bytes to 0xC8
+ otir
+ call map_kernel
+ ret