First iteration of denali server
This commit is contained in:
parent
82b1a5c4db
commit
ffa2d97a64
18 changed files with 273 additions and 39 deletions
|
|
@ -1,11 +1,14 @@
|
|||
add_executable(denali
|
||||
ahci/ahci_device.cpp
|
||||
ahci/ahci_driver.cpp
|
||||
denali.cpp)
|
||||
denali.cpp
|
||||
denali_server.cpp
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(denali
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
target_link_libraries(denali
|
||||
cxx
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ z_err_t AhciDevice::SendIdentify() {
|
|||
memcpy(command_table_->command_fis, &fis, sizeof(fis));
|
||||
|
||||
commands_[0].region = MappedMemoryRegion::ContiguousPhysical(512);
|
||||
commands_[0].callback = HandleIdent;
|
||||
// commands_[0].callback = HandleIdent;
|
||||
|
||||
command_table_->prds[0].region_address = commands_[0].region.paddr();
|
||||
command_table_->prds[0].byte_count = 512;
|
||||
|
|
@ -119,7 +119,7 @@ void AhciDevice::HandleIrq() {
|
|||
|
||||
for (uint64_t i = 0; i < 32; i++) {
|
||||
if (commands_finished & (1 << i)) {
|
||||
commands_[i].callback(this);
|
||||
// commands_[i].callback(this);
|
||||
commands_issued_ &= ~(1 << i);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,9 +29,8 @@ class AhciDevice {
|
|||
CommandTable* command_table_ = nullptr;
|
||||
|
||||
struct Command {
|
||||
typedef void (*Callback)(AhciDevice*);
|
||||
MappedMemoryRegion region;
|
||||
Callback callback;
|
||||
// std::function<void(MappedMemoryRegion)> callback;
|
||||
};
|
||||
Command commands_[32];
|
||||
uint32_t commands_issued_ = 0;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,19 @@ z_err_t AhciDriver::Init() {
|
|||
return Z_OK;
|
||||
}
|
||||
|
||||
z_err_t AhciDriver::GetDevice(uint64_t id, AhciDevice& device) {
|
||||
if (id >= 32) {
|
||||
return Z_ERR_INVALID;
|
||||
}
|
||||
|
||||
if (!devices_[id].IsInit()) {
|
||||
return Z_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
device = devices_[id];
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
void AhciDriver::DumpCapabilities() {
|
||||
dbgln("AHCI Capabilities:");
|
||||
uint32_t caps = ahci_hba_->capabilities;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ class AhciDriver {
|
|||
|
||||
void InterruptLoop();
|
||||
|
||||
z_err_t GetDevice(uint64_t id, AhciDevice& device);
|
||||
|
||||
void DumpCapabilities();
|
||||
void DumpPorts();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
#include <mammoth/channel.h>
|
||||
#include <mammoth/debug.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ahci/ahci_driver.h"
|
||||
#include "denali_server.h"
|
||||
|
||||
int main(uint64_t bootstrap_cap) {
|
||||
AhciDriver driver;
|
||||
RET_ERR(driver.Init());
|
||||
|
||||
while (1) {
|
||||
};
|
||||
DenaliServer server(bootstrap_cap, driver);
|
||||
RET_ERR(server.RunServer());
|
||||
// FIXME: Add thread join.
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
44
sys/denali/denali_server.cpp
Normal file
44
sys/denali/denali_server.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include "denali_server.h"
|
||||
|
||||
#include <mammoth/debug.h>
|
||||
#include <zcall.h>
|
||||
|
||||
DenaliServer::DenaliServer(uint64_t channel_cap, AhciDriver& driver)
|
||||
: channel_cap_(channel_cap), driver_(driver) {}
|
||||
|
||||
z_err_t DenaliServer::RunServer() {
|
||||
while (true) {
|
||||
uint64_t buff_size = kBuffSize;
|
||||
uint64_t cap_size = 0;
|
||||
uint64_t type = DENALI_INVALID;
|
||||
RET_ERR(ZChannelRecv(channel_cap_, buff_size, read_buffer_, 0, nullptr,
|
||||
&type, &buff_size, &cap_size));
|
||||
switch (type) {
|
||||
case Z_INVALID:
|
||||
dbgln(reinterpret_cast<char*>(read_buffer_));
|
||||
break;
|
||||
case DENALI_READ: {
|
||||
DenaliRead* read_req = reinterpret_cast<DenaliRead*>(read_buffer_);
|
||||
uint64_t memcap = 0;
|
||||
DenaliReadResponse resp;
|
||||
RET_ERR(HandleRead(*read_req, resp, memcap));
|
||||
uint64_t caps_len = memcap ? 1 : 0;
|
||||
RET_ERR(ZChannelSend(channel_cap_, 0, sizeof(DenaliReadResponse),
|
||||
reinterpret_cast<uint8_t*>(&resp), caps_len,
|
||||
&memcap));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dbgln("Invalid message type.");
|
||||
return Z_ERR_UNIMPLEMENTED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
z_err_t DenaliServer::HandleRead(const DenaliRead& read,
|
||||
DenaliReadResponse& resp, uint64_t& memcap) {
|
||||
AhciDevice device;
|
||||
RET_ERR(driver_.GetDevice(read.device_id, device));
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
21
sys/denali/denali_server.h
Normal file
21
sys/denali/denali_server.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include "ahci/ahci_driver.h"
|
||||
#include "denali/denali.h"
|
||||
|
||||
class DenaliServer {
|
||||
public:
|
||||
DenaliServer(uint64_t channel_cap, AhciDriver& driver);
|
||||
|
||||
z_err_t RunServer();
|
||||
|
||||
private:
|
||||
static const uint64_t kBuffSize = 1024;
|
||||
uint64_t channel_cap_;
|
||||
uint8_t read_buffer_[kBuffSize];
|
||||
|
||||
AhciDriver& driver_;
|
||||
|
||||
z_err_t HandleRead(const DenaliRead& read, DenaliReadResponse& resp,
|
||||
uint64_t& mem_cap);
|
||||
};
|
||||
20
sys/denali/include/denali/denali.h
Normal file
20
sys/denali/include/denali/denali.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DENALI_INVALID 0
|
||||
#define DENALI_READ 100
|
||||
|
||||
struct DenaliRead {
|
||||
uint64_t device_id;
|
||||
|
||||
uint64_t lba;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
// Will also include a memory capability.
|
||||
struct DenaliReadResponse {
|
||||
uint64_t device_id;
|
||||
uint64_t lba;
|
||||
uint64_t size;
|
||||
};
|
||||
|
|
@ -3,7 +3,8 @@ add_executable(yellowstone
|
|||
yellowstone.cpp
|
||||
)
|
||||
target_include_directories(yellowstone
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../denali/include/")
|
||||
|
||||
target_link_libraries(yellowstone
|
||||
cxx
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#include <denali/denali.h>
|
||||
#include <mammoth/channel.h>
|
||||
#include <mammoth/debug.h>
|
||||
#include <mammoth/process.h>
|
||||
#include <zcall.h>
|
||||
|
|
@ -8,7 +10,10 @@ uint64_t main() {
|
|||
dbgln("Yellowstone Initializing.");
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, Z_INIT_BOOT_VMMO, &vaddr));
|
||||
check(SpawnProcessFromElfRegion(vaddr));
|
||||
|
||||
Channel local;
|
||||
check(SpawnProcessFromElfRegion(vaddr, local));
|
||||
local.WriteStr("Hello!");
|
||||
|
||||
DumpPciEDevices();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue