Jonathan Harston
2021-07-12 01:10:20 UTC
I've been experimenting with BSD 2.11 Unix. I'm having problems
getting assembly code to execute and do anything. I stripped
down to a minimal example:
ORG 0 ; position independant code
EQUW &0107 ; magic number, also branch to Startup
EQUW _DATA%-_TEXT% ; size of text
EQUW _BSS%-_DATA% ; size of initialised data
EQUW _END%-_BSS% ; size of uninitialised data
EQUW &0000 ; size of symbol data
EQUW _ENTRY%-_TEXT% ; entry point
EQUW &0000 ; not used
EQUW &0001 ; no relocation info
ORG 0 ; position independant code
._TEXT%
;
._ENTRY%
mov #1,r0 ; r0=STDOUT
trap 4 ; write()
equw msg_hello ; Start of data
equw end_hello-msg_hello ; Length of data
;
trap 1 ; exit()
halt ; drop to monitor
;
._DATA%
.msg_hello
equs "Hello world!",10,13
.end_hello
align
;
._BSS%
._END%
Running it just returns to the command prompt with no output.
Examining the binary with adb shows the expected code and
data, and single-stepping through it successfully sets R0, then
at the sys write() it makes the call, outputs nothing, and ends
at the exit().
If I can't even get any output so I can display debug messages,
I'm stumped!
Aside, I've written the same code in C and compiled it, and it
works fine, so my next direction of attack is to disassemble
the generated code and see what it's doing that my assembly
code isn't.
jgh
getting assembly code to execute and do anything. I stripped
down to a minimal example:
ORG 0 ; position independant code
EQUW &0107 ; magic number, also branch to Startup
EQUW _DATA%-_TEXT% ; size of text
EQUW _BSS%-_DATA% ; size of initialised data
EQUW _END%-_BSS% ; size of uninitialised data
EQUW &0000 ; size of symbol data
EQUW _ENTRY%-_TEXT% ; entry point
EQUW &0000 ; not used
EQUW &0001 ; no relocation info
ORG 0 ; position independant code
._TEXT%
;
._ENTRY%
mov #1,r0 ; r0=STDOUT
trap 4 ; write()
equw msg_hello ; Start of data
equw end_hello-msg_hello ; Length of data
;
trap 1 ; exit()
halt ; drop to monitor
;
._DATA%
.msg_hello
equs "Hello world!",10,13
.end_hello
align
;
._BSS%
._END%
Running it just returns to the command prompt with no output.
Examining the binary with adb shows the expected code and
data, and single-stepping through it successfully sets R0, then
at the sys write() it makes the call, outputs nothing, and ends
at the exit().
If I can't even get any output so I can display debug messages,
I'm stumped!
Aside, I've written the same code in C and compiled it, and it
works fine, so my next direction of attack is to disassemble
the generated code and see what it's doing that my assembly
code isn't.
jgh