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
#include "types.h"
#include <stdbool.h>
#include <stddef.h>

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,10 @@
#pragma once
#include "types.h"
#include <stdint.h>
struct font {
u32 height;
u32 width;
u32 yoffset;
uint32_t height;
uint32_t width;
uint32_t yoffset;
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
#include "tss.h"
#include "types.h"
#include <stdint.h>
#define GDT_SIZE 8
// https://wiki.osdev.org/Global_Descriptor_Table#GDTR
struct gdt_descriptor {
u16 size;
u32 base;
uint16_t size;
uint32_t base;
} __attribute__((packed));
extern struct tss TSS;
@ -34,7 +34,7 @@ void init_gdt();
#define GDT_ACCESS_A_ACCESSED 0b00000001
#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_DATA 0x10

View File

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

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,23 +1,22 @@
#pragma once
#include "types.h"
#include <stdint.h>
struct registers {
// data segment selector
u32 ds;
uint32_t ds;
// 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
u32 int_no, err_code;
uint32_t int_no, err_code;
// pushed by CPU automatically
u32 eip, cs, eflags, useresp, ss;
uint32_t eip, cs, eflags, useresp, ss;
};
typedef void (*isr_t)(struct registers *);
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);
static inline void cli(void)

View File

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

View File

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

View File

@ -93,71 +93,71 @@
#ifndef ASM_FILE
typedef unsigned char multiboot_u8;
typedef unsigned short multiboot_u16;
typedef unsigned int multiboot_u32;
typedef unsigned long long multiboot_u64;
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header {
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_u32 magic;
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_u32 flags;
multiboot_uint32_t flags;
/* 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. */
multiboot_u32 header_addr;
multiboot_u32 load_addr;
multiboot_u32 load_end_addr;
multiboot_u32 bss_end_addr;
multiboot_u32 entry_addr;
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_u32 mode_type;
multiboot_u32 width;
multiboot_u32 height;
multiboot_u32 depth;
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table {
multiboot_u32 tabsize;
multiboot_u32 strsize;
multiboot_u32 addr;
multiboot_u32 reserved;
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table {
multiboot_u32 num;
multiboot_u32 size;
multiboot_u32 addr;
multiboot_u32 shndx;
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
};
typedef struct multiboot_elf_section_header_table
multiboot_elf_section_header_table_t;
struct multiboot_info {
/* Multiboot info version number */
multiboot_u32 flags;
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_u32 mem_lower;
multiboot_u32 mem_upper;
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_u32 boot_device;
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_u32 cmdline;
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_u32 mods_count;
multiboot_u32 mods_addr;
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union {
multiboot_aout_symbol_table_t aout_sym;
@ -165,105 +165,104 @@ struct multiboot_info {
} u;
/* Memory Mapping buffer */
multiboot_u32 mmap_length;
multiboot_u32 mmap_addr;
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_u32 drives_length;
multiboot_u32 drives_addr;
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_u32 config_table;
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_u32 boot_loader_name;
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_u32 apm_table;
multiboot_uint32_t apm_table;
/* Video */
multiboot_u32 vbe_control_info;
multiboot_u32 vbe_mode_info;
multiboot_u16 vbe_mode;
multiboot_u16 vbe_interface_seg;
multiboot_u16 vbe_interface_off;
multiboot_u16 vbe_interface_len;
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
multiboot_u64 framebuffer_addr;
multiboot_u32 framebuffer_pitch;
multiboot_u32 framebuffer_width;
multiboot_u32 framebuffer_height;
multiboot_u8 framebuffer_bpp;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_u8 framebuffer_type;
multiboot_uint8_t framebuffer_type;
union {
struct {
multiboot_u32 framebuffer_palette_addr;
multiboot_u16 framebuffer_palette_num_colors;
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct {
multiboot_u8 framebuffer_red_field_position;
multiboot_u8 framebuffer_red_mask_size;
multiboot_u8 framebuffer_green_field_position;
multiboot_u8 framebuffer_green_mask_size;
multiboot_u8 framebuffer_blue_field_position;
multiboot_u8 framebuffer_blue_mask_size;
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color {
multiboot_u8 red;
multiboot_u8 green;
multiboot_u8 blue;
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry {
multiboot_u32 size;
multiboot_u64 addr;
multiboot_u64 len;
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_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
multiboot_u32 type;
multiboot_uint32_t type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list {
/* the memory used goes from bytes mod_start to mod_end-1 inclusive
*/
multiboot_u32 mod_start;
multiboot_u32 mod_end;
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
/* Module command line */
multiboot_u32 cmdline;
multiboot_uint32_t cmdline;
/* 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;
/* APM BIOS info. */
struct multiboot_apm_info {
multiboot_u16 version;
multiboot_u16 cseg;
multiboot_u32 offset;
multiboot_u16 cseg_16;
multiboot_u16 dseg;
multiboot_u16 flags;
multiboot_u16 cseg_len;
multiboot_u16 cseg_16_len;
multiboot_u16 dseg_len;
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
};
#endif /* ! ASM_FILE */
#include "types.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
#include "types.h"
#include <stdint.h>
#define SECOND_REGISTER 0x00
@ -18,14 +17,14 @@
enum { CMOS_ADDRESS = 0x70, CMOS_DATA = 0x71 };
struct rtc_date {
u8 second;
u8 minute;
u8 hour;
uint8_t second;
uint8_t minute;
uint8_t hour;
u8 index_of_the_day;
u8 day;
u8 month;
u32 year;
uint8_t index_of_the_day;
uint8_t day;
uint8_t month;
uint32_t year;
};
struct rtc_date get_date(void);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,29 +1,28 @@
#pragma once
#include "types.h"
#include <stddef.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");
}
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");
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");
}
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");
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 <stdint.h>
void *memcpy(void *dest, const void *src, size_t n)
{
u8 *c1 = (u8 *)dest;
const u8 *c2 = (const u8 *)src;
uint8_t *c1 = (uint8_t *)dest;
const uint8_t *c2 = (const uint8_t *)src;
for (size_t i = 0; i < n; i++)
c1[i] = c2[i];

View File

@ -1,10 +1,10 @@
#include "types.h"
#include <stddef.h>
#include <stdint.h>
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++)
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 DELAY (1000 / (PIT_FREQUENCY / PIT_COUNT))
static u32 sleep_counter;
static u32 scheduler_counter;
static uint32_t sleep_counter;
static uint32_t scheduler_counter;
static void clock_handler(struct registers *regs);
@ -44,7 +44,7 @@ static void clock_handler(struct registers *regs)
sleep_counter--;
}
void sleep(u64 delay)
void sleep(uint64_t delay)
{
sleep_counter = delay / DELAY;
while (sleep_counter)

View File

@ -3,17 +3,17 @@
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
const u32 coords = x + y * display.pitch / 4;
const uint32_t coords = x + y * display.pitch / 4;
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 (u32 x = 0; x < img->width; x++) {
for (uint32_t y = 0; y < img->height; y++) {
for (uint32_t x = 0; x < img->width; x++) {
put_pixel(img->pixels[y * img->width + x], pos_x + x,
pos_y + y);
}

View File

@ -3,14 +3,14 @@
#include "gdt.h"
#include "kprintf.h"
extern void set_gdt(u32 gdt_ptr);
extern void set_gdt(uint32_t gdt_ptr);
struct tss TSS;
u8 gdt_entries[GDT_SIZE * 8];
uint8_t gdt_entries[GDT_SIZE * 8];
struct gdt_descriptor gdtr;
static void set_gdt_entry_value(u8 *target, u32 base, u32 limit,
u8 access, u8 granularity)
static void set_gdt_entry_value(uint8_t *target, uint32_t base, uint32_t limit,
uint8_t access, uint8_t granularity)
{
if (limit > 0xFFFFF) {
kprintf(KERN_ERR
@ -38,7 +38,7 @@ static void set_gdt_entry_value(u8 *target, u32 base, u32 limit,
void init_gdt(void)
{
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
@ -92,8 +92,8 @@ void init_gdt(void)
GDT_ACCESS_A_ACCESSED,
GDT_FLAG_32BIT_MODE | GDT_FLAG_PAGE_MODE); // User stack
// 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);
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)
{
u8 i = 0;
uint8_t i = 0;
while (i < ARRAY_SIZE(faults)) {
if (i == regs->int_no)
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 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];
descriptor->isr_low = (u32)isr & 0xFFFF;
descriptor->isr_low = (uint32_t)isr & 0xFFFF;
descriptor->kernel_cs = GDT_OFFSET_KERNEL_CODE;
descriptor->attributes = flags;
descriptor->isr_high = (u32)isr >> 16;
descriptor->isr_high = (uint32_t)isr >> 16;
descriptor->reserved = 0;
}
void init_idt(void)
{
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++)
idt_set_descriptor(i, isr_stub_table[i], 0x8E);
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);
load_idt(&idtr);
__asm__ volatile("sti");

View File

@ -1,9 +1,9 @@
#include "types.h"
#include <cpuid.h>
#include <stdbool.h>
#include <stdint.h>
const u32 CPUID_FLAG_MSR = 1 << 5;
const uint32_t CPUID_FLAG_MSR = 1 << 5;
bool cpu_has_msr()
{
@ -12,12 +12,12 @@ bool cpu_has_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));
}
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));
}

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
#include <stdarg.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)
{
@ -20,19 +20,19 @@ static int print_flag(char flag, va_list *ap)
case '%':
return terminal_putchar('%');
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':
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':
return terminal_putchar(va_arg(*ap, int));
case 's':
return terminal_writestring(va_arg(*ap, char *));
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':
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':
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;
}

View File

@ -3,11 +3,11 @@
#include "string.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);
u64 div = 1;
u32 tmp;
uint64_t div = 1;
uint32_t tmp;
int rv = 0;
if (prefix)

View File

@ -34,7 +34,7 @@ int free_frame(void *frame_ptr)
frame_ptr >= it->addr + it->total_frames * PAGE_SIZE))
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);
if (it->first_free_frame > index)
it->first_free_frame = index;

View File

@ -1,22 +1,22 @@
#include "debug.h"
#include "kprintf.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;
}
i16 add_page_table(u16 pd_index)
int16_t add_page_table(uint16_t pd_index)
{
void *frame = alloc_frame();
if (!frame)
return -1;
page_table_default[PT_START + pd_index] =
((u32)frame & PAGE_MASK) | 0x03;
u32 *page_table =
(u32 *)GET_PAGE_ADDR(0, PT_START + pd_index);
((uint32_t)frame & PAGE_MASK) | 0x03;
uint32_t *page_table =
(uint32_t *)GET_PAGE_ADDR(0, PT_START + pd_index);
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;
}

View File

@ -8,7 +8,7 @@
void show_valloc_mem(void)
{
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) {
int count = 0;
@ -23,7 +23,7 @@ void show_valloc_mem(void)
/* i++; */
/* if (i < 10) */
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);
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;
block_it = block_it->next_free) {
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);
}

View File

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

View File

@ -8,7 +8,7 @@
* Find first available (not in_use) block
* 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 (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
* 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 <
(Block *)((u32)zone + get_zone_size(zone->type)));
(Block *)((uint32_t)zone + get_zone_size(zone->type)));
// Newly created block metadata
new_block->size = old_block->size - align_mem(size);
new_block->sub_size = new_block->size;
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->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)
*/
void *vmalloc(u32 size)
void *vmalloc(uint32_t size)
{
void *ptr = NULL;
@ -136,7 +136,7 @@ void *vmalloc(u32 size)
// Find an available block in a zone of type "type"
Block *available = find_block(head, size);
if (available == NULL) {
u32 full_size;
uint32_t full_size;
if (type == LARGE)
full_size = size + sizeof(Block) + sizeof(Zone);
else

View File

@ -4,7 +4,7 @@
// Prototype for kfree and vmalloc
void kfree(void *ptr);
void *vmalloc(u32 size);
void *vmalloc(uint32_t size);
/*
* 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
*/
void *vrealloc(void *ptr, u32 size)
void *vrealloc(void *ptr, uint32_t size)
{
void *new_ptr = NULL;
if (ptr == NULL)
return NULL;
Block *block = (Block *)((u32)ptr - sizeof(Block));
Block *block = (Block *)((uint32_t)ptr - sizeof(Block));
if (block->size >= size) {
block->sub_size = size;
return (ptr);

View File

@ -1,9 +1,9 @@
#include "alloc.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;
}

View File

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

View File

@ -1,9 +1,8 @@
#include "interrupts.h"
#include "kprintf.h"
#include "task.h"
#include "types.h"
u16 fork(void)
uint16_t fork(void)
{
current_task->status = FORKED;
scheduler();

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@
#include "kprintf.h"
static u16 raw_read_register(u16 cmos_register)
static uint16_t raw_read_register(uint16_t cmos_register)
{
// selecting the register
outb(CMOS_ADDRESS, cmos_register);
@ -12,19 +12,19 @@ static u16 raw_read_register(u16 cmos_register)
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;
}
static u16 read_register(u16 cmos_register)
static uint16_t read_register(uint16_t cmos_register)
{
while (update_is_in_progress())
kprintf("%d\n", update_is_in_progress());
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);
}
@ -32,7 +32,7 @@ u8 bcd_mode_to_bin(u8 value)
struct rtc_date get_date(void)
{
struct rtc_date rv = {};
u8 century;
uint8_t century;
rv.second = read_register(SECOND_REGISTER);
rv.minute = read_register(MINUTE_REGISTER);

View File

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

View File

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