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
@@ -192,9 +192,9 @@ You can change the logging level by including the following lines at the beginni
```C++
// 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_INFO
```
This example sets the `__DEBUG_LEVEL__`, so that all the messages from `INFO` and below are shown. While `__DEBUG_HEADER__` is just a string that is automatically prepended to your message, helping you identifying from which code the message is coming from.
+1 -1
View File
@@ -853,7 +853,7 @@ INPUT_ENCODING = UTF-8
# C comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f, *.for, *.tcl, *.vhd,
# *.vhdl, *.ucf, *.qsf and *.ice.
FILE_PATTERNS = *.c *.h
FILE_PATTERNS = *.c *.h *.S
# The RECURSIVE tag can be used to specify whether or not subdirectories should
# be searched for input files as well.
+2 -1
View File
@@ -35,7 +35,8 @@ void dbg_printf(const char *file, const char *fun, int line, const char *format,
const char *to_human_size(unsigned long bytes);
/// @brief Transforms the given value to a binary string.
/// @param value The decimal value.
/// @param value to print.
/// @param length of the binary output.
/// @return String representing the binary value.
const char *dec_to_binary(unsigned long value, unsigned length);
+51 -54
View File
@@ -10,66 +10,63 @@
/// Maximum number of users per group
#define MAX_MEMBERS_PER_GROUP 64
///@brief Contains user group informations
typedef struct group{
/// @brief Contains user group informations.
typedef struct group {
/// The name of the group.
char *gr_name;
/// Encrypted password.
char *gr_passwd;
/// Group ID.
gid_t gr_gid;
/// List of group members.
char *gr_mem[MAX_MEMBERS_PER_GROUP + 1];
} group_t;
char* gr_name; // the name of the group
gid_t gr_gid; // numerical group ID
char* gr_passwd; // password
/// @brief Provides access to the group database entry for `uid`.
/// @param gid The gid to search inside the database.
/// @return A pointer to the structure containing the database entry.
group_t *getgrgid(gid_t gid);
//pointer to a null-terminated array of character pointers to member names
char* gr_mem[MAX_MEMBERS_PER_GROUP + 1];
} group;
/// @brief Provides access to the group database entry for `name`.
/// @param name The name to search inside the database.
/// @return A pointer to the structure containing the database entry.
group_t *getgrnam(const char *name);
///@brief Provides access to the group database entry for `uid`.
///@param gid The gid to search inside the database.
///@return A pointer to the structure containing the database entry.
struct group* getgrgid(gid_t gid);
/// @brief Provides the same information as getgrgid but it stores the results
/// inside group, and the string information are store store inside `buf`.
/// @param gid The uid to search inside the database.
/// @param group The structure containing pointers to the entry fields.
/// @param buf The buffer where the strings should be stored.
/// @param buflen The lenght of the buffer.
/// @param result A pointer to the result or NULL is stored here.
/// @return If the entry was found returns zero and set *result to group, if the
/// entry was not found returns zero and set *result to NULL, on failure returns
/// a number and sets and set *result to NULL.
int getgrgid_r(gid_t gid, group_t *group, char *buf, size_t buflen, group_t **result);
///@brief Provides access to the group database entry for `name`.
///@param name The name to search inside the database.
///@return A pointer to the structure containing the database entry.
struct group* getgrnam(const char* name);
/// @brief Provides the same information as getgrnam but it stores the results
///inside group, and the string information are store store inside `buf`.
/// @param name The name to search inside the database.
/// @param group The structure containing pointers to the entry fields.
/// @param buf The buffer where the strings should be stored.
/// @param buflen The lenght of the buffer.
/// @param result A pointer to the result or NULL is stored here.
/// @return If the entry was found returns zero and set *result to group, if the
/// entry was not found returns zero and set *result to NULL, on failure returns
/// a number and sets and set *result to NULL.
int getgrnam_r(const char *name, group_t *group, char *buf, size_t buflen, group_t **result);
///@brief Provides the same information as getgrgid but it stores the
/// results inside group, and the string information are store store
/// inside `buf`.
///@param gid The uid to search inside the database.
///@param group The structure containing pointers to the entry fields.
///@param buf The buffer where the strings should be stored.
///@param buflen The lenght of the buffer.
///@param result A pointer to the result or NULL is stored here.
///@return If the entry was found returns zero and set *result to group,
/// if the entry was not found returns zero and set *result to NULL,
/// on failure returns a number and sets and set *result to NULL.
int getgrgid_r(gid_t gid, struct group* group, char* buf, size_t buflen, struct group ** result);
/// @brief Returns a pointer to a structure containing the broken-out fields of
/// an entry in the group database.
/// @return pointer to the group entry.
/// @details When first called returns a pointer to a group structure containing
/// the first entry in the group database. Thereafter, it returns a pointer to a
/// group structure containing the next group structure in the group database,
/// so successive calls may be used to search the entire database.
group_t *getgrent(void);
///@brief Provides the same information as getgrnam but it stores the
/// results inside group, and the string information are store store
/// inside `buf`.
///@param name The name to search inside the database.
///@param group The structure containing pointers to the entry fields.
///@param buf The buffer where the strings should be stored.
///@param buflen The lenght of the buffer.
///@param result A pointer to the result or NULL is stored here.
///@return If the entry was found returns zero and set *result to group,
/// if the entry was not found returns zero and set *result to NULL,
/// on failure returns a number and sets and set *result to NULL.
int getgrnam_r(const char* name, struct group* group, char* buf, size_t buflen, struct group** result);
///@brief Returns a pointer to a structure containing the broken-out
/// fields of an entry in the group database.
/// When first called returns a pointer to a group structure
/// containing the first entry in the group database.
/// Thereafter, it returns a pointer to a group structure
/// containing the next group structure in the group database,
/// so successive calls may be used to search the entire database.
struct group* getgrent(void);
///@brief Rewinds the group database to allow repeated searches.
/// @brief Rewinds the group database to allow repeated searches.
void endgrent(void);
///@brief May be called to close the group database when processing is complete.
/// @brief May be called to close the group database when processing is complete.
void setgrent(void);
+66 -10
View File
@@ -17,15 +17,15 @@ typedef unsigned int msgqnum_t;
typedef unsigned int msglen_t;
/// @brief Buffer to use with the message queue IPC.
struct msgbuf {
typedef struct msgbuf {
/// Type of the message.
long mtype;
/// Text of the message.
char mtext[1];
};
} msgbuf_t;
/// @brief Message queue data structure.
struct msqid_ds {
typedef struct msqid_ds {
/// Ownership and permissions.
struct ipc_perm msg_perm;
/// Time of last msgsnd(2).
@@ -44,26 +44,82 @@ struct msqid_ds {
pid_t msg_lspid;
/// PID of last msgrcv(2).
pid_t msg_lrpid;
};
} msqid_ds_t;
#ifdef __KERNEL__
/// @brief Get a System V message queue identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created message queue, or to create a new set.
/// @param msgflg controls the behaviour of the function.
/// @return the message queue identifier, -1 on failure, and errno is set to
/// indicate the error.
long sys_msgget(key_t key, int msgflg);
long sys_msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg);
/// @brief Used to send messages.
/// @param msqid the message queue identifier.
/// @param msgp points to a used-defined msgbuf.
/// @param msgsz specifies the size in bytes of mtext.
/// @param msgflg specifies the action to be taken in case of specific events.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
long sys_msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg);
/// @brief Used to receive messages.
/// @param msqid the message queue identifier.
/// @param msgp points to a used-defined msgbuf.
/// @param msgsz specifies the size in bytes of mtext.
/// @param msgtyp specifies the type of message requested, as follows:
/// - msgtyp == 0: the first message on the queue is received.
/// - msgtyp > 0: the first message of type, msgtyp, is received.
/// - msgtyp < 0: the first message of the lowest type that is less than or
/// equal to the absolute value of msgtyp is received.
/// @param msgflg specifies the action to be taken in case of specific events.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_msgrcv(int msqid, msgbuf_t *msgp, size_t msgsz, long msgtyp, int msgflg);
long sys_msgctl(int msqid, int cmd, struct msqid_ds *buf);
/// @brief Message queue control operations.
/// @param msqid the message queue identifier.
/// @param cmd The command to perform.
/// @param buf used with IPC_STAT and IPC_SET.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_msgctl(int msqid, int cmd, msqid_ds_t *buf);
#else
/// @brief Get a System V message queue identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created message queue, or to create a new set.
/// @param msgflg controls the behaviour of the function.
/// @return the message queue identifier, -1 on failure, and errno is set to
/// indicate the error.
long msgget(key_t key, int msgflg);
long msgsnd(int msqid, struct msgbuf *msgp, size_t msgsz, int msgflg);
/// @brief Used to send messages.
/// @param msqid the message queue identifier.
/// @param msgp points to a used-defined msgbuf.
/// @param msgsz specifies the size in bytes of mtext.
/// @param msgflg specifies the action to be taken in case of specific events.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long msgsnd(int msqid, msgbuf_t *msgp, size_t msgsz, int msgflg);
long msgrcv(int msqid, struct msgbuf *msgp, size_t msgsz, long msgtyp, int msgflg);
/// @brief Used to receive messages.
/// @param msqid the message queue identifier.
/// @param msgp points to a used-defined msgbuf.
/// @param msgsz specifies the size in bytes of mtext.
/// @param msgtyp specifies the type of message requested, as follows:
/// - msgtyp == 0: the first message on the queue is received.
/// - msgtyp > 0: the first message of type, msgtyp, is received.
/// - msgtyp < 0: the first message of the lowest type that is less than or
/// equal to the absolute value of msgtyp is received.
/// @param msgflg specifies the action to be taken in case of specific events.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long msgrcv(int msqid, msgbuf_t *msgp, size_t msgsz, long msgtyp, int msgflg);
long msgctl(int msqid, int cmd, struct msqid_ds *buf);
/// @brief Message queue control operations.
/// @param msqid the message queue identifier.
/// @param cmd The command to perform.
/// @param buf used with IPC_STAT and IPC_SET.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long msgctl(int msqid, int cmd, msqid_ds_t *buf);
#endif
+36
View File
@@ -22,18 +22,54 @@ struct sembuf {
#ifdef __KERNEL__
/// @brief Get a System V semaphore set identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created semaphore set, or to create a new set.
/// @param nsems number of semaphores.
/// @param semflg controls the behaviour of the function.
/// @return the semaphore set identifier, -1 on failure, and errno is set to
/// indicate the error.
long sys_semget(key_t key, int nsems, int semflg);
/// @brief Performs operations on selected semaphores in the set.
/// @param semid the semaphore set identifier.
/// @param sops specifies operations to be performed on single semaphores.
/// @param nsops number of operations.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_semop(int semid, struct sembuf *sops, unsigned nsops);
/// @brief Performs control operations on a semaphore set.
/// @param semid the semaphore set identifier.
/// @param semnum the n-th semaphore of the set on which we perform the operations.
/// @param cmd the command to perform.
/// @param arg
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_semctl(int semid, int semnum, int cmd, unsigned long arg);
#else
/// @brief Get a System V semaphore set identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created semaphore set, or to create a new set.
/// @param nsems number of semaphores.
/// @param semflg controls the behaviour of the function.
/// @return the semaphore set identifier, -1 on failure, and errno is set to
/// indicate the error.
long semget(key_t key, int nsems, int semflg);
/// @brief Performs operations on selected semaphores in the set.
/// @param semid the semaphore set identifier.
/// @param sops specifies operations to be performed on single semaphores.
/// @param nsops number of operations.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long semop(int semid, struct sembuf *sops, unsigned nsops);
/// @brief Performs control operations on a semaphore set.
/// @param semid the semaphore set identifier.
/// @param semnum the n-th semaphore of the set on which we perform the operations.
/// @param cmd the command to perform.
/// @param arg
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long semctl(int semid, int semnum, int cmd, unsigned long arg);
#endif
+56 -6
View File
@@ -135,22 +135,72 @@ struct shmid_ds *find_shm_fromvaddr(void *shmvaddr);
#ifdef __KERNEL__
long sys_shmat(int shmid, char *shmaddr, int shmflg);
/// @brief Get a System V shared memory identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created shared memory, or to create a new one.
/// @param size of the shared memory, rounded up to a multiple of PAGE_SIZE.
/// @param flag controls the behaviour of the function.
/// @return the shared memory identifier, -1 on failure, and errno is set to
/// indicate the error.
long sys_shmget(key_t key, size_t size, int flag);
long sys_shmdt(char *shmaddr);
/// @brief Attaches the shared memory segment identified by shmid to the address
/// space of the calling process.
/// @param shmid the shared memory identifier.
/// @param shmaddr the attaching address.
/// @param shmflg controls the behaviour of the function.
/// @return returns the address of the attached shared memory segment; on error
/// (void *) -1 is returned, and errno is set to indicate the error.
void * sys_shmat(int shmid, const void *shmaddr, int shmflg);
/// @brief Detaches the shared memory segment located at the address specified
/// by shmaddr from the address space of the calling process
/// @param shmaddr the address of the shared memory segment.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long sys_shmdt(const void *shmaddr);
/// @brief Performs the control operation specified by cmd on the shared memory
/// segment whose identifier is given in shmid.
/// @param shmid the shared memory identifier.
/// @param cmd the command to perform.
/// @param buf is a pointer to a shmid_ds structure.
/// @return a non-negative value basedon on the requested operation, -1 on
/// failure and errno is set to indicate the error.
long sys_shmctl(int shmid, int cmd, struct shmid_ds *buf);
#else
long shmat(int shmid, char *shmaddr, int shmflg);
/// @brief Get a System V shared memory identifier.
/// @param key can be used either to obtain the identifier of a previously
/// created shared memory, or to create a new one.
/// @param size of the shared memory, rounded up to a multiple of PAGE_SIZE.
/// @param flag controls the behaviour of the function.
/// @return the shared memory identifier, -1 on failure, and errno is set to
/// indicate the error.
long shmget(key_t key, size_t size, int flag);
long shmdt(char *shmaddr);
/// @brief Attaches the shared memory segment identified by shmid to the address
/// space of the calling process.
/// @param shmid the shared memory identifier.
/// @param shmaddr the attaching address.
/// @param shmflg controls the behaviour of the function.
/// @return returns the address of the attached shared memory segment; on error
/// (void *) -1 is returned, and errno is set to indicate the error.
void * shmat(int shmid, const void *shmaddr, int shmflg);
/// @brief Detaches the shared memory segment located at the address specified
/// by shmaddr from the address space of the calling process
/// @param shmaddr the address of the shared memory segment.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
long shmdt(const void *shmaddr);
/// @brief Performs the control operation specified by cmd on the shared memory
/// segment whose identifier is given in shmid.
/// @param shmid the shared memory identifier.
/// @param cmd the command to perform.
/// @param buf is a pointer to a shmid_ds structure.
/// @return a non-negative value basedon on the requested operation, -1 on
/// failure and errno is set to indicate the error.
long shmctl(int shmid, int cmd, struct shmid_ds *buf);
#endif
+15
View File
@@ -21,8 +21,23 @@ typedef struct sched_param_t {
bool_t is_periodic;
} sched_param_t;
/// @brief Sets scheduling parameters.
/// @param pid pid of the process we want to change the parameters. If zero,
/// then the parameters of the calling process are set.
/// @param param The interpretation of the argument param depends on the
/// scheduling policy of the thread identified by pid.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int sched_setparam(pid_t pid, const sched_param_t *param);
/// @brief Gets scheduling parameters.
/// @param pid pid of the process we want to retrieve the parameters. If zero,
/// then the parameters of the calling process are returned.
/// @param param The interpretation of the argument param depends on the
/// scheduling policy of the thread identified by pid.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int sched_getparam(pid_t pid, sched_param_t *param);
/// @brief Placed at the end of an infinite while loop, stops the process until,
/// its next period starts. The calling process must be a periodic one.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int waitperiod();
+7
View File
@@ -222,11 +222,13 @@ char *getcwd(char *buf, size_t size);
/// @brief Changes the current working directory to the given path.
/// @param path The new current working directory.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int chdir(char const *path);
/// @brief Is identical to chdir(), the only difference is that the
/// directory is given as an open file descriptor.
/// @param fd The file descriptor of the open directory.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int fchdir(int fd);
/// Provide access to the directory entries.
@@ -239,4 +241,9 @@ int fchdir(int fd);
int getdents(int fd, dirent_t *dirp, unsigned int count);
/// @brief Send signal to calling thread after desired seconds.
/// @param seconds the amount of seconds.
/// @return If there is a previous alarm() request with time remaining, alarm()
/// shall return a non-zero value that is the number of seconds until the
/// previous request would have generated a SIGALRM signal. Otherwise, alarm()
/// shall return 0.
int alarm(int seconds);
+27 -12
View File
@@ -7,10 +7,16 @@
#include "stddef.h"
/// Domains of interval timers
#define ITIMER_REAL 0
/// @brief This timer counts down in real (i.e., wall clock) time. At each
/// expiration, a SIGALRM signal is generated.
#define ITIMER_REAL 0
/// @brief This timer counts down against the user-mode CPU time consumed by the
/// process. At each expiration, a SIGVTALRM signal is generated.
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
/// @brief This timer counts down against the total (i.e., both user and system)
/// CPU time consumed by the process. At each expiration, a SIGPROF signal is
/// generated.
#define ITIMER_PROF 2
/// Used to store time values.
typedef unsigned int time_t;
@@ -37,16 +43,16 @@ typedef struct tm_t {
int tm_isdst;
} tm_t;
/// Rappresents time
/// Rappresents time.
typedef struct _timeval {
time_t tv_sec; /* seconds */
time_t tv_usec; /* microseconds */
time_t tv_sec; ///< Seconds.
time_t tv_usec; ///< Microseconds.
} timeval;
/// Rappresents a time interval
/// Rappresents a time interval.
typedef struct _itimerval {
timeval it_interval; /* next value */
timeval it_value; /* current value */
timeval it_interval; ///< Next value.
timeval it_value; ///< Current value.
} itimerval;
/// @brief Specify intervals of time with nanosecond precision.
@@ -101,9 +107,18 @@ int nanosleep(const timespec *req, timespec *rem);
/// left to sleep, if the call was interrupted by a signal handler.
unsigned int sleep(unsigned int seconds);
/// @brief Fills the structure pointed to by curr_value with the current setting for the timer specified by which.
/// @brief Fills the structure pointed to by curr_value with the current setting
/// for the timer specified by which.
/// @param which which timer.
/// @param curr_value where we place the timer value.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int getitimer(int which, itimerval *curr_value);
/// @brief The system provides each process with three interval timers, each decrementing in a distinct time domain.
/// When any timer expires, a signal is sent to the process, and the timer (potentially) restarts.
/// @brief The system provides each process with three interval timers, each
/// decrementing in a distinct time domain. When any timer expires, a signal is
/// sent to the process, and the timer (potentially) restarts.
/// @param which which timer.
/// @param new_value the new value for the timer.
/// @param old_value output variable where the function places the previous value.
/// @return 0 on success, -1 on failure and errno is set to indicate the error.
int setitimer(int which, const itimerval *new_value, itimerval *old_value);
+32 -35
View File
@@ -3,7 +3,7 @@
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
#include "grp.h"
#include "grp.h"
#include "sys/unistd.h"
#include "sys/errno.h"
#include "assert.h"
@@ -12,8 +12,9 @@
#include "debug.h"
#include "fcntl.h"
static int __fd = -1;
static inline void __parse_line(struct group* grp, char *buf)
static inline void __parse_line(group_t *grp, char *buf)
{
assert(grp && "Received null grp!");
char *token;
@@ -28,7 +29,7 @@ static inline void __parse_line(struct group* grp, char *buf)
grp->gr_gid = atoi(token);
size_t found_users = 0;
while((token = strtok(NULL, ",\n\0")) != NULL && found_users < MAX_MEMBERS_PER_GROUP) {
while ((token = strtok(NULL, ",\n\0")) != NULL && found_users < MAX_MEMBERS_PER_GROUP) {
grp->gr_mem[found_users] = token;
found_users += 1;
}
@@ -89,45 +90,44 @@ static inline char *__search_entry(int fd, char *buf, int buflen, const char *na
return NULL;
}
struct group* getgrgid(gid_t gid) {
static group grp;
group_t *getgrgid(gid_t gid)
{
static group_t grp;
static char buffer[BUFSIZ];
group *result;
group_t *result;
if (!getgrgid_r(gid, &grp, buffer, BUFSIZ, &result))
return NULL;
return &grp;
}
struct group *getgrnam(const char* name) {
group_t *getgrnam(const char *name)
{
if (name == NULL)
return NULL;
static group grp;
static group_t grp;
static char buffer[BUFSIZ];
group *result;
group_t *result;
if (!getgrnam_r(name, &grp, buffer, BUFSIZ, &result))
return NULL;
return &grp;
}
int getgrgid_r(gid_t gid, struct group* group, char* buf, size_t buflen, struct group ** result) {
int getgrgid_r(gid_t gid, group_t *group, char *buf, size_t buflen, group_t **result)
{
int fd = open("/etc/group", O_RDONLY, 0);
if (fd == -1) {
errno = ENOENT;
*result = NULL;
return 0;
}
char *entry = __search_entry(fd, buf, buflen, NULL, gid);
if (entry != NULL) {
// Close the file.
close(fd);
// Parse the line.
@@ -142,18 +142,17 @@ int getgrgid_r(gid_t gid, struct group* group, char* buf, size_t buflen, struct
return 0;
}
int getgrnam_r(const char* name, struct group* group, char* buf, size_t buflen, struct group** result) {
int getgrnam_r(const char *name, group_t *group, char *buf, size_t buflen, group_t **result)
{
int fd = open("/etc/group", O_RDONLY, 0);
if (fd == -1) {
errno = ENOENT;
*result = NULL;
return 0;
}
char *entry = __search_entry(fd, buf, buflen, name, 0);
if (entry != NULL) {
// Close the file.
close(fd);
// Parse the line.
@@ -168,15 +167,14 @@ int getgrnam_r(const char* name, struct group* group, char* buf, size_t buflen,
return 0;
}
static int fd = -1;
struct group* getgrent(void) {
group_t *getgrent(void)
{
static group_t result;
static group result;
if (fd == -1) {
if (__fd == -1) {
//pr_debug("Opening group file\n");
fd = open("/etc/group", O_RDONLY, 0);
if (fd == -1) {
__fd = open("/etc/group", O_RDONLY, 0);
if (__fd == -1) {
errno = ENOENT;
return 0;
}
@@ -187,8 +185,7 @@ struct group* getgrent(void) {
int pos = 0;
static char buffer[BUFSIZ];
while ((ret = read(fd, &c, 1U))) {
while ((ret = read(__fd, &c, 1U))) {
// Skip carriage return.
if (c == '\r')
continue;
@@ -223,15 +220,15 @@ struct group* getgrent(void) {
return NULL;
}
void endgrent(void) {
void endgrent(void)
{
//pr_debug("Closing group file\n");
close(fd);
fd = -1;
close(__fd);
__fd = -1;
}
void setgrent(void) {
void setgrent(void)
{
//pr_debug("Resetting pointer to beginning of group file\n");
lseek(fd, 0, SEEK_SET);
lseek(__fd, 0, SEEK_SET);
}
+2 -2
View File
@@ -11,11 +11,11 @@
#include "ipc/shm.h"
#include "ipc/msg.h"
_syscall3(long, shmat, int, shmid, char *, shmaddr, int, shmflg)
_syscall3(void *, shmat, int, shmid, const void *, shmaddr, int, shmflg)
_syscall3(long, shmget, key_t, key, size_t, size, int, flag)
_syscall1(long, shmdt, char *, shmaddr)
_syscall1(long, shmdt, const void *, shmaddr)
_syscall3(long, shmctl, int, shmid, int, cmd, struct shmid_ds *, buf)
+5
View File
@@ -46,6 +46,11 @@ static inline void __parse_line(passwd_t *pwd, char *buf)
}
}
/// @brief Reads a line from the file.
/// @param fd the file descriptor.
/// @param buffer the buffer where we place the line.
/// @param buflen the length of the buffer.
/// @return the amount we read.
ssize_t __readline(int fd, char *buffer, size_t buflen)
{
memset(buffer, 0, buflen);
+2
View File
@@ -18,6 +18,7 @@ static const char *months[] = {
"July", "August", "September", "October", "November", "December"
};
/// @brief Time function.
_syscall1(time_t, time, time_t *, t)
time_t difftime(time_t time1, time_t time2)
@@ -377,6 +378,7 @@ size_t strftime(char *str, size_t maxsize, const char *format, const tm_t *timep
return ret;
}
/// @brief nanosleep function.
_syscall2(int, nanosleep, const timespec *, req, timespec *, rem)
unsigned int sleep(unsigned int seconds)
+5 -1
View File
@@ -59,7 +59,11 @@ static inline int __find_in_path(const char *file, char *buf, size_t buf_len)
return -1;
}
_syscall3(int, execve, const char *, path, char *const *, argv, char *const *, envp)
/// @brief Replaces the current process image with a new process
/// image (argument vector), allows the caller to specify
/// the environment of the executed program via `envp`.
/// @return Returns -1 only if an error has occurred, and sets errno.
_syscall3(int, execve, const char *, path, char *const *, argv, char *const *, envp);
int execv(const char *path, char *const argv[])
{
+2 -2
View File
@@ -2,7 +2,7 @@
/// @brief Data structures concerning the Global Descriptor Table (GDT).
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
/// @addtogroup descriptor_tables Memory Management Modules
/// @addtogroup descriptor_tables Descriptor Tables
/// @brief GDT, IDT and TSS are all data structures specified by Intel x86
/// architecture in memory management module.
/// @{
@@ -67,7 +67,7 @@
///
/// You can have both 16 bit and 32 bit selectors at once.
///
enum gdt_bits_t {
typedef enum gdt_bits_t {
/// @brief `0b10000000U` (Present): This must be 1 for all valid selectors.
GDT_PRESENT = 128U,
/// @brief `0b00000000U` (Privilege): Sets the 2 privilege bits (ring level) to 0 = highest (kernel).
+13 -117
View File
@@ -5,8 +5,8 @@
/// @addtogroup descriptor_tables Descriptor Tables
/// @{
/// @addtogroup idt Interrupt Descriptor Table (IDT)
/// @brief Is a data structure used by the x86 architecture to implement an
/// interrupt vector table. The IDT is used by the processor to determine the
/// @brief Is a data structure used by the x86 architecture to implement an
/// interrupt vector table. The IDT is used by the processor to determine the
/// correct response to interrupts and exceptions.
/// @{
@@ -36,132 +36,28 @@
/// @brief This structure describes one interrupt gate.
typedef struct idt_descriptor_t {
/// TODO: Comment.
unsigned short offset_low;
/// Segment selector.
unsigned short seg_selector;
/// The lower 16 bits of the ISR's address.
uint16_t offset_low;
/// The GDT segment selector that the CPU will load into CS before calling the ISR.
uint16_t seg_selector;
/// This will ALWAYS be set to 0.
unsigned char null_par;
/// @brief IDT descriptor options:
/// |P|DPL|01110|.
/// P present, DPL required Ring (2bits).
unsigned char options;
/// TODO: Comment.
unsigned short offset_high;
uint8_t reserved;
/// Descriptor options: |P|DPL|01110| (P: present, DPL: required Ring).
uint8_t options;
/// The higher 16 bits of the ISR's address.
uint16_t 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;
uint16_t limit;
/// The start address of the IDT.
unsigned int base;
uint32_t base;
} __attribute__((packed)) idt_pointer_t;
/// @brief Initialise the interrupt descriptor table.
void init_idt();
// == List of exceptions generated internally by the CPU ======================
//! @cond Doxygen_Suppress
extern void INT_0();
extern void INT_1();
extern void INT_2();
extern void INT_3();
extern void INT_4();
extern void INT_5();
extern void INT_6();
extern void INT_7();
extern void INT_8();
extern void INT_9();
extern void INT_10();
extern void INT_11();
extern void INT_12();
extern void INT_13();
extern void INT_14();
extern void INT_15();
extern void INT_16();
extern void INT_17();
extern void INT_18();
extern void INT_19();
extern void INT_20();
extern void INT_21();
extern void INT_22();
extern void INT_23();
extern void INT_24();
extern void INT_25();
extern void INT_26();
extern void INT_27();
extern void INT_28();
extern void INT_29();
extern void INT_30();
extern void INT_31();
extern void INT_80();
// == List of interrupts generated by PIC =====================================
extern void IRQ_0();
extern void IRQ_1();
extern void IRQ_2();
extern void IRQ_3();
extern void IRQ_4();
extern void IRQ_5();
extern void IRQ_6();
extern void IRQ_7();
extern void IRQ_8();
extern void IRQ_9();
extern void IRQ_10();
extern void IRQ_11();
extern void IRQ_12();
extern void IRQ_13();
extern void IRQ_14();
extern void IRQ_15();
/// @}
/// @}
+21 -20
View File
@@ -35,27 +35,28 @@ void irq_init();
* for a same IRQ.
*/
/// @brief Installs an ISR to handle an exception.
/// @param i Exception identifier.
/// @param handler Exception handler.
/// @param description Exception description.
/// @brief Installs an ISR to handle an interrupt.
/// @param i interrupt identifier.
/// @param handler interrupt handler.
/// @param description interrupt description.
/// @return 0 on success, -1 otherwise.
int isr_install_handler(unsigned i, interrupt_handler_t handler, char *description);
/// @brief Uninstall an ISR handler.
/// @param i Interrupt identifier.
/// @param i interrupt identifier.
/// @return 0 on success, -1 otherwise.
int isr_uninstall_handler(unsigned i);
/// @brief Installs an ISR to handle an interrupt.
/// @param i Interrupt identifier.
/// @param handler Interrupt handler.
/// @param description Interrupt description.
/// @param i interrupt identifier.
/// @param handler interrupt handler.
/// @param description interrupt description.
/// @return 0 on success, -1 otherwise.
int irq_install_handler(unsigned i, interrupt_handler_t handler, char *description);
/// @brief Uninstall an IRQ handler.
/// @param i Interrupt identifier.
/// @param i interrupt identifier.
/// @param handler interrupt handler.
/// @return 0 on success, -1 otherwise.
int irq_uninstall_handler(unsigned i, interrupt_handler_t handler);
@@ -68,16 +69,16 @@ extern void irq_handler(pt_regs *f);
extern void isq_handler(pt_regs *f);
//==== List of exceptions generated internally by the CPU ======================
#define DIVIDE_ERROR 0 ///< DE Divide Error.
#define DEBUG_EXC 1 ///< DB Debug.
#define NMI_INTERRUPT 2 ///< Non Mascable Interrupt.
#define BREAKPOINT 3 ///< BP Breakpoint.
#define OVERFLOW 4 ///< OF Overflow.
#define BOUND_RANGE_EXCEED 5 ///< BR Bound Range Exception.
#define INVALID_OPCODE 6 ///< UD Invalid OpCode Exception.
#define DEV_NOT_AVL 7 ///< NM Device Not Available.
#define DOUBLE_FAULT 8 ///< DF Double Fault.
#define COPROC_SEG_OVERRUN 9 ///< Coprocessor Segment Overrun.
#define DIVIDE_ERROR 0 ///< DE Divide Error.
#define DEBUG_EXC 1 ///< DB Debug.
#define NMI_INTERRUPT 2 ///< Non Mascable Interrupt.
#define BREAKPOINT 3 ///< BP Breakpoint.
#define OVERFLOW 4 ///< OF Overflow.
#define BOUND_RANGE_EXCEED 5 ///< BR Bound Range Exception.
#define INVALID_OPCODE 6 ///< UD Invalid OpCode Exception.
#define DEV_NOT_AVL 7 ///< NM Device Not Available.
#define DOUBLE_FAULT 8 ///< DF Double Fault.
#define COPROC_SEG_OVERRUN 9 ///< Coprocessor Segment Overrun.
#define INVALID_TSS 10 ///< TS Invalid TSS.
#define SEGMENT_NOT_PRESENT 11 ///< NP Segment Not Present.
#define STACK_SEGMENT_FAULT 12 ///< SS Stack Segment Fault.
@@ -93,7 +94,7 @@ extern void isq_handler(pt_regs *f);
#define SECURITY_EXC 30 ///< Security Exception.
#define TRIPLE_FAULT 31 ///< Triple Fault
#define SYSTEM_CALL 80 ///< System call interrupt.
//==============================================================================
//==============================================================================
/// @}
/// @}
+60 -28
View File
@@ -12,6 +12,7 @@
#include "stdint.h"
/// @brief Types of PCI commands.
typedef enum {
/// @brief If set to 1 the device can respond to I/O Space accesses;
/// otherwise, the device's response is disabled.
@@ -50,6 +51,7 @@ typedef enum {
pci_command_interrupt_disable = 10,
} pci_command_bit_t;
/// @brief Types of PCI status.
typedef enum {
/// @brief Represents the state of the device's INTx# signal. If set to 1
/// and bit 10 of the Command register (Interrupt Disable bit) is set to 0
@@ -256,61 +258,91 @@ static inline uint32_t pci_get_addr(uint32_t device, int field)
((field)&0xFC);
}
/// @brief TODO: doxygen comment.
/// @brief Get device number from: bus, slot and function.
/// @param bus
/// @param slot
/// @param func
/// @return uint32_t
static inline uint32_t pci_box_device(int bus, int slot, int func)
{
return (uint32_t)((bus << 16) | (slot << 8) | func);
}
/// @brief Reads a field from the given PCI device.
/// @param device the device.
/// @param field the field to read.
/// @param size the size of the field.
/// @return the value we read.
uint32_t pci_read_field(uint32_t device, int field, int size);
// TODO: doxygen comment.
/// @brief
/// @brief Writes a field from the given PCI device.
/// @param device the device number.
/// @param field the field to write.
/// @param size the size of the field.
/// @param value the value we write.
void pci_write_field(uint32_t device, int field, int size, uint32_t value);
// TODO: doxygen comment.
/// @brief
/// @brief Finds the type of the given device.
/// @param device the device number.
/// @return the type of the device.
uint32_t pci_find_type(uint32_t device);
// TODO: doxygen comment.
/// @brief
/// @brief Searches for the vendor name from the ID.
/// @param vendor_id the vendor ID.
/// @return the vendor name.
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);
// TODO: doxygen comment.
/// @brief
void pci_scan_hit(pci_scan_func_t f, uint32_t dev, void *extra);
/// @brief Searches for the device name from its ID and the vendor id.
/// @param vendor_id the vendor ID.
/// @param device_id the device ID.
/// @return the device name.
const char *pci_device_lookup(unsigned short vendor_id, unsigned short device_id);
// TODO: doxygen comment.
/// @brief
/// @brief Calls the function f on the device if found.
/// @param f the function to call.
/// @param device the device number.
/// @param extra the extra arguemnts.
void pci_scan_hit(pci_scan_func_t f, uint32_t device, void *extra);
/// @brief Scans for the given type of device.
/// @param f the function to call once we have found the device.
/// @param type the type of device we are searching for.
/// @param bus bus number.
/// @param slot slot number.
/// @param func choose a specific function in a device.
/// @param extra the extra arguemnts.
void pci_scan_func(pci_scan_func_t f, int type, int bus, int slot, int func, void *extra);
// TODO: doxygen comment.
/// @brief
/// @brief Scans for the given type of device.
/// @param f the function to call once we have found the device.
/// @param type the type of device we are searching for.
/// @param bus bus number.
/// @param slot slot number.
/// @param extra the extra arguemnts.
void pci_scan_slot(pci_scan_func_t f, int type, int bus, int slot, void *extra);
// TODO: doxygen comment.
/// @brief
/// @brief Scans for the given type of device.
/// @param f the function to call once we have found the device.
/// @param type the type of device we are searching for.
/// @param bus bus number.
/// @param extra the extra arguemnts.
void pci_scan_bus(pci_scan_func_t f, int type, int bus, void *extra);
// TODO: doxygen comment.
/// @brief
/// @brief Scans for the given type of device.
/// @param f the function to call once we have found the device.
/// @param type the type of device we are searching for.
/// @param extra the extra arguemnts.
void pci_scan(pci_scan_func_t f, int type, void *extra);
// TODO: doxygen comment.
/// @brief
/// @brief PCI-to-ISA remapping.
void pci_remap(void);
// TODO: doxygen comment.
/// @brief
/// @brief Retrieves the interrupt number for the given device.
/// @param device the device.
/// @return interrupt number.
int pci_get_interrupt(uint32_t device);
// TODO: doxygen comment.
/// @brief
/// @brief Prints all the devices connected to the PCI interfance.
void pci_debug_scan();
/// @}
-2
View File
@@ -12,5 +12,3 @@ int ext2_initialize();
/// @brief De-initializes the EXT2 drivers.
/// @return 0 on success, 1 on error.
int ext2_finalize();
void ext2_test();
+2 -1
View File
@@ -57,7 +57,8 @@ void dbg_print_regs(struct pt_regs *frame);
const char *to_human_size(unsigned long bytes);
/// @brief Transforms the given value to a binary string.
/// @param value The decimal value.
/// @param value to print.
/// @param length of the binary output.
/// @return String representing the binary value.
const char *dec_to_binary(unsigned long value, unsigned length);
+1 -3
View File
@@ -5,8 +5,6 @@
#pragma once
#pragma once
/// @brief Initializes the VGA.
void vga_initialize();
@@ -61,7 +59,7 @@ void vga_draw_rectangle(unsigned int sx, unsigned int sy, unsigned int ex, unsig
/// @brief Draws a circle provided the position of the center and the radius.
/// @param xc x-axis position.
/// @param yc y-axis position.
/// @param t radius.
/// @param r radius.
/// @param fill color used to fill the circle.
void vga_draw_circle(unsigned int xc, unsigned int yc, unsigned int r, unsigned char fill);
+5 -2
View File
@@ -1,4 +1,4 @@
/// @file vga_model.h
/// @file vga_mode.h
/// @brief VGA models.
/// @copyright (c) 2014-2021 This file is distributed under the MIT License.
/// See LICENSE.md for details.
@@ -67,6 +67,7 @@ typedef struct {
} ac;
} vga_mode_t;
/// @brief Size 80x25, 16 colors.
vga_mode_t _mode_80_25_text = {
// 3C2h (W): Miscellaneous Output Register
// bit 0 If set Color Emulation:
@@ -157,6 +158,7 @@ vga_mode_t _mode_80_25_text = {
}
};
/// @brief Size 320x200, 256 colors.
vga_mode_t _mode_320_200_256 = {
// 3C2h (W): Miscellaneous Output Register
// bit 0 If set Color Emulation:
@@ -247,7 +249,7 @@ vga_mode_t _mode_320_200_256 = {
}
};
/// @brief Size 640x480, 16 colors.
vga_mode_t _mode_640_480_16 = {
// 3C2h (W): Miscellaneous Output Register
// bit 0 If set Color Emulation:
@@ -338,6 +340,7 @@ vga_mode_t _mode_640_480_16 = {
}
};
/// @brief Size 720x480, 16 colors.
vga_mode_t _mode_720_480_16 = {
// 3C2h (W): Miscellaneous Output Register
// bit 0 If set Color Emulation:
+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"
+8 -8
View File
@@ -8,15 +8,15 @@
#include "string.h"
#include <stdio.h>
static void list_groups() {
group* iter;
static void list_groups()
{
group_t *iter;
while ((iter = getgrent()) != NULL) {
printf("Group\n\tname: %s\n\tpasswd: %s\n\tnames:\n",iter->gr_name, iter->gr_passwd);
printf("Group\n\tname: %s\n\tpasswd: %s\n\tnames:\n", iter->gr_name, iter->gr_passwd);
size_t count = 0;
while (iter->gr_mem[count] != NULL) {
printf("\t\t%s\n",iter->gr_mem[count]);
printf("\t\t%s\n", iter->gr_mem[count]);
count += 1;
}
@@ -24,8 +24,8 @@ static void list_groups() {
}
}
int main(int argc, char** argv) {
int main(int argc, char **argv)
{
printf("List of all groups:\n");
list_groups();
@@ -36,7 +36,7 @@ int main(int argc, char** argv) {
list_groups();
endgrent();
group* root_group = getgrgid(0);
group_t *root_group = getgrgid(0);
if (strcmp(root_group->gr_name, "root") != 0) {
printf("Error in getgrgid function.");
return 1;