2 #include "kernel/kernel.h"
5 #include <machine/vm.h>
7 #include <minix/syslib.h>
8 #include <minix/cpufeature.h>
14 #include <machine/vm.h>
17 #include "arch_proto.h"
22 #include "kernel/watchdog.h"
26 phys_bytes video_mem_vaddr
= 0;
28 #define HASPT(procptr) ((procptr)->p_seg.p_cr3 != 0)
29 static int nfreepdes
= 0;
31 static int freepdes
[MAXFREEPDES
];
33 static u32_t
phys_get32(phys_bytes v
);
35 void mem_clear_mapcache(void)
38 for(i
= 0; i
< nfreepdes
; i
++) {
39 struct proc
*ptproc
= get_cpulocal_var(ptproc
);
40 int pde
= freepdes
[i
];
43 ptv
= ptproc
->p_seg
.p_cr3_v
;
49 /* This function sets up a mapping from within the kernel's address
50 * space to any other area of memory, either straight physical
51 * memory (pr == NULL) or a process view of memory, in 4MB windows.
52 * I.e., it maps in 4MB chunks of virtual (or physical) address space
53 * to 4MB chunks of kernel virtual address space.
55 * It recognizes pr already being in memory as a special case (no
58 * The target (i.e. in-kernel) mapping area is one of the freepdes[]
59 * VM has earlier already told the kernel about that is available. It is
60 * identified as the 'pde' parameter. This value can be chosen freely
61 * by the caller, as long as it is in range (i.e. 0 or higher and corresponds
62 * to a known freepde slot). It is up to the caller to keep track of which
63 * freepde's are in use, and to determine which ones are free to use.
65 * The logical number supplied by the caller is translated into an actual
66 * pde number to be used, and a pointer to it (linear address) is returned
67 * for actual use by phys_copy or memset.
69 static phys_bytes
createpde(
70 const struct proc
*pr
, /* Requested process, NULL for physical. */
71 const phys_bytes linaddr
,/* Address after segment translation. */
72 phys_bytes
*bytes
, /* Size of chunk, function may truncate it. */
73 int free_pde_idx
, /* index of the free slot to use */
74 int *changed
/* If mapping is made, this is set to 1. */
81 assert(free_pde_idx
>= 0 && free_pde_idx
< nfreepdes
);
82 pde
= freepdes
[free_pde_idx
];
83 assert(pde
>= 0 && pde
< 1024);
85 if(pr
&& ((pr
== get_cpulocal_var(ptproc
)) || iskernelp(pr
))) {
86 /* Process memory is requested, and
87 * it's a process that is already in current page table, or
88 * the kernel, which is always there.
89 * Therefore linaddr is valid directly, with the requested
96 /* Requested address is in a process that is not currently
97 * accessible directly. Grab the PDE entry of that process'
98 * page table that corresponds to the requested address.
100 assert(pr
->p_seg
.p_cr3_v
);
101 pdeval
= pr
->p_seg
.p_cr3_v
[I386_VM_PDE(linaddr
)];
103 /* Requested address is physical. Make up the PDE entry. */
104 pdeval
= (linaddr
& I386_VM_ADDR_MASK_4MB
) |
105 I386_VM_BIGPAGE
| I386_VM_PRESENT
|
106 I386_VM_WRITE
| I386_VM_USER
;
109 /* Write the pde value that we need into a pde that the kernel
110 * can access, into the currently loaded page table so it becomes
113 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
114 if(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] != pdeval
) {
115 get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] = pdeval
;
119 /* Memory is now available, but only the 4MB window of virtual
120 * address space that we have mapped; calculate how much of
121 * the requested range is visible and return that in *bytes,
122 * if that is less than the requested range.
124 offset
= linaddr
& I386_VM_OFFSET_MASK_4MB
; /* Offset in 4MB window. */
125 *bytes
= MIN(*bytes
, I386_BIG_PAGE_SIZE
- offset
);
127 /* Return the linear address of the start of the new mapping. */
128 return I386_BIG_PAGE_SIZE
*pde
+ offset
;
132 /*===========================================================================*
133 * check_resumed_caller *
134 *===========================================================================*/
135 static int check_resumed_caller(struct proc
*caller
)
137 /* Returns the result from VM if caller was resumed, otherwise OK. */
138 if (caller
&& (caller
->p_misc_flags
& MF_KCALL_RESUME
)) {
139 assert(caller
->p_vmrequest
.vmresult
!= VMSUSPEND
);
140 return caller
->p_vmrequest
.vmresult
;
146 /*===========================================================================*
148 *===========================================================================*/
149 static int lin_lin_copy(struct proc
*srcproc
, vir_bytes srclinaddr
,
150 struct proc
*dstproc
, vir_bytes dstlinaddr
, vir_bytes bytes
)
155 assert(get_cpulocal_var(ptproc
));
156 assert(get_cpulocal_var(proc_ptr
));
157 assert(read_cr3() == get_cpulocal_var(ptproc
)->p_seg
.p_cr3
);
159 procslot
= get_cpulocal_var(ptproc
)->p_nr
;
161 assert(procslot
>= 0 && procslot
< I386_VM_DIR_ENTRIES
);
163 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
164 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
165 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
166 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
167 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_VMINHIBIT
));
168 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_VMINHIBIT
));
171 phys_bytes srcptr
, dstptr
;
172 vir_bytes chunk
= bytes
;
176 unsigned cpu
= cpuid
;
178 if (srcproc
&& GET_BIT(srcproc
->p_stale_tlb
, cpu
)) {
180 UNSET_BIT(srcproc
->p_stale_tlb
, cpu
);
182 if (dstproc
&& GET_BIT(dstproc
->p_stale_tlb
, cpu
)) {
184 UNSET_BIT(dstproc
->p_stale_tlb
, cpu
);
188 /* Set up 4MB ranges. */
189 srcptr
= createpde(srcproc
, srclinaddr
, &chunk
, 0, &changed
);
190 dstptr
= createpde(dstproc
, dstlinaddr
, &chunk
, 1, &changed
);
194 /* Check for overflow. */
195 if (srcptr
+ chunk
< srcptr
) return EFAULT_SRC
;
196 if (dstptr
+ chunk
< dstptr
) return EFAULT_DST
;
199 PHYS_COPY_CATCH(srcptr
, dstptr
, chunk
, addr
);
202 /* If addr is nonzero, a page fault was caught. */
204 if(addr
>= srcptr
&& addr
< (srcptr
+ chunk
)) {
207 if(addr
>= dstptr
&& addr
< (dstptr
+ chunk
)) {
211 panic("lin_lin_copy fault out of range");
217 /* Update counter and addresses for next iteration, if any. */
223 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
224 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
225 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
226 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
232 static u32_t
phys_get32(phys_bytes addr
)
237 if((r
=lin_lin_copy(NULL
, addr
,
238 proc_addr(SYSTEM
), (phys_bytes
) &v
, sizeof(v
))) != OK
) {
239 panic("lin_lin_copy for phys_get32 failed: %d", r
);
246 static char *cr0_str(u32_t e
)
250 #define FLAG(v) do { if(e & (v)) { strcat(str, #v " "); e &= ~v; } } while(0)
258 if(e
) { strcat(str
, " (++)"); }
262 static char *cr4_str(u32_t e
)
274 if(e
) { strcat(str
, " (++)"); }
279 /*===========================================================================*
281 *===========================================================================*/
282 phys_bytes
umap_virtual(
283 register struct proc
*rp
, /* pointer to proc table entry for process */
284 int seg
, /* T, D, or S segment */
285 vir_bytes vir_addr
, /* virtual address in bytes within the seg */
286 vir_bytes bytes
/* # of bytes to be copied */
291 if(vm_lookup(rp
, vir_addr
, &phys
, NULL
) != OK
) {
292 printf("SYSTEM:umap_virtual: vm_lookup of %s: seg 0x%x: 0x%lx failed\n", rp
->p_name
, seg
, vir_addr
);
296 panic("vm_lookup returned phys: 0x%lx", phys
);
300 printf("SYSTEM:umap_virtual: lookup failed\n");
304 /* Now make sure addresses are contiguous in physical memory
305 * so that the umap makes sense.
307 if(bytes
> 0 && vm_lookup_range(rp
, vir_addr
, NULL
, bytes
) != bytes
) {
308 printf("umap_virtual: %s: %lu at 0x%lx (vir 0x%lx) not contiguous\n",
309 rp
->p_name
, bytes
, vir_addr
, vir_addr
);
313 /* phys must be larger than 0 (or the caller will think the call
314 * failed), and address must not cross a page boundary.
322 /*===========================================================================*
324 *===========================================================================*/
325 int vm_lookup(const struct proc
*proc
, const vir_bytes
virtual,
326 phys_bytes
*physical
, u32_t
*ptent
)
334 assert(!isemptyp(proc
));
337 /* Retrieve page directory entry. */
338 root
= (u32_t
*) proc
->p_seg
.p_cr3
;
339 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
340 pde
= I386_VM_PDE(virtual);
341 assert(pde
>= 0 && pde
< I386_VM_DIR_ENTRIES
);
342 pde_v
= phys_get32((u32_t
) (root
+ pde
));
344 if(!(pde_v
& I386_VM_PRESENT
)) {
348 /* We don't expect to ever see this. */
349 if(pde_v
& I386_VM_BIGPAGE
) {
350 *physical
= pde_v
& I386_VM_ADDR_MASK_4MB
;
351 if(ptent
) *ptent
= pde_v
;
352 *physical
+= virtual & I386_VM_OFFSET_MASK_4MB
;
354 /* Retrieve page table entry. */
355 pt
= (u32_t
*) I386_VM_PFA(pde_v
);
356 assert(!((u32_t
) pt
% I386_PAGE_SIZE
));
357 pte
= I386_VM_PTE(virtual);
358 assert(pte
>= 0 && pte
< I386_VM_PT_ENTRIES
);
359 pte_v
= phys_get32((u32_t
) (pt
+ pte
));
360 if(!(pte_v
& I386_VM_PRESENT
)) {
364 if(ptent
) *ptent
= pte_v
;
366 /* Actual address now known; retrieve it and add page offset. */
367 *physical
= I386_VM_PFA(pte_v
);
368 *physical
+= virtual % I386_PAGE_SIZE
;
374 /*===========================================================================*
376 *===========================================================================*/
377 size_t vm_lookup_range(const struct proc
*proc
, vir_bytes vir_addr
,
378 phys_bytes
*phys_addr
, size_t bytes
)
380 /* Look up the physical address corresponding to linear virtual address
381 * 'vir_addr' for process 'proc'. Return the size of the range covered
382 * by contiguous physical memory starting from that address; this may
383 * be anywhere between 0 and 'bytes' inclusive. If the return value is
384 * nonzero, and 'phys_addr' is non-NULL, 'phys_addr' will be set to the
385 * base physical address of the range. 'vir_addr' and 'bytes' need not
386 * be page-aligned, but the caller must have verified that the given
387 * linear range is valid for the given process at all.
389 phys_bytes phys
, next_phys
;
396 /* Look up the first page. */
397 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
400 if (phys_addr
!= NULL
)
403 len
= I386_PAGE_SIZE
- (vir_addr
% I386_PAGE_SIZE
);
405 next_phys
= phys
+ len
;
407 /* Look up any next pages and test physical contiguity. */
408 while (len
< bytes
) {
409 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
412 if (next_phys
!= phys
)
415 len
+= I386_PAGE_SIZE
;
416 vir_addr
+= I386_PAGE_SIZE
;
417 next_phys
+= I386_PAGE_SIZE
;
420 /* We might now have overshot the requested length somewhat. */
421 return MIN(bytes
, len
);
424 /*===========================================================================*
426 *===========================================================================*/
427 int vm_check_range(struct proc
*caller
, struct proc
*target
,
428 vir_bytes vir_addr
, size_t bytes
, int writeflag
)
430 /* Public interface to vm_suspend(), for use by kernel calls. On behalf
431 * of 'caller', call into VM to check linear virtual address range of
432 * process 'target', starting at 'vir_addr', for 'bytes' bytes. This
433 * function assumes that it will called twice if VM returned an error
434 * the first time (since nothing has changed in that case), and will
435 * then return the error code resulting from the first call. Upon the
436 * first call, a non-success error code is returned as well.
440 if ((caller
->p_misc_flags
& MF_KCALL_RESUME
) &&
441 (r
= caller
->p_vmrequest
.vmresult
) != OK
)
444 vm_suspend(caller
, target
, vir_addr
, bytes
, VMSTYPE_KERNELCALL
,
451 static char *flagstr(u32_t e
, const int dir
)
455 FLAG(I386_VM_PRESENT
);
460 FLAG(I386_VM_GLOBAL
);
462 FLAG(I386_VM_BIGPAGE
); /* Page directory entry only */
464 FLAG(I386_VM_DIRTY
); /* Page table entry only */
468 static void vm_pt_print(u32_t
*pagetable
, const u32_t v
)
473 assert(!((u32_t
) pagetable
% I386_PAGE_SIZE
));
475 for(pte
= 0; pte
< I386_VM_PT_ENTRIES
; pte
++) {
477 pte_v
= phys_get32((u32_t
) (pagetable
+ pte
));
478 if(!(pte_v
& I386_VM_PRESENT
))
480 pfa
= I386_VM_PFA(pte_v
);
481 printf("%4d:%08lx:%08lx %2s ",
482 pte
, v
+ I386_PAGE_SIZE
*pte
, pfa
,
483 (pte_v
& I386_VM_WRITE
) ? "rw":"RO");
485 if(col
== 3) { printf("\n"); col
= 0; }
487 if(col
> 0) printf("\n");
492 static void vm_print(u32_t
*root
)
496 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
498 printf("page table 0x%lx:\n", root
);
500 for(pde
= 0; pde
< I386_VM_DIR_ENTRIES
; pde
++) {
503 pde_v
= phys_get32((u32_t
) (root
+ pde
));
504 if(!(pde_v
& I386_VM_PRESENT
))
506 if(pde_v
& I386_VM_BIGPAGE
) {
507 printf("%4d: 0x%lx, flags %s\n",
508 pde
, I386_VM_PFA(pde_v
), flagstr(pde_v
, 1));
510 pte_a
= (u32_t
*) I386_VM_PFA(pde_v
);
511 printf("%4d: pt %08lx %s\n",
512 pde
, pte_a
, flagstr(pde_v
, 1));
513 vm_pt_print(pte_a
, pde
* I386_VM_PT_ENTRIES
* I386_PAGE_SIZE
);
523 /*===========================================================================*
525 *===========================================================================*/
526 int vm_memset(struct proc
* caller
, endpoint_t who
, phys_bytes ph
, int c
,
530 struct proc
*whoptr
= NULL
;
531 phys_bytes cur_ph
= ph
;
532 phys_bytes left
= count
;
533 phys_bytes ptr
, chunk
, pfa
= 0;
536 if ((r
= check_resumed_caller(caller
)) != OK
)
539 /* NONE for physical, otherwise virtual */
540 if (who
!= NONE
&& !(whoptr
= endpoint_lookup(who
)))
544 pattern
= c
| (c
<< 8) | (c
<< 16) | (c
<< 24);
546 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
547 assert(!catch_pagefaults
);
548 catch_pagefaults
= 1;
550 /* We can memset as many bytes as we have remaining,
551 * or as many as remain in the 4MB chunk we mapped in.
556 ptr
= createpde(whoptr
, cur_ph
, &chunk
, 0, &new_cr3
);
561 /* If a page fault happens, pfa is non-null */
562 if ((pfa
= phys_memset(ptr
, pattern
, chunk
))) {
564 /* If a process pagefaults, VM may help out */
566 vm_suspend(caller
, whoptr
, ph
, count
,
567 VMSTYPE_KERNELCALL
, 1);
568 assert(catch_pagefaults
);
569 catch_pagefaults
= 0;
573 /* Pagefault when phys copying ?! */
574 panic("vm_memset: pf %lx addr=%lx len=%lu\n",
582 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
583 assert(catch_pagefaults
);
584 catch_pagefaults
= 0;
589 /*===========================================================================*
591 *===========================================================================*/
593 struct proc
* caller
,
594 struct vir_addr
*src_addr
, /* source virtual address */
595 struct vir_addr
*dst_addr
, /* destination virtual address */
596 vir_bytes bytes
, /* # of bytes to copy */
597 int vmcheck
/* if nonzero, can return VMSUSPEND */
600 /* Copy bytes from virtual address src_addr to virtual address dst_addr. */
601 struct vir_addr
*vir_addr
[2]; /* virtual source and destination address */
603 struct proc
*procs
[2];
605 assert((vmcheck
&& caller
) || (!vmcheck
&& !caller
));
607 /* Check copy count. */
608 if (bytes
<= 0) return(EDOM
);
610 /* Do some more checks and map virtual addresses to physical addresses. */
611 vir_addr
[_SRC_
] = src_addr
;
612 vir_addr
[_DST_
] = dst_addr
;
614 for (i
=_SRC_
; i
<=_DST_
; i
++) {
615 endpoint_t proc_e
= vir_addr
[i
]->proc_nr_e
;
622 if(!isokendpt(proc_e
, &proc_nr
)) {
623 printf("virtual_copy: no reasonable endpoint\n");
626 p
= proc_addr(proc_nr
);
632 if ((r
= check_resumed_caller(caller
)) != OK
)
635 if((r
=lin_lin_copy(procs
[_SRC_
], vir_addr
[_SRC_
]->offset
,
636 procs
[_DST_
], vir_addr
[_DST_
]->offset
, bytes
)) != OK
) {
638 struct proc
*target
= NULL
;
640 if(r
!= EFAULT_SRC
&& r
!= EFAULT_DST
)
641 panic("lin_lin_copy failed: %d", r
);
642 if(!vmcheck
|| !caller
) {
646 if(r
== EFAULT_SRC
) {
647 lin
= vir_addr
[_SRC_
]->offset
;
648 target
= procs
[_SRC_
];
650 } else if(r
== EFAULT_DST
) {
651 lin
= vir_addr
[_DST_
]->offset
;
652 target
= procs
[_DST_
];
655 panic("r strange: %d", r
);
661 vm_suspend(caller
, target
, lin
, bytes
, VMSTYPE_KERNELCALL
, writeflag
);
668 /*===========================================================================*
670 *===========================================================================*/
671 int data_copy(const endpoint_t from_proc
, const vir_bytes from_addr
,
672 const endpoint_t to_proc
, const vir_bytes to_addr
,
675 struct vir_addr src
, dst
;
677 src
.offset
= from_addr
;
678 dst
.offset
= to_addr
;
679 src
.proc_nr_e
= from_proc
;
680 dst
.proc_nr_e
= to_proc
;
681 assert(src
.proc_nr_e
!= NONE
);
682 assert(dst
.proc_nr_e
!= NONE
);
684 return virtual_copy(&src
, &dst
, bytes
);
687 /*===========================================================================*
688 * data_copy_vmcheck *
689 *===========================================================================*/
690 int data_copy_vmcheck(struct proc
* caller
,
691 const endpoint_t from_proc
, const vir_bytes from_addr
,
692 const endpoint_t to_proc
, const vir_bytes to_addr
,
695 struct vir_addr src
, dst
;
697 src
.offset
= from_addr
;
698 dst
.offset
= to_addr
;
699 src
.proc_nr_e
= from_proc
;
700 dst
.proc_nr_e
= to_proc
;
701 assert(src
.proc_nr_e
!= NONE
);
702 assert(dst
.proc_nr_e
!= NONE
);
704 return virtual_copy_vmcheck(caller
, &src
, &dst
, bytes
);
707 void memory_init(void)
709 assert(nfreepdes
== 0);
711 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
712 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
714 assert(kinfo
.freepde_start
< I386_VM_DIR_ENTRIES
);
715 assert(nfreepdes
== 2);
716 assert(nfreepdes
<= MAXFREEPDES
);
719 /*===========================================================================*
721 *===========================================================================*/
722 void arch_proc_init(struct proc
*pr
, const u32_t ip
, const u32_t sp
,
723 const u32_t ps_str
, char *name
)
726 strlcpy(pr
->p_name
, name
, sizeof(pr
->p_name
));
728 /* set custom state we know */
731 pr
->p_reg
.bx
= ps_str
;
734 static int oxpcie_mapping_index
= -1,
735 lapic_mapping_index
= -1,
736 ioapic_first_index
= -1,
737 ioapic_last_index
= -1,
738 video_mem_mapping_index
= -1,
739 usermapped_glo_index
= -1,
740 usermapped_index
= -1, first_um_idx
= -1;
742 extern char *video_mem
;
744 extern char usermapped_start
, usermapped_end
, usermapped_nonglo_start
;
746 int arch_phys_map(const int index
,
751 static int first
= 1;
753 static char *ser_var
= NULL
;
754 u32_t glo_len
= (u32_t
) &usermapped_nonglo_start
-
755 (u32_t
) &usermapped_start
;
758 memset(&minix_kerninfo
, 0, sizeof(minix_kerninfo
));
759 video_mem_mapping_index
= freeidx
++;
761 usermapped_glo_index
= freeidx
++;
764 usermapped_index
= freeidx
++;
765 first_um_idx
= usermapped_index
;
766 if(usermapped_glo_index
!= -1)
767 first_um_idx
= usermapped_glo_index
;
771 lapic_mapping_index
= freeidx
++;
772 if (ioapic_enabled
) {
773 ioapic_first_index
= freeidx
;
774 assert(nioapics
> 0);
776 ioapic_last_index
= freeidx
-1;
781 if((ser_var
= env_get("oxpcie"))) {
782 if(ser_var
[0] != '0' || ser_var
[1] != 'x') {
783 printf("oxpcie address in hex please\n");
785 printf("oxpcie address is %s\n", ser_var
);
786 oxpcie_mapping_index
= freeidx
++;
794 if(index
== usermapped_glo_index
) {
795 *addr
= vir2phys(&usermapped_start
);
797 *flags
= VMMF_USER
| VMMF_GLO
;
800 else if(index
== usermapped_index
) {
801 *addr
= vir2phys(&usermapped_nonglo_start
);
802 *len
= (u32_t
) &usermapped_end
-
803 (u32_t
) &usermapped_nonglo_start
;
807 else if (index
== video_mem_mapping_index
) {
808 /* map video memory in so we can print panic messages */
809 *addr
= MULTIBOOT_VIDEO_BUFFER
;
810 *len
= I386_PAGE_SIZE
;
815 else if (index
== lapic_mapping_index
) {
816 /* map the local APIC if enabled */
820 *len
= 4 << 10 /* 4kB */;
821 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
824 else if (ioapic_enabled
&& index
>= ioapic_first_index
&& index
<= ioapic_last_index
) {
825 int ioapic_idx
= index
- ioapic_first_index
;
826 *addr
= io_apic
[ioapic_idx
].paddr
;
828 *len
= 4 << 10 /* 4kB */;
829 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
830 printf("ioapic map: addr 0x%lx\n", *addr
);
836 if(index
== oxpcie_mapping_index
) {
837 *addr
= strtoul(ser_var
+2, NULL
, 16);
839 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
847 int arch_phys_map_reply(const int index
, const vir_bytes addr
)
850 /* if local APIC is enabled */
851 if (index
== lapic_mapping_index
&& lapic_addr
) {
852 lapic_addr_vaddr
= addr
;
855 else if (ioapic_enabled
&& index
>= ioapic_first_index
&&
856 index
<= ioapic_last_index
) {
857 int i
= index
- ioapic_first_index
;
858 io_apic
[i
].vaddr
= addr
;
864 if (index
== oxpcie_mapping_index
) {
865 oxpcie_set_vaddr((unsigned char *) addr
);
869 if(index
== first_um_idx
) {
870 extern struct minix_ipcvecs minix_ipcvecs_sysenter
,
871 minix_ipcvecs_syscall
,
872 minix_ipcvecs_softint
;
873 extern u32_t usermapped_offset
;
874 assert(addr
> (u32_t
) &usermapped_start
);
875 usermapped_offset
= addr
- (u32_t
) &usermapped_start
;
876 #define FIXEDPTR(ptr) (void *) ((u32_t)ptr + usermapped_offset)
877 #define FIXPTR(ptr) ptr = FIXEDPTR(ptr)
878 #define ASSIGN(minixstruct) minix_kerninfo.minixstruct = FIXEDPTR(&minixstruct)
884 ASSIGN(arm_frclock
); /* eh, why not. */
887 /* select the right set of IPC routines to map into processes */
888 if(minix_feature_flags
& MKF_I386_INTEL_SYSENTER
) {
889 DEBUGBASIC(("kernel: selecting intel sysenter ipc style\n"));
890 minix_kerninfo
.minix_ipcvecs
= &minix_ipcvecs_sysenter
;
891 } else if(minix_feature_flags
& MKF_I386_AMD_SYSCALL
) {
892 DEBUGBASIC(("kernel: selecting amd syscall ipc style\n"));
893 minix_kerninfo
.minix_ipcvecs
= &minix_ipcvecs_syscall
;
895 DEBUGBASIC(("kernel: selecting fallback (int) ipc style\n"));
896 minix_kerninfo
.minix_ipcvecs
= &minix_ipcvecs_softint
;
899 /* adjust the pointers of the functions and the struct
900 * itself to the user-accessible mapping
902 FIXPTR(minix_kerninfo
.minix_ipcvecs
->send
);
903 FIXPTR(minix_kerninfo
.minix_ipcvecs
->receive
);
904 FIXPTR(minix_kerninfo
.minix_ipcvecs
->sendrec
);
905 FIXPTR(minix_kerninfo
.minix_ipcvecs
->senda
);
906 FIXPTR(minix_kerninfo
.minix_ipcvecs
->sendnb
);
907 FIXPTR(minix_kerninfo
.minix_ipcvecs
->notify
);
908 FIXPTR(minix_kerninfo
.minix_ipcvecs
->do_kernel_call
);
909 FIXPTR(minix_kerninfo
.minix_ipcvecs
);
911 minix_kerninfo
.kerninfo_magic
= KERNINFO_MAGIC
;
912 minix_kerninfo
.minix_feature_flags
= minix_feature_flags
;
913 minix_kerninfo_user
= (vir_bytes
) FIXEDPTR(&minix_kerninfo
);
915 /* if libc_ipc is set, disable usermapped ipc functions
916 * and force binaries to use in-libc fallbacks.
918 if(env_get("libc_ipc")) {
919 printf("kernel: forcing in-libc fallback ipc style\n");
920 minix_kerninfo
.minix_ipcvecs
= NULL
;
922 minix_kerninfo
.ki_flags
|= MINIX_KIF_IPCVECS
;
925 minix_kerninfo
.ki_flags
|= MINIX_KIF_USERINFO
;
930 if(index
== usermapped_index
) return OK
;
932 if (index
== video_mem_mapping_index
) {
933 video_mem_vaddr
= addr
;
940 int arch_enable_paging(struct proc
* caller
)
942 assert(caller
->p_seg
.p_cr3
);
944 /* load caller's page table */
945 switch_address_space(caller
);
947 video_mem
= (char *) video_mem_vaddr
;
950 /* start using the virtual addresses */
952 /* if local APIC is enabled */
954 lapic_addr
= lapic_addr_vaddr
;
955 lapic_eoi_addr
= LAPIC_EOI
;
957 /* if IO apics are enabled */
958 if (ioapic_enabled
) {
961 for (i
= 0; i
< nioapics
; i
++) {
962 io_apic
[i
].addr
= io_apic
[i
].vaddr
;
968 wait_for_APs_to_finish_booting();
974 * We make sure that we don't enable the watchdog until paging is turned
975 * on as we might get an NMI while switching and we might still use wrong
976 * lapic address. Bad things would happen. It is unfortunate but such is
979 if (watchdog_enabled
)
980 i386_watchdog_start();
986 void release_address_space(struct proc
*pr
)
988 pr
->p_seg
.p_cr3_v
= NULL
;
991 /* computes a checksum of a buffer of a given length. The byte sum must be zero */
992 int platform_tbl_checksum_ok(void *ptr
, unsigned int length
)
996 for (i
= 0; i
< length
; i
++)
997 total
+= ((unsigned char *)ptr
)[i
];
1001 int platform_tbl_ptr(phys_bytes start
,
1006 phys_bytes
* phys_addr
,
1007 int ((* cmp_f
)(void *)))
1011 for (addr
= start
; addr
< end
; addr
+= increment
) {
1012 phys_copy (addr
, (phys_bytes
) buff
, size
);