core: remove bozo typedef for types

This commit is contained in:
0x35c 2025-02-07 12:35:32 +01:00
parent 70739744ac
commit 3b798e5daa
55 changed files with 59841 additions and 1789 deletions

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>

View File

@ -1,13 +1,12 @@
#pragma once #pragma once
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
// MSR // MSR
bool cpu_has_msr(); bool cpu_has_msr();
void cpu_set_msr(u32 msr, u32 lo, u32 hi); void cpu_set_msr(uint32_t msr, uint32_t lo, uint32_t hi);
void cpu_get_msr(u32 msr, u32 *lo, u32 *hi); void cpu_get_msr(uint32_t msr, uint32_t *lo, uint32_t *hi);
// 8259 PIC // 8259 PIC
void pic_disable(void); void pic_disable(void);

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#define BASE_BIN "01" #define BASE_BIN "01"
#define BASE_OCTA BASE_BIN "234567" #define BASE_OCTA BASE_BIN "234567"
#define BASE_DECA BASE_OCTA "89" #define BASE_DECA BASE_OCTA "89"
#define BASE_HEXA BASE_DECA "abcdef" #define BASE_HEXA BASE_DECA "abcdef"

View File

@ -6,7 +6,7 @@ void date_cmd(char *arg);
void poweroff_cmd(char *arg); void poweroff_cmd(char *arg);
void stack_cmd(char *arg); void stack_cmd(char *arg);
void help_cmd(char *arg); void help_cmd(char *arg);
void reboot_cmd(char* arg); void reboot_cmd(char *arg);
void heap_cmd(char *arg); void heap_cmd(char *arg);
void clear_cmd(char *arg); void clear_cmd(char *arg);
void merdella_cmd(char *arg); void merdella_cmd(char *arg);

View File

@ -2,7 +2,7 @@
#include "kpanic.h" #include "kpanic.h"
#include "kprintf.h" #include "kprintf.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define PRINT_PTR(X) kprintf("%s:%u %s: %p\n", __FILE__, __LINE__, #X, X) #define PRINT_PTR(X) kprintf("%s:%u %s: %p\n", __FILE__, __LINE__, #X, X)
@ -18,13 +18,13 @@
} while (0) } while (0)
struct function_entry { struct function_entry {
u32 addr; uint32_t addr;
char name[64]; char name[64];
}; };
struct stackframe { struct stackframe {
struct stackframe *ebp; struct stackframe *ebp;
u32 eip; uint32_t eip;
}; };
void print_stack(void); void print_stack(void);

View File

@ -1,11 +1,10 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct font { struct font {
u32 height; uint32_t height;
u32 width; uint32_t width;
u32 yoffset; uint32_t yoffset;
char *bitmap; char *bitmap;
}; };

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
#pragma once #pragma once
#include "tss.h" #include "tss.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define GDT_SIZE 8 #define GDT_SIZE 8
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR // https://wiki.osdev.org/Global_Descriptor_Table#GDTR
struct gdt_descriptor { struct gdt_descriptor {
u16 size; uint16_t size;
u32 base; uint32_t base;
} __attribute__((packed)); } __attribute__((packed));
extern struct tss TSS; extern struct tss TSS;
@ -34,7 +34,7 @@ void init_gdt();
#define GDT_ACCESS_A_ACCESSED 0b00000001 #define GDT_ACCESS_A_ACCESSED 0b00000001
#define GDT_ACCESS_A_NOT_ACCESSED 0b00000000 #define GDT_ACCESS_A_NOT_ACCESSED 0b00000000
extern u8 gdt_entries[GDT_SIZE * 8]; extern uint8_t gdt_entries[GDT_SIZE * 8];
#define GDT_OFFSET_KERNEL_CODE 0x08 #define GDT_OFFSET_KERNEL_CODE 0x08
#define GDT_OFFSET_KERNEL_DATA 0x10 #define GDT_OFFSET_KERNEL_DATA 0x10

View File

@ -1,10 +1,9 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct icon { struct icon {
u32 height; uint32_t height;
u32 width; uint32_t width;
u32 *pixels; uint32_t *pixels;
}; };

File diff suppressed because one or more lines are too long

View File

@ -1,21 +1,20 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
// doc : https://wiki.osdev.org/Interrupt_Descriptor_Table#IDTR // doc : https://wiki.osdev.org/Interrupt_Descriptor_Table#IDTR
struct idt_descriptor { struct idt_descriptor {
u16 size; uint16_t size;
u32 offset; uint32_t offset;
} __attribute__((packed)); } __attribute__((packed));
struct idt_entry { struct idt_entry {
u16 isr_low; // The lower 16 bits of the ISR's address uint16_t isr_low; // The lower 16 bits of the ISR's address
u16 kernel_cs; // The GDT segment selector that the CPU will load uint16_t kernel_cs; // The GDT segment selector that the CPU will load
// into CS before calling the ISR // into CS before calling the ISR
u8 reserved; // Set to zero uint8_t reserved; // Set to zero
u8 attributes; // Type and attributes; see the IDT page uint8_t attributes; // Type and attributes; see the IDT page
u16 isr_high; // The higher 16 bits of the ISR's address uint16_t isr_high; // The higher 16 bits of the ISR's address
} __attribute__((packed)); } __attribute__((packed));
#define IDT_SIZE 256 #define IDT_SIZE 256

View File

@ -1,23 +1,22 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct registers { struct registers {
// data segment selector // data segment selector
u32 ds; uint32_t ds;
// general purpose registers pushed by pusha // general purpose registers pushed by pusha
u32 edi, esi, ebp, esp, ebx, edx, ecx, eax; uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
// pushed by isr procedure // pushed by isr procedure
u32 int_no, err_code; uint32_t int_no, err_code;
// pushed by CPU automatically // pushed by CPU automatically
u32 eip, cs, eflags, useresp, ss; uint32_t eip, cs, eflags, useresp, ss;
}; };
typedef void (*isr_t)(struct registers *); typedef void (*isr_t)(struct registers *);
void isr_handler(struct registers *regs); void isr_handler(struct registers *regs);
void pic_send_eoi(u8 irq); void pic_send_eoi(uint8_t irq);
void register_interrupt_handler(int index, isr_t handler); void register_interrupt_handler(int index, isr_t handler);
static inline void cli(void) static inline void cli(void)

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -117,8 +116,8 @@
#define KEY_CAPSLOCK 0x3A #define KEY_CAPSLOCK 0x3A
struct key_event { struct key_event {
u8 c; uint8_t c;
u8 scan_code; uint8_t scan_code;
}; };
struct key_event get_key(void); struct key_event get_key(void);

View File

@ -1,28 +1,28 @@
#pragma once #pragma once
#include "multiboot.h" #include "multiboot.h"
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#define PRESENT (1 << 0) #define PRESENT (1 << 0)
#define RW (1 << 1) #define RW (1 << 1)
#define SUPERVISOR (0 << 2) #define SUPERVISOR (0 << 2)
#define ACCESSED (1 << 4) #define ACCESSED (1 << 4)
#define INIT_FLAGS (PRESENT | RW | SUPERVISOR) #define INIT_FLAGS (PRESENT | RW | SUPERVISOR)
#define PAGE_SIZE 4096 #define PAGE_SIZE 4096
#define PT_SIZE 1024 #define PT_SIZE 1024
#define PD_SIZE 1024 #define PD_SIZE 1024
#define PAGE_MASK 0xFFFFF000 #define PAGE_MASK 0xFFFFF000
#define HEAP_END 0xC0000000 #define HEAP_END 0xC0000000
#define HEAP_START ((u32) & _kernel_end - HEAP_END) #define HEAP_START ((uint32_t)&_kernel_end - HEAP_END)
#define KERNEL_START ((u32) & _kernel_start) #define KERNEL_START \
#define KERNEL_END ((u32) & _kernel_end - HEAP_END) ((uint32_t)&_kernel_start) #define KERNEL_END((uint32_t)&_kernel_end - \
#define PT_START 256 HEAP_END)
#define PT_START 256
#define GET_PAGE_ADDR(pd_index, pt_index) \ #define GET_PAGE_ADDR(pd_index, pt_index) \
((((u32)pd_index * 1024) + (u32)pt_index) * 4096) ((((uint32_t)pd_index * 1024) + (uint32_t)pt_index) * 4096)
#define GET_FRAME(frame_table, i) (frame_table[i / 8] & (1 << (i % 8))) #define GET_FRAME(frame_table, i) (frame_table[i / 8] & (1 << (i % 8)))
#define SET_FRAME(frame_table, i, used) \ #define SET_FRAME(frame_table, i, used) \
@ -35,29 +35,30 @@
struct frame_zone { struct frame_zone {
void *addr; void *addr;
u32 first_free_frame; uint32_t first_free_frame;
u8 *frame_table; uint8_t *frame_table;
u32 total_frames; uint32_t total_frames;
u32 remaining_frames; uint32_t remaining_frames;
struct frame_zone *next; struct frame_zone *next;
}; };
extern u32 _kernel_end; extern uint32_t _kernel_end;
extern u32 _kernel_start; extern uint32_t _kernel_start;
extern u32 boot_page_directory; extern uint32_t boot_page_directory;
extern u32 *page_directory; extern uint32_t boot_page_table1;
extern u32 page_table_default[1024]; extern uint32_t *page_directory;
extern u32 mem_size; extern uint32_t page_table_default[1024];
extern uint32_t mem_size;
extern multiboot_memory_map_t *mmap_addr; extern multiboot_memory_map_t *mmap_addr;
extern multiboot_u32 mmap_length; extern multiboot_uint32_t mmap_length;
extern struct frame_zone *head; extern struct frame_zone *head;
u32 *virt_to_phys(u32 *virt_addr); uint32_t *virt_to_phys(uint32_t *virt_addr);
void init_memory(multiboot_info_t *mbd, u32 magic); void init_memory(multiboot_info_t *mbd, uint32_t magic);
void *alloc_frame(void); void *alloc_frame(void);
int free_frame(void *frame_ptr); int free_frame(void *frame_ptr);
i8 add_single_page(void *frame); int8_t add_single_page(void *frame);
void *alloc_pages(size_t size, void **phys_addr); void *alloc_pages(size_t size, void **phys_addr);
int free_pages(void *page_ptr, size_t size); int free_pages(void *page_ptr, size_t size);
void init_page_table(u32 page_table[1024], u16 start); void init_page_table(uint32_t page_table[1024], uint16_t start);
int16_t add_page_table(u16 pd_index); int16_t add_page_table(uint16_t pd_index);

View File

@ -93,71 +93,71 @@
#ifndef ASM_FILE #ifndef ASM_FILE
typedef unsigned char multiboot_u8; typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_u16; typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_u32; typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_u64; typedef unsigned long long multiboot_uint64_t;
struct multiboot_header { struct multiboot_header {
/* Must be MULTIBOOT_MAGIC - see above. */ /* Must be MULTIBOOT_MAGIC - see above. */
multiboot_u32 magic; multiboot_uint32_t magic;
/* Feature flags. */ /* Feature flags. */
multiboot_u32 flags; multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */ /* The above fields plus this one must equal 0 mod 2^32. */
multiboot_u32 checksum; multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */ /* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_u32 header_addr; multiboot_uint32_t header_addr;
multiboot_u32 load_addr; multiboot_uint32_t load_addr;
multiboot_u32 load_end_addr; multiboot_uint32_t load_end_addr;
multiboot_u32 bss_end_addr; multiboot_uint32_t bss_end_addr;
multiboot_u32 entry_addr; multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */ /* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_u32 mode_type; multiboot_uint32_t mode_type;
multiboot_u32 width; multiboot_uint32_t width;
multiboot_u32 height; multiboot_uint32_t height;
multiboot_u32 depth; multiboot_uint32_t depth;
}; };
/* The symbol table for a.out. */ /* The symbol table for a.out. */
struct multiboot_aout_symbol_table { struct multiboot_aout_symbol_table {
multiboot_u32 tabsize; multiboot_uint32_t tabsize;
multiboot_u32 strsize; multiboot_uint32_t strsize;
multiboot_u32 addr; multiboot_uint32_t addr;
multiboot_u32 reserved; multiboot_uint32_t reserved;
}; };
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t; typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */ /* The section header table for ELF. */
struct multiboot_elf_section_header_table { struct multiboot_elf_section_header_table {
multiboot_u32 num; multiboot_uint32_t num;
multiboot_u32 size; multiboot_uint32_t size;
multiboot_u32 addr; multiboot_uint32_t addr;
multiboot_u32 shndx; multiboot_uint32_t shndx;
}; };
typedef struct multiboot_elf_section_header_table typedef struct multiboot_elf_section_header_table
multiboot_elf_section_header_table_t; multiboot_elf_section_header_table_t;
struct multiboot_info { struct multiboot_info {
/* Multiboot info version number */ /* Multiboot info version number */
multiboot_u32 flags; multiboot_uint32_t flags;
/* Available memory from BIOS */ /* Available memory from BIOS */
multiboot_u32 mem_lower; multiboot_uint32_t mem_lower;
multiboot_u32 mem_upper; multiboot_uint32_t mem_upper;
/* "root" partition */ /* "root" partition */
multiboot_u32 boot_device; multiboot_uint32_t boot_device;
/* Kernel command line */ /* Kernel command line */
multiboot_u32 cmdline; multiboot_uint32_t cmdline;
/* Boot-Module list */ /* Boot-Module list */
multiboot_u32 mods_count; multiboot_uint32_t mods_count;
multiboot_u32 mods_addr; multiboot_uint32_t mods_addr;
union { union {
multiboot_aout_symbol_table_t aout_sym; multiboot_aout_symbol_table_t aout_sym;
@ -165,105 +165,104 @@ struct multiboot_info {
} u; } u;
/* Memory Mapping buffer */ /* Memory Mapping buffer */
multiboot_u32 mmap_length; multiboot_uint32_t mmap_length;
multiboot_u32 mmap_addr; multiboot_uint32_t mmap_addr;
/* Drive Info buffer */ /* Drive Info buffer */
multiboot_u32 drives_length; multiboot_uint32_t drives_length;
multiboot_u32 drives_addr; multiboot_uint32_t drives_addr;
/* ROM configuration table */ /* ROM configuration table */
multiboot_u32 config_table; multiboot_uint32_t config_table;
/* Boot Loader Name */ /* Boot Loader Name */
multiboot_u32 boot_loader_name; multiboot_uint32_t boot_loader_name;
/* APM table */ /* APM table */
multiboot_u32 apm_table; multiboot_uint32_t apm_table;
/* Video */ /* Video */
multiboot_u32 vbe_control_info; multiboot_uint32_t vbe_control_info;
multiboot_u32 vbe_mode_info; multiboot_uint32_t vbe_mode_info;
multiboot_u16 vbe_mode; multiboot_uint16_t vbe_mode;
multiboot_u16 vbe_interface_seg; multiboot_uint16_t vbe_interface_seg;
multiboot_u16 vbe_interface_off; multiboot_uint16_t vbe_interface_off;
multiboot_u16 vbe_interface_len; multiboot_uint16_t vbe_interface_len;
multiboot_u64 framebuffer_addr; multiboot_uint64_t framebuffer_addr;
multiboot_u32 framebuffer_pitch; multiboot_uint32_t framebuffer_pitch;
multiboot_u32 framebuffer_width; multiboot_uint32_t framebuffer_width;
multiboot_u32 framebuffer_height; multiboot_uint32_t framebuffer_height;
multiboot_u8 framebuffer_bpp; multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0 #define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1 #define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2 #define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_u8 framebuffer_type; multiboot_uint8_t framebuffer_type;
union { union {
struct { struct {
multiboot_u32 framebuffer_palette_addr; multiboot_uint32_t framebuffer_palette_addr;
multiboot_u16 framebuffer_palette_num_colors; multiboot_uint16_t framebuffer_palette_num_colors;
}; };
struct { struct {
multiboot_u8 framebuffer_red_field_position; multiboot_uint8_t framebuffer_red_field_position;
multiboot_u8 framebuffer_red_mask_size; multiboot_uint8_t framebuffer_red_mask_size;
multiboot_u8 framebuffer_green_field_position; multiboot_uint8_t framebuffer_green_field_position;
multiboot_u8 framebuffer_green_mask_size; multiboot_uint8_t framebuffer_green_mask_size;
multiboot_u8 framebuffer_blue_field_position; multiboot_uint8_t framebuffer_blue_field_position;
multiboot_u8 framebuffer_blue_mask_size; multiboot_uint8_t framebuffer_blue_mask_size;
}; };
}; };
}; };
typedef struct multiboot_info multiboot_info_t; typedef struct multiboot_info multiboot_info_t;
struct multiboot_color { struct multiboot_color {
multiboot_u8 red; multiboot_uint8_t red;
multiboot_u8 green; multiboot_uint8_t green;
multiboot_u8 blue; multiboot_uint8_t blue;
}; };
struct multiboot_mmap_entry { struct multiboot_mmap_entry {
multiboot_u32 size; multiboot_uint32_t size;
multiboot_u64 addr; multiboot_uint64_t addr;
multiboot_u64 len; multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1 #define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2 #define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3 #define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4 #define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5 #define MULTIBOOT_MEMORY_BADRAM 5
multiboot_u32 type; multiboot_uint32_t type;
} __attribute__((packed)); } __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t; typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list { struct multiboot_mod_list {
/* the memory used goes from bytes mod_start to mod_end-1 inclusive /* the memory used goes from bytes mod_start to mod_end-1 inclusive
*/ */
multiboot_u32 mod_start; multiboot_uint32_t mod_start;
multiboot_u32 mod_end; multiboot_uint32_t mod_end;
/* Module command line */ /* Module command line */
multiboot_u32 cmdline; multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */ /* padding to take it to 16 bytes (must be zero) */
multiboot_u32 pad; multiboot_uint32_t pad;
}; };
typedef struct multiboot_mod_list multiboot_module_t; typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */ /* APM BIOS info. */
struct multiboot_apm_info { struct multiboot_apm_info {
multiboot_u16 version; multiboot_uint16_t version;
multiboot_u16 cseg; multiboot_uint16_t cseg;
multiboot_u32 offset; multiboot_uint32_t offset;
multiboot_u16 cseg_16; multiboot_uint16_t cseg_16;
multiboot_u16 dseg; multiboot_uint16_t dseg;
multiboot_u16 flags; multiboot_uint16_t flags;
multiboot_u16 cseg_len; multiboot_uint16_t cseg_len;
multiboot_u16 cseg_16_len; multiboot_uint16_t cseg_16_len;
multiboot_u16 dseg_len; multiboot_uint16_t dseg_len;
}; };
#endif /* ! ASM_FILE */ #endif /* ! ASM_FILE */
#include "types.h"
#include <stdint.h> #include <stdint.h>
void init_multiboot(multiboot_info_t *mbd, u32 magic); void init_multiboot(multiboot_info_t *mbd, uint32_t magic);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
#define SECOND_REGISTER 0x00 #define SECOND_REGISTER 0x00
@ -18,14 +17,14 @@
enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 }; enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 };
struct rtc_date { struct rtc_date {
u8 second; uint8_t second;
u8 minute; uint8_t minute;
u8 hour; uint8_t hour;
u8 index_of_the_day; uint8_t index_of_the_day;
u8 day; uint8_t day;
u8 month; uint8_t month;
u32 year; uint32_t year;
}; };
struct rtc_date get_date(void); struct rtc_date get_date(void);

View File

@ -2,7 +2,6 @@
#include "list.h" #include "list.h"
#include "memory.h" #include "memory.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
@ -14,14 +13,14 @@ enum owner { OWNER_KERNEL, OWNER_USER };
#define STACK_SIZE PAGE_SIZE * 4 #define STACK_SIZE PAGE_SIZE * 4
struct task { struct task {
u8 *esp; uint8_t *esp;
u8 *esp0; uint8_t *esp0;
u32 *cr3; // physical uint32_t *cr3; // physical
u32 *heap; // virtual uint32_t *heap; // virtual
u32 *eip; uint32_t *eip;
u16 pid; uint16_t pid;
u8 status; uint8_t status;
u8 uid; uint8_t uid;
struct task *daddy; struct task *daddy;
struct task *child; struct task *child;
struct list **signals; struct list **signals;
@ -31,8 +30,8 @@ struct task {
void scheduler(void); void scheduler(void);
void switch_to_task(struct task *next_task); void switch_to_task(struct task *next_task);
struct task *create_task(u8 uid); struct task *create_task(uint8_t uid);
i8 create_kernel_task(void); int8_t create_kernel_task(void);
void remove_task(struct task *task); void remove_task(struct task *task);
struct task *copy_task(const struct task *task); struct task *copy_task(const struct task *task);
void kfork(struct task *daddy); void kfork(struct task *daddy);
@ -40,5 +39,5 @@ void zombify_task(struct task *task);
// utils // utils
void exec_fn(void (*fn)(void)); void exec_fn(void (*fn)(void));
u16 fork(void); uint16_t fork(void);
u16 wait(void); uint16_t wait(void);

View File

@ -3,7 +3,7 @@
#include "font.h" #include "font.h"
#include "icon.h" #include "icon.h"
#include "keyboard.h" #include "keyboard.h"
#include "types.h"
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -19,10 +19,10 @@
struct screen { struct screen {
size_t row; size_t row;
size_t column; size_t column;
u32 fg_color; uint32_t fg_color;
u32 bg_color; uint32_t bg_color;
u8 buffer[VGA_WIDTH * VGA_HEIGHT]; uint8_t buffer[VGA_WIDTH * VGA_HEIGHT];
u32 default_color; uint32_t default_color;
struct icon *background; struct icon *background;
struct font *font; struct font *font;
char line[256]; char line[256];
@ -50,8 +50,8 @@ typedef enum {
enum cursor_direction { LEFT, RIGHT, UP, DOWN }; enum cursor_direction { LEFT, RIGHT, UP, DOWN };
void terminal_initialize(void); void terminal_initialize(void);
void terminal_set_bg_color(u32 color); void terminal_set_bg_color(uint32_t color);
void terminal_set_fg_color(u32 color); void terminal_set_fg_color(uint32_t color);
int terminal_putchar(char c); int terminal_putchar(char c);
int terminal_write(const char *data, size_t size); int terminal_write(const char *data, size_t size);
int terminal_writestring(const char *data); int terminal_writestring(const char *data);
@ -63,9 +63,9 @@ struct key_event terminal_getkey(void);
void update_cursor(void); void update_cursor(void);
void move_cursor(int direction); void move_cursor(int direction);
void set_color_level(int level); void set_color_level(int level);
void terminal_set_default_fg_color(u32 fg_color); void terminal_set_default_fg_color(uint32_t fg_color);
void terminal_set_default_bg_color(u32 fg_color); void terminal_set_default_bg_color(uint32_t fg_color);
void terminal_change_default_fg_color(u32 color); void terminal_change_default_fg_color(uint32_t color);
u32 terminal_get_default_color(void); uint32_t terminal_get_default_color(void);
u8 terminal_get_char(int column, int row); uint8_t terminal_get_char(int column, int row);
void terminal_remove_last_char(void); void terminal_remove_last_char(void);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
void sleep(u64 delay); void sleep(uint64_t delay);

View File

@ -1,61 +1,60 @@
#pragma once #pragma once
#include "types.h"
#include <stdint.h> #include <stdint.h>
// _h fields are for the offset // _h fields are for the offset
struct tss { struct tss {
u16 link; uint16_t link;
u16 link_h; uint16_t link_h;
u32 esp0; uint32_t esp0;
u16 ss0; uint16_t ss0;
u16 ss0_h; uint16_t ss0_h;
u32 esp1; uint32_t esp1;
u16 ss1; uint16_t ss1;
u16 ss1_h; uint16_t ss1_h;
u32 esp2; uint32_t esp2;
u16 ss2; uint16_t ss2;
u16 ss2_h; uint16_t ss2_h;
u32 cr3; uint32_t cr3;
u32 eip; uint32_t eip;
u32 eflags; uint32_t eflags;
u32 eax; uint32_t eax;
u32 ecx; uint32_t ecx;
u32 edx; uint32_t edx;
u32 ebx; uint32_t ebx;
u32 esp; uint32_t esp;
u32 ebp; uint32_t ebp;
u32 esi; uint32_t esi;
u32 edi; uint32_t edi;
u16 es; uint16_t es;
u16 es_h; uint16_t es_h;
u16 cs; uint16_t cs;
u16 cs_h; uint16_t cs_h;
u16 ss; uint16_t ss;
u16 ss_h; uint16_t ss_h;
u16 ds; uint16_t ds;
u16 ds_h; uint16_t ds_h;
u16 fs; uint16_t fs;
u16 fs_h; uint16_t fs_h;
u16 gs; uint16_t gs;
u16 gs_h; uint16_t gs_h;
u16 ldt; uint16_t ldt;
u16 ldt_h; uint16_t ldt_h;
u16 trap; uint16_t trap;
u16 iomap; uint16_t iomap;
}; };

View File

@ -1,18 +1,18 @@
#pragma once #pragma once
#include "icon.h" #include "icon.h"
#include "types.h"
#include <stdint.h> #include <stdint.h>
struct vbe_interface { struct vbe_interface {
u32 *buff; uint32_t *buff;
u16 height; uint16_t height;
u16 width; uint16_t width;
u32 pitch; uint32_t pitch;
u8 bpp; uint8_t bpp;
}; };
extern struct vbe_interface display; extern struct vbe_interface display;
void draw_icon(u32 pos_x, u32 pos_y, struct icon *img); void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img);
void put_pixel(u32 color, u32 x, u32 y); void put_pixel(uint32_t color, uint32_t x, uint32_t y);

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
char *strchr(const char *str, int c); char *strchr(const char *str, int c);

View File

@ -1,29 +1,28 @@
#pragma once #pragma once
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
static inline void outb(u16 port, u8 val) static inline void outb(uint16_t port, uint8_t val)
{ {
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory"); __asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
} }
static inline u8 inb(u16 port) static inline uint8_t inb(uint16_t port)
{ {
u8 ret; uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory"); __asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret; return ret;
} }
static inline void outw(u16 port, u16 val) static inline void outw(uint16_t port, uint16_t val)
{ {
__asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory"); __asm__ volatile("outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
} }
static inline u16 inw(u16 port) static inline uint16_t inw(uint16_t port)
{ {
u8 ret; uint8_t ret;
__asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory"); __asm__ volatile("inb %w1, %b0" : "=a"(ret) : "Nd"(port) : "memory");
return ret; return ret;
} }

View File

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
// Unsigned int
typedef uint64_t u64;
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint8_t u8;
// Int
typedef int64_t i64;
typedef int32_t i32;
typedef int16_t i16;
typedef int8_t i8;

View File

@ -1,11 +1,11 @@
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
void *memcpy(void *dest, const void *src, size_t n) void *memcpy(void *dest, const void *src, size_t n)
{ {
u8 *c1 = (u8 *)dest; uint8_t *c1 = (uint8_t *)dest;
const u8 *c2 = (const u8 *)src; const uint8_t *c2 = (const uint8_t *)src;
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
c1[i] = c2[i]; c1[i] = c2[i];

View File

@ -1,10 +1,10 @@
#include "types.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
void *memset(void *str, int c, size_t n) void *memset(void *str, int c, size_t n)
{ {
u8 *c1 = (u8 *)str; uint8_t *c1 = (uint8_t *)str;
for (size_t i = 0; i < n; i++) for (size_t i = 0; i < n; i++)
c1[i] = c; c1[i] = c;

9
libbozo/src/types.sh Executable file
View File

@ -0,0 +1,9 @@
# !/bin/bash
sed -i 's/u8/uint8_t/g' **/*.c
sed -i 's/i8/int8_t/g' **/*.c
sed -i 's/u16/uint16_t/g' **/*.c
sed -i 's/i16/int16_t/g' **/*.c
sed -i 's/u32/uint32_t/g' **/*.c
sed -i 's/i32/int32_t/g' **/*.c
sed -i 's/u64/uint64_t/g' **/*.c
sed -i 's/i64/int64_t/g' **/*.c

View File

@ -13,8 +13,8 @@
#define PIT_COUNT (65535 / 2) #define PIT_COUNT (65535 / 2)
#define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT)) #define DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
static u32 sleep_counter; static uint32_t sleep_counter;
static u32 scheduler_counter; static uint32_t scheduler_counter;
static void clock_handler(struct registers *regs); static void clock_handler(struct registers *regs);
@ -44,7 +44,7 @@ static void clock_handler(struct registers *regs)
sleep_counter--; sleep_counter--;
} }
void sleep(u64 delay) void sleep(uint64_t delay)
{ {
sleep_counter = delay / DELAY; sleep_counter = delay / DELAY;
while (sleep_counter) while (sleep_counter)

View File

@ -3,17 +3,17 @@
struct vbe_interface display; struct vbe_interface display;
void put_pixel(u32 color, u32 x, u32 y) void put_pixel(uint32_t color, uint32_t x, uint32_t y)
{ {
// divide by 4 because display.buff is in 32bit instead of 8bit // divide by 4 because display.buff is in 32bit instead of 8bit
const u32 coords = x + y * display.pitch / 4; const uint32_t coords = x + y * display.pitch / 4;
display.buff[coords] = color; display.buff[coords] = color;
} }
void draw_icon(u32 pos_x, u32 pos_y, struct icon *img) void draw_icon(uint32_t pos_x, uint32_t pos_y, struct icon *img)
{ {
for (u32 y = 0; y < img->height; y++) { for (uint32_t y = 0; y < img->height; y++) {
for (u32 x = 0; x < img->width; x++) { for (uint32_t x = 0; x < img->width; x++) {
put_pixel(img->pixels[y * img->width + x], pos_x + x, put_pixel(img->pixels[y * img->width + x], pos_x + x,
pos_y + y); pos_y + y);
} }

View File

@ -3,14 +3,14 @@
#include "gdt.h" #include "gdt.h"
#include "kprintf.h" #include "kprintf.h"
extern void set_gdt(u32 gdt_ptr); extern void set_gdt(uint32_t gdt_ptr);
struct tss TSS; struct tss TSS;
u8 gdt_entries[GDT_SIZE * 8]; uint8_t gdt_entries[GDT_SIZE * 8];
struct gdt_descriptor gdtr; struct gdt_descriptor gdtr;
static void set_gdt_entry_value(u8 *target, u32 base, u32 limit, static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
u8 access, u8 granularity) uint8_t access, uint8_t granularity)
{ {
if (limit > 0xFFFFF) { if (limit > 0xFFFFF) {
kprintf(KERN_ERR kprintf(KERN_ERR
@ -38,7 +38,7 @@ static void set_gdt_entry_value(u8 *target, u32 base, u32 limit,
void init_gdt(void) void init_gdt(void)
{ {
gdtr.size = 8 * GDT_SIZE - 1; gdtr.size = 8 * GDT_SIZE - 1;
gdtr.base = (u32)&gdt_entries[0]; gdtr.base = (uint32_t)&gdt_entries[0];
set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment set_gdt_entry_value(gdt_entries + 0x00, 0, 0, 0, 0); // Null segment
@ -92,8 +92,8 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED, GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack
// TSS // TSS
set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (u32)&TSS, set_gdt_entry_value(gdt_entries + GDT_OFFSET_TSS, (uint32_t)&TSS,
sizeof(struct tss) - 1, 0x89, 0); sizeof(struct tss) - 1, 0x89, 0);
set_gdt(((u32)&gdtr)); set_gdt(((uint32_t)&gdtr));
} }

View File

@ -33,7 +33,7 @@ static isr_t interrupt_handlers[16];
void isr_handler(struct registers *regs) void isr_handler(struct registers *regs)
{ {
u8 i = 0; uint8_t i = 0;
while (i < ARRAY_SIZE(faults)) { while (i < ARRAY_SIZE(faults)) {
if (i == regs->int_no) if (i == regs->int_no)
kpanic("interrupt: %s\n", faults[i]); kpanic("interrupt: %s\n", faults[i]);

View File

@ -21,27 +21,27 @@ static struct idt_descriptor idtr;
void load_idt(struct idt_descriptor *idtr); void load_idt(struct idt_descriptor *idtr);
void idt_set_descriptor(u8 index, void *isr, u8 flags) void idt_set_descriptor(uint8_t index, void *isr, uint8_t flags)
{ {
struct idt_entry *descriptor = &idt_entries[index]; struct idt_entry *descriptor = &idt_entries[index];
descriptor->isr_low = (u32)isr & 0xFFFF; descriptor->isr_low = (uint32_t)isr & 0xFFFF;
descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE; descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE;
descriptor->attributes = flags; descriptor->attributes = flags;
descriptor->isr_high = (u32)isr >> 16; descriptor->isr_high = (uint32_t)isr >> 16;
descriptor->reserved = 0; descriptor->reserved = 0;
} }
void init_idt(void) void init_idt(void)
{ {
idtr.offset = (uintptr_t)&idt_entries[0]; idtr.offset = (uintptr_t)&idt_entries[0];
idtr.size = (u16)sizeof(struct idt_entry) * IDT_SIZE - 1; idtr.size = (uint16_t)sizeof(struct idt_entry) * IDT_SIZE - 1;
u8 i; uint8_t i;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
idt_set_descriptor(i, isr_stub_table[i], 0x8E); idt_set_descriptor(i, isr_stub_table[i], 0x8E);
pic_remap(0x20, 0x28); pic_remap(0x20, 0x28);
for (u8 j = 0; j < 16; j++) for (uint8_t j = 0; j < 16; j++)
idt_set_descriptor(i + j, irq_stub_table[j], 0x8E); idt_set_descriptor(i + j, irq_stub_table[j], 0x8E);
load_idt(&idtr); load_idt(&idtr);
__asm__ volatile("sti"); __asm__ volatile("sti");

View File

@ -1,9 +1,9 @@
#include "types.h"
#include <cpuid.h> #include <cpuid.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
const u32 CPUID_FLAG_MSR = 1 << 5; const uint32_t CPUID_FLAG_MSR = 1 << 5;
bool cpu_has_msr() bool cpu_has_msr()
{ {
@ -12,12 +12,12 @@ bool cpu_has_msr()
return edx & CPUID_FLAG_MSR; return edx & CPUID_FLAG_MSR;
} }
void cpu_get_msr(u32 msr, u32 *lo, u32 *hi) void cpu_get_msr(uint32_t msr, uint32_t *lo, uint32_t *hi)
{ {
asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr)); asm volatile("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
} }
void cpu_set_msr(u32 msr, u32 lo, u32 hi) void cpu_set_msr(uint32_t msr, uint32_t lo, uint32_t hi)
{ {
asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr)); asm volatile("wrmsr" : : "a"(lo), "d"(hi), "c"(msr));
} }

View File

@ -24,7 +24,7 @@
void pic_remap(int offset_master, int offset_slave) void pic_remap(int offset_master, int offset_slave)
{ {
u8 a1, a2; uint8_t a1, a2;
a1 = inb(PIC1_DATA); // save masks a1 = inb(PIC1_DATA); // save masks
a2 = inb(PIC2_DATA); a2 = inb(PIC2_DATA);
@ -56,7 +56,7 @@ void pic_remap(int offset_master, int offset_slave)
outb(PIC2_DATA, a2); outb(PIC2_DATA, a2);
} }
void pic_send_eoi(u8 irq) void pic_send_eoi(uint8_t irq)
{ {
if (irq >= 8) if (irq >= 8)
outb(PIC2_COMMAND, PIC_EOI); outb(PIC2_COMMAND, PIC_EOI);

View File

@ -43,7 +43,7 @@ static void owo(void)
static void awa(void) static void awa(void)
{ {
u32 pid = fork(); uint32_t pid = fork();
PRINT_INT(pid); PRINT_INT(pid);
if (pid < 0) if (pid < 0)
kprintf("camille il a une grosse bite (18cm)\n"); kprintf("camille il a une grosse bite (18cm)\n");
@ -52,7 +52,7 @@ static void awa(void)
wait(); wait();
} }
void kernel_main(multiboot_info_t *mbd, u32 magic) void kernel_main(multiboot_info_t *mbd, uint32_t magic)
{ {
terminal_initialize(); terminal_initialize();
init_gdt(); init_gdt();

View File

@ -7,7 +7,7 @@
#include "string.h" #include "string.h"
#include "terminal.h" #include "terminal.h"
extern u32 page_table1[1024]; extern uint32_t page_table1[1024];
extern const char *faults[]; extern const char *faults[];
__attribute__((noreturn)) void kpanic(const char *format, ...) __attribute__((noreturn)) void kpanic(const char *format, ...)
@ -20,7 +20,7 @@ __attribute__((noreturn)) void kpanic(const char *format, ...)
kvprintf(format, &va); kvprintf(format, &va);
va_end(va); va_end(va);
u32 faulting_address; uint32_t faulting_address;
__asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address)); __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_address));
kprintf("fault at address: %p\n", faulting_address); kprintf("fault at address: %p\n", faulting_address);
/* for (int i = 16; i < 32; i++) */ /* for (int i = 16; i < 32; i++) */

View File

@ -5,7 +5,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdint.h> #include <stdint.h>
int print_int_base(i64 number, const char *prefix, const char *base); int print_int_base(int64_t number, const char *prefix, const char *base);
static int get_level(const char *str) static int get_level(const char *str)
{ {
@ -20,19 +20,19 @@ static int print_flag(char flag, va_list *ap)
case '%': case '%':
return terminal_putchar('%'); return terminal_putchar('%');
case 'i': case 'i':
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
case 'd': case 'd':
return print_int_base(va_arg(*ap, i32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, int32_t), NULL, BASE_DECA);
case 'c': case 'c':
return terminal_putchar(va_arg(*ap, int)); return terminal_putchar(va_arg(*ap, int));
case 's': case 's':
return terminal_writestring(va_arg(*ap, char *)); return terminal_writestring(va_arg(*ap, char *));
case 'p': case 'p':
return print_int_base(va_arg(*ap, u32), "0x", BASE_HEXA); return print_int_base(va_arg(*ap, uint32_t), "0x", BASE_HEXA);
case 'x': case 'x':
return print_int_base(va_arg(*ap, i32), "0x", BASE_HEXA); return print_int_base(va_arg(*ap, int32_t), "0x", BASE_HEXA);
case 'u': case 'u':
return print_int_base(va_arg(*ap, u32), NULL, BASE_DECA); return print_int_base(va_arg(*ap, uint32_t), NULL, BASE_DECA);
} }
return 0; return 0;
} }

View File

@ -3,11 +3,11 @@
#include "string.h" #include "string.h"
#include "terminal.h" #include "terminal.h"
int print_int_base(i64 number, const char *prefix, const char *base) int print_int_base(int64_t number, const char *prefix, const char *base)
{ {
const int base_size = strlen(base); const int base_size = strlen(base);
u64 div = 1; uint64_t div = 1;
u32 tmp; uint32_t tmp;
int rv = 0; int rv = 0;
if (prefix) if (prefix)

View File

@ -34,7 +34,7 @@ int free_frame(void *frame_ptr)
frame_ptr >= it->addr + it->total_frames * PAGE_SIZE)) frame_ptr >= it->addr + it->total_frames * PAGE_SIZE))
it = it->next; it = it->next;
u32 index = ((frame_ptr - it->addr) / PAGE_SIZE); uint32_t index = ((frame_ptr - it->addr) / PAGE_SIZE);
SET_FRAME(it->frame_table, index, 0); SET_FRAME(it->frame_table, index, 0);
if (it->first_free_frame > index) if (it->first_free_frame > index)
it->first_free_frame = index; it->first_free_frame = index;

View File

@ -1,22 +1,22 @@
#include "debug.h" #include "debug.h"
#include "kprintf.h" #include "kprintf.h"
#include "memory.h" #include "memory.h"
void init_page_table(u32 page_table[1024], u16 start) void init_page_table(uint32_t page_table[1024], uint16_t start)
{ {
for (u16 i = start; i < 1024; i++) for (uint16_t i = start; i < 1024; i++)
page_table[i] = (i << 12) | 0x03; page_table[i] = (i << 12) | 0x03;
} }
i16 add_page_table(u16 pd_index) int16_t add_page_table(uint16_t pd_index)
{ {
void *frame = alloc_frame(); void *frame = alloc_frame();
if (!frame) if (!frame)
return -1; return -1;
page_table_default[PT_START + pd_index] = page_table_default[PT_START + pd_index] =
((u32)frame & PAGE_MASK) | 0x03; ((uint32_t)frame & PAGE_MASK) | 0x03;
u32 *page_table = uint32_t *page_table =
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index); (uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
init_page_table(page_table, 0); init_page_table(page_table, 0);
page_directory[pd_index] = ((u32)frame & PAGE_MASK) | 0x03; page_directory[pd_index] = ((uint32_t)frame & PAGE_MASK) | 0x03;
return 0; return 0;
} }

View File

@ -8,7 +8,7 @@
void show_valloc_mem(void) void show_valloc_mem(void)
{ {
char *const zones_name[3] = {"TINY", "SMALL", "LARGE"}; char *const zones_name[3] = {"TINY", "SMALL", "LARGE"};
u32 total_size = 0; uint32_t total_size = 0;
for (block_type_t type = 0; type < 3; ++type) { for (block_type_t type = 0; type < 3; ++type) {
int count = 0; int count = 0;
@ -23,7 +23,7 @@ void show_valloc_mem(void)
/* i++; */ /* i++; */
/* if (i < 10) */ /* if (i < 10) */
kprintf("%p - %p : %u bytes\n", block_it->ptr, kprintf("%p - %p : %u bytes\n", block_it->ptr,
(u32)block_it->ptr + (uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block), block_it->sub_size + sizeof(Block),
block_it->sub_size); block_it->sub_size);
total_size += block_it->sub_size; total_size += block_it->sub_size;
@ -39,7 +39,7 @@ void show_valloc_mem(void)
for (Block *block_it = zone_it->free; block_it != NULL; for (Block *block_it = zone_it->free; block_it != NULL;
block_it = block_it->next_free) { block_it = block_it->next_free) {
kprintf("%p - %p : %u bytes\n", block_it->ptr, kprintf("%p - %p : %u bytes\n", block_it->ptr,
(u32)block_it->ptr + (uint32_t)block_it->ptr +
block_it->sub_size + sizeof(Block), block_it->sub_size + sizeof(Block),
block_it->sub_size); block_it->sub_size);
} }

View File

@ -98,7 +98,7 @@ void vfree(void *ptr)
{ {
if (ptr == NULL) if (ptr == NULL)
return; return;
Block *to_free = (Block *)((u32)ptr - sizeof(Block)); Block *to_free = (Block *)((uint32_t)ptr - sizeof(Block));
Block *to_merge = NULL; Block *to_merge = NULL;
to_free->in_use = false; to_free->in_use = false;
remove_used(to_free); remove_used(to_free);

View File

@ -8,7 +8,7 @@
* Find first available (not in_use) block * Find first available (not in_use) block
* in a zone matching the size we need * in a zone matching the size we need
*/ */
static Block *find_block(Zone *head, u32 size) static Block *find_block(Zone *head, uint32_t size)
{ {
for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) { for (Zone *zone_it = head; zone_it != NULL; zone_it = zone_it->next) {
for (Block *block_it = zone_it->free; block_it != NULL; for (Block *block_it = zone_it->free; block_it != NULL;
@ -46,17 +46,17 @@ static Block *find_block(Zone *head, u32 size)
* We can see that it now has its own metadata and available * We can see that it now has its own metadata and available
* data and it points towards [6] * data and it points towards [6]
*/ */
static void frag_block(Zone *zone, Block *old_block, u32 size) static void frag_block(Zone *zone, Block *old_block, uint32_t size)
{ {
Block *new_block = (Block *)align_mem((u32)old_block + size); Block *new_block = (Block *)align_mem((uint32_t)old_block + size);
assert(new_block < assert(new_block <
(Block *)((u32)zone + get_zone_size(zone->type))); (Block *)((uint32_t)zone + get_zone_size(zone->type)));
// Newly created block metadata // Newly created block metadata
new_block->size = old_block->size - align_mem(size); new_block->size = old_block->size - align_mem(size);
new_block->sub_size = new_block->size; new_block->sub_size = new_block->size;
new_block->in_use = false; new_block->in_use = false;
new_block->ptr = (void *)((u32)new_block + sizeof(Block)); new_block->ptr = (void *)((uint32_t)new_block + sizeof(Block));
new_block->zone = zone; new_block->zone = zone;
new_block->prev = old_block; new_block->prev = old_block;
@ -120,7 +120,7 @@ static void save_block(Zone *head, Block *block, Zone *zone)
* *
* ptr: returns the aligned pointer of the block (after the metadata) * ptr: returns the aligned pointer of the block (after the metadata)
*/ */
void *vmalloc(u32 size) void *vmalloc(uint32_t size)
{ {
void *ptr = NULL; void *ptr = NULL;
@ -136,7 +136,7 @@ void *vmalloc(u32 size)
// Find an available block in a zone of type "type" // Find an available block in a zone of type "type"
Block *available = find_block(head, size); Block *available = find_block(head, size);
if (available == NULL) { if (available == NULL) {
u32 full_size; uint32_t full_size;
if (type == LARGE) if (type == LARGE)
full_size = size + sizeof(Block) + sizeof(Zone); full_size = size + sizeof(Block) + sizeof(Zone);
else else

View File

@ -4,7 +4,7 @@
// Prototype for kfree and vmalloc // Prototype for kfree and vmalloc
void kfree(void *ptr); void kfree(void *ptr);
void *vmalloc(u32 size); void *vmalloc(uint32_t size);
/* /*
* ptr: block to resize (undefined behavior if invalid) * ptr: block to resize (undefined behavior if invalid)
@ -18,12 +18,12 @@ void *vmalloc(u32 size);
* *
* ptr: returns the aligned pointer of the vreallocated block * ptr: returns the aligned pointer of the vreallocated block
*/ */
void *vrealloc(void *ptr, u32 size) void *vrealloc(void *ptr, uint32_t size)
{ {
void *new_ptr = NULL; void *new_ptr = NULL;
if (ptr == NULL) if (ptr == NULL)
return NULL; return NULL;
Block *block = (Block *)((u32)ptr - sizeof(Block)); Block *block = (Block *)((uint32_t)ptr - sizeof(Block));
if (block->size >= size) { if (block->size >= size) {
block->sub_size = size; block->sub_size = size;
return (ptr); return (ptr);

View File

@ -1,9 +1,9 @@
#include "alloc.h" #include "alloc.h"
#include <stdint.h> #include <stdint.h>
u32 vsize(void *ptr) uint32_t vsize(void *ptr)
{ {
Block *meta_data = (Block *)((u32)ptr - sizeof(Block)); Block *meta_data = (Block *)((uint32_t)ptr - sizeof(Block));
return meta_data->sub_size; return meta_data->sub_size;
} }

View File

@ -9,21 +9,21 @@
#include "utils.h" #include "utils.h"
#include "vbe.h" #include "vbe.h"
u32 multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t multiboot_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
u32 vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE))); uint32_t vbe_page_table[1024] __attribute__((aligned(PAGE_SIZE)));
multiboot_memory_map_t *mmap_addr; multiboot_memory_map_t *mmap_addr;
multiboot_u32 mmap_length; multiboot_uint32_t mmap_length;
static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index) static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
{ {
// Index mbd->mmap_addr pointers // Index mbd->mmap_addr pointers
u32 i = 0; uint32_t i = 0;
for (; i < mbd_virt->mmap_length; i++) for (; i < mbd_virt->mmap_length; i++)
multiboot_page_table[i + *pt_index] = multiboot_page_table[i + *pt_index] =
((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) | ((mbd_virt->mmap_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS; INIT_FLAGS;
mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) + mmap_addr = (multiboot_memory_map_t *)(GET_PAGE_ADDR(1023, *pt_index) +
(u32)mbd_virt->mmap_addr % (uint32_t)mbd_virt->mmap_addr %
PAGE_SIZE); PAGE_SIZE);
mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t); mmap_length = mbd_virt->mmap_length / sizeof(multiboot_memory_map_t);
*pt_index += i; *pt_index += i;
@ -31,15 +31,15 @@ static void init_mmap(multiboot_info_t *mbd_virt, size_t *pt_index)
static void init_vbe(multiboot_info_t *mbd_virt) static void init_vbe(multiboot_info_t *mbd_virt)
{ {
const u32 framebuffer_size = const uint32_t framebuffer_size =
mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch; mbd_virt->framebuffer_height * mbd_virt->framebuffer_pitch;
for (u32 i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) { for (uint32_t i = 0; i < CEIL(framebuffer_size, PAGE_SIZE); i++) {
vbe_page_table[i % 1024] = vbe_page_table[i % 1024] =
((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) | ((mbd_virt->framebuffer_addr + i * PAGE_SIZE) & PAGE_MASK) |
INIT_FLAGS; INIT_FLAGS;
} }
page_directory[800] = ((u32)vbe_page_table - HEAP_END) | 0x03; page_directory[800] = ((uint32_t)vbe_page_table - HEAP_END) | 0x03;
display.buff = (u32 *)GET_PAGE_ADDR(800, 0) + display.buff = (uint32_t *)GET_PAGE_ADDR(800, 0) +
(mbd_virt->framebuffer_addr % PAGE_SIZE); (mbd_virt->framebuffer_addr % PAGE_SIZE);
display.height = mbd_virt->framebuffer_height; display.height = mbd_virt->framebuffer_height;
display.width = mbd_virt->framebuffer_width; display.width = mbd_virt->framebuffer_width;
@ -47,24 +47,24 @@ static void init_vbe(multiboot_info_t *mbd_virt)
display.bpp = mbd_virt->framebuffer_bpp; display.bpp = mbd_virt->framebuffer_bpp;
} }
void init_multiboot(multiboot_info_t *mbd, u32 magic) void init_multiboot(multiboot_info_t *mbd, uint32_t magic)
{ {
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) if (magic != MULTIBOOT_BOOTLOADER_MAGIC)
kpanic("invalid magic number! (git good skill issue)"); kpanic("invalid magic number! (git good skill issue)");
init_page_table(multiboot_page_table, 0); init_page_table(multiboot_page_table, 0);
page_directory[1023] = page_directory[1023] =
((u32)multiboot_page_table - HEAP_END) | 0x03; ((uint32_t)multiboot_page_table - HEAP_END) | 0x03;
size_t pt_index = CEIL( size_t pt_index = CEIL(
(u32)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE); (uint32_t)mbd % PAGE_SIZE + sizeof(multiboot_info_t), PAGE_SIZE);
// Index multiboot_info_t struct // Index multiboot_info_t struct
for (u32 i = 0; i < pt_index; i++) for (uint32_t i = 0; i < pt_index; i++)
multiboot_page_table[i] = multiboot_page_table[i] =
(((u32)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS; (((uint32_t)mbd + PAGE_SIZE * i) & PAGE_MASK) | INIT_FLAGS;
multiboot_info_t *mbd_virt = multiboot_info_t *mbd_virt =
(multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) + (multiboot_info_t *)(GET_PAGE_ADDR(1023, 0) +
(u32)mbd % PAGE_SIZE); (uint32_t)mbd % PAGE_SIZE);
init_mmap(mbd_virt, &pt_index); init_mmap(mbd_virt, &pt_index);
init_vbe(mbd_virt); init_vbe(mbd_virt);
} }

View File

@ -1,9 +1,8 @@
#include "interrupts.h" #include "interrupts.h"
#include "kprintf.h" #include "kprintf.h"
#include "task.h" #include "task.h"
#include "types.h"
u16 fork(void) uint16_t fork(void)
{ {
current_task->status = FORKED; current_task->status = FORKED;
scheduler(); scheduler();
@ -24,4 +23,4 @@ void kfork(struct task *daddy)
daddy->status = RUN; daddy->status = RUN;
child->status = RUN; child->status = RUN;
toris(); toris();
} }

View File

@ -12,8 +12,9 @@ struct task *current_task;
void scheduler(void) void scheduler(void)
{ {
// ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED // ZOMBIE, THREAD, RUN, WAIT, SLEEP, STOPPED, FORKED
void (*func[])(struct task *) = {zombify_task, NULL, NULL, NULL, void (*func[])(struct task *) = {
NULL, remove_task, kfork}; zombify_task, NULL, NULL, NULL, NULL, remove_task, kfork,
};
if (!current_task) // || current_task->next == current_task) if (!current_task) // || current_task->next == current_task)
return; return;

View File

@ -1,7 +1,7 @@
#include "interrupts.h" #include "interrupts.h"
#include "task.h" #include "task.h"
u16 wait(void) uint16_t wait(void)
{ {
if (current_task->child == NULL) if (current_task->child == NULL)
return -1; return -1;
@ -10,7 +10,7 @@ u16 wait(void)
current_task->child->status = STOPPED; current_task->child->status = STOPPED;
else else
current_task->status = WAIT; current_task->status = WAIT;
u16 child_pid = current_task->child->pid; uint16_t child_pid = current_task->child->pid;
toris(); toris();
scheduler(); scheduler();
return child_pid; return child_pid;

View File

@ -17,7 +17,7 @@
void reboot(void) void reboot(void)
{ {
u8 tmp; uint8_t tmp;
__asm__ volatile("cli"); /* disable all interrupts */ __asm__ volatile("cli"); /* disable all interrupts */
do { do {

View File

@ -4,7 +4,7 @@
#include "kprintf.h" #include "kprintf.h"
static u16 raw_read_register(u16 cmos_register) static uint16_t raw_read_register(uint16_t cmos_register)
{ {
// selecting the register // selecting the register
outb(CMOS_ADDRESS, cmos_register); outb(CMOS_ADDRESS, cmos_register);
@ -12,19 +12,19 @@ static u16 raw_read_register(u16 cmos_register)
return inb(CMOS_DATA); return inb(CMOS_DATA);
} }
static u8 update_is_in_progress(void) static uint8_t update_is_in_progress(void)
{ {
return raw_read_register(REGISTER_A) & 0x80; return raw_read_register(REGISTER_A) & 0x80;
} }
static u16 read_register(u16 cmos_register) static uint16_t read_register(uint16_t cmos_register)
{ {
while (update_is_in_progress()) while (update_is_in_progress())
kprintf("%d\n", update_is_in_progress()); kprintf("%d\n", update_is_in_progress());
return raw_read_register(cmos_register); return raw_read_register(cmos_register);
} }
u8 bcd_mode_to_bin(u8 value) uint8_t bcd_mode_to_bin(uint8_t value)
{ {
return (value & 0x0F) + ((value / 16) * 10); return (value & 0x0F) + ((value / 16) * 10);
} }
@ -32,7 +32,7 @@ u8 bcd_mode_to_bin(u8 value)
struct rtc_date get_date(void) struct rtc_date get_date(void)
{ {
struct rtc_date rv = {}; struct rtc_date rv = {};
u8 century; uint8_t century;
rv.second = read_register(SECOND_REGISTER); rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER); rv.minute = read_register(MINUTE_REGISTER);

View File

@ -6,7 +6,7 @@
void color_cmd(char *arg) void color_cmd(char *arg)
{ {
u8 tmp_color; uint8_t tmp_color;
static const char *colors[] = { static const char *colors[] = {
"BLACK", "BLUE", "GREEN", "CYAN", "BLACK", "BLUE", "GREEN", "CYAN",
"RED", "MAGENTA", "BROWN", "LIGHT_GREY", "RED", "MAGENTA", "BROWN", "LIGHT_GREY",

View File

@ -8,7 +8,7 @@ struct key_event terminal_getkey(void)
{ {
static bool caps_mode = false; static bool caps_mode = false;
struct key_event ev = {0}; struct key_event ev = {0};
u8 scan_code; uint8_t scan_code;
scan_code = inb(KEYBOARD_PORT); scan_code = inb(KEYBOARD_PORT);
if (scan_code == 0x3A || scan_code == 0x58) { if (scan_code == 0x3A || scan_code == 0x58) {

View File

@ -42,18 +42,18 @@ void terminal_remove_last_char(void)
screen->column = VGA_WIDTH - 1; screen->column = VGA_WIDTH - 1;
screen->row--; screen->row--;
} }
u32 pos_x = (screen->column) * FONT_WIDTH; uint32_t pos_x = (screen->column) * FONT_WIDTH;
u32 pos_y = screen->row * FONT_HEIGHT; uint32_t pos_y = screen->row * FONT_HEIGHT;
struct font node = get_font_node( struct font node = get_font_node(
screen->buffer[screen->row * VGA_WIDTH + screen->column]); screen->buffer[screen->row * VGA_WIDTH + screen->column]);
screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0'; screen->buffer[screen->row * VGA_WIDTH + screen->column] = '\0';
for (u32 y = 0; y < node.height; y++) { for (uint32_t y = 0; y < node.height; y++) {
for (u32 x = 0; x < node.width; x++) { for (uint32_t x = 0; x < node.width; x++) {
// Current bg is taking too much memory // Current bg is taking too much memory
// so we do a black bg for now // so we do a black bg for now
/* struct icon *bg = screen->background; */ /* struct icon *bg = screen->background; */
/* u32 pixel = 0; */ /* uint32_t pixel = 0; */
/* if (bg->width > pos_x + x && bg->height > pos_y + y) /* if (bg->width > pos_x + x && bg->height > pos_y + y)
*/ */
/* pixel = bg->pixels[(pos_y + y) * bg->width + */ /* pixel = bg->pixels[(pos_y + y) * bg->width + */
@ -74,38 +74,38 @@ void terminal_set_screen(int pos)
/* kprintf(PROMPT); */ /* kprintf(PROMPT); */
} }
void terminal_set_bg_color(u32 bg_color) void terminal_set_bg_color(uint32_t bg_color)
{ {
screen->bg_color = bg_color; screen->bg_color = bg_color;
} }
void terminal_set_fg_color(u32 fg_color) void terminal_set_fg_color(uint32_t fg_color)
{ {
screen->fg_color = screen->fg_color; screen->fg_color = screen->fg_color;
} }
void terminal_set_color(u32 fg_color, u32 bg_color) void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
{ {
screen->fg_color = fg_color; screen->fg_color = fg_color;
screen->bg_color = bg_color; screen->bg_color = bg_color;
} }
void terminal_set_default_fg_color(u32 fg_color) void terminal_set_default_fg_color(uint32_t fg_color)
{ {
screen->default_color = fg_color; screen->default_color = fg_color;
} }
u32 terminal_get_default_color(void) uint32_t terminal_get_default_color(void)
{ {
return screen->default_color; return screen->default_color;
} }
u8 terminal_get_char(int x, int y) uint8_t terminal_get_char(int x, int y)
{ {
return screen->buffer[y * VGA_WIDTH + x]; return screen->buffer[y * VGA_WIDTH + x];
} }
void terminal_putentryat(struct font node, u32 fg_color, u32 bg_color, void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
size_t x, size_t y) size_t x, size_t y)
{ {
char *glyph = node.bitmap; char *glyph = node.bitmap;
@ -128,8 +128,8 @@ static void terminal_scroll(void)
screen->row--; screen->row--;
memset(display.buff, 0, display.height * display.pitch); memset(display.buff, 0, display.height * display.pitch);
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) { for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
const u32 x = (i % VGA_WIDTH) * FONT_WIDTH; const uint32_t x = (i % VGA_WIDTH) * FONT_WIDTH;
const u32 y = (i / VGA_WIDTH) * FONT_HEIGHT; const uint32_t y = (i / VGA_WIDTH) * FONT_HEIGHT;
screen->buffer[i] = screen->buffer[i + VGA_WIDTH]; screen->buffer[i] = screen->buffer[i + VGA_WIDTH];
terminal_putentryat(get_font_node(screen->buffer[i]), terminal_putentryat(get_font_node(screen->buffer[i]),
screen->fg_color, screen->bg_color, x, y); screen->fg_color, screen->bg_color, x, y);
@ -143,7 +143,7 @@ static void terminal_new_line(void)
terminal_scroll(); terminal_scroll();
} }
void terminal_change_default_color(u32 color) void terminal_change_default_color(uint32_t color)
{ {
// TODO // TODO
/* terminal_set_color(color); */ /* terminal_set_color(color); */
@ -151,7 +151,7 @@ void terminal_change_default_color(u32 color)
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */ /* for (size_t x = 0; x < VGA_WIDTH; x++) { */
/* const size_t index = y * VGA_WIDTH + x; /* const size_t index = y * VGA_WIDTH + x;
*/ */
/* u8 entry_color = /* uint8_t entry_color =
* get_entry_color(TERM_BUF[index]); * get_entry_color(TERM_BUF[index]);
*/ */
/* TERM_BUF[index] = vga_entry( */ /* TERM_BUF[index] = vga_entry( */
@ -170,7 +170,7 @@ void terminal_change_default_color(u32 color)
/* screen->color = color; */ /* screen->color = color; */
} }
void terminal_change_default_fg_color(u32 fg_color) void terminal_change_default_fg_color(uint32_t fg_color)
{ {
terminal_set_fg_color(fg_color); terminal_set_fg_color(fg_color);
/* terminal_change_default_color(screen->fg_color); */ /* terminal_change_default_color(screen->fg_color); */
@ -228,7 +228,7 @@ int terminal_writestring(const char *data)
void update_cursor(void) void update_cursor(void)
{ {
/* u16 pos = screen->row * VGA_WIDTH + /* uint16_t pos = screen->row * VGA_WIDTH +
* screen->column; */ * screen->column; */
/* outb(0x3D4, 0x0F); */ /* outb(0x3D4, 0x0F); */