diff options
author | Michael Davidsaver <mdavidsaver@gmail.com> | 2016-07-09 11:40:51 -0400 |
---|---|---|
committer | Michael Davidsaver <mdavidsaver@gmail.com> | 2016-07-09 11:40:51 -0400 |
commit | b64a0d49db7e8e2963a8f867c8fdfd8d72b197ac (patch) | |
tree | f79a03570da7a19a2d16f4e682b3bf458b38d2c0 | |
parent | 3c1bfee634bf934b1079cb219a5241ea74fa1692 (diff) |
deinline
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | armv7m.c | 85 | ||||
-rw-r--r-- | armv7m.h | 88 | ||||
-rw-r--r-- | testme.o | bin | 7524 -> 0 bytes |
4 files changed, 103 insertions, 90 deletions
@@ -26,16 +26,16 @@ all: test10-kern.bin all: test11-kern.bin all: test12-kern.bin -test1-kern.elf: cortexm.ld common.ld setup.o init-m.o testme.o test1.o -test3-kern.elf: cortexm.ld common.ld setup.o init-m.o test3.o -test4-kern.elf: cortexm.ld common.ld setup.o init-m.o test4.o -test5-kern.elf: cortexm.ld common.ld setup.o init-m.o test5.o -test6-kern.elf: cortexm.ld common.ld setup.o init-m.o test6.o -test7-kern.elf: cortexm.ld common.ld setup.o init-m.o test7.o -test8-kern.elf: cortexm.ld common.ld setup.o init-m.o test8.o inst_skip.o -test9-kern.elf: cortexm.ld common.ld setup.o init-m-test9.o testme.o test9.o -test10-kern.elf:cortexm.ld common.ld setup.o init-m.o testme.o test10.o -test11-kern.elf:cortexm.ld common.ld setup.o init-m.o test11-buserr.o inst_skip.o +test1-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test1.o +test3-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test3.o +test4-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test4.o +test5-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test5.o +test6-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test6.o +test7-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test7.o +test8-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m.o test8.o inst_skip.o +test9-kern.elf: cortexm.ld common.ld setup.o armv7m.o init-m-test9.o testme.o test9.o +test10-kern.elf:cortexm.ld common.ld setup.o armv7m.o init-m.o testme.o test10.o +test11-kern.elf:cortexm.ld common.ld setup.o armv7m.o init-m.o test11-buserr.o inst_skip.o test12-kern.elf:cortexm.ld common.ld setup.o test12.o clean: diff --git a/armv7m.c b/armv7m.c new file mode 100644 index 0000000..60b243a --- /dev/null +++ b/armv7m.c @@ -0,0 +1,85 @@ + +#include "armv7m.h" + + +void putc(char c) +{ + if(c=='\n') + putc('\r'); + loop_until(32, UART_FLAG, 0x20, ==, 0); /* wait for TX FIFO not full */ + out8(UART_DATA, c); +} + +void puts(const char *s) +{ + char c; + while((c=*s++)!='\0') + putc(c); +} + +void flush(void) +{ + /* wait for TX FIFO empty */ + loop_until(32, UART_FLAG, 0x80, ==, 0x80); +} + + +void puthex(uint32_t v) +{ + unsigned i; + for(i=0; i<8; i++, v<<=4) { + putc(hexchars[v>>28]); + } +} + +void putdec(uint32_t v) +{ + unsigned out=0; + uint32_t base=1000000000; + for(;base; base/=10) { + uint32_t d=v/base; + if(!d && !out) continue; + putc('0'+d); + v%=base; + out=1; + } + if(!out) putc('0'); +} + +unsigned log2_ceil(uint32_t v) +{ + unsigned r=0, c=0; + while(v) { + c += v&1; + v >>= 1; + r++; + } + if(c>1) r++; + return r; +} + +void set_mpu(unsigned region, uint32_t base, uint32_t size, + uint32_t attrs) +{ + unsigned sbits = log2_ceil(size<32 ? 32 : size)-2; + uint32_t rbase = base&(~0x1f); + uint32_t rattr = (attrs&~0xffff) | (sbits<<1) | 1; + puts("set_mpu "); + putc('0'+region); + putc(' '); + puthex(rbase); + putc(' '); + puthex(rattr); + putc('\n'); + out32((void*)0xe000ed98, region&0xff); /* RNR */ + out32((void*)0xe000eda0, 0); /* Disable */ + out32((void*)0xe000ed9c, rbase); + out32((void*)0xe000eda0, rattr); +} + +void enable_mpu(unsigned usrena, unsigned privena, unsigned hfnmiena) +{ + uint32_t val = (usrena ? 1 : 0) | (hfnmiena ? 2 : 0) | (privena ? 0 : 4); + out32((void*)0xe000ed94, val); + __asm__ volatile ("dsb\nisb" :::); +} @@ -88,55 +88,17 @@ uint32_t in32(void *addr) void abort(void) __attribute__((noreturn)); -static inline -void putc(char c) -{ - if(c=='\n') - putc('\r'); - loop_until(32, UART_FLAG, 0x20, ==, 0); /* wait for TX FIFO not full */ - out8(UART_DATA, c); -} +void putc(char c); -static inline -void puts(const char *s) -{ - char c; - while((c=*s++)!='\0') - putc(c); -} +void puts(const char *s); -static inline -void flush(void) -{ - /* wait for TX FIFO empty */ - loop_until(32, UART_FLAG, 0x80, ==, 0x80); -} +void flush(void); extern const char hexchars[16]; -static inline -void puthex(uint32_t v) -{ - unsigned i; - for(i=0; i<8; i++, v<<=4) { - putc(hexchars[v>>28]); - } -} +void puthex(uint32_t v); -static inline -void putdec(uint32_t v) -{ - unsigned out=0; - uint32_t base=1000000000; - for(;base; base/=10) { - uint32_t d=v/base; - if(!d && !out) continue; - putc('0'+d); - v%=base; - out=1; - } - if(!out) putc('0'); -} +void putdec(uint32_t v); #define CPSIE(MASK) __asm__ volatile ("cpsie " #MASK ::: "memory") #define CPSID(MASK) __asm__ volatile ("cpsid " #MASK ::: "memory") @@ -168,46 +130,12 @@ void basepri(uint8_t prio) * log2_ceil(32) -> 6 * log2_ceil(33) -> 7 */ -static inline -unsigned log2_ceil(uint32_t v) -{ - unsigned r=0, c=0; - while(v) { - c += v&1; - v >>= 1; - r++; - } - if(c>1) r++; - return r; -} +unsigned log2_ceil(uint32_t v); -static inline void set_mpu(unsigned region, uint32_t base, uint32_t size, - uint32_t attrs) -{ - unsigned sbits = log2_ceil(size<32 ? 32 : size)-2; - uint32_t rbase = base&(~0x1f); - uint32_t rattr = (attrs&~0xffff) | (sbits<<1) | 1; - puts("set_mpu "); - putc('0'+region); - putc(' '); - puthex(rbase); - putc(' '); - puthex(rattr); - putc('\n'); - out32((void*)0xe000ed98, region&0xff); /* RNR */ - out32((void*)0xe000eda0, 0); /* Disable */ - out32((void*)0xe000ed9c, rbase); - out32((void*)0xe000eda0, rattr); -} + uint32_t attrs); -static inline -void enable_mpu(unsigned usrena, unsigned privena, unsigned hfnmiena) -{ - uint32_t val = (usrena ? 1 : 0) | (hfnmiena ? 2 : 0) | (privena ? 0 : 4); - out32((void*)0xe000ed94, val); - __asm__ volatile ("dsb\nisb" :::); -} +void enable_mpu(unsigned usrena, unsigned privena, unsigned hfnmiena); uint32_t* get_src_stack(uint32_t *sp); void inst_skip(uint32_t *sp); diff --git a/testme.o b/testme.o Binary files differdeleted file mode 100644 index 7f2fac4..0000000 --- a/testme.o +++ /dev/null |