3 // This software is copyright (c) 2006 Scott Wood <scott@buserror.net>.
5 // Permission is hereby granted, free of charge, to any person obtaining a copy of
6 // this software and associated documentation files (the "Software"), to deal with
7 // the Software without restriction, including without limitation the rights to
8 // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9 // of the Software, and to permit persons to whom the Software is furnished to do
10 // so, subject to the following condition:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
23 #include <kern/types.h>
24 #include <kern/libc.h>
25 #include <kern/time.h>
26 #include <kern/thread.h>
31 extern IMappable physmem;
34 void thread(void *arg)
36 // Yuck -- out param->return value promotion would turn it into
37 // AddrSpace aspace = AddrSpace::downcast(Mem::proc_addr_space_factory.create()),
38 // but that's still ugly. Perhaps something like:
39 // AddrSpace aspace(Mem::proc_addr_space_factory).
42 proc_addr_space_factory.create(&obj);
43 IAddrSpace aspace = IAddrSpace::downcast(obj);
45 printf("aspace %p created\n", (void *)aspace);
47 AddrSpace *kaspace = AddrSpace::classptr(aspace);
49 printf("kaspace %p\n", kaspace);
51 curthread->set_aspace(kaspace);
52 printf("Addr space set\n");
54 IAddrSpace stacked[2];
55 IMappable mappables[2];
57 for (int i = 0; i < 2; i++) {
58 addr_space_factory.create(&obj);
59 stacked[i] = IAddrSpace::downcast(obj);
60 stacked[i].get_mappable(&mappables[i]);
63 printf("stacked %p %p mappable %p %p\n",
64 (void *)stacked[0], (void *)stacked[1],
65 (void *)mappables[0], (void *)mappables[1]);
67 char *buf = new char[100000];
68 printf("buf %p\n", buf);
70 char *abuf = (char *)((((ulong)buf) + 4095) & ~4095);
71 printf("abuf %p\n", abuf);
73 memset(abuf, 'A', Arch::page_size);
74 memset(abuf + Arch::page_size, 'B', Arch::page_size);
78 System::Mem::MapFlags mf;
79 mf.access_IDLNS_Read = 1;
80 mf.access_IDLNS_Write = 1;
84 region.end = 0xffffffff;
85 vstart[4] = 0xdeadbeef00000000ULL;
86 vstart[5] = 0xdeadb12345678000ULL;
88 stacked[0].map(Mem::physmem, region, &vstart[4], mf);
90 stacked[0].map(Mem::physmem, region, &vstart[5], mf);
92 printf("stacked[0] vstart %llx, %llx\n", vstart[4], vstart[5]);
94 region.start = 0xdeadb00000000000ULL;
95 region.end = 0xdeadbfffffffffffULL;
96 vstart[4] = 0x1234500000000000ULL;
98 // mf.access_IDLNS_Write = 0;
100 stacked[1].map(mappables[0], region, &vstart[4], mf);
102 printf("stacked[1] vstart %llx\n", vstart[4]);
104 region.start = vstart[4] + 0xeef00000000ULL + kvirt_to_phys(abuf);
105 region.end = vstart[4] + 0xeef00000000ULL + kvirt_to_phys(abuf) + Arch::page_size - 1;
106 vstart[0] = System::Mem::AddrSpace_ns::unspecified_start;
107 vstart[1] = System::Mem::AddrSpace_ns::unspecified_start;
108 vstart[2] = System::Mem::AddrSpace_ns::unspecified_start;
109 mf.access_IDLNS_Write = 1;
111 aspace.map(mappables[1], region, &vstart[0], mf);
113 region.start += Arch::page_size;
114 region.end += Arch::page_size;
115 aspace.map(mappables[1], region, &vstart[1], mf);
117 region.start = vstart[4] + 0x12345678000ULL + kvirt_to_phys(abuf);
118 region.end = vstart[4] + 0x12345678000ULL + kvirt_to_phys(abuf) + Arch::page_size - 1;
120 aspace.map(mappables[1], region, &vstart[2], mf);
123 aspace.map(mappables[1], region, &vstart[3], mf);
125 printf("vstart %llx %llx %llx %llx\n", vstart[0], vstart[1], vstart[2], vstart[3]);
127 vbuf[0] = (char *)vstart[0];
128 vbuf[1] = (char *)vstart[1];
129 vbuf[2] = (char *)vstart[2];
130 vbuf[3] = (char *)vstart[3];
132 printf("%c%c%c%c ", vbuf[0][0], vbuf[0][1], vbuf[0][2], vbuf[0][3]);
133 printf("%c%c%c%c ", vbuf[1][0], vbuf[1][1], vbuf[1][2], vbuf[1][3]);
134 printf("%c%c%c%c ", vbuf[2][0], vbuf[2][1], vbuf[2][2], vbuf[2][3]);
135 printf("%c%c%c%c\n", vbuf[3][0], vbuf[3][1], vbuf[3][2], vbuf[3][3]);
143 region.start = 0xdeadbeef00000000ULL + kvirt_to_phys(abuf) + Arch::page_size;
144 region.end = region.start + Arch::page_size - 1;
145 printf("unmapping %llx->%llx\n", region.start, region.end);
147 stacked[0].unmap(region);
150 printf("%c%c%c%c ", vbuf[0][0], vbuf[0][1], vbuf[0][2], vbuf[0][3]);
151 printf("%c%c%c%c ", vbuf[1][0], vbuf[1][1], vbuf[1][2], vbuf[1][3]);
152 printf("%c%c%c%c ", vbuf[2][0], vbuf[2][1], vbuf[2][2], vbuf[2][3]);
153 printf("%c%c%c%c\n", vbuf[3][0], vbuf[3][1], vbuf[3][2], vbuf[3][3]);
158 Threads::sched.new_thread(thread, NULL, "thread")->wake();