feat: moved all required prints to printf

This commit is contained in:
2021-02-06 17:04:32 +01:00
parent 7ff33d611c
commit 9440fae968
4 changed files with 39 additions and 61 deletions

View File

@@ -10,8 +10,8 @@
#include <drivers/pci.h>
#include <libc/stdbool.h>
#include <libk.h>
#include <libc/libc.h>
#include <cpu/timer.h>
#include <libc/kprintf.h>
#define ATA_SR_BSY 0x80 // Busy
#define ATA_SR_DRDY 0x40 // Drive ready
@@ -299,14 +299,10 @@ unsigned char ide_print_error(unsigned int drive, unsigned char err) {
kprint("- Write Protected\n ");
err = 8;
}
kprint(" - [");
kprint((const char *[]) {"Primary", "Secondary"}[ide_devices[drive].channel]);
kprint(" ");
kprint((const char *[]) {"Master", "Slave"}[ide_devices[drive].drive]);
kprint("] ");
kprint(&ide_devices[drive].model);
kprint("\n");
printf(" - [%s %s] %s\n",
((const char *[]) {"Primary", "Secondary"}[ide_devices[drive].channel]),
((const char *[]) {"Master", "Slave"}[ide_devices[drive].drive]),
&ide_devices[drive].model);
return err;
}
@@ -472,21 +468,21 @@ u8 ide_pci_initialize(pci_device *device) {
count++;
}
// 4- Print Summary:
return PCI_INIT_OK;
}
void ide_print_devices() {
for (int i = 0; i < 4; i++) {
if (ide_devices[i].reserved == 1) {
char tmp[64];
itoa(ide_devices[i].size / 1024 / 2, tmp, 10);
kprint("Found ");
kprint((const char *[]) {"ATA", "ATAPI"}[ide_devices[i].type]);
kprint(" Drive ");
kprint(tmp);
kprint("MB - ");
kprint(ide_devices[i].model);
kprint("\n");
printf("Drive %d: %s Drive %dMB - %s\n",
i,
((const char *[]) {"ATA", "ATAPI"}[ide_devices[i].type]),
ide_devices[i].size / 1024 / 2,
ide_devices[i].model);
} else {
printf("Drive %d disconnected\n", i);
}
}
return PCI_INIT_OK;
}
void ide_register() {
@@ -587,7 +583,7 @@ u8 ide_read_ata_access(u8 direction, u8 drive, u32 lba, u8 numsects, void *targe
// if (lba_mode == 2 && dma == 1 && direction == 1) cmd = ATA_CMD_WRITE_DMA_EXT;
ide_write(channel, ATA_REG_COMMAND, cmd); // Send the Command.
void* cur_addr = target;
void *cur_addr = target;
// read response
if (dma) {
if (direction == 0);

View File

@@ -11,4 +11,6 @@ void ide_register();
u8 ide_read_access(u8 direction, u8 drive, u32 lba, u8 numsects, void *target);
void ide_print_devices();
#endif //NEW_KERNEL_IDE_H

View File

@@ -7,9 +7,8 @@
#include <types.h>
#include <drivers/ports.h>
#include <libc/libc.h>
#include <kprint.h>
#include <libk.h>
#include <libc/kprintf.h>
#define PCI_CONFIG_ENABLE (1 << 31)
@@ -96,18 +95,6 @@ u8 pci_get_header_type(u8 bus, u8 slot, u8 func) {
return pci_config_read_byte(bus, slot, func, PCI_CONFIG_HEADER_TYPE);
}
void print_u8(u8 val) {
char buf[3];
itoa(val, buf, 16);
kprint(buf);
}
void print_u16(u16 val) {
char buf[5];
itoa(val, buf, 16);
kprint(buf);
}
void pci_pick_driver(pci_device *device) {
for (int i = 0; i < MAX_PCI_DRIVERS; ++i) {
if (pci_drivers[i] == NULL) {
@@ -198,32 +185,11 @@ void pci_init_drivers() {
void pci_print_info() {
for (int i = 0; i < last_pci_device_index; ++i) {
kprint("PCI BSF: ");
print_u8(pci_devices[i].bus);
kprint("/");
print_u8(pci_devices[i].slot);
kprint("/");
print_u8(pci_devices[i].func);
kprint(", Class/Sub/If: ");
print_u8(pci_devices[i].class);
kprint("/");
print_u8(pci_devices[i].subclass);
kprint("/");
print_u8(pci_devices[i].programInterface);
kprint(", V/D: ");
print_u16(pci_devices[i].vendorId);
kprint("/");
print_u16(pci_devices[i].deviceId);
kprint(" driver_info: ");
if (pci_devices[i].pci_driver == NULL) {
kprint("NULL");
} else {
kprint(pci_devices[i].pci_driver->name);
}
kprint("\n");
printf("PCI BSF: %2x/%2x/%2x, CSI: %2x/%2x/%2x, V/D: %4x/%4x, driver: %s\n",
pci_devices[i].bus, pci_devices[i].slot, pci_devices[i].func,
pci_devices[i].class, pci_devices[i].subclass, pci_devices[i].programInterface,
pci_devices[i].vendorId, pci_devices[i].deviceId,
(pci_devices[i].pci_driver == NULL ? "none" : pci_devices[i].pci_driver->name));
}
}

View File

@@ -34,6 +34,7 @@ typedef struct {
} cmd_handler;
void print(const char *arg);
void ide(const char *arg);
void echo(const char *arg);
void help(const char *arg);
@@ -41,6 +42,7 @@ cmd_handler cmd_handlers[] = {
{"help", help},
{"echo", echo},
{"print", print},
{"ide", ide},
{NULL, NULL},
};
@@ -80,6 +82,18 @@ void print(const char *arg) {
print_bootinfo();
} else if (strcmp(arg, "pci") == 0) {
pci_print_info();
} else if (strcmp(arg, "ide") == 0) {
ide_print_devices();
} else {
kprint("Unknown print ");
kprint(arg);
kprint(newline);
}
}
void ide(const char* arg) {
if (strcmp(arg, "devices") == 0) {
ide_print_devices();
} else {
kprint("Unknown print ");
kprint(arg);