1 #include "u.h"
2 #include "tos.h"
3 #include "../port/lib.h"
4 #include "mem.h"
5 #include "dat.h"
6 #include "fns.h"
7 #include "io.h"
8 #include "ureg.h"
9 #include "../port/error.h"
10
11 #define LORMBUF (0x9000)
12
13 static long
rmemrw(int isr,void * a,long n,vlong off)14 rmemrw(int isr, void *a, long n, vlong off)
15 {
16 if(off < 0 || n < 0)
17 error("bad offset/count");
18 if(isr){
19 if(off >= MiB)
20 return 0;
21 if(off+n >= MiB)
22 n = MiB - off;
23 memmove(a, KADDR((uintptr)off), n);
24 }else{
25 /* realmode buf page ok, allow vga framebuf's access */
26 if(off >= MiB || off+n > MiB ||
27 (off < LORMBUF || off+n > LORMBUF+4*KiB) &&
28 (off < 0xA0000 || off+n > 0xB0000+0x10000))
29 error("bad offset/count in write");
30 memmove(KADDR((uintptr)off), a, n);
31 }
32 return n;
33 }
34
35 static long
rmemread(Chan *,void * a,long n,vlong off)36 rmemread(Chan*, void *a, long n, vlong off)
37 {
38 return rmemrw(1, a, n, off);
39 }
40
41 static long
rmemwrite(Chan *,void * a,long n,vlong off)42 rmemwrite(Chan*, void *a, long n, vlong off)
43 {
44 return rmemrw(0, a, n, off);
45 }
46
47 void
realmodelink(void)48 realmodelink(void)
49 {
50 addarchfile("realmodemem", 0660, rmemread, rmemwrite);
51 }
52