OpenCores
URL https://opencores.org/ocsvn/s80186/s80186/trunk

Subversion Repositories s80186

[/] [s80186/] [trunk/] [bios/] [entry.S] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
// Copyright Jamie Iles, 2017
2
//
3
// This file is part of s80x86.
4
//
5
// s80x86 is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// s80x86 is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
// GNU General Public License for more details.
14
//
15
// You should have received a copy of the GNU General Public License
16
// along with s80x86.  If not, see .
17
 
18
.code16
19
 
20
.section .reset.text, "ax"
21
.globl _reset
22
_reset:
23
    ljmp $0xf000, $_start
24
 
25
.section .model, "a"
26
    .byte 0xff
27
    .byte 0x00
28
 
29
.section .entry.text, "ax"
30
.globl _start
31
_start:
32
    // Wait for SDRAM to initialize
33
    mov $0xfffc, %dx
34
    mov $1, %ax
35
1:
36
    in (%dx), %ax
37
    cmp $0x1, %ax
38
    jne 1b
39
 
40
    mov %cs, %ax
41
    mov %ax, %ss
42
    mov %ax, %ds
43
    mov %ax, %es
44
 
45
    // Clear bss
46
    mov $bss_start, %di
47
    mov $bss_end, %cx
48
    sub $bss_start, %cx
49
    mov $0, %al
50
    rep stosb
51
 
52
    // Initialize rw data
53
    mov $data_start, %di
54
    mov $data_end, %cx
55
    sub $data_start, %cx
56
    mov $_data_load, %si
57
    rep movsb
58
 
59
    movw $stack_start, %sp
60
 
61
    jmp root
62
 
63
.section .data
64
bios_ss:
65
    .word 0xf000
66
bios_sp:
67
    .word stack_start
68
 
69
.section .bss
70
saved_ss:
71
    .word 0
72
saved_sp:
73
    .word 0
74
 
75
.section .text, "ax"
76
.globl irq_entry
77
irq_entry:
78
    // Save current stack pointer, load BIOS stack
79
    mov %ss, %cs:saved_ss
80
    mov %sp, %cs:saved_sp
81
    mov %cs:bios_ss, %ss
82
    mov %cs:bios_sp, %sp
83
 
84
    // Save registers, setup stack frame
85
    push %ds
86
    pusha
87
    mov %sp, %bp
88
    push %bp
89
 
90
    // Load flags from iret frame, store in callregs
91
    mov %cs:saved_ss, %ds
92
    mov %cs:saved_sp, %bx
93
    mov 0(%bx), %ax
94
    mov 6(%bx), %bx
95
    mov %bx, 18(%bp)
96
 
97
    // Use SS as DS inside the BIOS for stack-local variables that are passed
98
    // by address
99
    mov %ss, %bp
100
    mov %bp, %ds
101
 
102
    call *%ax
103
    // Discard regs pointer parameter
104
    add $2, %sp
105
    mov %sp, %bp
106
 
107
    // Write possibly updated flags to the iret frame
108
    mov 18(%bp), %ax
109
    mov %cs:saved_ss, %ds
110
    mov %cs:saved_sp, %bx
111
    mov %ax, 6(%bx)
112
 
113
    // Restore all regs apart from flags - the iret frame has been updated
114
    // already
115
    popa
116
    pop %ds
117
 
118
    // Restore the callers stack
119
    mov %cs:saved_ss, %ss
120
    mov %cs:saved_sp, %sp
121
    add $2, %sp
122
 
123
    iret
124
 
125
.macro int_handler vector, function
126
 
127
.pushsection .rodata.vectors
128
    .align 4
129
    .word \vector
130
    .word \function
131
.popsection
132
 
133
.endm
134
 
135
stub_irq:
136
    iret
137
 
138
int_handler 0x1c, stub_irq
139
 
140
timer_irq:
141
    cli
142
    push %ds
143
    push %bx
144
    push %ax
145
    push %dx
146
 
147
    movw $0x40, %bx
148
    mov %bx, %ds
149
    movw $0x6c, %bx
150
    add $1, %ds:0(%bx)
151
    adc $0, %ds:2(%bx)
152
 
153
    int $0x1c
154
 
155
    movb $0x20, %al
156
    outb %al, $0x20
157
 
158
    pop %dx
159
    pop %ax
160
    pop %bx
161
    pop %ds
162
 
163
    iret
164
 
165
int_handler 0x08, timer_irq
166
 
167
.pushsection ".bios_date", "a"
168
    .ascii BIOS_BUILD_DATE
169
.popsection

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.