+/rtos

git clone https://git.julia.blue/+/rtos

Vivek MalneediMerge branch 'master' of github.com:EE445M-Sp20/lab-6-vm22967_jbr2558ee4080a

master
802 B30 linesraw
1#include <stdint.h>
2
3#define PF2 (*((volatile uint32_t*)0x40025010))
4#define PF3 (*((volatile uint32_t*)0x40025020))
5
6volatile uint32_t id = 0; // bss
7
8volatile uint32_t other; // noinit (but actually bss)
9
10volatile static int y = 5; // data
11
12const int x = 17; // rodata (but actually just data)
13
14static __attribute__((naked)) void (*load_function(const char* name))(void) {
15    __asm("SVC #0");
16    __asm("BX LR");
17}
18
19void main(void) { // text
20    uint32_t (*OS_Id)(void) = (uint32_t(*)(void))load_function("OS_Id");
21    uint32_t (*printf)(const char*, ...) =
22        (uint32_t(*)(const char*, ...))load_function("printf");
23    id = OS_Id();
24    if ((id && y) || other) {
25        PF2 ^= 0x04;
26    } else {
27        PF3 ^= 0x08;
28    }
29    printf("Executed an entire loaded binary! (pid=%d)\n\r", id);
30}