From 3bfa61d189c2785bee509073adafb80ec3a65995 Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Fri, 10 May 2019 12:07:35 +0200 Subject: [PATCH] Re-format the code --- mentos/CMakeLists.txt | 4 +- mentos/inc/descriptor_tables/idt.h | 46 ++-- mentos/inc/devices/pci.h | 10 +- mentos/inc/libc/limits.h | 22 +- mentos/inc/libc/list_head.h | 126 +++++----- mentos/inc/libc/queue.h | 28 +-- mentos/inc/libc/stdarg.h | 2 +- mentos/inc/libc/stddef.h | 2 +- mentos/inc/multiboot.h | 216 ++++++++--------- mentos/inc/process/prio.h | 28 +-- mentos/inc/sys/dirent.h | 34 ++- mentos/inc/sys/utsname.h | 19 +- mentos/inc/system/signal_defs.h | 76 +++--- mentos/src/descriptor_tables/idt.c | 2 +- mentos/src/devices/pci.c | 120 +++++----- mentos/src/hardware/cpuid.c | 247 +++++++++---------- mentos/src/io/port_io.c | 33 +-- mentos/src/kernel/sys.c | 93 ++++---- mentos/src/libc/hashmap.c | 341 ++++++++++++--------------- mentos/src/libc/libgen.c | 87 ++++--- mentos/src/libc/ordered_array.c | 107 ++++----- mentos/src/libc/spinlock.c | 24 +- mentos/src/libc/stdlib.c | 31 +-- mentos/src/libc/strerror.c | 5 +- mentos/src/libc/unistd/getpid.c | 6 +- mentos/src/libc/unistd/open.c | 16 +- mentos/src/libc/unistd/read.c | 15 +- mentos/src/mem/zone_allocator.c | 52 ++-- mentos/src/process/process.c | 26 +- mentos/src/sys/unistd.c | 69 +++--- mentos/src/sys/utsname.c | 12 +- mentos/src/system/printk.c | 18 +- mentos/src/ui/command/cmd_cd.c | 84 +++---- mentos/src/ui/command/cmd_drv_load.c | 94 +++----- mentos/src/ui/command/cmd_echo.c | 26 +- mentos/src/ui/command/cmd_ipcrm.c | 66 +++--- mentos/src/ui/command/cmd_ipcs.c | 103 ++++---- mentos/src/ui/command/cmd_more.c | 54 ++--- mentos/src/ui/command/cmd_newfile.c | 67 +++--- mentos/src/ui/command/cmd_pwd.c | 12 +- mentos/src/ui/command/cmd_rmdir.c | 37 ++- mentos/src/ui/command/cmd_uname.c | 4 +- 42 files changed, 1143 insertions(+), 1321 deletions(-) diff --git a/mentos/CMakeLists.txt b/mentos/CMakeLists.txt index fe6abb0..0ca358e 100644 --- a/mentos/CMakeLists.txt +++ b/mentos/CMakeLists.txt @@ -307,8 +307,8 @@ set(SOURCE_FILES if (ENABLE_BUDDY_SYSTEM MATCHES "ON") set(SOURCE_FILES - ${SOURCE_FILES} - src/mem/buddysystem.c) + ${SOURCE_FILES} + src/mem/buddysystem.c) endif (ENABLE_BUDDY_SYSTEM MATCHES "ON") # ------------------------------------------------------------------------------ diff --git a/mentos/inc/descriptor_tables/idt.h b/mentos/inc/descriptor_tables/idt.h index ee388c3..ddb388b 100644 --- a/mentos/inc/descriptor_tables/idt.h +++ b/mentos/inc/descriptor_tables/idt.h @@ -14,19 +14,19 @@ #define IDT_SIZE 256 /// When an exception occurs whose entry is a Task Gate, a task switch results. -#define TASK_GATE 0x5 +#define TASK_GATE 0x5 /// Used to specify an interrupt service routine (16-bit). -#define INT16_GATE 0x6 +#define INT16_GATE 0x6 /// @brief Similar to an Interrupt gate (16-bit). -#define TRAP16_GATE 0x7 +#define TRAP16_GATE 0x7 /// Used to specify an interrupt service routine (32-bit). -#define INT32_GATE 0xE +#define INT32_GATE 0xE /// @brief Similar to an Interrupt gate (32-bit). -#define TRAP32_GATE 0xF +#define TRAP32_GATE 0xF /* * Trap and Interrupt gates are similar, and their descriptors are @@ -36,25 +36,23 @@ */ /// @brief This structure describes one interrupt gate. -typedef struct idt_descriptor_t -{ - unsigned short offset_low; - unsigned short seg_selector; - // This will ALWAYS be set to 0. - unsigned char null_par; - // |P|DPL|01110|. - // P present, DPL required Ring (2bits). - unsigned char options; - unsigned short offset_high; +typedef struct idt_descriptor_t { + unsigned short offset_low; + unsigned short seg_selector; + // This will ALWAYS be set to 0. + unsigned char null_par; + // |P|DPL|01110|. + // P present, DPL required Ring (2bits). + unsigned char options; + unsigned short offset_high; } __attribute__((packed)) idt_descriptor_t; /// @brief A pointer structure used for informing the CPU about our IDT. -typedef struct idt_pointer_t -{ - /// The size of the IDT (entry number). - unsigned short int limit; - /// The start address of the IDT. - unsigned int base; +typedef struct idt_pointer_t { + /// The size of the IDT (entry number). + unsigned short int limit; + /// The start address of the IDT. + unsigned int base; } __attribute__((packed)) idt_pointer_t; /// @brief Initialise the interrupt descriptor table. @@ -65,10 +63,8 @@ void init_idt(); /// @param handler Puntatore alla funzione che gestira' l'interrupt/Eccezione /// @param options Le opzioni del descrittore (PRESENT,NOTPRESENT,KERNEL,USER) /// @param seg_sel Il selettore del segmento della GDT. -void idt_set_gate(uint8_t index, - interrupt_handler_t handler, - uint16_t options, - uint8_t seg_sel); +void idt_set_gate(uint8_t index, interrupt_handler_t handler, uint16_t options, + uint8_t seg_sel); //==== List of exceptions generated internally by the CPU ====================== extern void INT_0(); diff --git a/mentos/inc/devices/pci.h b/mentos/inc/devices/pci.h index aa05b6d..f517fd4 100644 --- a/mentos/inc/devices/pci.h +++ b/mentos/inc/devices/pci.h @@ -155,7 +155,7 @@ // TODO: doxygen comment. /// @brief typedef void (*pci_func_t)(uint32_t device, uint16_t vendor_id, - uint16_t device_id, void *extra); + uint16_t device_id, void *extra); // TODO: doxygen comment. /// @brief @@ -183,8 +183,8 @@ static inline int pci_extract_func(uint32_t device) static inline uint32_t pci_get_addr(uint32_t device, int field) { return 0x80000000 | (pci_extract_bus(device) << 16) | - (pci_extract_slot(device) << 11) | - (pci_extract_func(device) << 8) | ((field)&0xFC); + (pci_extract_slot(device) << 11) | (pci_extract_func(device) << 8) | + ((field)&0xFC); } // TODO: doxygen comment. @@ -212,7 +212,7 @@ const char *pci_vendor_lookup(unsigned short vendor_id); // TODO: doxygen comment. /// @brief const char *pci_device_lookup(unsigned short vendor_id, - unsigned short device_id); + unsigned short device_id); // TODO: doxygen comment. /// @brief void pci_scan_hit(pci_func_t f, uint32_t dev, void *extra); @@ -220,7 +220,7 @@ void pci_scan_hit(pci_func_t f, uint32_t dev, void *extra); // TODO: doxygen comment. /// @brief void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, - void *extra); + void *extra); // TODO: doxygen comment. /// @brief diff --git a/mentos/inc/libc/limits.h b/mentos/inc/libc/limits.h index 9b09ccf..36e92e6 100644 --- a/mentos/inc/libc/limits.h +++ b/mentos/inc/libc/limits.h @@ -7,35 +7,35 @@ #pragma once /// Number of bits in a `char'. -#define CHAR_BIT 8 +#define CHAR_BIT 8 /// Minimum value a `signed char' can hold. -#define SCHAR_MIN (-128) +#define SCHAR_MIN (-128) /// Maximum value a `signed char' can hold. -#define SCHAR_MAX 127 +#define SCHAR_MAX 127 /// Maximum value a `char' can hold. (Minimum is 0.) -#define CHAR_MAX 255 +#define CHAR_MAX 255 /// Minimum value a `signed short int' can hold. -#define SHRT_MIN (-32768) +#define SHRT_MIN (-32768) /// Maximum value a `signed short int' can hold. -#define SHRT_MAX 32767 +#define SHRT_MAX 32767 /// Minimum value a `signed int' can hold. -#define INT_MIN (-INT_MAX - 1) +#define INT_MIN (-INT_MAX - 1) /// Maximum values a `signed int' can hold. -#define INT_MAX 2147483647 +#define INT_MAX 2147483647 /// Maximum value an `unsigned int' can hold. (Minimum is 0.) -#define UINT_MAX 4294967295U +#define UINT_MAX 4294967295U /// Minimum value a `signed long int' can hold. -#define LONG_MAX 2147483647L +#define LONG_MAX 2147483647L /// Maximum value a `signed long int' can hold. -#define LONG_MIN (-LONG_MAX - 1L) +#define LONG_MIN (-LONG_MAX - 1L) diff --git a/mentos/inc/libc/list_head.h b/mentos/inc/libc/list_head.h index f3a0641..2af28ec 100644 --- a/mentos/inc/libc/list_head.h +++ b/mentos/inc/libc/list_head.h @@ -9,125 +9,121 @@ #include "stddef.h" /// @brief Structure used to implement the list_head data structure. -typedef struct list_head -{ - /// @brief The previous element. - struct list_head * prev; - /// @brief The subsequent element. - struct list_head * next; +typedef struct list_head { + /// @brief The previous element. + struct list_head *prev; + /// @brief The subsequent element. + struct list_head *next; } list_head; /// @brief Get the struct for this entry. /// @param ptr The &struct list_head pointer. /// @param type The type of the struct this is embedded in. /// @param member The name of the list_head within the struct. -#define list_entry(ptr, type, member) \ - ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member))) +#define list_entry(ptr, type, member) \ + ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member))) /// @brief Iterates over a list. /// @param pos The &struct list_head to use as a loop cursor. /// @param head The head for your list. -#define list_for_each(pos, head) \ - for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next) +#define list_for_each(pos, head) \ + for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next) /// @brief Iterates over a list backwards. /// @param pos The &struct list_head to use as a loop cursor. /// @param head The head for your list. -#define list_for_each_prev(pos, head) \ - for ((pos) = (head)->prev; (pos) != (head); (pos) = (pos)->prev) +#define list_for_each_prev(pos, head) \ + for ((pos) = (head)->prev; (pos) != (head); (pos) = (pos)->prev) /// @brief Iterates over a list safe against removal of list entry. /// @param pos The &struct list_head to use as a loop cursor. /// @param store Another &struct list_head to use as temporary storage. /// @param head The head for your list. -#define list_for_each_safe(pos, store, head) \ - for ((pos) = (head)->next, (store) = (pos)->next; (pos) != (head); \ - (pos) = (store), (store) = (pos)->next) +#define list_for_each_safe(pos, store, head) \ + for ((pos) = (head)->next, (store) = (pos)->next; (pos) != (head); \ + (pos) = (store), (store) = (pos)->next) /// @brief Initializes the list_head. /// @param head The head for your list. -#define list_head_init(head) \ - (head)->next = (head)->prev = (head) +#define list_head_init(head) (head)->next = (head)->prev = (head) /// @brief Insert element l2 after l1. -static inline void list_head_insert_after(list_head * l1, list_head * l2) +static inline void list_head_insert_after(list_head *l1, list_head *l2) { - // [La]->l1 La<-[l1]->Lb <-[l2]-> l1<-[Lb] + // [La]->l1 La<-[l1]->Lb <-[l2]-> l1<-[Lb] - list_head * l1_next = l1->next; - // [La]->l1 La<-[l1]->l2 <-[l2]-> l1<-[Lb] - l1->next = l2; - // [La]->l1 La<-[l1]->l2 l1<-[l2]-> l1<-[Lb] - l2->prev = l1; - // [La]->l1 La<-[l1]->l2 l1<-[l2]->Lb l1<-[Lb] - l2->next = l1_next; - // [La]->l1 La<-[l1]->l2 l1<-[l2]->Lb l2<-[Lb] - l1_next->prev = l2; + list_head *l1_next = l1->next; + // [La]->l1 La<-[l1]->l2 <-[l2]-> l1<-[Lb] + l1->next = l2; + // [La]->l1 La<-[l1]->l2 l1<-[l2]-> l1<-[Lb] + l2->prev = l1; + // [La]->l1 La<-[l1]->l2 l1<-[l2]->Lb l1<-[Lb] + l2->next = l1_next; + // [La]->l1 La<-[l1]->l2 l1<-[l2]->Lb l2<-[Lb] + l1_next->prev = l2; } /// @brief Insert element l2 before l1. -static inline void list_head_insert_before(list_head * l1, list_head * l2) +static inline void list_head_insert_before(list_head *l1, list_head *l2) { - // [La]->l1 [l2] La<-[l1]->Lb l1<-[Lb] + // [La]->l1 [l2] La<-[l1]->Lb l1<-[Lb] - list_head * l1_prev = l1->prev; - // [La]->l2 [l2] La<-[l1]->Lb l1<-[Lb] - l1_prev->next = l2; - // [La]->l2 La<-[l2] La<-[l1]->Lb l1<-[Lb] - l2->prev = l1_prev; - // [La]->l2 La<-[l2]->l1 La<-[l1]->Lb l1<-[Lb] - l2->next = l1; - // [La]->l2 La<-[l2]->l1 l2<-[l1]->Lb l1<-[Lb] - l1->prev = l2; + list_head *l1_prev = l1->prev; + // [La]->l2 [l2] La<-[l1]->Lb l1<-[Lb] + l1_prev->next = l2; + // [La]->l2 La<-[l2] La<-[l1]->Lb l1<-[Lb] + l2->prev = l1_prev; + // [La]->l2 La<-[l2]->l1 La<-[l1]->Lb l1<-[Lb] + l2->next = l1; + // [La]->l2 La<-[l2]->l1 l2<-[l1]->Lb l1<-[Lb] + l1->prev = l2; } /// @brief Remove l from the list. /// @param l The element to remove. -static inline void list_head_del(list_head * l) +static inline void list_head_del(list_head *l) { - // [La]->l La<-[l]->Lb l<-[Lb] + // [La]->l La<-[l]->Lb l<-[Lb] - // [La]->Lb La<-[l]->Lb l<-[Lb] - l->prev->next = l->next; - // [La]->Lb La<-[l]->Lb La<-[Lb] - l->next->prev = l->prev; - // [La]->Lb l<-[l]->l La<-[Lb] - l->next = l->prev = l; + // [La]->Lb La<-[l]->Lb l<-[Lb] + l->prev->next = l->next; + // [La]->Lb La<-[l]->Lb La<-[Lb] + l->next->prev = l->prev; + // [La]->Lb l<-[l]->l La<-[Lb] + l->next = l->prev = l; } /// @brief Tests whether the given list is empty. /// @param head The list to check. /// @return 1 if empty, 0 otherwise. -static inline int list_head_empty(list_head const * head) +static inline int list_head_empty(list_head const *head) { - return head->next == head; + return head->next == head; } /// Insert a new entry between two known consecutive entries. -static inline void __list_add(list_head * new, - list_head * prev, - list_head * next) +static inline void __list_add(list_head *new, list_head *prev, list_head *next) { - // [prev]-> <-[new]-> <-[next] + // [prev]-> <-[new]-> <-[next] - // [prev]-> <-[new]-> new<-[next] - next->prev = new; - // [prev]-> <-[new]->next new<-[next] - new->next = next; - // [prev]-> prev<-[new]->next new<-[next] - new->prev = prev; - // [prev]->new prev<-[new]->next new<-[next] - prev->next = new; + // [prev]-> <-[new]-> new<-[next] + next->prev = new; + // [prev]-> <-[new]->next new<-[next] + new->next = next; + // [prev]-> prev<-[new]->next new<-[next] + new->prev = prev; + // [prev]->new prev<-[new]->next new<-[next] + prev->next = new; } /// @brief Insert element l2 before l1. -static inline void list_head_add(list_head * new, list_head * head) +static inline void list_head_add(list_head *new, list_head *head) { - __list_add(new, head, head->next); + __list_add(new, head, head->next); } /// @brief Insert element l2 before l1. -static inline void list_head_add_tail(list_head * new, list_head * head) +static inline void list_head_add_tail(list_head *new, list_head *head) { - __list_add(new, head->prev, head); + __list_add(new, head->prev, head); } diff --git a/mentos/inc/libc/queue.h b/mentos/inc/libc/queue.h index ca7a1f9..599d507 100644 --- a/mentos/inc/libc/queue.h +++ b/mentos/inc/libc/queue.h @@ -10,24 +10,22 @@ #include "stdbool.h" /// @brief A node of the queue. -typedef struct queue_node_t -{ - /// The wrapped data. - void *data; - /// The next node of the queue. - struct queue_node_t *next; +typedef struct queue_node_t { + /// The wrapped data. + void *data; + /// The next node of the queue. + struct queue_node_t *next; } queue_node_t; /// @brief The queue. -typedef struct queue_t -{ - /// The front of the queue. - queue_node_t *front; - /// The back of the queue. - queue_node_t *back; - /// The size of the data contained inside the queue. - size_t data_size; -} *queue_t; +typedef struct queue_t { + /// The front of the queue. + queue_node_t *front; + /// The back of the queue. + queue_node_t *back; + /// The size of the data contained inside the queue. + size_t data_size; +} * queue_t; /// @brief Creates a queue. /// @param data_size The size of the stored elements. diff --git a/mentos/inc/libc/stdarg.h b/mentos/inc/libc/stdarg.h index c36e914..6890b22 100644 --- a/mentos/inc/libc/stdarg.h +++ b/mentos/inc/libc/stdarg.h @@ -17,7 +17,7 @@ typedef char *va_list; /// @brief Amount of space required in an argument list (ie. the stack) for an /// argument of type t. #define va_size(t) \ - (((sizeof(t) + sizeof(va_item) - 1) / sizeof(va_item)) * sizeof(va_item)) + (((sizeof(t) + sizeof(va_item) - 1) / sizeof(va_item)) * sizeof(va_item)) /// @brief The start of a variadic list. #define va_start(ap, last_arg) (ap = ((va_list)(&last_arg) + va_size(last_arg))) diff --git a/mentos/inc/libc/stddef.h b/mentos/inc/libc/stddef.h index 04a4a03..9098592 100644 --- a/mentos/inc/libc/stddef.h +++ b/mentos/inc/libc/stddef.h @@ -9,7 +9,7 @@ #ifndef NULL /// @brief Define NULL. -#define NULL ((void*)0) +#define NULL ((void *)0) #endif diff --git a/mentos/inc/multiboot.h b/mentos/inc/multiboot.h index 237f5b2..6a282d4 100644 --- a/mentos/inc/multiboot.h +++ b/mentos/inc/multiboot.h @@ -10,43 +10,43 @@ #include "stdint.h" -#define MULTIBOOT_FLAG_MEM 0x001 +#define MULTIBOOT_FLAG_MEM 0x001 -#define MULTIBOOT_FLAG_DEVICE 0x002 +#define MULTIBOOT_FLAG_DEVICE 0x002 #define MULTIBOOT_FLAG_CMDLINE 0x004 -#define MULTIBOOT_FLAG_MODS 0x008 +#define MULTIBOOT_FLAG_MODS 0x008 -#define MULTIBOOT_FLAG_AOUT 0x010 +#define MULTIBOOT_FLAG_AOUT 0x010 -#define MULTIBOOT_FLAG_ELF 0x020 +#define MULTIBOOT_FLAG_ELF 0x020 -#define MULTIBOOT_FLAG_MMAP 0x040 +#define MULTIBOOT_FLAG_MMAP 0x040 -#define MULTIBOOT_FLAG_CONFIG 0x080 +#define MULTIBOOT_FLAG_CONFIG 0x080 -#define MULTIBOOT_FLAG_LOADER 0x100 +#define MULTIBOOT_FLAG_LOADER 0x100 -#define MULTIBOOT_FLAG_APM 0x200 +#define MULTIBOOT_FLAG_APM 0x200 -#define MULTIBOOT_FLAG_VBE 0x400 +#define MULTIBOOT_FLAG_VBE 0x400 -#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_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 // +-------------------+ // 0 | flags | (required) @@ -93,130 +93,120 @@ // +-------------------+ /// The symbol table for a.out. -typedef struct multiboot_aout_symbol_table -{ - uint32_t tabsize; - uint32_t strsize; - uint32_t addr; - uint32_t reserved; +typedef struct multiboot_aout_symbol_table { + uint32_t tabsize; + uint32_t strsize; + uint32_t addr; + uint32_t reserved; } multiboot_aout_symbol_table_t; /// The section header table for ELF. -typedef struct multiboot_elf_section_header_table -{ - uint32_t num; - uint32_t size; - uint32_t addr; - uint32_t shndx; +typedef struct multiboot_elf_section_header_table { + uint32_t num; + uint32_t size; + uint32_t addr; + uint32_t shndx; } multiboot_elf_section_header_table_t; // TODO: doxygen comment. -typedef struct multiboot_mod_list -{ - // The memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive. - uint32_t mod_start; - uint32_t mod_end; - // Module command line. - uint32_t cmdline; - // Padding to take it to 16 bytes (must be zero). - uint32_t pad; +typedef struct multiboot_mod_list { + // The memory used goes from bytes 'mod_start' to 'mod_end-1' inclusive. + uint32_t mod_start; + uint32_t mod_end; + // Module command line. + uint32_t cmdline; + // Padding to take it to 16 bytes (must be zero). + uint32_t pad; } multiboot_module_t; // TODO: doxygen comment. -typedef struct multiboot_mmap_entry -{ - uint32_t size; - uint64_t addr; - uint64_t len; - uint32_t type; +typedef struct multiboot_mmap_entry { + uint32_t size; + uint64_t addr; + uint64_t len; + uint32_t type; } __attribute__((packed)) multiboot_memory_map_t; // TODO: doxygen comment. -typedef struct multiboot_info -{ - /// Multiboot info version number. - uint32_t flags; +typedef struct multiboot_info { + /// Multiboot info version number. + uint32_t flags; - /// Available memory from BIOS. - uint32_t mem_lower; - uint32_t mem_upper; + /// Available memory from BIOS. + uint32_t mem_lower; + uint32_t mem_upper; - /// "root" partition. - uint32_t boot_device; + /// "root" partition. + uint32_t boot_device; - /// Kernel command line. - uint32_t cmdline; + /// Kernel command line. + uint32_t cmdline; - /// Boot-Module list. - uint32_t mods_count; - uint32_t mods_addr; + /// Boot-Module list. + uint32_t mods_count; + uint32_t mods_addr; - union - { - multiboot_aout_symbol_table_t aout_sym; - multiboot_elf_section_header_table_t elf_sec; - } u; + union { + multiboot_aout_symbol_table_t aout_sym; + multiboot_elf_section_header_table_t elf_sec; + } u; - /// Memory Mapping buffer. - uint32_t mmap_length; - uint32_t mmap_addr; + /// Memory Mapping buffer. + uint32_t mmap_length; + uint32_t mmap_addr; - /// Drive Info buffer. - uint32_t drives_length; - uint32_t drives_addr; + /// Drive Info buffer. + uint32_t drives_length; + uint32_t drives_addr; - /// ROM configuration table. - uint32_t config_table; + /// ROM configuration table. + uint32_t config_table; - /// Boot Loader Name. - uint32_t boot_loader_name; + /// Boot Loader Name. + uint32_t boot_loader_name; - /// APM table. - uint32_t apm_table; + /// APM table. + uint32_t apm_table; - /// Video. - uint32_t vbe_control_info; - uint32_t vbe_mode_info; - uint32_t vbe_mode; - uint32_t vbe_interface_seg; - uint32_t vbe_interface_off; - uint32_t vbe_interface_len; + /// Video. + uint32_t vbe_control_info; + uint32_t vbe_mode_info; + uint32_t vbe_mode; + uint32_t vbe_interface_seg; + uint32_t vbe_interface_off; + uint32_t vbe_interface_len; - uint32_t framebuffer_addr; - uint32_t framebuffer_pitch; - uint32_t framebuffer_width; - uint32_t framebuffer_height; - uint32_t framebuffer_bpp; - uint32_t framebuffer_type; - union - { - struct - { - uint32_t framebuffer_palette_addr; - uint16_t framebuffer_palette_num_colors; - }; - struct - { - uint8_t framebuffer_red_field_position; - uint8_t framebuffer_red_mask_size; - uint8_t framebuffer_green_field_position; - uint8_t framebuffer_green_mask_size; - uint8_t framebuffer_blue_field_position; - uint8_t framebuffer_blue_mask_size; - }; - }; + uint32_t framebuffer_addr; + uint32_t framebuffer_pitch; + uint32_t framebuffer_width; + uint32_t framebuffer_height; + uint32_t framebuffer_bpp; + uint32_t framebuffer_type; + union { + struct { + uint32_t framebuffer_palette_addr; + uint16_t framebuffer_palette_num_colors; + }; + struct { + uint8_t framebuffer_red_field_position; + uint8_t framebuffer_red_mask_size; + uint8_t framebuffer_green_field_position; + uint8_t framebuffer_green_mask_size; + uint8_t framebuffer_blue_field_position; + uint8_t framebuffer_blue_mask_size; + }; + }; } __attribute__((packed)) multiboot_info_t; // Be careful that the offset 0 is base_addr_low but no size. /// @brief The memory map. -typedef struct memory_map -{ - uint32_t size; - uint32_t base_addr_low; - uint32_t base_addr_high; - uint32_t length_low; - uint32_t length_high; - uint32_t type; +typedef struct memory_map { + uint32_t size; + uint32_t base_addr_low; + uint32_t base_addr_high; + uint32_t length_low; + uint32_t length_high; + uint32_t type; } memory_map_t; // TODO: doxygen comment. diff --git a/mentos/inc/process/prio.h b/mentos/inc/process/prio.h index b5fbfe2..82a4a63 100644 --- a/mentos/inc/process/prio.h +++ b/mentos/inc/process/prio.h @@ -4,11 +4,11 @@ /// @copyright (c) 2019 This file is distributed under the MIT License. /// See LICENSE.md for details. -#define MAX_NICE +19 +#define MAX_NICE +19 -#define MIN_NICE -20 +#define MIN_NICE -20 -#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1) +#define NICE_WIDTH (MAX_NICE - MIN_NICE + 1) // Priority of a process goes from 0..MAX_PRIO-1, valid RT // priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH @@ -23,7 +23,7 @@ #define MAX_RT_PRIO 100 -#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH) +#define MAX_PRIO (MAX_RT_PRIO + NICE_WIDTH) #define DEFAULT_PRIO (MAX_RT_PRIO + NICE_WIDTH / 2) @@ -32,24 +32,24 @@ // and back. #define NICE_TO_PRIO(nice) ((nice) + DEFAULT_PRIO) -#define PRIO_TO_NICE(prio) ((prio) - DEFAULT_PRIO) +#define PRIO_TO_NICE(prio) ((prio)-DEFAULT_PRIO) // 'User priority' is the nice value converted to something we // can work with better when scaling various scheduler parameters, // it's a [ 0 ... 39 ] range. -#define USER_PRIO(p) ((p)-MAX_RT_PRIO) +#define USER_PRIO(p) ((p)-MAX_RT_PRIO) #define TASK_USER_PRIO(p) USER_PRIO((p)->static_prio) #define MAX_USER_PRIO (USER_PRIO(MAX_PRIO)) static const int prio_to_weight[NICE_WIDTH] = { - /* 100 */ 88761, 71755, 56483, 46273, 36291, - /* 105 */ 29154, 23254, 18705, 14949, 11916, - /* 110 */ 9548, 7620, 6100, 4904, 3906, - /* 115 */ 3121, 2501, 1991, 1586, 1277, - /* 120 */ 1024, 820, 655, 526, 423, - /* 125 */ 335, 272, 215, 172, 137, - /* 130 */ 110, 87, 70, 56, 45, - /* 135 */ 36, 29, 23, 18, 15 + /* 100 */ 88761, 71755, 56483, 46273, 36291, + /* 105 */ 29154, 23254, 18705, 14949, 11916, + /* 110 */ 9548, 7620, 6100, 4904, 3906, + /* 115 */ 3121, 2501, 1991, 1586, 1277, + /* 120 */ 1024, 820, 655, 526, 423, + /* 125 */ 335, 272, 215, 172, 137, + /* 130 */ 110, 87, 70, 56, 45, + /* 135 */ 36, 29, 23, 18, 15 }; diff --git a/mentos/inc/sys/dirent.h b/mentos/inc/sys/dirent.h index ae2a3ae..9ac6e2c 100644 --- a/mentos/inc/sys/dirent.h +++ b/mentos/inc/sys/dirent.h @@ -12,32 +12,30 @@ #define NAME_MAX 30 /// @brief Contains the entries of a directory. -typedef struct dirent_t -{ - /// The inode of the entry. - ino_t d_ino; +typedef struct dirent_t { + /// The inode of the entry. + ino_t d_ino; - /// The type of the entry. - int d_type; + /// The type of the entry. + int d_type; - /// The nam of the entry. - char d_name[NAME_MAX + 1]; + /// The nam of the entry. + char d_name[NAME_MAX + 1]; } dirent_t; /// @brief Contains information concerning a directory. -typedef struct DIR -{ - /// Filesystem directory handle. - int handle; +typedef struct DIR { + /// Filesystem directory handle. + int handle; - /// The currently opened entry. - ino_t cur_entry; + /// The currently opened entry. + ino_t cur_entry; - /// Path to the directory. - char path[NAME_MAX + 1]; + /// Path to the directory. + char path[NAME_MAX + 1]; - /// Next directory item. - dirent_t entry; + /// Next directory item. + dirent_t entry; } DIR; /// @brief Opens a directory and returns a handler to it. diff --git a/mentos/inc/sys/utsname.h b/mentos/inc/sys/utsname.h index 461ebd6..c79cc74 100644 --- a/mentos/inc/sys/utsname.h +++ b/mentos/inc/sys/utsname.h @@ -10,19 +10,18 @@ #define SYS_LEN 257 /// @brief Holds information concerning the machine and the os. -typedef struct utsname_t -{ - /// The name of the system. - char sysname[SYS_LEN]; +typedef struct utsname_t { + /// The name of the system. + char sysname[SYS_LEN]; - /// The name of the node. - char nodename[SYS_LEN]; + /// The name of the node. + char nodename[SYS_LEN]; - /// The version of the OS. - char version[SYS_LEN]; + /// The version of the OS. + char version[SYS_LEN]; - /// The name of the machine. - char machine[SYS_LEN]; + /// The name of the machine. + char machine[SYS_LEN]; } utsname_t; /// @brief Sets the values of os_infos. diff --git a/mentos/inc/system/signal_defs.h b/mentos/inc/system/signal_defs.h index 3057c07..d06a730 100644 --- a/mentos/inc/system/signal_defs.h +++ b/mentos/inc/system/signal_defs.h @@ -7,115 +7,115 @@ // Signal names (from the Unix specification on signals) /// Hangup. -#define SIGHUP 1 +#define SIGHUP 1 /// Interupt. -#define SIGINT 2 +#define SIGINT 2 /// Quit. -#define SIGQUIT 3 +#define SIGQUIT 3 /// Illegal instruction. -#define SIGILL 4 +#define SIGILL 4 /// A breakpoint or trace instruction has been reached. -#define SIGTRAP 5 +#define SIGTRAP 5 /// Another process has requested that you abort. -#define SIGABRT 6 +#define SIGABRT 6 /// Emulation trap XXX. -#define SIGEMT 7 +#define SIGEMT 7 /// Floating-point arithmetic exception. -#define SIGFPE 8 +#define SIGFPE 8 /// You have been stabbed repeated with a large knife. -#define SIGKILL 9 +#define SIGKILL 9 /// Bus error (device error). -#define SIGBUS 10 +#define SIGBUS 10 /// Segmentation fault. -#define SIGSEGV 11 +#define SIGSEGV 11 /// Bad system call. -#define SIGSYS 12 +#define SIGSYS 12 /// Attempted to read or write from a broken pipe. -#define SIGPIPE 13 +#define SIGPIPE 13 /// This is your wakeup call. -#define SIGALRM 14 +#define SIGALRM 14 /// You have been Schwarzenegger'd. -#define SIGTERM 15 +#define SIGTERM 15 /// User Defined Signal #1. -#define SIGUSR1 16 +#define SIGUSR1 16 /// User Defined Signal #2. -#define SIGUSR2 17 +#define SIGUSR2 17 /// Child status report. -#define SIGCHLD 18 +#define SIGCHLD 18 /// We need moar powah!. -#define SIGPWR 19 +#define SIGPWR 19 /// Your containing terminal has changed size. -#define SIGWINCH 20 +#define SIGWINCH 20 /// An URGENT! event (On a socket). -#define SIGURG 21 +#define SIGURG 21 /// XXX OBSOLETE; socket i/o possible. -#define SIGPOLL 22 +#define SIGPOLL 22 /// Stopped (signal). -#define SIGSTOP 23 +#define SIGSTOP 23 /// ^Z (suspend). -#define SIGTSTP 24 +#define SIGTSTP 24 /// Unsuspended (please, continue). -#define SIGCONT 25 +#define SIGCONT 25 /// TTY input has stopped. -#define SIGTTIN 26 +#define SIGTTIN 26 /// TTY output has stopped. -#define SIGTTOUT 27 +#define SIGTTOUT 27 /// Virtual timer has expired. -#define SIGVTALRM 28 +#define SIGVTALRM 28 /// Profiling timer expired. -#define SIGPROF 29 +#define SIGPROF 29 /// CPU time limit exceeded. -#define SIGXCPU 30 +#define SIGXCPU 30 /// File size limit exceeded. -#define SIGXFSZ 31 +#define SIGXFSZ 31 /// Herp. -#define SIGWAITING 32 +#define SIGWAITING 32 /// Die in a fire. -#define SIGDIAF 33 +#define SIGDIAF 33 /// The sending process does not like you. -#define SIGHATE 34 +#define SIGHATE 34 /// Window server event. #define SIGWINEVENT 35 /// Everybody loves cats. -#define SIGCAT 36 +#define SIGCAT 36 -#define SIGTTOU 37 +#define SIGTTOU 37 -#define NUMSIGNALS 38 +#define NUMSIGNALS 38 -#define NSIG NUMSIGNALS +#define NSIG NUMSIGNALS diff --git a/mentos/src/descriptor_tables/idt.c b/mentos/src/descriptor_tables/idt.c index 3823834..ce15413 100644 --- a/mentos/src/descriptor_tables/idt.c +++ b/mentos/src/descriptor_tables/idt.c @@ -114,7 +114,7 @@ void init_idt() } void idt_set_gate(uint8_t index, interrupt_handler_t handler, uint16_t options, - uint8_t seg_sel) + uint8_t seg_sel) { uint32_t base_prt = (uint32_t)handler; diff --git a/mentos/src/devices/pci.c b/mentos/src/devices/pci.c index 6074f26..086feb0 100644 --- a/mentos/src/devices/pci.c +++ b/mentos/src/devices/pci.c @@ -44,17 +44,17 @@ uint32_t pci_read_field(uint32_t device, int field, int size) uint32_t pci_find_type(uint32_t device) { return pci_read_field(device, PCI_CLASS, 1) << 16 | - pci_read_field(device, PCI_SUBCLASS, 1) << 8 | - pci_read_field(device, PCI_PROG_IF, 1); + pci_read_field(device, PCI_SUBCLASS, 1) << 8 | + pci_read_field(device, PCI_PROG_IF, 1); } struct { uint16_t id; const char *name; } _pci_vendors[] = { - { 0x1022, "AMD" }, { 0x106b, "Apple, Inc." }, + { 0x1022, "AMD" }, { 0x106b, "Apple, Inc." }, { 0x1234, "Bochs/QEMU" }, { 0x1274, "Ensoniq" }, - { 0x15ad, "VMWare" }, { 0x8086, "Intel Corporation" }, + { 0x15ad, "VMWare" }, { 0x8086, "Intel Corporation" }, { 0x80EE, "VirtualBox" }, }; @@ -97,18 +97,16 @@ struct { { 0x010100, "ISA Compatibility mode-only controller" }, { 0x010105, "PCI native mode-only controller" }, { 0x01010a, "ISA Compatibility mode controller, supports both channels " - "switched to PCI native mode" }, - { 0x01010f, - "PCI native mode controller, supports both channels switched " - "to ISA compatibility mode" }, + "switched to PCI native mode" }, + { 0x01010f, "PCI native mode controller, supports both channels switched " + "to ISA compatibility mode" }, { 0x010180, "ISA Compatibility mode-only controller, supports bus mastering" }, { 0x010185, "PCI native mode-only controller, supports bus mastering" }, { 0x01018a, "ISA Compatibility mode controller, supports both channels " - "switched to PCI native mode, supports bus mastering" }, - { 0x01018f, - "PCI native mode controller, supports both channels switched " - "\to ISA compatibility mode, supports bus mastering" }, + "switched to PCI native mode, supports bus mastering" }, + { 0x01018f, "PCI native mode controller, supports both channels switched " + "\to ISA compatibility mode, supports bus mastering" }, { 0x010200, "Floppy disk controller" }, { 0x010300, "IPI bus controller" }, @@ -154,10 +152,8 @@ struct { { 0x060600, "NuBus bridge" }, { 0x060700, "CardBus bridge" }, // { 0x0608xx , "RACEway bridge" }, - { 0x060940, - "PCI-to-PCI bridge, Semi-transparent, primary facing Host" }, - { 0x060980, - "PCI-to-PCI bridge, Semi-transparent, secondary facing Host" }, + { 0x060940, "PCI-to-PCI bridge, Semi-transparent, primary facing Host" }, + { 0x060980, "PCI-to-PCI bridge, Semi-transparent, secondary facing Host" }, { 0x060A00, "InfiniBand-to-PCI host bridge" }, { 0x068000, "Bridge device" }, @@ -273,8 +269,7 @@ struct { const char *pci_vendor_lookup(unsigned short vendor_id) { - for (int i = 0; i < sizeof(_pci_vendors) / sizeof(_pci_vendors[0]); - ++i) { + for (int i = 0; i < sizeof(_pci_vendors) / sizeof(_pci_vendors[0]); ++i) { if (_pci_vendors[i].id == vendor_id) { return _pci_vendors[i].name; } @@ -284,12 +279,11 @@ const char *pci_vendor_lookup(unsigned short vendor_id) } const char *pci_device_lookup(unsigned short vendor_id, - unsigned short device_id) + unsigned short device_id) { - for (int i = 0; i < sizeof(_pci_devices) / sizeof(_pci_devices[0]); - ++i) { + for (int i = 0; i < sizeof(_pci_devices) / sizeof(_pci_devices[0]); ++i) { if (_pci_devices[i].ven_id == vendor_id && - _pci_devices[i].dev_id == device_id) { + _pci_devices[i].dev_id == device_id) { return _pci_devices[i].name; } } @@ -299,8 +293,7 @@ const char *pci_device_lookup(unsigned short vendor_id, const char *pci_class_lookup(uint32_t class_code) { - for (int i = 0; i < sizeof(_pci_classes) / sizeof(_pci_classes[0]); - ++i) { + for (int i = 0; i < sizeof(_pci_classes) / sizeof(_pci_classes[0]); ++i) { if (_pci_classes[i].id == class_code) { return _pci_classes[i].name; } @@ -317,7 +310,7 @@ void pci_scan_hit(pci_func_t f, uint32_t dev, void *extra) } void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, - void *extra) + void *extra) { uint32_t dev = pci_box_device(bus, slot, func); @@ -325,8 +318,7 @@ void pci_scan_func(pci_func_t f, int type, int bus, int slot, int func, pci_scan_hit(f, dev, extra); } if (pci_find_type(dev) == PCI_TYPE_BRIDGE) { - pci_scan_bus(f, type, pci_read_field(dev, PCI_SECONDARY_BUS, 1), - extra); + pci_scan_bus(f, type, pci_read_field(dev, PCI_SECONDARY_BUS, 1), extra); } } @@ -378,7 +370,7 @@ void pci_scan(pci_func_t f, int type, void *extra) } static void find_isa_bridge(uint32_t device, uint16_t vendorid, - uint16_t deviceid, void *extra) + uint16_t deviceid, void *extra) { if (vendorid == 0x8086 && (deviceid == 0x7000 || deviceid == 0x7110)) { *((uint32_t *)extra) = device; @@ -423,11 +415,10 @@ int pci_get_interrupt(uint32_t device) uint32_t int_line = pci_read_field(device, PCI_INTERRUPT_LINE, 1); - dbg_print( - "Slot is %d, irq pin is %d, so pirq is %d and that maps to %d?" - "int_line=%d\n", - pci_extract_slot(device), irq_pin, pirq, pci_remaps[pirq], - int_line); + dbg_print("Slot is %d, irq pin is %d, so pirq is %d and that maps to %d?" + "int_line=%d\n", + pci_extract_slot(device), irq_pin, pirq, pci_remaps[pirq], + int_line); if (pci_remaps[pirq] == 0x80) { dbg_print("Not mapped, remapping?\n"); @@ -442,7 +433,7 @@ int pci_get_interrupt(uint32_t device) } static void scan_count(uint32_t device, uint16_t vendorid, uint16_t deviceid, - void *extra) + void *extra) { (void)device; (void)vendorid; @@ -452,61 +443,56 @@ static void scan_count(uint32_t device, uint16_t vendorid, uint16_t deviceid, } static void scan_hit_list(uint32_t device, uint16_t vendorid, uint16_t deviceid, - void *extra) + void *extra) { (void)extra; - dbg_print("%2x:%2x.%d\n", pci_extract_bus(device), - pci_extract_slot(device), pci_extract_func(device), deviceid); + dbg_print("%2x:%2x.%d\n", pci_extract_bus(device), pci_extract_slot(device), + pci_extract_func(device), deviceid); dbg_print(" Vendor : [0x%06x] %s\n", vendorid, - pci_vendor_lookup(vendorid)); + pci_vendor_lookup(vendorid)); dbg_print(" Device : [0x%06x] %s\n", deviceid, - pci_device_lookup(vendorid, deviceid)); + pci_device_lookup(vendorid, deviceid)); dbg_print(" Type : [0x%06x] %s\n", pci_find_type(device), - pci_class_lookup(pci_find_type(device))); + pci_class_lookup(pci_find_type(device))); dbg_print(" Status : 0x%4x\n", - pci_read_field(device, PCI_STATUS, 2)); + pci_read_field(device, PCI_STATUS, 2)); dbg_print(" Command : 0x%4x\n", - pci_read_field(device, PCI_COMMAND, 2)); + pci_read_field(device, PCI_COMMAND, 2)); dbg_print(" Revision : %2d\n", - pci_read_field(device, PCI_REVISION_ID, 1)); + pci_read_field(device, PCI_REVISION_ID, 1)); dbg_print(" Cache Line Size : %2d\n", - pci_read_field(device, PCI_CACHE_LINE_SIZE, 1)); + pci_read_field(device, PCI_CACHE_LINE_SIZE, 1)); dbg_print(" Latency Timer : %2d\n", - pci_read_field(device, PCI_LATENCY_TIMER, 1)); + pci_read_field(device, PCI_LATENCY_TIMER, 1)); dbg_print(" Header Type : %2d\n", - pci_read_field(device, PCI_HEADER_TYPE, 1)); - dbg_print(" BIST : %2d\n", - pci_read_field(device, PCI_BIST, 1)); - dbg_print(" BAR0 : 0x%08x", - pci_read_field(device, PCI_BASE_ADDRESS_0, 4)); - dbg_print(" BAR1 : 0x%08x", - pci_read_field(device, PCI_BASE_ADDRESS_1, 4)); + pci_read_field(device, PCI_HEADER_TYPE, 1)); + dbg_print(" BIST : %2d\n", pci_read_field(device, PCI_BIST, 1)); + dbg_print(" BAR0 : 0x%08x", pci_read_field(device, PCI_BASE_ADDRESS_0, 4)); + dbg_print(" BAR1 : 0x%08x", pci_read_field(device, PCI_BASE_ADDRESS_1, 4)); dbg_print(" BAR2 : 0x%08x\n", - pci_read_field(device, PCI_BASE_ADDRESS_2, 4)); - dbg_print(" BAR3 : 0x%08x", - pci_read_field(device, PCI_BASE_ADDRESS_3, 4)); - dbg_print(" BAR4 : 0x%08x", - pci_read_field(device, PCI_BASE_ADDRESS_4, 4)); + pci_read_field(device, PCI_BASE_ADDRESS_2, 4)); + dbg_print(" BAR3 : 0x%08x", pci_read_field(device, PCI_BASE_ADDRESS_3, 4)); + dbg_print(" BAR4 : 0x%08x", pci_read_field(device, PCI_BASE_ADDRESS_4, 4)); dbg_print(" BAR6 : 0x%08x\n", - pci_read_field(device, PCI_BASE_ADDRESS_5, 4)); + pci_read_field(device, PCI_BASE_ADDRESS_5, 4)); dbg_print(" Cardbus CIS : 0x%08x\n", - pci_read_field(device, PCI_CARDBUS_CIS, 4)); + pci_read_field(device, PCI_CARDBUS_CIS, 4)); dbg_print(" Subsystem V. ID : 0x%08x\n", - pci_read_field(device, PCI_SUBSYSTEM_VENDOR_ID, 2)); + pci_read_field(device, PCI_SUBSYSTEM_VENDOR_ID, 2)); dbg_print(" Subsystem ID : 0x%08x\n", - pci_read_field(device, PCI_SUBSYSTEM_ID, 2)); + pci_read_field(device, PCI_SUBSYSTEM_ID, 2)); dbg_print(" ROM Base Address: 0x%08x\n", - pci_read_field(device, PCI_ROM_ADDRESS, 4)); + pci_read_field(device, PCI_ROM_ADDRESS, 4)); dbg_print(" PCI Cp. LinkList: 0x%08x\n", - pci_read_field(device, PCI_CAPABILITY_LIST, 1)); + pci_read_field(device, PCI_CAPABILITY_LIST, 1)); dbg_print(" Max Latency : 0x%08x\n", - pci_read_field(device, PCI_MAX_LAT, 1)); + pci_read_field(device, PCI_MAX_LAT, 1)); dbg_print(" Min Grant : 0x%08x\n", - pci_read_field(device, PCI_MIN_GNT, 1)); + pci_read_field(device, PCI_MIN_GNT, 1)); dbg_print(" Interrupt Pin : %2d\n", - pci_read_field(device, PCI_INTERRUPT_PIN, 1)); + pci_read_field(device, PCI_INTERRUPT_PIN, 1)); dbg_print(" Interrupt Line : %2d\n", - pci_read_field(device, PCI_INTERRUPT_LINE, 1)); + pci_read_field(device, PCI_INTERRUPT_LINE, 1)); dbg_print(" Interrupt Number: %2d\n", pci_get_interrupt(device)); dbg_print("\n"); } diff --git a/mentos/src/hardware/cpuid.c b/mentos/src/hardware/cpuid.c index 4735565..412158e 100644 --- a/mentos/src/hardware/cpuid.c +++ b/mentos/src/hardware/cpuid.c @@ -9,164 +9,152 @@ void get_cpuid(cpuinfo_t *cpuinfo) { - register_t ereg; + register_t ereg; - ereg.eax = ereg.ebx = ereg.ecx = ereg.edx = 0; - cpuid_write_vendor(cpuinfo, &ereg); + ereg.eax = ereg.ebx = ereg.ecx = ereg.edx = 0; + cpuid_write_vendor(cpuinfo, &ereg); - ereg.eax = 1; - ereg.ebx = ereg.ecx = ereg.edx = 0; - cpuid_write_proctype(cpuinfo, &ereg); + ereg.eax = 1; + ereg.ebx = ereg.ecx = ereg.edx = 0; + cpuid_write_proctype(cpuinfo, &ereg); } void call_cpuid(register_t *registers) { - __asm__ ("cpuid\n\t" : - "=a" (registers->eax), - "=b" (registers->ebx), - "=c" (registers->ecx), - "=d" (registers->edx) : - "a" (registers->eax)); + __asm__("cpuid\n\t" + : "=a"(registers->eax), "=b"(registers->ebx), "=c"(registers->ecx), + "=d"(registers->edx) + : "a"(registers->eax)); } void cpuid_write_vendor(cpuinfo_t *cpuinfo, register_t *registers) { - call_cpuid(registers); + call_cpuid(registers); - cpuinfo->cpu_vendor[0] = (char) ((registers->ebx & 0x000000FF)); - cpuinfo->cpu_vendor[1] = (char) ((registers->ebx & 0x0000FF00) >> 8); - cpuinfo->cpu_vendor[2] = (char) ((registers->ebx & 0x00FF0000) >> 16); - cpuinfo->cpu_vendor[3] = (char) ((registers->ebx & 0xFF000000) >> 24); - cpuinfo->cpu_vendor[4] = (char) ((registers->edx & 0x000000FF)); - cpuinfo->cpu_vendor[5] = (char) ((registers->edx & 0x0000FF00) >> 8); - cpuinfo->cpu_vendor[6] = (char) ((registers->edx & 0x00FF0000) >> 16); - cpuinfo->cpu_vendor[7] = (char) ((registers->edx & 0xFF000000) >> 24); - cpuinfo->cpu_vendor[8] = (char) ((registers->ecx & 0x000000FF)); - cpuinfo->cpu_vendor[9] = (char) ((registers->ecx & 0x0000FF00) >> 8); - cpuinfo->cpu_vendor[10] = (char) ((registers->ecx & 0x00FF0000) >> 16); - cpuinfo->cpu_vendor[11] = (char) ((registers->ecx & 0xFF000000) >> 24); - cpuinfo->cpu_vendor[12] = '\0'; + cpuinfo->cpu_vendor[0] = (char)((registers->ebx & 0x000000FF)); + cpuinfo->cpu_vendor[1] = (char)((registers->ebx & 0x0000FF00) >> 8); + cpuinfo->cpu_vendor[2] = (char)((registers->ebx & 0x00FF0000) >> 16); + cpuinfo->cpu_vendor[3] = (char)((registers->ebx & 0xFF000000) >> 24); + cpuinfo->cpu_vendor[4] = (char)((registers->edx & 0x000000FF)); + cpuinfo->cpu_vendor[5] = (char)((registers->edx & 0x0000FF00) >> 8); + cpuinfo->cpu_vendor[6] = (char)((registers->edx & 0x00FF0000) >> 16); + cpuinfo->cpu_vendor[7] = (char)((registers->edx & 0xFF000000) >> 24); + cpuinfo->cpu_vendor[8] = (char)((registers->ecx & 0x000000FF)); + cpuinfo->cpu_vendor[9] = (char)((registers->ecx & 0x0000FF00) >> 8); + cpuinfo->cpu_vendor[10] = (char)((registers->ecx & 0x00FF0000) >> 16); + cpuinfo->cpu_vendor[11] = (char)((registers->ecx & 0xFF000000) >> 24); + cpuinfo->cpu_vendor[12] = '\0'; } void cpuid_write_proctype(cpuinfo_t *cpuinfo, register_t *registers) { - call_cpuid(registers); + call_cpuid(registers); - uint32_t type = cpuid_get_byte(registers->eax, 0xB, 0x3); + uint32_t type = cpuid_get_byte(registers->eax, 0xB, 0x3); - switch (type) - { - case 0: - cpuinfo->cpu_type = "Original OEM Processor"; - break; - case 1: - cpuinfo->cpu_type = "Intel Overdrive Processor"; - break; - case 2: - cpuinfo->cpu_type = "Dual processor"; - break; - case 3: - cpuinfo->cpu_type = "(Intel reserved bit)"; - break; - } + switch (type) { + case 0: + cpuinfo->cpu_type = "Original OEM Processor"; + break; + case 1: + cpuinfo->cpu_type = "Intel Overdrive Processor"; + break; + case 2: + cpuinfo->cpu_type = "Dual processor"; + break; + case 3: + cpuinfo->cpu_type = "(Intel reserved bit)"; + break; + } - uint32_t familyID = cpuid_get_byte(registers->eax, 0x7, 0xE); - cpuinfo->cpu_family = familyID; + uint32_t familyID = cpuid_get_byte(registers->eax, 0x7, 0xE); + cpuinfo->cpu_family = familyID; - if (familyID == 0x0F) - { - cpuinfo->cpu_family += cpuid_get_byte(registers->eax, 0x13, 0xFF); - } + if (familyID == 0x0F) { + cpuinfo->cpu_family += cpuid_get_byte(registers->eax, 0x13, 0xFF); + } - uint32_t model = cpuid_get_byte(registers->eax, 0x3, 0xE); - cpuinfo->cpu_model = model; + uint32_t model = cpuid_get_byte(registers->eax, 0x3, 0xE); + cpuinfo->cpu_model = model; - if (familyID == 0x06 || familyID == 0x0F) - { - uint32_t ext_model = cpuid_get_byte(registers->eax, 0xF, 0xE); - cpuinfo->cpu_model += (ext_model << 4); - } - cpuinfo->apic_id = cpuid_get_byte(registers->ebx, 0x17, 0xFF); + if (familyID == 0x06 || familyID == 0x0F) { + uint32_t ext_model = cpuid_get_byte(registers->eax, 0xF, 0xE); + cpuinfo->cpu_model += (ext_model << 4); + } + cpuinfo->apic_id = cpuid_get_byte(registers->ebx, 0x17, 0xFF); - cpuid_feature_ecx(cpuinfo, registers->ecx); - cpuid_feature_edx(cpuinfo, registers->edx); + cpuid_feature_ecx(cpuinfo, registers->ecx); + cpuid_feature_edx(cpuinfo, registers->edx); - /* Get brand string to identify the processor */ - if (familyID >= 0x0F && model >= 0x03) - { - cpuinfo->brand_string = cpuid_brand_string(registers); - } - else - { - cpuinfo->brand_string = cpuid_brand_index(registers); - } + /* Get brand string to identify the processor */ + if (familyID >= 0x0F && model >= 0x03) { + cpuinfo->brand_string = cpuid_brand_string(registers); + } else { + cpuinfo->brand_string = cpuid_brand_index(registers); + } } void cpuid_feature_ecx(cpuinfo_t *cpuinfo, uint32_t ecx) { - uint32_t temp = ecx; - uint32_t i; + uint32_t temp = ecx; + uint32_t i; - for (i = 0; i < ECX_FLAGS_SIZE; ++i) - { - temp = cpuid_get_byte(temp, i, 1); - cpuinfo->cpuid_ecx_flags[i] = temp; - temp = ecx; - } + for (i = 0; i < ECX_FLAGS_SIZE; ++i) { + temp = cpuid_get_byte(temp, i, 1); + cpuinfo->cpuid_ecx_flags[i] = temp; + temp = ecx; + } } void cpuid_feature_edx(cpuinfo_t *cpuinfo, uint32_t edx) { - uint32_t temp = edx; - uint32_t i; + uint32_t temp = edx; + uint32_t i; - for (i = 0; i < EDX_FLAGS_SIZE; ++i) - { - temp = cpuid_get_byte(temp, i, 1); - cpuinfo->cpuid_edx_flags[i] = temp; - temp = edx; - } + for (i = 0; i < EDX_FLAGS_SIZE; ++i) { + temp = cpuid_get_byte(temp, i, 1); + cpuinfo->cpuid_edx_flags[i] = temp; + temp = edx; + } } -inline uint32_t cpuid_get_byte(const uint32_t reg, - const uint32_t position, - const uint32_t value) +inline uint32_t cpuid_get_byte(const uint32_t reg, const uint32_t position, + const uint32_t value) { - return ((reg >> position) & value); + return ((reg >> position) & value); } char *cpuid_brand_index(register_t *r) { - char *indexes[21] = {"Reserved", - "Intel Celeron", - "Intel Pentium III", - "Intel Pentium III Xeon", - "Mobile Intel Pentium III", - "Mobile Intel Celeron", - "Intel Pentium 4", - "Intel Pentium 4", - "Intel Celeron", - "Intel Xeon MP", - "Intel Xeon MP", - "Mobile Intel Pentium 4", - "Mobile Intel Celeron", - "Mobile Genuine Intel", - "Intel Celeron M", - "Mobile Intel Celeron", - "Intel Celeron", - "Mobile Genuine Intel", - "Intel Pentium M", - "Mobile Intel Celeron", - NULL}; + char *indexes[21] = { "Reserved", + "Intel Celeron", + "Intel Pentium III", + "Intel Pentium III Xeon", + "Mobile Intel Pentium III", + "Mobile Intel Celeron", + "Intel Pentium 4", + "Intel Pentium 4", + "Intel Celeron", + "Intel Xeon MP", + "Intel Xeon MP", + "Mobile Intel Pentium 4", + "Mobile Intel Celeron", + "Mobile Genuine Intel", + "Intel Celeron M", + "Mobile Intel Celeron", + "Intel Celeron", + "Mobile Genuine Intel", + "Intel Pentium M", + "Mobile Intel Celeron", + NULL }; - int bx = (r->ebx & 0xFF); + int bx = (r->ebx & 0xFF); - if (bx > 0x17) - { - bx = 0; - } + if (bx > 0x17) { + bx = 0; + } - return indexes[bx]; + return indexes[bx]; } /// @@ -174,21 +162,20 @@ char *cpuid_brand_index(register_t *r) /// @return char *cpuid_brand_string(register_t *r) { - char *temp = ""; + char *temp = ""; - for (r->eax = 0x80000002; r->eax <= 0x80000004; (r->eax)++) - { - r->ebx = r->ecx = r->edx = 0; - call_cpuid(r); - temp = strncat(temp, (const char *) r->eax, - strlen((const char *) r->eax)); - temp = strncat(temp, (const char *) r->ebx, - strlen((const char *) r->ebx)); - temp = strncat(temp, (const char *) r->ecx, - strlen((const char *) r->ecx)); - temp = strncat(temp, (const char *) r->edx, - strlen((const char *) r->edx)); - } + for (r->eax = 0x80000002; r->eax <= 0x80000004; (r->eax)++) { + r->ebx = r->ecx = r->edx = 0; + call_cpuid(r); + temp = + strncat(temp, (const char *)r->eax, strlen((const char *)r->eax)); + temp = + strncat(temp, (const char *)r->ebx, strlen((const char *)r->ebx)); + temp = + strncat(temp, (const char *)r->ecx, strlen((const char *)r->ecx)); + temp = + strncat(temp, (const char *)r->edx, strlen((const char *)r->edx)); + } - return temp; + return temp; } diff --git a/mentos/src/io/port_io.c b/mentos/src/io/port_io.c index edfb4bd..ee85812 100644 --- a/mentos/src/io/port_io.c +++ b/mentos/src/io/port_io.c @@ -8,49 +8,52 @@ inline uint8_t inportb(uint16_t port) { - unsigned char data = 0; - __asm__ __volatile__("inb %%dx, %%al" : "=a" (data) : "d" (port)); + unsigned char data = 0; + __asm__ __volatile__("inb %%dx, %%al" : "=a"(data) : "d"(port)); - return data; + return data; } inline uint16_t inports(uint16_t port) { - uint16_t rv; - __asm__ __volatile__("inw %1, %0" : "=a" (rv) : "dN" (port)); + uint16_t rv; + __asm__ __volatile__("inw %1, %0" : "=a"(rv) : "dN"(port)); - return rv; + return rv; } -void inportsm(uint16_t port, uint8_t * data, unsigned long size) +void inportsm(uint16_t port, uint8_t *data, unsigned long size) { - __asm__ __volatile__("rep insw" : "+D" (data), "+c" (size) : "d" (port) : "memory"); + __asm__ __volatile__("rep insw" + : "+D"(data), "+c"(size) + : "d"(port) + : "memory"); } inline uint32_t inportl(uint16_t port) { - uint32_t rv; - __asm__ __volatile__("inl %%dx, %%eax" : "=a" (rv) : "dN" (port)); + uint32_t rv; + __asm__ __volatile__("inl %%dx, %%eax" : "=a"(rv) : "dN"(port)); - return rv; + return rv; } inline void outportb(uint16_t port, uint8_t data) { - __asm__ __volatile__("outb %%al, %%dx"::"a" (data), "d" (port)); + __asm__ __volatile__("outb %%al, %%dx" ::"a"(data), "d"(port)); } inline void outports(uint16_t port, uint16_t data) { - __asm__ __volatile__("outw %1, %0" : : "dN" (port), "a" (data)); + __asm__ __volatile__("outw %1, %0" : : "dN"(port), "a"(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) { - __asm__ __volatile__("outl %%eax, %%dx" : : "dN" (port), "a" (data)); + __asm__ __volatile__("outl %%eax, %%dx" : : "dN"(port), "a"(data)); } diff --git a/mentos/src/kernel/sys.c b/mentos/src/kernel/sys.c index 3972c1c..bb15def 100644 --- a/mentos/src/kernel/sys.c +++ b/mentos/src/kernel/sys.c @@ -13,66 +13,61 @@ static void machine_power_off() { - while (true) - { - cpu_relax(); - } + while (true) { + cpu_relax(); + } } /// @brief Shutdown everything and perform a clean system power_off. static void kernel_power_off() { -// kernel_shutdown_prepare(SYSTEM_POWER_OFF); -// if (pm_power_off_prepare) -// { -// pm_power_off_prepare(); -// } -// migrate_to_reboot_cpu(); -// syscore_shutdown(); - printf("Power down\n"); -// kmsg_dump(KMSG_DUMP_POWEROFF); - machine_power_off(); + // kernel_shutdown_prepare(SYSTEM_POWER_OFF); + // if (pm_power_off_prepare) + // { + // pm_power_off_prepare(); + // } + // migrate_to_reboot_cpu(); + // syscore_shutdown(); + printf("Power down\n"); + // kmsg_dump(KMSG_DUMP_POWEROFF); + machine_power_off(); } int sys_reboot(int magic1, int magic2, unsigned int cmd, void *arg) { - static mutex_t reboot_mutex; + static mutex_t reboot_mutex; - // For safety, we require "magic" arguments. - if (magic1 != LINUX_REBOOT_MAGIC1 || - (magic2 != LINUX_REBOOT_MAGIC2 && - magic2 != LINUX_REBOOT_MAGIC2A && - magic2 != LINUX_REBOOT_MAGIC2B && - magic2 != LINUX_REBOOT_MAGIC2C)) - { - return -EINVAL; - } + // For safety, we require "magic" arguments. + if (magic1 != LINUX_REBOOT_MAGIC1 || + (magic2 != LINUX_REBOOT_MAGIC2 && magic2 != LINUX_REBOOT_MAGIC2A && + magic2 != LINUX_REBOOT_MAGIC2B && magic2 != LINUX_REBOOT_MAGIC2C)) { + return -EINVAL; + } - mutex_lock(&reboot_mutex, 0); + mutex_lock(&reboot_mutex, 0); - switch (cmd) - { - case LINUX_REBOOT_CMD_RESTART: - break; - case LINUX_REBOOT_CMD_CAD_ON: - break; - case LINUX_REBOOT_CMD_CAD_OFF: - break; - case LINUX_REBOOT_CMD_HALT: - break; - case LINUX_REBOOT_CMD_POWER_OFF: - kernel_power_off(); - break; - case LINUX_REBOOT_CMD_RESTART2: - break; - case LINUX_REBOOT_CMD_KEXEC: - break; - case LINUX_REBOOT_CMD_SW_SUSPEND: - break; - default: - return -EINVAL; - } - mutex_unlock(&reboot_mutex); + switch (cmd) { + case LINUX_REBOOT_CMD_RESTART: + break; + case LINUX_REBOOT_CMD_CAD_ON: + break; + case LINUX_REBOOT_CMD_CAD_OFF: + break; + case LINUX_REBOOT_CMD_HALT: + break; + case LINUX_REBOOT_CMD_POWER_OFF: + kernel_power_off(); + break; + case LINUX_REBOOT_CMD_RESTART2: + break; + case LINUX_REBOOT_CMD_KEXEC: + break; + case LINUX_REBOOT_CMD_SW_SUSPEND: + break; + default: + return -EINVAL; + } + mutex_unlock(&reboot_mutex); - return 0; + return 0; } diff --git a/mentos/src/libc/hashmap.c b/mentos/src/libc/hashmap.c index feb00a5..c553e63 100644 --- a/mentos/src/libc/hashmap.c +++ b/mentos/src/libc/hashmap.c @@ -8,287 +8,260 @@ #include "string.h" #include "stdlib.h" -struct hashmap_entry_t -{ - char *key; - void *value; - struct hashmap_entry_t *next; +struct hashmap_entry_t { + char *key; + void *value; + struct hashmap_entry_t *next; }; -struct hashmap_t -{ - hashmap_hash_t hash_func; - hashmap_comp_t hash_comp; - hashmap_dupe_t hash_key_dup; - hashmap_free_t hash_key_free; - hashmap_free_t hash_val_free; - size_t size; - hashmap_entry_t **entries; +struct hashmap_t { + hashmap_hash_t hash_func; + hashmap_comp_t hash_comp; + hashmap_dupe_t hash_key_dup; + hashmap_free_t hash_key_free; + hashmap_free_t hash_val_free; + size_t size; + hashmap_entry_t **entries; }; size_t hashmap_string_hash(void *_key) { - size_t hash = 0; - char *key = (char *) _key; - int c; - /* - * This is the so-called "sdbm" hash. It comes from a piece of public - * domain code from a clone of ndbm. - */ - while ((c = *key++)) - { - hash = c + (hash << 6) + (hash << 16) - hash; - } - - return hash; + size_t hash = 0; + char *key = (char *)_key; + int c; + // This is the so-called "sdbm" hash. It comes from a piece of public + // domain code from a clone of ndbm. + while ((c = *key++)) { + hash = c + (hash << 6) + (hash << 16) - hash; + } + return hash; } bool_t hashmap_string_comp(void *a, void *b) { - return !strcmp(a, b); + return !strcmp(a, b); } void *hashmap_string_dupe(void *key) { - return strdup(key); + return strdup(key); } static size_t hashmap_int_hash(void *key) { - return (size_t) key; + return (size_t)key; } static bool_t hashmap_int_comp(void *a, void *b) { - return (int) a == (int) b; + return (int)a == (int)b; } static void *hashmap_int_dupe(void *key) { - return key; + return key; } static void hashmap_int_free(void *ptr) { - (void) ptr; + (void)ptr; } hashmap_t *hashmap_create(size_t size) { - hashmap_t *map = malloc(sizeof(hashmap_t)); + hashmap_t *map = malloc(sizeof(hashmap_t)); - map->hash_func = &hashmap_string_hash; - map->hash_comp = &hashmap_string_comp; - map->hash_key_dup = &hashmap_string_dupe; - map->hash_key_free = &free; - map->hash_val_free = &free; + map->hash_func = &hashmap_string_hash; + map->hash_comp = &hashmap_string_comp; + map->hash_key_dup = &hashmap_string_dupe; + map->hash_key_free = &free; + map->hash_val_free = &free; - map->size = size; - map->entries = malloc(sizeof(hashmap_entry_t *) * size); - memset(map->entries, 0, sizeof(hashmap_entry_t *) * size); + map->size = size; + map->entries = malloc(sizeof(hashmap_entry_t *) * size); + memset(map->entries, 0, sizeof(hashmap_entry_t *) * size); - return map; + return map; } hashmap_t *hashmap_create_int(size_t size) { - hashmap_t *map = malloc(sizeof(hashmap_t)); + hashmap_t *map = malloc(sizeof(hashmap_t)); - map->hash_func = &hashmap_int_hash; - map->hash_comp = &hashmap_int_comp; - map->hash_key_dup = &hashmap_int_dupe; - map->hash_key_free = &hashmap_int_free; - map->hash_val_free = &free; + map->hash_func = &hashmap_int_hash; + map->hash_comp = &hashmap_int_comp; + map->hash_key_dup = &hashmap_int_dupe; + map->hash_key_free = &hashmap_int_free; + map->hash_val_free = &free; - map->size = size; - map->entries = malloc(sizeof(hashmap_entry_t *) * size); - memset(map->entries, 0, sizeof(hashmap_entry_t *) * size); + map->size = size; + map->entries = malloc(sizeof(hashmap_entry_t *) * size); + memset(map->entries, 0, sizeof(hashmap_entry_t *) * size); - return map; + return map; } void hashmap_free(hashmap_t *map) { - for (size_t i = 0; i < map->size; ++i) - { - hashmap_entry_t *x = map->entries[i], * p; - while (x) - { - p = x; - x = x->next; - map->hash_key_free(p->key); - map->hash_val_free(p); - } - } + for (size_t i = 0; i < map->size; ++i) { + hashmap_entry_t *x = map->entries[i], *p; + while (x) { + p = x; + x = x->next; + map->hash_key_free(p->key); + map->hash_val_free(p); + } + } - free(map->entries); + free(map->entries); } void *hashmap_set(hashmap_t *map, void *key, void *value) { - size_t hash = map->hash_func(key) % map->size; - hashmap_entry_t *x = map->entries[hash]; + size_t hash = map->hash_func(key) % map->size; + hashmap_entry_t *x = map->entries[hash]; - if (x == NULL) - { - hashmap_entry_t *e = malloc(sizeof(hashmap_entry_t)); - e->key = map->hash_key_dup(key); - e->value = value; - e->next = NULL; - map->entries[hash] = e; + if (x == NULL) { + hashmap_entry_t *e = malloc(sizeof(hashmap_entry_t)); + e->key = map->hash_key_dup(key); + e->value = value; + e->next = NULL; + map->entries[hash] = e; - return NULL; - } + return NULL; + } - hashmap_entry_t *p = NULL; + hashmap_entry_t *p = NULL; - do - { - if (map->hash_comp(x->key, key)) - { - void *out = x->value; - x->value = value; + do { + if (map->hash_comp(x->key, key)) { + void *out = x->value; + x->value = value; - return out; - } - p = x; - x = x->next; - } while (x); + return out; + } + p = x; + x = x->next; + } while (x); - hashmap_entry_t *e = malloc(sizeof(hashmap_entry_t)); - e->key = map->hash_key_dup(key); - e->value = value; - e->next = NULL; - p->next = e; + hashmap_entry_t *e = malloc(sizeof(hashmap_entry_t)); + e->key = map->hash_key_dup(key); + e->value = value; + e->next = NULL; + p->next = e; - return NULL; + return NULL; } void *hashmap_get(hashmap_t *map, void *key) { - size_t hash = map->hash_func(key) % map->size; - hashmap_entry_t *x = map->entries[hash]; + size_t hash = map->hash_func(key) % map->size; + hashmap_entry_t *x = map->entries[hash]; - if (x == NULL) - { - return NULL; - } - do - { - if (map->hash_comp(x->key, key)) - { - return x->value; - } - x = x->next; - } while (x); + if (x == NULL) { + return NULL; + } + do { + if (map->hash_comp(x->key, key)) { + return x->value; + } + x = x->next; + } while (x); - return NULL; + return NULL; } void *hashmap_remove(hashmap_t *map, void *key) { - size_t hash = map->hash_func(key) % map->size; - hashmap_entry_t *x = map->entries[hash]; + size_t hash = map->hash_func(key) % map->size; + hashmap_entry_t *x = map->entries[hash]; - if (x == NULL) - { - return NULL; - } - if (map->hash_comp(x->key, key)) - { - void *out = x->value; - map->entries[hash] = x->next; - map->hash_key_free(x->key); - map->hash_val_free(x); + if (x == NULL) { + return NULL; + } + if (map->hash_comp(x->key, key)) { + void *out = x->value; + map->entries[hash] = x->next; + map->hash_key_free(x->key); + map->hash_val_free(x); - return out; - } + return out; + } - hashmap_entry_t * p = x; - x = x->next; - do - { - if (map->hash_comp(x->key, key)) - { - void *out = x->value; - p->next = x->next; - map->hash_key_free(x->key); - map->hash_val_free(x); + hashmap_entry_t *p = x; + x = x->next; + do { + if (map->hash_comp(x->key, key)) { + void *out = x->value; + p->next = x->next; + map->hash_key_free(x->key); + map->hash_val_free(x); - return out; - } - p = x; - x = x->next; - } while (x); + return out; + } + p = x; + x = x->next; + } while (x); - return NULL; + return NULL; } bool_t hashmap_is_empty(hashmap_t *map) { - for (size_t i = 0; i < map->size; ++i) - { - if (map->entries[i]) - { - return false; - } - } + for (size_t i = 0; i < map->size; ++i) { + if (map->entries[i]) { + return false; + } + } - return true; + return true; } bool_t hashmap_has(hashmap_t *map, void *key) { - size_t hash = map->hash_func(key) % map->size; - hashmap_entry_t * x = map->entries[hash]; + size_t hash = map->hash_func(key) % map->size; + hashmap_entry_t *x = map->entries[hash]; - if (x == NULL) - { - return false; - } - do - { - if (map->hash_comp(x->key, key)) - { - return true; - } - x = x->next; - } while (x); + if (x == NULL) { + return false; + } + do { + if (map->hash_comp(x->key, key)) { + return true; + } + x = x->next; + } while (x); - return false; + return false; } list_t *hashmap_keys(hashmap_t *map) { - list_t *l = list_create(); + list_t *l = list_create(); - for (size_t i = 0; i < map->size; ++i) - { - hashmap_entry_t * x = map->entries[i]; - while (x) - { - list_insert_back(l, x->key); - x = x->next; - } - } + for (size_t i = 0; i < map->size; ++i) { + hashmap_entry_t *x = map->entries[i]; + while (x) { + list_insert_back(l, x->key); + x = x->next; + } + } - return l; + return l; } list_t *hashmap_values(hashmap_t *map) { - list_t *l = list_create(); + list_t *l = list_create(); - for (size_t i = 0; i < map->size; ++i) - { - hashmap_entry_t *x = map->entries[i]; + for (size_t i = 0; i < map->size; ++i) { + hashmap_entry_t *x = map->entries[i]; - while (x) - { - list_insert_back(l, x->value); - x = x->next; - } - } + while (x) { + list_insert_back(l, x->value); + x = x->next; + } + } - return l; + return l; } diff --git a/mentos/src/libc/libgen.c b/mentos/src/libc/libgen.c index d6827d8..3625f48 100644 --- a/mentos/src/libc/libgen.c +++ b/mentos/src/libc/libgen.c @@ -10,71 +10,64 @@ int parse_path(char *out, char **cur, char sep, size_t max) { - if (**cur == '\0') - { - return 0; - } + if (**cur == '\0') { + return 0; + } - *out++ = **cur; - ++*cur; - --max; + *out++ = **cur; + ++*cur; + --max; - while ((max > 0) && (**cur != '\0') && (**cur != sep)) - { - *out++ = **cur; - ++*cur; - --max; - } + while ((max > 0) && (**cur != '\0') && (**cur != sep)) { + *out++ = **cur; + ++*cur; + --max; + } - *out = '\0'; + *out = '\0'; - return 1; + return 1; } char *dirname(const char *path) { - static char s[MAX_PATH_LENGTH]; + static char s[MAX_PATH_LENGTH]; - static char dot[2] = "."; + static char dot[2] = "."; - // Check the input path. - if (path == NULL) return dot; + // Check the input path. + if (path == NULL) + return dot; - // Copy the path to the support string. - strcpy(s, path); + // Copy the path to the support string. + strcpy(s, path); - // Get the last occurrence of '/'. - char *last_slash = strrchr(s, '/'); + // Get the last occurrence of '/'. + char *last_slash = strrchr(s, '/'); - if (last_slash == s) - { - // If the slash is acutally the first character of the string, move the - // pointer to the last slash after it. - ++last_slash; - } - else if ((last_slash != NULL) && (last_slash[1] == '\0')) - { - // If the slash is the last character, we need to search before it. - last_slash = memchr(s, '/', last_slash - s); - } + if (last_slash == s) { + // If the slash is acutally the first character of the string, move the + // pointer to the last slash after it. + ++last_slash; + } else if ((last_slash != NULL) && (last_slash[1] == '\0')) { + // If the slash is the last character, we need to search before it. + last_slash = memchr(s, '/', last_slash - s); + } - if (last_slash != NULL) - { - // If we have found it, close the string. - last_slash[0] = '\0'; - } - else - { - // Otherwise, return '.'. - return dot; - } + if (last_slash != NULL) { + // If we have found it, close the string. + last_slash[0] = '\0'; + } else { + // Otherwise, return '.'. + return dot; + } - return s; + return s; } char *basename(const char *path) { - char *p = strrchr(path, '/'); + char *p = strrchr(path, '/'); - return p ? p + 1 : (char *) path; + return p ? p + 1 : (char *)path; } diff --git a/mentos/src/libc/ordered_array.c b/mentos/src/libc/ordered_array.c index 1247cee..c9c3af9 100644 --- a/mentos/src/libc/ordered_array.c +++ b/mentos/src/libc/ordered_array.c @@ -11,87 +11,80 @@ int8_t standard_lessthan_predicate(array_type_t a, array_type_t b) { - return (a < b); + return (a < b); } ordered_array_t create_ordered_array(uint32_t max_size, - lessthan_predicate_t less_than) + lessthan_predicate_t less_than) { - ordered_array_t to_ret; - to_ret.array = malloc(max_size * sizeof(array_type_t)); - memset(to_ret.array, 0, max_size * sizeof(array_type_t)); - to_ret.size = 0; - to_ret.max_size = max_size; - to_ret.less_than = less_than; + ordered_array_t to_ret; + to_ret.array = malloc(max_size * sizeof(array_type_t)); + memset(to_ret.array, 0, max_size * sizeof(array_type_t)); + to_ret.size = 0; + to_ret.max_size = max_size; + to_ret.less_than = less_than; - return to_ret; + return to_ret; } -ordered_array_t place_ordered_array(void * addr, - uint32_t max_size, - lessthan_predicate_t less_than) +ordered_array_t place_ordered_array(void *addr, uint32_t max_size, + lessthan_predicate_t less_than) { - ordered_array_t to_ret; - to_ret.array = (array_type_t *) addr; - memset(to_ret.array, 0, max_size * sizeof(array_type_t)); - to_ret.size = 0; - to_ret.max_size = max_size; - to_ret.less_than = less_than; + ordered_array_t to_ret; + to_ret.array = (array_type_t *)addr; + memset(to_ret.array, 0, max_size * sizeof(array_type_t)); + to_ret.size = 0; + to_ret.max_size = max_size; + to_ret.less_than = less_than; - return to_ret; + return to_ret; } -void destroy_ordered_array(ordered_array_t * array) +void destroy_ordered_array(ordered_array_t *array) { - free(array->array); + free(array->array); } -void insert_ordered_array(array_type_t item, ordered_array_t * array) +void insert_ordered_array(array_type_t item, ordered_array_t *array) { - assert(array->less_than); + assert(array->less_than); - uint32_t iterator = 0; - while (iterator < array->size && array->less_than(array->array[iterator], - item)) - { - iterator++; - } + uint32_t iterator = 0; + while (iterator < array->size && + array->less_than(array->array[iterator], item)) { + iterator++; + } - // Just add at the end of the array. - if (iterator == array->size) - { - array->array[array->size++] = item; - } - else - { - array_type_t tmp = array->array[iterator]; - array->array[iterator] = item; + // Just add at the end of the array. + if (iterator == array->size) { + array->array[array->size++] = item; + } else { + array_type_t tmp = array->array[iterator]; + array->array[iterator] = item; - while (iterator < array->size) - { - iterator++; - array_type_t tmp2 = array->array[iterator]; - array->array[iterator] = tmp; - tmp = tmp2; - } - array->size++; - } + while (iterator < array->size) { + iterator++; + array_type_t tmp2 = array->array[iterator]; + array->array[iterator] = tmp; + tmp = tmp2; + } + array->size++; + } } -array_type_t lookup_ordered_array(uint32_t i, ordered_array_t * array) +array_type_t lookup_ordered_array(uint32_t i, ordered_array_t *array) { - assert(i < array->size); + assert(i < array->size); - return array->array[i]; + return array->array[i]; } -void remove_ordered_array(uint32_t i, ordered_array_t * array) +void remove_ordered_array(uint32_t i, ordered_array_t *array) { - while (i < array->size) - { - array->array[i] = array->array[i + 1]; - i++; - } + while (i < array->size) { + array->array[i] = array->array[i + 1]; + i++; + } - array->size--; + array->size--; } diff --git a/mentos/src/libc/spinlock.c b/mentos/src/libc/spinlock.c index 659511c..235906d 100644 --- a/mentos/src/libc/spinlock.c +++ b/mentos/src/libc/spinlock.c @@ -8,29 +8,27 @@ void spinlock_init(spinlock_t *spinlock) { - (*spinlock) = 0; + (*spinlock) = 0; } void spinlock_lock(spinlock_t *spinlock) { - while (true) - { - if (atomic_set_and_test(spinlock, SPINLOCK_BUSY) == 0) - { - break; - } - while (*spinlock) cpu_relax(); - } + while (true) { + if (atomic_set_and_test(spinlock, SPINLOCK_BUSY) == 0) { + break; + } + while (*spinlock) + cpu_relax(); + } } void spinlock_unlock(spinlock_t *spinlock) { - barrier(); - - atomic_set(spinlock, SPINLOCK_FREE); + barrier(); + atomic_set(spinlock, SPINLOCK_FREE); } bool_t spinlock_trylock(spinlock_t *spinlock) { - return (bool_t) (atomic_set_and_test(spinlock, SPINLOCK_BUSY) == 0); + return (bool_t)(atomic_set_and_test(spinlock, SPINLOCK_BUSY) == 0); } diff --git a/mentos/src/libc/stdlib.c b/mentos/src/libc/stdlib.c index f064066..2af772e 100644 --- a/mentos/src/libc/stdlib.c +++ b/mentos/src/libc/stdlib.c @@ -9,43 +9,38 @@ #include "string.h" /// Used to align the memory. -#define ALIGN(x) \ - (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1)) - +#define ALIGN(x) (((x) + (sizeof(size_t) - 1)) & ~(sizeof(size_t) - 1)) void *malloc(unsigned int size) { - void *_res; - DEFN_SYSCALL1(_res, __NR_brk, size); + void *_res; + DEFN_SYSCALL1(_res, __NR_brk, size); - return _res; + return _res; } void free(void *p) { - int _res; - DEFN_SYSCALL1(_res, __NR_free, p); + int _res; + DEFN_SYSCALL1(_res, __NR_free, p); } - void *calloc(size_t element_number, size_t element_size) { - void *ptr = malloc(element_number * element_size); - if (ptr) - { - memset(ptr, 0, element_number * element_size); - } + void *ptr = malloc(element_number * element_size); + if (ptr) { + memset(ptr, 0, element_number * element_size); + } - return ptr; + return ptr; } - /// Seed used to generate random numbers. int rseed = 0; inline void srand(int x) { - rseed = x; + rseed = x; } #ifndef MS_RAND @@ -57,7 +52,7 @@ inline void srand(int x) /// between 0 and RAND_MAX. inline int rand() { - return rseed = (rseed * 1103515245 + 12345) & RAND_MAX; + return rseed = (rseed * 1103515245 + 12345) & RAND_MAX; } // MS rand. diff --git a/mentos/src/libc/strerror.c b/mentos/src/libc/strerror.c index 668ea21..afcb482 100644 --- a/mentos/src/libc/strerror.c +++ b/mentos/src/libc/strerror.c @@ -328,7 +328,7 @@ char *strerror(int errnum) #ifdef ELIBMAX case ELIBMAX: strcpy(error, - "Attempting to link in more shared libraries than system limit"); + "Attempting to link in more shared libraries than system limit"); break; #endif #ifdef ELIBEXEC @@ -368,8 +368,7 @@ char *strerror(int errnum) #endif #ifdef EAFNOSUPPORT case EAFNOSUPPORT: - strcpy(error, - "Address family not supported by protocol family"); + strcpy(error, "Address family not supported by protocol family"); break; #endif #ifdef EPROTOTYPE diff --git a/mentos/src/libc/unistd/getpid.c b/mentos/src/libc/unistd/getpid.c index 58616cb..c1059b8 100644 --- a/mentos/src/libc/unistd/getpid.c +++ b/mentos/src/libc/unistd/getpid.c @@ -11,9 +11,9 @@ pid_t getpid() { - pid_t ret; + pid_t ret; - DEFN_SYSCALL0(ret, __NR_getpid); + DEFN_SYSCALL0(ret, __NR_getpid); - return ret; + return ret; } diff --git a/mentos/src/libc/unistd/open.c b/mentos/src/libc/unistd/open.c index f6c8f3a..20b1e71 100644 --- a/mentos/src/libc/unistd/open.c +++ b/mentos/src/libc/unistd/open.c @@ -10,15 +10,13 @@ int open(const char *pathname, int flags, mode_t mode) { - ssize_t retval; + ssize_t retval; - DEFN_SYSCALL3(retval, __NR_open, pathname, flags, mode); + DEFN_SYSCALL3(retval, __NR_open, pathname, flags, mode); - if (retval < 0) - { - errno = -retval; - retval = -1; - - } - return retval; + if (retval < 0) { + errno = -retval; + retval = -1; + } + return retval; } diff --git a/mentos/src/libc/unistd/read.c b/mentos/src/libc/unistd/read.c index f233796..396dafa 100644 --- a/mentos/src/libc/unistd/read.c +++ b/mentos/src/libc/unistd/read.c @@ -10,15 +10,14 @@ ssize_t read(int fd, void *buf, size_t nbytes) { - ssize_t retval; + ssize_t retval; - DEFN_SYSCALL3(retval, __NR_read, fd, buf, nbytes); + DEFN_SYSCALL3(retval, __NR_read, fd, buf, nbytes); - if (retval < 0) - { - errno = -retval; - retval = -1; - } + if (retval < 0) { + errno = -retval; + retval = -1; + } - return retval; + return retval; } diff --git a/mentos/src/mem/zone_allocator.c b/mentos/src/mem/zone_allocator.c index db8b353..ddb3989 100644 --- a/mentos/src/mem/zone_allocator.c +++ b/mentos/src/mem/zone_allocator.c @@ -190,40 +190,40 @@ static bool_t pmm_check() /// @param zone A memory zone. static void buddy_system_init(zone_t *zone) { - // Initialize the free_lists of each area of the zone. - for (unsigned int order = 0; order < MAX_ORDER; order++) { - free_area_t *area = zone->free_area + order; - area->nr_free = 0; - list_head_init(&area->free_list); - } + // Initialize the free_lists of each area of the zone. + for (unsigned int order = 0; order < MAX_ORDER; order++) { + free_area_t *area = zone->free_area + order; + area->nr_free = 0; + list_head_init(&area->free_list); + } - // Current base page descriptor of the zone. - page_t *page = zone->zone_mem_map; - // Address of the last page descriptor of the zone. - page_t *last_page = page + zone->size; + // Current base page descriptor of the zone. + page_t *page = zone->zone_mem_map; + // Address of the last page descriptor of the zone. + page_t *last_page = page + zone->size; - // Get the free area collecting the larges block of page frames. - const unsigned int order = MAX_ORDER - 1; - free_area_t *area = zone->free_area + order; + // Get the free area collecting the larges block of page frames. + const unsigned int order = MAX_ORDER - 1; + free_area_t *area = zone->free_area + order; - // Add all zone's pages to the largest free area block. - uint32_t block_size = 1UL << order; - while ((page + block_size) <= last_page) { - /* page has already the _count field set to -1, + // Add all zone's pages to the largest free area block. + uint32_t block_size = 1UL << order; + while ((page + block_size) <= last_page) { + /* page has already the _count field set to -1, * therefore only save the order of the page. */ - page->private = order; + page->private = order; - // Insert page as first element in the list. - list_head_add_tail(&page->lru, &area->free_list); - // Increase the number of free block of the free_area_t. - area->nr_free++; + // Insert page as first element in the list. + list_head_add_tail(&page->lru, &area->free_list); + // Increase the number of free block of the free_area_t. + area->nr_free++; - page += block_size; - } + page += block_size; + } - assert(page == last_page && - "Memory size is not aligned to MAX_ORDER size!"); + assert(page == last_page && + "Memory size is not aligned to MAX_ORDER size!"); } /// @brief Initializes the memory attributes. diff --git a/mentos/src/process/process.c b/mentos/src/process/process.c index ae2eabc..1f32f5b 100644 --- a/mentos/src/process/process.c +++ b/mentos/src/process/process.c @@ -284,19 +284,19 @@ int sys_execve(pt_regs *r) PUSH_ON_STACK(current->thread.useresp, int, argc); PUSH_ON_STACK(current->thread.useresp, uintptr_t, (uintptr_t)exit_handler); -// dbg_print("_ARGV:0x%09x {\n", _argv); -// for (int i = 0; _argv[i] != NULL; ++i) { -// dbg_print("\t[%d][0x%09x]%s\n", i, _argv[i], _argv[i]); -// } -// dbg_print("}\n"); -// -// if (_envp != NULL) { -// dbg_print("_ENVP:0x%09x {\n", _envp); -// for (int i = 0; _envp[i] != NULL; ++i) { -// dbg_print("\t[%d][0x%09x]%s\n", i, _envp[i], _envp[i]); -// } -// dbg_print("}\n"); -// } + // dbg_print("_ARGV:0x%09x {\n", _argv); + // for (int i = 0; _argv[i] != NULL; ++i) { + // dbg_print("\t[%d][0x%09x]%s\n", i, _argv[i], _argv[i]); + // } + // dbg_print("}\n"); + // + // if (_envp != NULL) { + // dbg_print("_ENVP:0x%09x {\n", _envp); + // for (int i = 0; _envp[i] != NULL; ++i) { + // dbg_print("\t[%d][0x%09x]%s\n", i, _envp[i], _envp[i]); + // } + // dbg_print("}\n"); + // } // Perform the switch to the new process. do_switch(current, r); diff --git a/mentos/src/sys/unistd.c b/mentos/src/sys/unistd.c index d8b88a6..a703cae 100644 --- a/mentos/src/sys/unistd.c +++ b/mentos/src/sys/unistd.c @@ -15,52 +15,45 @@ int close(int fildes) { - if (fildes < 0) - { - return -1; - } - if (fd_list[fildes].fs_spec_id >= -1) - { - int mp_id = fd_list[fildes].mountpoint_id; - if (mountpoint_list[mp_id].operations.close_f != NULL) - { - int fs_fd = fd_list[fildes].fs_spec_id; - mountpoint_list[mp_id].operations.close_f(fs_fd); - } - fd_list[fildes].fs_spec_id = -1; - fd_list[fildes].mountpoint_id = -1; - } - else - { - return -1; - } + if (fildes < 0) { + return -1; + } + if (fd_list[fildes].fs_spec_id >= -1) { + int mp_id = fd_list[fildes].mountpoint_id; + if (mountpoint_list[mp_id].operations.close_f != NULL) { + int fs_fd = fd_list[fildes].fs_spec_id; + mountpoint_list[mp_id].operations.close_f(fs_fd); + } + fd_list[fildes].fs_spec_id = -1; + fd_list[fildes].mountpoint_id = -1; + } else { + return -1; + } - return 0; + return 0; } int rmdir(const char *path) { - char absolute_path[MAX_PATH_LENGTH]; - strcpy(absolute_path, path); + char absolute_path[MAX_PATH_LENGTH]; + strcpy(absolute_path, path); - if (path[0] != '/') - { - get_absolute_path(absolute_path); - } + if (path[0] != '/') { + get_absolute_path(absolute_path); + } - int32_t mp_id = get_mountpoint_id(absolute_path); - if (mp_id < 0) - { - printf("rmdir: failed to remove '%s':" - "Cannot find mount-point\n", path); + int32_t mp_id = get_mountpoint_id(absolute_path); + if (mp_id < 0) { + printf("rmdir: failed to remove '%s':" + "Cannot find mount-point\n", + path); - return -1; - } + return -1; + } - if (mountpoint_list[mp_id].dir_op.rmdir_f == NULL) - { - return -1; - } + if (mountpoint_list[mp_id].dir_op.rmdir_f == NULL) { + return -1; + } - return mountpoint_list[mp_id].dir_op.rmdir_f(absolute_path); + return mountpoint_list[mp_id].dir_op.rmdir_f(absolute_path); } diff --git a/mentos/src/sys/utsname.c b/mentos/src/sys/utsname.c index 007d539..c72a8d7 100644 --- a/mentos/src/sys/utsname.c +++ b/mentos/src/sys/utsname.c @@ -10,11 +10,11 @@ int uname(utsname_t *os_infos) { - // Uname code goes here. - strcpy(os_infos->sysname, OS_NAME); - strcpy(os_infos->version, OS_VERSION); - strcpy(os_infos->nodename, "testbed"); - strcpy(os_infos->machine, "i686"); + // Uname code goes here. + strcpy(os_infos->sysname, OS_NAME); + strcpy(os_infos->version, OS_VERSION); + strcpy(os_infos->nodename, "testbed"); + strcpy(os_infos->machine, "i686"); - return 0; + return 0; } diff --git a/mentos/src/system/printk.c b/mentos/src/system/printk.c index 9518a64..a0a308b 100644 --- a/mentos/src/system/printk.c +++ b/mentos/src/system/printk.c @@ -9,15 +9,15 @@ #include "stdio.h" #include "video.h" -void printk(const char * format, ...) +void printk(const char *format, ...) { - char buffer[4096]; - va_list ap; - // Start variabile argument's list. - va_start (ap, format); - int len = vsprintf(buffer, format, ap); - va_end (ap); + char buffer[4096]; + va_list ap; + // Start variabile argument's list. + va_start(ap, format); + int len = vsprintf(buffer, format, ap); + va_end(ap); - for (size_t i = 0; (i < len); ++i) - video_putc(buffer[i]); + for (size_t i = 0; (i < len); ++i) + video_putc(buffer[i]); } diff --git a/mentos/src/ui/command/cmd_cd.c b/mentos/src/ui/command/cmd_cd.c index bfb4cab..06826e8 100644 --- a/mentos/src/ui/command/cmd_cd.c +++ b/mentos/src/ui/command/cmd_cd.c @@ -15,57 +15,45 @@ void cmd_cd(int argc, char **argv) { - DIR *dirp = NULL; - char path[MAX_PATH_LENGTH]; - memset(path, 0, MAX_PATH_LENGTH); + DIR *dirp = NULL; + char path[MAX_PATH_LENGTH]; + memset(path, 0, MAX_PATH_LENGTH); - char current_path[MAX_PATH_LENGTH]; - getcwd(current_path, MAX_PATH_LENGTH); + char current_path[MAX_PATH_LENGTH]; + getcwd(current_path, MAX_PATH_LENGTH); - if (argc <= 1) - { - strcpy(path, "/"); - } - else if (argc > 2) - { - printf("%s: too many arguments\n\n", argv[0]); + if (argc <= 1) { + strcpy(path, "/"); + } else if (argc > 2) { + printf("%s: too many arguments\n\n", argv[0]); - return; - } - else if (strncmp(argv[1], "..", 2) == 0) - { - if (strcmp(current_path, dirname(current_path)) == 0) - { - return; - } - strcpy(path, dirname(current_path)); - } - else if (strncmp(argv[1], ".", 1) == 0) - { - return; - } - else - { - // Copy the current path. - strcpy(path, current_path); - // Get the absolute path. - get_absolute_path(path); - // If the current directory is not the root, add a '/'. - if (strcmp(path, "/") != 0) - { - strncat(path, "/", 1); - } - // Concatenate the input dir. - strncat(path, argv[1], strlen(argv[1])); - } + return; + } else if (strncmp(argv[1], "..", 2) == 0) { + if (strcmp(current_path, dirname(current_path)) == 0) { + return; + } + strcpy(path, dirname(current_path)); + } else if (strncmp(argv[1], ".", 1) == 0) { + return; + } else { + // Copy the current path. + strcpy(path, current_path); + // Get the absolute path. + get_absolute_path(path); + // If the current directory is not the root, add a '/'. + if (strcmp(path, "/") != 0) { + strncat(path, "/", 1); + } + // Concatenate the input dir. + strncat(path, argv[1], strlen(argv[1])); + } - dirp = opendir(path); - if (dirp == NULL) - { - printf("%s: no such file or directory: %s\n\n", argv[0], argv[1]); + dirp = opendir(path); + if (dirp == NULL) { + printf("%s: no such file or directory: %s\n\n", argv[0], argv[1]); - return; - } - chdir(path); - closedir(dirp); + return; + } + chdir(path); + closedir(dirp); } diff --git a/mentos/src/ui/command/cmd_drv_load.c b/mentos/src/ui/command/cmd_drv_load.c index 549c681..685eef1 100644 --- a/mentos/src/ui/command/cmd_drv_load.c +++ b/mentos/src/ui/command/cmd_drv_load.c @@ -1,6 +1,6 @@ /// MentOS, The Mentoring Operating system project /// @file cmd_drv_load.c -/// @brief +/// @brief /// @copyright (c) 2019 This file is distributed under the MIT License. /// See LICENSE.md for details. @@ -11,59 +11,43 @@ void cmd_drv_load(int argc, char **argv) { - if (argc < 2) - { - printf( - "No driver inserted or bad usage! Type %s --help for the usage.\n", - argv[0]); - } - else - { - if ((_kstrncmp(argv[1], "-r", 2) == 0)) - { - if ((argv[2] != NULL)) - { - if (_kstrncmp(argv[2], "mouse", 5) == 0) - { - printf("Disattivamento %s in corso..\n", argv[2]); - mouse_disable(); - } - else - printf("FATAL: Driver %s not found.\n", argv[2]); - } - else - printf("Warning, no driver name inserted!\n"); - } - else if (_kstrncmp(argv[1], "mouse", 5) == 0) - { - // Enabling mouse. - mouse_install(); - } - else if ((_kstrncmp(argv[1], "--help", 6) == 0) || - (_kstrncmp(argv[1], "-h", 2) == 0)) - { - printf("---------------------------------------------------\n" - "Driver tool to load and kill driver\n" - "Simple to use, just type:\n" - "\n" - "Usage: %s - driver_name\n" - "\t-> %s module_name - to load driver\n" - "\t-> %s -r module_name - to kill driver\n" - "---------------------------------------------------\n", - argv[0], argv[0], argv[0]); - } - else - { - if ((_kstrncmp(argv[1], "-r", 2) == 0) && - (_kstrncmp(argv[2], "mouse", 5) == -1)) - { - printf("FATAL: Driver %s not found.\n", argv[2]); - } + if (argc < 2) { + printf( + "No driver inserted or bad usage! Type %s --help for the usage.\n", + argv[0]); + } else { + if ((_kstrncmp(argv[1], "-r", 2) == 0)) { + if ((argv[2] != NULL)) { + if (_kstrncmp(argv[2], "mouse", 5) == 0) { + printf("Disattivamento %s in corso..\n", argv[2]); + mouse_disable(); + } else + printf("FATAL: Driver %s not found.\n", argv[2]); + } else + printf("Warning, no driver name inserted!\n"); + } else if (_kstrncmp(argv[1], "mouse", 5) == 0) { + // Enabling mouse. + mouse_install(); + } else if ((_kstrncmp(argv[1], "--help", 6) == 0) || + (_kstrncmp(argv[1], "-h", 2) == 0)) { + printf("---------------------------------------------------\n" + "Driver tool to load and kill driver\n" + "Simple to use, just type:\n" + "\n" + "Usage: %s - driver_name\n" + "\t-> %s module_name - to load driver\n" + "\t-> %s -r module_name - to kill driver\n" + "---------------------------------------------------\n", + argv[0], argv[0], argv[0]); + } else { + if ((_kstrncmp(argv[1], "-r", 2) == 0) && + (_kstrncmp(argv[2], "mouse", 5) == -1)) { + printf("FATAL: Driver %s not found.\n", argv[2]); + } - else - { - printf("FATAL: Driver %s not found.\n", argv[1]); - } - } - } + else { + printf("FATAL: Driver %s not found.\n", argv[1]); + } + } + } } diff --git a/mentos/src/ui/command/cmd_echo.c b/mentos/src/ui/command/cmd_echo.c index 69d8d5c..d8967b5 100644 --- a/mentos/src/ui/command/cmd_echo.c +++ b/mentos/src/ui/command/cmd_echo.c @@ -1,6 +1,6 @@ /// MentOS, The Mentoring Operating system project /// @file echo.c -/// @brief +/// @brief /// @copyright (c) 2019 This file is distributed under the MIT License. /// See LICENSE.md for details. @@ -9,18 +9,14 @@ void cmd_echo(int argc, char **argv) { - int i = argc; - int j = 0; - if (argc == 1) - { - printf(""); - } - else - { - while (--i > 0) - { - printf("%s ", argv[++j]); - } - } - printf("\n"); + int i = argc; + int j = 0; + if (argc == 1) { + printf(""); + } else { + while (--i > 0) { + printf("%s ", argv[++j]); + } + } + printf("\n"); } diff --git a/mentos/src/ui/command/cmd_ipcrm.c b/mentos/src/ui/command/cmd_ipcrm.c index 2208de9..05856ca 100644 --- a/mentos/src/ui/command/cmd_ipcrm.c +++ b/mentos/src/ui/command/cmd_ipcrm.c @@ -10,49 +10,41 @@ extern struct shmid_ds *head; -void cmd_ipcrm(int argc, char **argv){ - if (argc != 2) - { - printf("Bad arguments: you have to specify only IPC id, see ipcs.\n"); +void cmd_ipcrm(int argc, char **argv) +{ + if (argc != 2) { + printf("Bad arguments: you have to specify only IPC id, see ipcs.\n"); - return; - } + return; + } - struct shmid_ds *shmid_ds = head; - struct shmid_ds *prev = NULL; + struct shmid_ds *shmid_ds = head; + struct shmid_ds *prev = NULL; - while (shmid_ds != NULL) - { - char strid[10]; - int_to_str(strid, (shmid_ds ->shm_perm).seq, 10); + while (shmid_ds != NULL) { + char strid[10]; + int_to_str(strid, (shmid_ds->shm_perm).seq, 10); - if (strcmp(strid, argv[1]) == 0) - { - break; - } + if (strcmp(strid, argv[1]) == 0) { + break; + } - prev = shmid_ds; - shmid_ds = shmid_ds -> next; - } + prev = shmid_ds; + shmid_ds = shmid_ds->next; + } - if (shmid_ds == NULL) - { - printf("No shared memory find. \n"); - } - else - { - kfree(shmid_ds -> shm_location); + if (shmid_ds == NULL) { + printf("No shared memory find. \n"); + } else { + kfree(shmid_ds->shm_location); - // shmid_ds = head. - if (prev == NULL) - { - head = head -> next; - } - else - { - prev -> next = shmid_ds -> next; - } + // shmid_ds = head. + if (prev == NULL) { + head = head->next; + } else { + prev->next = shmid_ds->next; + } - kfree(shmid_ds); - } + kfree(shmid_ds); + } } diff --git a/mentos/src/ui/command/cmd_ipcs.c b/mentos/src/ui/command/cmd_ipcs.c index f8fab60..9f39744 100644 --- a/mentos/src/ui/command/cmd_ipcs.c +++ b/mentos/src/ui/command/cmd_ipcs.c @@ -14,85 +14,70 @@ extern struct shmid_ds *head; static void print_sem_stat() { - printf("Semaphores: \n"); - printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", - "OWNER", "GROUP"); - printf("%-20s %-10s %-20s \n\n", "", "Semaphores not implemented", ""); + printf("Semaphores: \n"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", + "OWNER", "GROUP"); + printf("%-20s %-10s %-20s \n\n", "", "Semaphores not implemented", ""); } static void print_shm_stat() { - struct shmid_ds *shm_list = head; + struct shmid_ds *shm_list = head; - printf("Shared Memory: \n"); - printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", - "OWNER", "GROUP"); + printf("Shared Memory: \n"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", + "OWNER", "GROUP"); - while (shm_list != NULL) - { - char mode[12]; - strmode((shm_list->shm_perm).mode, mode); + while (shm_list != NULL) { + char mode[12]; + strmode((shm_list->shm_perm).mode, mode); - printf("%-10s %-10i %-10i %-10s %-10s %-10s \n", - "m", - (shm_list->shm_perm).seq, - (shm_list->shm_perm).key, - mode, - "-", "-"); + printf("%-10s %-10i %-10i %-10s %-10s %-10s \n", "m", + (shm_list->shm_perm).seq, (shm_list->shm_perm).key, mode, "-", + "-"); - shm_list = shm_list->next; - } + shm_list = shm_list->next; + } - printf("\n"); + printf("\n"); } static void print_msg_stat() { - printf("Message Queues: \n"); - printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", - "OWNER", "GROUP"); - printf("%-20s %-10s %-20s \n\n", "", "Message Queues not implemented", ""); + printf("Message Queues: \n"); + printf("%-10s %-10s %-10s %-10s %-10s %-10s \n", "T", "ID", "KEY", "MODE", + "OWNER", "GROUP"); + printf("%-20s %-10s %-20s \n\n", "", "Message Queues not implemented", ""); } void cmd_ipcs(int argc, char **argv) { - if (argc > 2) - { - printf("Too much arguments.\n"); + if (argc > 2) { + printf("Too much arguments.\n"); - return; - } + return; + } - char datehour[100] = ""; - strdatehour(datehour); + char datehour[100] = ""; + strdatehour(datehour); - printf("IPC status from "OS_NAME" as of %s\n", datehour); + printf("IPC status from " OS_NAME " as of %s\n", datehour); - if (argc == 2) - { - if (strcmp(argv[1], "-s") == 0) - { - print_sem_stat(); - } - else if (strcmp(argv[1], "-m") == 0) - { - print_shm_stat(); - } - else if (strcmp(argv[1], "-q") == 0) - { - print_msg_stat(); - } - else - { - printf("Option not recognize.\n"); - } - } - else - { - print_sem_stat(); - print_shm_stat(); - print_msg_stat(); - } + if (argc == 2) { + if (strcmp(argv[1], "-s") == 0) { + print_sem_stat(); + } else if (strcmp(argv[1], "-m") == 0) { + print_shm_stat(); + } else if (strcmp(argv[1], "-q") == 0) { + print_msg_stat(); + } else { + printf("Option not recognize.\n"); + } + } else { + print_sem_stat(); + print_shm_stat(); + print_msg_stat(); + } - return; + return; } diff --git a/mentos/src/ui/command/cmd_more.c b/mentos/src/ui/command/cmd_more.c index 7dd0ddc..0cc3575 100644 --- a/mentos/src/ui/command/cmd_more.c +++ b/mentos/src/ui/command/cmd_more.c @@ -13,39 +13,35 @@ void cmd_more(int argc, char **argv) { - if (argc != 2) - { - printf("%s: missing operand.\n", argv[0]); - printf("Try '%s --help' for more information.\n\n", argv[0]); + if (argc != 2) { + printf("%s: missing operand.\n", argv[0]); + printf("Try '%s --help' for more information.\n\n", argv[0]); - return; - } + return; + } - if (strcmp(argv[1], "--help") == 0) - { - printf("Prints the content of the given file.\n"); - printf("Usage:\n"); - printf(" %s \n\n", argv[0]); + if (strcmp(argv[1], "--help") == 0) { + printf("Prints the content of the given file.\n"); + printf("Usage:\n"); + printf(" %s \n\n", argv[0]); - return; - } + return; + } - int fd = open(argv[1], O_RDONLY, 42); - if (fd < 0) - { - printf("%s: Cannot stat file '%s': %s\n\n", - argv[0], argv[1],"unknown"/*strerror(errno)*/); + int fd = open(argv[1], O_RDONLY, 42); + if (fd < 0) { + printf("%s: Cannot stat file '%s': %s\n\n", argv[0], argv[1], + "unknown" /*strerror(errno)*/); - return; - } + return; + } - char c; - // Put on the standard output the characters. - while (read(fd, &c, 1) > 0) - { - putchar(c); - } - putchar('\n'); - putchar('\n'); - close(fd); + char c; + // Put on the standard output the characters. + while (read(fd, &c, 1) > 0) { + putchar(c); + } + putchar('\n'); + putchar('\n'); + close(fd); } diff --git a/mentos/src/ui/command/cmd_newfile.c b/mentos/src/ui/command/cmd_newfile.c index 8cdc39c..2ac8ef3 100644 --- a/mentos/src/ui/command/cmd_newfile.c +++ b/mentos/src/ui/command/cmd_newfile.c @@ -14,49 +14,44 @@ void cmd_newfile(int argc, char **argv) { - if (argc != 2) - { - printf("%s: missing operand.\n", argv[0]); - printf("Try '%s --help' for more information.\n\n", argv[0]); + if (argc != 2) { + printf("%s: missing operand.\n", argv[0]); + printf("Try '%s --help' for more information.\n\n", argv[0]); - return; - } + return; + } - if (strcmp(argv[1], "--help") == 0) - { - printf("Makes a new file, and prompt for it's content.\n"); - printf("Usage:\n"); - printf(" %s \n", argv[0]); + if (strcmp(argv[1], "--help") == 0) { + printf("Makes a new file, and prompt for it's content.\n"); + printf("Usage:\n"); + printf(" %s \n", argv[0]); - return; - } + return; + } - char text[256]; - printf("Filename: %s\n", argv[1]); - int fd = open(argv[1], O_RDWR | O_CREAT | O_APPEND, 0); - if (fd < 0) - { - printf("%s: Cannot create file '%s': %s\n\n", - argv[0], argv[1], "unknown"/*strerror(errno)*/); + char text[256]; + printf("Filename: %s\n", argv[1]); + int fd = open(argv[1], O_RDWR | O_CREAT | O_APPEND, 0); + if (fd < 0) { + printf("%s: Cannot create file '%s': %s\n\n", argv[0], argv[1], + "unknown" /*strerror(errno)*/); - return; - } + return; + } - printf("Type one line of text here (new line to complete):\n"); - scanf("%s", text); - if (write(fd, text, strlen(text)) == -1) - { - printf("%s: Cannot write on file '%s': %s\n\n", - argv[0], argv[1], "unknown"/*strerror(errno)*/); + printf("Type one line of text here (new line to complete):\n"); + scanf("%s", text); + if (write(fd, text, strlen(text)) == -1) { + printf("%s: Cannot write on file '%s': %s\n\n", argv[0], argv[1], + "unknown" /*strerror(errno)*/); - return; - } + return; + } - if (close(fd) == -1) - { - printf("%s: Cannot close file '%s': %s\n\n", - argv[0], argv[1], "unknown"/*strerror(errno)*/); + if (close(fd) == -1) { + printf("%s: Cannot close file '%s': %s\n\n", argv[0], argv[1], + "unknown" /*strerror(errno)*/); - return; - } + return; + } } diff --git a/mentos/src/ui/command/cmd_pwd.c b/mentos/src/ui/command/cmd_pwd.c index e4f123f..8fc3d10 100644 --- a/mentos/src/ui/command/cmd_pwd.c +++ b/mentos/src/ui/command/cmd_pwd.c @@ -1,6 +1,6 @@ /// MentOS, The Mentoring Operating system project /// @file cmd_pwd.c -/// @brief +/// @brief /// @copyright (c) 2019 This file is distributed under the MIT License. /// See LICENSE.md for details. @@ -11,9 +11,9 @@ void cmd_pwd(int argc, char **argv) { - (void) argc; - (void) argv; - char cwd[MAX_PATH_LENGTH]; - getcwd(cwd, MAX_PATH_LENGTH); - printf("%s\n", cwd); + (void)argc; + (void)argv; + char cwd[MAX_PATH_LENGTH]; + getcwd(cwd, MAX_PATH_LENGTH); + printf("%s\n", cwd); } diff --git a/mentos/src/ui/command/cmd_rmdir.c b/mentos/src/ui/command/cmd_rmdir.c index 6c703a0..e423560 100644 --- a/mentos/src/ui/command/cmd_rmdir.c +++ b/mentos/src/ui/command/cmd_rmdir.c @@ -12,29 +12,26 @@ void cmd_rmdir(int argc, char **argv) { - // Check the number of arguments. - if (argc != 2) - { - printf("Bad usage.\n"); - printf("Try 'rmdir --help' for more information.\n"); + // Check the number of arguments. + if (argc != 2) { + printf("Bad usage.\n"); + printf("Try 'rmdir --help' for more information.\n"); - return; - } + return; + } - if (strcmp(argv[1], "--help") == 0) - { - printf("Removes a directory.\n"); - printf("Usage:\n"); - printf(" rmdir \n"); + if (strcmp(argv[1], "--help") == 0) { + printf("Removes a directory.\n"); + printf("Usage:\n"); + printf(" rmdir \n"); - return; - } + return; + } - if (rmdir(argv[1]) != 0) - { - printf("%s: failed to remove '%s': %s\n\n", - argv[0], argv[1], "unknown"/*strerror(errno)*/); + if (rmdir(argv[1]) != 0) { + printf("%s: failed to remove '%s': %s\n\n", argv[0], argv[1], + "unknown" /*strerror(errno)*/); - return; - } + return; + } } diff --git a/mentos/src/ui/command/cmd_uname.c b/mentos/src/ui/command/cmd_uname.c index 8a069ab..e0a7013 100644 --- a/mentos/src/ui/command/cmd_uname.c +++ b/mentos/src/ui/command/cmd_uname.c @@ -42,10 +42,10 @@ void cmd_uname(int argc, char **argv) printf("Micro: %d\n", OS_MICRO_VERSION); // CPU Info. - printf("\nCPU:"); + printf("\nCPU:"); video_set_color(BRIGHT_RED); video_move_cursor(61, video_get_line()); - printf(sinfo.cpu_vendor); + printf(sinfo.cpu_vendor); video_set_color(WHITE); printf("\n");