From: Alan Cox Date: Thu, 19 Oct 2017 21:59:03 +0000 (+0100) Subject: 8086: add the page clear and copy logic X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6956112d5daa140b6e7b09f57121ed4be1c4f31b;p=FUZIX.git 8086: add the page clear and copy logic Fast 4K copy and clear routines for shuffling memory --- diff --git a/Kernel/bank8086.c b/Kernel/bank8086.c index 6397aa1c..59cb6276 100644 --- a/Kernel/bank8086.c +++ b/Kernel/bank8086.c @@ -60,6 +60,10 @@ #ifdef CONFIG_BANK_8086 +/* private : asm helpers */ +extern void do_copy_page(uint16_t, uint16_t); +extern void do_zero_page(uint16_t); + typedef uint8_t page_t; /* Assuming a 640K PC/XT. This model needs some work to handle a 16MB 286 @@ -224,6 +228,21 @@ static int do_process_create(uint8_t csize, uint8_t dsize, uint8_t ssize) return 0; } +static void copy_pages(page_t to, page_t from, uint16_t len) +{ + uint16_t ts = page_to_segment(to); + uint16_t fs = page_to_segment(from); + while(len--) + do_copy_page(ts++, fs++); +} + +static void zero_pages(page_t to, uint16_t len) +{ + uint16_t ts = page_to_segment(to); + while(len--) + do_zero_page(ts++); +} + /* * A brk() or stack grow has collided with some other piece of memory. * Try and find a place to move our data and stacks so that they can diff --git a/Kernel/lowlevel-8086.S b/Kernel/lowlevel-8086.S index 8c1d3910..131b62da 100644 --- a/Kernel/lowlevel-8086.S +++ b/Kernel/lowlevel-8086.S @@ -14,6 +14,9 @@ .global set_irq .global cpu_detect + .global copy_to_far + .global copy_from_far + /* GCC glue */ .global __ashrsi3 .global __ashlsi3 @@ -413,6 +416,57 @@ always_16bit: movb $16,bus_width ret +/* + * Handy routines for block copying to/from far memory. These + * are not optimized. We should be smarter about using movsw + * and alignment on 8086+ + * + * Warning: don't use prefixes with rep as we have to run on 8086 + * + * copy_to_far(int16_t seg, int16_t to, void *from, int16_t len) + * copy_from_far(int16_t seg, void *to, int16_t from, int16_t len) + */ + +copy_to_far: + pushw %bp + movw %sp,%bp + pushw %es + pushw %si + pushw %di + pushw %ds + movw 4(%bp),%ax + movw %ax,%es +copier: + movw 6(%bp),%di + movw 8(%bp),%si + movw 10(%bp),%ax + movw %ax,%cx + shr %cx + jz noblock + rep movsw +noblock: + testb $1,%al + jne nofinal + movsb +nofinal: + popw %ds + popw %di + popw %si + popw %es + popw %bp + ret + +copy_from_far: + pushw %bp + movw %sp,%bp + pushw %es + pushw %si + pushw %di + pushw %ds + movw 4(%bp),%ax + movw %ax,%ds + jmp copier + /* FIXME: extract from C library or write nice ones */ __ashlsi3: