Fix all the missing comments.

This commit is contained in:
Enrico Fraccaroli
2022-01-03 22:25:21 +01:00
parent 181d1d69cb
commit 2461d82431
59 changed files with 826 additions and 601 deletions
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[EXEPT ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "system/panic.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[GDT ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "io/debug.h"
+107 -10
View File
@@ -5,15 +5,114 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[IDT ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "descriptor_tables/idt.h"
#include "descriptor_tables/gdt.h"
#include "descriptor_tables/isr.h"
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_0();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_1();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_2();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_3();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_4();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_5();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_6();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_7();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_8();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_9();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_10();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_11();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_12();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_13();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_14();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_15();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_16();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_17();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_18();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_19();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_20();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_21();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_22();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_23();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_24();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_25();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_26();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_27();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_28();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_29();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_30();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_31();
/// @brief Interrupt Service Routine (ISR) for exception handling.
extern void INT_80();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_0();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_1();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_2();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_3();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_4();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_5();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_6();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_7();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_8();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_9();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_10();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_11();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_12();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_13();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_14();
/// @brief Interrupt Request (IRQ) coming from the PIC.
extern void IRQ_15();
/// @brief This function is in idt.asm.
/// @param idt_pointer Address of the idt.
extern void idt_flush(uint32_t idt_pointer);
@@ -25,20 +124,18 @@ static idt_descriptor_t idt_table[IDT_SIZE];
idt_pointer_t idt_pointer;
/// @brief Use this function to set an entry in the IDT.
/// @param index Indice della 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.
/// @param index Index of the IDT entry.
/// @param handler Pointer to the entry handler.
/// @param options Descriptors options (PRESENT, NOTPRESENT, KERNEL, USER).
/// @param seg_sel GDT segment selector.
static inline void __idt_set_gate(uint8_t index, interrupt_handler_t handler, uint16_t options, uint8_t seg_sel)
{
uintptr_t base_prt = (uintptr_t)handler;
// Assign the base values.
idt_table[index].offset_low = (base_prt & 0xFFFFu);
idt_table[index].offset_high = (base_prt >> 16u) & 0xFFFFu;
// Set the other fields.
idt_table[index].null_par = 0x00;
idt_table[index].reserved = 0x00;
idt_table[index].seg_selector = seg_sel;
idt_table[index].options = options | IDT_PADDING;
}
@@ -49,7 +146,7 @@ void init_idt()
for (uint32_t it = 0; it < IDT_SIZE; ++it) {
idt_table[it].offset_low = 0;
idt_table[it].seg_selector = 0;
idt_table[it].null_par = 0;
idt_table[it].reserved = 0;
idt_table[it].options = 0;
idt_table[it].offset_high = 0;
}
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[IRQ ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "descriptor_tables/isr.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[TSS ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "descriptor_tables/tss.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[FPU ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "devices/fpu.h"
+18 -18
View File
@@ -6,9 +6,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PCI ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "devices/pci.h"
@@ -309,43 +309,43 @@ const char *pci_class_lookup(uint32_t class_code)
return "Unknown";
}
void pci_scan_hit(pci_scan_func_t f, uint32_t dev, void *extra)
void pci_scan_hit(pci_scan_func_t f, uint32_t device, void *extra)
{
uint16_t dev_vend = (uint16_t)pci_read_field(dev, PCI_VENDOR_ID, 2);
uint16_t dev_dvid = (uint16_t)pci_read_field(dev, PCI_DEVICE_ID, 2);
f(dev, dev_vend, dev_dvid, extra);
uint16_t vendor_id = (uint16_t)pci_read_field(device, PCI_VENDOR_ID, 2);
uint16_t device_id = (uint16_t)pci_read_field(device, PCI_DEVICE_ID, 2);
f(device, vendor_id, device_id, extra);
}
void pci_scan_func(pci_scan_func_t f, int type, int bus, int slot, int func, void *extra)
{
uint32_t dev = pci_box_device(bus, slot, func);
uint32_t device = pci_box_device(bus, slot, func);
if ((type == -1) || (type == pci_find_type(dev))) {
pci_scan_hit(f, dev, extra);
if ((type == -1) || (type == pci_find_type(device))) {
pci_scan_hit(f, device, extra);
}
if (pci_find_type(dev) == PCI_TYPE_BRIDGE) {
pci_scan_bus(f, type, pci_read_field(dev, PCI_SECONDARY_BUS, 1), extra);
if (pci_find_type(device) == PCI_TYPE_BRIDGE) {
pci_scan_bus(f, type, pci_read_field(device, PCI_SECONDARY_BUS, 1), extra);
}
}
void pci_scan_slot(pci_scan_func_t f, int type, int bus, int slot, void *extra)
{
uint32_t dev = pci_box_device(bus, slot, 0);
uint32_t device = pci_box_device(bus, slot, 0);
if (pci_read_field(dev, PCI_VENDOR_ID, 2) == PCI_NONE) {
if (pci_read_field(device, PCI_VENDOR_ID, 2) == PCI_NONE) {
return;
}
pci_scan_func(f, type, bus, slot, 0, extra);
if (!pci_read_field(dev, PCI_HEADER_TYPE, 1)) {
if (!pci_read_field(device, PCI_HEADER_TYPE, 1)) {
return;
}
for (int func = 1; func < 8; func++) {
dev = pci_box_device(bus, slot, func);
device = pci_box_device(bus, slot, func);
if (pci_read_field(dev, PCI_VENDOR_ID, 2) != PCI_NONE) {
if (pci_read_field(device, PCI_VENDOR_ID, 2) != PCI_NONE) {
pci_scan_func(f, type, bus, slot, func, extra);
}
}
@@ -366,9 +366,9 @@ void pci_scan(pci_scan_func_t f, int type, void *extra)
}
for (int func = 0; func < 8; ++func) {
uint32_t dev = pci_box_device(0, 0, func);
uint32_t device = pci_box_device(0, 0, func);
if (pci_read_field(dev, PCI_VENDOR_ID, 2) == PCI_NONE) {
if (pci_read_field(device, PCI_VENDOR_ID, 2) == PCI_NONE) {
break;
}
pci_scan_bus(f, type, func, extra);
+99 -31
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[ATA ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "drivers/ata.h"
@@ -85,29 +85,98 @@ typedef enum {
ata_dma_command_write_no_retry = 0xCB, ///< Write DMA without retries (28 bit LBA).
} ata_dma_command_t;
/// @brief ATA identity commands.
typedef enum {
ata_command_pata_ident = 0xEC, ///< Identify Device.
ata_command_patapi_ident = 0xA1, ///< Identify Device.
} ata_identity_command_t;
/// @brief IDENTIFY device data (response to 0xEC).
typedef struct ata_identify_t {
uint16_t flags; ///<
uint16_t unused1[9]; ///<
char serial[20]; ///<
uint16_t unused2[3]; ///<
char firmware[8]; ///<
char model[40]; ///<
uint16_t sectors_per_int; ///<
uint16_t unused3; ///<
uint16_t capabilities[2]; ///<
uint16_t unused4[2]; ///<
uint16_t valid_ext_data; ///<
uint16_t unused5[5]; ///<
uint16_t size_of_rw_mult; ///<
uint32_t sectors_28; ///<
uint16_t unused6[38]; ///<
uint64_t sectors_48; ///<
uint16_t unused7[152]; ///<
/// Word 0 : General configuration.
struct {
/// Reserved.
uint16_t reserved1 : 1;
/// This member is no longer used.
uint16_t retired3 : 1;
/// Indicates that the response was incomplete.
uint16_t response_incomplete : 1;
/// This member is no longer used.
uint16_t retired2 : 3;
/// Indicates when set to 1 that the device is fixed.
uint16_t fixed_fevice : 1;
/// Indicates when set to 1 that the media is removable.
uint16_t removable_media : 1;
/// This member is no longer used.
uint16_t retired1 : 7;
/// Indicates when set to 1 that the device is an ATA device.
uint16_t device_type : 1;
} general_configuration;
/// Word 1-9 : Unused.
uint16_t unused1[9];
/// Word 10-19 : Contains the serial number of the device.
uint8_t serial_number[20];
/// Word 20-22 : Unused.
uint16_t unused2[3];
/// Word 23-26 : Contains the revision number of the device's firmware.
uint8_t firmware_revision[8];
/// Word 27-46 : Contains the device's model number.
uint8_t model_number[40];
/// Word 47 : Maximum number of sectors that shall be transferred per interrupt.
uint8_t maximum_block_transfer;
/// Word 48 : Unused.
uint8_t unused3;
/// Word 49-50 :
struct {
/// Unused.
uint8_t current_long_physical_sector_alignment : 2;
/// Reserved.
uint8_t reserved_byte49 : 6;
/// Indicates that the device supports DMA operations.
uint8_t dma_supported : 1;
/// Indicates that the device supports logical block addressing.
uint8_t lba_supported : 1;
/// Indicates when set to 1 that I/O channel ready is disabled for the device.
uint8_t io_rdy_disable : 1;
/// Indicates when set to 1 that I/O channel ready is supported by the device.
uint8_t io_rdy_supported : 1;
/// Reserved.
uint8_t reserved1 : 1;
/// Indicates when set to 1 that the device supports standby timers.
uint8_t stand_by_timer_support : 1;
/// Reserved.
uint8_t reserved2 : 2;
/// Reserved.
uint16_t reserved_word50;
} capabilities;
/// Word 51-52 : Obsolete.
uint16_t unused4[2];
/// Word 53 : Bit 0 = obsolete; Bit 1 = words 70:64 valid; bit 2 = word 88 valid.
uint16_t valid_ext_data;
/// Word 54-58 : Obsolete.
uint16_t unused5[5];
/// Word 59 : Indicates the multisector setting.
uint8_t current_multisector_setting;
/// Indicates when TRUE that the multisector setting is valid.
uint8_t multisector_setting_valid : 1;
/// Reserved.
uint8_t reserved_byte59 : 3;
/// The device supports the sanitize command.
uint8_t sanitize_feature_supported : 1;
/// The device supports cryptographic erase.
uint8_t crypto_scramble_ext_command_supported : 1;
/// The device supports block overwrite.
uint8_t overwrite_ext_command_supported : 1;
/// The device supports block erase.
uint8_t block_erase_ext_command_supported : 1;
/// Word 60-61 : Contains the total number of 28 bit LBA addressable sectors on the drive.
uint32_t sectors_28;
/// Word 62-99 : We do not care for these right now.
uint16_t unused6[38];
/// Word 100-103: Contains the total number of 48 bit addressable sectors on the drive.
uint64_t sectors_48;
/// Word 104-256: We do not care for these right now.
uint16_t unused7[152];
} ata_identify_t;
/// @brief Physical Region Descriptor Table (PRDT) entry.
@@ -138,6 +207,7 @@ typedef struct ata_device_t {
ata_device_type_t type;
/// The "I/O" port base.
unsigned io_base;
/// I/O registers.
struct {
/// [R/W] Data Register. Read/Write PIO data bytes (16-bit).
unsigned data;
@@ -216,7 +286,7 @@ typedef struct ata_device_t {
vfs_file_t *fs_root;
} ata_device_t;
// The sector size.
/// The sector size.
#define ATA_SECTOR_SIZE 512
/// The size of the DMA area.
#define ATA_DMA_SIZE 512
@@ -397,12 +467,10 @@ static inline void ata_device_select(ata_device_t *dev)
static inline uint64_t ata_max_offset(ata_device_t *dev)
{
uint64_t sectors = dev->identity.sectors_48;
if (!sectors) {
// Fall back to sectors_28.
sectors = dev->identity.sectors_28;
if (dev->identity.sectors_48) {
return dev->identity.sectors_48 * ATA_SECTOR_SIZE;
}
return sectors * ATA_SECTOR_SIZE;
return dev->identity.sectors_28 * ATA_SECTOR_SIZE;
}
static inline void ata_fix_string(char *str, unsigned len)
@@ -430,11 +498,11 @@ static inline bool_t ata_read_device_identity(ata_device_t *dev, ata_identity_co
buffer[i] = inports(dev->io_reg.data);
}
// Fix the serial.
ata_fix_string((char *)&dev->identity.serial, 20 - 1);
ata_fix_string((char *)&dev->identity.serial_number, 20 - 1);
// Fix the firmware.
ata_fix_string((char *)&dev->identity.firmware, 8 - 1);
ata_fix_string((char *)&dev->identity.firmware_revision, 8 - 1);
// Fix the model.
ata_fix_string((char *)&dev->identity.model, 40 - 1);
ata_fix_string((char *)&dev->identity.model_number, 40 - 1);
return true;
}
@@ -592,9 +660,9 @@ static bool_t ata_device_init(ata_device_t *dev)
// Print the device data.
pr_debug("Device name : %s\n", dev->name);
pr_debug("Device status : [%s]\n", ata_get_device_status_str(dev));
pr_debug("Device Serial : %s\n", dev->identity.serial);
pr_debug("Device Firmware : %s\n", dev->identity.firmware);
pr_debug("Device Model : %s\n", dev->identity.model);
pr_debug("Device Serial : %s\n", dev->identity.serial_number);
pr_debug("Device Firmware : %s\n", dev->identity.firmware_revision);
pr_debug("Device Model : %s\n", dev->identity.model_number);
pr_debug("Sectors (48) : %d\n", dev->identity.sectors_48);
pr_debug("Sectors (24) : %d\n", dev->identity.sectors_28);
pr_debug("PCI device ID : 0x%x\n", ata_pci);
+2 -2
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[FDC ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "drivers/fdc.h"
+2 -2
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[KEYBRD]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "drivers/keyboard/keyboard.h"
+2 -2
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[MOUSE ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "drivers/mouse.h"
+2 -2
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[RTC ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "drivers/rtc.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[ELF ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "elf/elf.h"
+9 -143
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[EXT2 ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "process/scheduler.h"
@@ -62,6 +62,7 @@
// Data Structures
// ============================================================================
/// @brief Types of file in an EXT2 filesystem.
typedef enum ext2_file_type_t {
ext2_file_type_unknown, ///< Unknown type.
ext2_file_type_regular_file, ///< Regular file.
@@ -73,6 +74,7 @@ typedef enum ext2_file_type_t {
ext2_file_type_symbolic_link ///< Symbolic link.
} ext2_file_type_t;
/// @brief Status of a block.
typedef enum ext2_block_status_t {
ext2_block_status_free = 0, ///< The block is free.
ext2_block_status_occupied = 1 ///< The block is occupied.
@@ -210,7 +212,7 @@ typedef struct ext2_superblock_t {
uint8_t reserved[760];
} ext2_superblock_t;
/// @brief
/// @brief Entry of the Block Group Descriptor Table (BGDT).
typedef struct ext2_group_descriptor_t {
/// @brief The block number of the block bitmap for this Block Group
uint32_t block_bitmap;
@@ -256,10 +258,10 @@ typedef struct ext2_inode_t {
uint32_t flags;
/// @brief OS dependant value.
uint32_t osd1;
/// @brief
union blocks_t {
/// [60 byte]
struct blocks_data_t {
/// @brief Mutable data.
union {
/// [60 byte] Blocks indices.
struct {
/// [48 byte]
uint32_t dir_blocks[EXT2_INDIRECT_BLOCKS];
/// [ 4 byte]
@@ -3032,139 +3034,3 @@ int ext2_finalize(void)
vfs_unregister_filesystem(&ext2_file_system_type);
return 0;
}
#include "assert.h"
void dump_dir(vfs_file_t *dir)
{
ext2_filesystem_t *fs = (ext2_filesystem_t *)dir->device;
// Check the filesystem.
if (fs == NULL) {
pr_err("The directory does not belong to an EXT2 filesystem `%s`.\n", dir->name);
return;
}
// Check the magic number.
if (fs->superblock.magic != EXT2_SUPERBLOCK_MAGIC) {
pr_err("The directory does not belong to an EXT2 filesystem `%s`.\n", dir->name);
return;
}
// Get the inode associated with the directory.
ext2_inode_t inode;
if (ext2_read_inode(fs, &inode, dir->ino) == -1) {
pr_err("Failed to read the inode (%d).\n", dir->ino);
return;
}
pr_debug("dir: `%-s` inode: `%4d` {\n", dir->name, dir->ino);
// Allocate the cache.
uint8_t *cache = kmem_cache_alloc(fs->ext2_buffer_cache, GFP_KERNEL);
// Clean the cache.
memset(cache, 0, fs->block_size);
// Iterate the directory.
ext2_direntry_iterator_t it = ext2_direntry_iterator_begin(fs, cache, &inode);
for (; ext2_direntry_iterator_valid(&it); ext2_direntry_iterator_next(&it)) {
if (it.direntry->inode != 0) {
ext2_inode_t __inode;
ext2_read_inode(fs, &__inode, it.direntry->inode);
pr_debug(" %-16s (inode: %4d, type: %2d, rec_len: %4d, name_len: %2d)[size: %d]\n",
it.direntry->name,
it.direntry->inode,
it.direntry->file_type,
it.direntry->rec_len,
it.direntry->name_len,
__inode.size);
} else {
pr_debug(" %-16s (inode: %4d, type: %2d, rec_len: %4d, name_len: %2d)\n",
it.direntry->name,
it.direntry->inode,
it.direntry->file_type,
it.direntry->rec_len,
it.direntry->name_len);
}
//ext2_dump_inode(&__inode);
//pr_debug("\n");
}
pr_debug("}\n");
kmem_cache_free(cache);
}
void ext2_test()
{
#if 0
char buffer[256];
memset(buffer, 0, 256);
for (int i = 0; i < 256; ++i) {
buffer[i] = '0' + (i % 9);
}
buffer[255] = 0;
vfs_file_t *home, *test1, *test2, *test3;
assert(home = vfs_open("/home", O_RDONLY, 0));
dump_dir(home);
assert(test1 = vfs_creat("/home/test1.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
dump_dir(home);
assert(test2 = vfs_creat("/home/test2.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
dump_dir(home);
assert(test3 = vfs_creat("/home/test3.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
dump_dir(home);
vfs_write(test1, buffer, 0, 256);
vfs_close(test1);
dump_dir(home);
vfs_write(test2, buffer, 0, 256);
vfs_close(test2);
dump_dir(home);
vfs_write(test3, buffer, 0, 256);
vfs_close(test3);
dump_dir(home);
vfs_mkdir("/home/pippo", EXT2_S_IRWXU | EXT2_S_IRGRP | EXT2_S_IXGRP | EXT2_S_IROTH | EXT2_S_IXOTH);
dump_dir(home);
vfs_rmdir("/home/pippo");
dump_dir(home);
vfs_rmdir("/home");
dump_dir(home);
vfs_close(home);
vfs_unlink("/home/test1.txt");
dump_dir(home);
vfs_unlink("/home/test2.txt");
dump_dir(home);
vfs_unlink("/home/test3.txt");
dump_dir(home);
#elif 1
vfs_file_t *home, *file;
assert(home = vfs_open("/home", O_RDONLY, 0));
dump_dir(home);
assert(file = vfs_creat("/home/test_file_1.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
vfs_close(file);
assert(file = vfs_creat("/home/test_file_2.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
vfs_close(file);
vfs_unlink("/home/test_file_1.txt");
vfs_unlink("/home/test_file_2.txt");
dump_dir(home);
assert(file = vfs_creat("/home/test_file_4.txt", EXT2_S_IWUSR | EXT2_S_IRUSR | EXT2_S_IRGRP | EXT2_S_IROTH));
vfs_close(file);
dump_dir(home);
vfs_close(home);
while (true) {}
#endif
}
+3 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PROCFS]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "fs/procfs.h"
@@ -73,6 +73,7 @@ typedef struct procfs_t {
kmem_cache_t *procfs_file_cache;
} procfs_t;
/// The procfs filesystem.
procfs_t fs;
// ============================================================================
+2 -2
View File
@@ -7,9 +7,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[VFS ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "process/scheduler.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PIC ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "hardware/pic8259.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[TIMER ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "hardware/timer.h"
+111 -32
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[VGA ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "io/vga/vga.h"
@@ -22,23 +22,40 @@
#include "io/debug.h"
#include "math.h"
/// Counts the number of elements of an array.
#define COUNT_OF(x) ((sizeof(x) / sizeof(0 [x])) / ((size_t)(!(sizeof(x) % sizeof(0 [x])))))
#define AC_INDEX 0x03C0
#define AC_WRITE 0x03C0
#define AC_READ 0x03C1
#define MISC_WRITE 0x03C2
#define MISC_READ 0x03CC
#define SC_INDEX 0x03C4 // VGA sequence controller.
#define SC_DATA 0x03C5
#define PALETTE_MASK 0x03C6
#define PALETTE_READ 0x03C7
#define PALETTE_INDEX 0x03C8 // VGA digital-to-analog converter.
#define PALETTE_DATA 0x03C9
#define GC_INDEX 0x03CE // VGA graphics controller.
#define GC_DATA 0x03CF
#define CRTC_INDEX 0x03D4 // VGA CRT controller.
#define CRTC_DATA 0x03D5
/// Attribute Controller index port.
#define AC_INDEX 0x03C0
/// Attribute Controller write port.
#define AC_WRITE 0x03C0
/// Attribute Controller data port.
#define AC_READ 0x03C1
/// Miscellaneous output register.
#define MISC_WRITE 0x03C2
/// Miscellaneous input register.
#define MISC_READ 0x03CC
/// Sequence controller index.
#define SC_INDEX 0x03C4
/// Sequence controller data.
#define SC_DATA 0x03C5
/// DAC Mask Register.
#define PALETTE_MASK 0x03C6
/// Controls the DAC.
#define PALETTE_READ 0x03C7
/// Controls the DAC index.
#define PALETTE_INDEX 0x03C8
/// Controls the DAC data.
#define PALETTE_DATA 0x03C9
/// Graphics controller index.
#define GC_INDEX 0x03CE
/// Graphics controller data.
#define GC_DATA 0x03CF
/// CRT controller index.
#define CRTC_INDEX 0x03D4
/// CRT controller data.
#define CRTC_DATA 0x03D5
/// By reading this port it'll go to the index state.
#define INPUT_STATUS_READ 0x03DA
/// VGA pointers for drawing operations.
@@ -69,21 +86,32 @@ typedef struct {
vga_ops_t *ops; ///< Writing operations.
} vga_driver_t;
/// Is VGA enabled.
static bool_t vga_enable = false;
/// The stored palette.
palette_entry_t stored_palette[256];
/// A buffer for storing a copy of the video memory.
char vidmem[262144];
/// Current driver.
static vga_driver_t *driver = NULL;
static vga_font_t *font;
/// Current font.
static vga_font_t *__font = NULL;
// ============================================================================
// == VGA MODEs ===============================================================
#define MODE_NUM_SEQ_REGS 5
/// Number of sequencer registers.
#define MODE_NUM_SEQ_REGS 5
/// Number of CRTC registers.
#define MODE_NUM_CRTC_REGS 25
#define MODE_NUM_GC_REGS 9
#define MODE_NUM_AC_REGS (16 + 5)
#define MODE_NUM_REGS (1 + MODE_NUM_SEQ_REGS + MODE_NUM_CRTC_REGS + MODE_NUM_GC_REGS + MODE_NUM_AC_REGS) // 61
/// Number of Graphics Controller (GC) registers.
#define MODE_NUM_GC_REGS 9
/// Number of Attribute Controller (AC) registers.
#define MODE_NUM_AC_REGS (16 + 5)
/// Total number of registers.
#define MODE_NUM_REGS (1 + MODE_NUM_SEQ_REGS + MODE_NUM_CRTC_REGS + MODE_NUM_GC_REGS + MODE_NUM_AC_REGS) // 61
/// @brief Returns the video address.
/// @return pointer to the video.
static inline char *__get_seg(void)
{
unsigned int seg;
@@ -98,6 +126,11 @@ static inline char *__get_seg(void)
return (char *)seg;
}
/// @brief Sets the color at the given index.
/// @param index index of the palette we want to change.
/// @param r red.
/// @param g green.
/// @param b blue.
void __vga_set_color_map(unsigned int index, unsigned char r, unsigned char g, unsigned char b)
{
outportb(PALETTE_MASK, 0xFF);
@@ -107,6 +140,11 @@ void __vga_set_color_map(unsigned int index, unsigned char r, unsigned char g, u
outportl(PALETTE_DATA, b);
}
/// @brief Gets the color at the given index.
/// @param index index of the palette we want to read.
/// @param r output value for red.
/// @param g output value for green.
/// @param b output value for blue.
void __vga_get_color_map(unsigned int index, unsigned char *r, unsigned char *g, unsigned char *b)
{
outportb(PALETTE_MASK, 0xFF);
@@ -116,6 +154,9 @@ void __vga_get_color_map(unsigned int index, unsigned char *r, unsigned char *g,
*b = inportl(PALETTE_DATA);
}
/// @brief Saves the current palette in p.
/// @param p output variable where we save the palette.
/// @param size the size of the palette.
static void __save_palette(palette_entry_t *p, size_t size)
{
outportb(PALETTE_MASK, 0xFF);
@@ -127,6 +168,9 @@ static void __save_palette(palette_entry_t *p, size_t size)
}
}
/// @brief Loads the palette p.
/// @param p palette we are going to load.
/// @param size the size of the palette.
static void __load_palette(palette_entry_t *p, size_t size)
{
outportb(PALETTE_MASK, 0xFF);
@@ -138,6 +182,8 @@ static void __load_palette(palette_entry_t *p, size_t size)
}
}
/// @brief Sets the current plane.
/// @param plane the plane to set.
static inline void __set_plane(unsigned int plane)
{
unsigned char pmask;
@@ -151,16 +197,23 @@ static inline void __set_plane(unsigned int plane)
outportb(SC_DATA, pmask);
}
/// @brief Reads from the video memory.
/// @param offset where we are going to read.
/// @return the value we read.
static unsigned char __read_byte(unsigned int offset)
{
return (unsigned char)(*(driver->address + offset));
}
/// @brief Writes onto the video memory.
/// @param offset where we are going to write.
static void __write_byte(unsigned int offset, unsigned char value)
{
*(char *)(driver->address + offset) = value;
}
/// @brief Sets the given mode.
/// @param vga_mode the new mode we set.
static void __set_mode(vga_mode_t *vga_mode)
{
unsigned char *ptr = &vga_mode->misc;
@@ -213,6 +266,8 @@ static void __set_mode(vga_mode_t *vga_mode)
outportb(AC_INDEX, 0x20);
}
/// @brief Reads the VGA registers.
/// @param vga_mode the current VGA mode.
static void __read_registers(vga_mode_t *vga_mode)
{
unsigned char *ptr = &vga_mode->misc;
@@ -255,6 +310,9 @@ static void __read_registers(vga_mode_t *vga_mode)
outportb(AC_INDEX, 0x20);
}
/// @brief Writes the font.
/// @param buf buffer where the font resides.
/// @param font_height the height of the font.
static void __write_font(unsigned char *buf, unsigned font_height)
{
unsigned char seq2, seq4, gc4, gc5, gc6;
@@ -306,6 +364,10 @@ assume: chain-4 addressing already off */
// ============================================================================
// == WRITE PIXEL FUNCTIONS ===================================================
/// @brief Writes a pixel.
/// @param x x coordinates.
/// @param y y coordinates.
/// @param c color.
static void __write_pixel_1(unsigned int x, unsigned int y, unsigned char c)
{
unsigned wd_in_bytes;
@@ -319,6 +381,10 @@ static void __write_pixel_1(unsigned int x, unsigned int y, unsigned char c)
__write_byte(off, (__read_byte(off) & ~mask) | (c & mask));
}
/// @brief Writes a pixel.
/// @param x x coordinates.
/// @param y y coordinates.
/// @param c color.
static void __write_pixel_2(unsigned int x, unsigned int y, unsigned char c)
{
unsigned wd_in_bytes;
@@ -332,6 +398,10 @@ static void __write_pixel_2(unsigned int x, unsigned int y, unsigned char c)
__write_byte(off, (__read_byte(off) & ~mask) | (c & mask));
}
/// @brief Writes a pixel.
/// @param x x coordinates.
/// @param y y coordinates.
/// @param c color.
static void __write_pixel_4(unsigned int x, unsigned int y, unsigned char color)
{
int rotation = 0;
@@ -370,6 +440,10 @@ static void __write_pixel_4(unsigned int x, unsigned int y, unsigned char color)
}
}
/// @brief Writes a pixel.
/// @param x x coordinates.
/// @param y y coordinates.
/// @param c color.
static inline void __write_pixel_8(unsigned int x, unsigned int y, unsigned char color)
{
__set_plane(x);
@@ -377,6 +451,9 @@ static inline void __write_pixel_8(unsigned int x, unsigned int y, unsigned char
// (y << 6) + (y << 4) + (x >> 2)
}
/// @brief Reverses the bits of the given number.
/// @param num the number of which we want to reverse the bits.
/// @return reversed bits.
unsigned int reverseBits(char num)
{
unsigned int NO_OF_BITS = sizeof(num) * 8;
@@ -408,11 +485,13 @@ int vga_height()
return 0;
}
void vga_setfont(const vga_font_t *__font)
/// @brief Sets the given font.
/// @param font the new font.
void __vga_setfont(const vga_font_t *font)
{
font->font = __font->font;
font->width = __font->width;
font->height = __font->height;
__font->font = font->font;
__font->width = font->width;
__font->height = font->height;
}
void vga_clear_screen()
@@ -436,10 +515,10 @@ void vga_draw_char(unsigned int x, unsigned int y, unsigned char c, unsigned cha
1u << 7u, // 128
1u << 8u, // 256
};
unsigned char *glyph = font->font + c * font->height;
for (unsigned cy = 0; cy < font->height; ++cy) {
for (unsigned cx = 0; cx < font->width; ++cx) {
driver->ops->write_pixel(x + (font->width - cx), y + cy, glyph[cy] & mask[cx] ? color : 0x00u);
unsigned char *glyph = __font->font + c * __font->height;
for (unsigned cy = 0; cy < __font->height; ++cy) {
for (unsigned cx = 0; cx < __font->width; ++cx) {
driver->ops->write_pixel(x + (__font->width - cx), y + cy, glyph[cy] & mask[cx] ? color : 0x00u);
}
}
}
@@ -653,7 +732,7 @@ void vga_initialize()
driver->address = __get_seg();
// Set the font.
vga_setfont(&font_8x8);
__vga_setfont(&font_8x8);
// Save the content of the memory.
memcpy(vidmem, driver->address, 0x4000);
+2 -2
View File
@@ -368,7 +368,7 @@ struct shmid_ds *find_shm_fromvaddr(void *shmvaddr)
}
#endif
long sys_shmat(int shmid, char *shmaddr, int shmflg)
void * sys_shmat(int shmid, const void *shmaddr, int shmflg)
{
TODO("Not implemented");
return 0;
@@ -380,7 +380,7 @@ long sys_shmget(key_t key, size_t size, int flag)
return 0;
}
long sys_shmdt(char *shmaddr)
long sys_shmdt(const void *shmaddr)
{
TODO("Not implemented");
return 0;
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[KERNEL]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "io/proc_modules.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[BUDDY ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_DEBUG
#include "mem/buddysystem.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[KHEAP ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/kheap.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PAGING]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/paging.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[SLAB ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/zone_allocator.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[VMEM ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/vmem_map.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PMM ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/zone_allocator.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[BOOT ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "multiboot.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[PROC ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "process/process.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[SCHED ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "assert.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[SCHALG]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "hardware/timer.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[WAIT ]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "process/wait.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[MODULE]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "mem/slab.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[SIGNAL]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "system/signal.h"
+2 -2
View File
@@ -5,9 +5,9 @@
// Include the kernel log levels.
#include "sys/kernel_levels.h"
// Change the header.
/// Change the header.
#define __DEBUG_HEADER__ "[SYSCLL]"
// Set the log level.
/// Set the log level.
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE
#include "devices/fpu.h"