feat: gdt, attributes move, reorder
Added late gdt setup with initial tss Moved attributes to include root Reordered some imports
This commit is contained in:
19
include/attributes.h
Normal file
19
include/attributes.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by rick on 24-02-21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef NEW_KERNEL_ATTRIBUTES_H
|
||||||
|
#define NEW_KERNEL_ATTRIBUTES_H
|
||||||
|
|
||||||
|
// generic
|
||||||
|
#define att_used __attribute((used))
|
||||||
|
|
||||||
|
// function
|
||||||
|
#define att_noreturn __attribute((noreturn))
|
||||||
|
#define att_cdecl __attribute((cdecl))
|
||||||
|
// structure
|
||||||
|
#define att_packed __attribute((packed))
|
||||||
|
// field
|
||||||
|
#define att_aligned(size) __attribute((aligned(size)))
|
||||||
|
|
||||||
|
#endif //NEW_KERNEL_ATTRIBUTES_H
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#define NEW_KERNEL_ELF_H
|
#define NEW_KERNEL_ELF_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
#define SHT_NULL 0
|
#define SHT_NULL 0
|
||||||
#define SHT_PROGBITS 1
|
#define SHT_PROGBITS 1
|
||||||
@@ -59,7 +59,7 @@ struct elf32_section_header {
|
|||||||
uint32_t sh_info;
|
uint32_t sh_info;
|
||||||
uint32_t sh_addr_align;
|
uint32_t sh_addr_align;
|
||||||
uint32_t sh_ent_size;
|
uint32_t sh_ent_size;
|
||||||
} packed;
|
} att_packed;
|
||||||
|
|
||||||
struct elf32_symtab_entry {
|
struct elf32_symtab_entry {
|
||||||
uint32_t st_name;
|
uint32_t st_name;
|
||||||
@@ -68,6 +68,6 @@ struct elf32_symtab_entry {
|
|||||||
uint8_t st_info;
|
uint8_t st_info;
|
||||||
uint8_t st_other;
|
uint8_t st_other;
|
||||||
uint16_t st_shndx;
|
uint16_t st_shndx;
|
||||||
} packed;
|
} att_packed;
|
||||||
|
|
||||||
#endif //NEW_KERNEL_ELF_H
|
#endif //NEW_KERNEL_ELF_H
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by rick on 24-02-21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef NEW_KERNEL_ATTRIBUTES_H
|
|
||||||
#define NEW_KERNEL_ATTRIBUTES_H
|
|
||||||
|
|
||||||
// generic
|
|
||||||
#define used __attribute((used))
|
|
||||||
|
|
||||||
// function
|
|
||||||
#define noreturn __attribute((noreturn))
|
|
||||||
#define cdecl __attribute((cdecl))
|
|
||||||
// structure
|
|
||||||
#define packed __attribute((packed))
|
|
||||||
// field
|
|
||||||
#define at_aligned(size) __attribute((aligned(size)))
|
|
||||||
|
|
||||||
#endif //NEW_KERNEL_ATTRIBUTES_H
|
|
||||||
10
include/myke/cpu/gdt.h
Normal file
10
include/myke/cpu/gdt.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//
|
||||||
|
// Created by rick on 19-03-21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef NEW_KERNEL_GDT_H
|
||||||
|
#define NEW_KERNEL_GDT_H
|
||||||
|
|
||||||
|
void gdt_init();
|
||||||
|
|
||||||
|
#endif //NEW_KERNEL_GDT_H
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#ifndef MY_KERNEL_IDT_H
|
#ifndef MY_KERNEL_IDT_H
|
||||||
#define MY_KERNEL_IDT_H
|
#define MY_KERNEL_IDT_H
|
||||||
|
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
#define KERNEL_CS 0x08
|
#define KERNEL_CS 0x08
|
||||||
|
|
||||||
@@ -22,12 +22,12 @@ typedef struct {
|
|||||||
* Bits 3-0: bits 1110 = decimal 14 = "32 bit interrupt gate" */
|
* Bits 3-0: bits 1110 = decimal 14 = "32 bit interrupt gate" */
|
||||||
uint8_t flags;
|
uint8_t flags;
|
||||||
uint16_t high_offset; /* Higher 16 bits of handler function address */
|
uint16_t high_offset; /* Higher 16 bits of handler function address */
|
||||||
} packed idt_gate_t;
|
} att_packed idt_gate_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t limit;
|
uint16_t limit;
|
||||||
uint32_t base;
|
uint32_t base;
|
||||||
} packed idt_register_t;
|
} att_packed idt_register_t;
|
||||||
|
|
||||||
#define IDT_REGISTERS 256
|
#define IDT_REGISTERS 256
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef NEW_KERNEL_DRIVER_H
|
#ifndef NEW_KERNEL_DRIVER_H
|
||||||
#define NEW_KERNEL_DRIVER_H
|
#define NEW_KERNEL_DRIVER_H
|
||||||
|
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
#include <myke/preprocessor_format_zero.h>
|
#include <myke/preprocessor_format_zero.h>
|
||||||
|
|
||||||
#ifndef STRUCT_ALIGNMENT
|
#ifndef STRUCT_ALIGNMENT
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <myke/driver.h>
|
#include <myke/driver.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
#define PCI_CLASS_MASS_STORAGE 0x01
|
#define PCI_CLASS_MASS_STORAGE 0x01
|
||||||
#define PCI_CLASS_BRIDGE 0x06
|
#define PCI_CLASS_BRIDGE 0x06
|
||||||
@@ -190,7 +190,7 @@ typedef union {
|
|||||||
bool fast_b2b_enable: 1;
|
bool fast_b2b_enable: 1;
|
||||||
bool interrupt_disable: 1;
|
bool interrupt_disable: 1;
|
||||||
uint8_t reserved2: 5;
|
uint8_t reserved2: 5;
|
||||||
} packed command;
|
} att_packed command;
|
||||||
} pci_command_register_t;
|
} pci_command_register_t;
|
||||||
|
|
||||||
typedef union {
|
typedef union {
|
||||||
@@ -209,7 +209,7 @@ typedef union {
|
|||||||
bool received_master_abort: 1;
|
bool received_master_abort: 1;
|
||||||
bool signaled_system_error: 1;
|
bool signaled_system_error: 1;
|
||||||
bool detected_parity_error: 1;
|
bool detected_parity_error: 1;
|
||||||
} packed status;
|
} att_packed status;
|
||||||
} pci_status_register_t;
|
} pci_status_register_t;
|
||||||
|
|
||||||
void pci_print_info();
|
void pci_print_info();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#ifndef NEW_KERNEL_LIBK_H
|
#ifndef NEW_KERNEL_LIBK_H
|
||||||
#define NEW_KERNEL_LIBK_H
|
#define NEW_KERNEL_LIBK_H
|
||||||
|
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
extern void *_kernel_start;
|
extern void *_kernel_start;
|
||||||
@@ -17,8 +17,8 @@ bool k_addr_in_kspace(void *addr);
|
|||||||
|
|
||||||
void k_wait_for_interrupt();
|
void k_wait_for_interrupt();
|
||||||
|
|
||||||
void noreturn k_panics(const char *msg);
|
void att_noreturn k_panics(const char *msg);
|
||||||
|
|
||||||
void noreturn k_panic();
|
void att_noreturn k_panic();
|
||||||
|
|
||||||
#endif //NEW_KERNEL_LIBK_H
|
#endif //NEW_KERNEL_LIBK_H
|
||||||
|
|||||||
@@ -6,14 +6,14 @@
|
|||||||
#define NEW_KERNEL_SYSCALL_H
|
#define NEW_KERNEL_SYSCALL_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
#define SYSCALL_START_SCHEDULER 0x01
|
#define SYSCALL_START_SCHEDULER 0x01
|
||||||
#define SYSCALL_YIELD_JOB 0x02
|
#define SYSCALL_YIELD_JOB 0x02
|
||||||
#define SYSCALL_YIELD_IRQ 0x03
|
#define SYSCALL_YIELD_IRQ 0x03
|
||||||
#define SYSCALL_SUSPEND 0x04
|
#define SYSCALL_SUSPEND 0x04
|
||||||
|
|
||||||
void noreturn syscall_start_scheduler();
|
void att_noreturn syscall_start_scheduler();
|
||||||
|
|
||||||
void syscall_yield_job();
|
void syscall_yield_job();
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
#ifndef NEW_KERNEL_POWER_H
|
#ifndef NEW_KERNEL_POWER_H
|
||||||
#define NEW_KERNEL_POWER_H
|
#define NEW_KERNEL_POWER_H
|
||||||
|
|
||||||
#include <myke/attributes.h>
|
#include <attributes.h>
|
||||||
|
|
||||||
void noreturn power_shutdown();
|
void att_noreturn power_shutdown();
|
||||||
|
|
||||||
#endif //NEW_KERNEL_POWER_H
|
#endif //NEW_KERNEL_POWER_H
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
//
|
//
|
||||||
// Created by rick on 23-02-21.
|
// Created by rick on 23-02-21.
|
||||||
//
|
//
|
||||||
#include <stdio.h>
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <readline/readline.h>
|
||||||
|
|
||||||
#include <myke/command.h>
|
#include <myke/command.h>
|
||||||
#include <myke/libk/libk.h>
|
|
||||||
#include <myke/mem/mem.h>
|
|
||||||
#include <myke/mem/malloc.h>
|
|
||||||
#include <myke/cpu/timer.h>
|
#include <myke/cpu/timer.h>
|
||||||
#include <myke/drivers/pci/pci.h>
|
|
||||||
#include <myke/drivers/pci/ide.h>
|
#include <myke/drivers/pci/ide.h>
|
||||||
|
#include <myke/drivers/pci/pci.h>
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
#include <myke/fs/mbr.h>
|
#include <myke/fs/mbr.h>
|
||||||
#include <readline/readline.h>
|
#include <myke/libk/libk.h>
|
||||||
#include <myke/attributes.h>
|
#include <myke/mem/malloc.h>
|
||||||
|
#include <myke/mem/mem.h>
|
||||||
#include <myke/util/power.h>
|
#include <myke/util/power.h>
|
||||||
|
|
||||||
#ifdef ENABLE_SELF_TEST
|
#ifdef ENABLE_SELF_TEST
|
||||||
@@ -172,7 +172,7 @@ void store_bootloader_info(multiboot_info_t *multiboot_info) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn main_loop(void *data) {
|
void att_noreturn main_loop(void *data) {
|
||||||
while (true) {
|
while (true) {
|
||||||
char *msg = readline(NULL);
|
char *msg = readline(NULL);
|
||||||
char *args = strchr(msg, ' ');
|
char *args = strchr(msg, ' ');
|
||||||
|
|||||||
18
kernel/cpu/gdt.S
Normal file
18
kernel/cpu/gdt.S
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.code32
|
||||||
|
.extern gdt_ptr
|
||||||
|
|
||||||
|
.global _gdt_switch
|
||||||
|
_gdt_switch:
|
||||||
|
lgdt gdt_ptr
|
||||||
|
movw $0x10,%ax
|
||||||
|
movw %ax,%ds
|
||||||
|
movw %ax,%es
|
||||||
|
movw %ax,%fs
|
||||||
|
movw %ax,%gs
|
||||||
|
ljmp $0x8, $_gdt_switch_continue
|
||||||
|
_gdt_switch_continue:
|
||||||
|
movw $0x2a, %ax // 0x28 + 0x03 = 0x2a
|
||||||
|
ltr %ax
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
192
kernel/cpu/gdt.c
Normal file
192
kernel/cpu/gdt.c
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
//
|
||||||
|
// Created by rick on 19-03-21.
|
||||||
|
//
|
||||||
|
#include <attributes.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <myke/libk/libk.h>
|
||||||
|
#include <myke/cpu/gdt.h>
|
||||||
|
|
||||||
|
typedef struct gdt {
|
||||||
|
uint32_t base;
|
||||||
|
uint32_t limit;
|
||||||
|
union {
|
||||||
|
uint8_t access_byte;
|
||||||
|
struct {
|
||||||
|
bool accessed: 1;
|
||||||
|
bool read_write: 1; // for executable, if reading is allowed. For Non-exec if writing is allowed
|
||||||
|
// data sector: direction
|
||||||
|
// grows up(false) or down(true).
|
||||||
|
// executable sector: conforming
|
||||||
|
// if true higher privilege levels can execute this code (e.g. ring 3 can exec ring 0 code) the privilege level it self is not changed.
|
||||||
|
// if false, only the specified ring can execute the code
|
||||||
|
bool direction_conforming: 1;
|
||||||
|
bool executable: 1;
|
||||||
|
bool is_sector: 1;
|
||||||
|
uint8_t privilege: 2;
|
||||||
|
bool present: 1;
|
||||||
|
} att_packed;
|
||||||
|
};
|
||||||
|
union {
|
||||||
|
uint8_t flags_byte: 4;
|
||||||
|
struct {
|
||||||
|
uint8_t unused: 2;
|
||||||
|
bool size: 1; // false 16bit, true 32bit
|
||||||
|
bool granularity: 1; // false 1 byte, true 4KiB
|
||||||
|
} att_packed;
|
||||||
|
};
|
||||||
|
} gdt_t;
|
||||||
|
|
||||||
|
struct tss_ring {
|
||||||
|
uint32_t esp;
|
||||||
|
uint16_t ss;
|
||||||
|
uint16_t: 16; // skipped
|
||||||
|
} att_packed;
|
||||||
|
|
||||||
|
typedef struct tss {
|
||||||
|
uint16_t link;
|
||||||
|
uint16_t: 16; // skipped
|
||||||
|
struct tss_ring r0;
|
||||||
|
struct tss_ring r1;
|
||||||
|
struct tss_ring r2;
|
||||||
|
struct {
|
||||||
|
uint32_t cr3;
|
||||||
|
uint32_t eip;
|
||||||
|
uint32_t eflags;
|
||||||
|
uint32_t eax;
|
||||||
|
uint32_t ecx;
|
||||||
|
uint32_t edx;
|
||||||
|
uint32_t ebx;
|
||||||
|
uint32_t esp;
|
||||||
|
uint32_t ebp;
|
||||||
|
uint32_t esi;
|
||||||
|
uint32_t edi;
|
||||||
|
uint16_t es;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t cs;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t ss;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t ds;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t fs;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t gs;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t ldtr;
|
||||||
|
uint16_t: 16;
|
||||||
|
} att_packed regs;
|
||||||
|
uint16_t: 16;
|
||||||
|
uint16_t iopb_offset;
|
||||||
|
} att_packed tss_t;
|
||||||
|
_Static_assert(sizeof(tss_t) == 104, "TSS incorrect size");
|
||||||
|
|
||||||
|
typedef struct gdtr {
|
||||||
|
uint16_t size;
|
||||||
|
uint32_t offset;
|
||||||
|
} att_packed gdtr_t;
|
||||||
|
|
||||||
|
#define num_gdts 5
|
||||||
|
|
||||||
|
extern void _gdt_switch();
|
||||||
|
|
||||||
|
tss_t tss = {
|
||||||
|
.iopb_offset = sizeof(tss_t),
|
||||||
|
.r0.ss = 0x10,
|
||||||
|
};
|
||||||
|
|
||||||
|
gdt_t gdts[num_gdts] = {
|
||||||
|
{ // 0x08 kernel code
|
||||||
|
.present = true,
|
||||||
|
.base = 0,
|
||||||
|
.limit = 0xFFFFFFFF,
|
||||||
|
.is_sector = true,
|
||||||
|
.size = true,
|
||||||
|
.granularity = true,
|
||||||
|
.executable = true,
|
||||||
|
.read_write = true,
|
||||||
|
.privilege = 0,
|
||||||
|
}, { // 0x10 kernel data
|
||||||
|
.present = true,
|
||||||
|
.base = 0,
|
||||||
|
.limit = 0xFFFFFFFF,
|
||||||
|
.is_sector = true,
|
||||||
|
.size = true,
|
||||||
|
.granularity = true,
|
||||||
|
.executable = false,
|
||||||
|
.read_write = true,
|
||||||
|
}, { // 0x18 user code
|
||||||
|
.present = true,
|
||||||
|
.base = 0,
|
||||||
|
.limit = 0xFFFFFFFF,
|
||||||
|
.privilege = 3,
|
||||||
|
.is_sector = true,
|
||||||
|
.size = true,
|
||||||
|
.granularity = true,
|
||||||
|
.executable = true,
|
||||||
|
.read_write = true,
|
||||||
|
}, { // 0x20 user data
|
||||||
|
.present = true,
|
||||||
|
.base = 0,
|
||||||
|
.limit = 0xFFFFFFFF,
|
||||||
|
.privilege = 3,
|
||||||
|
.is_sector = true,
|
||||||
|
.size = true,
|
||||||
|
.granularity = true,
|
||||||
|
.executable = true,
|
||||||
|
.read_write = true,
|
||||||
|
}, { // 0x28 tss
|
||||||
|
.base = (uint32_t) &tss,
|
||||||
|
.limit = sizeof(tss_t),
|
||||||
|
.present = true,
|
||||||
|
.executable = true,
|
||||||
|
.accessed = true,
|
||||||
|
.size = true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
uint64_t gdt_values[num_gdts + 1] = {0};
|
||||||
|
gdtr_t gdt_ptr = {
|
||||||
|
.size = sizeof(uint64_t) * (num_gdts + 1) - 1,
|
||||||
|
.offset = (uint32_t) &gdt_values,
|
||||||
|
};
|
||||||
|
_Static_assert(sizeof(gdt_ptr) == 6, "GDT PTR incorrect size");
|
||||||
|
|
||||||
|
uint64_t gdt_encode(gdt_t *gdt) {
|
||||||
|
// high limit must be full 4k
|
||||||
|
uint64_t limit = gdt->limit;
|
||||||
|
if (limit > 65536 && (limit & 0xFFF) != 0xFFF && !gdt->granularity) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
limit >>= 12;
|
||||||
|
}
|
||||||
|
uint64_t value = 0
|
||||||
|
| (limit & 0xFFFF)
|
||||||
|
| ((gdt->base & 0xFFFF) << 16)
|
||||||
|
| ((uint64_t) ((gdt->base >> 16) & 0xFF) << 32)
|
||||||
|
| ((uint64_t) (gdt->access_byte) << 40)
|
||||||
|
| ((limit >> 16) << 48)
|
||||||
|
| ((uint64_t) (gdt->flags_byte) << 52)
|
||||||
|
| ((uint64_t) (gdt->base >> 24) << 56);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdt_activate() {
|
||||||
|
gdt_values[0] = 0; // first is zero
|
||||||
|
for (int i = 0; i < num_gdts; ++i) {
|
||||||
|
gdt_values[i + 1] = gdt_encode(&gdts[i]);
|
||||||
|
if (gdt_values[i + 1] == 0) {
|
||||||
|
// todo failed to encode
|
||||||
|
k_panics("Failed to encode GDT\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_gdt_switch();
|
||||||
|
}
|
||||||
|
|
||||||
|
void gdt_init() {
|
||||||
|
// Replace the early gdt with a new one
|
||||||
|
// this one will be extensible and support stuff like TSS
|
||||||
|
|
||||||
|
tss.r0.esp = 0; // todo
|
||||||
|
|
||||||
|
gdt_activate();
|
||||||
|
}
|
||||||
@@ -4,11 +4,12 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <elf.h>
|
||||||
|
|
||||||
#define DEBUG_INIT
|
#define DEBUG_INIT
|
||||||
|
|
||||||
#include <myke/debug/debug.h>
|
#include <myke/debug/debug.h>
|
||||||
#include <elf.h>
|
|
||||||
#include <myke/libk/libk.h>
|
#include <myke/libk/libk.h>
|
||||||
#include <myke/libk/kprint.h>
|
#include <myke/libk/kprint.h>
|
||||||
|
|
||||||
@@ -73,7 +74,8 @@ void debug_store_info(struct multiboot_info *info) {
|
|||||||
if (sizeof(struct elf32_section_header) != info->u.elf_sec.size) {
|
if (sizeof(struct elf32_section_header) != info->u.elf_sec.size) {
|
||||||
k_panics("ELF size not correct");
|
k_panics("ELF size not correct");
|
||||||
}
|
}
|
||||||
elf_headers = (struct elf32_section_header *) info->u.elf_sec.addr;
|
elf_headers = calloc(info->u.elf_sec.num, sizeof(struct elf32_section_header));
|
||||||
|
memcpy(elf_headers, (const void *) info->u.elf_sec.addr, sizeof(struct elf32_section_header) * info->u.elf_sec.num);
|
||||||
elf_header_cnt = info->u.elf_sec.num;
|
elf_header_cnt = info->u.elf_sec.num;
|
||||||
debug_find_sections(info->u.elf_sec.shndx);
|
debug_find_sections(info->u.elf_sec.shndx);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,20 @@
|
|||||||
//
|
//
|
||||||
// https://wiki.osdev.org/PCI_IDE_Controller
|
// https://wiki.osdev.org/PCI_IDE_Controller
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <myke/drivers/pci/ide.h>
|
|
||||||
#include <myke/debug/debug.h>
|
|
||||||
#include <myke/drivers/ports.h>
|
|
||||||
#include <myke/libk/kprint.h>
|
|
||||||
#include <myke/drivers/pci/pci.h>
|
|
||||||
#include <myke/libk/libk.h>
|
|
||||||
#include <myke/cpu/timer.h>
|
#include <myke/cpu/timer.h>
|
||||||
|
#include <myke/debug/debug.h>
|
||||||
|
#include <myke/drivers/pci/ide.h>
|
||||||
|
#include <myke/drivers/pci/pci.h>
|
||||||
|
#include <myke/drivers/ports.h>
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
|
#include <myke/libk/kprint.h>
|
||||||
|
#include <myke/libk/libk.h>
|
||||||
#include <myke/tasks/locking.h>
|
#include <myke/tasks/locking.h>
|
||||||
|
|
||||||
#define ATA_SR_BSY 0x80 // Busy
|
#define ATA_SR_BSY 0x80 // Busy
|
||||||
@@ -414,7 +415,7 @@ void ide_register_block_devices() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t used ide_pci_validate(const pci_device *device) {
|
uint8_t att_used ide_pci_validate(const pci_device *device) {
|
||||||
if (device->class != PCI_CLASS_MASS_STORAGE
|
if (device->class != PCI_CLASS_MASS_STORAGE
|
||||||
|| device->subclass != PCI_SUB_CLASS_IDE
|
|| device->subclass != PCI_SUB_CLASS_IDE
|
||||||
|| (device->programInterface != 0x8A && device->programInterface != 0x80)) {
|
|| (device->programInterface != 0x8A && device->programInterface != 0x80)) {
|
||||||
@@ -424,7 +425,7 @@ uint8_t used ide_pci_validate(const pci_device *device) {
|
|||||||
return PCI_VALIDATE_OK;
|
return PCI_VALIDATE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t used ide_pci_initialize(pci_device *device) {
|
uint8_t att_used ide_pci_initialize(pci_device *device) {
|
||||||
|
|
||||||
if (!ide_pci_init_channels(device)) {
|
if (!ide_pci_init_channels(device)) {
|
||||||
return PCI_INIT_FAIL;
|
return PCI_INIT_FAIL;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
//
|
//
|
||||||
// https://wiki.osdev.org/PCI
|
// https://wiki.osdev.org/PCI
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <attributes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/drivers/pci/pci.h>
|
#include <myke/drivers/pci/pci.h>
|
||||||
#include <myke/drivers/ports.h>
|
#include <myke/drivers/ports.h>
|
||||||
@@ -44,7 +45,7 @@ pci_device pci_devices[MAX_PCI_DEVICES];
|
|||||||
|
|
||||||
void pci_check_bus(uint8_t bus);
|
void pci_check_bus(uint8_t bus);
|
||||||
|
|
||||||
uint8_t used pci_secondary_bus_use(const pci_device *device) {
|
uint8_t att_used pci_secondary_bus_use(const pci_device *device) {
|
||||||
uint8_t secondary_bus = pci_config_read_byte(device->bus, device->slot, device->func,
|
uint8_t secondary_bus = pci_config_read_byte(device->bus, device->slot, device->func,
|
||||||
PCI_CONFIG_SECONDARY_BUS_NUMBER);
|
PCI_CONFIG_SECONDARY_BUS_NUMBER);
|
||||||
pci_check_bus(secondary_bus);
|
pci_check_bus(secondary_bus);
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
// Created by rick on 06-02-21.
|
// Created by rick on 06-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include <myke/libk/libk.h>
|
|
||||||
#include <myke/tasks/task.h>
|
|
||||||
#include <myke/tasks/locking.h>
|
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
|
#include <myke/libk/libk.h>
|
||||||
|
#include <myke/tasks/locking.h>
|
||||||
|
#include <myke/tasks/task.h>
|
||||||
|
|
||||||
#define MAX_BLOCK_DEVS 64
|
#define MAX_BLOCK_DEVS 64
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ void block_dev_scan() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn block_dev_task(void *data) {
|
void att_noreturn block_dev_task(void *data) {
|
||||||
while (true) {
|
while (true) {
|
||||||
semaphore_wait(block_semaphore);
|
semaphore_wait(block_semaphore);
|
||||||
block_dev_scan();
|
block_dev_scan();
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
// Created by rick on 07-02-21.
|
// Created by rick on 07-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <myke/attributes.h>
|
|
||||||
|
|
||||||
#define FAT_TYPE_12 1
|
#define FAT_TYPE_12 1
|
||||||
#define FAT_TYPE_16 2
|
#define FAT_TYPE_16 2
|
||||||
@@ -31,7 +31,7 @@ typedef struct {
|
|||||||
uint16_t heads_sides;
|
uint16_t heads_sides;
|
||||||
uint32_t hidden_sectors;
|
uint32_t hidden_sectors;
|
||||||
uint32_t large_total_sectors;
|
uint32_t large_total_sectors;
|
||||||
} packed bpb;
|
} att_packed bpb;
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint8_t drive_number;
|
uint8_t drive_number;
|
||||||
@@ -40,7 +40,7 @@ typedef struct {
|
|||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
uint8_t label[11];
|
uint8_t label[11];
|
||||||
uint8_t system_id[8];
|
uint8_t system_id[8];
|
||||||
} packed ebr_12_16;
|
} att_packed ebr_12_16;
|
||||||
struct {
|
struct {
|
||||||
uint32_t sectors_per_fat;
|
uint32_t sectors_per_fat;
|
||||||
uint16_t flags;
|
uint16_t flags;
|
||||||
@@ -55,21 +55,21 @@ typedef struct {
|
|||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
uint8_t label[11];
|
uint8_t label[11];
|
||||||
uint8_t system_id[8];
|
uint8_t system_id[8];
|
||||||
} packed ebr_32;
|
} att_packed ebr_32;
|
||||||
};
|
};
|
||||||
} packed fat_bpb;
|
} att_packed fat_bpb;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t hours: 5;
|
uint8_t hours: 5;
|
||||||
uint8_t minutes: 6;
|
uint8_t minutes: 6;
|
||||||
uint8_t seconds: 5;
|
uint8_t seconds: 5;
|
||||||
} packed time_83;
|
} att_packed time_83;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t hours: 5;
|
uint8_t hours: 5;
|
||||||
uint8_t minutes: 6;
|
uint8_t minutes: 6;
|
||||||
uint8_t seconds: 5;
|
uint8_t seconds: 5;
|
||||||
} packed date_83;
|
} att_packed date_83;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
@@ -86,7 +86,7 @@ typedef struct {
|
|||||||
date_83 last_mod_date;
|
date_83 last_mod_date;
|
||||||
uint16_t low_first_cluster;
|
uint16_t low_first_cluster;
|
||||||
uint32_t file_size;
|
uint32_t file_size;
|
||||||
} packed name_83;
|
} att_packed name_83;
|
||||||
struct {
|
struct {
|
||||||
uint8_t order;
|
uint8_t order;
|
||||||
uint16_t text_1[5];
|
uint16_t text_1[5];
|
||||||
@@ -96,9 +96,9 @@ typedef struct {
|
|||||||
uint16_t text_2[6];
|
uint16_t text_2[6];
|
||||||
uint16_t reserved;
|
uint16_t reserved;
|
||||||
uint16_t text_3[2];
|
uint16_t text_3[2];
|
||||||
} packed long_name;
|
} att_packed long_name;
|
||||||
};
|
};
|
||||||
} packed fat_directory_entry;
|
} att_packed fat_directory_entry;
|
||||||
|
|
||||||
void print_chars(char *chars, int amount) {
|
void print_chars(char *chars, int amount) {
|
||||||
for (int i = 0; i < amount; ++i) {
|
for (int i = 0; i < amount; ++i) {
|
||||||
@@ -107,7 +107,7 @@ void print_chars(char *chars, int amount) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t used fat_check_device(const block_device_t *device, uint8_t *first_sector) {
|
uint8_t att_used fat_check_device(const block_device_t *device, uint8_t *first_sector) {
|
||||||
fat_bpb bpb;
|
fat_bpb bpb;
|
||||||
memcpy((uint8_t *) &bpb, first_sector, sizeof(fat_bpb));
|
memcpy((uint8_t *) &bpb, first_sector, sizeof(fat_bpb));
|
||||||
if (bpb.bpb.sectors_per_fat == 0 || bpb.bpb.sectors_per_cluster == 0) {
|
if (bpb.bpb.sectors_per_fat == 0 || bpb.bpb.sectors_per_cluster == 0) {
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
// Created by rick on 06-02-21.
|
// Created by rick on 06-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/fs/mbr.h>
|
|
||||||
#include <myke/drivers/pci/ide.h>
|
#include <myke/drivers/pci/ide.h>
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
#include <myke/attributes.h>
|
#include <myke/fs/mbr.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t bootable;
|
uint8_t bootable;
|
||||||
@@ -23,14 +23,14 @@ typedef struct {
|
|||||||
uint16_t ending_cylinder: 10;
|
uint16_t ending_cylinder: 10;
|
||||||
uint32_t start_lba;
|
uint32_t start_lba;
|
||||||
uint32_t num_lbas;
|
uint32_t num_lbas;
|
||||||
} packed mbr_partition_table_entry;
|
} att_packed mbr_partition_table_entry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t unique_id;
|
uint32_t unique_id;
|
||||||
uint16_t reserved;
|
uint16_t reserved;
|
||||||
mbr_partition_table_entry entries[4];
|
mbr_partition_table_entry entries[4];
|
||||||
uint8_t signature[2];
|
uint8_t signature[2];
|
||||||
} packed mbr_table;
|
} att_packed mbr_table;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const block_device_t *device;
|
const block_device_t *device;
|
||||||
@@ -52,7 +52,7 @@ mbr_block_dev_access(const block_device_t *device, uint8_t direction, uint32_t l
|
|||||||
return info->device->access(info->device, direction, actual_lba, sectors, target);
|
return info->device->access(info->device, direction, actual_lba, sectors, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t used mbr_check_device(const block_device_t *device, uint8_t *first_sector) {
|
uint8_t att_used mbr_check_device(const block_device_t *device, uint8_t *first_sector) {
|
||||||
mbr_table table;
|
mbr_table table;
|
||||||
memcpy((uint8_t *) &table, first_sector + (device->block_size - sizeof(mbr_table)), sizeof(mbr_table));
|
memcpy((uint8_t *) &table, first_sector + (device->block_size - sizeof(mbr_table)), sizeof(mbr_table));
|
||||||
if (table.signature[0] != 0x55 && table.signature[1] != 0xAA) { // AA 55 but in little endian
|
if (table.signature[0] != 0x55 && table.signature[1] != 0xAA) { // AA 55 but in little endian
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
//
|
//
|
||||||
// Created by rick on 11-03-21.
|
// Created by rick on 11-03-21.
|
||||||
//
|
//
|
||||||
|
#include <attributes.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/fs/blockdev.h>
|
#include <myke/fs/blockdev.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char filename[100];
|
char filename[100];
|
||||||
@@ -25,7 +26,7 @@ typedef struct {
|
|||||||
uint64_t device_major;
|
uint64_t device_major;
|
||||||
uint64_t device_minor;
|
uint64_t device_minor;
|
||||||
char prefix[155];
|
char prefix[155];
|
||||||
} packed ustar_sector;
|
} att_packed ustar_sector;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
ustar_sector sector;
|
ustar_sector sector;
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#include <stdio.h>
|
#include <attributes.h>
|
||||||
#include <multiboot.h>
|
#include <multiboot.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#define DEBUG_INIT
|
#define DEBUG_INIT
|
||||||
|
|
||||||
|
#include <myke/command.h>
|
||||||
#include <myke/cpu/cpuidx.h>
|
#include <myke/cpu/cpuidx.h>
|
||||||
|
#include <myke/cpu/gdt.h>
|
||||||
#include <myke/cpu/isr.h>
|
#include <myke/cpu/isr.h>
|
||||||
#include <myke/cpu/timer.h>
|
#include <myke/cpu/timer.h>
|
||||||
#include <myke/debug/debug.h>
|
#include <myke/debug/debug.h>
|
||||||
@@ -17,8 +20,6 @@
|
|||||||
#include <myke/libk/syscall.h>
|
#include <myke/libk/syscall.h>
|
||||||
#include <myke/mem/mem.h>
|
#include <myke/mem/mem.h>
|
||||||
#include <myke/tasks/task.h>
|
#include <myke/tasks/task.h>
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/command.h>
|
|
||||||
|
|
||||||
const int version_major = 0,
|
const int version_major = 0,
|
||||||
version_minor = 0,
|
version_minor = 0,
|
||||||
@@ -38,7 +39,7 @@ void init_pci_system() {
|
|||||||
pci_init_drivers();
|
pci_init_drivers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn used kmain(multiboot_info_t *multiboot_info, uint32_t mb_name) {
|
void att_noreturn att_used kmain(multiboot_info_t *multiboot_info, uint32_t mb_name) {
|
||||||
// early init
|
// early init
|
||||||
isr_install();
|
isr_install();
|
||||||
vga_clear_screen();
|
vga_clear_screen();
|
||||||
@@ -57,6 +58,8 @@ void noreturn used kmain(multiboot_info_t *multiboot_info, uint32_t mb_name) {
|
|||||||
// initialize memory management
|
// initialize memory management
|
||||||
init_mmap(multiboot_info);
|
init_mmap(multiboot_info);
|
||||||
|
|
||||||
|
gdt_init();
|
||||||
|
|
||||||
// initialize kprint functionality
|
// initialize kprint functionality
|
||||||
kprint_init();
|
kprint_init();
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
// Created by rick on 28-01-21.
|
// Created by rick on 28-01-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <string.h>
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <myke/util/stream.h>
|
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/tasks/task.h>
|
|
||||||
#include <myke/libk/kprint.h>
|
#include <myke/libk/kprint.h>
|
||||||
|
#include <myke/tasks/task.h>
|
||||||
|
#include <myke/util/stream.h>
|
||||||
|
|
||||||
#define MAX_HANDLERS 8
|
#define MAX_HANDLERS 8
|
||||||
#define STREAM_SIZE (32*1024)
|
#define STREAM_SIZE (32*1024)
|
||||||
@@ -49,7 +49,7 @@ void kprint_init() {
|
|||||||
kprint_stream = stream_create(STREAM_SIZE);
|
kprint_stream = stream_create(STREAM_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn kprint_task(void *_) {
|
void att_noreturn kprint_task(void *_) {
|
||||||
uint32_t last_read = 0;
|
uint32_t last_read = 0;
|
||||||
uint8_t data[PRINT_BUFFER_SIZE + 1] = {0};
|
uint8_t data[PRINT_BUFFER_SIZE + 1] = {0};
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
// Created by rick on 02-02-21.
|
// Created by rick on 02-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
|
|
||||||
#include <myke/libk/kprint.h>
|
#include <myke/libk/kprint.h>
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/libk/libk.h>
|
#include <myke/libk/libk.h>
|
||||||
|
|
||||||
bool k_addr_in_kspace(void *addr) {
|
bool k_addr_in_kspace(void *addr) {
|
||||||
@@ -14,13 +15,13 @@ void k_wait_for_interrupt() {
|
|||||||
__asm__ __volatile__("hlt;");
|
__asm__ __volatile__("hlt;");
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn k_panics(const char *msg) {
|
void att_noreturn k_panics(const char *msg) {
|
||||||
// todo this is not printed
|
// todo this is not printed
|
||||||
kprint_sync(msg);
|
kprint_sync(msg);
|
||||||
k_panic();
|
k_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn k_panic() {
|
void att_noreturn k_panic() {
|
||||||
kprint_sync("PANIC!");
|
kprint_sync("PANIC!");
|
||||||
while (1) {
|
while (1) {
|
||||||
__asm__ __volatile__("cli;"
|
__asm__ __volatile__("cli;"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
// Created by rick on 22-02-21.
|
// Created by rick on 22-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/libk/syscall.h>
|
#include <myke/libk/syscall.h>
|
||||||
#include <myke/attributes.h>
|
|
||||||
|
|
||||||
void syscall1(uint32_t arg1) {
|
void syscall1(uint32_t arg1) {
|
||||||
__asm__("int $0x80"
|
__asm__("int $0x80"
|
||||||
@@ -19,7 +19,7 @@ void syscall2(uint32_t arg1, uint32_t arg2) {
|
|||||||
: "a"(arg1), "b"(arg2));
|
: "a"(arg1), "b"(arg2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn syscall_start_scheduler() {
|
void att_noreturn syscall_start_scheduler() {
|
||||||
syscall1(SYSCALL_START_SCHEDULER);
|
syscall1(SYSCALL_START_SCHEDULER);
|
||||||
while (1) { __asm__("hlt"); };
|
while (1) { __asm__("hlt"); };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
// Created by rick on 22-04-20.
|
// Created by rick on 22-04-20.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/mem/pmm.h>
|
|
||||||
#include <myke/mem/mem.h>
|
|
||||||
#include <myke/libk/libk.h>
|
#include <myke/libk/libk.h>
|
||||||
#include <myke/attributes.h>
|
#include <myke/mem/mem.h>
|
||||||
|
#include <myke/mem/pmm.h>
|
||||||
|
|
||||||
#define MEMMAP_ENTRIES 16
|
#define MEMMAP_ENTRIES 16
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ typedef struct {
|
|||||||
uint32_t address;
|
uint32_t address;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
} packed mmap_entry;
|
} att_packed mmap_entry;
|
||||||
|
|
||||||
int last_memmap_entry = 0;
|
int last_memmap_entry = 0;
|
||||||
mmap_entry memmap[MEMMAP_ENTRIES] = {
|
mmap_entry memmap[MEMMAP_ENTRIES] = {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
// Created by rick on 21-02-21.
|
// Created by rick on 21-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <myke/mem/paging.h>
|
#include <myke/mem/paging.h>
|
||||||
#include <myke/attributes.h>
|
|
||||||
|
|
||||||
#define TABLE_ADDR_MASK 0xFFFFF000
|
#define TABLE_ADDR_MASK 0xFFFFF000
|
||||||
#define DIRECTORY_SIZE 1024
|
#define DIRECTORY_SIZE 1024
|
||||||
@@ -25,10 +25,10 @@ typedef struct {
|
|||||||
bool page_size: 1;
|
bool page_size: 1;
|
||||||
bool global: 1; // ignored
|
bool global: 1; // ignored
|
||||||
uint8_t avail: 3;
|
uint8_t avail: 3;
|
||||||
} packed;
|
} att_packed;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
};
|
};
|
||||||
} packed page_directory_entry;
|
} att_packed page_directory_entry;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
union {
|
union {
|
||||||
@@ -43,12 +43,12 @@ typedef struct {
|
|||||||
char ignored: 1;
|
char ignored: 1;
|
||||||
bool global: 1;
|
bool global: 1;
|
||||||
uint8_t available: 3;
|
uint8_t available: 3;
|
||||||
} packed;
|
} att_packed;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
};
|
};
|
||||||
} packed page_table_entry;
|
} att_packed page_table_entry;
|
||||||
|
|
||||||
page_directory_entry page_directory[DIRECTORY_SIZE] at_aligned(4096);
|
page_directory_entry page_directory[DIRECTORY_SIZE] att_aligned(4096);
|
||||||
|
|
||||||
void page_pre_init() {
|
void page_pre_init() {
|
||||||
for (int i = 0; i < DIRECTORY_SIZE; ++i) {
|
for (int i = 0; i < DIRECTORY_SIZE; ++i) {
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
// Created by rick on 22-02-21.
|
// Created by rick on 22-02-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <attributes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <myke/tasks/task.h>
|
|
||||||
#include <myke/cpu/cpu.h>
|
#include <myke/cpu/cpu.h>
|
||||||
#include <myke/mem/pmm.h>
|
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/libk/libk.h>
|
#include <myke/libk/libk.h>
|
||||||
|
#include <myke/mem/pmm.h>
|
||||||
|
#include <myke/tasks/task.h>
|
||||||
|
|
||||||
#define stack_end(task) ((task)->stack + ((task)->stack_page_count * PAGE_SIZE))
|
#define stack_end(task) ((task)->stack + ((task)->stack_page_count * PAGE_SIZE))
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ typedef struct {
|
|||||||
task_entrypoint entrypoint;
|
task_entrypoint entrypoint;
|
||||||
void *entry_data;
|
void *entry_data;
|
||||||
char alignment[4];
|
char alignment[4];
|
||||||
} packed task_stack_start;
|
} att_packed task_stack_start;
|
||||||
|
|
||||||
volatile uint32_t task_locked = 0;
|
volatile uint32_t task_locked = 0;
|
||||||
|
|
||||||
@@ -62,12 +62,12 @@ uint32_t last_tid = 0;
|
|||||||
extern switch_task(task_registers_t
|
extern switch_task(task_registers_t
|
||||||
**, task_registers_t*);
|
**, task_registers_t*);
|
||||||
|
|
||||||
extern cdecl noreturn void __task_entry_point();
|
extern att_cdecl att_noreturn void __task_entry_point();
|
||||||
|
|
||||||
extern noreturn void __task_entry_point_inner();
|
extern att_noreturn void __task_entry_point_inner();
|
||||||
|
|
||||||
// explicit cdecl calling convention
|
// explicit cdecl calling convention
|
||||||
void cdecl noreturn task_entry_point(task_entrypoint entrypoint, void *entry_data) {
|
void att_cdecl att_noreturn task_entry_point(task_entrypoint entrypoint, void *entry_data) {
|
||||||
entrypoint(entry_data);
|
entrypoint(entry_data);
|
||||||
// task_end_self();
|
// task_end_self();
|
||||||
while (true); // halt
|
while (true); // halt
|
||||||
@@ -114,7 +114,7 @@ void task_suspend() {
|
|||||||
task_switch_next();
|
task_switch_next();
|
||||||
}
|
}
|
||||||
|
|
||||||
void noreturn task_idle(void *data) {
|
void att_noreturn task_idle(void *data) {
|
||||||
while (true) __asm__("hlt");
|
while (true) __asm__("hlt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
// Created by rick on 03-03-21.
|
// Created by rick on 03-03-21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
|
|
||||||
#include <myke/drivers/ports.h>
|
#include <myke/drivers/ports.h>
|
||||||
#include <myke/attributes.h>
|
|
||||||
#include <myke/libk/libk.h>
|
#include <myke/libk/libk.h>
|
||||||
#include <myke/util/power.h>
|
#include <myke/util/power.h>
|
||||||
|
|
||||||
void noreturn power_shutdown() {
|
void att_noreturn power_shutdown() {
|
||||||
port_word_out(PORT_ACPI, PORT_ACPI_SHUTDOWN);
|
port_word_out(PORT_ACPI, PORT_ACPI_SHUTDOWN);
|
||||||
port_word_out(PORT_QEMU_COMMAND, PORT_QEMU_COMMAND_SHUTDOWN);
|
port_word_out(PORT_QEMU_COMMAND, PORT_QEMU_COMMAND_SHUTDOWN);
|
||||||
port_word_out(PORT_VBOX, PORT_VBOX_SHUTDOWN);
|
port_word_out(PORT_VBOX, PORT_VBOX_SHUTDOWN);
|
||||||
|
|||||||
Reference in New Issue
Block a user