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

Last change on this file since 6099cac was 8325447, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Removed _ prefix.

  • Property mode set to 100644
File size: 3.2 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 = 0x18 | bss base
27p_blen = 0x1C | 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_: movea.l #0,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 #0x2000 | "Die, sucker!"
67 bra hstop
68
69 .page
70
71| panic -- hard halt for fatal errors
72| ----- --------------------------
73panic: 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 #0x2700 | 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
87brk: 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 #0x100,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: .asciz " returned from Croot() "
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
123errno: .ds.w 1 | System error number
124
125 .end
Note: See TracBrowser for help on using the repository browser.