↑ Back to main site.

EPOS

Experimental Protected-mode Operating System

debug.c
/*
EPOS
http://www.atanaslaskov.com/epos/

FILE:        debug.c
DESCRIPTION: Debugger services
 
Copyright (c) 2006, Atanas Laskov
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
   1. Redistributions of source code must retain the above copyright notice,
   this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "..\..\memory\memory.h"
#include "..\..\process\process.h"
#include "..\..\gdt\gdt.h"
#include "..\process\process.h"
#include "..\..\paging\paging.h"
#include "..\ipc\ipc.h"

#include "debug.h"
#include "..\..\access\access.h"

int strcpy(char *dest, const char *src);

// Globals
//
char g_arRegistred[MAX_PROCESS_CNT];

extern unsigned long g_dwLastServiceN;
extern unsigned long g_pidLastService;
extern char       g_bCompleted;

// Initialize debugger
//
void k_debugInit() {
    PID i;
    for(i=0; i<MAX_PROCESS_CNT; i++) g_arRegistred[i] = 0;
}

// Send a debug message to user process
//
void k_debugMessage(DEBUGMSG *pMsg)
{
    PID i;
    char *c = (char*)pMsg;
    unsigned long k;

    for(i=0; i<MAX_PROCESS_CNT; i++) if(g_arRegistred[i])
    {
        //Send message to the process handling this IRQ
        struct IPCTransfer ipctTransfer;
        pageDirectorySwitch(PAGING_DIR_KERNEL);
        ipctTransfer.msg.dwMessage = MSG_KRN_DEBUG;

        ipctTransfer.msg.dwSize     = sizeof(DEBUGMSG);
        pMsg->dwlastServicePID      = g_pidLastService;
        pMsg->dwLastService         = g_dwLastServiceN;
        pMsg->bLastServiceCompleted = g_bCompleted;

        kMemCpy(ipctTransfer.msg.arData, pMsg, sizeof(DEBUGMSG));
        //for(k=0; k<sizeof(DEBUGMSG); k++) ipctTransfer.msg.arData[k] = c[k];

        ipctTransfer.hLine         = tmGetProcessLine(i);
        k_ipcSend(&ipctTransfer);
    }
}

// User services
//
void debugSend() {
    // register as recepietn for debug messages
    g_arRegistred[tmGetCrProcessID()] = 1;
}

void debugDontSend() {
    // unregister as recepietn for debug messages
    g_arRegistred[tmGetCrProcessID()] = 0;
}

void debugGetOSVersion(OSVER *v) {
    strcpy(v->strName, access_get_name());
    v->wMajor = access_get_major();
    v->wMinor = access_get_minor();
    v->wBuild = access_get_build();
}

void debugMemInfo(MEMINFO *i) {
    i->dwTotalBlockCnt    = MEM_MAX_BLOCK_COUNT;
    i->dwFreeBlockCnt     = memGetFreeBlockCnt();
    i->dwTotalPhysicalMem = memGetPhysicalMemorySize();
    i->dwFreePhysicalMem  = memGetFreePhysicalMemorySize();
}

void debugProcessRegs(PIDREGS *p) {
}

int strcpy(char *dest, const char *src) {
    unsigned long i=0;
    do{dest[i]=src[i];}while(src[i++]!='\0');
    return 0;
}