2 #include "kernel/kernel.h"
5 #include <machine/vm.h>
7 #include <minix/type.h>
8 #include <minix/syslib.h>
9 #include <minix/cpufeature.h>
15 #include <machine/vm.h>
18 #include "arch_proto.h"
23 #include "kernel/watchdog.h"
27 phys_bytes video_mem_vaddr
= 0;
29 #define HASPT(procptr) ((procptr)->p_seg.p_cr3 != 0)
30 static int nfreepdes
= 0;
32 static int freepdes
[MAXFREEPDES
];
34 static u32_t
phys_get32(phys_bytes v
);
36 void mem_clear_mapcache(void)
39 for(i
= 0; i
< nfreepdes
; i
++) {
40 struct proc
*ptproc
= get_cpulocal_var(ptproc
);
41 int pde
= freepdes
[i
];
44 ptv
= ptproc
->p_seg
.p_cr3_v
;
50 /* This function sets up a mapping from within the kernel's address
51 * space to any other area of memory, either straight physical
52 * memory (pr == NULL) or a process view of memory, in 4MB windows.
53 * I.e., it maps in 4MB chunks of virtual (or physical) address space
54 * to 4MB chunks of kernel virtual address space.
56 * It recognizes pr already being in memory as a special case (no
59 * The target (i.e. in-kernel) mapping area is one of the freepdes[]
60 * VM has earlier already told the kernel about that is available. It is
61 * identified as the 'pde' parameter. This value can be chosen freely
62 * by the caller, as long as it is in range (i.e. 0 or higher and corresonds
63 * to a known freepde slot). It is up to the caller to keep track of which
64 * freepde's are in use, and to determine which ones are free to use.
66 * The logical number supplied by the caller is translated into an actual
67 * pde number to be used, and a pointer to it (linear address) is returned
68 * for actual use by phys_copy or memset.
70 static phys_bytes
createpde(
71 const struct proc
*pr
, /* Requested process, NULL for physical. */
72 const phys_bytes linaddr
,/* Address after segment translation. */
73 phys_bytes
*bytes
, /* Size of chunk, function may truncate it. */
74 int free_pde_idx
, /* index of the free slot to use */
75 int *changed
/* If mapping is made, this is set to 1. */
82 assert(free_pde_idx
>= 0 && free_pde_idx
< nfreepdes
);
83 pde
= freepdes
[free_pde_idx
];
84 assert(pde
>= 0 && pde
< 1024);
86 if(pr
&& ((pr
== get_cpulocal_var(ptproc
)) || iskernelp(pr
))) {
87 /* Process memory is requested, and
88 * it's a process that is already in current page table, or
89 * the kernel, which is always there.
90 * Therefore linaddr is valid directly, with the requested
97 /* Requested address is in a process that is not currently
98 * accessible directly. Grab the PDE entry of that process'
99 * page table that corresponds to the requested address.
101 assert(pr
->p_seg
.p_cr3_v
);
102 pdeval
= pr
->p_seg
.p_cr3_v
[I386_VM_PDE(linaddr
)];
104 /* Requested address is physical. Make up the PDE entry. */
105 pdeval
= (linaddr
& I386_VM_ADDR_MASK_4MB
) |
106 I386_VM_BIGPAGE
| I386_VM_PRESENT
|
107 I386_VM_WRITE
| I386_VM_USER
;
110 /* Write the pde value that we need into a pde that the kernel
111 * can access, into the currently loaded page table so it becomes
114 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
115 if(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] != pdeval
) {
116 get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] = pdeval
;
120 /* Memory is now available, but only the 4MB window of virtual
121 * address space that we have mapped; calculate how much of
122 * the requested range is visible and return that in *bytes,
123 * if that is less than the requested range.
125 offset
= linaddr
& I386_VM_OFFSET_MASK_4MB
; /* Offset in 4MB window. */
126 *bytes
= MIN(*bytes
, I386_BIG_PAGE_SIZE
- offset
);
128 /* Return the linear address of the start of the new mapping. */
129 return I386_BIG_PAGE_SIZE
*pde
+ offset
;
132 /*===========================================================================*
134 *===========================================================================*/
135 static int lin_lin_copy(struct proc
*srcproc
, vir_bytes srclinaddr
,
136 struct proc
*dstproc
, vir_bytes dstlinaddr
, vir_bytes bytes
)
141 assert(get_cpulocal_var(ptproc
));
142 assert(get_cpulocal_var(proc_ptr
));
143 assert(read_cr3() == get_cpulocal_var(ptproc
)->p_seg
.p_cr3
);
145 procslot
= get_cpulocal_var(ptproc
)->p_nr
;
147 assert(procslot
>= 0 && procslot
< I386_VM_DIR_ENTRIES
);
149 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
150 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
151 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
152 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
153 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_VMINHIBIT
));
154 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_VMINHIBIT
));
157 phys_bytes srcptr
, dstptr
;
158 vir_bytes chunk
= bytes
;
162 unsigned cpu
= cpuid
;
164 if (srcproc
&& GET_BIT(srcproc
->p_stale_tlb
, cpu
)) {
166 UNSET_BIT(srcproc
->p_stale_tlb
, cpu
);
168 if (dstproc
&& GET_BIT(dstproc
->p_stale_tlb
, cpu
)) {
170 UNSET_BIT(dstproc
->p_stale_tlb
, cpu
);
174 /* Set up 4MB ranges. */
175 srcptr
= createpde(srcproc
, srclinaddr
, &chunk
, 0, &changed
);
176 dstptr
= createpde(dstproc
, dstlinaddr
, &chunk
, 1, &changed
);
181 PHYS_COPY_CATCH(srcptr
, dstptr
, chunk
, addr
);
184 /* If addr is nonzero, a page fault was caught. */
186 if(addr
>= srcptr
&& addr
< (srcptr
+ chunk
)) {
189 if(addr
>= dstptr
&& addr
< (dstptr
+ chunk
)) {
193 panic("lin_lin_copy fault out of range");
199 /* Update counter and addresses for next iteration, if any. */
205 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
206 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
207 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
208 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
214 static u32_t
phys_get32(phys_bytes addr
)
219 if((r
=lin_lin_copy(NULL
, addr
,
220 proc_addr(SYSTEM
), (phys_bytes
) &v
, sizeof(v
))) != OK
) {
221 panic("lin_lin_copy for phys_get32 failed: %d", r
);
228 static char *cr0_str(u32_t e
)
232 #define FLAG(v) do { if(e & (v)) { strcat(str, #v " "); e &= ~v; } } while(0)
240 if(e
) { strcat(str
, " (++)"); }
244 static char *cr4_str(u32_t e
)
256 if(e
) { strcat(str
, " (++)"); }
261 /*===========================================================================*
263 *===========================================================================*/
264 phys_bytes
umap_virtual(rp
, seg
, vir_addr
, bytes
)
265 register struct proc
*rp
; /* pointer to proc table entry for process */
266 int seg
; /* T, D, or S segment */
267 vir_bytes vir_addr
; /* virtual address in bytes within the seg */
268 vir_bytes bytes
; /* # of bytes to be copied */
272 if(vm_lookup(rp
, vir_addr
, &phys
, NULL
) != OK
) {
273 printf("SYSTEM:umap_virtual: vm_lookup of %s: seg 0x%x: 0x%lx failed\n", rp
->p_name
, seg
, vir_addr
);
277 panic("vm_lookup returned phys: %d", phys
);
281 printf("SYSTEM:umap_virtual: lookup failed\n");
285 /* Now make sure addresses are contiguous in physical memory
286 * so that the umap makes sense.
288 if(bytes
> 0 && vm_lookup_range(rp
, vir_addr
, NULL
, bytes
) != bytes
) {
289 printf("umap_virtual: %s: %lu at 0x%lx (vir 0x%lx) not contiguous\n",
290 rp
->p_name
, bytes
, vir_addr
, vir_addr
);
294 /* phys must be larger than 0 (or the caller will think the call
295 * failed), and address must not cross a page boundary.
303 /*===========================================================================*
305 *===========================================================================*/
306 int vm_lookup(const struct proc
*proc
, const vir_bytes
virtual,
307 phys_bytes
*physical
, u32_t
*ptent
)
315 assert(!isemptyp(proc
));
318 /* Retrieve page directory entry. */
319 root
= (u32_t
*) proc
->p_seg
.p_cr3
;
320 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
321 pde
= I386_VM_PDE(virtual);
322 assert(pde
>= 0 && pde
< I386_VM_DIR_ENTRIES
);
323 pde_v
= phys_get32((u32_t
) (root
+ pde
));
325 if(!(pde_v
& I386_VM_PRESENT
)) {
329 /* We don't expect to ever see this. */
330 if(pde_v
& I386_VM_BIGPAGE
) {
331 *physical
= pde_v
& I386_VM_ADDR_MASK_4MB
;
332 if(ptent
) *ptent
= pde_v
;
333 *physical
+= virtual & I386_VM_OFFSET_MASK_4MB
;
335 /* Retrieve page table entry. */
336 pt
= (u32_t
*) I386_VM_PFA(pde_v
);
337 assert(!((u32_t
) pt
% I386_PAGE_SIZE
));
338 pte
= I386_VM_PTE(virtual);
339 assert(pte
>= 0 && pte
< I386_VM_PT_ENTRIES
);
340 pte_v
= phys_get32((u32_t
) (pt
+ pte
));
341 if(!(pte_v
& I386_VM_PRESENT
)) {
345 if(ptent
) *ptent
= pte_v
;
347 /* Actual address now known; retrieve it and add page offset. */
348 *physical
= I386_VM_PFA(pte_v
);
349 *physical
+= virtual % I386_PAGE_SIZE
;
355 /*===========================================================================*
357 *===========================================================================*/
358 size_t vm_lookup_range(const struct proc
*proc
, vir_bytes vir_addr
,
359 phys_bytes
*phys_addr
, size_t bytes
)
361 /* Look up the physical address corresponding to linear virtual address
362 * 'vir_addr' for process 'proc'. Return the size of the range covered
363 * by contiguous physical memory starting from that address; this may
364 * be anywhere between 0 and 'bytes' inclusive. If the return value is
365 * nonzero, and 'phys_addr' is non-NULL, 'phys_addr' will be set to the
366 * base physical address of the range. 'vir_addr' and 'bytes' need not
367 * be page-aligned, but the caller must have verified that the given
368 * linear range is valid for the given process at all.
370 phys_bytes phys
, next_phys
;
377 /* Look up the first page. */
378 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
381 if (phys_addr
!= NULL
)
384 len
= I386_PAGE_SIZE
- (vir_addr
% I386_PAGE_SIZE
);
386 next_phys
= phys
+ len
;
388 /* Look up any next pages and test physical contiguity. */
389 while (len
< bytes
) {
390 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
393 if (next_phys
!= phys
)
396 len
+= I386_PAGE_SIZE
;
397 vir_addr
+= I386_PAGE_SIZE
;
398 next_phys
+= I386_PAGE_SIZE
;
401 /* We might now have overshot the requested length somewhat. */
402 return MIN(bytes
, len
);
405 /*===========================================================================*
407 *===========================================================================*/
408 static void vm_suspend(struct proc
*caller
, const struct proc
*target
,
409 const vir_bytes linaddr
, const vir_bytes len
, const int type
)
411 /* This range is not OK for this process. Set parameters
412 * of the request and notify VM about the pending request.
414 assert(!RTS_ISSET(caller
, RTS_VMREQUEST
));
415 assert(!RTS_ISSET(target
, RTS_VMREQUEST
));
417 RTS_SET(caller
, RTS_VMREQUEST
);
419 caller
->p_vmrequest
.req_type
= VMPTYPE_CHECK
;
420 caller
->p_vmrequest
.target
= target
->p_endpoint
;
421 caller
->p_vmrequest
.params
.check
.start
= linaddr
;
422 caller
->p_vmrequest
.params
.check
.length
= len
;
423 caller
->p_vmrequest
.params
.check
.writeflag
= 1;
424 caller
->p_vmrequest
.type
= type
;
426 /* Connect caller on vmrequest wait queue. */
427 if(!(caller
->p_vmrequest
.nextrequestor
= vmrequest
))
428 if(OK
!= send_sig(VM_PROC_NR
, SIGKMEM
))
429 panic("send_sig failed");
433 /*===========================================================================*
435 *===========================================================================*/
436 int vm_check_range(struct proc
*caller
, struct proc
*target
,
437 vir_bytes vir_addr
, size_t bytes
)
439 /* Public interface to vm_suspend(), for use by kernel calls. On behalf
440 * of 'caller', call into VM to check linear virtual address range of
441 * process 'target', starting at 'vir_addr', for 'bytes' bytes. This
442 * function assumes that it will called twice if VM returned an error
443 * the first time (since nothing has changed in that case), and will
444 * then return the error code resulting from the first call. Upon the
445 * first call, a non-success error code is returned as well.
449 if ((caller
->p_misc_flags
& MF_KCALL_RESUME
) &&
450 (r
= caller
->p_vmrequest
.vmresult
) != OK
)
453 vm_suspend(caller
, target
, vir_addr
, bytes
, VMSTYPE_KERNELCALL
);
458 /*===========================================================================*
460 *===========================================================================*/
461 void delivermsg(struct proc
*rp
)
465 assert(rp
->p_misc_flags
& MF_DELIVERMSG
);
466 assert(rp
->p_delivermsg
.m_source
!= NONE
);
468 if (copy_msg_to_user(&rp
->p_delivermsg
,
469 (message
*) rp
->p_delivermsg_vir
)) {
470 printf("WARNING wrong user pointer 0x%08lx from "
472 rp
->p_delivermsg_vir
,
478 /* Indicate message has been delivered; address is 'used'. */
479 rp
->p_delivermsg
.m_source
= NONE
;
480 rp
->p_misc_flags
&= ~MF_DELIVERMSG
;
482 if(!(rp
->p_misc_flags
& MF_CONTEXT_SET
)) {
483 rp
->p_reg
.retreg
= r
;
488 static char *flagstr(u32_t e
, const int dir
)
492 FLAG(I386_VM_PRESENT
);
497 FLAG(I386_VM_GLOBAL
);
499 FLAG(I386_VM_BIGPAGE
); /* Page directory entry only */
501 FLAG(I386_VM_DIRTY
); /* Page table entry only */
505 static void vm_pt_print(u32_t
*pagetable
, const u32_t v
)
510 assert(!((u32_t
) pagetable
% I386_PAGE_SIZE
));
512 for(pte
= 0; pte
< I386_VM_PT_ENTRIES
; pte
++) {
514 pte_v
= phys_get32((u32_t
) (pagetable
+ pte
));
515 if(!(pte_v
& I386_VM_PRESENT
))
517 pfa
= I386_VM_PFA(pte_v
);
518 printf("%4d:%08lx:%08lx %2s ",
519 pte
, v
+ I386_PAGE_SIZE
*pte
, pfa
,
520 (pte_v
& I386_VM_WRITE
) ? "rw":"RO");
522 if(col
== 3) { printf("\n"); col
= 0; }
524 if(col
> 0) printf("\n");
529 static void vm_print(u32_t
*root
)
533 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
535 printf("page table 0x%lx:\n", root
);
537 for(pde
= 0; pde
< I386_VM_DIR_ENTRIES
; pde
++) {
540 pde_v
= phys_get32((u32_t
) (root
+ pde
));
541 if(!(pde_v
& I386_VM_PRESENT
))
543 if(pde_v
& I386_VM_BIGPAGE
) {
544 printf("%4d: 0x%lx, flags %s\n",
545 pde
, I386_VM_PFA(pde_v
), flagstr(pde_v
, 1));
547 pte_a
= (u32_t
*) I386_VM_PFA(pde_v
);
548 printf("%4d: pt %08lx %s\n",
549 pde
, pte_a
, flagstr(pde_v
, 1));
550 vm_pt_print(pte_a
, pde
* I386_VM_PT_ENTRIES
* I386_PAGE_SIZE
);
560 int vm_memset(endpoint_t who
, phys_bytes ph
, const u8_t c
, phys_bytes bytes
)
563 struct proc
*whoptr
= NULL
;
565 /* NONE for physical, otherwise virtual */
568 if(!isokendpt(who
, &n
)) return ESRCH
;
569 whoptr
= proc_addr(n
);
572 p
= c
| (c
<< 8) | (c
<< 16) | (c
<< 24);
574 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
576 assert(!catch_pagefaults
);
579 /* With VM, we have to map in the memory (virtual or physical).
580 * We can do this 4MB at a time.
584 phys_bytes chunk
= bytes
, ptr
, pfa
;
585 ptr
= createpde(whoptr
, ph
, &chunk
, 0, &changed
);
589 /* We can memset as many bytes as we have remaining,
590 * or as many as remain in the 4MB chunk we mapped in.
592 if((pfa
=phys_memset(ptr
, p
, chunk
))) {
593 printf("kernel memset pagefault\n");
600 assert(catch_pagefaults
);
603 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
608 /*===========================================================================*
610 *===========================================================================*/
611 int virtual_copy_f(caller
, src_addr
, dst_addr
, bytes
, vmcheck
)
612 struct proc
* caller
;
613 struct vir_addr
*src_addr
; /* source virtual address */
614 struct vir_addr
*dst_addr
; /* destination virtual address */
615 vir_bytes bytes
; /* # of bytes to copy */
616 int vmcheck
; /* if nonzero, can return VMSUSPEND */
618 /* Copy bytes from virtual address src_addr to virtual address dst_addr. */
619 struct vir_addr
*vir_addr
[2]; /* virtual source and destination address */
621 struct proc
*procs
[2];
623 assert((vmcheck
&& caller
) || (!vmcheck
&& !caller
));
625 /* Check copy count. */
626 if (bytes
<= 0) return(EDOM
);
628 /* Do some more checks and map virtual addresses to physical addresses. */
629 vir_addr
[_SRC_
] = src_addr
;
630 vir_addr
[_DST_
] = dst_addr
;
632 for (i
=_SRC_
; i
<=_DST_
; i
++) {
633 endpoint_t proc_e
= vir_addr
[i
]->proc_nr_e
;
640 if(!isokendpt(proc_e
, &proc_nr
)) {
641 printf("virtual_copy: no reasonable endpoint\n");
644 p
= proc_addr(proc_nr
);
650 if(caller
&& (caller
->p_misc_flags
& MF_KCALL_RESUME
)) {
651 assert(caller
->p_vmrequest
.vmresult
!= VMSUSPEND
);
652 if(caller
->p_vmrequest
.vmresult
!= OK
) {
653 return caller
->p_vmrequest
.vmresult
;
657 if((r
=lin_lin_copy(procs
[_SRC_
], vir_addr
[_SRC_
]->offset
,
658 procs
[_DST_
], vir_addr
[_DST_
]->offset
, bytes
)) != OK
) {
659 struct proc
*target
= NULL
;
661 if(r
!= EFAULT_SRC
&& r
!= EFAULT_DST
)
662 panic("lin_lin_copy failed: %d", r
);
663 if(!vmcheck
|| !caller
) {
667 if(r
== EFAULT_SRC
) {
668 lin
= vir_addr
[_SRC_
]->offset
;
669 target
= procs
[_SRC_
];
670 } else if(r
== EFAULT_DST
) {
671 lin
= vir_addr
[_DST_
]->offset
;
672 target
= procs
[_DST_
];
674 panic("r strange: %d", r
);
680 vm_suspend(caller
, target
, lin
, bytes
, VMSTYPE_KERNELCALL
);
687 /*===========================================================================*
689 *===========================================================================*/
690 int data_copy(const endpoint_t from_proc
, const vir_bytes from_addr
,
691 const endpoint_t to_proc
, const vir_bytes to_addr
,
694 struct vir_addr src
, dst
;
696 src
.offset
= from_addr
;
697 dst
.offset
= to_addr
;
698 src
.proc_nr_e
= from_proc
;
699 dst
.proc_nr_e
= to_proc
;
700 assert(src
.proc_nr_e
!= NONE
);
701 assert(dst
.proc_nr_e
!= NONE
);
703 return virtual_copy(&src
, &dst
, bytes
);
706 /*===========================================================================*
707 * data_copy_vmcheck *
708 *===========================================================================*/
709 int data_copy_vmcheck(struct proc
* caller
,
710 const endpoint_t from_proc
, const vir_bytes from_addr
,
711 const endpoint_t to_proc
, const vir_bytes to_addr
,
714 struct vir_addr src
, dst
;
716 src
.offset
= from_addr
;
717 dst
.offset
= to_addr
;
718 src
.proc_nr_e
= from_proc
;
719 dst
.proc_nr_e
= to_proc
;
720 assert(src
.proc_nr_e
!= NONE
);
721 assert(dst
.proc_nr_e
!= NONE
);
723 return virtual_copy_vmcheck(caller
, &src
, &dst
, bytes
);
726 void memory_init(void)
728 assert(nfreepdes
== 0);
730 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
731 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
733 assert(kinfo
.freepde_start
< I386_VM_DIR_ENTRIES
);
734 assert(nfreepdes
== 2);
735 assert(nfreepdes
<= MAXFREEPDES
);
738 /*===========================================================================*
740 *===========================================================================*/
741 void arch_proc_init(struct proc
*pr
, const u32_t ip
, const u32_t sp
, char *name
)
744 strlcpy(pr
->p_name
, name
, sizeof(pr
->p_name
));
746 /* set custom state we know */
751 static int oxpcie_mapping_index
= -1,
752 lapic_mapping_index
= -1,
753 ioapic_first_index
= -1,
754 ioapic_last_index
= -1,
755 video_mem_mapping_index
= -1,
756 usermapped_glo_index
= -1,
757 usermapped_index
= -1, first_um_idx
= -1;
759 extern char *video_mem
;
761 extern char usermapped_start
, usermapped_end
, usermapped_nonglo_start
;
763 int arch_phys_map(const int index
,
768 static int first
= 1;
770 static char *ser_var
= NULL
;
771 u32_t glo_len
= (u32_t
) &usermapped_nonglo_start
-
772 (u32_t
) &usermapped_start
;
775 video_mem_mapping_index
= freeidx
++;
777 usermapped_glo_index
= freeidx
++;
780 usermapped_index
= freeidx
++;
781 first_um_idx
= usermapped_index
;
782 if(usermapped_glo_index
!= -1)
783 first_um_idx
= usermapped_glo_index
;
787 lapic_mapping_index
= freeidx
++;
788 if (ioapic_enabled
) {
789 ioapic_first_index
= freeidx
;
790 assert(nioapics
> 0);
792 ioapic_last_index
= freeidx
-1;
797 if((ser_var
= env_get("oxpcie"))) {
798 if(ser_var
[0] != '0' || ser_var
[1] != 'x') {
799 printf("oxpcie address in hex please\n");
801 printf("oxpcie address is %s\n", ser_var
);
802 oxpcie_mapping_index
= freeidx
++;
810 if(index
== usermapped_glo_index
) {
811 *addr
= vir2phys(&usermapped_start
);
813 *flags
= VMMF_USER
| VMMF_GLO
;
816 else if(index
== usermapped_index
) {
817 *addr
= vir2phys(&usermapped_nonglo_start
);
818 *len
= (u32_t
) &usermapped_end
-
819 (u32_t
) &usermapped_nonglo_start
;
823 else if (index
== video_mem_mapping_index
) {
824 /* map video memory in so we can print panic messages */
825 *addr
= MULTIBOOT_VIDEO_BUFFER
;
826 *len
= I386_PAGE_SIZE
;
831 else if (index
== lapic_mapping_index
) {
832 /* map the local APIC if enabled */
836 *len
= 4 << 10 /* 4kB */;
837 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
840 else if (ioapic_enabled
&& index
>= ioapic_first_index
&& index
<= ioapic_last_index
) {
841 int ioapic_idx
= index
- ioapic_first_index
;
842 *addr
= io_apic
[ioapic_idx
].paddr
;
844 *len
= 4 << 10 /* 4kB */;
845 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
846 printf("ioapic map: addr 0x%lx\n", *addr
);
852 if(index
== oxpcie_mapping_index
) {
853 *addr
= strtoul(ser_var
+2, NULL
, 16);
855 *flags
= VMMF_UNCACHED
| VMMF_WRITE
;
863 int arch_phys_map_reply(const int index
, const vir_bytes addr
)
866 /* if local APIC is enabled */
867 if (index
== lapic_mapping_index
&& lapic_addr
) {
868 lapic_addr_vaddr
= addr
;
871 else if (ioapic_enabled
&& index
>= ioapic_first_index
&&
872 index
<= ioapic_last_index
) {
873 int i
= index
- ioapic_first_index
;
874 io_apic
[i
].vaddr
= addr
;
880 if (index
== oxpcie_mapping_index
) {
881 oxpcie_set_vaddr((unsigned char *) addr
);
885 if(index
== first_um_idx
) {
886 u32_t usermapped_offset
;
887 assert(addr
> (u32_t
) &usermapped_start
);
888 usermapped_offset
= addr
- (u32_t
) &usermapped_start
;
889 memset(&minix_kerninfo
, 0, sizeof(minix_kerninfo
));
890 #define FIXEDPTR(ptr) (void *) ((u32_t)ptr + usermapped_offset)
891 #define FIXPTR(ptr) ptr = FIXEDPTR(ptr)
892 #define ASSIGN(minixstruct) minix_kerninfo.minixstruct = FIXEDPTR(&minixstruct)
898 /* adjust the pointers of the functions and the struct
899 * itself to the user-accessible mapping
901 minix_kerninfo
.kerninfo_magic
= KERNINFO_MAGIC
;
902 minix_kerninfo
.minix_feature_flags
= minix_feature_flags
;
903 minix_kerninfo_user
= (vir_bytes
) FIXEDPTR(&minix_kerninfo
);
908 if(index
== usermapped_index
) return OK
;
910 if (index
== video_mem_mapping_index
) {
911 video_mem_vaddr
= addr
;
918 int arch_enable_paging(struct proc
* caller
)
920 assert(caller
->p_seg
.p_cr3
);
922 /* load caller's page table */
923 switch_address_space(caller
);
925 video_mem
= (char *) video_mem_vaddr
;
928 /* start using the virtual addresses */
930 /* if local APIC is enabled */
932 lapic_addr
= lapic_addr_vaddr
;
933 lapic_eoi_addr
= LAPIC_EOI
;
935 /* if IO apics are enabled */
936 if (ioapic_enabled
) {
939 for (i
= 0; i
< nioapics
; i
++) {
940 io_apic
[i
].addr
= io_apic
[i
].vaddr
;
946 wait_for_APs_to_finish_booting();
952 * We make sure that we don't enable the watchdog until paging is turned
953 * on as we might get an NMI while switching and we might still use wrong
954 * lapic address. Bad things would happen. It is unfortunate but such is
957 if (watchdog_enabled
)
958 i386_watchdog_start();
964 void release_address_space(struct proc
*pr
)
966 pr
->p_seg
.p_cr3_v
= NULL
;
969 /* computes a checksum of a buffer of a given length. The byte sum must be zero */
970 int platform_tbl_checksum_ok(void *ptr
, unsigned int length
)
974 for (i
= 0; i
< length
; i
++)
975 total
+= ((unsigned char *)ptr
)[i
];
979 int platform_tbl_ptr(phys_bytes start
,
984 phys_bytes
* phys_addr
,
985 int ((* cmp_f
)(void *)))
989 for (addr
= start
; addr
< end
; addr
+= increment
) {
990 phys_copy (addr
, (phys_bytes
) buff
, size
);