started memory allocator, allocated final stack, added move_init_stack
[lugburz] / src / amiga / startup.s
1 | vi:filetype=gas68k:
2         .include "hwregs.inc"
3
4         .global move_init_stack
5         .global halt_cpu
6         .global panic
7         .extern main
8
9         .section .startup,"a"
10
11         | enter supervisor mode (assumes VBR=0)
12         move.l #super, 0x80
13         trap #0
14 super:
15         or.w #0x0700, %sr       | disable interrupts
16
17         | zero the .bss section
18         move.l #_bss_start, %a0
19         move.l #_bss_end, %a1
20         cmp.l %a0, %a1
21         beq.s 1f        | skip zeroing if the section is empty
22 0:      clr.b (%a0)+
23         cmp.l %a0, %a1
24         bne.s 0b
25 1:
26         | setup a temporary stack
27         move.l #0x40000, %sp
28         and.w #0xf8ff, %sr      | enable interrupts
29
30         | initialize early exception handlers
31         jsr exc_init
32
33         jsr main
34 0:      bra.b 0b
35
36 move_init_stack:
37         move.l #0x40000, %a1    | a1 <- old stack
38         move.l 4(%sp), %a0      | a0 <- new stack
39 0:      move.l -(%a1), %d0
40         move.l %d0, -(%a0)
41         cmp.l %sp, %a1
42         bhi.s 0b
43         move.l %a0, %sp
44         rts
45
46 halt_cpu:
47         stop #0x2700
48
49 panic:
50         or.w #0x0700, %sr
51         move.l #0xdff000, %a0
52         move.w #0x7fff, DMACON(%a0)     | clear all DMACON bits
53         move.w #0xf00, COLOR0(%a0)
54
55         pea str_panic
56         jsr printf
57         add.l #8, %sp   | also get rid of the reutrn address
58
59         jsr printf
60         bra halt_cpu
61
62 str_panic: .asciz "Kernel panic!\n~~~~~~~~~~~~~\n"