Support malloc() on bare metal
Your Actually Portable Executables now contains a simple virtual memory that works similarly to the Linux Kernel in the sense that it maps your physical memory to negative addresses. This is needed to support mmap() and malloc(). This functionality has zero code size impact. For example the MODE=tiny LIFE.COM executable is still only 12KB in size. The APE bootloader code has also been simplified to improve readibility and further elevate the elegance by which we're able to support so many platforms thereby enhancing verifiability so that we may engender trust in this bootloading process.
This commit is contained in:
@ -2109,9 +2109,9 @@ static void OnE820(void) {
|
||||
if (Read32(m->dx) == 0x534D4150 && Read32(m->cx) == 24 &&
|
||||
addr + sizeof(p) <= m->real.n) {
|
||||
if (!Read32(m->bx)) {
|
||||
Write64(p + 000, 0);
|
||||
Write64(p + 010, m->real.n);
|
||||
Write32(p + 014, 1);
|
||||
Write64(p + 0, 0);
|
||||
Write64(p + 8, m->real.n);
|
||||
Write32(p + 16, 1);
|
||||
memcpy(m->real.p + addr, p, sizeof(p));
|
||||
SetWriteAddr(m, addr, sizeof(p));
|
||||
Write32(m->cx, sizeof(p));
|
||||
@ -2716,6 +2716,7 @@ static void Tui(void) {
|
||||
ExecuteInstruction(m);
|
||||
++opcount;
|
||||
if (!(action & CONTINUE) || interactive) {
|
||||
if (!(action & CONTINUE)) ReactiveDraw();
|
||||
ScrollMemoryViews();
|
||||
}
|
||||
} else {
|
||||
@ -2737,8 +2738,11 @@ static void Tui(void) {
|
||||
} while (tuimode);
|
||||
} else {
|
||||
if (OnHalt(interrupt)) {
|
||||
ReactiveDraw();
|
||||
ScrollMemoryViews();
|
||||
goto KeepGoing;
|
||||
}
|
||||
ReactiveDraw();
|
||||
ScrollOp(&pan.disassembly, GetDisIndex());
|
||||
}
|
||||
TuiCleanup();
|
||||
|
||||
@ -115,6 +115,7 @@ struct Command command;
|
||||
const char *const kSafeEnv[] = {
|
||||
"ADDR2LINE", // needed by GetAddr2linePath
|
||||
"MAKEFLAGS", // needed by IsRunningUnderMake
|
||||
"MODE", // needed by test scripts
|
||||
"PATH", // needed by clang
|
||||
"PWD", // just seems plain needed
|
||||
"TERM", // needed by IsTerminalInarticulate
|
||||
|
||||
@ -281,9 +281,8 @@ int main(int argc, char *argv[]) {
|
||||
struct stat st;
|
||||
const char *path;
|
||||
if (argc == 1) {
|
||||
path = "o/v127/examples/hello2.com.dbg";
|
||||
/* fprintf(stderr, "USAGE: %s ELF\n", program_invocation_name); */
|
||||
/* exit(1); */
|
||||
fprintf(stderr, "USAGE: %s ELF\n", program_invocation_name);
|
||||
exit(1);
|
||||
} else {
|
||||
path = argv[1];
|
||||
}
|
||||
|
||||
@ -100,6 +100,7 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
|
||||
d->syms.p[j].unique = i;
|
||||
d->syms.p[j].size = st[i].st_size;
|
||||
d->syms.p[j].name = st[i].st_name;
|
||||
CHECK_GE(st[i].st_value, 0);
|
||||
d->syms.p[j].addr = st[i].st_value;
|
||||
d->syms.p[j].rank =
|
||||
-islocal + -isweak + -isabs + isprotected + isobject + isfunc;
|
||||
@ -112,7 +113,14 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
|
||||
}
|
||||
|
||||
static void DisSortSyms(struct Dis *d) {
|
||||
size_t i, j;
|
||||
qsort(d->syms.p, d->syms.i, sizeof(struct DisSym), (void *)DisSymCompare);
|
||||
for (i = 0; i < d->syms.i; ++i) {
|
||||
if (!strcmp("_end", d->syms.stab + d->syms.p[i].name)) {
|
||||
d->syms.i = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DisCanonizeSyms(struct Dis *d) {
|
||||
@ -178,6 +186,10 @@ long DisFindSym(struct Dis *d, int64_t addr) {
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
if (r && d->syms.p[r - 1].addr < 256) {
|
||||
/* XXX: prevent skewed binbase from doing weirdness */
|
||||
return -1;
|
||||
}
|
||||
if (r && (addr == d->syms.p[r - 1].addr ||
|
||||
(addr > d->syms.p[r - 1].addr &&
|
||||
(addr <= d->syms.p[r - 1].addr + d->syms.p[r - 1].size ||
|
||||
|
||||
@ -16,9 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/config.h"
|
||||
#include "ape/lib/pc.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/build/lib/case.h"
|
||||
@ -988,7 +987,7 @@ static void OpFnop(struct Machine *m) {
|
||||
}
|
||||
|
||||
void OpFinit(struct Machine *m) {
|
||||
m->fpu.cw = X87_NORMAL;
|
||||
m->fpu.cw = 0x037f;
|
||||
m->fpu.sw = 0;
|
||||
m->fpu.tw = -1;
|
||||
}
|
||||
|
||||
@ -194,6 +194,7 @@
|
||||
"forcealign"
|
||||
"typeof"
|
||||
"textreal"
|
||||
"texthead"
|
||||
"autotype"
|
||||
"_Section"
|
||||
"_Vector_size"))
|
||||
|
||||
@ -18,7 +18,6 @@ TOOL_NET_BINS = \
|
||||
$(TOOL_NET_COMS:%=%.dbg)
|
||||
|
||||
TOOL_NET_DIRECTDEPS = \
|
||||
APE_LIB \
|
||||
LIBC_ALG \
|
||||
LIBC_BITS \
|
||||
LIBC_CALLS \
|
||||
|
||||
Reference in New Issue
Block a user