about summary refs log tree commit diff stats
Commit message (Expand)AuthorAgeFilesLines
...
* removed the <M> togglelayout callAnselm R Garbe2008-05-172-5/+2
* s/tilegeom/updatetilegeom/Anselm R Garbe2008-05-171-16/+16
* removed monocle for nowAnselm R Garbe2008-05-173-14/+0
* removed the exact focus mechanism of next/prev windowAnselm R Garbe2008-05-174-26/+16
* moved all tile()-related stuff into tile.c which is included from config.def....Anselm R Garbe2008-05-173-108/+119
* removed tileh, renamed tilev into tile again, removed counttiles, tilemasterAnselm R Garbe2008-05-172-57/+15
* removed Layout->isfloatingAnselm R Garbe2008-05-172-31/+21
* removed reapply() -- unnecessaryAnselm R Garbe2008-05-172-13/+0
* renamed setlayout into togglelayoutAnselm R Garbe2008-05-172-98/+97
* removed temporary wildcard handlingAnselm R Garbe2008-05-151-6/+2
* added wild-card handling for tagsAnselm R Garbe2008-05-151-2/+6
* applied nsz's another style patchAnselm R Garbe2008-05-141-4/+3
* applied nsz's style.diff patchAnselm R Garbe2008-05-131-14/+13
* just added a commentAnselm R Garbe2008-05-131-1/+1
* minor fixesAnselm R Garbe2008-05-111-3/+1
* having monocle on Mod1-mAnselm R Garbe2008-05-112-1/+2
* hotfixAnselm R Garbe2008-05-111-1/+1
* removed Geom stuff, introduced updategeom() again, still view is somewhat bro...Anselm R Garbe2008-05-113-85/+52
* cleaned up config.def.hAnselm R Garbe2008-05-111-8/+2
* implemented exact focus next, if arg != NULL to focus{next,prev}Anselm R Garbe2008-05-114-17/+27
* applied the proposal by nszAnselm R Garbe2008-05-061-3/+5
* applied JUCE patchAnselm R Garbe2008-05-062-0/+3
* simplification of view() as proposed by anydotAnselm R Garbe2008-04-271-10/+3
* applied yiyus tagset patchAnselm R Garbe2008-04-271-21/+16
* applied yiyus fgeom patchAnselm R Garbe2008-04-272-35/+41
* applied dfenze drawtext simplificationsAnselm R Garbe2008-04-271-8/+7
* this is the correct wayanselm@anselm12008-04-201-0/+1
* copyright notice is in LICENSEanselm@anselm12008-04-201-1/+0
* applied Ph's seltags-simplification with some modificationsanselm@anselm12008-04-201-13/+10
* applied Ph's MIN/MAX patch, nice work!anselm@anselm12008-04-201-31/+22
* applied Ph's patch regarding geom and lt initializationanselm@anselm12008-04-201-8/+4
* applied Gottox' applyrules() fixanselm@anselm12008-04-201-2/+2
* geometry fix proposed by JukkaAnselm R Garbe2008-04-081-1/+1
* applied applyrules-fix by Jukka, thank you Jukka!Anselm R Garbe2008-04-071-3/+3
* fixAnselm R Garbe2008-04-051-1/+1
* applied the proposed monocle patch from the mailinglistAnselm R Garbe2008-04-051-1/+1
* next version is 5.0Anselm R Garbe2008-04-041-1/+1
* Added tag 4.9 for changeset 22c669b2dd36anselm@anselm12008-04-031-0/+1
* yet another cleanup 4.9Anselm R Garbe2008-04-031-2/+2
* some cleanup changesAnselm R Garbe2008-04-032-3/+1
* uncommented dual layout in preparation of dwm 4.9anselm@anselm12008-04-021-2/+2
* applied Peter Hartlich's simplification patch of setmfact and his revival of ...anselm@anselm12008-04-022-42/+24
* aspects hints seem broken for fullscreen appsAnselm R Garbe2008-04-011-3/+5
* removed uneccessary lineAnselm R Garbe2008-03-311-1/+0
* bugfixAnselm R Garbe2008-03-251-1/+1
* setmfact should not have any effect if in floating layoutAnselm R Garbe2008-03-241-1/+1
* minor fixAnselm R Garbe2008-03-241-1/+1
* revival of mfact and setmfactAnselm R Garbe2008-03-243-1/+31
* setlayout and setgeom are now togglable againAnselm R Garbe2008-03-243-42/+38
* geom indicator and layout indicator is only displayed if there are several ge...Anselm R Garbe2008-03-242-12/+15
artik/mu/blame/kernel.soso/main.c?h=main&id=ded2b24ce28f4a9df75ce40117f0f06f09574369'>^
67de9b02 ^
46bb1d31 ^






1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

































                                                     

                                                                










                                                            
                       
















                                                                                   
                       







                                                                                       
                                                                                                


                                                 
                  
                                                                                  
                   
                                       
                    



                                                                  
                                    

                                                                                                                       
                                     













                                                 
                      










                                                                                                  
                                        











                                                     
                                                                        



                                                                                                                                                                                                 
          

























                                                                                                                                                                 
                                  




















                                                                  
                                 

                                     
          



                                                                                                                  
                           



                                                                                    
              







                                                 
                 






                     
#include "screen.h"
#include "descriptortables.h"
#include "timer.h"
#include "multiboot.h"
#include "fs.h"
#include "syscalls.h"
#include "serial.h"
#include "isr.h"
#include "vmm.h"
#include "alloc.h"
#include "process.h"
#include "keyboard.h"
#include "ttydriver.h"
#include "devfs.h"
#include "systemfs.h"
#include "pipe.h"
#include "sharedmemory.h"
#include "random.h"
#include "null.h"
#include "elf.h"
#include "debugprint.h"
#include "ramdisk.h"
#include "fatfilesystem.h"
#include "vbe.h"
#include "fifobuffer.h"
#include "gfx.h"
#include "mouse.h"
#include "sleep.h"

extern uint32 _start;
extern uint32 _end;
uint32 gPhysicalKernelStartAddress = (uint32)&_start;
uint32 gPhysicalKernelEndAddress = (uint32)&_end;

static void* locateInitrd(struct Multiboot *mbi, uint32* size) {
    if (mbi->mods_count > 0) {
        uint32 startLocation = *((uint32*)mbi->mods_addr);
        uint32 endLocation = *(uint32*)(mbi->mods_addr + 4);

        *size = endLocation - startLocation;

        return (void*)startLocation;
    }

    return NULL;
}

void printUsageInfo() {
    char buffer[164];

    sprintf(buffer, "Used kheap:%d", getKernelHeapUsed());
    Screen_Print(0, 60, buffer);

    sprintf(buffer, "Pages:%d/%d       ", getUsedPageCount(), getTotalPageCount());
    Screen_Print(1, 60, buffer);

    sprintf(buffer, "Uptime:%d sec   ", getUptimeSeconds());
    Screen_Print(2, 60, buffer);

    Thread* p = getMainKernelThread();

    int line = 3;
    sprintf(buffer, "[idle]   cs:%d   ", p->totalContextSwitchCount);
    Screen_Print(line++, 60, buffer);
    p = p->next;
    while (p != NULL) {
        sprintf(buffer, "thread:%d cs:%d   ", p->threadId, p->totalContextSwitchCount);

        Screen_Print(line++, 60, buffer);

        p = p->next;
    }
}

int executeFile(const char *path, char *const argv[], char *const envp[], FileSystemNode* tty) {
    int result = -1;

    Process* process = getCurrentThread()->owner;
    if (process) {
        FileSystemNode* node = getFileSystemNodeAbsoluteOrRelative(path, process);
        if (node) {
            File* f = open_fs(node, 0);
            if (f) {
                void* image = kmalloc(node->length);

                int32 bytesRead = read_fs(f, node->length, image);

                if (bytesRead > 0) {
                    Process* newProcess = createUserProcessFromElfData("userProcess", image, argv, envp, process, tty);

                    if (newProcess) {
                        result = newProcess->pid;
                    }
                }
                close_fs(f);

                kfree(image);
            }

        }
    }

    return result;
}

void printAsciiArt() {
    printkf("     ________       ________      ________       ________     \n");
    printkf("    |\\   ____\\     |\\   __  \\    |\\   ____\\     |\\   __  \\    \n");
    printkf("    \\ \\  \\___|_    \\ \\  \\|\\  \\   \\ \\  \\___|_    \\ \\  \\|\\  \\   \n");
    printkf("     \\ \\_____  \\    \\ \\  \\\\\\  \\   \\ \\_____  \\    \\ \\  \\\\\\  \\  \n");
    printkf("      \\|____|\\  \\    \\ \\  \\\\\\  \\   \\|____|\\  \\    \\ \\  \\\\\\  \\ \n");
    printkf("        ____\\_\\  \\    \\ \\_______\\    ____\\_\\  \\    \\ \\_______\\\n");
    printkf("       |\\_________\\    \\|_______|   |\\_________\\    \\|_______|\n");
    printkf("       \\|_________|                 \\|_________|              \n");
    printkf("\n");
}

int kmain(struct Multiboot *mboot_ptr) {
    int stack = 5;

    initializeDescriptorTables();

    initializeSerial();

    uint32 memoryKb = mboot_ptr->mem_upper;//96*1024;
    initializeMemory(memoryKb);

    initializeVFS();
    initializeDevFS();

    if (MULTIBOOT_FRAMEBUFFER_TYPE_RGB == mboot_ptr->framebuffer_type) {
        Gfx_Initialize((uint32*)(uint32)mboot_ptr->framebuffer_addr, mboot_ptr->framebuffer_width, mboot_ptr->framebuffer_height, mboot_ptr->framebuffer_bpp / 32, mboot_ptr->framebuffer_pitch);

        initializeTTYs(TRUE);
    }
    else {
        initializeTTYs(FALSE);
    }
    //printkf works after TTY initialization

    printAsciiArt();

    printkf("Lower Memory: %d KB\n", mboot_ptr->mem_lower);
    printkf("Upper Memory: %d KB\n", mboot_ptr->mem_upper);
    printkf("Memory initialized for %d MB\n", memoryKb / 1024);
    printkf("Kernel start: %x - end:%x\n", gPhysicalKernelStartAddress, gPhysicalKernelEndAddress);
    printkf("Initial stack: %x\n", &stack);
    printkf("Video: %dx%dx%d Pitch:%d\n", mboot_ptr->framebuffer_width, mboot_ptr->framebuffer_height, mboot_ptr->framebuffer_bpp, mboot_ptr->framebuffer_pitch);

    initializeSystemFS();
    initializePipes();
    initializeSharedMemory();

    initializeTasking();

    initialiseSyscalls();

    initializeTimer();

    initializeKeyboard();
    initializeMouse();

    if (0 != mboot_ptr->cmdline) {
        printkf("Kernel cmdline:%s\n", (char*)mboot_ptr->cmdline);
    }

    Debug_initialize("/dev/tty9");

    Serial_PrintF("pitch:%d\n", mboot_ptr->framebuffer_pitch);

    initializeRandom();
    initializeNull();

    createRamdisk("ramdisk1", 20*1024*1024);

    initializeFatFileSystem();

    printkf("System started!\n");

    char* argv[] = {"shell", NULL};
    char* envp[] = {"HOME=/", "PATH=/initrd", NULL};

    uint32 initrdSize = 0;
    uint8* initrdLocation = locateInitrd(mboot_ptr, &initrdSize);
    if (initrdLocation == NULL) {
        PANIC("Initrd not found!\n");
    }
    else {
        printkf("Initrd found at %x (%d bytes)\n", initrdLocation, initrdSize);
        memcpy((uint8*)*(uint32*)getFileSystemNode("/dev/ramdisk1")->privateNodeData, initrdLocation, initrdSize);
        BOOL mountSuccess = mountFileSystem("/dev/ramdisk1", "/initrd", "fat", 0, 0);

        if (mountSuccess) {
            printkf("Starting shell on TTYs\n");

            executeFile("/initrd/init", argv, envp, getFileSystemNode("/dev/tty1"));
        }
        else {
            printkf("Mounting initrd failed!\n");
        }
    }

    enableScheduler();

    enableInterrupts();

    while(TRUE) {
        //Idle thread

        halt();
    }

    return 0;
}