2 8bit/some 16bit platforms
4 magic XX YY ; magic is the CPU specific magic
5 ; XX and YY are any value
6 ; used to form a jump around the header
7 FZX1 ; format magic (general)
8 loadpage.b ; 0 means 'relocatable'
9 chmem.w ; chmem value (0 all, will change to stack)
10 code.w ; size of code segment
11 data.w ; size of data segment
12 bss.w ; size of the BSS
15 Header is intentionally part of the code so that we load aligned blocks into
16 memory fast. The binary ends with the last block of data (and if need be
17 some zeros of the BSS but see below)
19 Address of code is deliberately passed into the crt0.S from kernel for
20 relocators to be possible
23 One new magic for split I/D on relevant platforms
24 chmem size will become stack size (only breaks stuff with it set)
25 0 base will mean 'has relocations'
26 BSS will start with relocation data
28 Rework the header so that code/data/bss are in terms of 256 byte
29 pages. Makes exec a lot simpler (no overflow maths).
35 6502/68HC11 will use cpuspecific.b for ZP space needed
37 The CPUfeature bit is bits for features not CPU subtypes as
41 0: NMOS illegals 6502 only
42 1: 65C02 65C02 and friends
43 2: 65C02 bitops Rockwell and later WDC C02
47 6-7 spare for 740 family etc
48 [don't need to cover kernel only bits]
50 This way means we can just do an and and a compare to check
64 1: 801C86 instructions (push immediate etc)
74 5: FPU (might need 2 bits of FPU info)
83 Proposed Relocation Format:
85 1-255 skip 1-255 bytes and then add the high byte of the base
88 0 1-255 skip 1-255 bytes
90 6502/HC11 has a second set of entries that relocate ZP shifting the ZP offsets
91 by the ZP base of the platform
93 65C816 if we disallow swapping and support large mode will also need a 3rd
94 pass that updates banks from 0..n to the ones assigned
96 Stick relocation data at end of data segment in a place we load but then
97 count as bss (so brk will go over it). So the loader will consume the relocs
98 and then brk them out of existance.
100 Need to think about compressed binaries and especially for 6502 a fixed
101 lib6502 for the intrinsics code which is a fair size, common to all binaries for
102 the most part, and also could be shared with kernel (eg on Apple IIe) where
103 we have the right mappings.
108 Do we want to just use a.out ?
113 Uses binfmt_flat with tiny tweaks to avoid loading Linux binaries
116 Entry Conditions & System Calls
119 C stack configured in zero page (unrelocated 0/1)
120 6502 stack set to end of 6502 stack space (may not be $1FF)
121 X holds high byte of load address
122 A holds first zero page value allocated
125 Execution begins at first byte of loaded binary
126 Signal vector helper code must be present at offset 20
128 Need to sort out syscall vector and relocations for it (maybe
131 System calls via jmp ($00fe) [to be fixed for relocation etc]
132 Arguments on C stack (ZP:0 + base)
133 X holds the syscall number
134 Y holds the number of arguments
136 Behaves like a cc65 non fast call, so the syscall unstacks the
139 Returns in YX with error code in A and Z clear if no error
142 A7 is set to the C stack
143 Code is always relocated
144 Other registers are undefined
148 32bit pointer / 32bit int unlike smaller ports
150 trap 15 causes a SIGTRAP
152 trap14 (currently - may relocate this)
159 The only register we guarantee to save is A5, thus anything using
160 base relative addressing needs to use A5 as the base because signal
161 handling at the wrong moment may mean all other registers are
162 undefined. This might seem a pain but it saves us a load of clocks!
164 return value is in d0.l and a0.l (for convenience)
165 error code is in d1.w
168 S is set to the C stack
169 X holds the load address
170 other registers undefined
172 Execution begins at first byte of loaded binary
173 No signal vector helper required
175 System calls are via swi
176 Arguments on the caller stack, call number in D when swi
179 Returns error code in D, return in X
182 SP is set to the C stack
183 IY holds the base address (load for relocatables)
184 HL holds the load address
187 Alternate registers are saved
189 On entry userspace stack holds the syscall arguments
190 On return HL holds the return value and carry is clear
191 On error return HL holds the error and carry is set