From 3f73b8d8a0c37dc67815b958066a2aef2220558f Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Tue, 13 Dec 2022 14:31:27 -0500 Subject: [PATCH] Add newline at the end of the files. Use built in keywords properly. --- libc/src/io/port_io.c | 3 +-- mentos/inc/descriptor_tables/tss.h | 2 +- mentos/inc/io/vga/vga_palette.h | 2 +- mentos/inc/klib/compiler.h | 5 ++--- mentos/inc/klib/stack_helper.h | 4 ++-- mentos/src/descriptor_tables/gdt.c | 2 +- mentos/src/devices/fpu.c | 22 +++++++++++----------- mentos/src/elf/elf.c | 2 +- mentos/src/io/port_io.c | 2 +- mentos/src/io/proc_system.c | 2 +- mentos/src/io/proc_video.c | 2 +- mentos/src/io/vga/vga.c | 2 +- mentos/src/io/video.c | 2 +- mentos/src/ipc/msg.c | 2 +- mentos/src/ipc/sem.c | 2 +- mentos/src/klib/libgen.c | 2 +- mentos/src/klib/mutex.c | 12 ++++++------ mentos/src/klib/ndtree.c | 2 +- mentos/src/klib/time.c | 2 +- mentos/src/mem/paging.c | 6 +++--- mentos/src/mem/zone_allocator.c | 2 +- mentos/src/process/scheduler.c | 2 +- mentos/src/process/scheduler_algorithm.c | 2 +- mentos/src/process/wait.c | 2 +- mentos/src/system/panic.c | 4 ++-- programs/tests/t_kill.c | 2 +- 26 files changed, 46 insertions(+), 48 deletions(-) diff --git a/libc/src/io/port_io.c b/libc/src/io/port_io.c index 603f6c2..a2011c1 100644 --- a/libc/src/io/port_io.c +++ b/libc/src/io/port_io.c @@ -33,7 +33,6 @@ inline uint32_t inportl(uint16_t port) { uint32_t rv; __asm__ __volatile__("inl %%dx, %%eax" : "=a"(rv) : "dN"(port)); - return rv; } @@ -49,7 +48,7 @@ inline void outports(uint16_t port, uint16_t data) void outportsm(uint16_t port, uint8_t *data, uint16_t size) { - asm volatile("rep outsw" : "+S"(data), "+c"(size) : "d"(port)); + __asm__ __volatile__("rep outsw" : "+S"(data), "+c"(size) : "d"(port)); } inline void outportl(uint16_t port, uint32_t data) diff --git a/mentos/inc/descriptor_tables/tss.h b/mentos/inc/descriptor_tables/tss.h index 1287693..46a6414 100644 --- a/mentos/inc/descriptor_tables/tss.h +++ b/mentos/inc/descriptor_tables/tss.h @@ -60,4 +60,4 @@ void tss_init(uint8_t idx, uint32_t ss0); void tss_set_stack(uint32_t kss, uint32_t kesp); /// @} -/// @} \ No newline at end of file +/// @} diff --git a/mentos/inc/io/vga/vga_palette.h b/mentos/inc/io/vga/vga_palette.h index a6eb6ff..a2addea 100644 --- a/mentos/inc/io/vga/vga_palette.h +++ b/mentos/inc/io/vga/vga_palette.h @@ -290,4 +290,4 @@ palette_entry_t ansi_256_palette[256] = { { 218, 218, 218 }, // Grey85 { 228, 228, 228 }, // Grey89 { 238, 238, 238 }, // Grey93 -}; \ No newline at end of file +}; diff --git a/mentos/inc/klib/compiler.h b/mentos/inc/klib/compiler.h index 6d5ecc6..89a5d4b 100644 --- a/mentos/inc/klib/compiler.h +++ b/mentos/inc/klib/compiler.h @@ -41,9 +41,8 @@ #pragma once - /// @brief Assign the value to the given variable. -#define WRITE_ONCE(var, val) (*((volatile typeof(val) *)(&(var))) = (val)) +#define WRITE_ONCE(var, val) (*((__volatile__ __typeof__(val) *)(&(var))) = (val)) /// @brief Read the value from the given variable. -#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) +#define READ_ONCE(var) (*((__volatile__ __typeof__(var) *)(&(var)))) diff --git a/mentos/inc/klib/stack_helper.h b/mentos/inc/klib/stack_helper.h index c06b86b..3da2807 100644 --- a/mentos/inc/klib/stack_helper.h +++ b/mentos/inc/klib/stack_helper.h @@ -12,6 +12,6 @@ /// @brief Moves the pointer up. #define __MOVE_PTR_UP(type, ptr) ((ptr) += sizeof(type)) /// @brief First, it moves the pointer down, and then it pushes the value at that memory location. -#define PUSH_VALUE_ON_STACK(ptr, value) (__ACCESS_PTR(typeof(value), __MOVE_PTR_DOWN(typeof(value), ptr)) = (value)) +#define PUSH_VALUE_ON_STACK(ptr, value) (__ACCESS_PTR(__typeof__(value), __MOVE_PTR_DOWN(__typeof__(value), ptr)) = (value)) /// @brief First, it access the value at the given memory location, and then it moves the pointer up. -#define POP_VALUE_FROM_STACK(value, ptr) ({value = __ACCESS_PTR(typeof(value), ptr); __MOVE_PTR_UP(typeof(value), ptr); }) +#define POP_VALUE_FROM_STACK(value, ptr) ({value = __ACCESS_PTR(__typeof__(value), ptr); __MOVE_PTR_UP(__typeof__(value), ptr); }) diff --git a/mentos/src/descriptor_tables/gdt.c b/mentos/src/descriptor_tables/gdt.c index ee49008..8420e3c 100644 --- a/mentos/src/descriptor_tables/gdt.c +++ b/mentos/src/descriptor_tables/gdt.c @@ -192,4 +192,4 @@ void gdt_set_gate(uint8_t index, uint32_t base, uint32_t limit, uint8_t access, // and the data selectors ds, ss, ..., should store 35 (0x23): // | 0000000000100| 0| 11| // | index 4 (data) | GDT| non-privileged| -// \ No newline at end of file +// diff --git a/mentos/src/devices/fpu.c b/mentos/src/devices/fpu.c index 592a0f8..00612dd 100644 --- a/mentos/src/devices/fpu.c +++ b/mentos/src/devices/fpu.c @@ -29,23 +29,23 @@ uint8_t saves[512] __attribute__((aligned(16))); /// @param cw What to set the control word to. static inline void __set_fpu_cw(const uint16_t cw) { - asm volatile("fldcw %0" ::"m"(cw)); + __asm__ __volatile__("fldcw %0" ::"m"(cw)); } /// @brief Enable the FPU and SSE. static inline void __enable_fpu() { - asm volatile("clts"); + __asm__ __volatile__("clts"); size_t t; - asm volatile("mov %%cr0, %0" + __asm__ __volatile__("mov %%cr0, %0" : "=r"(t)); t &= ~(1U << 2U); t |= (1U << 1U); - asm volatile("mov %0, %%cr0" ::"r"(t)); - asm volatile("mov %%cr4, %0" + __asm__ __volatile__("mov %0, %%cr0" ::"r"(t)); + __asm__ __volatile__("mov %%cr4, %0" : "=r"(t)); t |= 3U << 9U; - asm volatile("mov %0, %%cr4" ::"r"(t)); + __asm__ __volatile__("mov %0, %%cr4" ::"r"(t)); } /// Disable FPU and SSE so it traps to the kernel. @@ -53,12 +53,12 @@ static inline void __disable_fpu() { size_t t; - asm volatile("mov %%cr0, %0" + __asm__ __volatile__("mov %%cr0, %0" : "=r"(t)); t |= 1U << 3U; - asm volatile("mov %0, %%cr0" ::"r"(t)); + __asm__ __volatile__("mov %0, %%cr0" ::"r"(t)); } /// @brief Restore the FPU for a process. @@ -68,7 +68,7 @@ static inline void __restore_fpu(task_struct *proc) memcpy(&saves, (uint8_t *)&proc->thread.fpu_register, 512); - asm volatile("fxrstor (%0)" ::"r"(saves)); + __asm__ __volatile__("fxrstor (%0)" ::"r"(saves)); } /// Save the FPU for a process. @@ -76,7 +76,7 @@ static inline void __save_fpu(task_struct *proc) { assert(proc && "Trying to save FPU of NULL process."); - asm volatile("fxsave (%0)" ::"r"(saves)); + __asm__ __volatile__("fxsave (%0)" ::"r"(saves)); memcpy((uint8_t *)&proc->thread.fpu_register, &saves, 512); } @@ -84,7 +84,7 @@ static inline void __save_fpu(task_struct *proc) /// Initialize the FPU. static inline void __init_fpu() { - asm volatile("fninit"); + __asm__ __volatile__("fninit"); } /// Kernel trap for FPU usage when FPU is disabled. diff --git a/mentos/src/elf/elf.c b/mentos/src/elf/elf.c index 305191f..172e6b8 100644 --- a/mentos/src/elf/elf.c +++ b/mentos/src/elf/elf.c @@ -453,4 +453,4 @@ const char *elf_symbol_bind_to_string(int bind) if (bind == STB_WEAK) return "WEAK"; return "-1"; -} \ No newline at end of file +} diff --git a/mentos/src/io/port_io.c b/mentos/src/io/port_io.c index 918d8ee..deb9c3a 100644 --- a/mentos/src/io/port_io.c +++ b/mentos/src/io/port_io.c @@ -57,7 +57,7 @@ inline void outports(uint16_t port, uint16_t data) void outportsm(uint16_t port, uint8_t *data, uint16_t size) { - asm volatile("rep outsw" + __asm__ __volatile__("rep outsw" : "+S"(data), "+c"(size) : "d"(port)); } diff --git a/mentos/src/io/proc_system.c b/mentos/src/io/proc_system.c index 4e227fa..c0c5ee4 100644 --- a/mentos/src/io/proc_system.c +++ b/mentos/src/io/proc_system.c @@ -202,4 +202,4 @@ static ssize_t procs_do_meminfo(char *buffer, size_t bufsize) static ssize_t procs_do_stat(char *buffer, size_t bufsize) { return 0; -} \ No newline at end of file +} diff --git a/mentos/src/io/proc_video.c b/mentos/src/io/proc_video.c index 481ff33..3513602 100644 --- a/mentos/src/io/proc_video.c +++ b/mentos/src/io/proc_video.c @@ -241,4 +241,4 @@ int procv_module_init() video->sys_operations = &procv_sys_operations; video->fs_operations = &procv_fs_operations; return 0; -} \ No newline at end of file +} diff --git a/mentos/src/io/vga/vga.c b/mentos/src/io/vga/vga.c index ac759fd..6f81cbd 100644 --- a/mentos/src/io/vga/vga.c +++ b/mentos/src/io/vga/vga.c @@ -890,4 +890,4 @@ void vga_update() void vga_set_color(unsigned int color) { _color = color; -} \ No newline at end of file +} diff --git a/mentos/src/io/video.c b/mentos/src/io/video.c index aaa4f64..7f86de3 100644 --- a/mentos/src/io/video.c +++ b/mentos/src/io/video.c @@ -428,4 +428,4 @@ void video_scroll_down() stored_y = 0; } -#endif \ No newline at end of file +#endif diff --git a/mentos/src/ipc/msg.c b/mentos/src/ipc/msg.c index ee871fa..79a0bab 100644 --- a/mentos/src/ipc/msg.c +++ b/mentos/src/ipc/msg.c @@ -31,4 +31,4 @@ long sys_msgctl(int msqid, int cmd, struct msqid_ds *buf) return 0; } -///! @endcond \ No newline at end of file +///! @endcond diff --git a/mentos/src/ipc/sem.c b/mentos/src/ipc/sem.c index 6d21fca..a875d12 100644 --- a/mentos/src/ipc/sem.c +++ b/mentos/src/ipc/sem.c @@ -25,4 +25,4 @@ long sys_semctl(int semid, int semnum, int cmd, unsigned long arg) return 0; } -///! @endcond \ No newline at end of file +///! @endcond diff --git a/mentos/src/klib/libgen.c b/mentos/src/klib/libgen.c index 2a7a692..c36671d 100644 --- a/mentos/src/klib/libgen.c +++ b/mentos/src/klib/libgen.c @@ -137,4 +137,4 @@ char *realpath(const char *path, char *resolved) else resolved[1] = '\0'; return resolved; -} \ No newline at end of file +} diff --git a/mentos/src/klib/mutex.c b/mentos/src/klib/mutex.c index 58c1c25..fdc8ecd 100644 --- a/mentos/src/klib/mutex.c +++ b/mentos/src/klib/mutex.c @@ -14,12 +14,12 @@ void mutex_lock(mutex_t *mutex, uint32_t owner) while (mutex->state == 0 || failure || mutex->owner != owner) { failure = 1; if (mutex->state == 0) { - asm("movl $0x01,%%eax\n\t" // move 1 to eax - "xchg %%eax,%0\n\t" // try to set the lock bit - "mov %%eax,%1\n\t" // export our result to a test var - : "=m"(mutex->state), "=r"(failure) - : "m"(mutex->state) - : "%eax"); + __asm__ __volatile__("movl $0x01,%%eax\n\t" // move 1 to eax + "xchg %%eax,%0\n\t" // try to set the lock bit + "mov %%eax,%1\n\t" // export our result to a test var + : "=m"(mutex->state), "=r"(failure) + : "m"(mutex->state) + : "%eax"); } if (failure == 0) { mutex->owner = owner; //test to see if we got the lock bit diff --git a/mentos/src/klib/ndtree.c b/mentos/src/klib/ndtree.c index 444f7de..2356c52 100644 --- a/mentos/src/klib/ndtree.c +++ b/mentos/src/klib/ndtree.c @@ -374,4 +374,4 @@ void ndtree_tree_visitor(ndtree_t *tree, ndtree_tree_node_f enter_fun, ndtree_tr { if (tree && tree->root) __ndtree_tree_visitor_iter(tree, tree->root, enter_fun, exit_fun); -} \ No newline at end of file +} diff --git a/mentos/src/klib/time.c b/mentos/src/klib/time.c index 7fd7554..597b5ee 100644 --- a/mentos/src/klib/time.c +++ b/mentos/src/klib/time.c @@ -111,4 +111,4 @@ tm_t *localtime(const time_t *time) // Calculate day of week. date.tm_wday = day_of_week(date.tm_year, date.tm_mon, date.tm_mday); return &date; -} \ No newline at end of file +} diff --git a/mentos/src/mem/paging.c b/mentos/src/mem/paging.c index 9af1ac3..6a08d56 100644 --- a/mentos/src/mem/paging.c +++ b/mentos/src/mem/paging.c @@ -221,7 +221,7 @@ static inline void __set_pg_table_flags(page_table_entry_t *table, uint32_t flag /// @param addr The faulting address. static void __page_fault_panic(pt_regs *f, uint32_t addr) { - asm volatile("cli"); + __asm__ __volatile__("cli"); // Gather fault info and print to screen pr_err("Faulting address (cr2): 0x%p\n", addr); @@ -250,7 +250,7 @@ static void __page_fault_panic(pt_regs *f, uint32_t addr) // main_mm->pgd->entries[addr/(1024*4096)].user = 1; // main_directory->entries[addr/(1024*4096)]. = 1; - asm volatile("cli"); + __asm__ __volatile__("cli"); } static void __page_handle_cow(page_table_entry_t *entry) @@ -327,7 +327,7 @@ void page_fault_handler(pt_regs *f) // When the exception occurs, the CPU control unit stores that // value in the cr2 control register. uint32_t faulting_addr; - asm volatile("mov %%cr2, %0" + __asm__ __volatile__("mov %%cr2, %0" : "=r"(faulting_addr)); // Get the physical address of the current page directory. uint32_t phy_dir = (uint32_t)paging_get_current_directory(); diff --git a/mentos/src/mem/zone_allocator.c b/mentos/src/mem/zone_allocator.c index 99bd085..851d8dc 100644 --- a/mentos/src/mem/zone_allocator.c +++ b/mentos/src/mem/zone_allocator.c @@ -479,4 +479,4 @@ unsigned long get_zone_cached_space(gfp_t gfp_mask) zone_t *zone = get_zone_from_flags(gfp_mask); assert(zone && "Cannot retrieve the correct zone."); return buddy_system_get_cached_space(&zone->buddy_system); -} \ No newline at end of file +} diff --git a/mentos/src/process/scheduler.c b/mentos/src/process/scheduler.c index f2d3b37..23af5c3 100644 --- a/mentos/src/process/scheduler.c +++ b/mentos/src/process/scheduler.c @@ -738,4 +738,4 @@ int sys_waitperiod() // Tell the scheduler that we have executed the periodic process. current->se.executed = true; return 0; -} \ No newline at end of file +} diff --git a/mentos/src/process/scheduler_algorithm.c b/mentos/src/process/scheduler_algorithm.c index 41b1e46..c069e3d 100644 --- a/mentos/src/process/scheduler_algorithm.c +++ b/mentos/src/process/scheduler_algorithm.c @@ -247,4 +247,4 @@ static void __update_task_statistics(task_struct *task) task->se.vruntime += /* ... */; } #endif -} \ No newline at end of file +} diff --git a/mentos/src/process/wait.c b/mentos/src/process/wait.c index 3b16a10..cbd1b4c 100644 --- a/mentos/src/process/wait.c +++ b/mentos/src/process/wait.c @@ -42,4 +42,4 @@ void remove_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wq) spinlock_lock(&head->lock); __remove_wait_queue(head, wq); spinlock_unlock(&head->lock); -} \ No newline at end of file +} diff --git a/mentos/src/system/panic.c b/mentos/src/system/panic.c index 1642402..fa27d7d 100644 --- a/mentos/src/system/panic.c +++ b/mentos/src/system/panic.c @@ -10,6 +10,6 @@ void kernel_panic(const char *msg) { pr_emerg("\nPANIC:\n%s\n\nWelcome to Kernel Debugging Land...\n\n", msg); pr_emerg("\n"); - asm("cli"); // Disable interrupts - for (;;) asm("hlt"); // Decrease power consumption with hlt + __asm__ __volatile__("cli"); // Disable interrupts + for (;;) __asm__ __volatile__("hlt"); // Decrease power consumption with hlt } diff --git a/programs/tests/t_kill.c b/programs/tests/t_kill.c index 002b22c..933a2a9 100644 --- a/programs/tests/t_kill.c +++ b/programs/tests/t_kill.c @@ -11,7 +11,7 @@ #include #include -#define cpu_relax() asm volatile("pause\n" \ +#define cpu_relax() __asm__ __volatile__("pause\n" \ : \ : \ : "memory")