Skip to content

Commit 9113925

Browse files
committed
* Added function to print cpuinfo
* Added driver for PIT * Added driver for serialport * Added driver for keyboard * Implemented a basic shell * Added a function sysfetch which will fetch and print info about the os * Updated Makefile * Bumped kernel version to 1.2.0 * Updated bochsrc * updated Interrupt.c
1 parent 075e30c commit 9113925

File tree

19 files changed

+964
-31
lines changed

19 files changed

+964
-31
lines changed

docs/bochsrc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
megs: 32
2-
romimage: file=/usr/share/bochs/BIOS-bochs-latest, address=0xf0000
3-
vgaromimage: /usr/share/bochs/VGABIOS-elpin-2.40
4-
floppya: 1_44=/dev/loop0, status=inserted
5-
boot: a
2+
ata0-slave: type=cdrom, path=SectorOS_RE2.iso, status=inserted
3+
com1: enabled=1, mode=file, dev=serial.log
4+
speaker: enabled=1, mode=sound
65
log: bochsout.txt
6+
boot: cdrom
77
mouse: enabled=0
88
clock: sync=realtime
9-
cpu: ips=500000
9+
cpu: ips=5000000

src/Include/idt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ typedef struct {
2020

2121

2222
void init_idt();
23-
void idt_set_gate(uint8_t num, uint32_t base, uint16_t selector, uint8_t flags);
23+
void set_idt_gate(uint8_t num, uint32_t base, uint16_t selector, uint8_t flags);
2424

2525
#endif

src/Include/isr.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
#include "system.h"
55

6-
typedef void (*isr_t)(registers_t *);
6+
typedef void (*isr_t)(registers_t);
77
extern isr_t interrupt_handlers[256];
88

99
void register_interrupt_handler(int num, isr_t handler);
10+
void enable_interrupts();
11+
void disable_interrupts();
12+
13+
#define IRQ_BASE 0x20
14+
#define IRQ(n) (IRQ_BASE + n)
1015

1116

1217
// Pointer to the Interrupts in idt_helper.asm

src/Include/keyboard.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __KEYBOARD_H__
2+
#define __KEYBOARD_H__
3+
4+
#include "system.h"
5+
#include "string.h"
6+
#include "port.h"
7+
#include "printf.h"
8+
#include "isr.h"
9+
10+
#define KEYBOARD_COMMAND_PORT 0x64
11+
#define KEYBOARD_DATA_PORT 0x60
12+
13+
typedef void (*keyboard_handler_t)(uint8_t);
14+
15+
void init_keyboard(keyboard_handler_t handler);
16+
void keyboard_callback(registers_t regs);
17+
18+
#endif

src/Include/pic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
// PIC command
1717
#define PIC_EOI 0x20
1818

19-
void pic_init();
19+
void init_pic();
2020
void pic_eoi(unsigned char irq);
2121

2222
#endif

src/Include/pit.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef __PIT_H
2+
#define __PIT_H
3+
4+
#include "system.h"
5+
#include "port.h"
6+
#include "isr.h"
7+
#include "printf.h"
8+
9+
#define PIT_FREQUENCY 1193180
10+
#define PIT_CHANNEL0 0x40
11+
#define PIT_CHANNEL1 0x41
12+
#define PIT_CHANNEL2 0x42
13+
#define PIT_COMMAND 0x43
14+
15+
typedef void (*PIT_CALLBACK)(void);
16+
17+
void init_pit(uint32_t frequency, isr_t callback);
18+
void chfreq(uint32_t freq);
19+
void wait(uint32_t ms);
20+
void register_function(PIT_CALLBACK callback);
21+
22+
#endif

src/Include/serial.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef __SERIAL_H
2+
#define __SERIAL_H
3+
4+
#include "system.h"
5+
#include "printf.h"
6+
#include "port.h"
7+
#include "pit.h"
8+
9+
#define COM1 0x3F8
10+
#define COM2 0x2F8
11+
#define COM3 0x3E8
12+
#define COM4 0x2E8
13+
14+
void init_serial(uint16_t port);
15+
void serial_putc(char c);
16+
void serial_puts(char *str);
17+
char serial_getc();
18+
void serial_printf(char *fmt, ...);
19+
20+
#endif

src/Include/shell.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef __SHELL_H__
2+
#define __SHELL_H__
3+
4+
#include "system.h"
5+
#include "printf.h"
6+
#include "string.h"
7+
#include "vga.h"
8+
#include "serial.h"
9+
10+
#define SHELL_BUFFER_SIZE 256
11+
12+
void shell_run(uint8_t);
13+
14+
#endif

src/Include/system.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
#include <stdint.h>
55
#include <stdarg.h>
66
#include <stddef.h>
7+
#include <stdbool.h>
78
#include "string.h"
9+
#include "multiboot.h"
810

911
#define KB 1024
1012
#define MB (1024*KB)
1113
#define GB (1024*MB)
1214

15+
#define MSECOND 1
16+
#define SECOND 1000*MSECOND
17+
#define MINUTE 60*SECOND
18+
#define HOUR 60*MINUTE
19+
1320
#define HALT asm("cli"); asm("hlt");
1421
#define ASSERT(x) if(!(x)) { \
22+
printf("Assertion failed: %s, %s, %d\n", #x, __FILE__, __LINE__); \
23+
HALT; \
24+
}
1525

26+
#define CPUID(in, a, b, c, d) __asm__("cpuid": "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "a"(in));
1627
#ifndef KERNEL_BUILD
1728
#define KERNEL_BUILD "2022-01-01"
1829
#endif
@@ -22,13 +33,16 @@
2233
#endif
2334

2435
extern uint32_t end;
36+
extern uint32_t mboot_addr;
2537

2638
#define KERNEL_BASE 0x100000
2739
#define KERNEL_END end
2840

29-
#define KERNEL_VERSION "1.0.3"
41+
#define KERNEL_VERSION "1.2.0"
3042
#define KERNEL_NAME "SectorOS-RE2"
3143

44+
void print_cpuinfo();
45+
3246
typedef struct CPUSTATE
3347
{
3448
uint32_t eax;

src/Interrupt/exception.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ char* exception_messages[] =
4141

4242
void exception_handler(registers_t cps)
4343
{
44-
if(cps.ino < 32)
44+
if(cps.ino < IRQ_BASE)
4545
{
4646
change_color(VGA_COLOR_RED, VGA_COLOR_BLACK);
4747
printf("KERNEL PANIC. EXCEPTION %d: %s\n", cps.ino, exception_messages[cps.ino]);
@@ -65,7 +65,7 @@ void exception_handler(registers_t cps)
6565
if(interrupt_handlers[cps.ino] != 0)
6666
{
6767
isr_t handler = interrupt_handlers[cps.ino];
68-
handler(&cps);
68+
handler(cps);
6969
}
7070
else
7171
{

0 commit comments

Comments
 (0)