Comments (19)
Hello @georgp24,
Use the -melks
switch to compile for ELKS --- gcc-ia16
compiles for MS-DOS on default. For now you also need to specify -mcmodel=small
to compile for the small memory model (but I hope to remove this need for ELKS).
You should not need the -I
... switch.
Thank you!
from gcc-ia16.
Hi @tkchia,
I still do not get to compile, I just run the env.sh script in elks and this apparently does not set the paths as required. So I have to add the -I switch or it will not find stdio.h. Now I tried:
~/elks> ia16-elf-gcc hello.c -o hello -Icross/ia16-elf/lib/elkslibc/include -melks -mcmodel=small
It now says: Linkerscript »elk-mssl.ld« missing
from gcc-ia16.
Hello @georgp24,
My apologies... the options should be -melks-libc -mcmodel=small
. Please let me know if you encounter any further problems.
(-melks
will currently link with the Newlib C library for ELKS, but I am in the process of dropping support for that, in favour of ELKS's own C library.)
Thank you!
from gcc-ia16.
Hi tkchia,
thank you! I could compile my hello world program now and got it to run on ELKS.
Now I try to compile an assembler program with these commands:
ia16-elf-gcc -c hello.S
ia16-elf-ld hello.o -o hello
This generates a program that works on my Linux system but not with ELKS. What needs to be done here?
from gcc-ia16.
Hello @georgp24,
You can also use ia16-elf-gcc
for the linking step (it will pass the correct linker script etc. to ia16-elf-ld
):
ia16-elf-gcc hello.o -o hello
If you want to exclude the system startup files and/or libraries from the link, use the -nostdlib
or -nodefaultlibs
option (see the GCC documentation). Thank you!
from gcc-ia16.
I forgot: also add -melks-libc -mcmodel=small
to the GCC command lines. Thank you!
from gcc-ia16.
I tried these lines:
ia16-elf-gcc -c hello.S -mcmodel=small -melks-libc
ia16-elf-gcc -c hello.o -o helloa -nodefaultlibs
In the linking step it reports the warning that: 'the input files of the linker will be used because no linking takes place'. No executable is generated.
This is the code:
.text # section declaration
# we must export the entry point to the ELF linker or
.global _start # loader. They conventionally recognize _start as their
# entry point. Use ld -e foo to override the default.
_start:
# write our string to stdout
movl $len,%edx # third argument: message length
movl $msg,%ecx # second argument: pointer to message to write
movl $1,%ebx # first argument: file handle (stdout)
movl $4,%eax # system call number (sys_write)
int $0x80 # call kernel and exit
movl $0,%ebx # first argument: exit code
movl $1,%eax # system call number (sys_exit)
int $0x80 # call kernel
.data # section declaration
msg:
.ascii "Hello, world!\n" # our dear string
len = . - msg # length of our dear string
from gcc-ia16.
OK, the link line should rather be:
ia16-elf-gcc hello.o -o helloa -nodefaultlibs
now I get the problem: Linkerscript »dos-mts.ld« cannot be found.
from gcc-ia16.
Meanwhile I tried:
ia16-elf-ld hello.o -o helloa -nodefaultlibs
This generates a program called defaultlibs which can be executed with Linux and outputs "Hello world". Then I tried:
ia16-elf-ld hello.o -nodefaultlibs -o helloa
This generates a program called helloa that runs on Linux but not on ELKS.
from gcc-ia16.
Helo @georgp24,
There are several things:
- You need to specify
-melks-libc -mcmodel=small
both at compilation time (-c
) and at link time. - You need to specify
.code16
near the start of the assembly source so that GNUas
will assemble instructions in 16-bit mode (this is a bit unfortunate, and I hope to fix this some day). - The "true" entry point is currently called
entry
, not_start
, in ELKS's C library linker scripts (perhaps this should also be fixed...). [edit: I have sent in a pull request to ELKS to fix this.] - Also,
-nostdlib
rather than-nodefaultlibs
is probably what you need, if you also want to leave out the program startup module (crt0.o
). - There is no need to set 32-bit registers
%eax
etc. when making syscalls. The ELKS kernel --- which can also run on 16-bit-only machines --- only cares about the contents of the 16-bit registers%ax
,%bx
,%cx
, etc.
Therefore:
$ cat hello.S
.code16
.text
.global entry
entry:
movw $len,%dx
movw $msg,%cx
movw $1,%bx
movw $4,%ax
int $0x80
movw $0,%bx
movw $1,%ax
int $0x80
.data
msg:
.ascii "Hello, world\n"
len = . - msg
$ ia16-elf-gcc -melks-libc -mcmodel=small -c hello.S -o hello.o
$ ia16-elf-gcc -melks-libc -mcmodel=small -nostdlib hello.o -o helloa
Thank you!
from gcc-ia16.
Hello @georgp24,
Another tip: if you build the whole ELKS tree, there will also be a program elksemu
which can run an ELKS program under Linux/x86-32 or Linux/x86-64. This should be under elksemu/elksemu
. You can use this program to quickly test your ELKS programs on Linux before moving them onto a real ELKS system.
$ ./helloa
bash: ./helloa: cannot execute binary file: Exec format error
$ ....../elksemu helloa
Hello, world
Thank you!
from gcc-ia16.
Hello @georgp24, let me know if you still have any questions. Thank you!
from gcc-ia16.
Thank you very much tkchia, I got it working now!
I saw in the linker script that you also support the tiny model. Does this work too?
from gcc-ia16.
I also tried elksemu as you mentioned.
elksemu/elksemu ./helloa
This did just output:
waitpid failed
from gcc-ia16.
Hello @georgp24,
Thank you very much tkchia, I got it working now!
No problem. :-)
I saw in the linker script that you also support the tiny model. Does this work too?
The newer ELKS kernel unfortunately does not run tiny model programs --- so you can try to compile a program for the tiny model, but it will not run.
This did just output:
waitpid failed
This is strange. What is the output of strace
on elksemu
? I.e.
strace elksemu/elksemu ./helloa
Thank you!
from gcc-ia16.
I tried Intel syntax with as. Is it correct that gcc-ia16 does not support the -mnaked-reg
parameter?
Here is the strace output:
ia16-elf-gcc: Fehler: nicht erkannte Kommandozeilenoption »-mnaked-reg«
georg@linux-lj8b:~/elks> strace elksemu/elksemu ./helloa
execve("elksemu/elksemu", ["elksemu/elksemu", "./helloa"], [/* 103 vars */]) = 0
brk(0) = 0x1a7e000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f610d21a000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=154583, ...}) = 0
mmap(NULL, 154583, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f610d1f4000
close(3) = 0
open("/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\10\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1925032, ...}) = 0
mmap(NULL, 3811776, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f610cc58000
mprotect(0x7f610cdf1000, 2097152, PROT_NONE) = 0
mmap(0x7f610cff1000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x199000) = 0x7f610cff1000
mmap(0x7f610cff7000, 14784, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f610cff7000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f610d1f3000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f610d1f2000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f610d1f1000
arch_prctl(ARCH_SET_FS, 0x7f610d1f2700) = 0
mprotect(0x7f610cff1000, 16384, PROT_READ) = 0
mprotect(0x605000, 4096, PROT_READ) = 0
mprotect(0x7f610d21b000, 4096, PROT_READ) = 0
munmap(0x7f610d1f4000, 154583) = 0
access("./helloa", X_OK) = 0
open("./helloa", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0755, st_size=77, ...}) = 0
getuid() = 1000
getgid() = 100
setregid(100, 100) = 0
setreuid(1000, 1000) = 0
modify_ldt(0, 0x7fff9585af60, 0x10000) = 0
modify_ldt(0x1, 0x7fff9585af50, 0x10) = 0
modify_ldt(0x1, 0x7fff9585af40, 0x10) = 0
mmap(NULL, 135168, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANONYMOUS|MAP_32BIT, -1, 0) = 0x4021f000
mprotect(0x4023f000, 4096, PROT_NONE) = 0
read(3, "\1\0030\4 \0\0\0 \0\0\0\r\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32) = 32
read(3, "f\272\r\0\0\0f\271\0\0\0\0f\273\1\0\0\0\270\4\0\315\200\273\0\0\270\1\0\315\200\220", 32) = 32
read(3, "Hello, world\n", 13) = 13
modify_ldt(0x1, 0x7fff9586af70, 0x10) = 0
modify_ldt(0x1, 0x7fff9586af80, 0x10) = 0
close(3) = 0
clone(child_stack=0x4022e10e, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_IO) = 3195
ptrace(PTRACE_ATTACH, 3195, 0, 0) = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_TRAPPED, si_pid=3195, si_status=SIGSTOP, si_utime=0, si_stime=0} ---
wait4(3195, 0x7fff9586aebc, 0, NULL) = -1 ECHILD (No child processes)
write(2, "waitpid failed\n", 15waitpid failed
) = 15
exit_group(255) = ?
+++ exited with 255 +++
georg@linux-lj8b:~/elks> sudo mount -o loop image/fd1440.bin floppy1
root's password:
georg@linux-lj8b:~/elks> sudo cp ./helloa floppy1/usr/bin
georg@linux-lj8b:~/elks> ./qemu.sh
(process:3212): GLib-WARNING **: gmem.c:483: custom memory allocation vtable not supported
char device redirected to /dev/pts/2 (label chardev1)
Warning: default mac address being used, creating potential for address conflict
from gcc-ia16.
The newer ELKS kernel unfortunately does not run tiny model program --- so you can try to >compile a program for the tiny model, but it will not run.
I looked at the program loader about three years ago. It had code to run tiny model programs but that did not work and I did not get it to work.
from gcc-ia16.
Hello @georgp24,
I tried Intel syntax with as. Is it correct that gcc-ia16 does not support the
-mnaked-reg
parameter?
The GCC front end does not understand this option --- only the assembler does. So you need to wrap it in -Wa,
... e.g. -Wa,-mnaked-reg
or -Wa,-msyntax=INTEL
etc.
Alternatively, you can write a pseudo-op inside the .S
source file itself, e.g.
.intel_syntax
or
.intel_syntax noprefix
etc.
ptrace(PTRACE_ATTACH, 3195, 0, 0) = 0 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_TRAPPED, si_pid=3195, si_status=SIGSTOP, si_utime=0, si_stime=0} --- wait4(3195, 0x7fff9586aebc, 0, NULL) = -1 ECHILD (No child processes)
The ECHILD
error is strange. I am unfortunately still unable to reproduce this problem on my end. Meanwhile I think I will help you open an issue report for this on the ELKS project.
Thank you!
from gcc-ia16.
I tried Intel syntax with as. Is it correct that gcc-ia16 does not support the
-mnaked-reg
parameter?
-masm=intel
is the switch you're looking for.
edit: To make gcc emit intel asm, that is. For assembling I think .intel_syntax noprefix
is the best option.
from gcc-ia16.
Related Issues (20)
- Various issues building the `G` editor ... HOT 4
- Verify if -mcmodel=medium still enables -msegment-relocation-stuff HOT 3
- Potential optimization: Interesting code generation quirk
- Compact/large memory models HOT 1
- Medium model data relocations not emitted for ELKS? HOT 5
- Undefined references on ELKS kernel with compiler upgrade HOT 6
- Feature request: ISR attribute to save call-used registers HOT 6
- Far function pointer calls violate %ds = .data invariant HOT 3
- is flat memory model supported? HOT 1
- medium memory model doesn't seem to work HOT 25
- how DPMI-safe is libc? HOT 20
- long type seems broken HOT 2
- i386 support? HOT 13
- please enable UMB for internal allocs
- 32bit dpmi mode? HOT 48
- How to add option to r-elks.specs file HOT 2
- possible -mdpmi extensions HOT 2
- enlarge overlay info? HOT 15
- Potential optimization: (AX << 8) | value => AH<-AL; AL=value HOT 2
- ICE in g++ for template constructor with -mno-callee-assume-ss-data-segment HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gcc-ia16.