Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Architecture rewrite (pre mem rewrite) #8

Merged
merged 11 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/max-os.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:

- name: Build MaxOS (Release)
run: |
cd toolchain
./version.sh --force
cd ../
mkdir -p cmake-build
cd cmake-build
cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain/CMakeToolchain.txt
Expand Down
21 changes: 20 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,23 @@ ADD_CUSTOM_TARGET(run

# Ensure it runs in the terminal
USES_TERMINAL
)
)

ADD_CUSTOM_TARGET(debug
# Run qemu
COMMENT "Running qemu"
COMMAND ${CMAKE_COMMAND} -E env "SOURCE_DIR=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/toolchain/run_qemu.sh --debug

# Ensure it runs in the terminal
USES_TERMINAL
)

ADD_CUSTOM_TARGET(gdb
# Run GDB
COMMENT "Running GDB"
COMMAND ${CMAKE_COMMAND} -E env "SOURCE_DIR=${CMAKE_SOURCE_DIR}" ${CMAKE_SOURCE_DIR}/toolchain/run_gdb.sh
BYPRODUCTS ${CMAKE_SOURCE_DIR}/MaxOS.sym

# Ensure it runs in the terminal
USES_TERMINAL
)
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![Build][built-shield]][built-url]
[![Lines of Code][loc-shield]][loc-url]

<!-- PROJECT LOGO -->
<br />
Expand Down Expand Up @@ -239,4 +240,6 @@ Distributed under the BSD 3-Clause License. See `LICENSE` for more information.
[issues-shield]: https://img.shields.io/github/issues/maxtyson123/MaxOS.svg?style=for-the-badge
[issues-url]: https://github.com/maxtyson123/MaxOS/issues
[built-shield]: https://img.shields.io/github/actions/workflow/status/maxtyson123/MaxOS/max-os.yml?style=for-the-badge
[built-url]: https://github.com/maxtyson123/MaxOS/actions/workflows/max-os.yml
[built-url]: https://github.com/maxtyson123/MaxOS/actions/workflows/max-os.yml
[loc-shield]: https://img.shields.io/tokei/lines/github/maxtyson123/MaxOS?style=for-the-badge
[loc-url]: https://github.com/maxtyson123/MaxOS
29 changes: 10 additions & 19 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,35 @@ We love your input! We want to make contributing to this project as easy and tra
We use GitHub to host code, to track issues and feature requests, as well as accept pull requests.

## Code Standard
To keep the code understanble please make sure it is formatted and reable. Additionally add comments exapling what your function does and the various steps. Summary's and params are only needed if the function is intended to be used on a wider scale e.g. printf but not EtherFrameProvider::OnRawDataReceived(...);
To keep the code understanble please make sure it is formatted and reable. Please look in the coding style [docs](Styles/Coding%20Style.md) for more information.

## We Use [GitHub Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests
Pull requests are the best way to propose changes to the codebase (we use [GitHub Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests:

1. Fork the repo and create your branch from `m_is_master`.
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
4. Clean up the code: clear any debug code, make sure no warnings are generated when compiling, etc.
5. Ensure the kernel builds and runs.
6. Issue that pull request!

## Report bugs using GitHub's [issues](https://github.com/briandk/transcriptase-atom/issues)
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](); it's that easy!
We use GitHub issues to track public bugs. Report a bug by [opening a new issue](https://github.com/maxtyson123/MaxOS/issues/new/choose); it's that easy!

## write bug reports with detail, m_background, and sample code
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report someone wrote, and I think it's not a bad model. Here's [another example from Craig Hockenberry](http://www.openradar.me/11905408), an app developer whom I greatly respect.
## Write bug reports with detail, background, and sample code
[This is an example](http://stackoverflow.com/q/12488905/180626) of a bug report someone wrote on stack overflow.

**Great Bug Reports** tend to have:

- A quick summary and/or m_background
- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can. [This stackoverflow question](http://stackoverflow.com/q/12488905/180626) includes sample code that *anyone* with a base R setup can run to reproduce what I was seeing
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

People *love* thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style
I'm again borrowing these from [Facebook's Guidelines](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)

* 2 spaces for indentation rather than tabs

People *love* thorough bug reports.

## License
By contributing, you agree that your contributions will be licensed under its MIT License.

## References
This document was adapted from the open-source contribution guidelines for [Facebook's Draft](https://github.com/facebook/draft-js/blob/a9316a723f9e918afde44dea68b5f9f39b7d9b00/CONTRIBUTING.md)
By contributing, you agree that your contributions will be licensed under this projects [LICENSE](../LICENSE).
Empty file removed filesystem/bin/TEST
Empty file.
Empty file removed filesystem/etc/.gitkeep
Empty file.
Empty file removed filesystem/home/.gitkeep
Empty file.
Empty file removed filesystem/lib/.gitkeep
Empty file.
Empty file removed filesystem/media/.gitkeep
Empty file.
Empty file removed filesystem/opt/.gitkeep
Empty file.
File renamed without changes.
Empty file removed filesystem/tmp/.gitkeep
Empty file.
File renamed without changes.
Empty file removed filesystem/usr/bin/.gitkeep
Empty file.
Empty file removed filesystem/usr/include/.gitkeep
Empty file.
Empty file removed filesystem/usr/lib/.gitkeep
Empty file.
Empty file removed filesystem/usr/local/.gitkeep
Empty file.
Empty file removed filesystem/usr/share/.gitkeep
Empty file.
Empty file removed filesystem/usr/src/.gitkeep
Empty file.
Empty file removed filesystem/var/.gitkeep
Empty file.
13 changes: 12 additions & 1 deletion kernel/include/common/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ namespace MaxOS {
};

typedef String string;

}

// Compare functions
bool strcmp(char const *str1, char const *str2);
bool strcmp(char const *str1, MaxOS::String const &str2);
bool strcmp(MaxOS::String const &str1, char const *str2);
bool strcmp(MaxOS::String const &str1, MaxOS::String const &str2);

// Compare limited functions
bool strncmp(char const *str1, char const *str2, int length);
bool strncmp(char const *str1, MaxOS::String const &str2, int length);
bool strncmp(MaxOS::String const &str1, char const *str2, int length);
bool strncmp(MaxOS::String const &str1, MaxOS::String const &str2, int length);

#endif //MAXOS_STRING_H
3 changes: 2 additions & 1 deletion kernel/include/drivers/clock/clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace MaxOS {

protected:

bool m_binary_coded_decimal_representation;
bool m_binary;
bool m_24_hour_clock;

// Ports
hardwarecommunication::Port8Bit m_data_port;
Expand Down
75 changes: 75 additions & 0 deletions kernel/include/hardwarecommunication/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// Created by 98max on 18/01/2024.
//

#ifndef MAXOS_HARDWARECOMMUNICATION_ACPI_H
#define MAXOS_HARDWARECOMMUNICATION_ACPI_H

#include <stdint.h>
#include <stddef.h>
#include <system/multiboot.h>
#include <common/string.h>
#include <memory/memorymanagement.h>

namespace MaxOS {
namespace hardwarecommunication {

struct RSDPDescriptor {
char signature[8];
uint8_t checksum;
char OEMID[6];
uint8_t revision;
uint32_t rsdt_address;
} __attribute__ ((packed));

struct RSDPDescriptor2 {
RSDPDescriptor firstPart;
uint32_t length;
uint64_t xsdt_address;
uint8_t extended_checksum;
uint8_t reserved[3];
} __attribute__ ((packed));

struct ACPISDTHeader {
char signature[4];
uint32_t length;
uint8_t revision;
uint8_t checksum;
char OEM_id[6];
char OEM_table_id[8];
uint32_t OEM_revision;
uint32_t creator_id;
uint32_t creator_revision;
} __attribute__ ((packed));

struct RSDT {
ACPISDTHeader header;
uint32_t pointers[];
};

struct XSDT {
ACPISDTHeader header;
uint64_t pointers[];
};

class AdvancedConfigurationAndPowerInterface {
protected:
uint8_t m_type;
ACPISDTHeader* m_header;

XSDT* m_xsdt;
RSDT* m_rsdt;

static bool validate(const char* discriptor, size_t length);

public:
AdvancedConfigurationAndPowerInterface(system::Multiboot* multiboot);
~AdvancedConfigurationAndPowerInterface();

ACPISDTHeader* find(const char* signature);
};

}
}

#endif // MAXOS_HARDWARECOMMUNICATION_ACPI_H
125 changes: 125 additions & 0 deletions kernel/include/hardwarecommunication/apic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
//
// Created by 98max on 18/01/2024.
//

#ifndef MAXOS_HARDWARECOMMUNICATION_APIC_H
#define MAXOS_HARDWARECOMMUNICATION_APIC_H

#include <hardwarecommunication/port.h>
#include <system/cpu.h>
#include <hardwarecommunication/acpi.h>

namespace MaxOS {
namespace hardwarecommunication {


class LocalAPIC {

protected:
uint64_t m_apic_base;
uint32_t m_id;
bool m_x2apic;

uint32_t read(uint32_t reg);
void write(uint32_t reg, uint32_t value);

public:
LocalAPIC();
~LocalAPIC();

void init();

uint32_t id();

};

struct MADT {
ACPISDTHeader header;
uint32_t local_apic_address;
uint32_t flags;
} __attribute__((packed));

struct MADT_Item {
uint8_t type;
uint8_t length;
} __attribute__((packed));

struct MADT_IOAPIC {
uint8_t io_apic_id;
uint8_t reserved;
uint32_t io_apic_address;
uint32_t global_system_interrupt_base;
} __attribute__((packed));

union RedirectionEntry {
struct {
uint64_t vector : 8;
uint64_t delivery_mode : 3;
uint64_t destination_mode : 1;
uint64_t delivery_status : 1;
uint64_t pin_polarity : 1;
uint64_t remote_irr : 1;
uint64_t trigger_mode : 1;
uint64_t mask : 1;
uint64_t reserved : 39;
uint64_t destination : 8;
} __attribute__((packed));

uint64_t raw;
};

struct Override {
uint8_t bus;
uint8_t source;
uint32_t global_system_interrupt;
uint16_t flags;
} __attribute__((packed));

class IOAPIC {
private:
AdvancedConfigurationAndPowerInterface* m_acpi;
MADT* m_madt;
uint32_t m_address;
uint32_t m_version;
uint8_t m_max_redirect_entry;

uint32_t m_override_array_size;
Override m_override_array[0x10];

MADT_Item* get_madt_item(uint8_t type, uint8_t index);

uint32_t read(uint32_t reg);
void write(uint32_t reg, uint32_t value);

void read_redirect(uint8_t index, RedirectionEntry* entry);
void write_redirect(uint8_t index, RedirectionEntry* entry);

public:
IOAPIC(AdvancedConfigurationAndPowerInterface* acpi);
~IOAPIC();

void init();
};

class AdvancedProgrammableInterruptController {

protected:
LocalAPIC m_local_apic;
IOAPIC m_io_apic;

Port8BitSlow m_pic_master_command_port;
Port8BitSlow m_pic_master_data_port;
Port8BitSlow m_pic_slave_command_port;
Port8BitSlow m_pic_slave_data_port;

void disable_pic();

public:
AdvancedProgrammableInterruptController(AdvancedConfigurationAndPowerInterface* acpi);
~AdvancedProgrammableInterruptController();
};

}
}

#endif // MAXOS_HARDWARECOMMUNICATION_APIC_H
Loading
Loading