2 #include "kernel/kernel.h"
3 #include "kernel/proc.h"
6 #include <machine/vm.h>
8 #include <minix/type.h>
9 #include <minix/syslib.h>
10 #include <minix/cpufeature.h>
16 #include <machine/vm.h>
19 #include "arch_proto.h"
20 #include "kernel/proto.h"
21 #include "kernel/debug.h"
26 #include "kernel/watchdog.h"
30 phys_bytes video_mem_vaddr
= 0;
32 #define HASPT(procptr) ((procptr)->p_seg.p_cr3 != 0)
33 static int nfreepdes
= 0;
35 static int freepdes
[MAXFREEPDES
];
37 static u32_t
phys_get32(phys_bytes v
);
39 void mem_clear_mapcache(void)
42 for(i
= 0; i
< nfreepdes
; i
++) {
43 struct proc
*ptproc
= get_cpulocal_var(ptproc
);
44 int pde
= freepdes
[i
];
47 ptv
= ptproc
->p_seg
.p_cr3_v
;
53 /* This function sets up a mapping from within the kernel's address
54 * space to any other area of memory, either straight physical
55 * memory (pr == NULL) or a process view of memory, in 4MB windows.
56 * I.e., it maps in 4MB chunks of virtual (or physical) address space
57 * to 4MB chunks of kernel virtual address space.
59 * It recognizes pr already being in memory as a special case (no
62 * The target (i.e. in-kernel) mapping area is one of the freepdes[]
63 * VM has earlier already told the kernel about that is available. It is
64 * identified as the 'pde' parameter. This value can be chosen freely
65 * by the caller, as long as it is in range (i.e. 0 or higher and corresonds
66 * to a known freepde slot). It is up to the caller to keep track of which
67 * freepde's are in use, and to determine which ones are free to use.
69 * The logical number supplied by the caller is translated into an actual
70 * pde number to be used, and a pointer to it (linear address) is returned
71 * for actual use by phys_copy or memset.
73 static phys_bytes
createpde(
74 const struct proc
*pr
, /* Requested process, NULL for physical. */
75 const phys_bytes linaddr
,/* Address after segment translation. */
76 phys_bytes
*bytes
, /* Size of chunk, function may truncate it. */
77 int free_pde_idx
, /* index of the free slot to use */
78 int *changed
/* If mapping is made, this is set to 1. */
85 assert(free_pde_idx
>= 0 && free_pde_idx
< nfreepdes
);
86 pde
= freepdes
[free_pde_idx
];
87 assert(pde
>= 0 && pde
< 1024);
89 if(pr
&& ((pr
== get_cpulocal_var(ptproc
)) || iskernelp(pr
))) {
90 /* Process memory is requested, and
91 * it's a process that is already in current page table, or
92 * the kernel, which is always there.
93 * Therefore linaddr is valid directly, with the requested
100 /* Requested address is in a process that is not currently
101 * accessible directly. Grab the PDE entry of that process'
102 * page table that corresponds to the requested address.
104 assert(pr
->p_seg
.p_cr3_v
);
105 pdeval
= pr
->p_seg
.p_cr3_v
[I386_VM_PDE(linaddr
)];
107 /* Requested address is physical. Make up the PDE entry. */
108 pdeval
= (linaddr
& I386_VM_ADDR_MASK_4MB
) |
109 I386_VM_BIGPAGE
| I386_VM_PRESENT
|
110 I386_VM_WRITE
| I386_VM_USER
;
113 /* Write the pde value that we need into a pde that the kernel
114 * can access, into the currently loaded page table so it becomes
117 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
118 if(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] != pdeval
) {
119 get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
[pde
] = pdeval
;
123 /* Memory is now available, but only the 4MB window of virtual
124 * address space that we have mapped; calculate how much of
125 * the requested range is visible and return that in *bytes,
126 * if that is less than the requested range.
128 offset
= linaddr
& I386_VM_OFFSET_MASK_4MB
; /* Offset in 4MB window. */
129 *bytes
= MIN(*bytes
, I386_BIG_PAGE_SIZE
- offset
);
131 /* Return the linear address of the start of the new mapping. */
132 return I386_BIG_PAGE_SIZE
*pde
+ offset
;
135 /*===========================================================================*
137 *===========================================================================*/
138 static int lin_lin_copy(struct proc
*srcproc
, vir_bytes srclinaddr
,
139 struct proc
*dstproc
, vir_bytes dstlinaddr
, vir_bytes bytes
)
144 assert(get_cpulocal_var(ptproc
));
145 assert(get_cpulocal_var(proc_ptr
));
146 assert(read_cr3() == get_cpulocal_var(ptproc
)->p_seg
.p_cr3
);
148 procslot
= get_cpulocal_var(ptproc
)->p_nr
;
150 assert(procslot
>= 0 && procslot
< I386_VM_DIR_ENTRIES
);
152 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
153 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
154 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
155 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
156 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_VMINHIBIT
));
157 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_VMINHIBIT
));
160 phys_bytes srcptr
, dstptr
;
161 vir_bytes chunk
= bytes
;
165 unsigned cpu
= cpuid
;
167 if (srcproc
&& GET_BIT(srcproc
->p_stale_tlb
, cpu
)) {
169 UNSET_BIT(srcproc
->p_stale_tlb
, cpu
);
171 if (dstproc
&& GET_BIT(dstproc
->p_stale_tlb
, cpu
)) {
173 UNSET_BIT(dstproc
->p_stale_tlb
, cpu
);
177 /* Set up 4MB ranges. */
178 srcptr
= createpde(srcproc
, srclinaddr
, &chunk
, 0, &changed
);
179 dstptr
= createpde(dstproc
, dstlinaddr
, &chunk
, 1, &changed
);
184 PHYS_COPY_CATCH(srcptr
, dstptr
, chunk
, addr
);
187 /* If addr is nonzero, a page fault was caught. */
189 if(addr
>= srcptr
&& addr
< (srcptr
+ chunk
)) {
192 if(addr
>= dstptr
&& addr
< (dstptr
+ chunk
)) {
196 panic("lin_lin_copy fault out of range");
202 /* Update counter and addresses for next iteration, if any. */
208 if(srcproc
) assert(!RTS_ISSET(srcproc
, RTS_SLOT_FREE
));
209 if(dstproc
) assert(!RTS_ISSET(dstproc
, RTS_SLOT_FREE
));
210 assert(!RTS_ISSET(get_cpulocal_var(ptproc
), RTS_SLOT_FREE
));
211 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
217 static u32_t
phys_get32(phys_bytes addr
)
222 if((r
=lin_lin_copy(NULL
, addr
,
223 proc_addr(SYSTEM
), (phys_bytes
) &v
, sizeof(v
))) != OK
) {
224 panic("lin_lin_copy for phys_get32 failed: %d", r
);
231 static char *cr0_str(u32_t e
)
235 #define FLAG(v) do { if(e & (v)) { strcat(str, #v " "); e &= ~v; } } while(0)
243 if(e
) { strcat(str
, " (++)"); }
247 static char *cr4_str(u32_t e
)
259 if(e
) { strcat(str
, " (++)"); }
264 /*===========================================================================*
266 *===========================================================================*/
267 phys_bytes
umap_virtual(rp
, seg
, vir_addr
, bytes
)
268 register struct proc
*rp
; /* pointer to proc table entry for process */
269 int seg
; /* T, D, or S segment */
270 vir_bytes vir_addr
; /* virtual address in bytes within the seg */
271 vir_bytes bytes
; /* # of bytes to be copied */
275 if(vm_lookup(rp
, vir_addr
, &phys
, NULL
) != OK
) {
276 printf("SYSTEM:umap_virtual: vm_lookup of %s: seg 0x%x: 0x%lx failed\n", rp
->p_name
, seg
, vir_addr
);
280 panic("vm_lookup returned phys: %d", phys
);
284 printf("SYSTEM:umap_virtual: lookup failed\n");
288 /* Now make sure addresses are contiguous in physical memory
289 * so that the umap makes sense.
291 if(bytes
> 0 && vm_lookup_range(rp
, vir_addr
, NULL
, bytes
) != bytes
) {
292 printf("umap_virtual: %s: %lu at 0x%lx (vir 0x%lx) not contiguous\n",
293 rp
->p_name
, bytes
, vir_addr
, vir_addr
);
297 /* phys must be larger than 0 (or the caller will think the call
298 * failed), and address must not cross a page boundary.
306 /*===========================================================================*
308 *===========================================================================*/
309 int vm_lookup(const struct proc
*proc
, const vir_bytes
virtual,
310 phys_bytes
*physical
, u32_t
*ptent
)
318 assert(!isemptyp(proc
));
321 /* Retrieve page directory entry. */
322 root
= (u32_t
*) proc
->p_seg
.p_cr3
;
323 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
324 pde
= I386_VM_PDE(virtual);
325 assert(pde
>= 0 && pde
< I386_VM_DIR_ENTRIES
);
326 pde_v
= phys_get32((u32_t
) (root
+ pde
));
328 if(!(pde_v
& I386_VM_PRESENT
)) {
332 /* We don't expect to ever see this. */
333 if(pde_v
& I386_VM_BIGPAGE
) {
334 *physical
= pde_v
& I386_VM_ADDR_MASK_4MB
;
335 if(ptent
) *ptent
= pde_v
;
336 *physical
+= virtual & I386_VM_OFFSET_MASK_4MB
;
338 /* Retrieve page table entry. */
339 pt
= (u32_t
*) I386_VM_PFA(pde_v
);
340 assert(!((u32_t
) pt
% I386_PAGE_SIZE
));
341 pte
= I386_VM_PTE(virtual);
342 assert(pte
>= 0 && pte
< I386_VM_PT_ENTRIES
);
343 pte_v
= phys_get32((u32_t
) (pt
+ pte
));
344 if(!(pte_v
& I386_VM_PRESENT
)) {
348 if(ptent
) *ptent
= pte_v
;
350 /* Actual address now known; retrieve it and add page offset. */
351 *physical
= I386_VM_PFA(pte_v
);
352 *physical
+= virtual % I386_PAGE_SIZE
;
358 /*===========================================================================*
360 *===========================================================================*/
361 size_t vm_lookup_range(const struct proc
*proc
, vir_bytes vir_addr
,
362 phys_bytes
*phys_addr
, size_t bytes
)
364 /* Look up the physical address corresponding to linear virtual address
365 * 'vir_addr' for process 'proc'. Return the size of the range covered
366 * by contiguous physical memory starting from that address; this may
367 * be anywhere between 0 and 'bytes' inclusive. If the return value is
368 * nonzero, and 'phys_addr' is non-NULL, 'phys_addr' will be set to the
369 * base physical address of the range. 'vir_addr' and 'bytes' need not
370 * be page-aligned, but the caller must have verified that the given
371 * linear range is valid for the given process at all.
373 phys_bytes phys
, next_phys
;
380 /* Look up the first page. */
381 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
384 if (phys_addr
!= NULL
)
387 len
= I386_PAGE_SIZE
- (vir_addr
% I386_PAGE_SIZE
);
389 next_phys
= phys
+ len
;
391 /* Look up any next pages and test physical contiguity. */
392 while (len
< bytes
) {
393 if (vm_lookup(proc
, vir_addr
, &phys
, NULL
) != OK
)
396 if (next_phys
!= phys
)
399 len
+= I386_PAGE_SIZE
;
400 vir_addr
+= I386_PAGE_SIZE
;
401 next_phys
+= I386_PAGE_SIZE
;
404 /* We might now have overshot the requested length somewhat. */
405 return MIN(bytes
, len
);
408 /*===========================================================================*
410 *===========================================================================*/
411 static void vm_suspend(struct proc
*caller
, const struct proc
*target
,
412 const vir_bytes linaddr
, const vir_bytes len
, const int type
)
414 /* This range is not OK for this process. Set parameters
415 * of the request and notify VM about the pending request.
417 assert(!RTS_ISSET(caller
, RTS_VMREQUEST
));
418 assert(!RTS_ISSET(target
, RTS_VMREQUEST
));
420 RTS_SET(caller
, RTS_VMREQUEST
);
422 caller
->p_vmrequest
.req_type
= VMPTYPE_CHECK
;
423 caller
->p_vmrequest
.target
= target
->p_endpoint
;
424 caller
->p_vmrequest
.params
.check
.start
= linaddr
;
425 caller
->p_vmrequest
.params
.check
.length
= len
;
426 caller
->p_vmrequest
.params
.check
.writeflag
= 1;
427 caller
->p_vmrequest
.type
= type
;
429 /* Connect caller on vmrequest wait queue. */
430 if(!(caller
->p_vmrequest
.nextrequestor
= vmrequest
))
431 if(OK
!= send_sig(VM_PROC_NR
, SIGKMEM
))
432 panic("send_sig failed");
436 /*===========================================================================*
438 *===========================================================================*/
439 int vm_check_range(struct proc
*caller
, struct proc
*target
,
440 vir_bytes vir_addr
, size_t bytes
)
442 /* Public interface to vm_suspend(), for use by kernel calls. On behalf
443 * of 'caller', call into VM to check linear virtual address range of
444 * process 'target', starting at 'vir_addr', for 'bytes' bytes. This
445 * function assumes that it will called twice if VM returned an error
446 * the first time (since nothing has changed in that case), and will
447 * then return the error code resulting from the first call. Upon the
448 * first call, a non-success error code is returned as well.
452 if ((caller
->p_misc_flags
& MF_KCALL_RESUME
) &&
453 (r
= caller
->p_vmrequest
.vmresult
) != OK
)
456 vm_suspend(caller
, target
, vir_addr
, bytes
, VMSTYPE_KERNELCALL
);
461 /*===========================================================================*
463 *===========================================================================*/
464 void delivermsg(struct proc
*rp
)
468 assert(rp
->p_misc_flags
& MF_DELIVERMSG
);
469 assert(rp
->p_delivermsg
.m_source
!= NONE
);
471 if (copy_msg_to_user(&rp
->p_delivermsg
,
472 (message
*) rp
->p_delivermsg_vir
)) {
473 printf("WARNING wrong user pointer 0x%08lx from "
475 rp
->p_delivermsg_vir
,
481 /* Indicate message has been delivered; address is 'used'. */
482 rp
->p_delivermsg
.m_source
= NONE
;
483 rp
->p_misc_flags
&= ~MF_DELIVERMSG
;
485 if(!(rp
->p_misc_flags
& MF_CONTEXT_SET
)) {
486 rp
->p_reg
.retreg
= r
;
491 static char *flagstr(u32_t e
, const int dir
)
495 FLAG(I386_VM_PRESENT
);
500 FLAG(I386_VM_GLOBAL
);
502 FLAG(I386_VM_BIGPAGE
); /* Page directory entry only */
504 FLAG(I386_VM_DIRTY
); /* Page table entry only */
508 static void vm_pt_print(u32_t
*pagetable
, const u32_t v
)
513 assert(!((u32_t
) pagetable
% I386_PAGE_SIZE
));
515 for(pte
= 0; pte
< I386_VM_PT_ENTRIES
; pte
++) {
517 pte_v
= phys_get32((u32_t
) (pagetable
+ pte
));
518 if(!(pte_v
& I386_VM_PRESENT
))
520 pfa
= I386_VM_PFA(pte_v
);
521 printf("%4d:%08lx:%08lx %2s ",
522 pte
, v
+ I386_PAGE_SIZE
*pte
, pfa
,
523 (pte_v
& I386_VM_WRITE
) ? "rw":"RO");
525 if(col
== 3) { printf("\n"); col
= 0; }
527 if(col
> 0) printf("\n");
532 static void vm_print(u32_t
*root
)
536 assert(!((u32_t
) root
% I386_PAGE_SIZE
));
538 printf("page table 0x%lx:\n", root
);
540 for(pde
= 0; pde
< I386_VM_DIR_ENTRIES
; pde
++) {
543 pde_v
= phys_get32((u32_t
) (root
+ pde
));
544 if(!(pde_v
& I386_VM_PRESENT
))
546 if(pde_v
& I386_VM_BIGPAGE
) {
547 printf("%4d: 0x%lx, flags %s\n",
548 pde
, I386_VM_PFA(pde_v
), flagstr(pde_v
, 1));
550 pte_a
= (u32_t
*) I386_VM_PFA(pde_v
);
551 printf("%4d: pt %08lx %s\n",
552 pde
, pte_a
, flagstr(pde_v
, 1));
553 vm_pt_print(pte_a
, pde
* I386_VM_PT_ENTRIES
* I386_PAGE_SIZE
);
563 int vm_memset(endpoint_t who
, phys_bytes ph
, const u8_t c
, phys_bytes bytes
)
567 struct proc
*whoptr
= NULL
;
569 /* NONE for physical, otherwise virtual */
572 if(!isokendpt(who
, &n
)) return ESRCH
;
573 whoptr
= proc_addr(n
);
576 p
= c
| (c
<< 8) | (c
<< 16) | (c
<< 24);
578 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
580 assert(!catch_pagefaults
);
583 /* With VM, we have to map in the memory (virtual or physical).
584 * We can do this 4MB at a time.
588 phys_bytes chunk
= bytes
, ptr
, pfa
;
589 ptr
= createpde(whoptr
, ph
, &chunk
, 0, &changed
);
593 /* We can memset as many bytes as we have remaining,
594 * or as many as remain in the 4MB chunk we mapped in.
596 if((pfa
=phys_memset(ptr
, p
, chunk
))) {
597 printf("kernel memset pagefault\n");
605 assert(catch_pagefaults
);
608 assert(get_cpulocal_var(ptproc
)->p_seg
.p_cr3_v
);
613 /*===========================================================================*
615 *===========================================================================*/
616 int virtual_copy_f(caller
, src_addr
, dst_addr
, bytes
, vmcheck
)
617 struct proc
* caller
;
618 struct vir_addr
*src_addr
; /* source virtual address */
619 struct vir_addr
*dst_addr
; /* destination virtual address */
620 vir_bytes bytes
; /* # of bytes to copy */
621 int vmcheck
; /* if nonzero, can return VMSUSPEND */
623 /* Copy bytes from virtual address src_addr to virtual address dst_addr. */
624 struct vir_addr
*vir_addr
[2]; /* virtual source and destination address */
626 struct proc
*procs
[2];
628 assert((vmcheck
&& caller
) || (!vmcheck
&& !caller
));
630 /* Check copy count. */
631 if (bytes
<= 0) return(EDOM
);
633 /* Do some more checks and map virtual addresses to physical addresses. */
634 vir_addr
[_SRC_
] = src_addr
;
635 vir_addr
[_DST_
] = dst_addr
;
637 for (i
=_SRC_
; i
<=_DST_
; i
++) {
638 endpoint_t proc_e
= vir_addr
[i
]->proc_nr_e
;
645 if(!isokendpt(proc_e
, &proc_nr
)) {
646 printf("virtual_copy: no reasonable endpoint\n");
649 p
= proc_addr(proc_nr
);
655 if(caller
&& (caller
->p_misc_flags
& MF_KCALL_RESUME
)) {
656 assert(caller
->p_vmrequest
.vmresult
!= VMSUSPEND
);
657 if(caller
->p_vmrequest
.vmresult
!= OK
) {
658 return caller
->p_vmrequest
.vmresult
;
662 if((r
=lin_lin_copy(procs
[_SRC_
], vir_addr
[_SRC_
]->offset
,
663 procs
[_DST_
], vir_addr
[_DST_
]->offset
, bytes
)) != OK
) {
664 struct proc
*target
= NULL
;
666 if(r
!= EFAULT_SRC
&& r
!= EFAULT_DST
)
667 panic("lin_lin_copy failed: %d", r
);
668 if(!vmcheck
|| !caller
) {
672 if(r
== EFAULT_SRC
) {
673 lin
= vir_addr
[_SRC_
]->offset
;
674 target
= procs
[_SRC_
];
675 } else if(r
== EFAULT_DST
) {
676 lin
= vir_addr
[_DST_
]->offset
;
677 target
= procs
[_DST_
];
679 panic("r strange: %d", r
);
685 vm_suspend(caller
, target
, lin
, bytes
, VMSTYPE_KERNELCALL
);
692 /*===========================================================================*
694 *===========================================================================*/
695 int data_copy(const endpoint_t from_proc
, const vir_bytes from_addr
,
696 const endpoint_t to_proc
, const vir_bytes to_addr
,
699 struct vir_addr src
, dst
;
701 src
.offset
= from_addr
;
702 dst
.offset
= to_addr
;
703 src
.proc_nr_e
= from_proc
;
704 dst
.proc_nr_e
= to_proc
;
705 assert(src
.proc_nr_e
!= NONE
);
706 assert(dst
.proc_nr_e
!= NONE
);
708 return virtual_copy(&src
, &dst
, bytes
);
711 /*===========================================================================*
712 * data_copy_vmcheck *
713 *===========================================================================*/
714 int data_copy_vmcheck(struct proc
* caller
,
715 const endpoint_t from_proc
, const vir_bytes from_addr
,
716 const endpoint_t to_proc
, const vir_bytes to_addr
,
719 struct vir_addr src
, dst
;
721 src
.offset
= from_addr
;
722 dst
.offset
= to_addr
;
723 src
.proc_nr_e
= from_proc
;
724 dst
.proc_nr_e
= to_proc
;
725 assert(src
.proc_nr_e
!= NONE
);
726 assert(dst
.proc_nr_e
!= NONE
);
728 return virtual_copy_vmcheck(caller
, &src
, &dst
, bytes
);
731 void memory_init(void)
733 assert(nfreepdes
== 0);
735 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
736 freepdes
[nfreepdes
++] = kinfo
.freepde_start
++;
738 assert(kinfo
.freepde_start
< I386_VM_DIR_ENTRIES
);
739 assert(nfreepdes
== 2);
740 assert(nfreepdes
<= MAXFREEPDES
);
743 /*===========================================================================*
745 *===========================================================================*/
746 void arch_proc_init(struct proc
*pr
, const u32_t ip
, const u32_t sp
, char *name
)
749 strlcpy(pr
->p_name
, name
, sizeof(pr
->p_name
));
751 /* set custom state we know */
756 static int oxpcie_mapping_index
= -1,
757 lapic_mapping_index
= -1,
758 ioapic_first_index
= -1,
759 ioapic_last_index
= -1,
760 video_mem_mapping_index
= -1;
762 extern char *video_mem
;
764 int arch_phys_map(const int index
,
769 static int first
= 1;
771 static char *ser_var
= NULL
;
774 video_mem_mapping_index
= freeidx
++;
778 lapic_mapping_index
= freeidx
++;
779 if (ioapic_enabled
) {
780 ioapic_first_index
= freeidx
;
781 assert(nioapics
> 0);
783 ioapic_last_index
= freeidx
-1;
788 if((ser_var
= env_get("oxpcie"))) {
789 if(ser_var
[0] != '0' || ser_var
[1] != 'x') {
790 printf("oxpcie address in hex please\n");
792 printf("oxpcie address is %s\n", ser_var
);
793 oxpcie_mapping_index
= freeidx
++;
802 if (index
== video_mem_mapping_index
) {
803 /* map video memory in so we can print panic messages */
804 *addr
= MULTIBOOT_VIDEO_BUFFER
;
805 *len
= I386_PAGE_SIZE
;
809 else if (index
== lapic_mapping_index
) {
810 /* map the local APIC if enabled */
814 *len
= 4 << 10 /* 4kB */;
815 *flags
= VMMF_UNCACHED
;
818 else if (ioapic_enabled
&& index
>= ioapic_first_index
&& index
<= ioapic_last_index
) {
819 int ioapic_idx
= index
- ioapic_first_index
;
820 *addr
= io_apic
[ioapic_idx
].paddr
;
822 *len
= 4 << 10 /* 4kB */;
823 *flags
= VMMF_UNCACHED
;
824 printf("ioapic map: addr 0x%lx\n", *addr
);
830 if(index
== oxpcie_mapping_index
) {
831 *addr
= strtoul(ser_var
+2, NULL
, 16);
833 *flags
= VMMF_UNCACHED
;
841 int arch_phys_map_reply(const int index
, const vir_bytes addr
)
844 /* if local APIC is enabled */
845 if (index
== lapic_mapping_index
&& lapic_addr
) {
846 lapic_addr_vaddr
= addr
;
849 else if (ioapic_enabled
&& index
>= ioapic_first_index
&&
850 index
<= ioapic_last_index
) {
851 int i
= index
- ioapic_first_index
;
852 io_apic
[i
].vaddr
= addr
;
858 if (index
== oxpcie_mapping_index
) {
859 oxpcie_set_vaddr((unsigned char *) addr
);
863 if (index
== video_mem_mapping_index
) {
864 video_mem_vaddr
= addr
;
871 int arch_enable_paging(struct proc
* caller
)
873 assert(caller
->p_seg
.p_cr3
);
875 /* load caller's page table */
876 switch_address_space(caller
);
878 video_mem
= (char *) video_mem_vaddr
;
881 /* start using the virtual addresses */
883 /* if local APIC is enabled */
885 lapic_addr
= lapic_addr_vaddr
;
886 lapic_eoi_addr
= LAPIC_EOI
;
888 /* if IO apics are enabled */
889 if (ioapic_enabled
) {
892 for (i
= 0; i
< nioapics
; i
++) {
893 io_apic
[i
].addr
= io_apic
[i
].vaddr
;
899 wait_for_APs_to_finish_booting();
905 * We make sure that we don't enable the watchdog until paging is turned
906 * on as we might get an NMI while switching and we might still use wrong
907 * lapic address. Bad things would happen. It is unfortunate but such is
910 if (watchdog_enabled
)
911 i386_watchdog_start();
917 void release_address_space(struct proc
*pr
)
919 pr
->p_seg
.p_cr3_v
= NULL
;
922 /* computes a checksum of a buffer of a given length. The byte sum must be zero */
923 int platform_tbl_checksum_ok(void *ptr
, unsigned int length
)
927 for (i
= 0; i
< length
; i
++)
928 total
+= ((unsigned char *)ptr
)[i
];
932 int platform_tbl_ptr(phys_bytes start
,
937 phys_bytes
* phys_addr
,
938 int ((* cmp_f
)(void *)))
942 for (addr
= start
; addr
< end
; addr
+= increment
) {
943 phys_copy (addr
, (phys_bytes
) buff
, size
);