rtc
This commit is contained in:
@@ -29,6 +29,9 @@ Hello world programs that run without an operating system.
|
||||
1. [Interrupt zero divide](interrupt_zero_divide.S)
|
||||
1. in
|
||||
1. [in keyboard](in_keyboard.S)
|
||||
1. [in PIT (TODO)](in_pit.S)
|
||||
1. [in RTC](in_rtc.S)
|
||||
1. [in mouse (TODO)](in_mouse.S)
|
||||
1. APM
|
||||
1. [APM shutdown](apm_shutdown.S)
|
||||
1. [APM shutdown 2](apm_shutdown2.S)
|
||||
|
||||
9
common.h
9
common.h
@@ -84,6 +84,15 @@ letter:
|
||||
end:
|
||||
.endm
|
||||
|
||||
#define PRINT_HEX(reg) \
|
||||
HEX(<reg>);\
|
||||
PUTC(%al);\
|
||||
PUTC(%bl)
|
||||
|
||||
#define PRINT_NEWLINE \
|
||||
PUTC($0x0A);\
|
||||
PUTC($0x0D)
|
||||
|
||||
/*
|
||||
Print a null terminated string.
|
||||
|
||||
|
||||
8
in.md
Normal file
8
in.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# in
|
||||
|
||||
TODO http://wiki.osdev.org/CMOS#Getting_Current_Date_and_Time_from_RTC says:
|
||||
|
||||
/* since the 0x80 bit of al is not set, NMI is active */
|
||||
out 0x70,al
|
||||
|
||||
What does it mean?
|
||||
@@ -9,9 +9,14 @@ Scancode tables: TODO: official specs?
|
||||
- http://flint.cs.yale.edu/cs422/doc/art-of-asm/pdf/APNDXC.PDF
|
||||
- https://en.wikipedia.org/wiki/Scancode
|
||||
|
||||
TODO Where does the 0x60 come from? http://wiki.osdev.org/I/O_Ports has a small list.
|
||||
TODO Where does the 0x60 come from?
|
||||
|
||||
- http://wiki.osdev.org/I/O_Ports
|
||||
- http://stackoverflow.com/questions/14194798/is-there-a-specification-of-x86-i-o-port-assignment
|
||||
|
||||
TODO Possible to do this with the interrupt table instead of `in`?
|
||||
|
||||
TODO understand http://wiki.osdev.org/PS2_Keyboard
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
@@ -20,14 +25,12 @@ BEGIN
|
||||
/* TODO why CLI makes no difference? We are not using interrupts? */
|
||||
/*cli*/
|
||||
loop:
|
||||
/* Store the scancode to al. */
|
||||
in $0x60, %al
|
||||
cmp %al, %cl
|
||||
jz loop
|
||||
mov %al, %cl
|
||||
HEX(<%al>)
|
||||
PUTC(%al)
|
||||
PUTC(%bl)
|
||||
PUTC($0x0A)
|
||||
PUTC($0x0D)
|
||||
PRINT_HEX(%al)
|
||||
PRINT_NEWLINE
|
||||
jmp loop
|
||||
END
|
||||
|
||||
10
in_mouse.S
Normal file
10
in_mouse.S
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
TODO http://wiki.osdev.org/Mouse_Input
|
||||
|
||||
I am so going to make a pixel drawing program with this.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
BEGIN
|
||||
hlt
|
||||
END
|
||||
10
in_pit.S
Normal file
10
in_pit.S
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
TODO http://wiki.osdev.org/PIT
|
||||
|
||||
Going to use in 0x40
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
BEGIN
|
||||
hlt
|
||||
END
|
||||
73
in_rtc.S
Normal file
73
in_rtc.S
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
TODO http://wiki.osdev.org/RTC
|
||||
|
||||
Kenrel 4.2 usage: https://github.com/torvalds/linux/blob/v4.2/arch/x86/kernel/rtc.c#L121
|
||||
|
||||
http://stackoverflow.com/questions/1465927/how-can-i-access-system-time-using-nasm
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
BEGIN
|
||||
|
||||
.equ RTCaddress, 0x70
|
||||
.equ RTCdata, 0x71
|
||||
|
||||
update_in_progress:
|
||||
mov $10, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
testb $0x80, %al
|
||||
jne update_in_progress
|
||||
|
||||
/* Second. */
|
||||
mov $0, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
|
||||
/* Only print if second changed. */
|
||||
cmp %al, %cl
|
||||
je update_in_progress
|
||||
mov %al, %cl
|
||||
|
||||
PRINT_HEX(%al)
|
||||
PUTC($0x20)
|
||||
|
||||
/* Minute. */
|
||||
mov $0x02, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
PRINT_HEX(%al)
|
||||
PUTC($0x20)
|
||||
|
||||
/* Hour. */
|
||||
mov $0x04, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
PRINT_HEX(%al)
|
||||
PUTC($0x20)
|
||||
|
||||
/* Day. */
|
||||
mov $0x07, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
PRINT_HEX(%al)
|
||||
PUTC($0x20)
|
||||
|
||||
/* Month. */
|
||||
mov $0x08, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
PRINT_HEX(%al)
|
||||
PUTC($0x20)
|
||||
|
||||
/* Year. */
|
||||
mov $0x09, %al
|
||||
out %al, $RTCaddress
|
||||
in $RTCdata, %al
|
||||
PRINT_HEX(%al)
|
||||
PRINT_NEWLINE
|
||||
|
||||
jmp update_in_progress
|
||||
|
||||
hlt
|
||||
END
|
||||
10
interrupt.S
10
interrupt.S
@@ -6,19 +6,25 @@ Should print the characters 'ab' to screen.
|
||||
TODO: is STI not needed because this interrupt is not maskable?
|
||||
|
||||
TODO: use IDTR as a base. Is the initial value 0 guaranteed?
|
||||
|
||||
TODO: interrupt priority: order looks like: 0, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15, 3, 4, 5, 6, 7
|
||||
|
||||
## iret
|
||||
|
||||
Returns to the next instruction to be executed
|
||||
before the interrupt came in.
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
BEGIN
|
||||
CLEAR
|
||||
movw $handler, 0x00
|
||||
movw $0x00, 0x02
|
||||
movw %cs, 0x02
|
||||
int $0
|
||||
PUTC($0x62)
|
||||
jmp end
|
||||
handler:
|
||||
PUTC($0x61)
|
||||
/* Returns to the int instruction. */
|
||||
iret
|
||||
end:
|
||||
hlt
|
||||
|
||||
@@ -6,8 +6,8 @@ Same as doing an `int $0`.
|
||||
BEGIN
|
||||
CLEAR
|
||||
movw $handler, 0x00
|
||||
movw $0x00, 0x02
|
||||
mov $0x00, %ax
|
||||
movw %cs, 0x02
|
||||
mov $0, %ax
|
||||
div %ax
|
||||
jmp fail
|
||||
handler:
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/*
|
||||
|
||||
*/
|
||||
|
||||
#include "common.h"
|
||||
BEGIN
|
||||
hlt
|
||||
|
||||
@@ -2,22 +2,17 @@
|
||||
|
||||
Successor for BIOS.
|
||||
|
||||
TODO get a hello world program working.
|
||||
TODO get a hello world program working:
|
||||
|
||||
- http://www.rodsbooks.com/efi-programming/hello.html Best source so far: allowed me to compile the hello world! TODO: how to run it now on QEMU and real hardware?
|
||||
- https://fedoraproject.org/wiki/Using_UEFI_with_QEMU
|
||||
- https://wiki.ubuntu.com/UEFI/OVMF
|
||||
|
||||
Sources:
|
||||
|
||||
- https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface
|
||||
- http://wiki.osdev.org/UEFI
|
||||
|
||||
Running without image gives the UEFI shell, and a Linux kernel image booted fine with it: http://unix.stackexchange.com/a/228053/32558 , so we just need to generate the image.
|
||||
|
||||
OVMF.fd IA32 r15214 downloaded from: https://sourceforge.net/projects/edk2/files/OVMF/OVMF-IA32-r15214.zip/download
|
||||
OVMF.fd IA32 r15214 downloaded from: https://sourceforge.net/projects/edk2/files/OVMF/OVMF-IA32-r15214.zip/download Included in-source for convenience, even though it is ugly.
|
||||
|
||||
Included in-source for convenience, even though it is ugly.
|
||||
UEFI offers a large API. The POSIX C library has been ported to it, and there is some talk about Python running on it (through that POSIX lib)?
|
||||
|
||||
## Shell
|
||||
|
||||
@@ -34,3 +29,9 @@ Exit the shell.
|
||||
Enter a filesystem.
|
||||
|
||||
TODO: how to make it visible in the first place?
|
||||
|
||||
## Bibliography
|
||||
|
||||
- https://www.youtube.com/watch?v=V2aq5M3Q76U hardcore kernel dev Matthew Garrett saying how bad UEFI is
|
||||
- https://wiki.archlinux.org/index.php/Unified_Extensible_Firmware_Interface
|
||||
- http://wiki.osdev.org/UEFI
|
||||
|
||||
Reference in New Issue
Block a user