Changes to get platform-v8080 running again
[FUZIX.git] / README.binfmt
1
2 8bit/some 16bit platforms
3
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
13         0.w                     ; reserved
14
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)
18
19 Address of code is deliberately passed into the crt0.S from kernel for
20 relocators to be possible
21
22 Proposed changes:
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
27
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).
30
31         0.w will become
32                 cpufeature.b
33                 cpuspecific.b
34
35         6502/68HC11 will use cpuspecific.b for ZP space needed
36
37         The CPUfeature bit is bits for features not CPU subtypes as
38         o65 does it so
39
40         6502 bits
41         0:      NMOS illegals           6502 only
42         1:      65C02                   65C02 and friends
43         2:      65C02 bitops            Rockwell and later WDC C02
44         3:      65CE02  (Z)             65CE02
45         4:      BCD                     All but 2A03
46         5:      65C802/816
47         6-7 spare for 740 family etc
48         [don't need to cover kernel only bits]
49
50         This way means we can just do an and and a compare to check
51         compatibility
52
53         Z80 bits
54         0:      Z80 illegals
55         1:      Z180
56         2:      Z280
57         3:      R800
58
59         6809 bits
60         0:      6309
61
62         8086 bits
63         0:      8087
64         1:      801C86 instructions (push immediate etc)
65         2:      80286
66         3:      80287
67
68         68000 bits
69         0:      68010
70         1:      68020
71         2:      68030
72         3:      68040
73         4:      68060
74         5:      FPU     (might need 2 bits of FPU info)
75
76         68HC11
77         None needed I believe
78
79         PDP/11  TBD
80
81
82
83 Proposed Relocation Format:
84         
85         1-255   skip 1-255 bytes and then add the high byte of the base
86                 to this address.
87         0 0     end
88         0 1-255 skip 1-255 bytes
89
90 6502/HC11 has a second set of entries that relocate ZP shifting the ZP offsets
91 by the ZP base of the platform
92
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
95
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.
99
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.
104
105
106 PDP-11
107
108 Do we want to just use a.out ?
109
110
111 32bit
112
113 Uses binfmt_flat with tiny tweaks to avoid loading Linux binaries
114
115
116 Entry Conditions & System Calls
117
118 6502/65C816:
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
123         Y undefined
124
125         Execution begins at first byte of loaded binary
126         Signal vector helper code must be present at offset 20
127
128         Need to sort out syscall vector and relocations for it (maybe
129         pass it in Y ?)
130
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
135
136         Behaves like a cc65 non fast call, so the syscall unstacks the
137         passed arguments
138
139         Returns in YX with error code in A and Z clear if no error
140
141 68000:
142         A7 is set to the C stack
143         Code is always relocated
144         Other registers are undefined
145
146         System calls:
147
148         32bit pointer / 32bit int unlike smaller ports
149
150         trap 15 causes a SIGTRAP
151
152         trap14 (currently - may relocate this)
153         d0 = syscall
154         d1 = arg1
155         a0 = arg2
156         a1 = arg3
157         a2 = arg4
158
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!
163
164         return value is in d0.l and a0.l (for convenience)
165         error code is in d1.w
166
167 6809:
168         S is set to the C stack
169         X holds the load address
170         other registers undefined
171
172         Execution begins at first byte of loaded binary
173         No signal vector helper required
174
175         System calls are via swi
176         Arguments on the caller stack, call number in D when swi
177         Caller unstacks
178
179         Returns error code in D, return in X
180
181 Z80:
182         SP is set to the C stack
183         IY holds the base address (load for relocatables)
184         HL holds the load address
185
186         System calls:
187         Alternate registers are saved
188
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
192