possibly ata pio

This commit is contained in:
koniifer 2024-12-26 02:00:51 +00:00
parent 986077435f
commit 90f1b3fdc5
4 changed files with 120 additions and 121 deletions

View file

@ -130,15 +130,27 @@ fmt_container := fn(v: @Any(), str: []u8, opts: FormatOptions): uint {
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr) *@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(".(".ptr)
len += 2 len += 2
} }
$loop {
v_sub := v[i] if kind == .Slice {
len += @inline(format, v_sub, str[len..], opts) loop {
i += 1 len += @inline(format, v[i], str[len..], opts)
if i == @lenof(T2) break else { i += 1
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr) if i == v.len break else {
len += 2 *@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr)
len += 2
}
}
} else {
$loop {
len += @inline(format, v[i], str[len..], opts)
i += 1
if i == @lenof(T2) break else {
*@as(^[2]u8, @bitcast(str.ptr + len)) = *@bitcast(", ".ptr)
len += 2
}
} }
} }
if kind == .Struct | kind == .Tuple { if kind == .Struct | kind == .Tuple {
*@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr) *@as(^[1]u8, @bitcast(str.ptr + len)) = *@bitcast(")".ptr)
len += 1 len += 1

View file

@ -69,6 +69,16 @@ $inl := fn(addr: u16): u32 {
return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg)) return @eca(3, 3, &InlMsg.(0, 2, addr), @sizeof(InlMsg))
} }
OutsMsg := packed struct {a: u8, b: u8, addr: u16, value: u16}
$outs := fn(addr: u16, value: u32): void {
return @eca(3, 3, &OutsMsg.(1, 1, addr, value), @sizeof(OutsMsg))
}
InsMsg := packed struct {a: u8, b: u8, addr: u16}
$ins := fn(addr: u16): u16 {
return @eca(3, 3, &InsMsg.(0, 1, addr), @sizeof(InsMsg))
}
CopyMsg := packed struct {a: u8, count: uint, src: ^u8, dest: ^u8} CopyMsg := packed struct {a: u8, count: uint, src: ^u8, dest: ^u8}
$copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void { $copy := fn($Expr: type, src: ^Expr, dest: ^Expr, count: uint): void {
return @eca(3, 2, &CopyMsg.(4, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg)) return @eca(3, 2, &CopyMsg.(4, count * @sizeof(Expr), @bitcast(src), @bitcast(dest)), @sizeof(CopyMsg))

View file

@ -1,134 +1,111 @@
.{memory, buffer, log} := @use("stn"); .{memory: .{inb, outb, ins, alloc}, log} := @use("stn")
.{inb, outb} := memory
regs := @use("regs.hb"); $ATA_PRIMARY_DATA := 0x1F0
.{ATA_PRIMARY_IO, ATA_PRIMARY_DEVCTL, ATA_SECONDARY_DEVCTL, ATA_REG_STAT, ATA_SR_ERR, ATA_SR_BSY, ATA_SR_DF, ATA_SR_DRQ} := regs $ATA_PRIMARY_ERR := 0x1F1
$ATA_PRIMARY_SECCOUNT := 0x1F2
$ATA_PRIMARY_LBA_LO := 0x1F3
$ATA_PRIMARY_LBA_MID := 0x1F4
$ATA_PRIMARY_LBA_HI := 0x1F5
$ATA_PRIMARY_DRIVE_HEAD := 0x1F6
$ATA_PRIMARY_COMM_REGSTAT := 0x1F7
$ATA_PRIMARY_ALTSTAT_DCR := 0x3F6
sloop := fn(i: u8): void { $STAT_ERR := 1 << 0
// idx := 0xFFFFFFF $STAT_DRQ := 1 << 3
// loop { $STAT_SRV := 1 << 4
// if idx == 0 { $STAT_DF := 1 << 5
// break $STAT_RDY := 1 << 6
// } else { $STAT_BSY := 1 << 7
// idx -= 1
// }
// }
loop { Drive := enum {Master, Slave}
if i == 0 {
break
} else {
a := inb(ATA_SECONDARY_DEVCTL)
i -= 1 select_drive := fn(drive: Drive): void {
} match drive {
.Master => outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0),
.Slave => outb(ATA_PRIMARY_DRIVE_HEAD, 0xB0),
} }
} }
// identify := fn(): u8 { identify := fn(drive: Drive): u8 {
// a := inb(ATA_PRIMARY_COMM_REGSTAT) if inb(ATA_PRIMARY_COMM_REGSTAT) == 0xFF {
// outb(ATA_PRIMARY_DRIVE_HEAD, 0xA0) log.error("(ata: drive not present) status=0xFF")
// log.info("Primary drive head set.") return 0
}
// a = inb(ATA_PRIMARY_COMM_REGSTAT) select_drive(drive)
// outb(ATA_PRIMARY_SECCOUNT, 0) inb(ATA_PRIMARY_COMM_REGSTAT)
// a = inb(ATA_PRIMARY_COMM_REGSTAT) outb(ATA_PRIMARY_SECCOUNT, 0)
// outb(ATA_PRIMARY_LBA_LO, 0) inb(ATA_PRIMARY_COMM_REGSTAT)
// a = inb(ATA_PRIMARY_COMM_REGSTAT) outb(ATA_PRIMARY_LBA_LO, 0)
// outb(ATA_PRIMARY_LBA_MID, 0) inb(ATA_PRIMARY_COMM_REGSTAT)
// a = inb(ATA_PRIMARY_COMM_REGSTAT) outb(ATA_PRIMARY_LBA_MID, 0)
// outb(ATA_PRIMARY_LBA_HI, 0) inb(ATA_PRIMARY_COMM_REGSTAT)
// a = inb(ATA_PRIMARY_COMM_REGSTAT) outb(ATA_PRIMARY_LBA_HI, 0)
// outb(ATA_PRIMARY_COMM_REGSTAT, 0xEC) inb(ATA_PRIMARY_COMM_REGSTAT)
// outb(ATA_PRIMARY_COMM_REGSTAT, 0xE7) outb(ATA_PRIMARY_COMM_REGSTAT, 0xEC)
outb(ATA_PRIMARY_COMM_REGSTAT, 0xE7)
// status := inb(ATA_PRIMARY_COMM_REGSTAT) status := inb(ATA_PRIMARY_COMM_REGSTAT)
// log.info("Waiting for status.")
// loop {
// if (status & STAT_BSY) == 0 {
// log.info("Status got.")
// break
// } else {
// sloop()
// }
// status = inb(ATA_PRIMARY_COMM_REGSTAT)
// }
// if status == 0 {
// log.error("No drive detected.")
// return 0 loop if (status & STAT_BSY) == 0 break else {
// } // if DEBUG_PRINT log.printf("(ata: waiting for status) status={}", .(status), .{radix: 16, log: .Warn})
// log.info("Status indicates presence of a drive. Polling while STAT_BSY... ") status = inb(ATA_PRIMARY_COMM_REGSTAT)
// loop { }
// if (status & STAT_BSY) == 0 {
// log.info("Status got.")
// break
// } else {
// sloop()
// }
// status = inb(ATA_PRIMARY_COMM_REGSTAT)
// }
// mid := inb(ATA_PRIMARY_LBA_MID) if status == 0 {
// hi := inb(ATA_PRIMARY_LBA_HI) log.error("(ata: drive not present) status=0")
return 0
}
// if (mid | hi) == 0 { loop if (status & STAT_BSY) == 0 break else {
// log.error("The drive is not ATA. (Who knows what it is.)") if DEBUG_PRINT log.printf("(ata: waiting for busy to end) status={}", .(status), .{radix: 16, log: .Warn})
// return 0 status = inb(ATA_PRIMARY_COMM_REGSTAT)
// } }
// return 0 mid := inb(ATA_PRIMARY_LBA_MID)
// } hi := inb(ATA_PRIMARY_LBA_HI)
if (mid | hi) != 0 {
log.error("the drive is not ata...?")
return 0
}
drive_reset := fn(): void { loop if (status & (STAT_ERR | STAT_DRQ)) != 0 break else {
log.warn("Drive resetting.") if DEBUG_PRINT log.printf("(ata: waiting for ERR or DRQ) status={}", .(status), .{radix: 16, log: .Warn})
outb(ATA_PRIMARY_DEVCTL, 0x4) status = inb(ATA_PRIMARY_COMM_REGSTAT)
sloop(4) }
outb(ATA_PRIMARY_DEVCTL, 0x0)
}
poll := fn(): u8 { if (status & STAT_ERR) != 0 {
sloop(4) if DEBUG_PRINT log.printf("(ata: drive error) status={}", .(status), .{radix: 16, log: .Error})
status := 0 return 0
// busy loop waiting for status }
loop {
status = inb(ATA_PRIMARY_IO + ATA_REG_STAT) if DEBUG_PRINT log.printf("status={}", .(status), .{radix: 16})
if (status & ATA_SR_BSY) == 0 {
break buffer := alloc(u16, 255)[0..255]
read(buffer)
if DEBUG_PRINT {
if (buffer[83] & 1 << 10) != 0 {
log.info("LBA48 mode supported")
log.printf("{} 48 bit addressable sectors", *@as(^uint, @bitcast(buffer[100..].ptr)), .{})
} }
} log.print(buffer, .{})
status = inb(ATA_PRIMARY_IO + ATA_REG_STAT)
if (status & ATA_SR_DF) == 0 {
log.error("ATA PRIMARY DRIVE FAULT")
return 1
}
if (status & ATA_SR_ERR) == 0 {
log.error("ATA PRIMARY ERR")
return 2
}
if (status & ATA_SR_DRQ) == 0 {
log.error("ATA PRIMARY DRQ")
return 3
} }
return 0 return 0
} }
main := fn(): int { read := fn(buffer: []u16): void {
// shuts down ableOS i := 0
// outb(0xF400, 0) loop if i == buffer.len break else {
buffer[i] = ins(ATA_PRIMARY_DATA)
i += 1
}
}
a := inb(0x4600) // inflates asm a lot
b := inb(0x4700) $DEBUG_PRINT := true
// c := buffer.search("XNumber") main := fn(): void {
// c := identify() identify(.Master)
d := drive_reset()
e := poll()
return 0
} }

View file

@ -44,8 +44,8 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.ablefetch] # [boot.limine.ableos.modules.ablefetch]
# path = "boot:///ablefetch.hbf" # path = "boot:///ablefetch.hbf"
# [boot.limine.ableos.modules.diskio_driver] [boot.limine.ableos.modules.diskio_driver]
# path = "boot:///diskio_driver.hbf" path = "boot:///diskio_driver.hbf"
# [boot.limine.ableos.modules.angels_halo] # [boot.limine.ableos.modules.angels_halo]
# path = "boot:///angels_halo.hbf" # path = "boot:///angels_halo.hbf"
@ -53,5 +53,5 @@ resolution = "1024x768x24"
# [boot.limine.ableos.modules.test] # [boot.limine.ableos.modules.test]
# path = "boot:///test.hbf" # path = "boot:///test.hbf"
[boot.limine.ableos.modules.vfsaur] # [boot.limine.ableos.modules.vfsaur]
path = "boot:///vfsaur.hbf" # path = "boot:///vfsaur.hbf"