diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/acpi.h | 143 | ||||
-rw-r--r-- | include/gdt.h | 10 | ||||
-rw-r--r-- | include/idt.h | 17 | ||||
-rw-r--r-- | include/mem.h | 11 | ||||
-rw-r--r-- | include/memory.h | 13 | ||||
-rw-r--r-- | include/multiboot.h | 173 | ||||
-rw-r--r-- | include/nrvn.h | 22 | ||||
-rw-r--r-- | include/pic.h | 9 | ||||
-rw-r--r-- | include/ps2.h | 9 | ||||
-rw-r--r-- | include/vga.h | 38 |
10 files changed, 445 insertions, 0 deletions
diff --git a/include/acpi.h b/include/acpi.h new file mode 100644 index 0000000..1c68ef4 --- /dev/null +++ b/include/acpi.h @@ -0,0 +1,143 @@ +#ifndef _ACPI_H_ +#define _ACPI_H_ + +#include <stdint.h> +#include <stddef.h> + +struct rsdp { + char signature[8]; + uint8_t checksum; + char oemid[6]; + uint8_t revision; + uint32_t rsdt_address; +} __attribute__((packed)); + +struct xsdp { + char signature[8]; + uint8_t checksum; + char oemid[6]; + uint8_t revision; + uint32_t rsdt_address; // deprecated since version 2.0 + + uint32_t length; + uint64_t xsdt_address; + uint8_t extended_checksum; + uint8_t reserved[3]; +} __attribute__((packed)); + +struct acpi_sdt_header { + char signature[4]; + uint32_t len; + uint8_t rev; + uint8_t checksum; + char oemid[6]; + char oem_tableid[8]; + uint32_t oem_revision; + uint32_t creatorid; + uint32_t creator_rev; +} __attribute__((packed)); + +struct rsdt { + struct acpi_sdt_header header; + uint32_t sdt_pointers[]; +} __attribute__((packed)); + +struct xsdt { + struct acpi_sdt_header header; + uint64_t sdt_pointers[]; +} __attribute__((packed)); + +struct generic_address { + uint8_t address_space; + uint8_t bid_width; + uint8_t bit_offset; + uint8_t access_size; + uint64_t address; +} __attribute__((packed)); + +struct fadt { + struct acpi_sdt_header header; + uint32_t firmware_ctrl; + uint32_t dsdt; + + uint8_t reserved; + + uint8_t prevered_power_management_profile; + uint16_t sci_interrupt; + uint32_t smi_command_port; + uint8_t acpi_enable; + uint8_t acpi_disable; + uint8_t s4_bios_req; + uint8_t pstate_control; + + uint32_t pm1a_event_block; + uint32_t pm1b_event_block; + + uint32_t pm1a_control_block; + uint32_t pm1b_control_block; + + uint32_t pm2_control_block; + + uint32_t pm_timer_block; + + uint32_t gpe0_block; + uint32_t gpe1_block; + + uint8_t pm1_event_length; + uint8_t pm1_control_length; + uint8_t pm2_control_length; + uint8_t pm_timer_length; + + uint8_t gpe0_length; + uint8_t gpe1_length; + uint8_t gpe1_base; + + uint8_t cstate_control; + + uint16_t worst_c2_latency; + uint16_t worst_c3_latency; + + uint16_t flush_size; + uint16_t flush_stride; + + uint8_t duty_offset; + uint8_t duty_width; + + uint8_t day_alarm; + uint8_t month_alarm; + uint8_t century; + + uint16_t boot_arch_flags; + + uint8_t reserved_2; + uint32_t flags; + + struct generic_address reset_reg; + + uint8_t reset_valued; + uint8_t reserved_3[3]; + + uint64_t x_firmware_control; + uint64_t x_dsdt; + + struct generic_address x_pm1a_event_block; + struct generic_address x_pm1b_event_block; + struct generic_address x_pm1a_control_block; + struct generic_address x_pm1b_control_block; + struct generic_address x_pm2_control_block; + struct generic_address x_pm_timer_block; + struct generic_address x_gpe0_block; + struct generic_address x_gpe1_block; +} __attribute__((packed)); + +struct xsdp *find_rsdp(); +struct fadt *find_facp(struct xsdt *root_sdt); +void print_rsdp(const struct rsdp *rsdp); + +static inline struct xsdt *get_rsdt(struct xsdp *rsdp) { + if (rsdp == NULL || rsdp->revision == 0) + return NULL; + return (struct xsdt *) rsdp->xsdt_address; +} + +#endif diff --git a/include/gdt.h b/include/gdt.h new file mode 100644 index 0000000..63ff08b --- /dev/null +++ b/include/gdt.h @@ -0,0 +1,10 @@ +#ifndef _GDT_H_ +#define _GDT_H_ + +#include <stdint.h> +#include <stddef.h> + +void gdt_set_gate(size_t num, uint64_t base, uint32_t limit, uint8_t access, uint8_t gran); +void gdt_install(); + +#endif diff --git a/include/idt.h b/include/idt.h new file mode 100644 index 0000000..587419b --- /dev/null +++ b/include/idt.h @@ -0,0 +1,17 @@ +#ifndef _IDT_H_ +#define _IDT_H_ + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +void idt_set_isr(uint8_t num, uint64_t offset, uint16_t sel, uint8_t flags); +void idt_init(); + +extern uint64_t isr_table[32]; + + +bool idt_register_isr(size_t num, void (*func)(uint64_t, uint64_t)); +bool idt_remove_isr(size_t num, void (*func)(uint64_t, uint64_t)); + +#endif diff --git a/include/mem.h b/include/mem.h new file mode 100644 index 0000000..ee68165 --- /dev/null +++ b/include/mem.h @@ -0,0 +1,11 @@ +#ifndef _MEM_H_ +#define _MEM_H_ + +#include <stddef.h> + +void *memcpy(void *restrict dest, const void *restrict src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); + +#endif diff --git a/include/memory.h b/include/memory.h new file mode 100644 index 0000000..b349e62 --- /dev/null +++ b/include/memory.h @@ -0,0 +1,13 @@ +#ifndef _PAGE_H_ +#define _PAGE_H_ + +#include <stddef.h> +#include <stdbool.h> + +void *kmalloc(size_t size); +void *kmalloc_a(size_t size, size_t alignment); +void kfree(void *ptr); +void print_blocks(); +bool paging_init(); + +#endif diff --git a/include/multiboot.h b/include/multiboot.h new file mode 100644 index 0000000..d2be87b --- /dev/null +++ b/include/multiboot.h @@ -0,0 +1,173 @@ +#ifndef _MULTIBOOT_H_ +#define _MULTIBOOT_H_ + +#include <stdint.h> + +struct multiboot_header +{ + uint32_t magic; + + uint32_t flags; + + /* The above fields plus this one must equal 0 mod 2^32. */ + uint32_t checksum; + + /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ + uint32_t header_addr; + uint32_t load_addr; + uint32_t load_end_addr; + uint32_t bss_end_addr; + uint32_t entry_addr; + + /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ + uint32_t mode_type; + uint32_t width; + uint32_t height; + uint32_t depth; +}; + +/* The symbol table for a.out. */ +struct multiboot_aout_symbol_table +{ + uint32_t tabsize; + uint32_t strsize; + uint32_t addr; + uint32_t reserved; +}; + +/* The section header table for ELF. */ +struct multiboot_elf_section_header_table +{ + uint32_t num; + uint32_t size; + uint32_t addr; + uint32_t shndx; +}; + +struct multiboot_info +{ + /* Multiboot info version number */ + uint32_t flags; + + /* Available memory from BIOS */ + uint32_t mem_lower; + uint32_t mem_upper; + + /* "root" partition */ + uint32_t boot_device; + + /* Kernel command line */ + uint32_t cmdline; + + /* Boot-Module list */ + uint32_t mods_count; + uint32_t mods_addr; + + union + { + struct multiboot_aout_symbol_table aout_sym; + struct multiboot_elf_section_header_table elf_sec; + } u; + + /* Memory Mapping buffer */ + uint32_t mmap_length; + uint32_t mmap_addr; + + /* Drive Info buffer */ + uint32_t drives_length; + uint32_t drives_addr; + + /* ROM configuration table */ + uint32_t config_table; + + /* Boot Loader Name */ + uint32_t boot_loader_name; + + /* APM table */ + uint32_t apm_table; + + /* Video */ + uint32_t vbe_control_info; + uint32_t vbe_mode_info; + uint16_t vbe_mode; + uint16_t vbe_interface_seg; + uint16_t vbe_interface_off; + uint16_t vbe_interface_len; + + uint64_t framebuffer_addr; + uint32_t framebuffer_pitch; + uint32_t framebuffer_width; + uint32_t framebuffer_height; + uint8_t framebuffer_bpp; +#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 +#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 +#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 + uint8_t framebuffer_type; + union + { + struct + { + uint32_t framebuffer_palette_addr; + uint16_t framebuffer_palette_num_colors; + }; + struct + { + uint8_t framebuffer_red_field_position; + uint8_t framebuffer_red_mask_size; + uint8_t framebuffer_green_field_position; + uint8_t framebuffer_green_mask_size; + uint8_t framebuffer_blue_field_position; + uint8_t framebuffer_blue_mask_size; + }; + }; +}; + +struct multiboot_color +{ + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct multiboot_mmap_entry +{ + uint32_t size; + uint64_t addr; + uint64_t len; +#define MULTIBOOT_MEMORY_AVAILABLE 1 +#define MULTIBOOT_MEMORY_RESERVED 2 +#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 +#define MULTIBOOT_MEMORY_NVS 4 +#define MULTIBOOT_MEMORY_BADRAM 5 + uint32_t type; +} __attribute__((packed)); + +struct multiboot_mod_list +{ + /* the memory used goes from bytes ’mod_start’ to ’mod_end-1’ inclusive */ + uint32_t mod_start; + uint32_t mod_end; + + /* Module command line */ + uint32_t cmdline; + + /* padding to take it to 16 bytes (must be zero) */ + uint32_t pad; +}; + +/* APM BIOS info. */ +struct multiboot_apm_info +{ + uint16_t version; + uint16_t cseg; + uint32_t offset; + uint16_t cseg_16; + uint16_t dseg; + uint16_t flags; + uint16_t cseg_len; + uint16_t cseg_16_len; + uint16_t dseg_len; +}; + +#endif + diff --git a/include/nrvn.h b/include/nrvn.h new file mode 100644 index 0000000..abb03b4 --- /dev/null +++ b/include/nrvn.h @@ -0,0 +1,22 @@ +#ifndef _NRVN_H_ +#define _NRVN_H_ + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +static inline void outb(uint16_t port, uint8_t val) { + asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory"); +} + +static inline uint8_t inb(uint16_t port) { + uint8_t ret; + asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port) : "memory"); + return ret; +} + +static inline void io_wait(void) { + outb(0x80, 0); +} + +#endif diff --git a/include/pic.h b/include/pic.h new file mode 100644 index 0000000..08ec6e7 --- /dev/null +++ b/include/pic.h @@ -0,0 +1,9 @@ +#ifndef _PIC_H_ +#define _PIC_H_ + +#include <stdint.h> + +void pic_init(void); +void pic_eoi(uint8_t irq); + +#endif diff --git a/include/ps2.h b/include/ps2.h new file mode 100644 index 0000000..29c1f09 --- /dev/null +++ b/include/ps2.h @@ -0,0 +1,9 @@ +#ifndef _PS2_H_ +#define _PS2_H_ + +#include <stdbool.h> +#include <acpi.h> + +bool ps2_init(struct fadt *fadt); + +#endif diff --git a/include/vga.h b/include/vga.h new file mode 100644 index 0000000..6d74671 --- /dev/null +++ b/include/vga.h @@ -0,0 +1,38 @@ +#ifndef _VGA_H_ +#define _VGA_H_ + +#include <stdint.h> +#include <stddef.h> + +/* Hardware text mode color constants. */ +enum vga_color { + VGA_BLACK = 0, + VGA_BLUE = 1, + VGA_GREEN = 2, + VGA_CYAN = 3, + VGA_RED = 4, + VGA_MAGENTA = 5, + VGA_BROWN = 6, + VGA_LIGHT_GREY = 7, + VGA_DARK_GREY = 8, + VGA_LIGHT_BLUE = 9, + VGA_LIGHT_GREEN = 10, + VGA_LIGHT_CYAN = 11, + VGA_LIGHT_RED = 12, + VGA_LIGHT_MAGENTA = 13, + VGA_LIGHT_BROWN = 14, + VGA_WHITE = 15, +}; + +static const size_t VGA_WIDTH = 80; +static const size_t VGA_HEIGHT = 25; + +void vga_init(void); +void vga_putn(const size_t num); +void vga_putx(const size_t hex); +void vga_putc(const char c); +void vga_puts(const char *s); +void vga_putsn(const char *s, const size_t len); +void vga_set_color(const uint8_t fg, const uint8_t bg); + +#endif |