about summary refs log blame commit diff stats
path: root/src/ui/statusbar.h
blob: 390d02032214524289b78c516b25ab2329104c8f (plain) (tree)
1
2
3
4


              
                                                            













                                                                       
                                                                      
  











                                                                                
   









                                     
                                                     

                               
      
/*
 * statusbar.h
 *
 * Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
 *
 * This file is part of Profanity.
 *
 * Profanity is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Profanity is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Profanity.  If not, see <https://www.gnu.org/licenses/>.
 *
 * In addition, as a special exception, the copyright holders give permission to
 * link the code of portions of this program with the OpenSSL library under
 * certain conditions as described in each individual source file, and
 * distribute linked combinations including the two.
 *
 * You must obey the GNU General Public License in all respects for all of the
 * code used other than OpenSSL. If you modify file(s) with this exception, you
 * may extend this exception to your version of the file(s), but you are not
 * obligated to do so. If you do not wish to do so, delete this exception
 * statement from your version. If you delete this exception statement from all
 * source files in the program, then also delete it here.
 *
 */

#ifndef UI_STATUSBAR_H
#define UI_STATUSBAR_H

void create_status_bar(void);
void status_bar_update_virtual(void);
void status_bar_resize(void);
void status_bar_clear(void);
void status_bar_clear_message(void);
void status_bar_get_password(void);
void status_bar_print_message(const char *const msg);
void status_bar_current(int i);

#endif
light .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#ifndef PROCESS_H
#define PROCESS_H

#define KERNELMODE	0
#define USERMODE	1

#define MAX_OPENED_FILES 20

#include "common.h"
#include "fs.h"
#include "fifobuffer.h"
#include "spinlock.h"

typedef enum ThreadState {
    TS_RUN,
    TS_WAITIO,
    TS_WAITCHILD,
    TS_SLEEP,
    TS_SUSPEND,
    TS_YIELD
} ThreadState;

struct Process {
    char name[32];

    uint32 pid;


    uint32 *pd;

    uint32 b_exec;
    uint32 e_exec;
    uint32 b_bss;
    uint32 e_bss;

    char *heapBegin;
    char *heapEnd;
    char *heapNextUnallocatedPageBegin;

    uint8 mmappedVirtualMemory[RAM_AS_4M_PAGES / 8];

    uint32 signal;
    void* sigfn[32];

    FileSystemNode* tty;

    FileSystemNode* workingDirectory;

    //Thread* mainThread;

    Process* parent;

    // Save exit status of child process that most recently performed exit().
    int32 childExitStatusPresent;  // boolean
    int32 childExitStatus;

    File* fd[MAX_OPENED_FILES];

} __attribute__ ((packed));

typedef struct Process Process;

struct Thread {
    uint32 threadId;

    struct {
        uint32 eax, ecx, edx, ebx;
        uint32 esp, ebp, esi, edi;
        uint32 eip, eflags;
        uint32 cs:16, ss:16, ds:16, es:16, fs:16, gs:16;
        uint32 cr3;
    } regs __attribute__ ((packed));

    struct {
        uint32 esp0;
        uint16 ss0;
        uint32 stackStart;
    } kstack __attribute__ ((packed));


    uint32 userMode;

    ThreadState state;

    Process* owner;

    uint32 yield;

    uint32 contextSwitchCount;
    uint32 totalContextSwitchCount;
    uint32 totalContextSwitchCountPrevious;

    void* state_privateData;

    FifoBuffer* messageQueue;
    Spinlock messageQueueLock;

    struct Thread* next;

};

typedef struct Thread Thread;

typedef struct TimerInt_Registers {
    uint32 gs, fs, es, ds;
    uint32 edi, esi, ebp, esp, ebx, edx, ecx, eax; //pushed by pushad
    uint32 eip, cs, eflags, esp_if_privilege_change, ss_if_privilege_change; //pushed by the CPU
} TimerInt_Registers;

typedef void (*Function0)();

void initializeTasking();
Process* createUserProcessFromElfData(const char* name, uint8* elfData, char *const argv[], char *const envp[], Process* parent, FileSystemNode* tty);
Process* createUserProcessEx(const char* name, uint32 processId, uint32 threadId, Function0 func, uint8* elfData, char *const argv[], char *const envp[], Process* parent, FileSystemNode* tty);
void destroyThread(Thread* thread);
void destroyProcess(Process* process);
void threadStateToString(ThreadState state, uint8* buffer, uint32 bufferSize);
void waitForSchedule();
void yield(uint32 count);
int32 getEmptyFd(Process* process);
int32 addFileToProcess(Process* process, File* file);
int32 removeFileFromProcess(Process* process, File* file);
Thread* getThreadById(uint32 threadId);
Thread* getPreviousThread(Thread* thread);
Thread* getMainKernelThread();
Thread* getCurrentThread();
void schedule(TimerInt_Registers* registers);
BOOL isThreadValid(Thread* thread);
BOOL isProcessValid(Process* process);
uint32 getSystemContextSwitchCount();

#endif // PROCESS_H