Skip to content
2 changes: 1 addition & 1 deletion common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static void acpi_table_unmap_pages(void *addr, unsigned mapped_pages) {
mfn_t mfn = virt_to_mfn(addr);

for (unsigned i = 0; i < mapped_pages; i++, mfn++) {
vunmap(mfn_to_virt_kern(mfn), PAGE_ORDER_4K);
vunmap_kern(mfn_to_virt_kern(mfn), PAGE_ORDER_4K);
}
}

Expand Down
4 changes: 2 additions & 2 deletions common/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ static void probe_pci_bus(uint8_t bus, uint8_t start_dev, pcidev_t *bridge) {
BUG_ON(!new_dev);

new_dev->bridge = bridge;
snprintf(&new_dev->bdf_str[0], sizeof(new_dev->bdf_str), "%02x:%1x.%1x", bus,
dev, func);
snprintf(&new_dev->bdf_str[0], sizeof(new_dev->bdf_str), "%02x:%02x.%02x",
bus, dev, func);

list_add_tail(&new_dev->list, &pci_list);

Expand Down
50 changes: 27 additions & 23 deletions common/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@

boot_flags_t boot_flags;

unsigned long cpu_frequency;

#define QEMU_CONSOLE_PORT 0x0e9

static void __text_init init_console(void) {
Expand Down Expand Up @@ -123,15 +125,14 @@ static void __text_init map_bios_area(void) {

static void display_cpu_info(void) {
char cpu_identifier[49];
unsigned long freq;

if (!cpu_vendor_string(cpu_identifier))
return;

printk("CPU: %.48s\n", cpu_identifier);
freq = get_cpu_freq(cpu_identifier);
if (freq > 0)
printk("Frequency: %lu MHz\n", freq / MHZ(1));
cpu_frequency = get_cpu_freq(cpu_identifier);
if (cpu_frequency > 0)
printk("Frequency: %lu MHz\n", cpu_frequency / MHZ(1));
}

static void display_banner(void) { draw_logo(); }
Expand All @@ -150,6 +151,9 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,
/* Zero-out BSS sections */
zero_bss();

/* Initialize console early */
init_console();

if (multiboot_magic == MULTIBOOT_BOOTLOADER_MAGIC) {
/* Indentity mapping is still on, so fill in multiboot structures */
init_multiboot(mbi, &kernel_cmdline);
Expand All @@ -160,9 +164,6 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,
if (!string_empty(kernel_cmdline))
printk("Command line: %s\n", kernel_cmdline);

/* Initialize console early */
init_console();

init_boot_traps();

init_real_mode();
Expand Down Expand Up @@ -208,22 +209,34 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,

init_slab();

/* Try to initialize ACPI (and MADT) */
init_apic(bsp->id, APIC_MODE_XAPIC);

init_tasks();

/* Initialize timers */
bool hpet_initialized = false;
if (opt_hpet)
hpet_initialized = init_hpet(bsp);

if (!hpet_initialized && opt_pit)
init_pit(bsp);

if (opt_apic_timer)
init_apic_timer();

/* Try to initialize ACPI (and MADT) */
#ifndef KTF_ACPICA
if (init_acpi() < 0) {
#else
if (ACPI_FAILURE(init_acpi())) {
#endif
/* Fallback to MP tables when no ACPI */
if (init_mptables() < 0)
BUG();
boot_flags.nosmp = true;
}

init_apic(bsp->id, APIC_MODE_XAPIC);

init_tasks();

init_smp();
if (!boot_flags.nosmp)
init_smp();

init_ioapic();

Expand All @@ -232,15 +245,6 @@ void __noreturn __text_init kernel_start(uint32_t multiboot_magic,
/* Initialize console input */
init_uart_input(bsp);

/* Initialize timers */
bool hpet_initialized = false;
if (opt_hpet)
hpet_initialized = init_hpet(bsp);
if (!hpet_initialized && opt_pit)
init_pit(bsp);
if (opt_apic_timer)
init_apic_timer();

/* Initialize keyboard */
if (opt_keyboard)
init_keyboard(bsp);
Expand Down
7 changes: 5 additions & 2 deletions drivers/acpi/acpica/osl.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,11 @@ void AcpiOsSleep(UINT64 Miliseconds) { msleep(Miliseconds); }
/* FIXME: Return in correct 100ns units */
UINT64 AcpiOsGetTimer(void) { return get_timer_ticks(); }

/* FIXME: Use microseconds granularity */
void AcpiOsStall(UINT32 Microseconds) { msleep(1); }
/* FIXME: Use actual microseconds granularity */
void AcpiOsStall(UINT32 Microseconds) {
for (unsigned long i = Microseconds * 1000; i > 0; i--)
cpu_relax();
}

/* PCI Configuration read/write functions */

Expand Down
6 changes: 4 additions & 2 deletions drivers/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ void init_keyboard(const cpu_t *cpu) {
outb(KEYBOARD_PORT_CMD, KEYBOARD_CMD_DISABLE_PORT_2);

/* Flush output buffer */
while (inb(KEYBOARD_PORT_CMD) & KEYBOARD_STATUS_OUT_FULL)
; /* discard leftover bytes */
for (unsigned short i = 0; i; i++) {
if ((inb(KEYBOARD_PORT_CMD) & KEYBOARD_STATUS_OUT_FULL) == 0)
break;
}

/* Controller configuration */
keyboard_controller_config_t current_status;
Expand Down
1 change: 1 addition & 0 deletions grub/boot/grub/grub.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set timeout=0
set default=0

insmod serial
insmod all_video

serial --speed=115200 --word=8 --parity=no --stop=1
Expand Down
2 changes: 1 addition & 1 deletion include/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ struct pcidev {
uint8_t hdr;
uint8_t cap_ptr;
struct pcidev *bridge;
char bdf_str[7];
char bdf_str[10];
};
typedef struct pcidev pcidev_t;

Expand Down
3 changes: 2 additions & 1 deletion include/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@

struct boot_flags {
uint64_t virt : 1, legacy_devs : 1, i8042 : 1, vga : 1, msi : 1, aspm : 1, rtc : 1,
rsvd : 57;
nosmp : 1, rsvd : 56;
};
typedef struct boot_flags boot_flags_t;

extern char cpu_identifier[49];
extern unsigned long cpu_frequency;
extern boot_flags_t boot_flags;

/* Static declarations */
Expand Down
2 changes: 1 addition & 1 deletion mm/slab.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static void *ktf_alloc(size_t size) {
*/
order_index -= 4;

dprintk("Alloc size %zu, powerof 2 size %zu, order %zu\n", size, size_power2,
dprintk("Alloc size %u, powerof 2 size %u, order %u\n", size, size_power2,
order_index);
spin_lock(&slab_mm_lock);
/* Go through list of meta_slab_t and try to allocate a free slab */
Expand Down