Skip to content

Instantly share code, notes, and snippets.

@lain-dono
Last active August 29, 2015 13:57
Show Gist options
  • Save lain-dono/9634596 to your computer and use it in GitHub Desktop.
Save lain-dono/9634596 to your computer and use it in GitHub Desktop.
BareBones arm

Собираем стартовый файл arm-eabi-as -o boot.o boot.s

Собираем main.c arm-eabi-gcc -nostdlib -nostartfiles -ffreestanding -std=c99 -c kernel_main.c -o kernel_main.o

Линкуем всё в kernel arm-eabi-ld -T linker.ld -o kernel boot.o kernel_main.o

Запускаем qemu-system-arm -m 128 -kernel kernel -serial stdio

// Таблица прерываний
interrupt_vector_table:
b . // Reset
b .
b . // SoftWare Interrupt instruction
b .
b .
b .
b .
b .
.comm stack, 0x10000 // Оставляем 64k под стек (пойдёт в BSS секцию)
_start:
.globl _start
ldr sp, =stack+0x10000 // Настраиваем стек
bl kernel_main // Прыгаем к main
1: // Вечный цикл
b 1b @ Halt
#define SERIAL_BASE 0x16000000
#define SERIAL_FLAG_REGISTER 0x18
#define SERIAL_BUFFER_FULL (1 << 5)
void putc (char c) {
/* Ждём, пока буфер не станет пустым */
while (*(volatile unsigned long*)(SERIAL_BASE + SERIAL_FLAG_REGISTER) & (SERIAL_BUFFER_FULL)) {
}
/* Помещаем символ в буфер */
*(volatile unsigned long*)SERIAL_BASE = c;
}
void puts (const char * str) {
while (*str) putc (*str++);
}
int kernel_main (void) {
puts ("hello, world!\n");
return 0;
}
ENTRY (_start)
SECTIONS
{
. = 0;
.text : { *(.text*) *(.rodata*) }
.data : { *(.data*) }
.bss : { *(.bss*) *(COMMON*) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment