Compare commits
8 Commits
685070d65e
...
36a83b142b
Author | SHA1 | Date |
---|---|---|
|
36a83b142b | |
|
45cf2115da | |
|
a202bf2371 | |
|
0aa38ac4a4 | |
|
1cebe547c0 | |
|
ec915338dc | |
|
a15ab24d9b | |
|
27f540e9ae |
|
@ -104,6 +104,15 @@ int vsprintf(char *str, const char *format, va_list arg) {
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 's': {
|
||||||
|
char *instr = va_arg(arg, char *);
|
||||||
|
int width = 0;
|
||||||
|
while (*instr != '\0') {
|
||||||
|
*(str++) = *(instr++);
|
||||||
|
width++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
*(str++) = *(format++);
|
*(str++) = *(format++);
|
||||||
chars++;
|
chars++;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <ztypes.h>
|
#include <zcall.h>
|
||||||
|
|
||||||
class Channel {
|
class Channel {
|
||||||
public:
|
public:
|
||||||
|
@ -13,6 +13,12 @@ class Channel {
|
||||||
z_err_t WriteStr(const char* msg);
|
z_err_t WriteStr(const char* msg);
|
||||||
z_err_t ReadStr(char* buffer, uint64_t* size);
|
z_err_t ReadStr(char* buffer, uint64_t* size);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
z_err_t WriteStruct(T*);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
z_err_t ReadStructAndCap(T*, uint64_t*);
|
||||||
|
|
||||||
// FIXME: Close channel here.
|
// FIXME: Close channel here.
|
||||||
~Channel() {}
|
~Channel() {}
|
||||||
|
|
||||||
|
@ -21,3 +27,22 @@ class Channel {
|
||||||
};
|
};
|
||||||
|
|
||||||
uint64_t CreateChannels(Channel& c1, Channel& c2);
|
uint64_t CreateChannels(Channel& c1, Channel& c2);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
z_err_t Channel::WriteStruct(T* obj) {
|
||||||
|
return ZChannelSend(chan_cap_, sizeof(T), obj, 0, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
z_err_t Channel::ReadStructAndCap(T* obj, uint64_t* cap) {
|
||||||
|
uint64_t num_bytes, num_caps;
|
||||||
|
uint64_t ret = ZChannelRecv(chan_cap_, sizeof(T), obj, /* num_caps= */ 1, cap,
|
||||||
|
&num_bytes, &num_caps);
|
||||||
|
if (ret != Z_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
if (num_caps != 1 || num_bytes != sizeof(T)) {
|
||||||
|
return Z_ERR_INVALID;
|
||||||
|
}
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <ztypes.h>
|
||||||
|
|
||||||
class MappedMemoryRegion {
|
class MappedMemoryRegion {
|
||||||
public:
|
public:
|
||||||
|
@ -8,6 +9,7 @@ class MappedMemoryRegion {
|
||||||
static MappedMemoryRegion DirectPhysical(uint64_t phys_addr, uint64_t size);
|
static MappedMemoryRegion DirectPhysical(uint64_t phys_addr, uint64_t size);
|
||||||
static MappedMemoryRegion ContiguousPhysical(uint64_t size);
|
static MappedMemoryRegion ContiguousPhysical(uint64_t size);
|
||||||
static MappedMemoryRegion Default(uint64_t size);
|
static MappedMemoryRegion Default(uint64_t size);
|
||||||
|
static MappedMemoryRegion FromCapability(z_cap_t vmmo_cap);
|
||||||
|
|
||||||
MappedMemoryRegion() {}
|
MappedMemoryRegion() {}
|
||||||
// TODO: Disallow copy before doing any cleanup here.
|
// TODO: Disallow copy before doing any cleanup here.
|
||||||
|
|
|
@ -35,3 +35,11 @@ MappedMemoryRegion MappedMemoryRegion::Default(uint64_t size) {
|
||||||
|
|
||||||
return MappedMemoryRegion(vmmo_cap, 0, vaddr, size);
|
return MappedMemoryRegion(vmmo_cap, 0, vaddr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MappedMemoryRegion MappedMemoryRegion::FromCapability(z_cap_t vmmo_cap) {
|
||||||
|
uint64_t vaddr;
|
||||||
|
check(ZAddressSpaceMap(gSelfVmasCap, 0, vmmo_cap, &vaddr));
|
||||||
|
|
||||||
|
// FIXME: get the size here.
|
||||||
|
return MappedMemoryRegion(vmmo_cap, 0, vaddr, 0);
|
||||||
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ add_executable(denali
|
||||||
|
|
||||||
target_include_directories(denali
|
target_include_directories(denali
|
||||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
"${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
target_link_libraries(denali
|
target_link_libraries(denali
|
||||||
cxx
|
cxx
|
||||||
|
@ -20,3 +20,19 @@ set_target_properties(denali PROPERTIES
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||||
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_library(libdenali
|
||||||
|
client/denali_client.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(libdenali
|
||||||
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
|
target_link_libraries(libdenali
|
||||||
|
mammoth_lib)
|
||||||
|
|
||||||
|
set_target_properties(libdenali PROPERTIES
|
||||||
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${BASE_COMPILE_FLAGS}"
|
||||||
|
LINK_FLAGS "${CMAKE_EXE_LINK_FLAGS} ${BASE_LINK_FLAGS}"
|
||||||
|
)
|
||||||
|
|
|
@ -76,9 +76,6 @@ void AhciDevice::HandleIrq() {
|
||||||
port_struct_->interrupt_status = int_status;
|
port_struct_->interrupt_status = int_status;
|
||||||
|
|
||||||
uint32_t commands_finished = commands_issued_ & ~port_struct_->command_issue;
|
uint32_t commands_finished = commands_issued_ & ~port_struct_->command_issue;
|
||||||
dbgln("finished %x", commands_finished);
|
|
||||||
dbgln("status %x", int_status);
|
|
||||||
dbgln("Issued %x, %x", commands_issued_, port_struct_->command_issue);
|
|
||||||
|
|
||||||
// FIXME: Pass error codes to the callback.
|
// FIXME: Pass error codes to the callback.
|
||||||
for (uint64_t i = 0; i < 32; i++) {
|
for (uint64_t i = 0; i < 32; i++) {
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#include "denali/denali_client.h"
|
||||||
|
|
||||||
|
#include <mammoth/debug.h>
|
||||||
|
|
||||||
|
#include "denali/denali.h"
|
||||||
|
|
||||||
|
MappedMemoryRegion DenaliClient::ReadSectors(uint64_t device_id, uint64_t lba,
|
||||||
|
uint64_t num_sectors) {
|
||||||
|
DenaliRead read{
|
||||||
|
.device_id = device_id,
|
||||||
|
.lba = lba,
|
||||||
|
.size = num_sectors,
|
||||||
|
};
|
||||||
|
check(channel_.WriteStruct(&read));
|
||||||
|
|
||||||
|
DenaliReadResponse resp;
|
||||||
|
uint64_t mem_cap;
|
||||||
|
check(channel_.ReadStructAndCap(&resp, &mem_cap));
|
||||||
|
|
||||||
|
return MappedMemoryRegion::FromCapability(mem_cap);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mammoth/channel.h>
|
||||||
|
#include <mammoth/memory_region.h>
|
||||||
|
|
||||||
|
class DenaliClient {
|
||||||
|
public:
|
||||||
|
DenaliClient(const Channel& channel) : channel_(channel) {}
|
||||||
|
|
||||||
|
MappedMemoryRegion ReadSectors(uint64_t device_id, uint64_t lba,
|
||||||
|
uint64_t num_sectors);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Channel channel_;
|
||||||
|
};
|
|
@ -1,14 +1,15 @@
|
||||||
add_executable(yellowstone
|
add_executable(yellowstone
|
||||||
|
hw/gpt.cpp
|
||||||
hw/pcie.cpp
|
hw/pcie.cpp
|
||||||
yellowstone.cpp
|
yellowstone.cpp
|
||||||
)
|
)
|
||||||
target_include_directories(yellowstone
|
target_include_directories(yellowstone
|
||||||
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
|
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../denali/include/")
|
|
||||||
|
|
||||||
target_link_libraries(yellowstone
|
target_link_libraries(yellowstone
|
||||||
cxx
|
cxx
|
||||||
mammoth_lib
|
mammoth_lib
|
||||||
|
libdenali
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(yellowstone PROPERTIES
|
set_target_properties(yellowstone PROPERTIES
|
||||||
|
|
|
@ -0,0 +1,101 @@
|
||||||
|
#include "hw/gpt.h"
|
||||||
|
|
||||||
|
#include <mammoth/debug.h>
|
||||||
|
#include <zcall.h>
|
||||||
|
#include <zglobal.h>
|
||||||
|
|
||||||
|
const uint64_t kSectorSize = 512;
|
||||||
|
|
||||||
|
const uint64_t kGptPartitionSignature = 0x54524150'20494645;
|
||||||
|
|
||||||
|
struct MbrPartition {
|
||||||
|
uint8_t boot_indicator;
|
||||||
|
uint8_t starting_chs[3];
|
||||||
|
uint8_t os_type;
|
||||||
|
uint8_t ending_chs[3];
|
||||||
|
uint32_t starting_lba;
|
||||||
|
uint32_t ending_lba;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct ParititionHeader {
|
||||||
|
uint64_t signature;
|
||||||
|
uint32_t revision;
|
||||||
|
uint32_t header_size;
|
||||||
|
uint32_t crc_32;
|
||||||
|
uint32_t reserved;
|
||||||
|
uint64_t lba_self;
|
||||||
|
uint64_t lba_mirror;
|
||||||
|
uint64_t lba_min;
|
||||||
|
uint64_t lba_max;
|
||||||
|
uint64_t guid_low;
|
||||||
|
uint64_t guid_high;
|
||||||
|
uint64_t lba_partition_entries;
|
||||||
|
uint32_t num_partitions;
|
||||||
|
uint32_t parition_entry_size;
|
||||||
|
uint32_t partition_entry_crc32;
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
struct PartitionEntry {
|
||||||
|
uint64_t type_guid_low;
|
||||||
|
uint64_t type_guid_high;
|
||||||
|
uint64_t part_guid_low;
|
||||||
|
uint64_t part_guid_high;
|
||||||
|
uint64_t lba_start;
|
||||||
|
uint64_t lba_end;
|
||||||
|
uint64_t attributes;
|
||||||
|
char partition_name[72];
|
||||||
|
} __attribute__((packed));
|
||||||
|
|
||||||
|
GptReader::GptReader(const DenaliClient& client) : denali_(client) {}
|
||||||
|
|
||||||
|
z_err_t GptReader::ParsePartitionTables() {
|
||||||
|
MappedMemoryRegion lba_1_and_2 = denali_.ReadSectors(0, 0, 2);
|
||||||
|
uint16_t* mbr_sig = reinterpret_cast<uint16_t*>(lba_1_and_2.vaddr() + 0x1FE);
|
||||||
|
if (*mbr_sig != 0xAA55) {
|
||||||
|
return Z_ERR_INVALID;
|
||||||
|
}
|
||||||
|
MbrPartition* first_partition =
|
||||||
|
reinterpret_cast<MbrPartition*>(lba_1_and_2.vaddr() + 0x1BE);
|
||||||
|
if (first_partition->boot_indicator != 0) {
|
||||||
|
dbgln("Boot indicator set: %u", first_partition->boot_indicator);
|
||||||
|
return Z_ERR_INVALID;
|
||||||
|
}
|
||||||
|
if (first_partition->os_type != 0xEE) {
|
||||||
|
dbgln("Incorrect OS type: %x", first_partition->os_type);
|
||||||
|
return Z_ERR_INVALID;
|
||||||
|
}
|
||||||
|
dbgln("LBAs: (%x, %x)", first_partition->starting_lba,
|
||||||
|
first_partition->ending_lba);
|
||||||
|
|
||||||
|
// FIXME: Don't hardcode sector size.
|
||||||
|
ParititionHeader* header =
|
||||||
|
reinterpret_cast<ParititionHeader*>(lba_1_and_2.vaddr() + 512);
|
||||||
|
|
||||||
|
dbgln("signature %lx", header->signature);
|
||||||
|
|
||||||
|
uint64_t num_partitions = header->num_partitions;
|
||||||
|
uint64_t entry_size = header->parition_entry_size;
|
||||||
|
uint64_t num_blocks = (num_partitions * entry_size) / 512;
|
||||||
|
|
||||||
|
dbgln("lba_partition_entries %lx", header->lba_partition_entries);
|
||||||
|
dbgln("num_partitions: %x", num_partitions);
|
||||||
|
dbgln("partition_entry_size: %x", entry_size);
|
||||||
|
dbgln("Num blocks: %x", num_blocks);
|
||||||
|
|
||||||
|
MappedMemoryRegion part_table =
|
||||||
|
denali_.ReadSectors(0, header->lba_partition_entries, num_blocks);
|
||||||
|
dbgln("Entries");
|
||||||
|
for (uint64_t i = 0; i < num_partitions; i++) {
|
||||||
|
PartitionEntry* entry = reinterpret_cast<PartitionEntry*>(
|
||||||
|
part_table.vaddr() + (i * entry_size));
|
||||||
|
if (entry->type_guid_low != 0 || entry->type_guid_high != 0) {
|
||||||
|
dbgln("Entry %u", i);
|
||||||
|
dbgln("T Guid: %lx-%lx", entry->type_guid_high, entry->type_guid_low);
|
||||||
|
dbgln("P Guid: %lx-%lx", entry->part_guid_high, entry->part_guid_low);
|
||||||
|
dbgln("LBA: %lx, %lx", entry->lba_start, entry->lba_end);
|
||||||
|
dbgln("Attrs: %lx", entry->attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Z_OK;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <denali/denali_client.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
class GptReader {
|
||||||
|
public:
|
||||||
|
GptReader(const DenaliClient&);
|
||||||
|
|
||||||
|
z_err_t ParsePartitionTables();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DenaliClient denali_;
|
||||||
|
};
|
|
@ -5,38 +5,25 @@
|
||||||
#include <mammoth/process.h>
|
#include <mammoth/process.h>
|
||||||
#include <zcall.h>
|
#include <zcall.h>
|
||||||
|
|
||||||
|
#include "hw/gpt.h"
|
||||||
#include "hw/pcie.h"
|
#include "hw/pcie.h"
|
||||||
|
|
||||||
uint64_t main(uint64_t port_cap) {
|
uint64_t main(uint64_t port_cap) {
|
||||||
dbgln("Yellowstone Initializing.");
|
dbgln("Yellowstone Initializing.");
|
||||||
check(ParseInitPort(port_cap));
|
check(ParseInitPort(port_cap));
|
||||||
|
|
||||||
|
DumpPciEDevices();
|
||||||
|
|
||||||
uint64_t vaddr;
|
uint64_t vaddr;
|
||||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));
|
check(ZAddressSpaceMap(gSelfVmasCap, 0, gBootDenaliVmmoCap, &vaddr));
|
||||||
|
|
||||||
Channel local;
|
Channel local;
|
||||||
check(SpawnProcessFromElfRegion(vaddr, local));
|
check(SpawnProcessFromElfRegion(vaddr, local));
|
||||||
|
|
||||||
DenaliRead read{
|
DenaliClient client(local);
|
||||||
.device_id = 0,
|
GptReader reader(client);
|
||||||
.lba = 0,
|
|
||||||
.size = 1,
|
|
||||||
};
|
|
||||||
check(ZChannelSend(local.cap(), sizeof(DenaliRead),
|
|
||||||
reinterpret_cast<uint8_t*>(&read), 0, nullptr));
|
|
||||||
|
|
||||||
DenaliReadResponse resp;
|
check(reader.ParsePartitionTables());
|
||||||
uint64_t mem_cap, bytes, caps;
|
|
||||||
|
|
||||||
check(ZChannelRecv(local.cap(), sizeof(resp),
|
|
||||||
reinterpret_cast<uint8_t*>(&resp), 1, &mem_cap, &bytes,
|
|
||||||
&caps));
|
|
||||||
|
|
||||||
check(ZAddressSpaceMap(gSelfVmasCap, 0, mem_cap, &vaddr));
|
|
||||||
uint32_t* mbr = reinterpret_cast<uint32_t*>(vaddr + 0x1FE);
|
|
||||||
dbgln("MBR: %x", *mbr);
|
|
||||||
|
|
||||||
DumpPciEDevices();
|
|
||||||
|
|
||||||
dbgln("Yellowstone Finished Successfully.");
|
dbgln("Yellowstone Finished Successfully.");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -37,25 +37,23 @@ void ZThreadExit();
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2);
|
[[nodiscard]] z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2);
|
||||||
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes,
|
||||||
const uint8_t* bytes, uint64_t num_caps,
|
const void* data, uint64_t num_caps,
|
||||||
const z_cap_t* caps);
|
const z_cap_t* caps);
|
||||||
[[nodiscard]] z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
void* data, uint64_t num_caps, z_cap_t* caps,
|
||||||
z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t* actual_bytes,
|
||||||
uint64_t* actual_caps);
|
uint64_t* actual_caps);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZPortCreate(z_cap_t* port_cap);
|
[[nodiscard]] z_err_t ZPortCreate(z_cap_t* port_cap);
|
||||||
[[nodiscard]] z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes,
|
||||||
const uint8_t* bytes, uint64_t num_caps,
|
const void* data, uint64_t num_caps,
|
||||||
z_cap_t* caps);
|
z_cap_t* caps);
|
||||||
[[nodiscard]] z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
void* data, uint64_t num_caps, z_cap_t* caps,
|
||||||
z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t* actual_bytes, uint64_t* actual_caps);
|
||||||
uint64_t* actual_caps);
|
|
||||||
[[nodiscard]] z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes,
|
[[nodiscard]] z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes,
|
||||||
uint8_t* bytes, uint64_t num_caps,
|
void* data, uint64_t num_caps, z_cap_t* caps,
|
||||||
z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t* actual_bytes, uint64_t* actual_caps);
|
||||||
uint64_t* actual_caps);
|
|
||||||
[[nodiscard]] z_err_t ZIrqRegister(uint64_t irq_num, z_cap_t* port_cap);
|
[[nodiscard]] z_err_t ZIrqRegister(uint64_t irq_num, z_cap_t* port_cap);
|
||||||
|
|
||||||
[[nodiscard]] z_err_t ZCapDuplicate(z_cap_t cap_in, z_cap_t* cap_out);
|
[[nodiscard]] z_err_t ZCapDuplicate(z_cap_t cap_in, z_cap_t* cap_out);
|
||||||
|
|
|
@ -37,7 +37,7 @@ z_err_t Channel::Read(ZMessage& msg) {
|
||||||
msg.num_bytes = next_msg->num_bytes;
|
msg.num_bytes = next_msg->num_bytes;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
msg.bytes[i] = next_msg->bytes[i];
|
static_cast<uint8_t*>(msg.data)[i] = next_msg->bytes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.num_caps = next_msg->caps.size();
|
msg.num_caps = next_msg->caps.size();
|
||||||
|
@ -63,7 +63,7 @@ z_err_t Channel::EnqueueMessage(const ZMessage& msg) {
|
||||||
message->num_bytes = msg.num_bytes;
|
message->num_bytes = msg.num_bytes;
|
||||||
message->bytes = new uint8_t[msg.num_bytes];
|
message->bytes = new uint8_t[msg.num_bytes];
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
message->bytes[i] = msg.bytes[i];
|
message->bytes[i] = static_cast<uint8_t*>(msg.data)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release and store capabilities.
|
// Release and store capabilities.
|
||||||
|
|
|
@ -14,7 +14,7 @@ z_err_t Port::Write(const ZMessage& msg) {
|
||||||
message->num_bytes = msg.num_bytes;
|
message->num_bytes = msg.num_bytes;
|
||||||
message->bytes = new uint8_t[msg.num_bytes];
|
message->bytes = new uint8_t[msg.num_bytes];
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
message->bytes[i] = msg.bytes[i];
|
message->bytes[i] = static_cast<uint8_t*>(msg.data)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_caps; i++) {
|
for (uint64_t i = 0; i < msg.num_caps; i++) {
|
||||||
|
@ -57,7 +57,7 @@ z_err_t Port::Read(ZMessage& msg) {
|
||||||
msg.num_bytes = next_msg->num_bytes;
|
msg.num_bytes = next_msg->num_bytes;
|
||||||
|
|
||||||
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
for (uint64_t i = 0; i < msg.num_bytes; i++) {
|
||||||
msg.bytes[i] = next_msg->bytes[i];
|
static_cast<uint8_t*>(msg.data)[i] = next_msg->bytes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.num_caps = next_msg->caps.size();
|
msg.num_caps = next_msg->caps.size();
|
||||||
|
|
|
@ -42,7 +42,14 @@ void Scheduler::Preempt() {
|
||||||
if (current_thread_ == sleep_thread_) {
|
if (current_thread_ == sleep_thread_) {
|
||||||
// Sleep should never be preempted. (We should yield it if another thread
|
// Sleep should never be preempted. (We should yield it if another thread
|
||||||
// becomes scheduleable).
|
// becomes scheduleable).
|
||||||
|
// FIXME: We should yield these threads instead of preempting them.
|
||||||
|
if (runnable_threads_.size() > 0) {
|
||||||
|
current_thread_ = runnable_threads_.PopFront();
|
||||||
|
sleep_thread_->SetState(Thread::RUNNABLE);
|
||||||
|
SwapToCurrent(*sleep_thread_);
|
||||||
|
} else {
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,14 +125,14 @@ z_err_t ZChannelCreate(z_cap_t* channel1, z_cap_t* channel2) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes, const uint8_t* bytes,
|
z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes, const void* data,
|
||||||
uint64_t num_caps, const z_cap_t* caps) {
|
uint64_t num_caps, const z_cap_t* caps) {
|
||||||
ZChannelSendReq req{
|
ZChannelSendReq req{
|
||||||
.chan_cap = chan_cap,
|
.chan_cap = chan_cap,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = const_cast<uint8_t*>(bytes),
|
.data = const_cast<void*>(data),
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
.caps = const_cast<z_cap_t*>(caps),
|
.caps = const_cast<z_cap_t*>(caps),
|
||||||
},
|
},
|
||||||
|
@ -140,7 +140,7 @@ z_err_t ZChannelSend(z_cap_t chan_cap, uint64_t num_bytes, const uint8_t* bytes,
|
||||||
return SysCall1(Z_CHANNEL_SEND, &req);
|
return SysCall1(Z_CHANNEL_SEND, &req);
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, void* data,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZChannelRecvReq req{
|
ZChannelRecvReq req{
|
||||||
|
@ -148,7 +148,7 @@ z_err_t ZChannelRecv(z_cap_t chan_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.data = data,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
.caps = caps,
|
.caps = caps,
|
||||||
},
|
},
|
||||||
|
@ -166,19 +166,19 @@ z_err_t ZPortCreate(z_cap_t* port_cap) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const uint8_t* bytes,
|
z_err_t ZPortSend(z_cap_t port_cap, uint64_t num_bytes, const void* data,
|
||||||
uint64_t num_caps, z_cap_t* caps) {
|
uint64_t num_caps, z_cap_t* caps) {
|
||||||
ZPortSendReq req{.port_cap = port_cap,
|
ZPortSendReq req{.port_cap = port_cap,
|
||||||
.message = {
|
.message = {
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = const_cast<uint8_t*>(bytes),
|
.data = const_cast<void*>(data),
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
.caps = caps,
|
.caps = caps,
|
||||||
}};
|
}};
|
||||||
return SysCall1(Z_PORT_SEND, &req);
|
return SysCall1(Z_PORT_SEND, &req);
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, void* data,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZPortRecvReq req{
|
ZPortRecvReq req{
|
||||||
|
@ -186,7 +186,7 @@ z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.data = data,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
.caps = caps,
|
.caps = caps,
|
||||||
},
|
},
|
||||||
|
@ -197,7 +197,7 @@ z_err_t ZPortRecv(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, void* data,
|
||||||
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
uint64_t num_caps, z_cap_t* caps, uint64_t* actual_bytes,
|
||||||
uint64_t* actual_caps) {
|
uint64_t* actual_caps) {
|
||||||
ZPortRecvReq req{
|
ZPortRecvReq req{
|
||||||
|
@ -205,7 +205,7 @@ z_err_t ZPortPoll(z_cap_t port_cap, uint64_t num_bytes, uint8_t* bytes,
|
||||||
.message =
|
.message =
|
||||||
{
|
{
|
||||||
.num_bytes = num_bytes,
|
.num_bytes = num_bytes,
|
||||||
.bytes = bytes,
|
.data = data,
|
||||||
.num_caps = num_caps,
|
.num_caps = num_caps,
|
||||||
.caps = caps,
|
.caps = caps,
|
||||||
},
|
},
|
||||||
|
|
|
@ -70,7 +70,7 @@ struct ZChannelCreateResp {
|
||||||
|
|
||||||
struct ZMessage {
|
struct ZMessage {
|
||||||
uint64_t num_bytes;
|
uint64_t num_bytes;
|
||||||
uint8_t* bytes;
|
void* data;
|
||||||
|
|
||||||
uint64_t num_caps;
|
uint64_t num_caps;
|
||||||
z_cap_t* caps;
|
z_cap_t* caps;
|
||||||
|
|
Loading…
Reference in New Issue