Skip to content

Commit

Permalink
refactoring ongoing, modules are risky, a lot of ICEs when module is …
Browse files Browse the repository at this point in the history
…imported by a module
  • Loading branch information
matgla committed Apr 25, 2024
1 parent e1f51f1 commit 9320f65
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 106 deletions.
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ if(${configuration_is_ready})
# Global flags that breaks ABI are specified globally
set(CMAKE_CPPFRONT_FLAGS "-fno-exceptions -fno-rtti")

set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(common_flags "-Werror -pedantic -Wall -Wextra -Wconversion -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wdouble-promotion -Wmissing-braces")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
set(common_flags "-Werror -pedantic -Wall -Wextra -Wconversion -Wunused -Wshadow -Wpointer-arith -Wcast-qual -Wdouble-promotion -Wmissing-braces ")
set(common_release_flags "")
set(common_debug_flags "-g")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions -fmodules-ts -fno-threadsafe-statics ${common_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions -fmodules-ts -fno-threadsafe-statics -fno-module-lazy ${common_flags}")

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${common_release_flags}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${common_debug_flags}")

Expand Down
2 changes: 1 addition & 1 deletion common/source/disk_parameters.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ yasboot: namespace =
filesystem: namespace =
{

export DiskParameters: type =
export DiskParameters: @struct type =
{
public read_size: std::size_t;
public write_size: std::size_t;
Expand Down
5 changes: 5 additions & 0 deletions cpu/arm/v6-m/rp2040/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ target_sources(rp2040
source/hal/system_stubs.cc
)

use_cppfront(
TARGET rp2040
MODULE_SOURCES source/hal/flash.cpp2
)

target_sources(
rp2040
PUBLIC
Expand Down
14 changes: 7 additions & 7 deletions cpu/arm/v6-m/rp2040/source/hal/disk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module;

export module hal.system.disk;

export namespace yasboot::hal::system
export namespace hal::system
{

class Disk
Expand All @@ -36,14 +36,14 @@ class Disk
void read_sector(uint32_t sector_number, void *buffer) const;

template <typename T>
T read(std::size_t address) const;
T read(std::size_t address, std::size_t size = sizeof(T)) const;
};

} // namespace yasboot::hal::system
} // namespace hal::system

/* This implementation is valid only for drive 0 (main memory) */

namespace yasboot::hal::system
namespace hal::system
{

void Disk::read_sector(uint32_t sector_number, void *buffer) const
Expand All @@ -55,11 +55,11 @@ void Disk::read_sector(uint32_t sector_number, void *buffer) const
}

template <typename T>
T Disk::read(std::size_t address) const
T Disk::read(std::size_t address, std::size_t size) const
{
T d;
std::memcpy(&d, reinterpret_cast<void *>(XIP_BASE + address), sizeof(T));
std::memcpy(&d, reinterpret_cast<void *>(XIP_BASE + address), size);
return d;
}

} // namespace yasboot::hal::system
} // namespace hal::system
38 changes: 38 additions & 0 deletions cpu/arm/v6-m/rp2040/source/hal/flash.cpp2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module;

/**
* flash.cpp2
*
* Copyright (C) 2024 Mateusz Stadnik <[email protected]>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General
* Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/

#include <cstring>

export module hal.flash;

yasboot: namespace = {
hal: namespace = {

export InternalFlash: type = {
read: (address: std::size_t, buffer: std::span<u8>) -> std::size_t = {
std::memcpy(buffer.data(), reinterpret_cast<*void>(0x10000000 + address), buffer.size());
return buffer.size();
}
}

} // namespace hal
} // namespace yasboot
23 changes: 23 additions & 0 deletions hal/interface/include/hal/uart.h2
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* uart.hpp
*
* Copyright (C) 2023 Mateusz Stadnik <[email protected]>
*
* This program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version
* 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General
* Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/

hal = namespace {

}
1 change: 0 additions & 1 deletion source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_sources(yasboot
use_cppfront(
TARGET yasboot
MODULE_SOURCES
app.cpp2
)

find_package(eul REQUIRED)
Expand Down
127 changes: 80 additions & 47 deletions source/app.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -19,63 +19,96 @@ module;
* <https://www.gnu.org/licenses/>.
*/

//#include <boost/sml.hpp>


#include <boost/sml.hpp>
#include <map>

export module yasboot.app;

import hal.system.disk;
import yasboot.mbr;
#include <format>

import yasboot.filesystem.disk_parameters;
import hal.flash;
import yasboot.filesystem.littlefs;


yasboot: namespace = {

release: @struct type = {
disk_: hal::system::Disk = ();
}

timeout: @struct type = {
}

export App: @copyable type = {
operator(): (in this) -> _ = {
using namespace boost::sml;
a:= :() -> void = {printf("A\n");};
return boost::sml::make_transition_table(
"initialize"_s* / :() = { initialize(); } = "mount_disks"_s,
"mount_disks"_s + on_entry<_> / :() = { mount_disks(); },
"mount_disks"_s [:() -> bool = { return mbr_.is_valid_mbr(); }] / :() = { printf("disks mounted\n"); } = "find_boot"_s,
"find_boot"_s / :() = { prepare_boot_parition(); } = X
);
}

print_hello: () = {
printf("\n\n");
printf("============== YASBOOT ===============\n");
}

initialize: () = {
print_hello();
}

mount_disks: () = {
printf("Mounting disks\n");
}

prepare_boot_parition: (this) = {
//f: std::unique_ptr<yasboot::filesystem::Fun> = ();
fs : std::unique_ptr<yasboot::filesystem::LittleFS> = ();
//fs: yasboot::filesystem::LittleFS = ();
p:= mbr_.get_bootable_partition();
if (p)
{
printf("Found bootable partition at: %lx, size: %ld\n", p*.lba_start, p*.number_of_sectors);
params:= yasboot::filesystem::DiskParameters(
4,
4,
4096,
(p*.number_of_sectors * 512) >> 12
);
//fs := new<yasboot::filesystem::LittleFS>(params,
// : (address: std::size_t, buffer: std::span<u8>) -> int = {
// offset:= p*.lba_start * 512;
// printf("%ld %d\n", address + offset, buffer.size());
// flash: yasboot::hal::InternalFlash = ();
// if (buffer.size() == flash.read(address + offset, buffer)) {
// return 0;
// }
// return -1;
// }
//);
printf("%u\n", params.read_size);
}
else
{
printf("%s\n", p.error().data());
}
}

operator=:(out this) = {
}

disk_: hal::system::Disk = ();
mbr_: yasboot::MbrParser = (disk_);
//f: std::function<void()> = ();
}

export app: () -> void = {
data: App = ();
sm: boost::sml::sm<App> = (data);
}

}
//
//timeout: @struct type = {
//}
//
//export App: @copyable type = {
// operator(): (in this) -> _ = {
// using namespace boost::sml;
// a:= :() -> void = {printf("A\n");};
// return boost::sml::make_transition_table(
// "initialize"_s* / :() = { initialize(); } = "mount_disks"_s,
// "mount_disks"_s + on_entry<_> / :() = { mount_disks(); },
// "mount_disks"_s [:() -> bool = { return false; }] / :() = { printf("disks mounted\n"); } = "find_boot"_s,
// "find_boot"_s / :() = { printf("searching boot parition\n"); } = X
// );
// }
//
// print_hello: () = {
// printf("\n\n");
// printf("============== YASBOOT ===============\n");
// }
//
// initialize: () = {
// print_hello();
// }
//
// mount_disks: () = {
// printf("Mounting disks\n");
// }
//
// operator=:(out this) = {
// }
//
// disk_: hal::system::Disk = ();
// mbr_: yasboot::MbrParser = (disk_);
//}
//
//export app: () -> void = {
// data: App = ();
// sm: boost::sml::sm<App> = (data);
//}
//
//}
Empty file added source/fs/fs.cpp2
Empty file.
30 changes: 15 additions & 15 deletions source/fs/littlefs.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ module;
* <https://www.gnu.org/licenses/>.
*/

#include <map>
#include <fcntl.h>

#include <eul/functional/function.hpp>

#include <fcntl.h>
#include <map>

#include <lfs.h>

#include "common/filesystem/file_descriptors.hpp"

import yasboot.filesystem.disk_parameters;


export module yasboot.filesystem.littlefs;


export import yasboot.filesystem.disk_parameters;

using ConstLfsConfig = const lfs_config *;
yasboot: namespace = {
filesystem: namespace = {
export yasboot: namespace = {
fs: namespace = {
LittleFS: type = {
ReadFromDisk: type == std::function<int(std::size_t, std::span<uint8_t>)>;
ReadFromDisk: type == std::function<int(std::size_t, std::span<u8>)>;

operator=: (out this, in disk: DiskParameters, in read: ReadFromDisk) = {
operator=: (out this) = {}
operator=: (out this, in disk: filesystem::DiskParameters, in read: ReadFromDisk) = {
read_ = read;
config_ = lfs_config(
this&,
Expand Down Expand Up @@ -91,7 +91,7 @@ filesystem: namespace = {
}
files_[fd] = ();
if (lfs_file_open(lfs_&, files_[fd]&, path.data(),
convert_flags(flags)) != LFS_ERR_OK) {
convert_flags(flags)) != LFS_ERR_OK) {
yasboot::fs::FileDescriptors::get().release(fd);
return std::unexpected(-1);
}
Expand All @@ -112,4 +112,4 @@ filesystem: namespace = {
}
} // namespace filesystem
} // namespace yasboot

Loading

0 comments on commit 9320f65

Please sign in to comment.