22 May 2023, 19:26 | #1 |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,146
|
"BSS" with ORG'ed code
Is there a way to do the moral equivalent of ds.y/dx.y without increasing the section size?
Concretely I'm making an executable that kills the system and relocates itself at a specific address, and don't want to unnecessarily increase the section size. (See below code). I'd like to just do "somvar1 ds.l 1" (or similar) rather than my hack of trying to guess the code size (rsset needs a constant expression). Using vasm, but isn't (wasn't) this a common "issue"? Hope the question makes sense Code:
LOAD_ADDR=$8000 SECTION code,code start: move.w #$7fff,d0 move.w d0,$dff09a move.w d0,$dff09c lea code_start(pc),a0 lea .reloc(pc),a1 move.w #$20,a2 moveq #(.reloc_end-.reloc)/2-1,d0 .reloc0: move.w (a1)+,(a2)+ dbf d0,.reloc0 jmp $20.w .reloc: lea LOAD_ADDR,a1 move.l #(code_end+3-main)/4,d0 cmpa.l a0,a1 bls.b .copy_down move.l d0,d1 lsl.l #2,d1 add.l d1,a0 add.l d1,a1 .copy_up: move.l -(a0),-(a1) subq.l #1,d0 bne.b .copy_up jmp LOAD_ADDR .copy_down: move.l (a0)+,(a1)+ subq.l #1,d0 bne.b .copy_down jmp LOAD_ADDR .reloc_end: code_start: ORG LOAD_ADDR main: move.l #42,somevar1 move.l #666,somevar2 bra main code_end=* CODE_SIZE=$4000 if code_end-main>CODE_SIZE error increase CODE_SIZE endc rsset LOAD_ADDR+CODE_SIZE somevar1 rs.l 1 somevar2 rs.l 1 ; Imagine this is rs.w 40000 or whatever |
23 May 2023, 12:00 | #2 | ||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
Quote:
Code:
*=*+4 Code:
myvar: *=*+4 oldstylesyntax module supports it perfectly. But I didn't see that a lot in Motorola's 68k syntax, where ' *' often introduces a comment. Quote:
NOLOADkeyword for that section. That said, you can indeed achieve similar behaviour like *=*+nwith vasm's mot-syntax module, but I'm not sure how compatible it is with other assemblers. When there are better, more portable solutions, I am happy to implement them. This works: Code:
somevar1 org *+4 Code:
LOAD_ADDR=$8000 SECTION code,code start: move.w #$7fff,d0 move.w d0,$dff09a move.w d0,$dff09c lea code_start(pc),a0 lea .reloc(pc),a1 move.w .dest,a2 moveq #(.reloc_end-.reloc)/2-1,d0 .reloc0: move.w (a1)+,(a2)+ dbf d0,.reloc0 jmp .dest.w .reloc: org $20 .dest: lea LOAD_ADDR,a1 move.l #(code_end+3-main)/4,d0 cmpa.l a0,a1 bls.b .copy_down move.l d0,d1 lsl.l #2,d1 add.l d1,a0 add.l d1,a1 .copy_up: move.l -(a0),-(a1) subq.l #1,d0 bne.b .copy_up jmp LOAD_ADDR .copy_down: move.l (a0)+,(a1)+ subq.l #1,d0 bne.b .copy_down jmp LOAD_ADDR section code,code .reloc_end: code_start: ORG LOAD_ADDR main: move.l #42,somevar1 move.l #666,somevar2 bra main code_end=* somevar1 org *+4 somevar2 org *+4 |
||
23 May 2023, 13:46 | #3 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,630
|
I think
Code:
move.w .dest,a2 Code:
move.w #.dest,a2 |
23 May 2023, 15:21 | #4 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
Correct! I inserted the
org $20and .destto make it more readable, where I did that typo. Probably paraj was aware of it, but I should mention that an orginside of a normal section, like in this example, is handled different as if you start your code directly with an org. Here the code after orgis still part of the codesection. But all its labels are relocated to an absolute address. You can switch back to the normal section with a sectiondirective. A noticeable difference is that there is no gap in the code between these relocated org blocks, which you would otherwise get in real absolute output without a sectiondirective. |
23 May 2023, 19:27 | #5 | |
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,146
|
Thanks for the feedback! Forgot to mention in my post that I had already seen stuff like
Code:
somevar1=* somvar2=somvar1+4 somvar3=somvar2+16 somevar1 org *+4works and is OK! rs.y/ds.y is a bit more readable, but nothing too bad. Quote:
Had another look at the vasm manual, and on a hunch I tried __RS set *and it work perfectly! In asm-pro (1.19c, i.e. one of a/b's recent builds) that doesn't work, but rsset *seems to do the same. Maybe there's something I'm missing, but maybe the restriction on the argument to rsset could be lifted without issue? I.e. Code:
section code,code move.l #var1,d0 move.l #var2,d1 move.l #var3,d2 rts ORG $1000 rsset * ; if VASM use "__RS set *" var1: rs.l 4 var2: rs.w $1000 var3: rs.l 0 Code:
MOVE.L #$00001000,D0 MOVE.L #$00001010,D1 MOVE.L #$00003010,D2 RTS |
|
24 May 2023, 11:10 | #6 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,510
|
Quote:
du.xfor declare uninitialized space: Code:
du macro ifc '\0','b' org *+\1 endc ifc '\0','w' org *+2*\1 endc ifc '\0','l' org *+4*\1 endc endm Quote:
Quote:
__RS set *is a bug. So I checked the source again, and indeed, the restriction was never needed. It even works within a relocatable section. Patch is committed and available with tomorrow's snapshot. Thanks! Code:
--- syntax/mot/syntax.c 10 May 2023 10:08:58 -0000 1.237 +++ syntax/mot/syntax.c 24 May 2023 08:44:33 -0000 1.238 @@ -1483,7 +1483,7 @@ static void handle_rsset(char *s) { - new_abs(rs_name,number_expr(parse_constexpr(&s))); + new_abs(rs_name,parse_expr_tmplab(&s)); } static void handle_rseven(char *s) @@ -1498,7 +1498,7 @@ static void handle_setfo(char *s) { - new_abs(fo_name,number_expr(parse_constexpr(&s))); + new_abs(fo_name,parse_expr_tmplab(&s)); } static void handle_rs8(char *s) |
|||
24 May 2023, 19:36 | #7 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,629
|
I'm thinking you're trying to write your own code to do things that there are already options for? Is it possible that you misunderstand ORG, LOAD, etc? (If not just try to explain the goal/what you're trying to achieve.)
If the absaddr code is not PC-relative, you have to put system off code at the start of it and reset every time you test it, unless the address is in available memory. Then you can ORG and LOAD and define a JUMPPTR. Outside an IDE it's just a pure binary file, and there's no monitor inside Amiga OS to jump to an address. One problem might be that you have to write an executable file every time you want to run it? Amiga OS won't load it to the right address, so you are trying to do what execrunchers do (without the crunching). Nevertheless, this was how it was done before RAM expansions on A500 etc, to allow the binary to be started from the OS, still able to use almost all of the chipmem, and not require the RAM expansion, and not require an entire disk for one program. If this is to be part of a devchain, then perhaps include an execruncher in it and done? Or include a trackloader and write a disk image instead of an exe file. (Since absolute addressing might require a reboot on every run anyway.) There's nothing really to stop an IDE or a normal text editor (if native) to compile by calling a command-line compiler. Those editors can include a monitor that can not only jump to the right address. The AsmOne etc. assemblers do this and support ORG/LOAD, just ORG to declare ds, and mix ORG/LOAD with SECTIONs. An alternative is to make such an assembler the last part of a devchain. The "assemble this source and and run it" can be provided as a command line parameter. If you want to provide a single structure to declare lots of offsets (e.g. buffers or structures), many assemblers support this with directives. If you want to make calculations between symbols and get an error out of it, this depends on how many passes the assembler is using. It's normal to do a first pass to establish the values of all symbols (so that the order in which you write your code is not forced, e.g. forward references). If you try to do the calculation before all symbols have values, you should get an error to that effect in every Assembler. In AsmOne etc. you can wrap such checks in the "IF2" directive to make sure the check is ignored in pass 1. |
24 May 2023, 20:31 | #8 | ||
Registered User
Join Date: Feb 2017
Location: Denmark
Posts: 1,146
|
Quote:
Quote:
This is strictly meant for 100% system killing code. Likely trackloaded, but could be done from an executable (like in my original post). For my current experiments it's because I need to put some large tables in "low" memory (<$8000) for optimization purposes. In a trackloaded scenario it's nice to have stuff in fixed (but flexible) memory locations with assembler help. These days I use vasm and cross-compile (assemble) with WinUAE for most testing, and an executable is easier than creating an ADF with trackloader+code, and when I do test on my Amiga it's also easier: just transfer executable (even if I need to reboot afterwards). If I were doing my development in e.g. Asm-Pro I'd try to do a more gentle system supspension, copy the first 64K somewhere else and restore them, etc. |
||
24 May 2023, 23:42 | #9 |
Moderator
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,629
|
It must be a very special case.
Yep, if you can restore low mem correctly, you can allow exit. This was sometimes done in the early years when RAM expansions came and "FastMemFirst" wasn't obeyed or not working 100%. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Recoverable Alert Error 0003 8007 when opening "ed" | jman | support.AmigaOS | 3 | 19 February 2023 00:33 |
"Diabolik" & "Dylan Dog" & "Tex" & "Time Runners" series | DamienD | request.Old Rare Games | 20 | 21 July 2022 16:58 |
"Voices8" 8 Channel Soundtracker "DemoSongI" song - "This is the Amiga with 8 Voices" | DemosongIHunter | request.Music | 45 | 23 May 2022 20:07 |
"Screech!! v2.41" & "Screech!! [AGA] v2.51" - "HD install" --> "ADFs" | DamienD | request.Old Rare Games | 45 | 15 June 2020 12:42 |
"Reminder "Lincs Amiga User Group aka "LAG" Meet Sat 5th of January 2013" | rockape | News | 4 | 30 January 2013 00:06 |
|
|