Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

## fixes
* Fixed the clear command outputing build number, Closing [#17](https://github.com/randomusert/tinos2c/issues/17)


# 0.1-alpha7
## Additions
* Init messages
* Try or install menu
2 changes: 2 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Alpha and beta releases are early versions and such will not get support
| ------- | ------------------ | ------ |
| 0.1 alpha 3 | :x: | A alpha release |
| 0.1 alpha 4 | :x: | A alpha release |
| 0.1 alpha 5 | :x: | A alpha release |
| 0.1 alpha 6 | :x: | A alpha release |


## Reporting a Vulnerability
Expand Down
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20
27
2 changes: 2 additions & 0 deletions docs/specs/FS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# FileSystem
This OS has a custom FileSystem...
4 changes: 4 additions & 0 deletions kernel/console/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ void console() {
char buffer[128];
int pos = 0;


print("console loaded\n");
print("Welcome to Tinos2CE! Type 'help' to see available commands\n");

print(">");

while (1) {
Expand Down
254 changes: 254 additions & 0 deletions kernel/drivers/disk/ata/ata.S.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
read_ata_st:
push edx
push ecx
push eax
test ebx, ebx ; # of sectors < 0 is a "reset" request from software
js short .reset
cmp ebx, 0x3fffff ; read will be bigger than 2GB? (error)
stc
jg short .r_don
mov edx, [esi + dd_prtlen] ; get the total partition length (sectors)
dec edx ; (to avoid handling "equality" case)
cmp edx, ebp ; verify ebp is legal (within partition limit)
jb short .r_don ; (carry is set automatically on an error)
cmp edx, ebx ; verify ebx is legal (forget about the ebx = edx case)
jb short .r_don
sub edx, ebx ; verify ebp + ebx - 1 is legal
inc edx
cmp edx, ebp ; (the test actually checks ebp <= edx - ebx + 1)
jb short .r_don
mov dx, [esi + dd_dcr] ; dx = alt status/DCR
in al, dx ; get the current status
test al, 0x88 ; check the BSY and DRQ bits -- both must be clear
je short .stat_ok

.reset:
call srst_ata_st
test ebx, ebx ; bypass any read on a "reset" request
jns short .stat_ok
xor ebx, ebx ; force zero flag on, carry clear
jmp short .r_don

.stat_ok:
cmp ebp, 0xfffffff
jg short .setreg
mov eax, [esi + dd_stLBA]
cmp eax, 0xfffffff
jg short .setreg
add eax, ebp
cmp eax, 0xfffffff
jg short .setreg
add eax, ebx
cmp eax, 0xfffffff

.setreg:
mov dx, [esi + dd_tf] ; dx = IO port base ("task file")
jle short .read28 ; test the flags from the eax cmp's above

.read48:
test ebx, ebx ; no more sectors to read?
je short .r_don
call pio48_read ; read up to 256 more sectors, updating registers
je short .read48 ; if successful, is there more to read?
jmp short .r_don

.read28:
test ebx, ebx ; no more sectors to read?
je short .r_don
call pio28_read ; read up to 256 more sectors, updating registers
je short .read28 ; if successful, is there more to read?

.r_don:
pop eax
pop ecx
pop edx
ret



pio28_read:
add ebp, [esi + dd_stLBA] ; convert relative LBA to absolute LBA
mov ecx, ebp ; save a working copy
mov al, bl ; set al= sector count (0 means 256 sectors)
or dl, 2 ; dx = sectorcount port -- usually port 1f2
out dx, al
mov al, cl ; ecx currently holds LBA
inc edx ; port 1f3 -- LBAlow
out dx, al
mov al, ch
inc edx ; port 1f4 -- LBAmid
out dx, al
bswap ecx
mov al, ch ; bits 16 to 23 of LBA
inc edx ; port 1f5 -- LBAhigh
out dx, al
mov al, cl ; bits 24 to 28 of LBA
or al, byte [esi + dd_sbits] ; master/slave flag | 0xe0
inc edx ; port 1f6 -- drive select
out dx, al

inc edx ; port 1f7 -- command/status
mov al, 0x20 ; send "read" command to drive
out dx, al
mov ecx, 4

.lp1:
in al, dx ; grab a status byte
test al, 0x80 ; BSY flag set?
jne short .retry
test al, 8 ; DRQ set?
jne short .data_rdy

.retry:
dec ecx
jg short .lp1
; need to wait some more -- loop until BSY clears or ERR sets (error exit if ERR sets)

.pior_l:
in al, dx ; grab a status byte
test al, 0x80 ; BSY flag set?
jne short .pior_l ; (all other flags are meaningless if BSY is set)
test al, 0x21 ; ERR or DF set?
jne short .fail

.data_rdy:
sub dl, 7 ; read from data port (ie. 0x1f0)
mov cx, 256
rep insw ; gulp one 512b sector into edi
or dl, 7 ; "point" dx back at the status register
in al, dx ; delay 400ns to allow drive to set new values of BSY and DRQ
in al, dx
in al, dx
in al, dx
inc ebp ; increment the current absolute LBA
dec ebx ; decrement the "sectors to read" count
test bl, bl ; check if the low byte just turned 0 (more sectors to read?)
jne short .pior_l

sub dx, 7 ; "point" dx back at the base IO port, so it's unchanged
sub ebp, [esi + dd_stLBA] ; convert absolute lba back to relative
; "test" sets the zero flag for a "success" return -- also clears the carry flag
test al, 0x21 ; test the last status ERR bits
je short .done
.fail:
stc
.done:
ret


pio48_read:
xor eax, eax
add ebp, [esi + dd_stLBA] ; convert relative LBA to absolute LBA
adc ah, 0 ; if so, ah = LBA byte #5 = 1
mov ecx, ebp ; save a working copy of 32 bit absolute LBA

; for speed purposes, never OUT to the same port twice in a row -- avoiding it is messy but best
;outb (0x1F2, sectorcount high)
;outb (0x1F3, LBA4)
;outb (0x1F4, LBA5) -- value = 0 or 1 only
;outb (0x1F5, LBA6) -- value = 0 always
;outb (0x1F2, sectorcount low)
;outb (0x1F3, LBA1)
;outb (0x1F4, LBA2)
;outb (0x1F5, LBA3)
bswap ecx ; make LBA4 and LBA3 easy to access (cl, ch)
or dl, 2 ; dx = sectorcount port -- usually port 1f2
mov al, bh ; sectorcount -- high byte
out dx, al
mov al, cl
inc edx
out dx, al ; LBA4 = LBAlow, high byte (1f3)
inc edx
mov al, ah ; LBA5 was calculated above
out dx, al ; LBA5 = LBAmid, high byte (1f4)
inc edx
mov al, 0 ; LBA6 is always 0 in 32 bit mode
out dx, al ; LBA6 = LBAhigh, high byte (1f5)

sub dl, 3
mov al, bl ; sectorcount -- low byte (1f2)
out dx, al
mov ax, bp ; get LBA1 and LBA2 into ax
inc edx
out dx, al ; LBA1 = LBAlow, low byte (1f3)
mov al, ah ; LBA2
inc edx
out dx, al ; LBA2 = LBAmid, low byte (1f4)
mov al, ch ; LBA3
inc edx
out dx, al ; LBA3 = LBAhigh, low byte (1f5)

mov al, byte [esi + dd_sbits]
inc edx
and al, 0x50
out dx, al

inc edx
mov al, 0x24
out dx, al
mov ecx, 4

.lp1:
in al, dx
test al, 0x80
jne short .retry
test al, 8 ; DRQ set?
jne short .data_rdy

.retry:
dec ecx
jg short .lp1


.pior_l:
in al, dx
test al, 0x80
jne short .pior_l
test al, 0x21
jne short .fail

.data_rdy:
sub dl, 7
mov cx, 256
rep insw
or dl, 7
in al, dx
in al, dx
in al, dx
in al, dx


inc ebp
dec ebx
test bx, bx
jne short .pior_l

sub dx, 7
sub ebp, [esi + dd_stLBA]

test al, 0x21 ; test the last status ERR bits
je short .done
.fail:
stc
.done:
ret



srst_ata_st:
push eax
mov al, 4
out dx, al ; do a "software reset" on the bus
xor eax, eax
out dx, al ; reset the bus to normal operation
in al, dx ; it might take 4 tries for status bits to reset
in al, dx ; ie. do a 400ns delay
in al, dx
in al, dx
.rdylp:
in al, dx
and al, 0xc0 ; check BSY and RDY
cmp al, 0x40 ; want BSY clear and RDY set
jne short .rdylp
pop eax
ret
43 changes: 43 additions & 0 deletions kernel/drivers/disk/ata/ata_cmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef ATA_CMD_H
#define ATA_CMD_H

// ATA commands
#define ATA_CMD_READ_PIO 0x20
#define ATA_CMD_READ_PIO_EXT 0x24
#define ATA_CMD_READ_DMA 0xC8
#define ATA_CMD_READ_DMA_EXT 0x25
#define ATA_CMD_WRITE_PIO 0x30
#define ATA_CMD_WRITE_PIO_EXT 0x34
#define ATA_CMD_WRITE_DMA 0xCA
#define ATA_CMD_WRITE_DMA_EXT 0x35
#define ATA_CMD_CACHE_FLUSH 0xE7
#define ATA_CMD_CACHE_FLUSH_EXT 0xEA
#define ATA_CMD_PACKET 0xA0
#define ATA_CMD_IDENTIFY_PACKET 0xA1
#define ATA_CMD_IDENTIFY 0xEC

// ATAPI commands
#define ATAPI_CMD_READ 0xA8
#define ATAPI_CMD_EJECT 0x1B

// ATA Identification stuff
#define ATA_IDENT_DEVICETYPE 0
#define ATA_IDENT_CYLINDERS 2
#define ATA_IDENT_HEADS 6
#define ATA_IDENT_SECTORS 12
#define ATA_IDENT_SERIAL 20
#define ATA_IDENT_MODEL 54
#define ATA_IDENT_CAPABILITIES 98
#define ATA_IDENT_FIELDVALID 106
#define ATA_IDENT_MAX_LBA 120
#define ATA_IDENT_COMMANDSETS 164
#define ATA_IDENT_MAX_LBA_EXT 200

// drive interface type and if the disk is master or slave
#define IDE_ATA 0x00
#define IDE_ATAPI 0x01

#define ATA_MASTER 0x00
#define ATA_SLAVE 0x01

#endif
13 changes: 13 additions & 0 deletions kernel/drivers/disk/ata/ata_errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef ATA_ERRORS_H
#define ATA_ERRORS_H

#define ATA_ER_BBK 0x80 // Bad block
#define ATA_ER_UNC 0x40 // Uncorrectable data
#define ATA_ER_MC 0x20 // Media changed
#define ATA_ER_IDNF 0x10 // ID mark not found
#define ATA_ER_MCR 0x08 // Media change request
#define ATA_ER_ABRT 0x04 // Command aborted
#define ATA_ER_TK0NF 0x02 // Track 0 not found
#define ATA_ER_AMNF 0x01 // No address mark

#endif
14 changes: 14 additions & 0 deletions kernel/drivers/disk/ata/ata_status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef ATA_STATUS_H
#define ATA_STATUS_H


#define ATA_SR_BSY 0x80 // Busy
#define ATA_SR_DRDY 0x40 // Drive ready
#define ATA_SR_DF 0x20 // Drive write fault
#define ATA_SR_DSC 0x10 // Drive seek complete
#define ATA_SR_DRQ 0x08 // Data request ready
#define ATA_SR_CORR 0x04 // Corrected data
#define ATA_SR_IDX 0x02 // Index
#define ATA_SR_ERR 0x01 // Error

#endif
Loading