init
This commit is contained in:
commit
d1ac414c5e
34 changed files with 64721 additions and 0 deletions
105
runtime/crt0.s
Normal file
105
runtime/crt0.s
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
STACK_AREA equ $1ff000
|
||||
ROM equ $000000
|
||||
RAM equ $100000
|
||||
|
||||
section VECTORS
|
||||
|
||||
vector_table:
|
||||
dc.l STACK_AREA
|
||||
dc.l init
|
||||
dc.l unhandled_exception ; 2: bus error
|
||||
dc.l unhandled_exception ; 3: address error
|
||||
dc.l unhandled_exception ; 4: illegal instruction
|
||||
dc.l unhandled_exception ; 5: zero divide
|
||||
dc.l unhandled_exception ; 6: chk
|
||||
dc.l unhandled_exception ; 7: trapv
|
||||
dc.l unhandled_exception ; 8: privilege violation
|
||||
dc.l unhandled_exception ; 9: trace
|
||||
dc.l unhandled_exception ; 10: 1010
|
||||
dc.l unhandled_exception ; 11: 1111
|
||||
dc.l unhandled_exception ; 12: -
|
||||
dc.l unhandled_exception ; 13: -
|
||||
dc.l unhandled_exception ; 14: -
|
||||
dc.l unhandled_exception ; 15: uninitialized interrupt
|
||||
dc.l unhandled_exception ; 16: -
|
||||
dc.l unhandled_exception ; 17: -
|
||||
dc.l unhandled_exception ; 18: -
|
||||
dc.l unhandled_exception ; 19: -
|
||||
dc.l unhandled_exception ; 20: -
|
||||
dc.l unhandled_exception ; 21: -
|
||||
dc.l unhandled_exception ; 22: -
|
||||
dc.l unhandled_exception ; 23: -
|
||||
dc.l unhandled_exception ; 24: spurious interrupt
|
||||
dc.l timer_irq ; 25: l1 irq
|
||||
dc.l unhandled_exception ; 26: l2 irq
|
||||
dc.l unhandled_exception ; 27: l3 irq
|
||||
dc.l unhandled_exception ; 28: l4 irq
|
||||
dc.l unhandled_exception ; 29: l5 irq
|
||||
dc.l unhandled_exception ; 30: l6 irq
|
||||
dc.l unhandled_exception ; 31: l7 irq
|
||||
dc.l unhandled_exception ; 32: trap 0
|
||||
dc.l unhandled_exception ; 33: trap 1
|
||||
dc.l unhandled_exception ; 34: trap 2
|
||||
dc.l unhandled_exception ; 35: trap 3
|
||||
dc.l unhandled_exception ; 36: trap 4
|
||||
dc.l unhandled_exception ; 37: trap 5
|
||||
dc.l unhandled_exception ; 38: trap 6
|
||||
dc.l unhandled_exception ; 39: trap 7
|
||||
dc.l unhandled_exception ; 40: trap 8
|
||||
dc.l unhandled_exception ; 41: trap 9
|
||||
dc.l unhandled_exception ; 42: trap 10
|
||||
dc.l unhandled_exception ; 43: trap 11
|
||||
dc.l unhandled_exception ; 44: trap 12
|
||||
dc.l unhandled_exception ; 45: trap 13
|
||||
dc.l unhandled_exception ; 46: trap 14
|
||||
dc.l unhandled_exception ; 47: trap 15
|
||||
|
||||
section CODE
|
||||
xref _main
|
||||
xref _tick
|
||||
xref _DATA_LOAD
|
||||
xref _DATA_START
|
||||
xref _DATA_END
|
||||
xref _BSS_START
|
||||
xref _BSS_END
|
||||
|
||||
init:
|
||||
move.w #$2700,sr
|
||||
|
||||
lea _DATA_START,a0
|
||||
lea _DATA_END,a1
|
||||
lea _DATA_LOAD,a2
|
||||
jsr copy
|
||||
|
||||
lea _BSS_START,a0
|
||||
lea _BSS_END,a1
|
||||
jsr clear
|
||||
|
||||
jsr _main
|
||||
|
||||
move.w #$2000,sr
|
||||
|
||||
bra.s *
|
||||
|
||||
copy:
|
||||
cmpa.l a1,a0
|
||||
bhs.s .done
|
||||
move.l (a2)+,(a0)+
|
||||
bra.s copy
|
||||
.done:
|
||||
rts
|
||||
|
||||
clear:
|
||||
cmpa.l a1,a0
|
||||
bhs.s .done
|
||||
clr.l (a0)+
|
||||
bra.s clear
|
||||
.done:
|
||||
rts
|
||||
|
||||
unhandled_exception:
|
||||
bra.s *
|
||||
|
||||
timer_irq:
|
||||
jsr _tick
|
||||
rte
|
||||
194
runtime/libc.s
Normal file
194
runtime/libc.s
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
section CODE
|
||||
public _memset
|
||||
|
||||
;;
|
||||
;; string.h
|
||||
;;
|
||||
|
||||
; memset:
|
||||
; 4(sp): dst
|
||||
; 8(sp): value
|
||||
; 12(sp): int
|
||||
_memset:
|
||||
move.l 4(sp),a0
|
||||
move.l 8(sp),d0
|
||||
move.l 12(sp),d1
|
||||
.loop:
|
||||
cmpi #0,d1
|
||||
beq.s .done
|
||||
move.b d0,(a0)+
|
||||
sub #1,d1
|
||||
bra.s .loop
|
||||
.done:
|
||||
rts
|
||||
|
||||
; memcpy:
|
||||
; 4(sp): dst
|
||||
; 8(sp): src
|
||||
; 12(sp): int
|
||||
_memcpy:
|
||||
move.l 4(sp),a0
|
||||
move.l 8(sp),a1
|
||||
move.l 12(sp),d1
|
||||
.loop:
|
||||
cmpi #0,d1
|
||||
beq.s .done
|
||||
move.b (a1)+,(a0)+
|
||||
sub #1,d1
|
||||
bra.s .loop
|
||||
.done:
|
||||
rts
|
||||
|
||||
|
||||
;;
|
||||
;; 32-bit div/mod: taken from vc.lib
|
||||
;;
|
||||
|
||||
public __divu
|
||||
public __divs
|
||||
public __modu
|
||||
public __mods
|
||||
public __ldivs
|
||||
public __ldivu
|
||||
public __lmods
|
||||
public __lmodu
|
||||
|
||||
__lmods:
|
||||
movem.l 4(sp),d0/d1
|
||||
__mods:
|
||||
tst.l d1
|
||||
bmi 1$
|
||||
tst.l d0
|
||||
bmi 2$
|
||||
bsr __divu
|
||||
move.l d1,d0
|
||||
rts
|
||||
1$:
|
||||
neg.l d1
|
||||
tst.l d0
|
||||
bmi 3$
|
||||
bsr __divu
|
||||
move.l d1,d0
|
||||
rts
|
||||
2$:
|
||||
neg.l d0
|
||||
bsr __divu
|
||||
neg.l d1
|
||||
move.l d1,d0
|
||||
rts
|
||||
3$:
|
||||
neg.l d0
|
||||
bsr __divu
|
||||
neg.l d1
|
||||
move.l d1,d0
|
||||
rts
|
||||
|
||||
|
||||
__lmodu:
|
||||
movem.l 4(sp),d0/d1
|
||||
__modu:
|
||||
bsr __divu
|
||||
move.l d1,d0
|
||||
rts
|
||||
|
||||
|
||||
__ldivs:
|
||||
movem.l 4(sp),d0/d1
|
||||
__divs:
|
||||
tst.l d0
|
||||
bpl 2$
|
||||
neg.l d0
|
||||
tst.l d1
|
||||
bpl 1$
|
||||
neg.l d1
|
||||
bsr __divu
|
||||
neg.l d1
|
||||
rts
|
||||
1$:
|
||||
bsr __divu
|
||||
neg.l d0
|
||||
neg.l d1
|
||||
rts
|
||||
2$:
|
||||
tst.l d1
|
||||
bpl __divu
|
||||
neg.l d1
|
||||
bsr __divu
|
||||
neg.l d0
|
||||
rts
|
||||
|
||||
|
||||
__ldivu:
|
||||
movem.l 4(sp),d0/d1
|
||||
__divu:
|
||||
move.l d2,-(sp)
|
||||
swap d1
|
||||
move.w d1,d2
|
||||
bne 2$
|
||||
swap d0
|
||||
swap d1
|
||||
swap d2
|
||||
move.w d0,d2
|
||||
beq 1$
|
||||
divu d1,d2
|
||||
move.w d2,d0
|
||||
1$:
|
||||
swap d0
|
||||
move.w d0,d2
|
||||
divu d1,d2
|
||||
move.w d2,d0
|
||||
swap d2
|
||||
move.w d2,d1
|
||||
move.l (sp)+,d2
|
||||
rts
|
||||
2$:
|
||||
move.l d3,-(sp)
|
||||
moveq #16,d3
|
||||
cmp.w #$80,d1
|
||||
bhs 3$
|
||||
rol.l #8,d1
|
||||
subq.w #8,d3
|
||||
3$:
|
||||
cmp.w #$800,d1
|
||||
bhs 4$
|
||||
rol.l #4,d1
|
||||
subq.w #4,d3
|
||||
4$:
|
||||
cmp.w #$2000,d1
|
||||
bhs 5$
|
||||
rol.l #2,d1
|
||||
subq.w #2,d3
|
||||
5$:
|
||||
tst.w d1
|
||||
bmi 6$
|
||||
rol.l #1,d1
|
||||
subq.w #1,d3
|
||||
6$:
|
||||
move.w d0,d2
|
||||
lsr.l d3,d0
|
||||
swap d2
|
||||
clr.w d2
|
||||
lsr.l d3,d2
|
||||
swap d3
|
||||
divu d1,d0
|
||||
move.w d0,d3
|
||||
move.w d2,d0
|
||||
move.w d3,d2
|
||||
swap d1
|
||||
mulu d1,d2
|
||||
sub.l d2,d0
|
||||
bhs 8$
|
||||
subq.w #1,d3
|
||||
add.l d1,d0
|
||||
7$:
|
||||
bhs.s 7$
|
||||
8$:
|
||||
moveq #0,d1
|
||||
move.w d3,d1
|
||||
swap d3
|
||||
rol.l d3,d0
|
||||
swap d0
|
||||
exg d0,d1
|
||||
move.l (sp)+,d3
|
||||
move.l (sp)+,d2
|
||||
rts
|
||||
29
runtime/linker.ld
Normal file
29
runtime/linker.ld
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
MEMORY {
|
||||
ROM : ORIGIN = 0x000000, LENGTH = 0x020000
|
||||
RAM : ORIGIN = 0x100000, LENGTH = 0x100000
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
VECTORS : {
|
||||
*(VECTORS);
|
||||
} > ROM;
|
||||
|
||||
CODE : {
|
||||
*(CODE);
|
||||
} > ROM;
|
||||
|
||||
DATA : {
|
||||
_DATA_START = .;
|
||||
*(DATA);
|
||||
. = ALIGN(4);
|
||||
_DATA_END = .;
|
||||
} > RAM AT>ROM;
|
||||
_DATA_LOAD = LOADADDR(DATA);
|
||||
|
||||
BSS (NOLOAD) : {
|
||||
_BSS_START = .;
|
||||
*(BSS);
|
||||
. = ALIGN(4);
|
||||
_BSS_END = .;
|
||||
} > RAM;
|
||||
}
|
||||
20
runtime/stdarg.h
Normal file
20
runtime/stdarg.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef __STDARG_H__
|
||||
#define __STDARG_H__
|
||||
|
||||
typedef unsigned char *va_list;
|
||||
|
||||
#define __va_align(type) (__alignof(type)>=4?__alignof(type):4)
|
||||
|
||||
#define __va_do_align(vl,type) ((vl)=(char *)((((unsigned int)(vl))+__va_align(type)-1)/__va_align(type)*__va_align(type)))
|
||||
|
||||
#define __va_mem(vl,type) (__va_do_align((vl),type),(vl)+=sizeof(type),((type*)(vl))[-1])
|
||||
|
||||
#define va_start(ap, lastarg) ((ap)=(va_list)(&lastarg+1))
|
||||
|
||||
#define va_arg(vl,type) __va_mem(vl,type)
|
||||
|
||||
#define va_end(vl) ((vl)=0)
|
||||
|
||||
#define va_copy(new,old) ((new)=(old))
|
||||
|
||||
#endif
|
||||
6
runtime/stddef.h
Normal file
6
runtime/stddef.h
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef __STDDEF_H__
|
||||
#define __STDDEF_H__
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#endif
|
||||
9
runtime/string.h
Normal file
9
runtime/string.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef __STRING_H__
|
||||
#define __STRING_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void memset(void* dst, int data, int sz);
|
||||
void memcpy(void* dst, void* src, int sz);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue