forked from PoliEcho-holding-org/kern
Added utility functions in system.h
This commit is contained in:
@@ -2,8 +2,14 @@
|
|||||||
[global _start]
|
[global _start]
|
||||||
|
|
||||||
[extern main]
|
[extern main]
|
||||||
|
[extern idtp]
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
call main
|
call main
|
||||||
cli
|
cli
|
||||||
hlt
|
hlt
|
||||||
|
|
||||||
|
[global idtLoad]
|
||||||
|
idtLoad:
|
||||||
|
lidt [idtp]
|
||||||
|
ret
|
||||||
|
|||||||
@@ -28,5 +28,7 @@ void idtSetGate(uint8_t i, uint32_t offset, uint16_t selector, uint8_t typeAttr)
|
|||||||
void setupIdt() {
|
void setupIdt() {
|
||||||
idtp.limit = sizeof(struct idtEntry) * 256;
|
idtp.limit = sizeof(struct idtEntry) * 256;
|
||||||
idtp.base = (uint32_t)&idt;
|
idtp.base = (uint32_t)&idt;
|
||||||
|
|
||||||
|
idtLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
void setupIdt();
|
void setupIdt();
|
||||||
void idtSetGate(uint8_t i, uint32_t offset, uint16_t selector, uint8_t typeAttr);
|
void idtSetGate(uint8_t i, uint32_t offset, uint16_t selector, uint8_t typeAttr);
|
||||||
|
extern void idtLoad();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1,27 @@
|
|||||||
#include "system.h"
|
#include "system.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
uint8_t inb(uint16_t port) {
|
||||||
|
uint8_t result;
|
||||||
|
asm volatile("in %1, %0" : "=a"(result) : "Nd"(port));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void outb(uint16_t port, uint8_t data) {
|
||||||
|
asm volatile("out %0, %1" :: "a"(data), "Nd"(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
char* memcopy(char* src, char* dst, uint16_t length) {
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
*(dst + i) = *(src + i);
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* memset(char* dst, char value, uint16_t length) {
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
*(dst + i) = value;
|
||||||
|
}
|
||||||
|
return dst;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
#ifndef SYSTEM_H
|
#ifndef SYSTEM_H
|
||||||
#define SYSTEM_H
|
#define SYSTEM_H
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
// Port functions
|
||||||
|
uint8_t inb(uint16_t port);
|
||||||
|
void outb(uint16_t port, uint8_t data);
|
||||||
|
|
||||||
|
// Memory functions
|
||||||
|
char* memcopy(char* src, char* dst, uint16_t length);
|
||||||
|
char* memset(char* dst, char data, uint16_t length);
|
||||||
|
|
||||||
|
struct regs {
|
||||||
|
unsigned int gs, fs, es, ds;
|
||||||
|
unsigned int edi, esi, ebp, esp, ebx, edx, ecx, eax;
|
||||||
|
unsigned int intNo, errCode;
|
||||||
|
unsigned int eip, cs, eflags, useresp, ss;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user