increasing usage of p<>, minor bugs fixed [code still broken]
[quarnos.git] / arch / x86 / isa.cpp
blobe92a992eb33c0cd57ad3ee07e62159fb8e9fdf40
1 /* Quarn OS
3 * ISA bus
5 * Copyright (C) 2008-2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "general.h"
24 #include "lowlevel.h"
26 #include "manes/manec.h"
27 #include "resources/unknown.h"
29 #include "resources/device.h"
30 #include "resources/keybscr.h"
31 #include "resources/speaker.h"
32 #include "resources/fdc.h"
34 #include "resources/isa.h"
36 using namespace arch;
37 using namespace manes;
38 using namespace resources;
40 int isa::scan_bus() {
41 int dev_count = 0;
43 /* Keyboard */
44 isa_did *tty0_addr = new isa_did(this);
45 device *tty = new_component((type_name)"keybscr")->get<device>();
46 // __asm__("cli\nhlt"::"a"(tty));
47 if (tty->init_device(tty0_addr))
48 dev_count++;
49 /* Get number of installed rs232 ports */
50 u8 *p_rs232_count = (u8*)0x411;
51 u8 rs232_count = *p_rs232_count & 7;
53 /* COM1 (RS232) serial port */
54 if (rs232_count > 0) {
55 u16 *com1_base_port = (u16*)0x400;
56 p<isa_did> com1_addr = new isa_did(this);
57 com1_addr->irq = 0x24;
58 com1_addr->ioport_base = (int)*com1_base_port;
60 /* if (manec::get()->get<type>("/type,rs232")) {
61 component *c = new_component((manes::type_name)"rs232");
62 c->get<device>()->init_device(com1_addr);
63 } else {*/
64 component *c = new_component((manes::type_name)"unknown");
65 c->get<unknown>()->init_device(com1_addr.cast<did>());
66 // }
68 dev_count++;
71 /* COM2 (RS232) serial port */
72 if (rs232_count > 1) {
73 u16 *com2_base_port = (u16*)0x402;
74 p<isa_did> com2_addr = new isa_did(this);
75 com2_addr->irq = 0x23 ;
76 com2_addr->ioport_base = (int)*com2_base_port;
78 component *c = new_component((manes::type_name)"unknown");
79 c->get<unknown>()->init_device(com2_addr.cast<did>());
81 dev_count++;
84 /* Speaker */
85 isa_did *speak_addr = new isa_did(this);
86 speaker *speak = new_component((type_name)"speaker")->get<speaker>();
87 speak->init_device(speak_addr);
88 dev_count++;
90 /* RTC */
92 /* Check if 1.44MB floppy disks drive exist (info stored int cmos) */
93 outb(0x70, 0x10);
94 u8 fd_drives = inb(0x71);
96 /* FDC 1 (A:) */
97 if ((fd_drives >> 4) == 4) {
98 isa_did *fdc_addr = new isa_did(this);
99 fdc_addr->irq = 0x26;
100 fdc_addr->ioport_base = 0x3f0;
101 fdc_addr->dma_channel = 2;
102 fdc *ofdc = manec::get()->new_component((type_name)"fdc")->get<fdc>();
103 ofdc->init_device(fdc_addr);
104 dev_count++;
107 /* FDC 2 (B:) */
108 if ((fd_drives & 0xF) == 4) {
109 /* not ready yet
110 isa_address fdc_addr;
111 fdc_addr.irq = 6;
112 fdc_addr.ioport_base = 0x370;
113 fdc_addr.dma_channel = 2;
114 fdc *ofdc = (fdc*)rman->new_object("fdc");
115 ofdc->init_device(fdc_addr);*/
116 dev_count++;
119 return dev_count;