{
printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt, drv.dma_cnt, drv.irq_cnt);
}
-void ide_cmd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd)
+
+void _ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd, bool pio)
{
drv.pio_cnt++;
drv.read_mode = cmd;
ide_printd();
- outb(0x00, REG_CTL(dev));
+ outb(0x00|(pio?0:HD_CTL_NIEN), REG_CTL(dev));
outb(0x40, REG_DEVSEL(dev));
- outb(0, REG_NSECTOR(dev)); // High
+ outb((u8)((sect_cnt>>8)&0xFF), REG_NSECTOR(dev)); // High
outb((u8)((sect_nr>>24)&0xFF), REG_LBAL(dev));
outb((u8)((sect_nr>>32)&0xFF), REG_LBAM(dev));
outb((u8)((sect_nr>>40)&0xFF), REG_LBAH(dev));
- outb((u8)nsect, REG_NSECTOR(dev)); // Low
+ outb((u8)((sect_cnt>>0)&0xFF), REG_NSECTOR(dev)); // Low
outb((u8)((sect_nr>> 0)&0xFF), REG_LBAL(dev));
outb((u8)((sect_nr>> 8)&0xFF), REG_LBAM(dev));
outb((u8)((sect_nr>>16)&0xFF), REG_LBAH(dev));
outb(cmd, REG_CMD(dev));
}
+void ide_wait_ready()
+{
+ u32 retires = 100;
+
+ do
+ {
+ int drq_retires = 100000;
+ while(!hd_drq(dev) && --drq_retires)
+ /* do nothing */;
+
+ if(drq_retires != 0)
+ break;
+ }while(--retires);
+
+ if(retires == 0)
+ panic("hard disk is not ready");
+}
+
+
+void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd)
+{
+ _ide_cmd_out(dev, sect_cnt, sect_nr, cmd, true);
+}
+
+void ide_wait_read(dev_t dev, u32 sect_cnt, u64 sect_nr, char *buf)
+{
+ _ide_cmd_out(dev, sect_cnt, sect_nr, HD_CMD_READ_EXT, false);
+ ide_wait_ready();
+ insl(REG_DATA(dev), buf, (sect_cnt*512)>>2);
+}
void dump_pci_ide();
void print_ide_identify(const char *buf)
{
- char *p;
- short *ident;
- int i;
+ char *p;
+ short *ident;
+ int i, j;
+ unsigned char c;
ident = (short *) buf;
p = (char *) (ident+10);
for(i=0; i<20; i++)
- {
hd_sn[i] = p[i];
+ for(j=0; j<20; j+=2)
+ {
+ c = hd_sn[j];
+ hd_sn[j] = hd_sn[j+1];
+ hd_sn[j+1] = c;
}
+
hd_sn[i] = 0;
p = (char *) (ident+27);
{
hd_model[i] = p[i];
}
+ for(j=0; j<20; j+=2)
+ {
+ c = hd_model[j];
+ hd_model[j] = hd_model[j+1];
+ hd_model[j+1] = c;
+ }
hd_model[i] = 0;
void ide_read_identify()
{
- outb(0x02, REG_CTL(0));
- outb(0x40, REG_DEVSEL(dev));
+ outb(HD_CTL_NIEN, REG_CTL(0));
+ outb(0x00, REG_DEVSEL(dev));
outb(HD_CMD_IDENTIFY, REG_CMD(dev));
- u32 retires = 100;
-
- do
- {
- int drq_retires = 100000;
- while(!hd_drq(dev) && --drq_retires)
- /* do nothing */;
-
- if(drq_retires != 0)
- break;
- }while(--retires);
-
- if(retires == 0)
- panic("hard disk is not ready");
+ ide_wait_ready();
insl(REG_DATA(0), buf, 512>>2);
print_ide_identify(buf);
inb(HD_CHL0_CTL_BASE); \
}
-
void ide_dma_pci_lba48()
{
drv.dma_cnt ++;
inb(drv.bus_status);
}
+typedef struct {
+ unsigned int a;
+ unsigned int b;
+ unsigned int lba;
+ unsigned int sect_cnt;
+} hd_part_t ;
+
void ide_init()
{
memset((void *)&drv, 0, sizeof(drv));
ide_read_identify();
ide_printd();
#endif
+ ide_wait_read(0, 1, 0, data);
+
+ hd_part_t *p = (hd_part_t *)(data+PARTITION_TABLE_OFFSET);
+ int i;
+ for(i=0; i<4; ++i)
+ {
+ printk(" Partition %d LBA %d SectCnt %d\n", i, p->lba, p->sect_cnt);
+ p++;
+ }
+
+ u16_t sig = *((u16_t *) (data+510));
+ printk("IDE_INIT______READ %04x\n", sig);
}
#define HD_CMD_IDENTIFY 0xEC
#define HD_CTL 0
-#define HD_CTL_NORETRY 0x80 /* disable access retry */
-#define HD_CTL_NOECC 0x40 /* disable ecc retry */
-#define HD_CTL_EIGHTHEADS 0x08 /* more than 8 heads */
-#define HD_CTL_RESET 0x04 /* reset controller */
-#define HD_CTL_DISABLE_INT 0x02 /* disable interrupts */
+#define HD_CTL_HOB 0x80 /* high order byte (LBA-48bit) */
+//#define HD_CTL_NOECC 0x40 /* disable ecc retry */
+//#define HD_CTL_EIGHTHEADS 0x08 /* more than 8 heads */
+#define HD_CTL_SRST 0x04 /* soft reset controller */
+#define HD_CTL_NIEN 0x02 /* disable interrupts */
#define HD_GET_CHL(dev) (0) /* only support channel 0 */
#define HD_GET_DEV(dev) (0) /* only support one hard disk */
#define PCI_IDE_STATUS_DRV1 0x40
#define PCI_IDE_STATUS_SIMPLEX 0x80
#define PCI_IDE_PRDT 4
+
+
+
+#define PARTITION_TABLE_OFFSET 0x1BE
if(scan_code == 0x43); // F9
if(scan_code == 0x44); // F10
- if(scan_code == 0x57) // F11
- poweroff();
+ if(scan_code == 0x57); // F11
if(scan_code == 0x58) // F12
vga_dbg_toggle();
} vga_screen_t;
#define VGA_MAX_SCREEN_CNT 4
+unsigned int vga_screen_cnt() {return VGA_MAX_SCREEN_CNT;}
vga_screen_t vga_screen[VGA_MAX_SCREEN_CNT] = {
{
0,
unsigned int ext2_start_sect;
Inode ext2_root_inode;
-void hd_read(Dev dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ }
+void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ }
void ext2_read_block(int block_id, char *buf);
static void ext2_print_group_descriptor(pGroupDesc p);
static void ext2_print_inode(pInode p);
#include <system.h>
#define SECT_SIZE 512
-File file_table[NR_FILES]
- __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
+File file_table[NR_FILES] __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
extern unsigned int ext2_start_sect;
-void hd_read(Dev dev, u64 sect_nr, void *buf, u32 count);
-void init_file_table();
-void save_boot_part(int n, pPartition p, u32 base_sect);
-void read_ext_part(u32 base, u32 offset);
+void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count);
+void init_file_table();
+void save_boot_part(int n, pPartition p, u32 base_sect);
+void read_ext_part(u32 base, u32 offset);
-void setup_fs()
+void setup_fs()
{
int i, minor;
pPartition p;
#endif
}
-void init_file_table()
+void init_file_table()
{
int i;
}
}
-void save_boot_part(int n, pPartition p, u32 base_sect)
+void save_boot_part(int n, pPartition p, u32 base_sect)
{
if(p->Type == 0x05)
panic("partition should not be extended");
}
static unsigned int ext_part = 5;
-void read_ext_part(u32 base, u32 offset)
+void read_ext_part(u32 base, u32 offset)
{
unsigned char *buf;
pPartition p;
free_virt_pages(buf);
}
-
#pragma once
+void switch_printk_screen();
int printk(char *fmtstr, ...);
int printd(unsigned int line, const char *fmtstr, ...);
u16 ss, _ss;
} __attribute__((packed)) pt_regs_t;
-typedef unsigned long Dev, *pDev;
+typedef unsigned long dev_t;
typedef struct system
{
- u32 mmap_addr;
- u32 mmap_size; // Byte
+ u32 mmap_addr;
+ u32 mmap_size; // Byte
- u32 mm_lower; // KB
- u32 mm_upper; // KB
- u64 mm_size; // Byte
+ u32 mm_lower; // KB
+ u32 mm_upper; // KB
+ u64 mm_size; // Byte
- u32 page_count;
- pPage page_map;
- u32 page_bitmap;
+ u32 page_count;
+ pPage page_map;
+ u32 page_bitmap;
u32 *page_dir;
- u32 *pte_start;
- u32 *pte_end;
+ u32 *pte_start;
+ u32 *pte_end;
- u32 kernel_end;
+ u32 kernel_end;
// +-------+-------+-------+-------+
// | drive | part1 | part2 | part3 |
// Partition numbers always start from zero.
// Unused partition bytes must be set to 0xFF.
// More Infomation see 'info multiboot'
- u32 boot_device;
+ u32 boot_device;
- Dev root_dev;
+ dev_t root_dev;
#define CMD_LINE_SIZE 128
- char *cmdline;
+ char *cmdline;
- u32 debug;
+ u32 debug;
} System, *pSystem;
extern System system;
const char *pci_get_info(unsigned int classcode, unsigned int progif)
{
pci_info_t *p = pci_info;
+ const char *s = 0;
+
while(p->code != 0 || p->flag != 0 || p->info != 0)
{
unsigned long code = classcode;
}
if(p->code == code)
- return p->info;
+ {
+ if(p->flag == 0)
+ {
+ return p->info;
+ }
+ else
+ {
+ s = p->info;
+ }
+ }
p++;
}
- return 0;
+ return s;
}
extern void vga_puts(unsigned int nr, const char *buf, unsigned char color);
extern void vga_dbg_puts(unsigned long line, const char *buf, unsigned char color);
+unsigned int printk_screen_nr = 0;
+
+extern unsigned int vga_screen_cnt();
+void switch_printk_screen()
+{
+ printk_screen_nr++;
+ printk_screen_nr %= vga_screen_cnt();
+}
+
char pkbuf[1024];
-extern int bvga;
int printk(const char *fmtstr, ...)
{
char *args = (char*)(((char*)&fmtstr)+4);
vsprintf(pkbuf, fmtstr, args);
- vga_puts(0, pkbuf,0x2);
+ vga_puts(printk_screen_nr, pkbuf, 0x2);
return 0;
}
{
char *args = (char*)(((char*)&fmtstr)+4);
vsprintf(pdbuf, fmtstr, args);
- vga_dbg_puts(line, pdbuf,0x7);
+ vga_dbg_puts(line, pdbuf, 0x7);
return 0;
}
setup_tasks();
setup_irqs();
-
+ switch_printk_screen();
setup_pci();
-
+ switch_printk_screen();
void ide_init();
ide_init();