Skip to content

Commit c9e380c

Browse files
fixes for booting in vmware
1 parent 0f2bb69 commit c9e380c

6 files changed

Lines changed: 187 additions & 149 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake-build-debug/*
12
build
23
.iso
34
os/modules

src/ahci.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ void port_rebase(ahci_hba_port_t* port, int portno)
7777
// Command list maxim size = 32*32 = 1K per port
7878
port->clb = (kmalloc_low(0x100000) & 0xFFFFFFFFFFFFF000) + 0x1000;
7979
port->clbu = 0;
80-
kprintf("Alloc: %08x\n", port->clb);
80+
dprintf("Alloc: %08x\n", port->clb);
8181
memset((void*)((uint64_t)port->clb), 0, 1024);
82-
kprintf("After memset\n");
82+
dprintf("After memset\n");
8383

8484
// FIS offset: 32K+256*portno
8585
// FIS entry size = 256 bytes per port
8686
port->fb = port->clb + (32 * 1024) + (portno << 8);
8787
port->fbu = 0;
8888
memset((void*)((uint64_t)port->fb), 0, 256);
8989

90-
kprintf("After 2nd memset\n");
90+
dprintf("After 2nd memset\n");
9191

9292
// Command table offset: 40K + 8K*portno
9393
// Command table size = 256*32 = 8K per port
@@ -100,11 +100,11 @@ void port_rebase(ahci_hba_port_t* port, int portno)
100100
cmdheader[i].ctbau = 0;
101101
memset((void*)(uint64_t)cmdheader[i].ctba, 0, 256);
102102
}
103-
kprintf("After table init\n");
103+
dprintf("After table init\n");
104104

105105
start_cmd(port); // Start command engine
106106

107-
kprintf("After start_cmd\n");
107+
dprintf("After start_cmd\n");
108108
}
109109

110110
int storage_device_ahci_block_read(void* dev, uint64_t start, uint32_t bytes, unsigned char* buffer)

src/idt.c

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,77 +18,78 @@ __attribute__((aligned(16)))
1818
idt_entry_t idt_entries[256];
1919

2020
volatile idt_ptr_t idt64 = {
21-
.limit = sizeof(idt_entries) - 1,
22-
.base = idt_entries
21+
.limit = sizeof(idt_entries) - 1,
22+
.base = idt_entries
2323
};
2424

2525
void io_wait() {
26-
outb(0x80, 0);
26+
outb(0x80, 0);
2727
}
2828

2929
void pic_remap(int offset1, int offset2) {
30-
uint8_t a1 = inb(PIC1_DATA);
31-
uint8_t a2 = inb(PIC2_DATA);
32-
33-
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
34-
io_wait();
35-
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
36-
io_wait();
37-
outb(PIC1_DATA, offset1);
38-
io_wait();
39-
outb(PIC2_DATA, offset2);
40-
io_wait();
41-
outb(PIC1_DATA, 4);
42-
io_wait();
43-
outb(PIC2_DATA, 2);
44-
io_wait();
45-
outb(PIC1_DATA, ICW4_8086);
46-
io_wait();
47-
outb(PIC2_DATA, ICW4_8086);
48-
io_wait();
49-
50-
outb(PIC1_DATA, a1);
51-
outb(PIC2_DATA, a2);
30+
uint8_t a1 = inb(PIC1_DATA);
31+
uint8_t a2 = inb(PIC2_DATA);
32+
33+
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
34+
io_wait();
35+
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
36+
io_wait();
37+
outb(PIC1_DATA, offset1);
38+
io_wait();
39+
outb(PIC2_DATA, offset2);
40+
io_wait();
41+
outb(PIC1_DATA, 4);
42+
io_wait();
43+
outb(PIC2_DATA, 2);
44+
io_wait();
45+
outb(PIC1_DATA, ICW4_8086);
46+
io_wait();
47+
outb(PIC2_DATA, ICW4_8086);
48+
io_wait();
49+
50+
outb(PIC1_DATA, a1);
51+
outb(PIC2_DATA, a2);
5252
}
5353

5454
void pic_disable() {
55-
outb(PIC1_DATA, 0xFF);
56-
outb(PIC2_DATA, 0xFF);
55+
outb(PIC1_DATA, 0xFF);
56+
outb(PIC2_DATA, 0xFF);
5757
}
5858

5959
void pic_enable() {
60-
outb(PIC1_DATA, 0x00);
61-
outb(PIC2_DATA, 0x00);
60+
outb(PIC1_DATA, 0x00);
61+
outb(PIC2_DATA, 0x00);
6262
}
6363

6464
void pic_eoi(int irq) {
65-
if (irq >= 8) {
66-
outb(PIC2_COMMAND, PIC_EOI);
67-
}
68-
outb(PIC1_COMMAND, PIC_EOI);
65+
if (irq >= 8) {
66+
outb(PIC2_COMMAND, PIC_EOI);
67+
}
68+
outb(PIC1_COMMAND, PIC_EOI);
6969
}
7070

7171
void init_idt() {
72-
memset(idt_entries, 0, sizeof(idt_entries));
72+
memset(idt_entries, 0, sizeof(idt_entries));
7373

74-
init_error_handler();
75-
register_interrupt_handler(IRQ0, timer_callback, dev_zero, NULL);
76-
init_debug();
74+
init_error_handler();
75+
register_interrupt_handler(IRQ0, timer_callback, dev_zero, NULL);
76+
init_debug();
7777

78-
// Fill the IDT with handler pointers (in loader.S)
79-
idt_init(idt_entries);
78+
// Fill the IDT with handler pointers (in loader.S)
79+
idt_init(idt_entries);
8080

81-
__asm__ volatile("lidtq (%0)" :: "r"(&idt64));
81+
__asm__ volatile("lidtq (%0)" :: "r"(&idt64));
8282

83-
uint32_t frequency = 50;
84-
uint32_t divisor = 1193180 / frequency;
85-
outb(0x43, 0x36);
86-
outb(0x40, divisor & 0xFF);
87-
outb(0x40, divisor >> 8);
83+
uint32_t frequency = 50;
84+
uint32_t divisor = 1193180 / frequency;
85+
outb(0x43, 0x36);
86+
outb(0x40, divisor & 0xFF);
87+
outb(0x40, divisor >> 8);
8888

89-
pic_remap(0x20, 0x28);
90-
pic_enable();
89+
pic_remap(0x20, 0x28);
90+
pic_enable();
9191

92-
interrupts_on();
93-
dprintf("Interrupts enabled!\n");
92+
interrupts_on();
93+
94+
dprintf("Interrupts enabled!\n");
9495
}

src/init.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,22 @@ init_func_t init_funcs[] = {
1010
NULL,
1111
};
1212

13+
char* init_funcs_names[] = {
14+
"console", "heap", "cores", "idt",
15+
"pci", "clock",
16+
"devicenames", "keyboard", "ide", "ahci",
17+
"filesystem", "iso9660", "devfs", "fat32",
18+
NULL,
19+
};
20+
21+
1322
void init()
1423
{
24+
uint32_t n = 0;
1525
for (init_func_t* func = init_funcs; *func; ++func) {
26+
dprintf("Bringing up %s...\n", init_funcs_names[n]);
1627
(*func)();
28+
dprintf("Initialisation of %s done!\n", init_funcs_names[n++]);
1729
}
1830

1931
}

0 commit comments

Comments
 (0)