headers/bsd: Add sys/queue.h.
[haiku.git] / src / system / kernel / arch / m68k / paging / 040 / M68KPagingStructures040.cpp
blob6c1f144b34e55665ad56fd5d248848bcdef3d659
1 /*
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.
8 */
11 #include "paging/040/M68KPagingStructures040.h"
13 #include <stdlib.h>
15 #include <heap.h>
16 #include <util/AutoLock.h>
19 // Accessor class to reuse the SinglyLinkedListLink of DeferredDeletable for
20 // M68KPagingStructures040.
21 struct PagingStructuresGetLink {
22 private:
23 typedef SinglyLinkedListLink<M68KPagingStructures040> Link;
25 public:
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>
40 PagingStructuresList;
43 static PagingStructuresList sPagingStructuresList;
44 static spinlock sPagingStructuresListLock;
47 M68KPagingStructures040::M68KPagingStructures040()
49 pgroot_virt(NULL)
54 M68KPagingStructures040::~M68KPagingStructures040()
56 // free the page dir
57 free(pgroot_virt);
61 void
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);
92 void
93 M68KPagingStructures040::Delete()
95 // remove from global list
96 InterruptsSpinLocker locker(sPagingStructuresListLock);
97 sPagingStructuresList.Remove(this);
98 locker.Unlock();
100 #if 0
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");
107 #endif
109 if (are_interrupts_enabled())
110 delete this;
111 else
112 deferred_delete(this);
116 /*static*/ void
117 M68KPagingStructures040::StaticInit()
119 B_INITIALIZE_SPINLOCK(&sPagingStructuresListLock);
120 new (&sPagingStructuresList) PagingStructuresList;
124 /*static*/ void
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)
129 #warning M68K:FIXME
130 InterruptsSpinLocker locker(sPagingStructuresListLock);
132 PagingStructuresList::Iterator it = sPagingStructuresList.GetIterator();
133 while (M68KPagingStructures040* info = it.Next())
134 info->pgroot_virt[index] = entry;