Initial import

This commit is contained in:
Jozef Nagy 2025-01-20 21:52:47 +01:00
commit 94aad4b8e1
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
77 changed files with 4414 additions and 0 deletions

View file

@ -0,0 +1,38 @@
/*********************************************************************************/
/* Module Name: paging.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _MM_PAGING_H
#define _MM_PAGING_H
#include <firmware/memmap.h>
#include <stddef.h>
#include <stdint.h>
#define PAGE_SIZE 0x1000
int paging_init(struct memory_map_info *memmap);
void paging_identity_map(uint64_t addr);
void paging_map(uint64_t phys, uint64_t virt);
void paging_unmap(uint64_t virt);
void *paging_allocate(size_t np);
#endif /* _MM_PAGING_H */

View file

View file

View file

View file

@ -0,0 +1,116 @@
/*********************************************************************************/
/* Module Name: cpu.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _ARCH_CPU_CPU_H
#define _ARCH_CPU_CPU_H
#include <stdint.h>
////
// Utilities
///
static inline void cpu_disable_interrupts(void)
{
__asm__ volatile("cli" ::: "memory");
}
static inline uint64_t read_cr0()
{
uint64_t val;
__asm__ volatile("mov %%cr0, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr2()
{
uint64_t val;
__asm__ volatile("mov %%cr2, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr3()
{
uint64_t val;
__asm__ volatile("mov %%cr3, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr4()
{
uint64_t val;
__asm__ volatile("mov %%cr4, %0"
: "=r"(val));
return val;
}
static inline uint64_t read_cr8()
{
uint64_t val;
__asm__ volatile("mov %%cr8, %0"
: "=r"(val));
return val;
}
static inline void write_cr0(uint64_t val)
{
__asm__ volatile("mov %0, %%cr0"
:: "r"(val));
}
static inline void write_cr2(uint64_t val)
{
__asm__ volatile("mov %0, %%cr2"
:: "r"(val));
}
static inline void write_cr3(uint64_t val)
{
__asm__ volatile("mov %0, %%cr3"
:: "r"(val) : "memory");
}
static inline void write_cr4(uint64_t val)
{
__asm__ volatile("mov %0, %%cr4"
:: "r"(val));
}
static inline void write_cr8(uint64_t val)
{
__asm__ volatile("mov %0, %%cr8"
:: "r"(val));
}
static inline uint8_t inb(uint16_t port)
{
uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret;
}
static inline void outb(uint16_t port, uint8_t val)
{
__asm__ volatile("outb %b0, %w1" :: "a"(val), "Nd"(port) : "memory");
}
#endif /* _ARCH_CPU_CPU_H */

View file

@ -0,0 +1,67 @@
/*********************************************************************************/
/* Module Name: gdt.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _ARCH_CPU_GDT_H
#define _ARCH_CPU_GDT_H
#include <stdint.h>
struct gdt_descriptor {
uint16_t limit_low;
uint16_t base_low;
uint8_t base_mid;
uint8_t access;
uint8_t limit_high : 4;
uint8_t flags : 4;
uint8_t base_high;
} __attribute__((packed));
struct tss_descriptor {
struct gdt_descriptor gdt;
uint32_t base_high;
uint32_t reserved;
} __attribute__((packed));
struct tss {
uint32_t reserved;
uint32_t rsp0[2];
uint32_t rsp1[2];
uint32_t rsp2[2];
uint32_t reserved0[2];
uint32_t ist0[2];
uint32_t ist1[2];
uint32_t ist2[2];
uint32_t ist3[2];
uint32_t ist4[2];
uint32_t ist5[2];
uint32_t ist6[2];
uint32_t ist7[2];
uint32_t reserved1[4];
uint16_t iomap_base;
} __attribute__((packed));
struct gdtr {
uint16_t limit;
uint64_t base;
} __attribute__((packed));
void gdt_set_entry(struct gdt_descriptor *entry, uint32_t base, uint32_t limit, uint8_t access,
uint8_t flags);
#endif /* _ARCH_CPU_GDT_H */

View file

@ -0,0 +1,29 @@
/*********************************************************************************/
/* Module Name: paging.h */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef _MM_PAGING_H
#define _MM_PAGING_H
#include <firmware/memmap.h>
#include <stdint.h>
#define PAGE_SIZE 0x1000
#endif /* _MM_PAGING_H */

View file