8086: add the page clear and copy logic
authorAlan Cox <alan@linux.intel.com>
Thu, 19 Oct 2017 21:59:03 +0000 (22:59 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 19 Oct 2017 21:59:03 +0000 (22:59 +0100)
Fast 4K copy and clear routines for shuffling memory

Kernel/bank8086.c
Kernel/lowlevel-8086.S

index 6397aa1..59cb627 100644 (file)
 
 #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
index 8c1d391..131b62d 100644 (file)
@@ -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: