2 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
6 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
7 * Distributed under the terms of the NewOS License.
11 #include "paging/040/M68KPagingStructures040.h"
16 #include <util/AutoLock.h>
19 // Accessor class to reuse the SinglyLinkedListLink of DeferredDeletable for
20 // M68KPagingStructures040.
21 struct PagingStructuresGetLink
{
23 typedef SinglyLinkedListLink
<M68KPagingStructures040
> Link
;
26 inline Link
* operator()(M68KPagingStructures040
* element
) const
28 return (Link
*)element
->GetSinglyLinkedListLink();
31 inline const Link
* operator()(
32 const M68KPagingStructures040
* element
) const
34 return (const Link
*)element
->GetSinglyLinkedListLink();
39 typedef SinglyLinkedList
<M68KPagingStructures040
, PagingStructuresGetLink
>
43 static PagingStructuresList sPagingStructuresList
;
44 static spinlock sPagingStructuresListLock
;
47 M68KPagingStructures040::M68KPagingStructures040()
54 M68KPagingStructures040::~M68KPagingStructures040()
62 M68KPagingStructures040::Init(page_root_entry
* virtualPageRoot
,
63 phys_addr_t physicalPageRoot
, page_root_entry
* kernelPageRoot
)
65 pgroot_virt
= virtualPageRoot
;
66 pgroot_phys
= physicalPageRoot
;
68 // zero out the bottom portion of the new pgroot
69 memset(pgroot_virt
+ FIRST_USER_PGROOT_ENT
, 0,
70 NUM_USER_PGROOT_ENTS
* sizeof(page_root_entry
));
72 // insert this new map into the map list
74 int state
= disable_interrupts();
75 acquire_spinlock(&sPagingStructuresListLock
);
77 // copy the top portion of the page dir from the kernel page dir
78 if (kernelPageRoot
!= NULL
) {
79 memcpy(pgroot_virt
+ FIRST_KERNEL_PGROOT_ENT
,
80 kernelPageRoot
+ FIRST_KERNEL_PGROOT_ENT
,
81 NUM_KERNEL_PGROOT_ENTS
* sizeof(page_root_entry
));
84 sPagingStructuresList
.Add(this);
86 release_spinlock(&sPagingStructuresListLock
);
87 restore_interrupts(state
);
93 M68KPagingStructures040::Delete()
95 // remove from global list
96 InterruptsSpinLocker
locker(sPagingStructuresListLock
);
97 sPagingStructuresList
.Remove(this);
101 // this sanity check can be enabled when corruption due to
102 // overwriting an active page directory is suspected
103 uint32 activePageDirectory
;
104 read_cr3(activePageDirectory
);
105 if (activePageDirectory
== pgdir_phys
)
106 panic("deleting a still active page directory\n");
109 if (are_interrupts_enabled())
112 deferred_delete(this);
117 M68KPagingStructures040::StaticInit()
119 B_INITIALIZE_SPINLOCK(&sPagingStructuresListLock
);
120 new (&sPagingStructuresList
) PagingStructuresList
;
125 M68KPagingStructures040::UpdateAllPageDirs(int index
,
126 page_root_entry entry
)
128 #warning M68K: TODO: allocate all kernel pgdirs at boot and remove this (also dont remove them anymore from unmap)
130 InterruptsSpinLocker
locker(sPagingStructuresListLock
);
132 PagingStructuresList::Iterator it
= sPagingStructuresList
.GetIterator();
133 while (M68KPagingStructures040
* info
= it
.Next())
134 info
->pgroot_virt
[index
] = entry
;