source: buchla-68k/prolog/fsmain.s@ c65a0e2

Last change on this file since c65a0e2 was 109c83b, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Compiled full ROM in Hatari.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1* ------------------------------------------------------------------------------
2* fsmain.s -- startup code for the Buchla 700 standalone C runtime library
3* Version 3 -- 1987-06-29 -- D.N. Lynx Crowe
4*
5* This code clears 'bss' space, sets up some global variables,
6* and calls Croot(), which sets up the file system and calls main().
7*
8* This routine should be entered with the address of the basepage
9* as its parameter.
10* ------------------------------------------------------------------------------
11 .text
12*
13 .xdef start_
14*
15 .xref _Croot
16*
17 .xdef _panic
18 .xdef _brk
19*
20 .xdef __heap
21 .xdef __break
22 .xdef __pmesg
23*
24 .xdef _errno
25*
26p_bbase .equ $18 * bss base
27p_blen .equ $1C * bss length
28*
29 .page
30*
31* start_ -- Initial entry point -- Must be first object file in link statement
32* ------ ------------------------------------------------------------------
33*
34* WARNING: Hazardous assumptions
35*
36* We assume that:
37*
38* the system has set the stack pointer for us.
39* the system passed us a pointer to a valid basepage.
40* the stack is above the heap.
41* BSS is located in RAM.
42*
43* If any of these assumptions is in error, we're in for serious trouble.
44*
45start_: clr.l a6 * Clear frame pointer
46 movea.l 4(a7),a1 * Set pointer to base page
47 movea.l p_bbase(a1),a0 * Setup to clear bss space
48*
49start1: clr.w (a0)+ * Clear a word
50 cmpa.l a0,a7 * See if we're done
51 bne start1 * Loop if not done yet
52*
53 move.l p_bbase(a1),d0 * Calculate break address
54 add.l p_blen(a1),d0 * ...
55 move.l d0,__break * Set initial break
56 move.l d0,__heap * Set heap start
57*
58 move.l #0,-(a7) * Pass NULL to Croot (no command line)
59 jsr _Croot * call Croot() routine
60 addq.l #4,a7 * ...
61*
62 move.l #pmsg1,-(a7) * panic(pmsg1);
63 jsr _panic * ...
64 addq.l #4,a7 * ...
65*
66hstop: stop #$2000 * "Die, sucker!"
67 bra hstop
68*
69 .page
70*
71* _panic -- hard halt for fatal errors
72* ------ --------------------------
73_panic: movea.l 4(a7),a0 * Save panic message address
74 move.l a0,__pmesg * ...
75*
76 trap #15 * Invoke ROMP (we hope ...)
77*
78pstop: stop #$2700 * HARD HALT
79 bra pstop
80*
81 .page
82*
83* _brk -- set break value
84* ---- ---------------
85* WARNING: This only works if the stack is above the heap.
86*
87_brk: cmpa.l __break,a7 * compare current break with stack
88 bcs pstop * actual stack overflow!
89*
90 movea.l 4(sp),a0 * get new break
91 move.l a0,d0 * compare with current stack,
92 adda.l #$100,a0 * ... including 256-byte slop factor
93 cmpa.l a0,a7 * if (sp < a0+256)
94 bcs badbrk * bad break;
95*
96 move.l d0,__break * OK break: save the break
97 clr.l d0 * Set OK return
98 rts * return
99*
100badbrk: moveq.l #-1,d0 * Load return reg
101 rts * Return
102*
103 .page
104*
105*************************************************************************
106* Data Area *
107*************************************************************************
108*
109 .data
110*
111pmsg1: dc.b ' returned from Croot() ',0
112*
113*************************************************************************
114* BSS Area *
115*************************************************************************
116*
117 .bss
118 .even
119*
120__pmesg: ds.l 1 * panic() message string address
121__heap: ds.l 1 * Heap start (initial break)
122__break: ds.l 1 * Current break location
123_errno: ds.w 1 * System error number
124*
125 .end
Note: See TracBrowser for help on using the repository browser.