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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [bios/] [bios.c] - 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 <http://www.gnu.org/licenses/>.
17
 
18
#include "bda.h"
19
#include "bios.h"
20
#include "display.h"
21
#include "sd.h"
22
#include "io.h"
23
#include "serial.h"
24
#include "keyboard.h"
25
#include "timer.h"
26
#include "utils.h"
27
 
28
#define INT11_DISKS_PRESENT (1 << 0)
29
#define INT11_CGA_ADAPTOR (2 << 4)
30
 
31
static void equipment_check(struct callregs *regs)
32
{
33
    regs->ax.x = INT11_CGA_ADAPTOR;
34
}
35
VECTOR(0x11, equipment_check);
36
 
37
static void serial_services(struct callregs *regs)
38
{
39
    regs->flags |= CF;
40
}
41
VECTOR(0x14, serial_services);
42
 
43
static void system_services(struct callregs *regs)
44
{
45
    regs->flags |= CF;
46
    regs->ax.h = 0x86;
47
}
48
VECTOR(0x15, system_services);
49
 
50
// Printer services
51
static void printer_services(struct callregs *regs)
52
{
53
    regs->flags |= CF;
54
}
55
VECTOR(0x17, printer_services);
56
 
57
static void basic_services(struct callregs __unused *regs)
58
{
59
    panic("No basic services\n");
60
}
61
VECTOR(0x18, basic_services);
62
 
63
static void boostrap_loader(struct callregs __unused *regs)
64
{
65
    asm volatile("jmp $0xffff, $0x0");
66
}
67
VECTOR(0x19, boostrap_loader);
68
 
69
static void conventional_memory(struct callregs *regs)
70
{
71
    regs->ax.x = 640;
72
}
73
VECTOR(0x12, conventional_memory);
74
 
75
static void break_handler(struct callregs __unused *regs)
76
{
77
    panic("No break handler\n");
78
}
79
VECTOR(0x1b, break_handler);
80
 
81
static void set_vector(int vector, void *handler)
82
{
83
    writew(0, vector * 4, (unsigned short)handler);
84
    writew(0, vector * 4 + 2, get_cs());
85
}
86
 
87
static unsigned char vpt[] = {80, 25, 8, 4000 & 0xff, 4000 >> 8};
88
 
89
static void install_vectors(void)
90
{
91
    struct vector {
92
        unsigned short num;
93
        void *handler;
94
    };
95
 
96
    extern struct vector vectors_start;
97
    extern struct vector vectors_end;
98
 
99
    struct vector *v;
100
 
101
    for (v = &vectors_start; v < &vectors_end; ++v)
102
        set_vector(v->num, v->handler);
103
 
104
    set_vector(0x1d, vpt);
105
}
106
 
107
static void bda_init(void)
108
{
109
    int i;
110
 
111
    for (i = 0; i < 256; ++i)
112
        writeb(0x40, i, 0);
113
}
114
 
115
#define PIC_COMMAND 0x20
116
#define PIC_DATA 0x21
117
 
118
#define PIC_ICW1_INIT (1 << 4)
119
#define PIC_ICW1_SINGLE (1 << 1)
120
#define PIC_ICW1_ICW4 (1 << 0)
121
#define PIC_ICW4_8086 (1 << 0)
122
 
123
static void irq_init(void)
124
{
125
    outb(PIC_COMMAND, PIC_ICW1_INIT | PIC_ICW1_SINGLE | PIC_ICW1_ICW4);
126
    outb(PIC_DATA, 0x08);
127
    outb(PIC_DATA, PIC_ICW4_8086);
128
    // All IRQs initially masked.
129
    outb(PIC_DATA, ~0);
130
}
131
 
132
void irq_enable(int irq_num)
133
{
134
    outb(PIC_DATA, inb(PIC_DATA) & ~(1 << irq_num));
135
}
136
 
137
void irq_ack(void)
138
{
139
    outb(0x20, 0x20);
140
}
141
 
142
void root(void)
143
{
144
    install_vectors();
145
 
146
    irq_init();
147
    bda_init();
148
    display_init();
149
 
150
    putstr("s80x86 BIOS, (C) Jamie Iles, " __DATE__ " " __TIME__ "\n");
151
    putstr("Platform: " __PLATFORM__ "\n");
152
    putstr("Build: " __BUILD__ "\n");
153
    putstr("\n");
154
 
155
    keyboard_init();
156
    init_timer();
157
 
158
    sd_init();
159
    sd_boot();
160
}

powered by: WebSVN 2.1.0

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