From 2bbc81955d54159889e6eb0a7399e7260d97f20a Mon Sep 17 00:00:00 2001 From: Xnoe Date: Wed, 19 Jan 2022 12:19:52 +0000 Subject: [PATCH] Updated program linker scripts to have link beginning at 0x20 rather than 0x8020. Program binary is now the first thing allocated. --- src/hello/hello.ld | 2 +- src/kernel/process.cpp | 4 +- src/program/program.ld | 2 +- src/world/world.c | 181 ++++++++++++++++++++++++++++++++--------- src/world/world.ld | 2 +- 5 files changed, 148 insertions(+), 43 deletions(-) diff --git a/src/hello/hello.ld b/src/hello/hello.ld index 0ccfd55..1d78fe9 100644 --- a/src/hello/hello.ld +++ b/src/hello/hello.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386:i386) OUTPUT(build/hello/hello.bin) SECTIONS { - . = 0x8020; + . = 0x20; .text : { build/program_code_entry.o(.text) diff --git a/src/kernel/process.cpp b/src/kernel/process.cpp index 5ddbc45..10d6b6d 100644 --- a/src/kernel/process.cpp +++ b/src/kernel/process.cpp @@ -47,6 +47,8 @@ Process::Process(uint32_t PID, PageDirectory* inherit, uint32_t inheritBase, cha for (int index = inheritBase >> 22; index < 1024; index++) this->PD->page_directory[index] = inherit->page_directory[index]; + uint8_t* program_data = this->allocate(file_size(filename) + 12) + 12; + this->stack = this->allocate(0x8000); this->kernelStackPtr = (new uint8_t[0x1000]) + 0xffc; this->kernelStackPtrDefault = this->kernelStackPtr; @@ -55,8 +57,6 @@ Process::Process(uint32_t PID, PageDirectory* inherit, uint32_t inheritBase, cha asm ("mov %%cr3, %0" : "=a" (pCR3) :); this->PD->select(); - uint8_t* program_data = this->allocate(file_size(filename) + 12) + 12; - // We also need to initialise ESP and the stack uint32_t* stack32 = ((uint32_t)this->kernelStackPtr); *(--stack32) = 0x23; // SS diff --git a/src/program/program.ld b/src/program/program.ld index 89fa91f..0bb6cb7 100644 --- a/src/program/program.ld +++ b/src/program/program.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386:i386) OUTPUT(build/program/program.bin) SECTIONS { - . = 0x8020; + . = 0x20; .text : { build/program_code_entry.o(.text) diff --git a/src/world/world.c b/src/world/world.c index b167a50..0b507d9 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -1,6 +1,15 @@ #include "../common/common.h" #include +typedef struct { + char* buffer; + int x; + int y; + uint32_t process; + uint32_t stdin; + uint32_t stdout; +} procbuffer; + void scrollBuffer(char* buf) { for (int y=0; y<21; y++) for (int x=0; x<38; x++) @@ -10,43 +19,43 @@ void scrollBuffer(char* buf) { buf[y*38+x] = ' '; } -void writeToBuf(char c, char* buf, int* cx, int* cy) { +void writeToBuf(char c, procbuffer* buf) { switch (c) { case '\n': - *cx = 0; - (*cy)++; + buf->x = 0; + buf->y++; break; case '\b': - if (*cx > 0) - (*cx)--; - else if (*cy > 0) { - *cx = 37; - (*cy)--; + if (buf->x > 0) + buf->x--; + else if (buf->y > 0) { + buf->x = 37; + buf->y--; } - buf[(*cy)*38+(*cx)] = ' '; + buf->buffer[buf->y*38+buf->x] = ' '; break; default: - buf[(*cy)*38+(*cx)++] = c; + buf->buffer[buf->y*38+buf->x++] = c; } - if (*cx == 38) { - *cx = 0; - (*cy)++; + if (buf->x == 38) { + buf->x = 0; + buf->y++; } - if (*cy == 21) { - (*cy)--; - scrollBuffer(buf); + if (buf->y == 21) { + buf->y--; + scrollBuffer(buf->buffer); } } -void writeStrToBuf(char* c, char* buf, int* cx, int* cy) { +void writeStrToBuf(char* c, procbuffer* b) { char* s = c; while(*s) - writeToBuf(*(s++), buf, cx, cy); + writeToBuf(*(s++), b); } -void displayBuf(char* buf, int dx, int dy) { +void displayBuf(procbuffer* b, int dx, int dy) { char pset[9] = "\x1b[00;00H"; for (int i=0; ibuffer+(38*i)); pset[3]++; if (pset[3] == 0x3a) { pset[3] = 0x30; @@ -73,6 +82,69 @@ void displayBuf(char* buf, int dx, int dy) { } } +void setCurPos(int x, int y) { + char pset[9] = "\x1b[00;00H"; + for (int i=0; i\n", selectedBuf); + writeStrToBuf(" Loads and executes the program \n", selectedBuf); + writeStrToBuf("--------\n", selectedBuf); + } + } else { + write(1, selectedBuf->stdin, &c); + } } - displayBuf(selectedBuf, 2, 2); - displayBuf(buf2, 42, 2); + displayBuf(&b1, 2, 2); + displayBuf(&b2, 42, 2); } } \ No newline at end of file diff --git a/src/world/world.ld b/src/world/world.ld index db6a260..24586b1 100644 --- a/src/world/world.ld +++ b/src/world/world.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386:i386) OUTPUT(build/world/world.bin) SECTIONS { - . = 0x8020; + . = 0x20; .text : { build/program_code_entry.o(.text)