summary refs log tree commit diff
path: root/elf.e
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-05-15 20:51:13 -0700
committerIrene Knapp <ireneista@irenes.space>2026-05-15 21:58:20 -0700
commit447921598269bae3e1406470015c37f23943cc74 (patch)
tree464583448ae74f83af637cefded39d8b3d431aff /elf.e
parent1af849abc637c4890285c4d3cc08d99faae2ea41 (diff)
make the label transformation work all the way, no crashing
the code doesn't quite run yet, that'll be a future CL

Force-Push: yes
Change-Id: I71e6a45127c1fc37906d902e36142c17afef2a21
Diffstat (limited to 'elf.e')
-rw-r--r--elf.e25
1 files changed, 8 insertions, 17 deletions
diff --git a/elf.e b/elf.e
index 708de13..68eb6f2 100644
--- a/elf.e
+++ b/elf.e
@@ -9,22 +9,11 @@
 ~   This relies on the label facility defined in labels.e. Make sure to load
 ~ that first.
 
-~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-~ ~~ Runtime memory origin ~~
-~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
-~
-~   First, we pick an origin to load at. This is arbitrary, but it can't be
-~ zero. We define a constant word for it so the body of the program can use
-~ it in label calculations in whatever ways it needs to.
-
-: origin 0x08000000 ;
-
-
 ~ ~~~~~~~~~~~~~~~~~~~~~
 ~ ~~ ELF file header ~~
 ~ ~~~~~~~~~~~~~~~~~~~~~
 ~
-~   Second, we output ELF's top-level file header. This header describes the
+~   First, we output ELF's top-level file header. This header describes the
 ~ entire file. An ELF always has exactly one of this header, which is always
 ~ at the start of the file.
 ~
@@ -48,7 +37,7 @@
   0x3e pack16                           ~ *Intel x86-64
   1 pack32                              ~ ELF format version
 
-  L@' cold-start origin + pack64        ~ *entry point
+  L@' cold-start L@' origin + pack64        ~ *entry point
     ~ This includes the origin, intentionally.
 
   L@' elf-program-header pack64         ~ *program header offset
@@ -74,7 +63,7 @@
 ~ ~~ ELF program header ~~
 ~ ~~~~~~~~~~~~~~~~~~~~~~~~
 ~
-~   Third, we output ELF's program header, which lists the memory regions
+~   Second, we output ELF's program header, which lists the memory regions
 ~ ("segments") we want to have and where we want them to come from. There may
 ~ be any number of these entries, one per segment, , and they may be anywhere
 ~ in the file as long as they're consecutive.
@@ -104,7 +93,7 @@
   1 pack32                              ~ *"loadable" segment type
   0x05 pack32                           ~ *read+execute permission
   0 pack64                              ~ *offset in file
-  origin pack64                         ~ *virtual address
+  L@' origin pack64                     ~ *virtual address
     ~ required, but can be anything, subject to alignment
   0 pack64                              ~ physical address (ignored)
 
@@ -123,6 +112,8 @@
 ~ ~~~~~~~~~~~~~~~~
 ~
 ~   ELF is a simple format, really.  Now you can output your own machine code
-~ that you generate however you want; make sure to define the label
-~ cold-start, which will be the first thing that runs.
+~ that you generate however you want; make sure to define the labels "origin"
+~ and "cold-start". Origin will control the address the code loads at;
+~ cold-start will be the first thing that runs. The origin is arbitrary, but
+~ can't be zero.