System clock
System clock
How would I get the current time on the computers clock for my OS through c?
Re: System clock
16bit or 32bit?
16bit you use the
Int 0x1A
Entry:
AH = 00h
Return:
CX = high (most signif.) portion of clock count
DX = low (least signif.) portion of clock count
AL = 0 if clock was read or written (via AH=0,1)
within the current 24-hour period
Otherwise, AL > 0
im not sure about how to interpret cx and dx to hour:minute:second though
32bit:
I have no idea
16bit you use the
Int 0x1A
Entry:
AH = 00h
Return:
CX = high (most signif.) portion of clock count
DX = low (least signif.) portion of clock count
AL = 0 if clock was read or written (via AH=0,1)
within the current 24-hour period
Otherwise, AL > 0
im not sure about how to interpret cx and dx to hour:minute:second though
32bit:
I have no idea
Re: System clock
here's my code, as it's just simple in's and out's you should be able to translate it to C yourself.
sorry for the long post, thought you might need the BCD converting functions...
Code: Select all
;----------------------------------------------------------;
; BOS kernel Christoffer Bubach, 2005. ;
;----------------------------------------------------------;
; ;
; To get stuff ( time & date ) from CMOS memory. ;
; ;
;----------------------------------------------------------;
;-----------------------------------;
; variables containing CMOS data ;
;-----------------------------------;
century db 0 ; latest century,
year db 0 ; year,
month db 0 ; month,
day db 0 ; day (1 = sunday),
hour db 0 ; hour,
minute db 0 ; minute and
second db 0 ; second read in from CMOS.
;-------------------------;
; save info from CMOS ;
;-------------------------;
get_cmos_data:
push ax
mov al, 0x00 ; get the "second" byte
out 0x70, al
in al, 0x71
mov [second], al ; save it.
mov al, 0x02 ; get the "minute" byte
out 0x70, al
in al, 0x71
mov [minute], al
mov al, 0x04 ; get the "hour" byte
out 0x70, al
in al, 0x71
mov [hour], al
mov al, 0x07 ; get the "day" byte
out 0x70, al
in al, 0x71
mov [day], al
mov al, 0x08 ; get the "month" byte
out 0x70, al
in al, 0x71
mov [month], al
mov al, 0x09 ; get the "year" byte
out 0x70, al
in al, 0x71
mov [year], al
mov al, 0x32 ; get the "century" byte
out 0x70, al
in al, 0x71
mov [century], al
pop ax
ret
;------------------------------------------------;
; calculate binary from BCD ;
; in: al = BCD ;
; out: al = bin ;
;------------------------------------------------;
BCD2bin:
push ebx
mov bl, al ; bl = al mod 16
and bl, 0x0F
shr al, 4 ; al = al / 16
mov bh, 10
mul bh ; multiply by 10
add al, bl ; add in low nib
pop ebx
ret
;------------------------------------------------;
; calculate ASCII from BCD ;
; in: al = BCD ;
; out: ax = ASCII ;
;------------------------------------------------;
BCD2ascii:
push ecx
mov ah, al
and ax, 0xF00F ; mask bits
shr ah, 4 ; right shift ah to get unpacked BCD
or ax, 0x3030 ; combine with 30 to get ASCII
xchg ah, al ; swap for ASCII storage convention
pop ecx
ret
Re: System clock
You shold better set bit 5 in CMOS B Register and write a INT that will handle IRQ8 which will be called every second. In that INT you will read time and date and store them in system variables. I'm doing in such way in my OS .
Re: System clock
actually its irq1 but by default it is mapped to interrupt number 8 but in protected mode it interferes with exceptions, so you have to remap it
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: System clock
Where can I get a listing of CMOS registers, btw?
Thanks,
Jeff
Thanks,
Jeff
Re: System clock
Hmmm, maybe you should invest some money in book like "PC Anatomy". We have such book in Poland it is great. So I think that there where you are living should be something like that also.
And for now , here you have some CMOS map:
http://www.gilanet.com/ohlandl/config/c ... sters.html
And for now , here you have some CMOS map:
http://www.gilanet.com/ohlandl/config/c ... sters.html
Re: System clock
well, actually it is IRQ0 and IRQ8, they are both clock interupts, though IRQ8 has a lower priority
most people just keep track of the time within the OS, and only read the clock occasionally, for acuracy purposes
they would keep a counter and inc it on each clock, then inc the timer.sec when it reaches the correct value (clocks/sec)
the reason for this is that retreaving the values from CMOS is extreamly slow (on some systems it may take longer than the time between clock tics! -- which will cause your OS to be very unresponsive)
most people just keep track of the time within the OS, and only read the clock occasionally, for acuracy purposes
they would keep a counter and inc it on each clock, then inc the timer.sec when it reaches the correct value (clocks/sec)
the reason for this is that retreaving the values from CMOS is extreamly slow (on some systems it may take longer than the time between clock tics! -- which will cause your OS to be very unresponsive)
Re: System clock
hckr83 you wrote: "actually its irq1 but...". From where you get that it is IRQ1 ???
- carbonBased
- Member
- Posts: 382
- Joined: Sat Nov 20, 2004 12:00 am
- Location: Wellesley, Ontario, Canada
- Contact:
Re: System clock
From what I can recall:
IRQ0 -> System timer
IRQ1 -> Keyboard
IRQ2 -> ??
IRQ3 -> Serial
IRQ4 -> Serial
IRQ5,6 -> ??
IRQ7 -> Printer
IRQ8 -> CMOS RTC
So, yeah, the IRQ1 comment is off... but may have just been a typo.
IRQ0, without remapping, is set to INT8... but, on most OSs I've seen, that's fairly irrelevant, as IRQ0 is used for task switching (could also be used to keep the time, though).
IRQ0 -> System timer
IRQ1 -> Keyboard
IRQ2 -> ??
IRQ3 -> Serial
IRQ4 -> Serial
IRQ5,6 -> ??
IRQ7 -> Printer
IRQ8 -> CMOS RTC
So, yeah, the IRQ1 comment is off... but may have just been a typo.
IRQ0, without remapping, is set to INT8... but, on most OSs I've seen, that's fairly irrelevant, as IRQ0 is used for task switching (could also be used to keep the time, though).
Re: System clock
oops i meant irq0
cause if i though it was irq1 my uptime counter on my os would be way off
cause if i though it was irq1 my uptime counter on my os would be way off
Re: System clock
carbonBased:
IRQ2 -> Chain to Slave PIC
afaik, most OSs do use IRQ0 also to track time (reading occasionally to maintain acuracy) -- though i've seen at least one person who uses IRQ8 to update OS time
IRQ2 -> Chain to Slave PIC
afaik, most OSs do use IRQ0 also to track time (reading occasionally to maintain acuracy) -- though i've seen at least one person who uses IRQ8 to update OS time