[denali] Get all caps from the init port.
This allows us to remove the bootstrap capabilities for good woo hoo!
This commit is contained in:
		
							parent
							
								
									6e86ce67f0
								
							
						
					
					
						commit
						7dcbbd671e
					
				|  | @ -1,4 +1,5 @@ | |||
| #include <zcall.h> | ||||
| #include <zglobal.h> | ||||
| #include <zinit.h> | ||||
| 
 | ||||
| #include "stdlib.h" | ||||
|  | @ -15,7 +16,7 @@ class NaiveAllocator { | |||
|     if (err != 0) { | ||||
|       ZProcessExit(err); | ||||
|     } | ||||
|     err = ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, vmmo_cap, &next_addr_); | ||||
|     err = ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &next_addr_); | ||||
|     max_addr_ = next_addr_ + kSize; | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -2,10 +2,6 @@ | |||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <zerrors.h> | ||||
| 
 | ||||
| extern uint64_t gSelfProcCap; | ||||
| extern uint64_t gSelfVmasCap; | ||||
| 
 | ||||
| extern uint64_t gBootDenaliVmmoCap; | ||||
| #include <zglobal.h> | ||||
| 
 | ||||
| z_err_t ParseInitPort(uint64_t init_port_cap); | ||||
|  |  | |||
|  | @ -1,6 +1,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| #include <zcall.h> | ||||
| #include <zerrors.h> | ||||
| 
 | ||||
| class Port { | ||||
|  | @ -9,6 +10,15 @@ class Port { | |||
| 
 | ||||
|   z_err_t PollForIntCap(uint64_t* msg, uint64_t* cap); | ||||
| 
 | ||||
|   template <typename T> | ||||
|   z_err_t WriteMessage(const T& obj, uint64_t cap); | ||||
| 
 | ||||
|  private: | ||||
|   uint64_t port_cap_; | ||||
| }; | ||||
| 
 | ||||
| template <typename T> | ||||
| z_err_t Port::WriteMessage(const T& obj, uint64_t cap) { | ||||
|   return ZPortSend(port_cap_, sizeof(obj), | ||||
|                    reinterpret_cast<const uint8_t*>(&obj), 1, &cap); | ||||
| } | ||||
|  |  | |||
|  | @ -8,6 +8,8 @@ | |||
| uint64_t gSelfProcCap = 0; | ||||
| uint64_t gSelfVmasCap = 0; | ||||
| 
 | ||||
| uint64_t gInitChannelCap = 0; | ||||
| 
 | ||||
| uint64_t gBootDenaliVmmoCap = 0; | ||||
| 
 | ||||
| z_err_t ParseInitPort(uint64_t init_port_cap) { | ||||
|  | @ -25,6 +27,9 @@ z_err_t ParseInitPort(uint64_t init_port_cap) { | |||
|         dbgln("received vmas"); | ||||
|         gSelfVmasCap = init_cap; | ||||
|         break; | ||||
|       case Z_INIT_CHANNEL: | ||||
|         gInitChannelCap = init_cap; | ||||
|         break; | ||||
|       case Z_BOOT_DENALI_VMMO: | ||||
|         dbgln("received denali"); | ||||
|         gBootDenaliVmmoCap = init_cap; | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <zinit.h> | ||||
| 
 | ||||
| #include "mammoth/debug.h" | ||||
| #include "mammoth/init.h" | ||||
| 
 | ||||
| MappedMemoryRegion MappedMemoryRegion::DirectPhysical(uint64_t paddr, | ||||
|                                                       uint64_t size) { | ||||
|  | @ -11,7 +12,7 @@ MappedMemoryRegion MappedMemoryRegion::DirectPhysical(uint64_t paddr, | |||
|   check(ZMemoryObjectCreatePhysical(paddr, size, &vmmo_cap)); | ||||
| 
 | ||||
|   uint64_t vaddr; | ||||
|   check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, vmmo_cap, &vaddr)); | ||||
|   check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr)); | ||||
| 
 | ||||
|   return MappedMemoryRegion(vmmo_cap, paddr, vaddr, size); | ||||
| } | ||||
|  | @ -21,7 +22,7 @@ MappedMemoryRegion MappedMemoryRegion::ContiguousPhysical(uint64_t size) { | |||
|   check(ZMemoryObjectCreateContiguous(size, &vmmo_cap, &paddr)); | ||||
| 
 | ||||
|   uint64_t vaddr; | ||||
|   check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, vmmo_cap, &vaddr)); | ||||
|   check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr)); | ||||
| 
 | ||||
|   return MappedMemoryRegion(vmmo_cap, paddr, vaddr, size); | ||||
| } | ||||
|  | @ -31,7 +32,7 @@ MappedMemoryRegion MappedMemoryRegion::Default(uint64_t size) { | |||
|   check(ZMemoryObjectCreate(size, &vmmo_cap)); | ||||
| 
 | ||||
|   uint64_t vaddr; | ||||
|   check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, vmmo_cap, &vaddr)); | ||||
|   check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr)); | ||||
| 
 | ||||
|   return MappedMemoryRegion(vmmo_cap, 0, vaddr, size); | ||||
| } | ||||
|  |  | |||
|  | @ -7,6 +7,7 @@ | |||
| #include "mammoth/channel.h" | ||||
| #include "mammoth/debug.h" | ||||
| #include "mammoth/init.h" | ||||
| #include "mammoth/port.h" | ||||
| 
 | ||||
| #define MAM_PROC_DEBUG 0 | ||||
| 
 | ||||
|  | @ -99,26 +100,40 @@ uint64_t SpawnProcessFromElfRegion(uint64_t program, Channel& local) { | |||
|   Channel foreign; | ||||
|   check(CreateChannels(local, foreign)); | ||||
| 
 | ||||
|   uint64_t proc_cap; | ||||
|   uint64_t as_cap; | ||||
|   uint64_t foreign_port_id; | ||||
|   uint64_t port_cap; | ||||
| #if MAM_PROC_DEBUG | ||||
|   dbgln("Port Create"); | ||||
| #endif | ||||
|   check(ZPortCreate(&port_cap)); | ||||
|   uint64_t port_cap_donate; | ||||
|   check(ZCapDuplicate(port_cap, &port_cap_donate)); | ||||
| 
 | ||||
| #if MAM_PROC_DEBUG | ||||
|   dbgln("Spawn"); | ||||
| #endif | ||||
|   uint64_t proc_cap; | ||||
|   uint64_t as_cap; | ||||
|   uint64_t foreign_chan_id; | ||||
|   check(ZProcessSpawn(gSelfProcCap, foreign.release_cap(), &proc_cap, &as_cap, | ||||
|                       &foreign_chan_id)); | ||||
|   check(ZProcessSpawn(gSelfProcCap, port_cap_donate, &proc_cap, &as_cap, | ||||
|                       &foreign_port_id)); | ||||
| 
 | ||||
|   uint64_t entry_point = LoadElfProgram(program, as_cap); | ||||
| 
 | ||||
| #if MAM_PROC_DEBUG | ||||
|   dbgln("Thread Create"); | ||||
| #endif | ||||
|   uint64_t thread_cap; | ||||
|   check(ZThreadCreate(proc_cap, &thread_cap)); | ||||
| 
 | ||||
|   Port p(port_cap); | ||||
|   check(p.WriteMessage<uint64_t>(Z_INIT_SELF_PROC, proc_cap)); | ||||
|   check(p.WriteMessage<uint64_t>(Z_INIT_SELF_VMAS, as_cap)); | ||||
|   check(p.WriteMessage<uint64_t>(Z_INIT_CHANNEL, foreign.release_cap())); | ||||
| 
 | ||||
| #if MAM_PROC_DEBUG | ||||
|   dbgln("Thread start"); | ||||
| #endif | ||||
|   check(ZThreadStart(thread_cap, entry_point, foreign_chan_id, 0)); | ||||
|   check(ZThreadStart(thread_cap, entry_point, foreign_port_id, 0)); | ||||
| 
 | ||||
|   return Z_OK; | ||||
| } | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <zinit.h> | ||||
| 
 | ||||
| #include "mammoth/debug.h" | ||||
| #include "mammoth/init.h" | ||||
| 
 | ||||
| namespace { | ||||
| 
 | ||||
|  | @ -16,7 +17,7 @@ extern "C" void thread_entry(Thread::Entry entry, void* arg1) { | |||
| }  // namespace
 | ||||
| 
 | ||||
| Thread::Thread(Entry e, const void* arg1) { | ||||
|   check(ZThreadCreate(Z_INIT_PROC_SELF, &thread_cap_)); | ||||
|   check(ZThreadCreate(gSelfProcCap, &thread_cap_)); | ||||
|   check(ZThreadStart(thread_cap_, reinterpret_cast<uint64_t>(thread_entry), | ||||
|                      reinterpret_cast<uint64_t>(e), | ||||
|                      reinterpret_cast<uint64_t>(arg1))); | ||||
|  |  | |||
|  | @ -1,15 +1,17 @@ | |||
| #include <mammoth/channel.h> | ||||
| #include <mammoth/debug.h> | ||||
| #include <mammoth/init.h> | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| #include "ahci/ahci_driver.h" | ||||
| #include "denali_server.h" | ||||
| 
 | ||||
| int main(uint64_t bootstrap_cap) { | ||||
| uint64_t main(uint64_t init_port_cap) { | ||||
|   check(ParseInitPort(init_port_cap)); | ||||
|   AhciDriver driver; | ||||
|   RET_ERR(driver.Init()); | ||||
| 
 | ||||
|   DenaliServer server(bootstrap_cap, driver); | ||||
|   DenaliServer server(gInitChannelCap, driver); | ||||
|   RET_ERR(server.RunServer()); | ||||
|   // FIXME: Add thread join.
 | ||||
|   return 0; | ||||
|  |  | |||
|  | @ -0,0 +1,10 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| extern uint64_t gSelfProcCap; | ||||
| extern uint64_t gSelfVmasCap; | ||||
| 
 | ||||
| extern uint64_t gInitChannelCap; | ||||
| 
 | ||||
| extern uint64_t gBootDenaliVmmoCap; | ||||
|  | @ -1,9 +1,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #define Z_INIT_PROC_SELF 0x00 | ||||
| #define Z_INIT_VMAS_SELF 0x01 | ||||
| 
 | ||||
| #define Z_INIT_SELF_PROC 0x100 | ||||
| #define Z_INIT_SELF_VMAS 0x101 | ||||
| 
 | ||||
| #define Z_INIT_CHANNEL 0x200 | ||||
| 
 | ||||
| #define Z_BOOT_DENALI_VMMO 0x1000 | ||||
|  |  | |||
|  | @ -21,13 +21,7 @@ RefPtr<Process> Process::RootProcess() { | |||
| 
 | ||||
|   return proc; | ||||
| } | ||||
| RefPtr<Process> Process::Create() { | ||||
|   auto proc = MakeRefCounted<Process>(); | ||||
|   proc->AddNewCapabilityWithId(Z_INIT_PROC_SELF, proc, | ||||
|                                ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD); | ||||
|   proc->AddNewCapabilityWithId(Z_INIT_VMAS_SELF, proc->vmas(), ZC_WRITE); | ||||
|   return proc; | ||||
| } | ||||
| RefPtr<Process> Process::Create() { return MakeRefCounted<Process>(); } | ||||
| 
 | ||||
| Process::Process() | ||||
|     : id_(gNextId++), vmas_(MakeRefCounted<AddressSpace>()), state_(RUNNING) {} | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue