Browse Source

Basic C linker

master
Stephen 1 year ago
parent
commit
e151ce5e54
4 changed files with 60 additions and 0 deletions
  1. +30
    -0
      os/Linker.ld
  2. +8
    -0
      os/Makefile
  3. +13
    -0
      os/main.c
  4. +9
    -0
      os/start.s

+ 30
- 0
os/Linker.ld View File

@ -0,0 +1,30 @@
STARTUP(start.o)
INPUT(main.o)
OUTPUT(os.bin)
OUTPUT_FORMAT("binary")
ENTRY(_start)
MEMORY
{
ROM(rx): ORIGIN = 0, LENGTH = 256k
RAM(rwx): ORIGIN = 0x120000, LENGTH = 256k
}
SECTIONS
{
.text :
{
*(.text)
*(.rodata*)
} > ROM
.data :
{
*(.data*)
} > RAM AT > ROM
.bss :
{
*(.bss*)
} > RAM
}

+ 8
- 0
os/Makefile View File

@ -0,0 +1,8 @@
os.bin: start.o main.o Linker.ld
m68k-elf-ld -T Linker.ld -o os.bin -O2 -nostdlib
start.o: start.s
m68k-elf-as -mcpu=68000 -o start.o start.s
main.o: main.c
m68k-elf-gcc -c main.c -o main.o -ffreestanding -O2 -Wall -Wextra

+ 13
- 0
os/main.c View File

@ -0,0 +1,13 @@
void kmain()
{
char *s = "Hello world!";
char *o = (char*)0x50500;
while(1)
{
*s = *o + 1;
*o = *s;
o++;
s++;
}
}

+ 9
- 0
os/start.s View File

@ -0,0 +1,9 @@
.global _start
.long _start
.org 0x400
_start:
.long 0xDEADBEEF
.long 0xDEADBEEF
.long 0xDEADBEEF
JSR kmain

Loading…
Cancel
Save