2018-03-24 00:58:24 +00:00
|
|
|
#ifndef HAL_CPU_H
|
|
|
|
#define HAL_CPU_H
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-25 09:53:35 +00:00
|
|
|
#include "type.h"
|
2018-01-26 08:43:22 +00:00
|
|
|
#include "kernel/hal/atomic.h"
|
2016-07-09 03:01:33 +00:00
|
|
|
|
|
|
|
#define HAL_CORE_COUNT 1
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-14 07:31:50 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
struct STRUCT_PACKED hal_gdt_ptr
|
2016-06-13 04:11:38 +00:00
|
|
|
{
|
2018-03-24 00:58:24 +00:00
|
|
|
uint16 limit;
|
|
|
|
uint64 base;
|
|
|
|
};
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
struct STRUCT_PACKED hal_idt_ptr
|
2016-06-13 04:11:38 +00:00
|
|
|
{
|
2018-03-24 00:58:24 +00:00
|
|
|
uint16 limit;
|
|
|
|
uint64 base;
|
|
|
|
};
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2016-06-24 01:48:34 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
/**
|
|
|
|
* CPU Instructions
|
|
|
|
*/
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_cpuid(uint32 *eax, uint32 *ebx, uint32 *ecx, uint32 *edx);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-18 07:48:59 +00:00
|
|
|
extern void SXAPI hal_halt_cpu(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-18 07:48:59 +00:00
|
|
|
extern void SXAPI hal_enable_interrupt(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-18 07:48:59 +00:00
|
|
|
extern void SXAPI hal_disable_interrupt(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* IO Port Operations
|
|
|
|
*/
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern int8 SXAPI hal_read_port_8(uint16 port);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern int16 SXAPI hal_read_port_16(uint16 port);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern int32 SXAPI hal_read_port_32(uint16 port);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_port_8(uint16 port, uint8 data);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_port_16(uint16 port, uint16 data);
|
2016-06-14 06:57:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_port_32(uint16 port, uint32 data);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CPU Structure Operations
|
|
|
|
*/
|
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_flush_gdt(struct hal_gdt_ptr *gdt_ptr, uint64 code_slct, uint64 data_slct);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-02-18 07:48:59 +00:00
|
|
|
extern void SXAPI hal_flush_tlb(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_flush_idt(struct hal_idt_ptr *idt_ptr);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_read_idt(struct hal_idt_ptr **idt_ptr);
|
2016-06-14 06:33:31 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
/**
|
|
|
|
* Control Register Operations
|
|
|
|
*/
|
|
|
|
#define MSR_IA32_APIC_BASE 0x1B
|
2018-02-18 04:06:57 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_read_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
|
2018-01-26 08:43:22 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_msr(uint32 *ecx, uint32 *edx, uint32 *eax);
|
2018-01-26 08:43:22 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_cr3(uint64 base);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern uint64 SXAPI hal_read_cr3(void);
|
2016-06-13 04:11:38 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern void SXAPI hal_write_cr8(uint64 pri);
|
2016-06-15 07:29:46 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
extern uint64 SXAPI hal_read_cr8(void);
|
2016-06-15 07:29:46 +00:00
|
|
|
|
2018-01-26 08:43:22 +00:00
|
|
|
|
2018-03-24 00:58:24 +00:00
|
|
|
#endif
|