summaryrefslogtreecommitdiff
path: root/kernel/cpu
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-10 15:47:08 +0100
committerAnton Kling <anton@kling.gg>2023-11-10 15:47:08 +0100
commit9a1f977e39d8e9fcb6a9cb2a612f4743e802221d (patch)
tree1fc53f6e80eb40d24274f2f8967d584b88c6d664 /kernel/cpu
parent0cb4afef6da5488a128e5aaece435e9aa5f5797e (diff)
Kernel Style: Change uint*_t -> u*
Diffstat (limited to 'kernel/cpu')
-rw-r--r--kernel/cpu/gdt.c14
-rw-r--r--kernel/cpu/gdt.h96
-rw-r--r--kernel/cpu/idt.c33
-rw-r--r--kernel/cpu/idt.h18
-rw-r--r--kernel/cpu/io.h22
-rw-r--r--kernel/cpu/spinlock.c4
-rw-r--r--kernel/cpu/syscall.c6
-rw-r--r--kernel/cpu/syscall.h2
8 files changed, 97 insertions, 98 deletions
diff --git a/kernel/cpu/gdt.c b/kernel/cpu/gdt.c
index 28853cf..553512f 100644
--- a/kernel/cpu/gdt.c
+++ b/kernel/cpu/gdt.c
@@ -9,16 +9,16 @@ tss_entry_t tss_entry;
typedef union {
struct GDT_Entry s;
- uint64_t raw;
+ u64 raw;
} GDT_Entry;
GDT_Entry gdt_entries[6] = {0};
GDT_Pointer gdtr;
-extern uint32_t inital_esp;
+extern u32 inital_esp;
void write_tss(struct GDT_Entry *gdt_entry) {
- uint32_t base = (uint32_t)&tss_entry;
- uint32_t limit = sizeof(tss_entry);
+ u32 base = (u32)&tss_entry;
+ u32 limit = sizeof(tss_entry);
gdt_entry->limit_low = limit;
gdt_entry->base_low = base;
@@ -34,11 +34,11 @@ void write_tss(struct GDT_Entry *gdt_entry) {
gdt_entry->long_mode = 0;
gdt_entry->big = 0;
gdt_entry->gran = 0;
- gdt_entry->base_high = (base & ((uint32_t)0xff << 24)) >> 24;
+ gdt_entry->base_high = (base & ((u32)0xff << 24)) >> 24;
memset(&tss_entry, 0, sizeof tss_entry);
tss_entry.ss0 = GDT_KERNEL_DATA_SEGMENT * GDT_ENTRY_SIZE;
- register uint32_t esp asm("esp");
+ register u32 esp asm("esp");
tss_entry.esp0 = esp;
}
@@ -63,7 +63,7 @@ void gdt_init() {
write_tss((struct GDT_Entry *)&gdt_entries[GDT_TSS_SEGMENT]);
- gdtr.offset = (uint32_t)&gdt_entries;
+ gdtr.offset = (u32)&gdt_entries;
gdtr.size = sizeof(gdt_entries) - 1;
asm("cli");
diff --git a/kernel/cpu/gdt.h b/kernel/cpu/gdt.h
index a490dea..7cb2dc9 100644
--- a/kernel/cpu/gdt.h
+++ b/kernel/cpu/gdt.h
@@ -1,6 +1,6 @@
#ifndef GDT_H
#define GDT_H
-#include <stdint.h>
+#include <typedefs.h>
#include <string.h>
#define GDT_ENTRY_SIZE 0x8
@@ -13,64 +13,64 @@
struct GDT_Entry
{
- uint16_t limit_low;
- uint32_t base_low : 24;
- uint32_t accessed : 1;
- uint32_t read_write : 1; // readable for code, writable for data
- uint32_t conforming_expand_down : 1; // conforming for code, expand down for data
- uint32_t code : 1; // 1 for code, 0 for data
- uint32_t code_data_segment : 1; // should be 1 for everything but TSS and LDT
- uint32_t DPL : 2; // privilege level
- uint32_t present : 1;
- uint32_t limit_high : 4;
- uint32_t available : 1; // only used in software; has no effect on hardware
- uint32_t long_mode : 1;
- uint32_t big : 1; // 32-bit opcodes for code, uint32_t stack for data
- uint32_t gran : 1; // 1 to use 4k page addressing, 0 for byte addressing
- uint8_t base_high;
+ u16 limit_low;
+ u32 base_low : 24;
+ u32 accessed : 1;
+ u32 read_write : 1; // readable for code, writable for data
+ u32 conforming_expand_down : 1; // conforming for code, expand down for data
+ u32 code : 1; // 1 for code, 0 for data
+ u32 code_data_segment : 1; // should be 1 for everything but TSS and LDT
+ u32 DPL : 2; // privilege level
+ u32 present : 1;
+ u32 limit_high : 4;
+ u32 available : 1; // only used in software; has no effect on hardware
+ u32 long_mode : 1;
+ u32 big : 1; // 32-bit opcodes for code, u32 stack for data
+ u32 gran : 1; // 1 to use 4k page addressing, 0 for byte addressing
+ u8 base_high;
}__attribute__((packed));
typedef struct GDT_Pointer
{
- uint16_t size;
- uint32_t offset;
+ u16 size;
+ u32 offset;
}__attribute__((packed)) GDT_Pointer;
struct tss_entry_struct
{
- uint32_t prev_tss; // The previous TSS - with hardware task switching these form a kind of backward linked list.
- uint32_t esp0; // The stack pointer to load when changing to kernel mode.
- uint32_t ss0; // The stack segment to load when changing to kernel mode.
+ u32 prev_tss; // The previous TSS - with hardware task switching these form a kind of backward linked list.
+ u32 esp0; // The stack pointer to load when changing to kernel mode.
+ u32 ss0; // The stack segment to load when changing to kernel mode.
// Everything below here is unused.
- uint32_t esp1; // esp and ss 1 and 2 would be used when switching to rings 1 or 2.
- uint32_t ss1;
- uint32_t esp2;
- uint32_t ss2;
- 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;
- uint32_t es;
- uint32_t cs;
- uint32_t ss;
- uint32_t ds;
- uint32_t fs;
- uint32_t gs;
- uint32_t ldt;
- uint16_t trap;
- uint16_t iomap_base;
+ u32 esp1; // esp and ss 1 and 2 would be used when switching to rings 1 or 2.
+ u32 ss1;
+ u32 esp2;
+ u32 ss2;
+ u32 cr3;
+ u32 eip;
+ u32 eflags;
+ u32 eax;
+ u32 ecx;
+ u32 edx;
+ u32 ebx;
+ u32 esp;
+ u32 ebp;
+ u32 esi;
+ u32 edi;
+ u32 es;
+ u32 cs;
+ u32 ss;
+ u32 ds;
+ u32 fs;
+ u32 gs;
+ u32 ldt;
+ u16 trap;
+ u16 iomap_base;
} __attribute__((packed));
void gdt_init();
-uint8_t gen_access_byte(uint8_t priv, uint8_t s, uint8_t ex, uint8_t dc, uint8_t rw);
-uint64_t gen_gdt_entry(uint32_t base, uint32_t limit, uint8_t access_byte, uint8_t flag);
-uint8_t gen_flag(uint8_t gr, uint8_t sz);
+u8 gen_access_byte(u8 priv, u8 s, u8 ex, u8 dc, u8 rw);
+u64 gen_gdt_entry(u32 base, u32 limit, u8 access_byte, u8 flag);
+u8 gen_flag(u8 gr, u8 sz);
#endif
diff --git a/kernel/cpu/idt.c b/kernel/cpu/idt.c
index abcafad..bf0061f 100644
--- a/kernel/cpu/idt.c
+++ b/kernel/cpu/idt.c
@@ -13,15 +13,15 @@
#define IDT_MAX_ENTRY 256
struct IDT_Descriptor {
- uint16_t low_offset;
- uint16_t code_segment_selector;
- uint8_t zero; // Always should be zero
- uint8_t type_attribute;
- uint16_t high_offset;
+ u16 low_offset;
+ u16 code_segment_selector;
+ u8 zero; // Always should be zero
+ u8 type_attribute;
+ u16 high_offset;
} __attribute__((packed)) __attribute__((aligned(4)));
struct IDT_Pointer {
- uint16_t size;
+ u16 size;
struct IDT_Descriptor **interrupt_table;
} __attribute__((packed));
@@ -30,9 +30,8 @@ struct IDT_Pointer idtr;
extern void load_idtr(void *idtr);
-void format_descriptor(uint32_t offset, uint16_t code_segment,
- uint8_t type_attribute,
- struct IDT_Descriptor *descriptor) {
+void format_descriptor(u32 offset, u16 code_segment,
+ u8 type_attribute, struct IDT_Descriptor *descriptor) {
descriptor->low_offset = offset & 0xFFFF;
descriptor->high_offset = offset >> 16;
descriptor->type_attribute = type_attribute;
@@ -40,13 +39,13 @@ void format_descriptor(uint32_t offset, uint16_t code_segment,
descriptor->zero = 0;
}
-void install_handler(void (*handler_function)(), uint16_t type_attribute,
- uint8_t entry) {
- format_descriptor((uint32_t)handler_function, KERNEL_CODE_SEGMENT_OFFSET,
+void install_handler(void (*handler_function)(), u16 type_attribute,
+ u8 entry) {
+ format_descriptor((u32)handler_function, KERNEL_CODE_SEGMENT_OFFSET,
type_attribute, &IDT_Entry[entry]);
}
-__attribute__((no_caller_saved_registers)) void EOI(uint8_t irq) {
+__attribute__((no_caller_saved_registers)) void EOI(u8 irq) {
if (irq > 7)
outb(SLAVE_PIC_COMMAND_PORT, 0x20);
@@ -158,8 +157,8 @@ void PIC_remap(int offset) {
}
void IRQ_set_mask(unsigned char IRQline) {
- uint16_t port;
- uint8_t value;
+ u16 port;
+ u8 value;
port = (IRQline < 8) ? MASTER_PIC_DATA_PORT : SLAVE_PIC_DATA_PORT;
if (IRQline >= 8)
IRQline -= 8;
@@ -168,8 +167,8 @@ void IRQ_set_mask(unsigned char IRQline) {
}
void IRQ_clear_mask(unsigned char IRQline) {
- uint16_t port;
- uint8_t value;
+ u16 port;
+ u8 value;
port = (IRQline < 8) ? MASTER_PIC_DATA_PORT : SLAVE_PIC_DATA_PORT;
if (IRQline >= 8) {
IRQline -= 8;
diff --git a/kernel/cpu/idt.h b/kernel/cpu/idt.h
index 025ba75..c68ce81 100644
--- a/kernel/cpu/idt.h
+++ b/kernel/cpu/idt.h
@@ -5,7 +5,7 @@ typedef struct registers registers_t;
#include <cpu/gdt.h>
#include <cpu/io.h>
#include <log.h>
-#include <stdint.h>
+#include <typedefs.h>
#include <stdio.h>
/*
@@ -55,16 +55,16 @@ typedef struct registers registers_t;
struct interrupt_frame;
struct registers {
- uint32_t error_code;
- uint32_t eip;
- uint32_t cs;
- uint32_t eflags;
- uint32_t esp;
- uint32_t ss;
+ u32 error_code;
+ u32 eip;
+ u32 cs;
+ u32 eflags;
+ u32 esp;
+ u32 ss;
};
void idt_init(void);
__attribute__((no_caller_saved_registers)) void EOI(unsigned char irq);
-void install_handler(void (*handler_function)(), uint16_t type_attribute,
- uint8_t entry);
+void install_handler(void (*handler_function)(), u16 type_attribute,
+ u8 entry);
#endif
diff --git a/kernel/cpu/io.h b/kernel/cpu/io.h
index 38858a4..af2981e 100644
--- a/kernel/cpu/io.h
+++ b/kernel/cpu/io.h
@@ -1,15 +1,15 @@
-#include <stdint.h>
+#include <typedefs.h>
-extern void outsw(uint16_t, uint32_t);
-extern void outb(uint16_t, uint8_t);
-extern void outw(uint16_t, uint16_t);
-extern void outl(uint16_t, uint32_t);
+extern void outsw(u16, u32);
+extern void outb(u16, u8);
+extern void outw(u16, u16);
+extern void outl(u16, u32);
-extern uint32_t inl(uint16_t);
-extern uint16_t inw(uint16_t);
-extern uint16_t inb(uint16_t);
+extern u32 inl(u16);
+extern u16 inw(u16);
+extern u16 inb(u16);
-extern void rep_outsw(uint16_t count, uint16_t port, volatile void *addy);
+extern void rep_outsw(u16 count, u16 port, volatile void *addy);
__attribute__((no_caller_saved_registers)) extern void
-rep_insw(uint16_t count, uint16_t port, volatile void *addy);
-extern void jump_usermode(void (*address)(), uint32_t stack_pointer);
+rep_insw(u16 count, u16 port, volatile void *addy);
+extern void jump_usermode(void (*address)(), u32 stack_pointer);
diff --git a/kernel/cpu/spinlock.c b/kernel/cpu/spinlock.c
index 3f87423..11bcf68 100644
--- a/kernel/cpu/spinlock.c
+++ b/kernel/cpu/spinlock.c
@@ -1,2 +1,2 @@
-#include <stdint.h>
-uint8_t locked;
+#include <typedefs.h>
+u8 locked;
diff --git a/kernel/cpu/syscall.c b/kernel/cpu/syscall.c
index 8e17ae1..024d06f 100644
--- a/kernel/cpu/syscall.c
+++ b/kernel/cpu/syscall.c
@@ -22,7 +22,7 @@
#include <scalls/socket.h>
#include <scalls/stat.h>
#include <scalls/uptime.h>
-#include <stdint.h>
+#include <typedefs.h>
#include <string.h>
#pragma GCC diagnostic ignored "-Wpedantic"
@@ -170,8 +170,8 @@ void (*syscall_functions[])() = {
(void(*))syscall_sigaction,
};
-void syscall_function_handler(uint32_t eax, uint32_t arg1, uint32_t arg2,
- uint32_t arg3, uint32_t arg4, uint32_t arg5) {
+void syscall_function_handler(u32 eax, u32 arg1, u32 arg2,
+ u32 arg3, u32 arg4, u32 arg5) {
assert(eax < sizeof(syscall_functions) / sizeof(syscall_functions[0]));
syscall_functions[eax](arg1, arg2, arg3, arg4, arg5);
}
diff --git a/kernel/cpu/syscall.h b/kernel/cpu/syscall.h
index 51d50f2..3568e51 100644
--- a/kernel/cpu/syscall.h
+++ b/kernel/cpu/syscall.h
@@ -1,6 +1,6 @@
#include "idt.h"
#include <stddef.h>
-#include <stdint.h>
+#include <typedefs.h>
void syscalls_init(void);