Skip to content

Commit

Permalink
Style Corrections for memory
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Jan 4, 2024
1 parent 251dd16 commit 39a9b9c
Show file tree
Hide file tree
Showing 24 changed files with 303 additions and 307 deletions.
20 changes: 10 additions & 10 deletions docs/Notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ See also [RTC](https://wiki.osdev.org/RTC)
- As hard drives have been around for a long time, they are well documented and easy to implement
- SATA devices are almost always compatible to ATA or AHCI (Advanced Host Controller Interface)
- Using the PCI controller, SATA hard drives can be found on class id 0x01 and subclass id 0x06
- There are two different ways of accessing a hard-drive. The first one is PIO (Programed Input Output) which is relatively simple to implement but rather slow (maxs out at 16 M/Bs)
- There are two different ways of accessing a hard-drive. The m_first_memory_chunk one is PIO (Programed Input Output) which is relatively simple to implement but rather slow (maxs out at 16 M/Bs)
- The second and better way would be DMA (Direct Memory Access) , which simply just writes the data to a memory location and sends an interrupt once finished
- Although it is better to read from the PCI devices list, the ports can just be hard coded
- For the Implementation of PIO:
Expand All @@ -155,18 +155,18 @@ See also [RTC](https://wiki.osdev.org/RTC)
### Partion Table
- This OS will use the MS DOS partition table is because it is the most common and well documented. Additionalym Windows uses it and so does Linux
- This partion table is simple so it is easy to implement, but it is also limited to 4 primary partitions and 1 extended partition.
- The partition table is located at the end of the first sector of the hard drive
- At the start of the first sector there is a 440 byte boot sector, which is used to boot the OS. The bootstraper will then look at the partition table to find the OS partition.
- The partition table is located at the end of the m_first_memory_chunk sector of the hard drive
- At the start of the m_first_memory_chunk sector there is a 440 byte boot sector, which is used to boot the OS. The bootstraper will then look at the partition table to find the OS partition.
- After the boot sector there are 4 bytes of signature.
- Then there is 2 bytes that are unused
- Then there is the partition table which is 64 bytes long and has 4 entries of 16 bytes each
- At the end there are 2 magic bytes (0x55, 0xAA) which is used to check if the partition table is m_valid
- The structure of the partition table is as follows:
- - First 1 byte: Bootable flag (0x80 = bootable, 0x00 = not bootable) (There can only be one bootable partition per hard drive)
- - Next 3 bytes: Cylinder Head Sector (CHS) address of the first sector of the partition
- - Next 3 bytes: Cylinder Head Sector (CHS) address of the m_first_memory_chunk sector of the partition
- - Next 1 byte: Partition type (0x00 = empty, 0x01 = FAT12, 0x04 = FAT16, 0x05 = Extended, 0x06 = FAT16, 0x07 = NTFS, 0x0B = FAT32, 0x0C = FAT32, 0x0E = FAT16, 0x0F = Extended, 0x11 = Hidden FAT12, 0x14 = Hidden FAT16, 0x16 = Hidden FAT16, 0x1B = Hidden FAT32, 0x1C = Hidden FAT32, 0x1E = Hidden FAT16, 0x42 = MBR, 0x82 = Linux Swap, 0x83 = Linux, 0x84 = Hibernation, 0x85 = Linux Extended, 0x86 = NTFS Volume Set, 0x87 = NTFS Volume Set, 0xA5 = FreeBSD, 0xA6 = OpenBSD, 0xA9 = NetBSD, 0xB7 = BSDI, 0xB8 = BSDI Swap, 0xEB = BeOS, 0xEE = GPT, 0xEF = EFI System, 0xFB = VMWare File System, 0xFC = VMWare Swap)
- - Next 3 bytes: Cylinder Head Sector (CHS) address of the last sector of the partition
- - Next 4 bytes: LBA address of the first sector of the partition
- - Next 4 bytes: LBA address of the m_first_memory_chunk sector of the partition
- - Next 4 bytes: Number of sectors in the partition
<!-- TOC --><a name="fat-32-file-system"></a>
### Fat 32 File System
Expand Down Expand Up @@ -235,7 +235,7 @@ See also [FAT32](https://en.wikipedia.org/wiki/Design_of_the_FAT_file_system#FAT
- A cluster can only belong to one file at a time. This is useful as that means that when a file is being read or expand the operating system doesnt need to split the cluster up.
<!-- TOC --><a name="graphics"></a>
# Graphics
Here are the notes on graphics for the operating system. (May need to read hardware communication first)
Here are the notes on graphics for the operating system. (May need to read hardware communication m_first_memory_chunk)
<!-- TOC --><a name="graphics-mode-vga"></a>
### Graphics Mode {VGA}
- To write pixels and such to the screen for a GUI the graphics card needs to be put into graphics mode (grub puts it into text mode by default)
Expand Down Expand Up @@ -311,7 +311,7 @@ See also [Stack](https://wiki.osdev.org/Stack), **Note this needs better explain
- - kernel will execute the interrupt handler
- - The interrupt handler will then return a pointer to the new task
- - Kernel will then execute the new task instead of executing function "X"
- To schedule processes fairly, a round-robin scheduler generally employs time-sharing, giving each job a time slot or quantum (its allowance of CPU time), and interrupting the job if it is not completed by then. The job is resumed next time a time slot is assigned to that task. If the task terminates or changes its state to waiting during its attributed time quantum, the scheduler selects the first task in the ready queue to execute
- To schedule processes fairly, a round-robin scheduler generally employs time-sharing, giving each job a time slot or quantum (its allowance of CPU time), and interrupting the job if it is not completed by then. The job is resumed next time a time slot is assigned to that task. If the task terminates or changes its state to waiting during its attributed time quantum, the scheduler selects the m_first_memory_chunk task in the ready queue to execute
<!-- TOC --><a name="threads"></a>
### Threads
See also: [Thread](https://wiki.osdev.org/Thread)
Expand Down Expand Up @@ -458,13 +458,13 @@ See also [Wikipedia - UDP](https://en.wikipedia.org/wiki/User_Datagram_Protocol)
### Transmission Control Protocol
See also [Wikipedia - TCP](https://en.wikipedia.org/wiki/Transmission_Control_Protocol)
- The Transmission Control Protocol (TCP) is one of the main protocols of the Internet protocol suite. It originated in the initial network implementation in which it complemented the Internet Protocol. It provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network. Major internet applications such as the World Wide Web, email, remote administration, and file transfer rely on TCP. Applications that do not require reliable data stream service may use the User Datagram Protocol (UDP), which provides a connectionless datagram service that emphasizes reduced latency over reliability.
- TCP is a connection-oriented protocol, which means that two computers must first establish a connection before exchanging data.
- TCP is a connection-oriented protocol, which means that two computers must m_first_memory_chunk establish a connection before exchanging data.
- The reason it is connection oriented is that it requires the host to acknowledge receipt of the data. This means that if the data is lost it will be resent and the application will know. This is fine for applications that require the data to be received.
- TCP is a reliable protocol, which means that it will resend any lost packets. This is done by using a sequence number and an acknowledgement number. The sequence number is the number of the first byte in the data. The acknowledgement number is the number of the next byte that is expected. If the acknowledgement number is not the same as the sequence number, the data is resent.
- TCP is a reliable protocol, which means that it will resend any lost packets. This is done by using a sequence number and an acknowledgement number. The sequence number is the number of the m_first_memory_chunk byte in the data. The acknowledgement number is the number of the next byte that is expected. If the acknowledgement number is not the same as the sequence number, the data is resent.
- The TCP data block is as follows: (known as the payload in the raw-data)
- - First 2 Bytes: Source Port (Port that the data is coming from)
- - Next 2 Bytes: Destination Port (Port that the data is going to)
- - Next 4 Bytes: Sequence Number (Number of the first byte in the data)
- - Next 4 Bytes: Sequence Number (Number of the m_first_memory_chunk byte in the data)
- - Next 4 Bytes: Acknowledgement Number (Number of the next byte that is expected)
- - Next 1 Byte: Header Length (Length of the TCP header)
- - Next 1 Byte: Flags (Flags that are set)
Expand Down
2 changes: 1 addition & 1 deletion docs/Styles/Coding Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This document describes the coding style used for C++ code in the Max Operating

A combination of CamelCase, snake\_case, and SCREAMING\_CASE:

- Use CamelCase (Capitalize the first letter, including all letters in an acronym) in a class, struct, or namespace name
- Use CamelCase (Capitalize the m_first_memory_chunk letter, including all letters in an acronym) in a class, struct, or namespace name
- Use snake\_case (all lowercase, with underscores separating words) for variable and function names
- Use SCREAMING\_CASE for constants (both global and static member variables)

Expand Down
6 changes: 3 additions & 3 deletions docs/Styles/Interface Style.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MaxOS employs two capitalization styles:

### Book m_title capitalization

In this style, we capitalize the first letter of the first and last word,
In this style, we capitalize the m_first_memory_chunk letter of the m_first_memory_chunk and last word,
as well as all words in between, *except* articles (a, an, the);
the seven coordinating conjunctions (for, and, nor, but, or, yet, so);
and prepositions with up to four letters (at, by, for, with, into, ...)
Expand All @@ -34,7 +34,7 @@ and prepositions with up to four letters (at, by, for, with, into, ...)
### Sentence-style capitalization

This style follows basic English sentence capitalization.
We capitalize the first letter of the first word, along with the first letter
We capitalize the m_first_memory_chunk letter of the m_first_memory_chunk word, along with the m_first_memory_chunk letter
of proper names, weekdays, etc.

#### Examples:
Expand All @@ -61,7 +61,7 @@ functions in the interface:
- Eliding text
- Foreshadowing additional user input

The first occurs programmatically, but the second requires care when setting
The m_first_memory_chunk occurs programmatically, but the second requires care when setting
text manually.

Control text which implies an action whose effect is incomplete pending further
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/common/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ namespace maxOS{
*
* @tparam Key The key type
* @tparam Value The value type
* @return The first element in the map
* @return The m_first_memory_chunk element in the map
*/
template<class Key, class Value> typename Map<Key, Value>::iterator Map<Key, Value>::begin() {
return m_elements.begin();
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/common/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace maxOS {
* @class Pair
* @brief A pair of two objects
*
* @tparam First The type of the first object
* @tparam First The type of the m_first_memory_chunk object
* @tparam Second The type of the second object
*/
template<class First, class Second> class Pair {
Expand Down
6 changes: 3 additions & 3 deletions kernel/include/common/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ namespace maxOS{
}

/**
* @brief Returns the first element of the Vector
* @brief Returns the m_first_memory_chunk element of the Vector
*
* @tparam Type Type of the Vector
* @return The first element of the Vector
* @return The m_first_memory_chunk element of the Vector
*/
template<class Type> typename Vector<Type>::iterator Vector<Type>::begin() {
return &m_elements[0];
Expand Down Expand Up @@ -231,7 +231,7 @@ namespace maxOS{
}

/**
* @brief Removes the first element from the Vector
* @brief Removes the m_first_memory_chunk element from the Vector
*
* @tparam Type Type of the Vector
*/
Expand Down
16 changes: 16 additions & 0 deletions kernel/include/hardwarecommunication/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ namespace maxOS {
~Port();
};

/**
* @class Port8Bit
* @brief Handles 8 bit ports
*/
class Port8Bit : public Port {
public:
Port8Bit(uint16_t port_number);
Expand All @@ -30,6 +34,10 @@ namespace maxOS {
virtual uint8_t read();
};

/**
* @class Port8BitSlow
* @brief Handles 8 bit ports (slow)
*/
class Port8BitSlow : public Port8Bit {
public:
Port8BitSlow(uint16_t port_number);
Expand All @@ -38,6 +46,10 @@ namespace maxOS {
virtual void write(uint8_t data) final;
};

/**
* @class Port16Bit
* @brief Handles 16 bit ports
*/
class Port16Bit : public Port {
public:
Port16Bit(uint16_t port_number);
Expand All @@ -47,6 +59,10 @@ namespace maxOS {
virtual uint16_t read();
};

/**
* @class Port32Bit
* @brief Handles 32 bit ports
*/
class Port32Bit : public Port {
public:
Port32Bit(uint16_t port_number);
Expand Down
58 changes: 27 additions & 31 deletions kernel/include/memory/memoryIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,64 @@
namespace maxOS{
namespace memory{

//Base class for memory I/o
/**
* @class MemIO
* @brief Base class for all memory IO
*/
class MemIO {
protected: //Protected so that it cant be instantiated bc its purely virtual
uint64_t address;
protected:
uint32_t m_address;

MemIO(uint64_t address);
MemIO(uint32_t address);
~MemIO();
};

/**
* @class MemIO8Bit
* @brief Handles 8 bit memory IO
*/
class MemIO8Bit : public MemIO {
public:
//Constructor / Deconstructor
MemIO8Bit(uint64_t address);
MemIO8Bit(uint32_t address);
~MemIO8Bit();

//read / write function
virtual void Write(uint8_t data);

virtual uint8_t Read();
virtual void write(uint8_t data);
virtual uint8_t read();
};


class MemIO16Bit : public MemIO {
public:
//Constructor / Deconstructor
MemIO16Bit(uint64_t address);
MemIO16Bit(uint32_t address);
~MemIO16Bit();

//read / write function
virtual void Write(uint16_t data);

virtual uint16_t Read();
virtual void write(uint16_t data);
virtual uint16_t read();
};

class MemIO32Bit : public MemIO {
public:
//Constructor / Deconstructor
MemIO32Bit(uint64_t address);
MemIO32Bit(uint32_t address);
~MemIO32Bit();

//read / write function
virtual void Write(uint32_t data);

virtual uint32_t Read();
virtual void write(uint32_t data);
virtual uint32_t read();
};

class MemIO64Bit : public MemIO {
public:
//Constructor / Deconstructor
MemIO64Bit(uint64_t address);
MemIO64Bit(uint32_t address);
~MemIO64Bit();

//read / write function
virtual void Write(uint64_t data);

virtual uint64_t Read();
virtual void write(uint64_t data);
virtual uint64_t read();
};


void* memcpy(void* destination, const void* source, uint32_t num);


static void* memcpy(void* destination, const void* source, uint32_t num);
static void* memset(void* ptr, int value, uint32_t num);
static void* memmove(void* destination, const void* source, uint32_t num);
static int memcmp(const void* ptr1, const void* ptr2, uint32_t num);
}
}

Expand Down
63 changes: 17 additions & 46 deletions kernel/include/memory/memorymanagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,26 @@ namespace maxOS{

};

/**
* @class MemoryManager
* @brief Handles memory allocation and deallocation
*/
class MemoryManager{

protected:
MemoryChunk* first;

public:
static MemoryManager* activeMemoryManager; //Similar to how we have the active interrupt manager

MemoryManager(size_t start, size_t size);
~MemoryManager();

void* malloc(size_t size);
void free(void* pointer);
int getMemoryUsed();

template<class Type> Type* Instantiate(uint32_t numberOfElements=1){
Type* result = (Type*)malloc(sizeof(Type)*numberOfElements);
new (result) Type();
return result;
}

template<class Type, class Parameter1> Type* Instantiate(Parameter1 p1){
Type* result = (Type*)malloc(sizeof(Type));
new (result) Type(p1);
return result;
}

template<class Type, class Parameter1, class Parameter2> Type* Instantiate(Parameter1 p1, Parameter2 p2) {
Type* result = (Type*)malloc(sizeof(Type));
new (result) Type(p1, p2);
return result;
}

template<class Type, class Parameter1, class Parameter2, class Parameter3> Type* Instantiate(Parameter1 p1, Parameter2 p2, Parameter3 p3) {
Type* result = (Type*)malloc(sizeof(Type));
new (result) Type(p1, p2, p3);
return result;
}

template<class Type, class Parameter1, class Parameter2, class Parameter3, class Parameter4> Type* Instantiate(Parameter1 p1, Parameter2 p2, Parameter3 p3, Parameter4 p4) {
Type* result = (Type*)malloc(sizeof(Type));
new (result) Type(p1, p2, p3, p4);
return result;
}
protected:
MemoryChunk* m_first_memory_chunk;

};
}
public:
static MemoryManager* s_active_memory_manager;

MemoryManager(size_t start, size_t size);
~MemoryManager();

void* malloc(size_t size);
void free(void* pointer);
int memory_used();
};
}
}


Expand All @@ -83,7 +54,7 @@ void* operator new[](size_t size);
void* operator new(size_t size, void* pointer);
void* operator new[](size_t size, void* pointer);

void operator delete(void* pointer);
void operator delete[](void* pointer);
void operator delete(void* pointer, size_t size);
void operator delete[](void* pointer, size_t size);

#endif //MAXOS_SYSTEM_MEMORYMANAGEMENT_H
8 changes: 4 additions & 4 deletions kernel/src/common/graphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ void GraphicsContext::invert_pixel(int32_t x, int32_t y) {
/**
* @brief Draws a line on the screen
*
* @param x0 The x coordinate of the first point
* @param y0 The y coordinate of the first point
* @param x0 The x coordinate of the m_first_memory_chunk point
* @param y0 The y coordinate of the m_first_memory_chunk point
* @param x1 The x coordinate of the final point
* @param y1 The y coordinate of the final point
* @param colour The colour of the line
Expand All @@ -459,8 +459,8 @@ void GraphicsContext::draw_line(int32_t x0, int32_t y0, int32_t x1, int32_t y1,
/**
* @brief Draws a line on the screen
*
* @param x0 The x coordinate of the first point
* @param y0 The y coordinate of the first point
* @param x0 The x coordinate of the m_first_memory_chunk point
* @param y0 The y coordinate of the m_first_memory_chunk point
* @param x1 The x coordinate of the final point
* @param y1 The y coordinate of the final point
* @param colour The colour of the line
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/drivers/console/vesaboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ VESABootConsole::VESABootConsole(GraphicsContext *graphics_context)
{

// Malloc the video memory
m_video_memory = (uint16_t*)MemoryManager::activeMemoryManager->malloc(
m_video_memory = (uint16_t*)MemoryManager::s_active_memory_manager->malloc(
graphics_context->get_width() * graphics_context->get_height() * sizeof(uint16_t));
}

Expand Down
Loading

0 comments on commit 39a9b9c

Please sign in to comment.